001/* 002 * $Id$ 003 */ 004 005package edu.jas.application; 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 * ResidueSolvablePolynomialRing generic solvable polynomial with residue 039 * coefficients factory implementing RingFactory and extending 040 * GenSolvablePolynomialRing factory. Factory for n-variate ordered solvable 041 * polynomials over solvable residue coefficients. The non-commutative 042 * multiplication relations are maintained in a relation table and the 043 * non-commutative multiplication relations between the coefficients and the 044 * main variables are maintained in a coefficient relation table. Almost 045 * immutable object, except variable names and relation table contents. 046 * @param <C> coefficient type. 047 * @author Heinz Kredel 048 */ 049 050public class ResidueSolvablePolynomialRing<C extends GcdRingElem<C>> extends 051 GenSolvablePolynomialRing<SolvableResidue<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 ResidueSolvablePolynomial<C> ZERO; 070 071 072 /** 073 * The constant polynomial 1 for this ring. Hides super ONE. 074 */ 075 public final ResidueSolvablePolynomial<C> ONE; 076 077 078 private static final Logger logger = LogManager.getLogger(ResidueSolvablePolynomialRing.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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, 103 RelationTable<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t, 129 RelationTable<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t, String[] v, 180 RelationTable<SolvableResidue<C>> rt) { 181 super(cf, n, t, v, rt); 182 //if (rt == null) { // handled in super } 183 SolvableResidueRing<C> cfring = (SolvableResidueRing<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 ResidueSolvablePolynomial<C>(this); 193 SolvableResidue<C> coeff = coFac.getONE(); 194 //evzero = ExpVector.create(nvar); // from super 195 ONE = new ResidueSolvablePolynomial<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 ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, ResidueSolvablePolynomialRing o) { 208 this(cf, o.nvar, o.tord, o.getVars(), null); 209 } 210 211 212 /** 213 * Get the String representation. 214 * @see java.lang.Object#toString() 215 */ 216 @Override 217 public String toString() { 218 String res = super.toString(); 219 if (PrettyPrint.isTrue()) { 220 //res += "\n" + table.toString(vars); 221 res += "\n" + polCoeff.coeffTable.toString(vars); 222 } else { 223 res += ", #rel = " + table.size() + " + " + polCoeff.coeffTable.size(); 224 } 225 return res; 226 } 227 228 229 /** 230 * Get a scripting compatible string representation. 231 * @return script compatible representation for this Element. 232 * @see edu.jas.structure.Element#toScript() 233 */ 234 @Override 235 public String toScript() { 236 StringBuffer s = new StringBuffer(); 237 switch (Scripting.getLang()) { 238 case Ruby: 239 s.append("SolvPolyRing.new("); 240 break; 241 case Python: 242 default: 243 s.append("SolvPolyRing("); 244 } 245 if (coFac instanceof RingElem) { 246 s.append(((RingElem<SolvableResidue<C>>) coFac).toScriptFactory()); 247 } else { 248 s.append(coFac.toScript().trim()); 249 } 250 s.append(",\"" + varsToString() + "\","); 251 String to = tord.toScript(); 252 s.append(to); 253 if (table.size() > 0) { 254 String rel = table.toScript(); 255 s.append(",rel="); 256 s.append(rel); 257 } 258 if (polCoeff.coeffTable.size() > 0) { 259 String rel = polCoeff.coeffTable.toScript(); 260 s.append(",coeffrel="); 261 s.append(rel); 262 } 263 s.append(")"); 264 return s.toString(); 265 } 266 267 268 /** 269 * Comparison with any other object. 270 * @see java.lang.Object#equals(java.lang.Object) 271 */ 272 @Override 273 @SuppressWarnings("unchecked") 274 public boolean equals(Object other) { 275 if (!(other instanceof ResidueSolvablePolynomialRing)) { 276 return false; 277 } 278 ResidueSolvablePolynomialRing<C> oring = null; 279 try { 280 oring = (ResidueSolvablePolynomialRing<C>) other; 281 } catch (ClassCastException ignored) { 282 } 283 if (oring == null) { 284 return false; 285 } 286 // do a super.equals( ) 287 if (!super.equals(other)) { 288 return false; 289 } 290 // check same base relations 291 //if ( ! table.equals(oring.table) ) { // done in super 292 // return false; 293 //} 294 if (!polCoeff.coeffTable.equals(oring.polCoeff.coeffTable)) { 295 return false; 296 } 297 return true; 298 } 299 300 301 /** 302 * Hash code for this polynomial ring. 303 * @see java.lang.Object#hashCode() 304 */ 305 @Override 306 public int hashCode() { 307 int h; 308 h = super.hashCode(); 309 h = 37 * h + table.hashCode(); // may be different after some computations 310 h = 37 * h + polCoeff.coeffTable.hashCode(); // may be different 311 return h; 312 } 313 314 315 /** 316 * Get the zero element. 317 * @return 0 as ResidueSolvablePolynomial<C>. 318 */ 319 @Override 320 public ResidueSolvablePolynomial<C> getZERO() { 321 return ZERO; 322 } 323 324 325 /** 326 * Get the one element. 327 * @return 1 as ResidueSolvablePolynomial<C>. 328 */ 329 @Override 330 public ResidueSolvablePolynomial<C> getONE() { 331 return ONE; 332 } 333 334 335 /** 336 * Query if this ring is commutative. 337 * @return true if this ring is commutative, else false. 338 */ 339 @Override 340 public boolean isCommutative() { 341 if (polCoeff.coeffTable.size() == 0) { 342 return super.isCommutative(); 343 } 344 // check structure of relations? 345 return false; 346 } 347 348 349 /** 350 * Query if this ring is associative. Test if the relations between the mian 351 * variables and the coefficient generators define an associative solvable 352 * ring. 353 * @return true, if this ring is associative, else false. 354 */ 355 @SuppressWarnings("unused") 356 @Override 357 public boolean isAssociative() { 358 if (!coFac.isAssociative()) { 359 return false; 360 } 361 //System.out.println("polCoeff = " + polCoeff.toScript()); 362 if (!polCoeff.isAssociative()) { // not done via generators?? 363 return false; 364 } 365 ResidueSolvablePolynomial<C> Xi, Xj, Xk, p, q; 366 List<GenPolynomial<SolvableResidue<C>>> gens = generators(); 367 //System.out.println("Residu gens = " + gens); 368 int ngen = gens.size(); 369 for (int i = 0; i < ngen; i++) { 370 Xi = (ResidueSolvablePolynomial<C>) gens.get(i); 371 for (int j = i + 1; j < ngen; j++) { 372 Xj = (ResidueSolvablePolynomial<C>) gens.get(j); 373 for (int k = j + 1; k < ngen; k++) { 374 Xk = (ResidueSolvablePolynomial<C>) gens.get(k); 375 p = Xk.multiply(Xj).multiply(Xi); 376 q = Xk.multiply(Xj.multiply(Xi)); 377 if (!p.equals(q)) { 378 logger.info("Xk = {}, Xj = {}, Xi = {}", Xk, Xj, Xi); 379 logger.info("p = ( Xk * Xj ) * Xi = {}", p); 380 logger.info("q = Xk * ( Xj * Xi ) = {}", q); 381 return false; 382 } 383 } 384 } 385 } 386 return true; 387 } 388 389 390 /** 391 * Get a (constant) ResidueSolvablePolynomial<C> element from a long 392 * value. 393 * @param a long. 394 * @return a ResidueSolvablePolynomial<C>. 395 */ 396 @Override 397 public ResidueSolvablePolynomial<C> fromInteger(long a) { 398 return new ResidueSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 399 } 400 401 402 /** 403 * Get a (constant) ResidueSolvablePolynomial<C> element from a 404 * BigInteger value. 405 * @param a BigInteger. 406 * @return a ResidueSolvablePolynomial<C>. 407 */ 408 @Override 409 public ResidueSolvablePolynomial<C> fromInteger(BigInteger a) { 410 return new ResidueSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 411 } 412 413 414 /** 415 * Random solvable polynomial. Generates a random solvable polynomial with k 416 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 417 * @param n number of terms. 418 * @return a random solvable polynomial. 419 */ 420 @Override 421 public ResidueSolvablePolynomial<C> random(int n) { 422 return random(n, random); 423 } 424 425 426 /** 427 * Random solvable polynomial. Generates a random solvable polynomial with k 428 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 429 * @param n number of terms. 430 * @param rnd is a source for random bits. 431 * @return a random solvable polynomial. 432 */ 433 @Override 434 public ResidueSolvablePolynomial<C> random(int n, Random rnd) { 435 if (nvar == 1) { 436 return random(5, n, n, 0.7f, rnd); 437 } 438 return random(5, n, 3, 0.3f, rnd); 439 } 440 441 442 /** 443 * Generate a random solvable polynomial. 444 * @param k bitsize of random coefficients. 445 * @param l number of terms. 446 * @param d maximal degree in each variable. 447 * @param q density of nozero exponents. 448 * @return a random solvable polynomial. 449 */ 450 @Override 451 public ResidueSolvablePolynomial<C> random(int k, int l, int d, float q) { 452 return random(k, l, d, q, random); 453 } 454 455 456 /** 457 * Random solvable polynomial. 458 * @param k size of random coefficients. 459 * @param l number of terms. 460 * @param d maximal degree in each variable. 461 * @param q density of nozero exponents. 462 * @param rnd is a source for random bits. 463 * @return a random solvable polynomial. 464 */ 465 @Override 466 public ResidueSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) { 467 ResidueSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 468 ExpVector e; 469 SolvableResidue<C> a; 470 // add random coeffs and exponents 471 for (int i = 0; i < l; i++) { 472 e = ExpVector.random(nvar, d, q, rnd); 473 a = coFac.random(k, rnd); 474 r = (ResidueSolvablePolynomial<C>) r.sum(a, e); 475 // somewhat inefficient but clean 476 } 477 return r; 478 } 479 480 481 /** 482 * Copy polynomial c. 483 * @param c 484 * @return a copy of c. 485 */ 486 public ResidueSolvablePolynomial<C> copy(ResidueSolvablePolynomial<C> c) { 487 return new ResidueSolvablePolynomial<C>(this, c.getMap()); 488 } 489 490 491 /** 492 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 493 * @param s String. 494 * @return ResidueSolvablePolynomial from s. 495 */ 496 @Override 497 public ResidueSolvablePolynomial<C> parse(String s) { 498 return parse(new StringReader(s)); 499 } 500 501 502 /** 503 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 504 * @param r Reader. 505 * @return next ResidueSolvablePolynomial from r. 506 */ 507 @Override 508 @SuppressWarnings("unchecked") 509 public ResidueSolvablePolynomial<C> parse(Reader r) { 510 GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r); 511 ResidueSolvablePolynomial<C> p = null; 512 try { 513 GenSolvablePolynomial<SolvableResidue<C>> s = pt.nextSolvablePolynomial(); 514 p = new ResidueSolvablePolynomial<C>(this, s); 515 } catch (IOException e) { 516 logger.error("{} parse {}", e, this); 517 p = ZERO; 518 } 519 return p; 520 } 521 522 523 /** 524 * Generate univariate solvable polynomial in a given variable. 525 * @param i the index of the variable. 526 * @return X_i as solvable univariate polynomial. 527 */ 528 @Override 529 public ResidueSolvablePolynomial<C> univariate(int i) { 530 return (ResidueSolvablePolynomial<C>) super.univariate(i); 531 } 532 533 534 /** 535 * Generate univariate solvable polynomial in a given variable with given 536 * exponent. 537 * @param i the index of the variable. 538 * @param e the exponent of the variable. 539 * @return X_i^e as solvable univariate polynomial. 540 */ 541 @Override 542 public ResidueSolvablePolynomial<C> univariate(int i, long e) { 543 return (ResidueSolvablePolynomial<C>) super.univariate(i, e); 544 } 545 546 547 /** 548 * Generate univariate solvable polynomial in a given variable with given 549 * exponent. 550 * @param modv number of module variables. 551 * @param i the index of the variable. 552 * @param e the exponent of the variable. 553 * @return X_i^e as solvable univariate polynomial. 554 */ 555 @Override 556 public ResidueSolvablePolynomial<C> univariate(int modv, int i, long e) { 557 return (ResidueSolvablePolynomial<C>) super.univariate(modv, i, e); 558 } 559 560 561 /** 562 * Generate list of univariate polynomials in all variables. 563 * @return List(X_1,...,X_n) a list of univariate polynomials. 564 */ 565 @Override 566 public List<ResidueSolvablePolynomial<C>> univariateList() { 567 return univariateList(0, 1L); 568 } 569 570 571 /** 572 * Generate list of univariate polynomials in all variables. 573 * @param modv number of module variables. 574 * @return List(X_1,...,X_n) a list of univariate polynomials. 575 */ 576 @Override 577 public List<ResidueSolvablePolynomial<C>> univariateList(int modv) { 578 return univariateList(modv, 1L); 579 } 580 581 582 /** 583 * Generate list of univariate polynomials in all variables with given 584 * exponent. 585 * @param modv number of module variables. 586 * @param e the exponent of the variables. 587 * @return List(X_1^e,...,X_n^e) a list of univariate polynomials. 588 */ 589 @Override 590 public List<ResidueSolvablePolynomial<C>> univariateList(int modv, long e) { 591 List<ResidueSolvablePolynomial<C>> pols = new ArrayList<ResidueSolvablePolynomial<C>>(nvar); 592 int nm = nvar - modv; 593 for (int i = 0; i < nm; i++) { 594 ResidueSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e); 595 pols.add(p); 596 } 597 return pols; 598 } 599 600 601 /** 602 * Extend variables. Used e.g. in module embedding. Extend number of 603 * variables by i. 604 * @param i number of variables to extend. 605 * @return extended solvable polynomial ring factory. 606 */ 607 @Override 608 public ResidueSolvablePolynomialRing<C> extend(int i) { 609 return extend(i, false); 610 } 611 612 613 /** 614 * Extend variables. Used e.g. in module embedding. Extend number of 615 * variables by i. 616 * @param i number of variables to extend. 617 * @param top true for TOP term order, false for POT term order. 618 * @return extended solvable polynomial ring factory. 619 */ 620 @Override 621 public ResidueSolvablePolynomialRing<C> extend(int i, boolean top) { 622 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(i, top); 623 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 624 pfac.tord, pfac.getVars()); 625 spfac.table.extend(this.table); 626 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 627 return spfac; 628 } 629 630 631 /** 632 * Extend variables. Used e.g. in module embedding. Extend number of 633 * variables by i. 634 * @param vn names for extended variables. 635 * @return extended solvable polynomial ring factory. 636 */ 637 @Override 638 public ResidueSolvablePolynomialRing<C> extend(String[] vn) { 639 return extend(vn, false); 640 } 641 642 643 /** 644 * Extend variables. Used e.g. in module embedding. Extend number of 645 * variables by i. 646 * @param vn names for extended variables. 647 * @param top true for TOP term order, false for POT term order. 648 * @return extended solvable polynomial ring factory. 649 */ 650 @Override 651 public ResidueSolvablePolynomialRing<C> extend(String[] vn, boolean top) { 652 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(vn, top); 653 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 654 pfac.tord, pfac.getVars()); 655 spfac.table.extend(this.table); 656 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 657 return spfac; 658 } 659 660 661 /** 662 * Contract variables. Used e.g. in module embedding. Contract number of 663 * variables by i. 664 * @param i number of variables to remove. 665 * @return contracted solvable polynomial ring factory. 666 */ 667 @Override 668 public ResidueSolvablePolynomialRing<C> contract(int i) { 669 GenPolynomialRing<SolvableResidue<C>> pfac = super.contract(i); 670 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 671 pfac.tord, pfac.getVars()); 672 spfac.table.contract(this.table); 673 spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable); 674 return spfac; 675 } 676 677 678 /** 679 * Reverse variables. Used e.g. in opposite rings. 680 * @return solvable polynomial ring factory with reversed variables. 681 */ 682 @Override 683 public ResidueSolvablePolynomialRing<C> reverse() { 684 return reverse(false); 685 } 686 687 688 /** 689 * Reverse variables. Used e.g. in opposite rings. 690 * @param partial true for partialy reversed term orders. 691 * @return solvable polynomial ring factory with reversed variables. 692 */ 693 @Override 694 public ResidueSolvablePolynomialRing<C> reverse(boolean partial) { 695 GenPolynomialRing<SolvableResidue<C>> pfac = super.reverse(partial); 696 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 697 pfac.tord, pfac.getVars()); 698 spfac.partial = partial; 699 spfac.table.reverse(this.table); 700 spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable); 701 return spfac; 702 } 703 704 705 /** 706 * Solvable residue coefficients from integral polynomial coefficients. 707 * Represent as polynomial with type SolvableResidue<C> coefficients. 708 * @param A polynomial with integral polynomial coefficients to be 709 * converted. 710 * @return polynomial with type SolvableResidue<C> coefficients. 711 */ 712 public ResidueSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) { 713 ResidueSolvablePolynomial<C> B = getZERO().copy(); 714 if (A == null || A.isZERO()) { 715 return B; 716 } 717 RingFactory<SolvableResidue<C>> cfac = coFac; 718 SolvableResidueRing<C> qfac = (SolvableResidueRing<C>) cfac; 719 for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) { 720 ExpVector e = y.getKey(); 721 GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue(); 722 SolvableResidue<C> p = new SolvableResidue<C>(qfac, a); // can be zero 723 if (!p.isZERO()) { 724 //B = B.sum( p, e ); // inefficient 725 B.doPutToMap(e, p); 726 } 727 } 728 return B; 729 } 730 731 732 /** 733 * Integral function from solvable residue coefficients. Represent as 734 * polynomial with type GenSolvablePolynomial<C> coefficients. 735 * @param A polynomial with solvable residue coefficients to be converted. 736 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 737 */ 738 public RecSolvablePolynomial<C> toPolyCoefficients(ResidueSolvablePolynomial<C> A) { 739 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 740 if (A == null || A.isZERO()) { 741 return B; 742 } 743 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 744 ExpVector e = y.getKey(); 745 SolvableResidue<C> a = y.getValue(); 746 GenPolynomial<C> p = a.val; // can not be zero 747 if (!p.isZERO()) { 748 //B = B.sum( p, e ); // inefficient 749 B.doPutToMap(e, p); 750 } 751 } 752 return B; 753 } 754 755 756 /** 757 * Integral function from solvable residue coefficients. Represent as 758 * polynomial with type GenSolvablePolynomial<C> coefficients. 759 * @param A polynomial with solvable residue coefficients to be converted. 760 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 761 */ 762 public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableResidue<C>> A) { 763 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 764 if (A == null || A.isZERO()) { 765 return B; 766 } 767 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 768 ExpVector e = y.getKey(); 769 SolvableResidue<C> a = y.getValue(); 770 GenPolynomial<C> p = a.val; // can not be zero 771 if (!p.isZERO()) { 772 //B = B.sum( p, e ); // inefficient 773 B.doPutToMap(e, p); 774 } 775 } 776 return B; 777 } 778 779}