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