001/*
002 * $Id: LocalSolvablePolynomialRing.java 5909 2018-08-25 19:04:06Z kredel $
003 */
004
005package edu.jas.application;
006
007
008import java.io.IOException;
009import java.io.Reader;
010import java.io.StringReader;
011import java.math.BigInteger;
012import java.util.ArrayList;
013import java.util.List;
014import java.util.Map;
015import java.util.Random;
016
017import org.apache.logging.log4j.Logger;
018import org.apache.logging.log4j.LogManager; 
019
020import edu.jas.kern.PrettyPrint;
021import edu.jas.kern.Scripting;
022import edu.jas.poly.ExpVector;
023import edu.jas.poly.GenPolynomial;
024import edu.jas.poly.GenPolynomialRing;
025import edu.jas.poly.GenPolynomialTokenizer;
026import edu.jas.poly.GenSolvablePolynomial;
027import edu.jas.poly.GenSolvablePolynomialRing;
028import edu.jas.poly.RecSolvablePolynomial;
029import edu.jas.poly.RecSolvablePolynomialRing;
030import edu.jas.poly.RelationTable;
031import edu.jas.poly.TermOrder;
032import edu.jas.structure.GcdRingElem;
033import edu.jas.structure.RingElem;
034import edu.jas.structure.RingFactory;
035
036
037/**
038 * LocalSolvablePolynomialRing generic recursive solvable polynomial factory
039 * implementing RingFactory and extending GenSolvablePolynomialRing factory.
040 * Factory for n-variate ordered solvable polynomials over solvable polynomial
041 * coefficients. The non-commutative multiplication relations are maintained in
042 * a relation table and the non-commutative multiplication relations between the
043 * coefficients and the main variables are maintained in a coefficient relation
044 * table. Almost immutable object, except variable names and relation table
045 * contents.
046 * @param <C> coefficient type.
047 * @author Heinz Kredel
048 * will be deprecated use QLRSolvablePolynomialRing
049 */
050
051public class LocalSolvablePolynomialRing<C extends GcdRingElem<C>> extends
052                GenSolvablePolynomialRing<SolvableLocal<C>> {
053
054
055    /*
056     * The solvable multiplication relations between variables and coefficients.
057     */
058    //public final RelationTable<GenPolynomial<C>> coeffTable;
059
060
061    /**
062     * Recursive solvable polynomial ring with polynomial coefficients.
063     */
064    public final RecSolvablePolynomialRing<C> polCoeff;
065
066
067    /**
068     * The constant polynomial 0 for this ring. Hides super ZERO.
069     */
070    public final LocalSolvablePolynomial<C> ZERO;
071
072
073    /**
074     * The constant polynomial 1 for this ring. Hides super ONE.
075     */
076    public final LocalSolvablePolynomial<C> ONE;
077
078
079    private static final Logger logger = LogManager.getLogger(LocalSolvablePolynomialRing.class);
080
081
082    //private static final boolean debug = logger.isDebugEnabled();
083
084
085    /**
086     * The constructor creates a solvable polynomial factory object with the
087     * default term order and commutative relations.
088     * @param cf factory for coefficients of type C.
089     * @param n number of variables.
090     */
091    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n) {
092        this(cf, n, new TermOrder(), null, null);
093    }
094
095
096    /**
097     * The constructor creates a solvable polynomial factory object with the
098     * default term order.
099     * @param cf factory for coefficients of type C.
100     * @param n number of variables.
101     * @param rt solvable multiplication relations.
102     */
103    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n,
104                    RelationTable<SolvableLocal<C>> rt) {
105        this(cf, n, new TermOrder(), null, rt);
106    }
107
108
109    /**
110     * The constructor creates a solvable polynomial factory object with the
111     * given term order and commutative relations.
112     * @param cf factory for coefficients of type C.
113     * @param n number of variables.
114     * @param t a term order.
115     */
116    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t) {
117        this(cf, n, t, null, null);
118    }
119
120
121    /**
122     * The constructor creates a solvable polynomial factory object with the
123     * given term order.
124     * @param cf factory for coefficients of type C.
125     * @param n number of variables.
126     * @param t a term order.
127     * @param rt solvable multiplication relations.
128     */
129    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t,
130                    RelationTable<SolvableLocal<C>> rt) {
131        this(cf, n, t, null, rt);
132    }
133
134
135    /**
136     * The constructor creates a solvable polynomial factory object with the
137     * given term order and commutative relations.
138     * @param cf factory for coefficients of type C.
139     * @param n number of variables.
140     * @param t a term order.
141     * @param v names for the variables.
142     */
143    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t, String[] v) {
144        this(cf, n, t, v, null);
145    }
146
147
148    /**
149     * The constructor creates a solvable polynomial factory object with the
150     * given term order and commutative relations.
151     * @param cf factory for coefficients of type C.
152     * @param t a term order.
153     * @param v names for the variables.
154     */
155    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, TermOrder t, String[] v) {
156        this(cf, v.length, t, v, null);
157    }
158
159
160    /**
161     * The constructor creates a solvable polynomial factory object with the
162     * default term order.
163     * @param cf factory for coefficients of type C.
164     * @param v names for the variables.
165     */
166    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, String[] v) {
167        this(cf, v.length, new TermOrder(), v, null);
168    }
169
170
171    /**
172     * The constructor creates a solvable polynomial factory object with the
173     * given term order.
174     * @param cf factory for coefficients of type C.
175     * @param n number of variables.
176     * @param t a term order.
177     * @param v names for the variables.
178     * @param rt solvable multiplication relations.
179     */
180    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, int n, TermOrder t, String[] v,
181                    RelationTable<SolvableLocal<C>> rt) {
182        super(cf, n, t, v, rt);
183        //if (rt == null) { // handled in super }
184        SolvableLocalRing<C> cfring = (SolvableLocalRing<C>) cf; // == coFac
185        polCoeff = new RecSolvablePolynomialRing<C>(cfring.ring, n, t, v);
186        if (table.size() > 0) { // TODO
187            ExpVector e = null;
188            ExpVector f = null;
189            GenSolvablePolynomial<GenPolynomial<C>> p = null;
190            polCoeff.table.update(e, f, p); // from rt
191        }
192        //coeffTable = polCoeff.coeffTable; //new RelationTable<GenPolynomial<C>>(polCoeff, true);
193        ZERO = new LocalSolvablePolynomial<C>(this);
194        SolvableLocal<C> coeff = coFac.getONE();
195        //evzero = ExpVector.create(nvar); // from super
196        ONE = new LocalSolvablePolynomial<C>(this, coeff, evzero);
197    }
198
199
200    /**
201     * The constructor creates a solvable polynomial factory object with the the
202     * same term order, number of variables and variable names as the given
203     * polynomial factory, only the coefficient factories differ and the
204     * solvable multiplication relations are <b>empty</b>.
205     * @param cf factory for coefficients of type C.
206     * @param o other solvable polynomial ring.
207     */
208    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, GenSolvablePolynomialRing o) {
209        this(cf, o.nvar, o.tord, o.getVars(), null);
210    }
211
212
213    /**
214     * The constructor creates a solvable polynomial factory object with the the
215     * same term order, number of variables and variable names as the given
216     * polynomial factory, only the coefficient factories differ and the
217     * solvable multiplication relations are <b>empty</b>.
218     * @param cf factory for coefficients of type C.
219     * @param o other solvable polynomial ring.
220     */
221    public LocalSolvablePolynomialRing(RingFactory<SolvableLocal<C>> cf, LocalSolvablePolynomialRing o) {
222        this(cf, (GenSolvablePolynomialRing) o);
223    }
224
225
226    /**
227     * Get the String representation.
228     * @see java.lang.Object#toString()
229     */
230    @Override
231    public String toString() {
232        String res = super.toString();
233        if (PrettyPrint.isTrue()) {
234            //res += "\n" + table.toString(vars);
235            res += "\n" + polCoeff.coeffTable.toString(vars);
236        } else {
237            res += ", #rel = " + table.size() + " + " + polCoeff.coeffTable.size();
238        }
239        return res;
240    }
241
242
243    /**
244     * Get a scripting compatible string representation.
245     * @return script compatible representation for this Element.
246     * @see edu.jas.structure.Element#toScript()
247     */
248    @Override
249    public String toScript() {
250        StringBuffer s = new StringBuffer();
251        switch (Scripting.getLang()) {
252        case Ruby:
253            s.append("SolvPolyRing.new(");
254            break;
255        case Python:
256        default:
257            s.append("SolvPolyRing(");
258        }
259        if (coFac instanceof RingElem) {
260            s.append(((RingElem<SolvableLocal<C>>) coFac).toScriptFactory());
261        } else {
262            s.append(coFac.toScript().trim());
263        }
264        s.append(",\"" + varsToString() + "\",");
265        String to = tord.toScript();
266        s.append(to);
267        if (table.size() > 0) {
268            String rel = table.toScript();
269            s.append(",rel=");
270            s.append(rel);
271        }
272        if (polCoeff.coeffTable.size() > 0) {
273            String rel = polCoeff.coeffTable.toScript();
274            s.append(",coeffrel=");
275            s.append(rel);
276        }
277        s.append(")");
278        return s.toString();
279    }
280
281
282    /**
283     * Comparison with any other object.
284     * @see java.lang.Object#equals(java.lang.Object)
285     */
286    @Override
287    @SuppressWarnings("unchecked")
288    public boolean equals(Object other) {
289        if (!(other instanceof LocalSolvablePolynomialRing)) {
290            return false;
291        }
292        LocalSolvablePolynomialRing<C> oring = null;
293        try {
294            oring = (LocalSolvablePolynomialRing<C>) other;
295        } catch (ClassCastException ignored) {
296        }
297        if (oring == null) {
298            return false;
299        }
300        // do a super.equals( )
301        if (!super.equals(other)) {
302            return false;
303        }
304        // check same base relations
305        //if ( ! table.equals(oring.table) ) { // done in super
306        //    return false;
307        //}
308        if (!polCoeff.coeffTable.equals(oring.polCoeff.coeffTable)) {
309            return false;
310        }
311        return true;
312    }
313
314
315    /**
316     * Hash code for this polynomial ring.
317     * @see java.lang.Object#hashCode()
318     */
319    @Override
320    public int hashCode() {
321        int h;
322        h = super.hashCode();
323        h = 37 * h + table.hashCode(); // may be different after some computations
324        h = 37 * h + polCoeff.coeffTable.hashCode(); // may be different
325        return h;
326    }
327
328
329    /**
330     * Get the zero element.
331     * @return 0 as LocalSolvablePolynomial<C>.
332     */
333    @Override
334    public LocalSolvablePolynomial<C> getZERO() {
335        return ZERO;
336    }
337
338
339    /**
340     * Get the one element.
341     * @return 1 as LocalSolvablePolynomial<C>.
342     */
343    @Override
344    public LocalSolvablePolynomial<C> getONE() {
345        return ONE;
346    }
347
348
349    /**
350     * Query if this ring is commutative.
351     * @return true if this ring is commutative, else false.
352     */
353    @Override
354    public boolean isCommutative() {
355        if (polCoeff.coeffTable.size() == 0) {
356            return super.isCommutative();
357        }
358        // check structure of relations?
359        return false;
360    }
361
362
363    /**
364     * Query if this ring is associative. Test if the relations between the mian
365     * variables and the coefficient generators define an associative solvable
366     * ring.
367     * @return true, if this ring is associative, else false.
368     */
369    @Override
370    public boolean isAssociative() {
371        if (!coFac.isAssociative()) {
372            return false;
373        }
374        LocalSolvablePolynomial<C> Xi, Xj, Xk, p, q;
375        List<GenPolynomial<SolvableLocal<C>>> gens = generators();
376        int ngen = gens.size();
377        for (int i = 0; i < ngen; i++) {
378            Xi = (LocalSolvablePolynomial<C>) gens.get(i);
379            for (int j = i + 1; j < ngen; j++) {
380                Xj = (LocalSolvablePolynomial<C>) gens.get(j);
381                for (int k = j + 1; k < ngen; k++) {
382                    Xk = (LocalSolvablePolynomial<C>) gens.get(k);
383                    try {
384                        p = Xk.multiply(Xj).multiply(Xi);
385                        q = Xk.multiply(Xj.multiply(Xi));
386                    } catch (IllegalArgumentException e) {
387                        //e.printStackTrace();
388                        continue;
389                    }
390                    if (p.compareTo(q) != 0) {
391                        if (logger.isInfoEnabled()) {
392                            logger.info("Xk = " + Xk + ", Xj = " + Xj + ", Xi = " + Xi);
393                            logger.info("p = ( Xk * Xj ) * Xi = " + p);
394                            logger.info("q = Xk * ( Xj * Xi ) = " + q);
395                            logger.info("q-p = " + p.subtract(q));
396                        }
397                        return false;
398                    }
399                }
400            }
401        }
402        return true; //coFac.isAssociative();
403    }
404
405
406    /**
407     * Get a (constant) LocalSolvablePolynomial&lt;C&gt; element from a long
408     * value.
409     * @param a long.
410     * @return a LocalSolvablePolynomial&lt;C&gt;.
411     */
412    @Override
413    public LocalSolvablePolynomial<C> fromInteger(long a) {
414        return new LocalSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero);
415    }
416
417
418    /**
419     * Get a (constant) LocalSolvablePolynomial&lt;C&gt; element from a
420     * BigInteger value.
421     * @param a BigInteger.
422     * @return a LocalSolvablePolynomial&lt;C&gt;.
423     */
424    @Override
425    public LocalSolvablePolynomial<C> fromInteger(BigInteger a) {
426        return new LocalSolvablePolynomial<C>(this, coFac.fromInteger(a), evzero);
427    }
428
429
430    /**
431     * Random solvable polynomial. Generates a random solvable polynomial with k
432     * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3.
433     * @param n number of terms.
434     * @return a random solvable polynomial.
435     */
436    @Override
437    public LocalSolvablePolynomial<C> random(int n) {
438        return random(n, random);
439    }
440
441
442    /**
443     * Random solvable polynomial. Generates a random solvable polynomial with k
444     * = 5, l = n, d = (nvar == 1) ? n : 3, q = (nvar == 1) ? 0.7 : 0.3.
445     * @param n number of terms.
446     * @param rnd is a source for random bits.
447     * @return a random solvable polynomial.
448     */
449    @Override
450    public LocalSolvablePolynomial<C> random(int n, Random rnd) {
451        if (nvar == 1) {
452            return random(5, n, n, 0.7f, rnd);
453        }
454        return random(5, n, 3, 0.3f, rnd);
455    }
456
457
458    /**
459     * Generate a random solvable polynomial.
460     * @param k bitsize of random coefficients.
461     * @param l number of terms.
462     * @param d maximal degree in each variable.
463     * @param q density of nozero exponents.
464     * @return a random solvable polynomial.
465     */
466    @Override
467    public LocalSolvablePolynomial<C> random(int k, int l, int d, float q) {
468        return random(k, l, d, q, random);
469    }
470
471
472    /**
473     * Random solvable polynomial.
474     * @param k size of random coefficients.
475     * @param l number of terms.
476     * @param d maximal degree in each variable.
477     * @param q density of nozero exponents.
478     * @param rnd is a source for random bits.
479     * @return a random solvable polynomial.
480     */
481    @Override
482    public LocalSolvablePolynomial<C> random(int k, int l, int d, float q, Random rnd) {
483        LocalSolvablePolynomial<C> r = getZERO(); // copy( ZERO ); 
484        ExpVector e;
485        SolvableLocal<C> a;
486        // add random coeffs and exponents
487        for (int i = 0; i < l; i++) {
488            e = ExpVector.random(nvar, d, q, rnd);
489            a = coFac.random(k, rnd);
490            r = (LocalSolvablePolynomial<C>) r.sum(a, e);
491            // somewhat inefficient but clean
492        }
493        return r;
494    }
495
496
497    /**
498     * Copy polynomial c.
499     * @param c
500     * @return a copy of c.
501     */
502    public LocalSolvablePolynomial<C> copy(LocalSolvablePolynomial<C> c) {
503        return new LocalSolvablePolynomial<C>(this, c.getMap());
504    }
505
506
507    /**
508     * Parse a solvable polynomial with the use of GenPolynomialTokenizer
509     * @param s String.
510     * @return LocalSolvablePolynomial from s.
511     */
512    @Override
513    public LocalSolvablePolynomial<C> parse(String s) {
514        return parse(new StringReader(s));
515    }
516
517
518    /**
519     * Parse a solvable polynomial with the use of GenPolynomialTokenizer
520     * @param r Reader.
521     * @return next LocalSolvablePolynomial from r.
522     */
523    @Override
524    @SuppressWarnings("unchecked")
525    public LocalSolvablePolynomial<C> parse(Reader r) {
526        GenPolynomialTokenizer pt = new GenPolynomialTokenizer(this, r);
527        LocalSolvablePolynomial<C> p = null;
528        try {
529            GenSolvablePolynomial<SolvableLocal<C>> s = pt.nextSolvablePolynomial();
530            p = new LocalSolvablePolynomial<C>(this, s);
531        } catch (IOException e) {
532            logger.error(e.toString() + " parse " + this);
533            p = ZERO;
534        }
535        return p;
536    }
537
538
539    /**
540     * Generate univariate solvable polynomial in a given variable.
541     * @param i the index of the variable.
542     * @return X_i as solvable univariate polynomial.
543     */
544    @Override
545    public LocalSolvablePolynomial<C> univariate(int i) {
546        return (LocalSolvablePolynomial<C>) super.univariate(i);
547    }
548
549
550    /**
551     * Generate univariate solvable polynomial in a given variable with given
552     * exponent.
553     * @param i the index of the variable.
554     * @param e the exponent of the variable.
555     * @return X_i^e as solvable univariate polynomial.
556     */
557    @Override
558    public LocalSolvablePolynomial<C> univariate(int i, long e) {
559        return (LocalSolvablePolynomial<C>) super.univariate(i, e);
560    }
561
562
563    /**
564     * Generate univariate solvable polynomial in a given variable with given
565     * exponent.
566     * @param modv number of module variables.
567     * @param i the index of the variable.
568     * @param e the exponent of the variable.
569     * @return X_i^e as solvable univariate polynomial.
570     */
571    @Override
572    public LocalSolvablePolynomial<C> univariate(int modv, int i, long e) {
573        return (LocalSolvablePolynomial<C>) super.univariate(modv, i, e);
574    }
575
576
577    /**
578     * Generate list of univariate polynomials in all variables.
579     * @return List(X_1,...,X_n) a list of univariate polynomials.
580     */
581    @Override
582    public List<LocalSolvablePolynomial<C>> univariateList() {
583        return univariateList(0, 1L);
584    }
585
586
587    /**
588     * Generate list of univariate polynomials in all variables.
589     * @param modv number of module variables.
590     * @return List(X_1,...,X_n) a list of univariate polynomials.
591     */
592    @Override
593    public List<LocalSolvablePolynomial<C>> univariateList(int modv) {
594        return univariateList(modv, 1L);
595    }
596
597
598    /**
599     * Generate list of univariate polynomials in all variables with given
600     * exponent.
601     * @param modv number of module variables.
602     * @param e the exponent of the variables.
603     * @return List(X_1^e,...,X_n^e) a list of univariate polynomials.
604     */
605    @Override
606    public List<LocalSolvablePolynomial<C>> univariateList(int modv, long e) {
607        List<LocalSolvablePolynomial<C>> pols = new ArrayList<LocalSolvablePolynomial<C>>(nvar);
608        int nm = nvar - modv;
609        for (int i = 0; i < nm; i++) {
610            LocalSolvablePolynomial<C> p = univariate(modv, nm - 1 - i, e);
611            pols.add(p);
612        }
613        return pols;
614    }
615
616
617    /**
618     * Extend variables. Used e.g. in module embedding. Extend number of
619     * variables by i.
620     * @param i number of variables to extend.
621     * @return extended solvable polynomial ring factory.
622     */
623    @Override
624    public LocalSolvablePolynomialRing<C> extend(int i) {
625        return extend(i,false);
626    }
627
628    
629    /**
630     * Extend variables. Used e.g. in module embedding. Extend number of
631     * variables by i.
632     * @param i number of variables to extend.
633     * @param top true for TOP term order, false for POT term order.
634     * @return extended solvable polynomial ring factory.
635     */
636    @Override
637    public LocalSolvablePolynomialRing<C> extend(int i, boolean top) {
638        GenPolynomialRing<SolvableLocal<C>> pfac = super.extend(i, top);
639        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
640                        pfac.tord, pfac.getVars());
641        spfac.table.extend(this.table);
642        spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable);
643        return spfac;
644    }
645
646
647    /**
648     * Extend variables. Used e.g. in module embedding. Extend number of
649     * variables by length(vn). New variables commute with the exiting
650     * variables.
651     * @param vn names for extended variables.
652     * @return extended polynomial ring factory.
653     */
654    @Override
655    public LocalSolvablePolynomialRing<C> extend(String[] vn) {
656        return extend(vn, false);
657    }
658
659    
660    /**
661     * Extend variables. Used e.g. in module embedding. Extend number of
662     * variables by length(vn). New variables commute with the exiting
663     * variables.
664     * @param vn names for extended variables.
665     * @param top true for TOP term order, false for POT term order.
666     * @return extended polynomial ring factory.
667     */
668    @Override
669    public LocalSolvablePolynomialRing<C> extend(String[] vn, boolean top) {
670        GenPolynomialRing<SolvableLocal<C>> pfac = super.extend(vn, top);
671        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
672                        pfac.tord, pfac.getVars());
673        spfac.table.extend(this.table);
674        spfac.polCoeff.coeffTable.extend(this.polCoeff.coeffTable);
675        return spfac;
676    }
677
678 
679    /**
680     * Contract variables. Used e.g. in module embedding. Contract number of
681     * variables by i.
682     * @param i number of variables to remove.
683     * @return contracted solvable polynomial ring factory.
684     */
685    @Override
686    public LocalSolvablePolynomialRing<C> contract(int i) {
687        GenPolynomialRing<SolvableLocal<C>> pfac = super.contract(i);
688        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
689                        pfac.tord, pfac.getVars());
690        spfac.table.contract(this.table);
691        spfac.polCoeff.coeffTable.contract(this.polCoeff.coeffTable);
692        return spfac;
693    }
694
695
696    /**
697     * Reverse variables. Used e.g. in opposite rings.
698     * @return solvable polynomial ring factory with reversed variables.
699     */
700    @Override
701    public LocalSolvablePolynomialRing<C> reverse() {
702        return reverse(false);
703    }
704
705
706    /**
707     * Reverse variables. Used e.g. in opposite rings.
708     * @param partial true for partialy reversed term orders.
709     * @return solvable polynomial ring factory with reversed variables.
710     */
711    @Override
712    public LocalSolvablePolynomialRing<C> reverse(boolean partial) {
713        GenPolynomialRing<SolvableLocal<C>> pfac = super.reverse(partial);
714        LocalSolvablePolynomialRing<C> spfac = new LocalSolvablePolynomialRing<C>(pfac.coFac, pfac.nvar,
715                        pfac.tord, pfac.getVars());
716        spfac.partial = partial;
717        spfac.table.reverse(this.table);
718        spfac.polCoeff.coeffTable.reverse(this.polCoeff.coeffTable);
719        return spfac;
720    }
721
722
723    /**
724     * Rational function from integral polynomial coefficients. Represent as
725     * polynomial with type SolvableLocal<C> coefficients.
726     * @param A polynomial with integral polynomial coefficients to be
727     *            converted.
728     * @return polynomial with type SolvableLocal<C> coefficients.
729     */
730    public LocalSolvablePolynomial<C> fromPolyCoefficients(GenSolvablePolynomial<GenPolynomial<C>> A) {
731        LocalSolvablePolynomial<C> B = getZERO().copy();
732        if (A == null || A.isZERO()) {
733            return B;
734        }
735        RingFactory<SolvableLocal<C>> cfac = coFac;
736        SolvableLocalRing<C> qfac = (SolvableLocalRing<C>) cfac;
737        for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.getMap().entrySet()) {
738            ExpVector e = y.getKey();
739            GenSolvablePolynomial<C> a = (GenSolvablePolynomial<C>) y.getValue();
740            SolvableLocal<C> p = new SolvableLocal<C>(qfac, a); // can not be zero
741            if (!p.isZERO()) {
742                //B = B.sum( p, e ); // inefficient
743                B.doPutToMap(e, p);
744            }
745        }
746        return B;
747    }
748
749
750    /**
751     * Integral function from rational polynomial coefficients. Represent as
752     * polynomial with type GenSolvablePolynomial<C> coefficients.
753     * @param A polynomial with rational polynomial coefficients to be
754     *            converted.
755     * @return polynomial with type GenSolvablePolynomial<C> coefficients.
756     */
757    public RecSolvablePolynomial<C> toPolyCoefficients(LocalSolvablePolynomial<C> A) {
758        RecSolvablePolynomial<C> B = polCoeff.getZERO().copy();
759        if (A == null || A.isZERO()) {
760            return B;
761        }
762        for (Map.Entry<ExpVector, SolvableLocal<C>> y : A.getMap().entrySet()) {
763            ExpVector e = y.getKey();
764            SolvableLocal<C> a = y.getValue();
765            if (!a.den.isONE()) {
766                throw new IllegalArgumentException("den != 1 not supported: " + a);
767            }
768            GenPolynomial<C> p = a.num; // can not be zero
769            if (!p.isZERO()) {
770                //B = B.sum( p, e ); // inefficient
771                B.doPutToMap(e, p);
772            }
773        }
774        return B;
775    }
776
777
778    /**
779     * Integral function from rational polynomial coefficients. Represent as
780     * polynomial with type GenSolvablePolynomial<C> coefficients.
781     * @param A polynomial with rational polynomial coefficients to be
782     *            converted.
783     * @return polynomial with type GenSolvablePolynomial<C> coefficients.
784     */
785    public RecSolvablePolynomial<C> toPolyCoefficients(GenPolynomial<SolvableLocal<C>> A) {
786        RecSolvablePolynomial<C> B = polCoeff.getZERO().copy();
787        if (A == null || A.isZERO()) {
788            return B;
789        }
790        for (Map.Entry<ExpVector, SolvableLocal<C>> y : A.getMap().entrySet()) {
791            ExpVector e = y.getKey();
792            SolvableLocal<C> a = y.getValue();
793            if (!a.den.isONE()) {
794                throw new IllegalArgumentException("den != 1 not supported: " + a);
795            }
796            GenPolynomial<C> p = a.num; // can not be zero
797            if (!p.isZERO()) {
798                //B = B.sum( p, e ); // inefficient
799                B.doPutToMap(e, p);
800            }
801        }
802        return B;
803    }
804
805}