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