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