001/*
002 * $Id: LocalSolvablePolynomialRing.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 * LocalSolvablePolynomialRing 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 LocalSolvablePolynomialRing<C extends GcdRingElem<C>> extends
051                GenSolvablePolynomialRing<SolvableLocal<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 LocalSolvablePolynomial<C> ZERO;
070
071
072    /**
073     * The constant polynomial 1 for this ring. Hides super ONE.
074     */
075    public final LocalSolvablePolynomial<C> ONE;
076
077
078    private static final Logger logger = Logger.getLogger(LocalSolvablePolynomialRing.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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n,
103                    RelationTable<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t,
129                    RelationTable<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t, String[] v,
180                    RelationTable<SolvableLocal<C>> rt) {
181        super(cf, n, t, v, rt);
182        //if (rt == null) { // handled in super }
183        SolvableLocalRing<C> cfring = (SolvableLocalRing<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 LocalSolvablePolynomial<C>(this);
193        SolvableLocal<C> coeff = coFac.getONE();
194        //evzero = ExpVector.create(nvar); // from super
195        ONE = new LocalSolvablePolynomial<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<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 LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, LocalSolvablePolynomialRing 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<SolvableLocal<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 instanceof LocalSolvablePolynomialRing)) {
289            return false;
290        }
291        LocalSolvablePolynomialRing<C> oring = null;
292        try {
293            oring = (LocalSolvablePolynomialRing<C>) other;
294        } catch (ClassCastException ignored) {
295        }
296        if (oring == null) {
297            return false;
298        }
299        // do a super.equals( )
300        if (!super.equals(other)) {
301            return false;
302        }
303        // check same base relations
304        //if ( ! table.equals(oring.table) ) { // done in super
305        //    return false;
306        //}
307        if (!polCoeff.coeffTable.equals(oring.polCoeff.coeffTable)) {
308            return false;
309        }
310        return true;
311    }
312
313
314    /**
315     * Hash code for this polynomial ring.
316     * @see java.lang.Object#hashCode()
317     */
318    @Override
319    public int hashCode() {
320        int h;
321        h = super.hashCode();
322        h = 37 * h + table.hashCode(); // may be different after some computations
323        h = 37 * h + polCoeff.coeffTable.hashCode(); // may be different
324        return h;
325    }
326
327
328    /**
329     * Get the zero element.
330     * @return 0 as LocalSolvablePolynomial<C>.
331     */
332    @Override
333    public LocalSolvablePolynomial<C> getZERO() {
334        return ZERO;
335    }
336
337
338    /**
339     * Get the one element.
340     * @return 1 as LocalSolvablePolynomial<C>.
341     */
342    @Override
343    public LocalSolvablePolynomial<C> getONE() {
344        return ONE;
345    }
346
347
348    /**
349     * Query if this ring is commutative.
350     * @return true if this ring is commutative, else false.
351     */
352    @Override
353    public boolean isCommutative() {
354        if (polCoeff.coeffTable.size() == 0) {
355            return super.isCommutative();
356        }
357        // check structure of relations?
358        return false;
359    }
360
361
362    /**
363     * Query if this ring is associative. Test if the relations between the mian
364     * variables and the coefficient generators define an associative solvable
365     * ring.
366     * @return true, if this ring is associative, else false.
367     */
368    @Override
369    public boolean isAssociative() {
370        if (!coFac.isAssociative()) {
371            return false;
372        }
373        LocalSolvablePolynomial<C> Xi, Xj, Xk, p, q;
374        List<GenPolynomial<SolvableLocal<C>>> gens = generators();
375        int ngen = gens.size();
376        for (int i = 0; i < ngen; i++) {
377            Xi = (LocalSolvablePolynomial<C>) gens.get(i);
378            for (int j = i + 1; j < ngen; j++) {
379                Xj = (LocalSolvablePolynomial<C>) gens.get(j);
380                for (int k = j + 1; k < ngen; k++) {
381                    Xk = (LocalSolvablePolynomial<C>) gens.get(k);
382                    try {
383                        p = Xk.multiply(Xj).multiply(Xi);
384                        q = Xk.multiply(Xj.multiply(Xi));
385                    } catch (IllegalArgumentException e) {
386                        //e.printStackTrace();
387                        continue;
388                    }
389                    if (p.compareTo(q) != 0) {
390                        if (logger.isInfoEnabled()) {
391                            logger.info("Xk = " + Xk + ", Xj = " + Xj + ", Xi = " + Xi);
392                            logger.info("p = ( Xk * Xj ) * Xi = " + p);
393                            logger.info("q = Xk * ( Xj * Xi ) = " + q);
394                            logger.info("q-p = " + p.subtract(q));
395                        }
396                        return false;
397                    }
398                }
399            }
400        }
401        return true; //coFac.isAssociative();
402    }
403
404
405    /**
406     * Get a (constant) LocalSolvablePolynomial&lt;C&gt; element from a long
407     * value.
408     * @param a long.
409     * @return a LocalSolvablePolynomial&lt;C&gt;.
410     */
411    @Override
412    public LocalSolvablePolynomial<C> fromInteger(long a) {
413        return new LocalSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero);
414    }
415
416
417    /**
418     * Get a (constant) LocalSolvablePolynomial&lt;C&gt; element from a
419     * BigInteger value.
420     * @param a BigInteger.
421     * @return a LocalSolvablePolynomial&lt;C&gt;.
422     */
423    @Override
424    public LocalSolvablePolynomial<C> fromInteger(BigInteger a) {
425        return new LocalSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero);
426    }
427
428
429    /**
430     * Random solvable polynomial. Generates a random solvable polynomial with k
431     * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3.
432     * @param n number of terms.
433     * @return a random solvable polynomial.
434     */
435    @Override
436    public LocalSolvablePolynomial<C> random(int n) {
437        return random(n, random);
438    }
439
440
441    /**
442     * Random solvable polynomial. Generates a random solvable polynomial with k
443     * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3.
444     * @param n number of terms.
445     * @param rnd is a source for random bits.
446     * @return a random solvable polynomial.
447     */
448    @Override
449    public LocalSolvablePolynomial<C> random(int n, Random rnd) {
450        if (nvar == 1) {
451            return random(5, n, n, 0.7f, rnd);
452        }
453        return random(5, n, 3, 0.3f, rnd);
454    }
455
456
457    /**
458     * Generate a random solvable polynomial.
459     * @param k bitsize 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     * @return a random solvable polynomial.
464     */
465    @Override
466    public LocalSolvablePolynomial<C> random(int k, int l, int d, float q) {
467        return random(k, l, d, q, random);
468    }
469
470
471    /**
472     * Random solvable polynomial.
473     * @param k size of random coefficients.
474     * @param l number of terms.
475     * @param d maximal degree in each variable.
476     * @param q density of nozero exponents.
477     * @param rnd is a source for random bits.
478     * @return a random solvable polynomial.
479     */
480    @Override
481    public LocalSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) {
482        LocalSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 
483        ExpVector e;
484        SolvableLocal<C> a;
485        // add random coeffs and exponents
486        for (int i = 0; i < l; i++) {
487            e = ExpVector.EVRAND(nvar, d, q, rnd);
488            a = coFac.random(k, rnd);
489            r = (LocalSolvablePolynomial<C>) r.sum(a, e);
490            // somewhat inefficient but clean
491        }
492        return r;
493    }
494
495
496    /**
497     * Copy polynomial c.
498     * @param c
499     * @return a copy of c.
500     */
501    public LocalSolvablePolynomial<C> copy(LocalSolvablePolynomial<C> c) {
502        return new LocalSolvablePolynomial<C>(this, c.getMap());
503    }
504
505
506    /**
507     * Parse a solvable polynomial with the use of GenPolynomialTokenizer
508     * @param s String.
509     * @return LocalSolvablePolynomial from s.
510     */
511    @Override
512    public LocalSolvablePolynomial<C> parse(String s) {
513        return parse(new StringReader(s));
514    }
515
516
517    /**
518     * Parse a solvable polynomial with the use of GenPolynomialTokenizer
519     * @param r Reader.
520     * @return next LocalSolvablePolynomial from r.
521     */
522    @Override
523    @SuppressWarnings("unchecked")
524    public LocalSolvablePolynomial<C> parse(Reader r) {
525        GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r);
526        LocalSolvablePolynomial<C> p = null;
527        try {
528            GenSolvablePolynomial<SolvableLocal<C>> s = pt.nextSolvablePolynomial();
529            p = new LocalSolvablePolynomial<C>(this, s);
530        } catch (IOException e) {
531            logger.error(e.toString() + " parse " + this);
532            p = ZERO;
533        }
534        return p;
535    }
536
537
538    /**
539     * Generate univariate solvable polynomial in a given variable.
540     * @param i the index of the variable.
541     * @return X_i as solvable univariate polynomial.
542     */
543    @Override
544    public LocalSolvablePolynomial<C> univariate(int i) {
545        return (LocalSolvablePolynomial<C>) super.univariate(i);
546    }
547
548
549    /**
550     * Generate univariate solvable polynomial in a given variable with given
551     * exponent.
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 LocalSolvablePolynomial<C> univariate(int i, long e) {
558        return (LocalSolvablePolynomial<C>) super.univariate(i, e);
559    }
560
561
562    /**
563     * Generate univariate solvable polynomial in a given variable with given
564     * exponent.
565     * @param modv number of module variables.
566     * @param i the index of the variable.
567     * @param e the exponent of the variable.
568     * @return X_i^e as solvable univariate polynomial.
569     */
570    @Override
571    public LocalSolvablePolynomial<C> univariate(int modv, int i, long e) {
572        return (LocalSolvablePolynomial<C>) super.univariate(modv, i, e);
573    }
574
575
576    /**
577     * Generate list of univariate polynomials in all variables.
578     * @return List(X_1,...,X_n) a list of univariate polynomials.
579     */
580    @Override
581    public List<LocalSolvablePolynomial<C>> univariateList() {
582        return univariateList(0, 1L);
583    }
584
585
586    /**
587     * Generate list of univariate polynomials in all variables.
588     * @param modv number of module variables.
589     * @return List(X_1,...,X_n) a list of univariate polynomials.
590     */
591    @Override
592    public List<LocalSolvablePolynomial<C>> univariateList(int modv) {
593        return univariateList(modv, 1L);
594    }
595
596
597    /**
598     * Generate list of univariate polynomials in all variables with given
599     * exponent.
600     * @param modv number of module variables.
601     * @param e the exponent of the variables.
602     * @return List(X_1^e,...,X_n^e) a list of univariate polynomials.
603     */
604    @Override
605    public List<LocalSolvablePolynomial<C>> univariateList(int modv, long e) {
606        List<LocalSolvablePolynomial<C>> pols = new ArrayList<LocalSolvablePolynomial<C>>(nvar);
607        int nm = nvar - modv;
608        for (int i = 0; i < nm; i++) {
609            LocalSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e);
610            pols.add(p);
611        }
612        return pols;
613    }
614
615
616    /**
617     * Extend variables. Used e.g. in module embedding. Extend number of
618     * variables by i.
619     * @param i number of variables to extend.
620     * @return extended solvable polynomial ring factory.
621     */
622    @Override
623    public LocalSolvablePolynomialRing<C> extend(int i) {
624        GenPolynomialRing<SolvableLocal<C>> pfac = super.extend(i);
625        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<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     * Contract variables. Used e.g. in module embedding. Contract number of
635     * variables by i.
636     * @param i number of variables to remove.
637     * @return contracted solvable polynomial ring factory.
638     */
639    @Override
640    public LocalSolvablePolynomialRing<C> contract(int i) {
641        GenPolynomialRing<SolvableLocal<C>> pfac = super.contract(i);
642        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
643                        pfac.tord, pfac.getVars());
644        spfac.table.contract(this.table);
645        spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable);
646        return spfac;
647    }
648
649
650    /**
651     * Reverse variables. Used e.g. in opposite rings.
652     * @return solvable polynomial ring factory with reversed variables.
653     */
654    @Override
655    public LocalSolvablePolynomialRing<C> reverse() {
656        return reverse(false);
657    }
658
659
660    /**
661     * Reverse variables. Used e.g. in opposite rings.
662     * @param partial true for partialy reversed term orders.
663     * @return solvable polynomial ring factory with reversed variables.
664     */
665    @Override
666    public LocalSolvablePolynomialRing<C> reverse(boolean partial) {
667        GenPolynomialRing<SolvableLocal<C>> pfac = super.reverse(partial);
668        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
669                        pfac.tord, pfac.getVars());
670        spfac.partial = partial;
671        spfac.table.reverse(this.table);
672        spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable);
673        return spfac;
674    }
675
676
677    /**
678     * Rational function from integral polynomial coefficients. Represent as
679     * polynomial with type SolvableLocal<C> coefficients.
680     * @param A polynomial with integral polynomial coefficients to be
681     *            converted.
682     * @return polynomial with type SolvableLocal<C> coefficients.
683     */
684    public LocalSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) {
685        LocalSolvablePolynomial<C> B = getZERO().copy();
686        if (A == null || A.isZERO()) {
687            return B;
688        }
689        RingFactory<SolvableLocal<C>> cfac = coFac;
690        SolvableLocalRing<C> qfac = (SolvableLocalRing<C>) cfac;
691        for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) {
692            ExpVector e = y.getKey();
693            GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue();
694            SolvableLocal<C> p = new SolvableLocal<C>(qfac, a); // can not be zero
695            if (!p.isZERO()) {
696                //B = B.sum( p, e ); // inefficient
697                B.doPutToMap(e, p);
698            }
699        }
700        return B;
701    }
702
703
704    /**
705     * Integral function from rational polynomial coefficients. Represent as
706     * polynomial with type GenSolvablePolynomial<C> coefficients.
707     * @param A polynomial with rational polynomial coefficients to be
708     *            converted.
709     * @return polynomial with type GenSolvablePolynomial<C> coefficients.
710     */
711    public RecSolvablePolynomial<C> toPolyCoefficients(LocalSolvablePolynomial<C> A) {
712        RecSolvablePolynomial<C> B = polCoeff.getZERO().copy();
713        if (A == null || A.isZERO()) {
714            return B;
715        }
716        for (Map.Entry<ExpVector, SolvableLocal<C>> y : A.getMap().entrySet()) {
717            ExpVector e = y.getKey();
718            SolvableLocal<C> a = y.getValue();
719            if (!a.den.isONE()) {
720                throw new IllegalArgumentException("den != 1 not supported: " + a);
721            }
722            GenPolynomial<C> p = a.num; // can not be zero
723            if (!p.isZERO()) {
724                //B = B.sum( p, e ); // inefficient
725                B.doPutToMap(e, p);
726            }
727        }
728        return B;
729    }
730
731
732    /**
733     * Integral function from rational polynomial coefficients. Represent as
734     * polynomial with type GenSolvablePolynomial<C> coefficients.
735     * @param A polynomial with rational polynomial coefficients to be
736     *            converted.
737     * @return polynomial with type GenSolvablePolynomial<C> coefficients.
738     */
739    public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableLocal<C>> A) {
740        RecSolvablePolynomial<C> B = polCoeff.getZERO().copy();
741        if (A == null || A.isZERO()) {
742            return B;
743        }
744        for (Map.Entry<ExpVector, SolvableLocal<C>> y : A.getMap().entrySet()) {
745            ExpVector e = y.getKey();
746            SolvableLocal<C> a = y.getValue();
747            if (!a.den.isONE()) {
748                throw new IllegalArgumentException("den != 1 not supported: " + a);
749            }
750            GenPolynomial<C> p = a.num; // can not be zero
751            if (!p.isZERO()) {
752                //B = B.sum( p, e ); // inefficient
753                B.doPutToMap(e, p);
754            }
755        }
756        return B;
757    }
758
759}