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