001/* 002 * $Id: QuotSolvablePolynomialRing.java 6010 2020-04-01 10:39:15Z kredel $ 003 */ 004 005package edu.jas.fd; 006 007 008import java.io.IOException; 009import java.io.Reader; 010import java.io.StringReader; 011import java.math.BigInteger; 012import java.util.ArrayList; 013import java.util.List; 014import java.util.Map; 015import java.util.Random; 016 017import org.apache.logging.log4j.LogManager; 018import org.apache.logging.log4j.Logger; 019 020import edu.jas.kern.PrettyPrint; 021import edu.jas.kern.Scripting; 022import edu.jas.poly.ExpVector; 023import edu.jas.poly.GenPolynomial; 024import edu.jas.poly.GenPolynomialRing; 025import edu.jas.poly.GenPolynomialTokenizer; 026import edu.jas.poly.GenSolvablePolynomial; 027import edu.jas.poly.GenSolvablePolynomialRing; 028import edu.jas.poly.RecSolvablePolynomial; 029import edu.jas.poly.RecSolvablePolynomialRing; 030import edu.jas.poly.RelationTable; 031import edu.jas.poly.TermOrder; 032import edu.jas.structure.GcdRingElem; 033import edu.jas.structure.RingElem; 034import edu.jas.structure.RingFactory; 035 036 037/** 038 * QuotSolvablePolynomialRing generic recursive solvable polynomial factory 039 * implementing RingFactory and extending GenSolvablePolynomialRing factory. 040 * Factory for n-variate ordered solvable polynomials over solvable polynomial 041 * coefficients. The non-commutative multiplication relations are maintained in 042 * a relation table and the non-commutative multiplication relations between the 043 * coefficients and the main variables are maintained in a coefficient relation 044 * table. Almost immutable object, except variable names and relation table 045 * contents. Will be deprecated use <code>QLRSolvablePolynomialRing</code> 046 * @param <C> coefficient type 047 * @author Heinz Kredel 048 */ 049 050public class QuotSolvablePolynomialRing<C extends GcdRingElem<C>> 051 extends GenSolvablePolynomialRing<SolvableQuotient<C>> { 052 053 054 /* 055 * The solvable multiplication relations between variables and coefficients. 056 */ 057 //public final RelationTable<GenPolynomial<C>> coeffTable; 058 059 060 /** 061 * Recursive solvable polynomial ring with polynomial coefficients. 062 */ 063 public final RecSolvablePolynomialRing<C> polCoeff; 064 065 066 /** 067 * The constant polynomial 0 for this ring. Hides super ZERO. 068 */ 069 public final QuotSolvablePolynomial<C> ZERO; 070 071 072 /** 073 * The constant polynomial 1 for this ring. Hides super ONE. 074 */ 075 public final QuotSolvablePolynomial<C> ONE; 076 077 078 private static final Logger logger = LogManager.getLogger(QuotSolvablePolynomialRing.class); 079 080 081 //private static final boolean debug = logger.isDebugEnabled(); 082 083 084 /** 085 * The constructor creates a solvable polynomial factory object with the 086 * default term order and commutative relations. 087 * @param cf factory for coefficients of type C. 088 * @param n number of variables. 089 */ 090 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n) { 091 this(cf, n, new TermOrder(), null, null); 092 } 093 094 095 /** 096 * The constructor creates a solvable polynomial factory object with the 097 * default term order. 098 * @param cf factory for coefficients of type C. 099 * @param n number of variables. 100 * @param rt solvable multiplication relations. 101 */ 102 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n, 103 RelationTable<SolvableQuotient<C>> rt) { 104 this(cf, n, new TermOrder(), null, rt); 105 } 106 107 108 /** 109 * The constructor creates a solvable polynomial factory object with the 110 * given term order and commutative relations. 111 * @param cf factory for coefficients of type C. 112 * @param n number of variables. 113 * @param t a term order. 114 */ 115 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n, TermOrder t) { 116 this(cf, n, t, null, null); 117 } 118 119 120 /** 121 * The constructor creates a solvable polynomial factory object with the 122 * given term order. 123 * @param cf factory for coefficients of type C. 124 * @param n number of variables. 125 * @param t a term order. 126 * @param rt solvable multiplication relations. 127 */ 128 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n, TermOrder t, 129 RelationTable<SolvableQuotient<C>> rt) { 130 this(cf, n, t, null, rt); 131 } 132 133 134 /** 135 * The constructor creates a solvable polynomial factory object with the 136 * given term order and commutative relations. 137 * @param cf factory for coefficients of type C. 138 * @param n number of variables. 139 * @param t a term order. 140 * @param v names for the variables. 141 */ 142 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n, TermOrder t, String[] v) { 143 this(cf, n, t, v, null); 144 } 145 146 147 /** 148 * The constructor creates a solvable polynomial factory object with the 149 * given term order and commutative relations. 150 * @param cf factory for coefficients of type C. 151 * @param t a term order. 152 * @param v names for the variables. 153 */ 154 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, TermOrder t, String[] v) { 155 this(cf, v.length, t, v, null); 156 } 157 158 159 /** 160 * The constructor creates a solvable polynomial factory object with the 161 * default term order. 162 * @param cf factory for coefficients of type C. 163 * @param v names for the variables. 164 */ 165 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, String[] v) { 166 this(cf, v.length, new TermOrder(), v, null); 167 } 168 169 170 /** 171 * The constructor creates a solvable polynomial factory object with the 172 * given term order. 173 * @param cf factory for coefficients of type C. 174 * @param n number of variables. 175 * @param t a term order. 176 * @param v names for the variables. 177 * @param rt solvable multiplication relations. 178 */ 179 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, int n, TermOrder t, String[] v, 180 RelationTable<SolvableQuotient<C>> rt) { 181 super(cf, n, t, v, rt); 182 //if (rt == null) { // handled in super } 183 SolvableQuotientRing<C> cfring = (SolvableQuotientRing<C>) cf; // == coFac 184 polCoeff = new RecSolvablePolynomialRing<C>(cfring.ring, n, t, v); 185 if (table.size() > 0) { // TODO 186 ExpVector e = null; 187 ExpVector f = null; 188 GenSolvablePolynomial<GenPolynomial<C>> p = null; 189 polCoeff.table.update(e, f, p); // from rt 190 } 191 //coeffTable = polCoeff.coeffTable; //new RelationTable<GenPolynomial<C>>(polCoeff, true); 192 ZERO = new QuotSolvablePolynomial<C>(this); 193 SolvableQuotient<C> coeff = coFac.getONE(); 194 //evzero = ExpVector.create(nvar); // from super 195 ONE = new QuotSolvablePolynomial<C>(this, coeff, evzero); 196 } 197 198 199 /** 200 * The constructor creates a solvable polynomial factory object with the the 201 * same term order, number of variables and variable names as the given 202 * polynomial factory, only the coefficient factories differ and the 203 * solvable multiplication relations are <b>empty</b>. 204 * @param cf factory for coefficients of type C. 205 * @param o other solvable polynomial ring. 206 */ 207 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, GenSolvablePolynomialRing o) { 208 this(cf, o.nvar, o.tord, o.getVars(), null); 209 } 210 211 212 /** 213 * The constructor creates a solvable polynomial factory object with the the 214 * same term order, number of variables and variable names as the given 215 * polynomial factory, only the coefficient factories differ and the 216 * solvable multiplication relations are <b>empty</b>. 217 * @param cf factory for coefficients of type C. 218 * @param o other solvable polynomial ring. 219 */ 220 public QuotSolvablePolynomialRing(RingFactory<SolvableQuotient<C>> cf, QuotSolvablePolynomialRing o) { 221 this(cf, (GenSolvablePolynomialRing) o); 222 } 223 224 225 /** 226 * Get the String representation. 227 * @see java.lang.Object#toString() 228 */ 229 @Override 230 public String toString() { 231 String res = super.toString(); 232 if (PrettyPrint.isTrue()) { 233 //res += "\n" + table.toString(vars); 234 res += "\n" + polCoeff.coeffTable.toString(vars); 235 } else { 236 res += ", #rel = " + table.size() + " + " + polCoeff.coeffTable.size(); 237 } 238 return res; 239 } 240 241 242 /** 243 * Get a scripting compatible string representation. 244 * @return script compatible representation for this Element. 245 * @see edu.jas.structure.Element#toScript() 246 */ 247 @Override 248 public String toScript() { 249 StringBuffer s = new StringBuffer(); 250 switch (Scripting.getLang()) { 251 case Ruby: 252 s.append("SolvPolyRing.new("); 253 break; 254 case Python: 255 default: 256 s.append("SolvPolyRing("); 257 } 258 if (coFac instanceof RingElem) { 259 s.append(((RingElem<SolvableQuotient<C>>) coFac).toScriptFactory()); 260 } else { 261 s.append(coFac.toScript().trim()); 262 } 263 s.append(",\"" + varsToString() + "\","); 264 String to = tord.toScript(); 265 s.append(to); 266 if (table.size() > 0) { 267 String rel = table.toScript(); 268 s.append(",rel="); 269 s.append(rel); 270 } 271 if (polCoeff.coeffTable.size() > 0) { 272 String rel = polCoeff.coeffTable.toScript(); 273 s.append(",coeffrel="); 274 s.append(rel); 275 } 276 s.append(")"); 277 return s.toString(); 278 } 279 280 281 /** 282 * Comparison with any other object. 283 * @see java.lang.Object#equals(java.lang.Object) 284 */ 285 @Override 286 @SuppressWarnings("unchecked") 287 public boolean equals(Object other) { 288 if (other == null) { 289 return false; 290 } 291 if (!(other instanceof QuotSolvablePolynomialRing)) { 292 return false; 293 } 294 QuotSolvablePolynomialRing<C> oring = (QuotSolvablePolynomialRing<C>) other; 295 // do a super.equals( ) 296 if (!super.equals(other)) { 297 return false; 298 } 299 // check same base relations 300 //if ( ! table.equals(oring.table) ) { // done in super 301 // return false; 302 //} 303 if (!polCoeff.coeffTable.equals(oring.polCoeff.coeffTable)) { 304 return false; 305 } 306 return true; 307 } 308 309 310 /** 311 * Hash code for this polynomial ring. 312 * @see java.lang.Object#hashCode() 313 */ 314 @Override 315 public int hashCode() { 316 int h; 317 h = super.hashCode(); 318 h = 37 * h + table.hashCode(); // may be different after some computations 319 h = 37 * h + polCoeff.coeffTable.hashCode(); // may be different 320 return h; 321 } 322 323 324 /** 325 * Get the zero element. 326 * @return 0 as QuotSolvablePolynomial<C>. 327 */ 328 @Override 329 public QuotSolvablePolynomial<C> getZERO() { 330 return ZERO; 331 } 332 333 334 /** 335 * Get the one element. 336 * @return 1 as QuotSolvablePolynomial<C>. 337 */ 338 @Override 339 public QuotSolvablePolynomial<C> getONE() { 340 return ONE; 341 } 342 343 344 /** 345 * Query if this ring is commutative. 346 * @return true if this ring is commutative, else false. 347 */ 348 @Override 349 public boolean isCommutative() { 350 if (polCoeff.coeffTable.size() == 0) { 351 return super.isCommutative(); 352 } 353 // todo: check structure of relations 354 return false; 355 } 356 357 358 /** 359 * Query if this ring is associative. Test if the relations between the mian 360 * variables and the coefficient generators define an associative solvable 361 * ring. 362 * @return true, if this ring is associative, else false. 363 */ 364 @Override 365 public boolean isAssociative() { 366 if (!coFac.isAssociative()) { 367 return false; 368 } 369 QuotSolvablePolynomial<C> Xi, Xj, Xk, p, q; 370 List<GenPolynomial<SolvableQuotient<C>>> gens = generators(); 371 int ngen = gens.size(); 372 for (int i = 0; i < ngen; i++) { 373 Xi = (QuotSolvablePolynomial<C>) gens.get(i); 374 for (int j = i + 1; j < ngen; j++) { 375 Xj = (QuotSolvablePolynomial<C>) gens.get(j); 376 for (int k = j + 1; k < ngen; k++) { 377 Xk = (QuotSolvablePolynomial<C>) gens.get(k); 378 p = Xk.multiply(Xj).multiply(Xi); 379 q = Xk.multiply(Xj.multiply(Xi)); 380 if (!p.equals(q)) { 381 if (logger.isInfoEnabled()) { 382 logger.info("Xk = " + Xk + ", Xj = " + Xj + ", Xi = " + Xi); 383 logger.info("p = ( Xk * Xj ) * Xi = " + p); 384 logger.info("q = Xk * ( Xj * Xi ) = " + q); 385 logger.info("q-p = " + p.subtract(q)); 386 } 387 return false; 388 } 389 } 390 } 391 } 392 return true; //coFac.isAssociative(); 393 } 394 395 396 /** 397 * Get a (constant) QuotSolvablePolynomial<C> element from a long 398 * value. 399 * @param a long. 400 * @return a QuotSolvablePolynomial<C>. 401 */ 402 @Override 403 public QuotSolvablePolynomial<C> fromInteger(long a) { 404 return new QuotSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 405 } 406 407 408 /** 409 * Get a (constant) QuotSolvablePolynomial<C> element from a 410 * BigInteger value. 411 * @param a BigInteger. 412 * @return a QuotSolvablePolynomial<C>. 413 */ 414 @Override 415 public QuotSolvablePolynomial<C> fromInteger(BigInteger a) { 416 return new QuotSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 417 } 418 419 420 /** 421 * Random solvable polynomial. Generates a random solvable polynomial with k 422 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 423 * @param n number of terms. 424 * @return a random solvable polynomial. 425 */ 426 @Override 427 public QuotSolvablePolynomial<C> random(int n) { 428 return random(n, random); 429 } 430 431 432 /** 433 * Random solvable polynomial. Generates a random solvable polynomial with k 434 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 435 * @param n number of terms. 436 * @param rnd is a source for random bits. 437 * @return a random solvable polynomial. 438 */ 439 @Override 440 public QuotSolvablePolynomial<C> random(int n, Random rnd) { 441 if (nvar == 1) { 442 return random(5, n, n, 0.7f, rnd); 443 } 444 return random(5, n, 3, 0.3f, rnd); 445 } 446 447 448 /** 449 * Generate a random solvable polynomial. 450 * @param k bitsize of random coefficients. 451 * @param l number of terms. 452 * @param d maximal degree in each variable. 453 * @param q density of nozero exponents. 454 * @return a random solvable polynomial. 455 */ 456 @Override 457 public QuotSolvablePolynomial<C> random(int k, int l, int d, float q) { 458 return random(k, l, d, q, random); 459 } 460 461 462 /** 463 * Random solvable polynomial. 464 * @param k size of random coefficients. 465 * @param l number of terms. 466 * @param d maximal degree in each variable. 467 * @param q density of nozero exponents. 468 * @param rnd is a source for random bits. 469 * @return a random solvable polynomial. 470 */ 471 @Override 472 public QuotSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) { 473 QuotSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 474 ExpVector e; 475 SolvableQuotient<C> a; 476 // add random coeffs and exponents 477 for (int i = 0; i < l; i++) { 478 e = ExpVector.random(nvar, d, q, rnd); 479 a = coFac.random(k, rnd); 480 r = (QuotSolvablePolynomial<C>) r.sum(a, e); 481 // somewhat inefficient but clean 482 } 483 return r; 484 } 485 486 487 /** 488 * Copy polynomial c. 489 * @param c 490 * @return a copy of c. 491 */ 492 public QuotSolvablePolynomial<C> copy(QuotSolvablePolynomial<C> c) { 493 return new QuotSolvablePolynomial<C>(this, c.getMap()); 494 } 495 496 497 /** 498 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 499 * @param s String. 500 * @return QuotSolvablePolynomial from s. 501 */ 502 @Override 503 public QuotSolvablePolynomial<C> parse(String s) { 504 return parse(new StringReader(s)); 505 } 506 507 508 /** 509 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 510 * @param r Reader. 511 * @return next QuotSolvablePolynomial from r. 512 */ 513 @Override 514 @SuppressWarnings("unchecked") 515 public QuotSolvablePolynomial<C> parse(Reader r) { 516 GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r); 517 QuotSolvablePolynomial<C> p = null; 518 try { 519 GenSolvablePolynomial<SolvableQuotient<C>> s = pt.nextSolvablePolynomial(); 520 p = new QuotSolvablePolynomial<C>(this, s); 521 } catch (IOException e) { 522 logger.error(e.toString() + " parse " + this); 523 p = ZERO; 524 } 525 return p; 526 } 527 528 529 /** 530 * Generate univariate solvable polynomial in a given variable. 531 * @param i the index of the variable. 532 * @return X_i as solvable univariate polynomial. 533 */ 534 @Override 535 public QuotSolvablePolynomial<C> univariate(int i) { 536 return (QuotSolvablePolynomial<C>) super.univariate(i); 537 } 538 539 540 /** 541 * Generate univariate solvable polynomial in a given variable with given 542 * exponent. 543 * @param i the index of the variable. 544 * @param e the exponent of the variable. 545 * @return X_i^e as solvable univariate polynomial. 546 */ 547 @Override 548 public QuotSolvablePolynomial<C> univariate(int i, long e) { 549 return (QuotSolvablePolynomial<C>) super.univariate(i, e); 550 } 551 552 553 /** 554 * Generate univariate solvable polynomial in a given variable with given 555 * exponent. 556 * @param modv number of module variables. 557 * @param i the index of the variable. 558 * @param e the exponent of the variable. 559 * @return X_i^e as solvable univariate polynomial. 560 */ 561 @Override 562 public QuotSolvablePolynomial<C> univariate(int modv, int i, long e) { 563 return (QuotSolvablePolynomial<C>) super.univariate(modv, i, e); 564 } 565 566 567 /** 568 * Generate list of univariate polynomials in all variables. 569 * @return List(X_1,...,X_n) a list of univariate polynomials. 570 */ 571 @Override 572 public List<QuotSolvablePolynomial<C>> univariateList() { 573 return univariateList(0, 1L); 574 } 575 576 577 /** 578 * Generate list of univariate polynomials in all variables. 579 * @param modv number of module variables. 580 * @return List(X_1,...,X_n) a list of univariate polynomials. 581 */ 582 @Override 583 public List<QuotSolvablePolynomial<C>> univariateList(int modv) { 584 return univariateList(modv, 1L); 585 } 586 587 588 /** 589 * Generate list of univariate polynomials in all variables with given 590 * exponent. 591 * @param modv number of module variables. 592 * @param e the exponent of the variables. 593 * @return List(X_1^e,...,X_n^e) a list of univariate polynomials. 594 */ 595 @Override 596 public List<QuotSolvablePolynomial<C>> univariateList(int modv, long e) { 597 List<QuotSolvablePolynomial<C>> pols = new ArrayList<QuotSolvablePolynomial<C>>(nvar); 598 int nm = nvar - modv; 599 for (int i = 0; i < nm; i++) { 600 QuotSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e); 601 pols.add(p); 602 } 603 return pols; 604 } 605 606 607 /** 608 * Extend variables. Used e.g. in module embedding. Extend number of 609 * variables by i. 610 * @param i number of variables to extend. 611 * @return extended solvable polynomial ring factory. 612 */ 613 @Override 614 public QuotSolvablePolynomialRing<C> extend(int i) { 615 return extend(i, false); 616 } 617 618 619 /** 620 * Extend variables. Used e.g. in module embedding. Extend number of 621 * variables by i. 622 * @param i number of variables to extend. 623 * @param top true for TOP term order, false for POT term order. 624 * @return extended solvable polynomial ring factory. 625 */ 626 @Override 627 public QuotSolvablePolynomialRing<C> extend(int i, boolean top) { 628 GenPolynomialRing<SolvableQuotient<C>> pfac = super.extend(i, top); 629 QuotSolvablePolynomialRing<C> spfac = new QuotSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 630 pfac.tord, pfac.getVars()); 631 spfac.table.extend(this.table); 632 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 633 return spfac; 634 } 635 636 637 /** 638 * Extend variables. Used e.g. in module embedding. Extend number of 639 * variables by i. 640 * @param vn names for extended variables. 641 * @return extended solvable polynomial ring factory. 642 */ 643 @Override 644 public QuotSolvablePolynomialRing<C> extend(String[] vn) { 645 return extend(vn, false); 646 } 647 648 649 /** 650 * Extend variables. Used e.g. in module embedding. Extend number of 651 * variables by i. 652 * @param vn names for extended variables. 653 * @param top true for TOP term order, false for POT term order. 654 * @return extended solvable polynomial ring factory. 655 */ 656 @Override 657 public QuotSolvablePolynomialRing<C> extend(String[] vn, boolean top) { 658 GenPolynomialRing<SolvableQuotient<C>> pfac = super.extend(vn, top); 659 QuotSolvablePolynomialRing<C> spfac = new QuotSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 660 pfac.tord, pfac.getVars()); 661 spfac.table.extend(this.table); 662 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 663 return spfac; 664 } 665 666 667 /** 668 * Contract variables. Used e.g. in module embedding. Contract number of 669 * variables by i. 670 * @param i number of variables to remove. 671 * @return contracted solvable polynomial ring factory. 672 */ 673 @Override 674 public QuotSolvablePolynomialRing<C> contract(int i) { 675 GenPolynomialRing<SolvableQuotient<C>> pfac = super.contract(i); 676 QuotSolvablePolynomialRing<C> spfac = new QuotSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 677 pfac.tord, pfac.getVars()); 678 spfac.table.contract(this.table); 679 spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable); 680 return spfac; 681 } 682 683 684 /** 685 * Reverse variables. Used e.g. in opposite rings. 686 * @return solvable polynomial ring factory with reversed variables. 687 */ 688 @Override 689 public QuotSolvablePolynomialRing<C> reverse() { 690 return reverse(false); 691 } 692 693 694 /** 695 * Reverse variables. Used e.g. in opposite rings. 696 * @param partial true for partialy reversed term orders. 697 * @return solvable polynomial ring factory with reversed variables. 698 */ 699 @Override 700 public QuotSolvablePolynomialRing<C> reverse(boolean partial) { 701 GenPolynomialRing<SolvableQuotient<C>> pfac = super.reverse(partial); 702 QuotSolvablePolynomialRing<C> spfac = new QuotSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 703 pfac.tord, pfac.getVars()); 704 spfac.partial = partial; 705 spfac.table.reverse(this.table); 706 spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable); 707 return spfac; 708 } 709 710 711 /** 712 * Rational function from integral polynomial coefficients. Represent as 713 * polynomial with type SolvableQuotient<C> coefficients. 714 * @param A polynomial with integral polynomial coefficients to be 715 * converted. 716 * @return polynomial with type SolvableQuotient<C> coefficients. 717 */ 718 public QuotSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) { 719 QuotSolvablePolynomial<C> B = getZERO().copy(); 720 if (A == null || A.isZERO()) { 721 return B; 722 } 723 RingFactory<SolvableQuotient<C>> cfac = coFac; 724 SolvableQuotientRing<C> qfac = (SolvableQuotientRing<C>) cfac; 725 for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) { 726 ExpVector e = y.getKey(); 727 GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue(); 728 SolvableQuotient<C> p = new SolvableQuotient<C>(qfac, a); // can not be zero 729 if (!p.isZERO()) { 730 //B = B.sum( p, e ); // inefficient 731 B.doPutToMap(e, p); 732 } 733 } 734 return B; 735 } 736 737 738 /** 739 * Integral function from rational polynomial coefficients. Represent as 740 * polynomial with type GenSolvablePolynomial<C> coefficients. 741 * @param A polynomial with rational polynomial coefficients to be 742 * converted. 743 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 744 */ 745 public RecSolvablePolynomial<C> toPolyCoefficients(QuotSolvablePolynomial<C> A) { 746 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 747 if (A == null || A.isZERO()) { 748 return B; 749 } 750 for (Map.Entry<ExpVector, SolvableQuotient<C>> y : A.getMap().entrySet()) { 751 ExpVector e = y.getKey(); 752 SolvableQuotient<C> a = y.getValue(); 753 if (!a.den.isONE()) { 754 throw new IllegalArgumentException("den != 1 not supported: " + a); 755 } 756 GenPolynomial<C> p = a.num; // can not be zero 757 if (!p.isZERO()) { 758 //B = B.sum( p, e ); // inefficient 759 B.doPutToMap(e, p); 760 } 761 } 762 return B; 763 } 764 765 766 /** 767 * Integral function from rational polynomial coefficients. Represent as 768 * polynomial with type GenSolvablePolynomial<C> coefficients. 769 * @param A polynomial with rational polynomial coefficients to be 770 * converted. 771 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 772 */ 773 public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableQuotient<C>> A) { 774 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 775 if (A == null || A.isZERO()) { 776 return B; 777 } 778 for (Map.Entry<ExpVector, SolvableQuotient<C>> y : A.getMap().entrySet()) { 779 ExpVector e = y.getKey(); 780 SolvableQuotient<C> a = y.getValue(); 781 if (!a.den.isONE()) { 782 throw new IllegalArgumentException("den != 1 not supported: " + a); 783 } 784 GenPolynomial<C> p = a.num; // can not be zero 785 if (!p.isZERO()) { 786 //B = B.sum( p, e ); // inefficient 787 B.doPutToMap(e, p); 788 } 789 } 790 return B; 791 } 792 793}