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