001/* 002 * $Id: ResidueSolvablePolynomialRing.java 5909 2018-08-25 19:04:06Z kredel $ 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 if (true || debug) { 379 logger.info("Xk = " + Xk + ", Xj = " + Xj + ", Xi = " + Xi); 380 logger.info("p = ( Xk * Xj ) * Xi = " + p); 381 logger.info("q = Xk * ( Xj * Xi ) = " + q); 382 } 383 return false; 384 } 385 } 386 } 387 } 388 return true; 389 } 390 391 392 /** 393 * Get a (constant) ResidueSolvablePolynomial<C> element from a long 394 * value. 395 * @param a long. 396 * @return a ResidueSolvablePolynomial<C>. 397 */ 398 @Override 399 public ResidueSolvablePolynomial<C> fromInteger(long a) { 400 return new ResidueSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 401 } 402 403 404 /** 405 * Get a (constant) ResidueSolvablePolynomial<C> element from a 406 * BigInteger value. 407 * @param a BigInteger. 408 * @return a ResidueSolvablePolynomial<C>. 409 */ 410 @Override 411 public ResidueSolvablePolynomial<C> fromInteger(BigInteger a) { 412 return new ResidueSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 413 } 414 415 416 /** 417 * Random solvable polynomial. Generates a random solvable polynomial with k 418 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 419 * @param n number of terms. 420 * @return a random solvable polynomial. 421 */ 422 @Override 423 public ResidueSolvablePolynomial<C> random(int n) { 424 return random(n, random); 425 } 426 427 428 /** 429 * Random solvable polynomial. Generates a random solvable polynomial with k 430 * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3. 431 * @param n number of terms. 432 * @param rnd is a source for random bits. 433 * @return a random solvable polynomial. 434 */ 435 @Override 436 public ResidueSolvablePolynomial<C> random(int n, Random rnd) { 437 if (nvar == 1) { 438 return random(5, n, n, 0.7f, rnd); 439 } 440 return random(5, n, 3, 0.3f, rnd); 441 } 442 443 444 /** 445 * Generate a random solvable polynomial. 446 * @param k bitsize of random coefficients. 447 * @param l number of terms. 448 * @param d maximal degree in each variable. 449 * @param q density of nozero exponents. 450 * @return a random solvable polynomial. 451 */ 452 @Override 453 public ResidueSolvablePolynomial<C> random(int k, int l, int d, float q) { 454 return random(k, l, d, q, random); 455 } 456 457 458 /** 459 * Random solvable polynomial. 460 * @param k size of random coefficients. 461 * @param l number of terms. 462 * @param d maximal degree in each variable. 463 * @param q density of nozero exponents. 464 * @param rnd is a source for random bits. 465 * @return a random solvable polynomial. 466 */ 467 @Override 468 public ResidueSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) { 469 ResidueSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 470 ExpVector e; 471 SolvableResidue<C> a; 472 // add random coeffs and exponents 473 for (int i = 0; i < l; i++) { 474 e = ExpVector.random(nvar, d, q, rnd); 475 a = coFac.random(k, rnd); 476 r = (ResidueSolvablePolynomial<C>) r.sum(a, e); 477 // somewhat inefficient but clean 478 } 479 return r; 480 } 481 482 483 /** 484 * Copy polynomial c. 485 * @param c 486 * @return a copy of c. 487 */ 488 public ResidueSolvablePolynomial<C> copy(ResidueSolvablePolynomial<C> c) { 489 return new ResidueSolvablePolynomial<C>(this, c.getMap()); 490 } 491 492 493 /** 494 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 495 * @param s String. 496 * @return ResidueSolvablePolynomial from s. 497 */ 498 @Override 499 public ResidueSolvablePolynomial<C> parse(String s) { 500 return parse(new StringReader(s)); 501 } 502 503 504 /** 505 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 506 * @param r Reader. 507 * @return next ResidueSolvablePolynomial from r. 508 */ 509 @Override 510 @SuppressWarnings("unchecked") 511 public ResidueSolvablePolynomial<C> parse(Reader r) { 512 GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r); 513 ResidueSolvablePolynomial<C> p = null; 514 try { 515 GenSolvablePolynomial<SolvableResidue<C>> s = pt.nextSolvablePolynomial(); 516 p = new ResidueSolvablePolynomial<C>(this, s); 517 } catch (IOException e) { 518 logger.error(e.toString() + " parse " + this); 519 p = ZERO; 520 } 521 return p; 522 } 523 524 525 /** 526 * Generate univariate solvable polynomial in a given variable. 527 * @param i the index of the variable. 528 * @return X_i as solvable univariate polynomial. 529 */ 530 @Override 531 public ResidueSolvablePolynomial<C> univariate(int i) { 532 return (ResidueSolvablePolynomial<C>) super.univariate(i); 533 } 534 535 536 /** 537 * Generate univariate solvable polynomial in a given variable with given 538 * exponent. 539 * @param i the index of the variable. 540 * @param e the exponent of the variable. 541 * @return X_i^e as solvable univariate polynomial. 542 */ 543 @Override 544 public ResidueSolvablePolynomial<C> univariate(int i, long e) { 545 return (ResidueSolvablePolynomial<C>) super.univariate(i, e); 546 } 547 548 549 /** 550 * Generate univariate solvable polynomial in a given variable with given 551 * exponent. 552 * @param modv number of module variables. 553 * @param i the index of the variable. 554 * @param e the exponent of the variable. 555 * @return X_i^e as solvable univariate polynomial. 556 */ 557 @Override 558 public ResidueSolvablePolynomial<C> univariate(int modv, int i, long e) { 559 return (ResidueSolvablePolynomial<C>) super.univariate(modv, i, e); 560 } 561 562 563 /** 564 * Generate list of univariate polynomials in all variables. 565 * @return List(X_1,...,X_n) a list of univariate polynomials. 566 */ 567 @Override 568 public List<ResidueSolvablePolynomial<C>> univariateList() { 569 return univariateList(0, 1L); 570 } 571 572 573 /** 574 * Generate list of univariate polynomials in all variables. 575 * @param modv number of module variables. 576 * @return List(X_1,...,X_n) a list of univariate polynomials. 577 */ 578 @Override 579 public List<ResidueSolvablePolynomial<C>> univariateList(int modv) { 580 return univariateList(modv, 1L); 581 } 582 583 584 /** 585 * Generate list of univariate polynomials in all variables with given 586 * exponent. 587 * @param modv number of module variables. 588 * @param e the exponent of the variables. 589 * @return List(X_1^e,...,X_n^e) a list of univariate polynomials. 590 */ 591 @Override 592 public List<ResidueSolvablePolynomial<C>> univariateList(int modv, long e) { 593 List<ResidueSolvablePolynomial<C>> pols = new ArrayList<ResidueSolvablePolynomial<C>>(nvar); 594 int nm = nvar - modv; 595 for (int i = 0; i < nm; i++) { 596 ResidueSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e); 597 pols.add(p); 598 } 599 return pols; 600 } 601 602 603 /** 604 * Extend variables. Used e.g. in module embedding. Extend number of 605 * variables by i. 606 * @param i number of variables to extend. 607 * @return extended solvable polynomial ring factory. 608 */ 609 @Override 610 public ResidueSolvablePolynomialRing<C> extend(int i) { 611 return extend(i, false); 612 } 613 614 615 /** 616 * Extend variables. Used e.g. in module embedding. Extend number of 617 * variables by i. 618 * @param i number of variables to extend. 619 * @param top true for TOP term order, false for POT term order. 620 * @return extended solvable polynomial ring factory. 621 */ 622 @Override 623 public ResidueSolvablePolynomialRing<C> extend(int i, boolean top) { 624 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(i, top); 625 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 626 pfac.tord, pfac.getVars()); 627 spfac.table.extend(this.table); 628 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 629 return spfac; 630 } 631 632 633 /** 634 * Extend variables. Used e.g. in module embedding. Extend number of 635 * variables by i. 636 * @param vn names for extended variables. 637 * @return extended solvable polynomial ring factory. 638 */ 639 @Override 640 public ResidueSolvablePolynomialRing<C> extend(String[] vn) { 641 return extend(vn, false); 642 } 643 644 645 /** 646 * Extend variables. Used e.g. in module embedding. Extend number of 647 * variables by i. 648 * @param vn names for extended variables. 649 * @param top true for TOP term order, false for POT term order. 650 * @return extended solvable polynomial ring factory. 651 */ 652 @Override 653 public ResidueSolvablePolynomialRing<C> extend(String[] vn, boolean top) { 654 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(vn, top); 655 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 656 pfac.tord, pfac.getVars()); 657 spfac.table.extend(this.table); 658 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 659 return spfac; 660 } 661 662 663 /** 664 * Contract variables. Used e.g. in module embedding. Contract number of 665 * variables by i. 666 * @param i number of variables to remove. 667 * @return contracted solvable polynomial ring factory. 668 */ 669 @Override 670 public ResidueSolvablePolynomialRing<C> contract(int i) { 671 GenPolynomialRing<SolvableResidue<C>> pfac = super.contract(i); 672 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 673 pfac.tord, pfac.getVars()); 674 spfac.table.contract(this.table); 675 spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable); 676 return spfac; 677 } 678 679 680 /** 681 * Reverse variables. Used e.g. in opposite rings. 682 * @return solvable polynomial ring factory with reversed variables. 683 */ 684 @Override 685 public ResidueSolvablePolynomialRing<C> reverse() { 686 return reverse(false); 687 } 688 689 690 /** 691 * Reverse variables. Used e.g. in opposite rings. 692 * @param partial true for partialy reversed term orders. 693 * @return solvable polynomial ring factory with reversed variables. 694 */ 695 @Override 696 public ResidueSolvablePolynomialRing<C> reverse(boolean partial) { 697 GenPolynomialRing<SolvableResidue<C>> pfac = super.reverse(partial); 698 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 699 pfac.tord, pfac.getVars()); 700 spfac.partial = partial; 701 spfac.table.reverse(this.table); 702 spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable); 703 return spfac; 704 } 705 706 707 /** 708 * Solvable residue coefficients from integral polynomial coefficients. 709 * Represent as polynomial with type SolvableResidue<C> coefficients. 710 * @param A polynomial with integral polynomial coefficients to be 711 * converted. 712 * @return polynomial with type SolvableResidue<C> coefficients. 713 */ 714 public ResidueSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) { 715 ResidueSolvablePolynomial<C> B = getZERO().copy(); 716 if (A == null || A.isZERO()) { 717 return B; 718 } 719 RingFactory<SolvableResidue<C>> cfac = coFac; 720 SolvableResidueRing<C> qfac = (SolvableResidueRing<C>) cfac; 721 for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) { 722 ExpVector e = y.getKey(); 723 GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue(); 724 SolvableResidue<C> p = new SolvableResidue<C>(qfac, a); // can be zero 725 if (!p.isZERO()) { 726 //B = B.sum( p, e ); // inefficient 727 B.doPutToMap(e, p); 728 } 729 } 730 return B; 731 } 732 733 734 /** 735 * Integral function from solvable residue coefficients. Represent as 736 * polynomial with type GenSolvablePolynomial<C> coefficients. 737 * @param A polynomial with solvable residue coefficients to be converted. 738 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 739 */ 740 public RecSolvablePolynomial<C> toPolyCoefficients(ResidueSolvablePolynomial<C> A) { 741 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 742 if (A == null || A.isZERO()) { 743 return B; 744 } 745 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 746 ExpVector e = y.getKey(); 747 SolvableResidue<C> a = y.getValue(); 748 GenPolynomial<C> p = a.val; // can not be zero 749 if (!p.isZERO()) { 750 //B = B.sum( p, e ); // inefficient 751 B.doPutToMap(e, p); 752 } 753 } 754 return B; 755 } 756 757 758 /** 759 * Integral function from solvable residue coefficients. Represent as 760 * polynomial with type GenSolvablePolynomial<C> coefficients. 761 * @param A polynomial with solvable residue coefficients to be converted. 762 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 763 */ 764 public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableResidue<C>> A) { 765 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 766 if (A == null || A.isZERO()) { 767 return B; 768 } 769 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 770 ExpVector e = y.getKey(); 771 SolvableResidue<C> a = y.getValue(); 772 GenPolynomial<C> p = a.val; // can not be zero 773 if (!p.isZERO()) { 774 //B = B.sum( p, e ); // inefficient 775 B.doPutToMap(e, p); 776 } 777 } 778 return B; 779 } 780 781}