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