001/* 002 * $Id: ResidueSolvablePolynomialRing.java 5290 2015-08-01 17:32:00Z 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.log4j.Logger; 018 019import edu.jas.kern.PrettyPrint; 020import edu.jas.kern.Scripting; 021import edu.jas.poly.ExpVector; 022import edu.jas.poly.GenPolynomial; 023import edu.jas.poly.GenPolynomialRing; 024import edu.jas.poly.GenPolynomialTokenizer; 025import edu.jas.poly.GenSolvablePolynomial; 026import edu.jas.poly.GenSolvablePolynomialRing; 027import edu.jas.poly.RecSolvablePolynomial; 028import edu.jas.poly.RecSolvablePolynomialRing; 029import edu.jas.poly.RelationTable; 030import edu.jas.poly.TermOrder; 031import edu.jas.structure.GcdRingElem; 032import edu.jas.structure.RingElem; 033import edu.jas.structure.RingFactory; 034 035 036/** 037 * ResidueSolvablePolynomialRing generic solvable polynomial with residue 038 * coefficients factory implementing RingFactory and extending 039 * GenSolvablePolynomialRing factory. Factory for n-variate ordered solvable 040 * polynomials over solvable residue coefficients. The non-commutative 041 * multiplication relations are maintained in a relation table and the 042 * non-commutative multiplication relations between the coefficients and the 043 * main variables are maintained in a coefficient relation table. Almost 044 * immutable object, except variable names and relation table contents. 045 * @param <C> coefficient type. 046 * @author Heinz Kredel 047 */ 048 049public class ResidueSolvablePolynomialRing<C extends GcdRingElem<C>> extends 050 GenSolvablePolynomialRing<SolvableResidue<C>> { 051 052 053 /* 054 * The solvable multiplication relations between variables and coefficients. 055 */ 056 //public final RelationTable<GenPolynomial<C>> coeffTable; 057 058 059 /** 060 * Recursive solvable polynomial ring with polynomial coefficients. 061 */ 062 public final RecSolvablePolynomialRing<C> polCoeff; 063 064 065 /** 066 * The constant polynomial 0 for this ring. Hides super ZERO. 067 */ 068 public final ResidueSolvablePolynomial<C> ZERO; 069 070 071 /** 072 * The constant polynomial 1 for this ring. Hides super ONE. 073 */ 074 public final ResidueSolvablePolynomial<C> ONE; 075 076 077 private static final Logger logger = Logger.getLogger(ResidueSolvablePolynomialRing.class); 078 079 080 private final boolean debug = logger.isDebugEnabled(); 081 082 083 /** 084 * The constructor creates a solvable polynomial factory object with the 085 * default term order and commutative relations. 086 * @param cf factory for coefficients of type C. 087 * @param n number of variables. 088 */ 089 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n) { 090 this(cf, n, new TermOrder(), null, null); 091 } 092 093 094 /** 095 * The constructor creates a solvable polynomial factory object with the 096 * default term order. 097 * @param cf factory for coefficients of type C. 098 * @param n number of variables. 099 * @param rt solvable multiplication relations. 100 */ 101 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, 102 RelationTable<SolvableResidue<C>> rt) { 103 this(cf, n, new TermOrder(), null, rt); 104 } 105 106 107 /** 108 * The constructor creates a solvable polynomial factory object with the 109 * given term order and commutative relations. 110 * @param cf factory for coefficients of type C. 111 * @param n number of variables. 112 * @param t a term order. 113 */ 114 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t) { 115 this(cf, n, t, null, null); 116 } 117 118 119 /** 120 * The constructor creates a solvable polynomial factory object with the 121 * given term order. 122 * @param cf factory for coefficients of type C. 123 * @param n number of variables. 124 * @param t a term order. 125 * @param rt solvable multiplication relations. 126 */ 127 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t, 128 RelationTable<SolvableResidue<C>> rt) { 129 this(cf, n, t, null, rt); 130 } 131 132 133 /** 134 * The constructor creates a solvable polynomial factory object with the 135 * given term order and commutative relations. 136 * @param cf factory for coefficients of type C. 137 * @param n number of variables. 138 * @param t a term order. 139 * @param v names for the variables. 140 */ 141 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t, String[] v) { 142 this(cf, n, t, v, null); 143 } 144 145 146 /** 147 * The constructor creates a solvable polynomial factory object with the 148 * given term order and commutative relations. 149 * @param cf factory for coefficients of type C. 150 * @param t a term order. 151 * @param v names for the variables. 152 */ 153 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, TermOrder t, String[] v) { 154 this(cf, v.length, t, v, null); 155 } 156 157 158 /** 159 * The constructor creates a solvable polynomial factory object with the 160 * default term order. 161 * @param cf factory for coefficients of type C. 162 * @param v names for the variables. 163 */ 164 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, String[] v) { 165 this(cf, v.length, new TermOrder(), v, null); 166 } 167 168 169 /** 170 * The constructor creates a solvable polynomial factory object with the 171 * given term order. 172 * @param cf factory for coefficients of type C. 173 * @param n number of variables. 174 * @param t a term order. 175 * @param v names for the variables. 176 * @param rt solvable multiplication relations. 177 */ 178 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, int n, TermOrder t, String[] v, 179 RelationTable<SolvableResidue<C>> rt) { 180 super(cf, n, t, v, rt); 181 //if (rt == null) { // handled in super } 182 SolvableResidueRing<C> cfring = (SolvableResidueRing<C>) cf; // == coFac 183 polCoeff = new RecSolvablePolynomialRing<C>(cfring.ring, n, t, v); 184 if (table.size() > 0) { // TODO 185 ExpVector e = null; 186 ExpVector f = null; 187 GenSolvablePolynomial<GenPolynomial<C>> p = null; 188 polCoeff.table.update(e, f, p); // from rt 189 } 190 //coeffTable = polCoeff.coeffTable; //new RelationTable<GenPolynomial<C>>(polCoeff, true); 191 ZERO = new ResidueSolvablePolynomial<C>(this); 192 SolvableResidue<C> coeff = coFac.getONE(); 193 //evzero = ExpVector.create(nvar); // from super 194 ONE = new ResidueSolvablePolynomial<C>(this, coeff, evzero); 195 } 196 197 198 /** 199 * The constructor creates a solvable polynomial factory object with the the 200 * same term order, number of variables and variable names as the given 201 * polynomial factory, only the coefficient factories differ and the 202 * solvable multiplication relations are <b>empty</b>. 203 * @param cf factory for coefficients of type C. 204 * @param o other solvable polynomial ring. 205 */ 206 public ResidueSolvablePolynomialRing(RingFactory<SolvableResidue<C>> cf, ResidueSolvablePolynomialRing o) { 207 this(cf, o.nvar, o.tord, o.getVars(), null); 208 } 209 210 211 /** 212 * Get the String representation. 213 * @see java.lang.Object#toString() 214 */ 215 @Override 216 public String toString() { 217 String res = super.toString(); 218 if (PrettyPrint.isTrue()) { 219 //res += "\n" + table.toString(vars); 220 res += "\n" + polCoeff.coeffTable.toString(vars); 221 } else { 222 res += ", #rel = " + table.size() + " + " + polCoeff.coeffTable.size(); 223 } 224 return res; 225 } 226 227 228 /** 229 * Get a scripting compatible string representation. 230 * @return script compatible representation for this Element. 231 * @see edu.jas.structure.Element#toScript() 232 */ 233 @Override 234 public String toScript() { 235 StringBuffer s = new StringBuffer(); 236 switch (Scripting.getLang()) { 237 case Ruby: 238 s.append("SolvPolyRing.new("); 239 break; 240 case Python: 241 default: 242 s.append("SolvPolyRing("); 243 } 244 if (coFac instanceof RingElem) { 245 s.append(((RingElem<SolvableResidue<C>>) coFac).toScriptFactory()); 246 } else { 247 s.append(coFac.toScript().trim()); 248 } 249 s.append(",\"" + varsToString() + "\","); 250 String to = tord.toString(); 251 if (tord.getEvord() == TermOrder.INVLEX) { 252 to = "PolyRing.lex"; 253 } 254 if (tord.getEvord() == TermOrder.IGRLEX) { 255 to = "PolyRing.grad"; 256 } 257 s.append(to); 258 if (table.size() > 0) { 259 String rel = table.toScript(); 260 s.append(",rel="); 261 s.append(rel); 262 } 263 if (polCoeff.coeffTable.size() > 0) { 264 String rel = polCoeff.coeffTable.toScript(); 265 s.append(",coeffrel="); 266 s.append(rel); 267 } 268 s.append(")"); 269 return s.toString(); 270 } 271 272 273 /** 274 * Comparison with any other object. 275 * @see java.lang.Object#equals(java.lang.Object) 276 */ 277 @Override 278 @SuppressWarnings("unchecked") 279 public boolean equals(Object other) { 280 if (!(other instanceof ResidueSolvablePolynomialRing)) { 281 return false; 282 } 283 ResidueSolvablePolynomialRing<C> oring = null; 284 try { 285 oring = (ResidueSolvablePolynomialRing<C>) other; 286 } catch (ClassCastException ignored) { 287 } 288 if (oring == null) { 289 return false; 290 } 291 // do a super.equals( ) 292 if (!super.equals(other)) { 293 return false; 294 } 295 // check same base relations 296 //if ( ! table.equals(oring.table) ) { // done in super 297 // return false; 298 //} 299 if (!polCoeff.coeffTable.equals(oring.polCoeff.coeffTable)) { 300 return false; 301 } 302 return true; 303 } 304 305 306 /** 307 * Hash code for this polynomial ring. 308 * @see java.lang.Object#hashCode() 309 */ 310 @Override 311 public int hashCode() { 312 int h; 313 h = super.hashCode(); 314 h = 37 * h + table.hashCode(); // may be different after some computations 315 h = 37 * h + polCoeff.coeffTable.hashCode(); // may be different 316 return h; 317 } 318 319 320 /** 321 * Get the zero element. 322 * @return 0 as ResidueSolvablePolynomial<C>. 323 */ 324 @Override 325 public ResidueSolvablePolynomial<C> getZERO() { 326 return ZERO; 327 } 328 329 330 /** 331 * Get the one element. 332 * @return 1 as ResidueSolvablePolynomial<C>. 333 */ 334 @Override 335 public ResidueSolvablePolynomial<C> getONE() { 336 return ONE; 337 } 338 339 340 /** 341 * Query if this ring is commutative. 342 * @return true if this ring is commutative, else false. 343 */ 344 @Override 345 public boolean isCommutative() { 346 if (polCoeff.coeffTable.size() == 0) { 347 return super.isCommutative(); 348 } 349 // todo: check structure of relations 350 return false; 351 } 352 353 354 /** 355 * Query if this ring is associative. Test if the relations between the mian 356 * variables and the coefficient generators define an associative solvable 357 * ring. 358 * @return true, if this ring is associative, else false. 359 */ 360 @SuppressWarnings("unused") 361 @Override 362 public boolean isAssociative() { 363 if (!coFac.isAssociative()) { 364 return false; 365 } 366 //System.out.println("polCoeff = " + polCoeff.toScript()); 367 if (!polCoeff.isAssociative()) { // not done via generators?? 368 return false; 369 } 370 ResidueSolvablePolynomial<C> Xi, Xj, Xk, p, q; 371 List<GenPolynomial<SolvableResidue<C>>> gens = generators(); 372 //System.out.println("Residu gens = " + gens); 373 int ngen = gens.size(); 374 for (int i = 0; i < ngen; i++) { 375 Xi = (ResidueSolvablePolynomial<C>) gens.get(i); 376 for (int j = i + 1; j < ngen; j++) { 377 Xj = (ResidueSolvablePolynomial<C>) gens.get(j); 378 for (int k = j + 1; k < ngen; k++) { 379 Xk = (ResidueSolvablePolynomial<C>) gens.get(k); 380 p = Xk.multiply(Xj).multiply(Xi); 381 q = Xk.multiply(Xj.multiply(Xi)); 382 if (!p.equals(q)) { 383 if (true || debug) { 384 logger.info("Xk = " + Xk + ", Xj = " + Xj + ", Xi = " + Xi); 385 logger.info("p = ( Xk * Xj ) * Xi = " + p); 386 logger.info("q = Xk * ( Xj * Xi ) = " + q); 387 } 388 return false; 389 } 390 } 391 } 392 } 393 return true; 394 } 395 396 397 /** 398 * Get a (constant) ResidueSolvablePolynomial<C> element from a long 399 * value. 400 * @param a long. 401 * @return a ResidueSolvablePolynomial<C>. 402 */ 403 @Override 404 public ResidueSolvablePolynomial<C> fromInteger(long a) { 405 return new ResidueSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero); 406 } 407 408 409 /** 410 * Get a (constant) ResidueSolvablePolynomial<C> element from a 411 * BigInteger value. 412 * @param a BigInteger. 413 * @return a ResidueSolvablePolynomial<C>. 414 */ 415 @Override 416 public ResidueSolvablePolynomial<C> fromInteger(BigInteger a) { 417 return new ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) { 474 ResidueSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 475 ExpVector e; 476 SolvableResidue<C> a; 477 // add random coeffs and exponents 478 for (int i = 0; i < l; i++) { 479 e = ExpVector.EVRAND(nvar, d, q, rnd); 480 a = coFac.random(k, rnd); 481 r = (ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<C> copy(ResidueSolvablePolynomial<C> c) { 494 return new ResidueSolvablePolynomial<C>(this, c.getMap()); 495 } 496 497 498 /** 499 * Parse a solvable polynomial with the use of GenPolynomialTokenizer 500 * @param s String. 501 * @return ResidueSolvablePolynomial from s. 502 */ 503 @Override 504 public ResidueSolvablePolynomial<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 ResidueSolvablePolynomial from r. 513 */ 514 @Override 515 @SuppressWarnings("unchecked") 516 public ResidueSolvablePolynomial<C> parse(Reader r) { 517 GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r); 518 ResidueSolvablePolynomial<C> p = null; 519 try { 520 GenSolvablePolynomial<SolvableResidue<C>> s = pt.nextSolvablePolynomial(); 521 p = new ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<C> univariate(int i) { 537 return (ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<C> univariate(int i, long e) { 550 return (ResidueSolvablePolynomial<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 ResidueSolvablePolynomial<C> univariate(int modv, int i, long e) { 564 return (ResidueSolvablePolynomial<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 //todo Override 573 @SuppressWarnings("unchecked") 574 public List<ResidueSolvablePolynomial<C>> recUnivariateList() { 575 //return castToSolvableList( super.univariateList() ); 576 return (List<ResidueSolvablePolynomial<C>>) (Object) univariateList(0, 1L); 577 } 578 579 580 /** 581 * Generate list of univariate polynomials in all variables. 582 * @param modv number of module variables. 583 * @return List(X_1,...,X_n) a list of univariate polynomials. 584 */ 585 //todo Override 586 @SuppressWarnings("unchecked") 587 public List<ResidueSolvablePolynomial<C>> recUnivariateList(int modv) { 588 return (List<ResidueSolvablePolynomial<C>>) (Object) univariateList(modv, 1L); 589 } 590 591 592 /** 593 * Generate list of univariate polynomials in all variables with given 594 * exponent. 595 * @param modv number of module variables. 596 * @param e the exponent of the variables. 597 * @return List(X_1^e,...,X_n^e) a list of univariate polynomials. 598 */ 599 //todo Override 600 public List<ResidueSolvablePolynomial<C>> recUnivariateList(int modv, long e) { 601 List<ResidueSolvablePolynomial<C>> pols = new ArrayList<ResidueSolvablePolynomial<C>>(nvar); 602 int nm = nvar - modv; 603 for (int i = 0; i < nm; i++) { 604 ResidueSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e); 605 pols.add(p); 606 } 607 return pols; 608 } 609 610 611 /* 612 * Generate list of univariate polynomials in all variables with given exponent. 613 * @param modv number of module variables. 614 * @param e the exponent of the variables. 615 * @return List(X_1^e,...,X_n^e) a list of univariate polynomials. 616 @Override 617 public List<ResidueSolvablePolynomial<C>> univariateList(int modv, long e) { 618 List<GenPolynomial<C>> pol = super.univariateList(modv,e); 619 UnaryFunctor<GenPolynomial<C>,ResidueSolvablePolynomial<C>> fc 620 = new UnaryFunctor<GenPolynomial<C>,ResidueSolvablePolynomial<C>>() { 621 public ResidueSolvablePolynomial<C> eval(GenPolynomial<C> p) { 622 if ( ! (p instanceof ResidueSolvablePolynomial) ) { 623 throw new RuntimeException("no solvable polynomial "+p); 624 } 625 return (ResidueSolvablePolynomial<C>) p; 626 } 627 }; 628 List<ResidueSolvablePolynomial<C>> pols 629 = ListUtil.<GenPolynomial<C>,ResidueSolvablePolynomial<C>>map(this,pol,fc); 630 return pols; 631 } 632 */ 633 634 635 /** 636 * Extend variables. Used e.g. in module embedding. Extend number of 637 * variables by i. 638 * @param i number of variables to extend. 639 * @return extended solvable polynomial ring factory. 640 */ 641 @Override 642 public ResidueSolvablePolynomialRing<C> extend(int i) { 643 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(i); 644 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 645 pfac.tord, pfac.getVars()); 646 spfac.table.extend(this.table); 647 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 648 return spfac; 649 } 650 651 652 /** 653 * Extend variables. Used e.g. in module embedding. Extend number of 654 * variables by i. 655 * @param vs names for extended variables. 656 * @return extended solvable polynomial ring factory. 657 */ 658 @Override 659 public ResidueSolvablePolynomialRing<C> extend(String[] vs) { 660 GenPolynomialRing<SolvableResidue<C>> pfac = super.extend(vs); 661 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 662 pfac.tord, pfac.getVars()); 663 spfac.table.extend(this.table); 664 spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable); 665 return spfac; 666 } 667 668 669 /** 670 * Contract variables. Used e.g. in module embedding. Contract number of 671 * variables by i. 672 * @param i number of variables to remove. 673 * @return contracted solvable polynomial ring factory. 674 */ 675 @Override 676 public ResidueSolvablePolynomialRing<C> contract(int i) { 677 GenPolynomialRing<SolvableResidue<C>> pfac = super.contract(i); 678 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 679 pfac.tord, pfac.getVars()); 680 spfac.table.contract(this.table); 681 spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable); 682 return spfac; 683 } 684 685 686 /** 687 * Reverse variables. Used e.g. in opposite rings. 688 * @return solvable polynomial ring factory with reversed variables. 689 */ 690 @Override 691 public ResidueSolvablePolynomialRing<C> reverse() { 692 return reverse(false); 693 } 694 695 696 /** 697 * Reverse variables. Used e.g. in opposite rings. 698 * @param partial true for partialy reversed term orders. 699 * @return solvable polynomial ring factory with reversed variables. 700 */ 701 @Override 702 public ResidueSolvablePolynomialRing<C> reverse(boolean partial) { 703 GenPolynomialRing<SolvableResidue<C>> pfac = super.reverse(partial); 704 ResidueSolvablePolynomialRing<C> spfac = new ResidueSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar, 705 pfac.tord, pfac.getVars()); 706 spfac.partial = partial; 707 spfac.table.reverse(this.table); 708 spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable); 709 return spfac; 710 } 711 712 713 /** 714 * Solvable residue coefficients from integral polynomial coefficients. 715 * Represent as polynomial with type SolvableResidue<C> coefficients. 716 * @param A polynomial with integral polynomial coefficients to be 717 * converted. 718 * @return polynomial with type SolvableResidue<C> coefficients. 719 */ 720 public ResidueSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) { 721 ResidueSolvablePolynomial<C> B = getZERO().copy(); 722 if (A == null || A.isZERO()) { 723 return B; 724 } 725 RingFactory<SolvableResidue<C>> cfac = coFac; 726 SolvableResidueRing<C> qfac = (SolvableResidueRing<C>) cfac; 727 for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) { 728 ExpVector e = y.getKey(); 729 GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue(); 730 SolvableResidue<C> p = new SolvableResidue<C>(qfac, a); // can be zero 731 if (!p.isZERO()) { 732 //B = B.sum( p, e ); // inefficient 733 B.doPutToMap(e, p); 734 } 735 } 736 return B; 737 } 738 739 740 /** 741 * Integral function from solvable residue coefficients. Represent as 742 * polynomial with type GenSolvablePolynomial<C> coefficients. 743 * @param A polynomial with solvable residue coefficients to be converted. 744 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 745 */ 746 public RecSolvablePolynomial<C> toPolyCoefficients(ResidueSolvablePolynomial<C> A) { 747 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 748 if (A == null || A.isZERO()) { 749 return B; 750 } 751 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 752 ExpVector e = y.getKey(); 753 SolvableResidue<C> a = y.getValue(); 754 GenPolynomial<C> p = a.val; // can not be zero 755 if (!p.isZERO()) { 756 //B = B.sum( p, e ); // inefficient 757 B.doPutToMap(e, p); 758 } 759 } 760 return B; 761 } 762 763 764 /** 765 * Integral function from solvable residue coefficients. Represent as 766 * polynomial with type GenSolvablePolynomial<C> coefficients. 767 * @param A polynomial with solvable residue coefficients to be converted. 768 * @return polynomial with type GenSolvablePolynomial<C> coefficients. 769 */ 770 public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableResidue<C>> A) { 771 RecSolvablePolynomial<C> B = polCoeff.getZERO().copy(); 772 if (A == null || A.isZERO()) { 773 return B; 774 } 775 for (Map.Entry<ExpVector, SolvableResidue<C>> y : A.getMap().entrySet()) { 776 ExpVector e = y.getKey(); 777 SolvableResidue<C> a = y.getValue(); 778 GenPolynomial<C> p = a.val; // can not be zero 779 if (!p.isZERO()) { 780 //B = B.sum( p, e ); // inefficient 781 B.doPutToMap(e, p); 782 } 783 } 784 return B; 785 } 786 787}