/symja_android_library/matheclipse-external/src/main/java/edu/jas/poly/PolyUtil.java
https://bitbucket.org/axelclk/symja_android_library · Java · 1285 lines · 718 code · 128 blank · 439 comment · 136 complexity · 71da9a1503a6aaec6fd82311a3b8b721 MD5 · raw file
- /*
- * $Id$
- */
- package edu.jas.poly;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.SortedMap;
- import java.util.TreeMap;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import edu.jas.arith.BigComplex;
- import edu.jas.arith.BigDecimal;
- import edu.jas.arith.BigDecimalComplex;
- import edu.jas.arith.BigInteger;
- import edu.jas.arith.BigRational;
- import edu.jas.arith.ModInteger;
- import edu.jas.arith.ModIntegerRing;
- import edu.jas.arith.Modular;
- import edu.jas.arith.ModularRingFactory;
- import edu.jas.arith.Product;
- import edu.jas.arith.ProductRing;
- import edu.jas.arith.Rational;
- import edu.jas.arith.Roots;
- import edu.jas.structure.Element;
- import edu.jas.structure.GcdRingElem;
- import edu.jas.structure.RingElem;
- import edu.jas.structure.RingFactory;
- import edu.jas.structure.StarRingElem;
- import edu.jas.structure.UnaryFunctor;
- import edu.jas.util.ListUtil;
- /**
- * Polynomial utilities, for example conversion between different
- * representations, evaluation and interpolation.
- * @author Heinz Kredel
- */
- public class PolyUtil {
- private static final Logger logger = LogManager.getLogger(PolyUtil.class);
- private static final boolean debug = logger.isDebugEnabled();
- /**
- * Recursive representation. Represent as polynomial in i variables with
- * coefficients in n-i variables. Works for arbitrary term orders.
- * @param <C> coefficient type.
- * @param rfac recursive polynomial ring factory.
- * @param A polynomial to be converted.
- * @return Recursive represenations of this in the ring rfac.
- */
- public static <C extends RingElem<C>> GenPolynomial<GenPolynomial<C>> recursive(
- GenPolynomialRing<GenPolynomial<C>> rfac, GenPolynomial<C> A) {
- GenPolynomial<GenPolynomial<C>> B = rfac.getZERO().copy();
- if (A.isZERO()) {
- return B;
- }
- int i = rfac.nvar;
- GenPolynomial<C> zero = rfac.getZEROCoefficient();
- Map<ExpVector, GenPolynomial<C>> Bv = B.val; //getMap();
- for (Map.Entry<ExpVector, C> y : A.getMap().entrySet()) {
- ExpVector e = y.getKey();
- C a = y.getValue();
- ExpVector f = e.contract(0, i);
- ExpVector g = e.contract(i, e.length() - i);
- GenPolynomial<C> p = Bv.get(f);
- if (p == null) {
- p = zero;
- }
- p = p.sum(a, g);
- Bv.put(f, p);
- }
- return B;
- }
- /**
- * Distribute a recursive polynomial to a generic polynomial. Works for
- * arbitrary term orders.
- * @param <C> coefficient type.
- * @param dfac combined polynomial ring factory of coefficients and this.
- * @param B polynomial to be converted.
- * @return distributed polynomial.
- */
- public static <C extends RingElem<C>> GenPolynomial<C> distribute(GenPolynomialRing<C> dfac,
- GenPolynomial<GenPolynomial<C>> B) {
- GenPolynomial<C> C = dfac.getZERO().copy();
- if (B.isZERO()) {
- return C;
- }
- Map<ExpVector, C> Cm = C.val; //getMap();
- for (Map.Entry<ExpVector, GenPolynomial<C>> y : B.getMap().entrySet()) {
- ExpVector e = y.getKey();
- GenPolynomial<C> A = y.getValue();
- for (Map.Entry<ExpVector, C> x : A.val.entrySet()) {
- ExpVector f = x.getKey();
- C b = x.getValue();
- ExpVector g = e.combine(f);
- assert (Cm.get(g) == null);
- Cm.put(g, b);
- }
- }
- return C;
- }
- /**
- * Recursive representation. Represent as polynomials in i variables with
- * coefficients in n-i variables. Works for arbitrary term orders.
- * @param <C> coefficient type.
- * @param rfac recursive polynomial ring factory.
- * @param L list of polynomials to be converted.
- * @return Recursive represenations of the list in the ring rfac.
- */
- public static <C extends RingElem<C>> List<GenPolynomial<GenPolynomial<C>>> recursive(
- GenPolynomialRing<GenPolynomial<C>> rfac, List<GenPolynomial<C>> L) {
- return ListUtil.<GenPolynomial<C>, GenPolynomial<GenPolynomial<C>>> map(L, new DistToRec<C>(rfac));
- }
- /**
- * Distribute a recursive polynomial list to a generic polynomial list.
- * Works for arbitrary term orders.
- * @param <C> coefficient type.
- * @param dfac combined polynomial ring factory of coefficients and this.
- * @param L list of polynomials to be converted.
- * @return distributed polynomial list.
- */
- public static <C extends RingElem<C>> List<GenPolynomial<C>> distribute(GenPolynomialRing<C> dfac,
- List<GenPolynomial<GenPolynomial<C>>> L) {
- return ListUtil.<GenPolynomial<GenPolynomial<C>>, GenPolynomial<C>> map(L, new RecToDist<C>(dfac));
- }
- /**
- * BigInteger from ModInteger coefficients, symmetric. Represent as
- * polynomial with BigInteger coefficients by removing the modules and
- * making coefficients symmetric to 0.
- * @param fac result polynomial factory.
- * @param A polynomial with ModInteger coefficients to be converted.
- * @return polynomial with BigInteger coefficients.
- */
- public static <C extends RingElem<C> & Modular> GenPolynomial<BigInteger> integerFromModularCoefficients(
- GenPolynomialRing<BigInteger> fac, GenPolynomial<C> A) {
- return PolyUtil.<C, BigInteger> map(fac, A, new ModSymToInt<C>());
- }
- /**
- * BigInteger from ModInteger coefficients, symmetric. Represent as
- * polynomial with BigInteger coefficients by removing the modules and
- * making coefficients symmetric to 0.
- * @param fac result polynomial factory.
- * @param L list of polynomials with ModInteger coefficients to be
- * converted.
- * @return list of polynomials with BigInteger coefficients.
- */
- public static <C extends RingElem<C> & Modular> List<GenPolynomial<BigInteger>> integerFromModularCoefficients(
- final GenPolynomialRing<BigInteger> fac, List<GenPolynomial<C>> L) {
- return ListUtil.<GenPolynomial<C>, GenPolynomial<BigInteger>> map(L,
- new UnaryFunctor<GenPolynomial<C>, GenPolynomial<BigInteger>>() {
- public GenPolynomial<BigInteger> eval(GenPolynomial<C> c) {
- return PolyUtil.<C> integerFromModularCoefficients(fac, c);
- }
- });
- }
- /**
- * BigInteger from ModInteger coefficients, positive. Represent as
- * polynomial with BigInteger coefficients by removing the modules.
- * @param fac result polynomial factory.
- * @param A polynomial with ModInteger coefficients to be converted.
- * @return polynomial with BigInteger coefficients.
- */
- public static <C extends RingElem<C> & Modular> GenPolynomial<BigInteger> integerFromModularCoefficientsPositive(
- GenPolynomialRing<BigInteger> fac, GenPolynomial<C> A) {
- return PolyUtil.<C, BigInteger> map(fac, A, new ModToInt<C>());
- }
- /**
- * BigInteger from BigRational coefficients. Represent as polynomial with
- * BigInteger coefficients by multiplication with the lcm of the numerators
- * of the BigRational coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with BigRational coefficients to be converted.
- * @return polynomial with BigInteger coefficients.
- */
- public static GenPolynomial<BigInteger> integerFromRationalCoefficients(GenPolynomialRing<BigInteger> fac,
- GenPolynomial<BigRational> A) {
- if (A == null || A.isZERO()) {
- return fac.getZERO();
- }
- java.math.BigInteger c = null;
- int s = 0;
- // lcm of denominators
- for (BigRational y : A.val.values()) {
- java.math.BigInteger x = y.denominator();
- // c = lcm(c,x)
- if (c == null) {
- c = x;
- s = x.signum();
- } else {
- java.math.BigInteger d = c.gcd(x);
- c = c.multiply(x.divide(d));
- }
- }
- if (s < 0) {
- c = c.negate();
- }
- return PolyUtil.<BigRational, BigInteger> map(fac, A, new RatToInt(c));
- }
- /**
- * BigInteger from BigRational coefficients. Represent as polynomial with
- * BigInteger coefficients by multiplication with the gcd of the numerators
- * and the lcm of the denominators of the BigRational coefficients. <br />
- * <b>Author:</b> Axel Kramer
- * @param fac result polynomial factory.
- * @param A polynomial with BigRational coefficients to be converted.
- * @return Object[] with 3 entries: [0]=gcd [1]=lcm and [2]=polynomial with
- * BigInteger coefficients.
- */
- public static Object[] integerFromRationalCoefficientsFactor(GenPolynomialRing<BigInteger> fac,
- GenPolynomial<BigRational> A) {
- Object[] result = new Object[3];
- if (A == null || A.isZERO()) {
- result[0] = java.math.BigInteger.ONE;
- result[1] = java.math.BigInteger.ZERO;
- result[2] = fac.getZERO();
- return result;
- }
- java.math.BigInteger gcd = null;
- java.math.BigInteger lcm = null;
- int sLCM = 0;
- int sGCD = 0;
- // lcm of denominators
- for (BigRational y : A.val.values()) {
- java.math.BigInteger numerator = y.numerator();
- java.math.BigInteger denominator = y.denominator();
- // lcm = lcm(lcm,x)
- if (lcm == null) {
- lcm = denominator;
- sLCM = denominator.signum();
- } else {
- java.math.BigInteger d = lcm.gcd(denominator);
- lcm = lcm.multiply(denominator.divide(d));
- }
- // gcd = gcd(gcd,x)
- if (gcd == null) {
- gcd = numerator;
- sGCD = numerator.signum();
- } else {
- gcd = gcd.gcd(numerator);
- }
- }
- if (sLCM < 0) {
- lcm = lcm.negate();
- }
- if (sGCD < 0) {
- gcd = gcd.negate();
- }
- //System.out.println("gcd* = " + gcd + ", lcm = " + lcm);
- result[0] = gcd;
- result[1] = lcm;
- result[2] = PolyUtil.<BigRational, BigInteger> map(fac, A, new RatToIntFactor(gcd, lcm));
- return result;
- }
- /**
- * BigInteger from BigRational coefficients. Represent as polynomial with
- * BigInteger coefficients by multiplication with the gcd of the numerators
- * and the lcm of the denominators of the BigRational coefficients. <br />
- * @param fac result polynomial factory.
- * @param gcd of rational coefficient numerators.
- * @param lcm of rational coefficient denominators.
- * @param A polynomial with BigRational coefficients to be converted.
- * @return polynomial with BigInteger coefficients.
- */
- public static GenPolynomial<BigInteger> integerFromRationalCoefficients(GenPolynomialRing<BigInteger> fac,
- java.math.BigInteger gcd, java.math.BigInteger lcm, GenPolynomial<BigRational> A) {
- //System.out.println("gcd = " + gcd + ", lcm = " + lcm);
- GenPolynomial<BigInteger> Ai = PolyUtil.<BigRational, BigInteger> map(fac, A,
- new RatToIntFactor(gcd, lcm));
- return Ai;
- }
- /**
- * BigInteger from BigRational coefficients. Represent as list of
- * polynomials with BigInteger coefficients by multiplication with the lcm
- * of the numerators of the BigRational coefficients of each polynomial.
- * @param fac result polynomial factory.
- * @param L list of polynomials with BigRational coefficients to be
- * converted.
- * @return polynomial list with BigInteger coefficients.
- */
- public static List<GenPolynomial<BigInteger>> integerFromRationalCoefficients(
- GenPolynomialRing<BigInteger> fac, List<GenPolynomial<BigRational>> L) {
- return ListUtil.<GenPolynomial<BigRational>, GenPolynomial<BigInteger>> map(L, new RatToIntPoly(fac));
- }
- /**
- * From BigInteger coefficients. Represent as polynomial with type C
- * coefficients, e.g. ModInteger or BigRational.
- * @param <C> coefficient type.
- * @param fac result polynomial factory.
- * @param A polynomial with BigInteger coefficients to be converted.
- * @return polynomial with type C coefficients.
- */
- public static <C extends RingElem<C>> GenPolynomial<C> fromIntegerCoefficients(GenPolynomialRing<C> fac,
- GenPolynomial<BigInteger> A) {
- return PolyUtil.<BigInteger, C> map(fac, A, new FromInteger<C>(fac.coFac));
- }
- /**
- * From BigInteger coefficients. Represent as list of polynomials with type
- * C coefficients, e.g. ModInteger or BigRational.
- * @param <C> coefficient type.
- * @param fac result polynomial factory.
- * @param L list of polynomials with BigInteger coefficients to be
- * converted.
- * @return list of polynomials with type C coefficients.
- */
- public static <C extends RingElem<C>> List<GenPolynomial<C>> fromIntegerCoefficients(
- GenPolynomialRing<C> fac, List<GenPolynomial<BigInteger>> L) {
- return ListUtil.<GenPolynomial<BigInteger>, GenPolynomial<C>> map(L, new FromIntegerPoly<C>(fac));
- }
- /**
- * Convert to decimal coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with Rational coefficients to be converted.
- * @return polynomial with BigDecimal coefficients.
- */
- public static <C extends RingElem<C> & Rational> GenPolynomial<BigDecimal> decimalFromRational(
- GenPolynomialRing<BigDecimal> fac, GenPolynomial<C> A) {
- return PolyUtil.<C, BigDecimal> map(fac, A, new RatToDec<C>());
- }
- /**
- * Convert to complex decimal coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with complex Rational coefficients to be converted.
- * @return polynomial with Complex BigDecimal coefficients.
- */
- public static <C extends RingElem<C> & Rational> GenPolynomial<Complex<BigDecimal>> complexDecimalFromRational(
- GenPolynomialRing<Complex<BigDecimal>> fac, GenPolynomial<Complex<C>> A) {
- return PolyUtil.<Complex<C>, Complex<BigDecimal>> map(fac, A, new CompRatToDec<C>(fac.coFac));
- }
- /**
- * Real part.
- * @param fac result polynomial factory.
- * @param A polynomial with BigComplex coefficients to be converted.
- * @return polynomial with real part of the coefficients.
- */
- public static GenPolynomial<BigRational> realPart(GenPolynomialRing<BigRational> fac,
- GenPolynomial<BigComplex> A) {
- return PolyUtil.<BigComplex, BigRational> map(fac, A, new RealPart());
- }
- /**
- * Imaginary part.
- * @param fac result polynomial factory.
- * @param A polynomial with BigComplex coefficients to be converted.
- * @return polynomial with imaginary part of coefficients.
- */
- public static GenPolynomial<BigRational> imaginaryPart(GenPolynomialRing<BigRational> fac,
- GenPolynomial<BigComplex> A) {
- return PolyUtil.<BigComplex, BigRational> map(fac, A, new ImagPart());
- }
- /**
- * Real part.
- * @param fac result polynomial factory.
- * @param A polynomial with BigComplex coefficients to be converted.
- * @return polynomial with real part of the coefficients.
- */
- public static <C extends RingElem<C>> GenPolynomial<C> realPartFromComplex(GenPolynomialRing<C> fac,
- GenPolynomial<Complex<C>> A) {
- return PolyUtil.<Complex<C>, C> map(fac, A, new RealPartComplex<C>());
- }
- /**
- * Imaginary part.
- * @param fac result polynomial factory.
- * @param A polynomial with BigComplex coefficients to be converted.
- * @return polynomial with imaginary part of coefficients.
- */
- public static <C extends RingElem<C>> GenPolynomial<C> imaginaryPartFromComplex(GenPolynomialRing<C> fac,
- GenPolynomial<Complex<C>> A) {
- return PolyUtil.<Complex<C>, C> map(fac, A, new ImagPartComplex<C>());
- }
- /**
- * Complex from real polynomial.
- * @param fac result polynomial factory.
- * @param A polynomial with C coefficients to be converted.
- * @return polynomial with Complex<C> coefficients.
- */
- public static <C extends RingElem<C>> GenPolynomial<Complex<C>> toComplex(
- GenPolynomialRing<Complex<C>> fac, GenPolynomial<C> A) {
- return PolyUtil.<C, Complex<C>> map(fac, A, new ToComplex<C>(fac.coFac));
- }
- /**
- * Complex from rational coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with BigRational coefficients to be converted.
- * @return polynomial with BigComplex coefficients.
- */
- public static GenPolynomial<BigComplex> complexFromRational(GenPolynomialRing<BigComplex> fac,
- GenPolynomial<BigRational> A) {
- return PolyUtil.<BigRational, BigComplex> map(fac, A, new RatToCompl());
- }
- /**
- * Complex from ring element coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with RingElem coefficients to be converted.
- * @return polynomial with Complex coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<Complex<C>> complexFromAny(
- GenPolynomialRing<Complex<C>> fac, GenPolynomial<C> A) {
- ComplexRing<C> cr = (ComplexRing<C>) fac.coFac;
- return PolyUtil.<C, Complex<C>> map(fac, A, new AnyToComplex<C>(cr));
- }
- /**
- * From AlgebraicNumber coefficients. Represent as polynomial with type
- * GenPolynomial<C> coefficients, e.g. ModInteger or BigRational.
- * @param rfac result polynomial factory.
- * @param A polynomial with AlgebraicNumber coefficients to be converted.
- * @return polynomial with type GenPolynomial<C> coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<GenPolynomial<C>> fromAlgebraicCoefficients(
- GenPolynomialRing<GenPolynomial<C>> rfac, GenPolynomial<AlgebraicNumber<C>> A) {
- return PolyUtil.<AlgebraicNumber<C>, GenPolynomial<C>> map(rfac, A, new AlgToPoly<C>());
- }
- /**
- * Convert to AlgebraicNumber coefficients. Represent as polynomial with
- * AlgebraicNumber<C> coefficients, C is e.g. ModInteger or BigRational.
- * @param pfac result polynomial factory.
- * @param A polynomial with C coefficients to be converted.
- * @return polynomial with AlgebraicNumber<C> coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<AlgebraicNumber<C>> convertToAlgebraicCoefficients(
- GenPolynomialRing<AlgebraicNumber<C>> pfac, GenPolynomial<C> A) {
- AlgebraicNumberRing<C> afac = (AlgebraicNumberRing<C>) pfac.coFac;
- return PolyUtil.<C, AlgebraicNumber<C>> map(pfac, A, new CoeffToAlg<C>(afac));
- }
- /**
- * Convert to recursive AlgebraicNumber coefficients. Represent as
- * polynomial with recursive AlgebraicNumber<C> coefficients, C is e.g.
- * ModInteger or BigRational.
- * @param depth recursion depth of AlgebraicNumber coefficients.
- * @param pfac result polynomial factory.
- * @param A polynomial with C coefficients to be converted.
- * @return polynomial with AlgebraicNumber<C> coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<AlgebraicNumber<C>> convertToRecAlgebraicCoefficients(
- int depth, GenPolynomialRing<AlgebraicNumber<C>> pfac, GenPolynomial<C> A) {
- AlgebraicNumberRing<C> afac = (AlgebraicNumberRing<C>) pfac.coFac;
- return PolyUtil.<C, AlgebraicNumber<C>> map(pfac, A, new CoeffToRecAlg<C>(depth, afac));
- }
- /**
- * Convert to AlgebraicNumber coefficients. Represent as polynomial with
- * AlgebraicNumber<C> coefficients, C is e.g. ModInteger or BigRational.
- * @param pfac result polynomial factory.
- * @param A recursive polynomial with GenPolynomial<BigInteger>
- * coefficients to be converted.
- * @return polynomial with AlgebraicNumber<C> coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<AlgebraicNumber<C>> convertRecursiveToAlgebraicCoefficients(
- GenPolynomialRing<AlgebraicNumber<C>> pfac, GenPolynomial<GenPolynomial<C>> A) {
- AlgebraicNumberRing<C> afac = (AlgebraicNumberRing<C>) pfac.coFac;
- return PolyUtil.<GenPolynomial<C>, AlgebraicNumber<C>> map(pfac, A, new PolyToAlg<C>(afac));
- }
- /**
- * Complex from algebraic coefficients.
- * @param fac result polynomial factory.
- * @param A polynomial with AlgebraicNumber coefficients Q(i) to be
- * converted.
- * @return polynomial with Complex coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<Complex<C>> complexFromAlgebraic(
- GenPolynomialRing<Complex<C>> fac, GenPolynomial<AlgebraicNumber<C>> A) {
- ComplexRing<C> cfac = (ComplexRing<C>) fac.coFac;
- return PolyUtil.<AlgebraicNumber<C>, Complex<C>> map(fac, A, new AlgebToCompl<C>(cfac));
- }
- /**
- * AlgebraicNumber from complex coefficients.
- * @param fac result polynomial factory over Q(i).
- * @param A polynomial with Complex coefficients to be converted.
- * @return polynomial with AlgebraicNumber coefficients.
- */
- public static <C extends GcdRingElem<C>> GenPolynomial<AlgebraicNumber<C>> algebraicFromComplex(
- GenPolynomialRing<AlgebraicNumber<C>> fac, GenPolynomial<Complex<C>> A) {
- AlgebraicNumberRing<C> afac = (AlgebraicNumberRing<C>) fac.coFac;
- return PolyUtil.<Complex<C>, AlgebraicNumber<C>> map(fac, A, new ComplToAlgeb<C>(afac));
- }
- /**
- * ModInteger chinese remainder algorithm on coefficients.
- * @param fac GenPolynomial<ModInteger> result factory with
- * A.coFac.modul*B.coFac.modul = C.coFac.modul.
- * @param A GenPolynomial<ModInteger>.
- * @param B other GenPolynomial<ModInteger>.
- * @param mi inverse of A.coFac.modul in ring B.coFac.
- * @return S = cra(A,B), with S mod A.coFac.modul == A and S mod
- * B.coFac.modul == B.
- */
- public static <C extends RingElem<C> & Modular> GenPolynomial<C> chineseRemainder(
- GenPolynomialRing<C> fac, GenPolynomial<C> A, C mi, GenPolynomial<C> B) {
- ModularRingFactory<C> cfac = (ModularRingFactory<C>) fac.coFac; // get RingFactory
- GenPolynomial<C> S = fac.getZERO().copy();
- GenPolynomial<C> Ap = A.copy();
- SortedMap<ExpVector, C> av = Ap.val; //getMap();
- SortedMap<ExpVector, C> bv = B.getMap();
- SortedMap<ExpVector, C> sv = S.val; //getMap();
- C c = null;
- for (Map.Entry<ExpVector, C> me : bv.entrySet()) {
- ExpVector e = me.getKey();
- C y = me.getValue(); //bv.get(e); // assert y != null
- C x = av.get(e);
- if (x != null) {
- av.remove(e);
- c = cfac.chineseRemainder(x, mi, y);
- if (!c.isZERO()) { // 0 cannot happen
- sv.put(e, c);
- }
- } else {
- //c = cfac.fromInteger( y.getVal() );
- c = cfac.chineseRemainder(A.ring.coFac.getZERO(), mi, y);
- if (!c.isZERO()) { // 0 cannot happen
- sv.put(e, c); // c != null
- }
- }
- }
- // assert bv is empty = done
- for (Map.Entry<ExpVector, C> me : av.entrySet()) { // rest of av
- ExpVector e = me.getKey();
- C x = me.getValue(); // av.get(e); // assert x != null
- //c = cfac.fromInteger( x.getVal() );
- c = cfac.chineseRemainder(x, mi, B.ring.coFac.getZERO());
- if (!c.isZERO()) { // 0 cannot happen
- sv.put(e, c); // c != null
- }
- }
- return S;
- }
- /**
- * GenPolynomial monic, i.e. leadingBaseCoefficient == 1. If
- * leadingBaseCoefficient is not invertible returns this unmodified.
- * @param <C> coefficient type.
- * @param p recursive GenPolynomial<GenPolynomial<C>>.
- * @return monic(p).
- */
- public static <C extends RingElem<C>> GenPolynomial<GenPolynomial<C>> monic(
- GenPolynomial<GenPolynomial<C>> p) {
- if (p == null || p.isZERO()) {
- return p;
- }
- C lc = p.leadingBaseCoefficient().leadingBaseCoefficient();
- if (!lc.isUnit()) {
- return p;
- }
- C lm = lc.inverse();
- GenPolynomial<C> L = p.ring.coFac.getONE();
- L = L.multiply(lm);
- return p.multiplyLeft(L);
- }
- /**
- * GenSolvablePolynomial monic, i.e. leadingBaseCoefficient == 1. If
- * leadingBaseCoefficient is not invertible returns this unmodified.
- * @param <C> coefficient type.
- * @param p recursive GenSolvablePolynomial<GenPolynomial<C>>.
- * @return monic(p).
- */
- public static <C extends RingElem<C>> GenSolvablePolynomial<GenPolynomial<C>> monic(
- GenSolvablePolynomial<GenPolynomial<C>> p) {
- if (p == null || p.isZERO()) {
- return p;
- }
- C lc = p.leadingBaseCoefficient().leadingBaseCoefficient();
- if (!lc.isUnit()) {
- return p;
- }
- C lm = lc.inverse();
- GenPolynomial<C> L = p.ring.coFac.getONE();
- L = L.multiply(lm);
- return p.multiplyLeft(L);
- }
- /**
- * Polynomial list monic.
- * @param <C> coefficient type.
- * @param L list of polynomials with field coefficients.
- * @return list of polynomials with leading coefficient 1.
- */
- public static <C extends RingElem<C>> List<GenPolynomial<C>> monic(List<GenPolynomial<C>> L) {
- return ListUtil.<GenPolynomial<C>, GenPolynomial<C>> map(L,
- new UnaryFunctor<GenPolynomial<C>, GenPolynomial<C>>() {
- public GenPolynomial<C> eval(GenPolynomial<C> c) {
- if (c == null) {
- return null;
- }
- return c.monic();
- }
- });
- }
- /**
- * Word polynomial list monic.
- * @param <C> coefficient type.
- * @param L list of word polynomials with field coefficients.
- * @return list of word polynomials with leading coefficient 1.
- */
- public static <C extends RingElem<C>> List<GenWordPolynomial<C>> wordMonic(List<GenWordPolynomial<C>> L) {
- return ListUtil.<GenWordPolynomial<C>, GenWordPolynomial<C>> map(L,
- new UnaryFunctor<GenWordPolynomial<C>, GenWordPolynomial<C>>() {
- public GenWordPolynomial<C> eval(GenWordPolynomial<C> c) {
- if (c == null) {
- return null;
- }
- return c.monic();
- }
- });
- }
- /**
- * Recursive polynomial list monic.
- * @param <C> coefficient type.
- * @param L list of recursive polynomials with field coefficients.
- * @return list of polynomials with leading base coefficient 1.
- */
- public static <C extends RingElem<C>> List<GenPolynomial<GenPolynomial<C>>> monicRec(
- List<GenPolynomial<GenPolynomial<C>>> L) {
- return ListUtil.<GenPolynomial<GenPolynomial<C>>, GenPolynomial<GenPolynomial<C>>> map(L,
- new UnaryFunctor<GenPolynomial<GenPolynomial<C>>, GenPolynomial<GenPolynomial<C>>>() {
- public GenPolynomial<GenPolynomial<C>> eval(GenPolynomial<GenPolynomial<C>> c) {
- if (c == null) {
- return null;
- }
- return PolyUtil.<C> monic(c);
- }
- });
- }
- /**
- * Polynomial list leading exponent vectors.
- * @param <C> coefficient type.
- * @param L list of polynomials.
- * @return list of leading exponent vectors.
- */
- public static <C extends RingElem<C>> List<ExpVector> leadingExpVector(List<GenPolynomial<C>> L) {
- return ListUtil.<GenPolynomial<C>, ExpVector> map(L, new UnaryFunctor<GenPolynomial<C>, ExpVector>() {
- public ExpVector eval(GenPolynomial<C> c) {
- if (c == null) {
- return null;
- }
- return c.leadingExpVector();
- }
- });
- }
- /**
- * Extend coefficient variables. Extend all coefficient ExpVectors by i
- * elements and multiply by x_j^k.
- * @param pfac extended polynomial ring factory (by i variables in the
- * coefficients).
- * @param j index of variable to be used for multiplication.
- * @param k exponent for x_j.
- * @return extended polynomial.
- */
- public static <C extends RingElem<C>> GenPolynomial<GenPolynomial<C>> extendCoefficients(
- GenPolynomialRing<GenPolynomial<C>> pfac, GenPolynomial<GenPolynomial<C>> A, int j,
- long k) {
- GenPolynomial<GenPolynomial<C>> Cp = pfac.getZERO().copy();
- if (A.isZERO()) {
- return Cp;
- }
- GenPolynomialRing<C> cfac = (GenPolynomialRing<C>) pfac.coFac;
- //GenPolynomialRing<C> acfac = (GenPolynomialRing<C>) A.ring.coFac;
- //int i = cfac.nvar - acfac.nvar;
- Map<ExpVector, GenPolynomial<C>> CC = Cp.val; //getMap();
- for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.val.entrySet()) {
- ExpVector e = y.getKey();
- GenPolynomial<C> a = y.getValue();
- GenPolynomial<C> f = a.extend(cfac, j, k);
- CC.put(e, f);
- }
- return Cp;
- }
- /**
- * Extend coefficient variables. Extend all coefficient ExpVectors by i
- * elements and multiply by x_j^k.
- * @param pfac extended polynomial ring factory (by i variables in the
- * coefficients).
- * @param j index of variable to be used for multiplication.
- * @param k exponent for x_j.
- * @return extended polynomial.
- */
- public static <C extends RingElem<C>> GenSolvablePolynomial<GenPolynomial<C>> extendCoefficients(
- GenSolvablePolynomialRing<GenPolynomial<C>> pfac,
- GenSolvablePolynomial<GenPolynomial<C>> A, int j, long k) {
- GenSolvablePolynomial<GenPolynomial<C>> Cp = pfac.getZERO().copy();
- if (A.isZERO()) {
- return Cp;
- }
- GenPolynomialRing<C> cfac = (GenPolynomialRing<C>) pfac.coFac;
- //GenPolynomialRing<C> acfac = (GenPolynomialRing<C>) A.ring.coFac;
- //int i = cfac.nvar - acfac.nvar;
- Map<ExpVector, GenPolynomial<C>> CC = Cp.val; //getMap();
- for (Map.Entry<ExpVector, GenPolynomial<C>> y : A.val.entrySet()) {
- ExpVector e = y.getKey();
- GenPolynomial<C> a = y.getValue();
- GenPolynomial<C> f = a.extend(cfac, j, k);
- CC.put(e, f);
- }
- return Cp;
- }
- /**
- * To recursive representation. Represent as polynomial in i+r variables
- * with coefficients in i variables. Works for arbitrary term orders.
- * @param <C> coefficient type.
- * @param rfac recursive polynomial ring factory.
- * @param A polynomial to be converted.
- * @return Recursive represenations of A in the ring rfac.
- */
- public static <C extends RingElem<C>> GenPolynomial<GenPolynomial<C>> toRecursive(
- GenPolynomialRing<GenPolynomial<C>> rfac, GenPolynomial<C> A) {
- GenPolynomial<GenPolynomial<C>> B = rfac.getZERO().copy();
- if (A.isZERO()) {
- return B;
- }
- //int i = rfac.nvar;
- //GenPolynomial<C> zero = rfac.getZEROCoefficient();
- GenPolynomial<C> one = rfac.getONECoefficient();
- Map<ExpVector, GenPolynomial<C>> Bv = B.val; //getMap();
- for (Monomial<C> m : A) {
- ExpVector e = m.e;
- C a = m.c;
- GenPolynomial<C> p = one.multiply(a);
- Bv.put(e, p);
- }
- return B;
- }
- /**
- * To recursive representation. Represent as solvable polynomial in i+r
- * variables with coefficients in i variables. Works for arbitrary term
- * orders.
- * @param <C> coefficient type.
- * @param rfac recursive solvable polynomial ring factory.
- * @param A solvable polynomial to be converted.
- * @return Recursive represenations of A in the ring rfac.
- */
- public static <C extends RingElem<C>> GenSolvablePolynomial<GenPolynomial<C>> toRecursive(
- GenSolvablePolynomialRing<GenPolynomial<C>> rfac, GenSolvablePolynomial<C> A) {
- GenSolvablePolynomial<GenPolynomial<C>> B = rfac.getZERO().copy();
- if (A.isZERO()) {
- return B;
- }
- //int i = rfac.nvar;
- //GenPolynomial<C> zero = rfac.getZEROCoefficient();
- GenPolynomial<C> one = rfac.getONECoefficient();
- Map<ExpVector, GenPolynomial<C>> Bv = B.val; //getMap();
- for (Monomial<C> m : A) {
- ExpVector e = m.e;
- C a = m.c;
- GenPolynomial<C> p = one.multiply(a);
- Bv.put(e, p);
- }
- return B;
- }
- /**
- * GenPolynomial coefficient wise remainder.
- * @param <C> coefficient type.
- * @param P GenPolynomial.
- * @param s nonzero coefficient.
- * @return coefficient wise remainder.
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- */
- public static <C extends RingElem<C>> GenPolynomial<C> baseRemainderPoly(GenPolynomial<C> P, C s) {
- if (s == null || s.isZERO()) {
- throw new ArithmeticException(P + " division by zero " + s);
- }
- GenPolynomial<C> h = P.ring.getZERO().copy();
- Map<ExpVector, C> hm = h.val; //getMap();
- for (Map.Entry<ExpVector, C> m : P.getMap().entrySet()) {
- ExpVector f = m.getKey();
- C a = m.getValue();
- C x = a.remainder(s);
- hm.put(f, x);
- }
- return h;
- }
- /**
- * GenPolynomial sparse pseudo remainder. For univariate polynomials.
- * @param <C> coefficient type.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return remainder with ldcf(S)<sup>m'</sup> P = quotient * S + remainder.
- * m' ≤ deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- * @deprecated(forRemoval=true) Use
- * {@link #baseSparsePseudoRemainder(edu.jas.poly.GenPolynomial,edu.jas.poly.GenPolynomial)}
- * instead
- */
- @Deprecated
- public static <C extends RingElem<C>> GenPolynomial<C> basePseudoRemainder(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- return baseSparsePseudoRemainder(P, S);
- }
- /**
- * GenPolynomial sparse pseudo remainder. For univariate polynomials.
- * @param <C> coefficient type.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return remainder with ldcf(S)<sup>m'</sup> P = quotient * S + remainder.
- * m' ≤ deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- */
- public static <C extends RingElem<C>> GenPolynomial<C> baseSparsePseudoRemainder(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- if (S == null || S.isZERO()) {
- throw new ArithmeticException(P.toString() + " division by zero " + S);
- }
- if (P.isZERO()) {
- return P;
- }
- if (S.isConstant()) {
- return P.ring.getZERO();
- }
- C c = S.leadingBaseCoefficient();
- ExpVector e = S.leadingExpVector();
- GenPolynomial<C> h;
- GenPolynomial<C> r = P;
- while (!r.isZERO()) {
- ExpVector f = r.leadingExpVector();
- if (f.multipleOf(e)) {
- C a = r.leadingBaseCoefficient();
- ExpVector fe = f.subtract(e);
- C x = a.remainder(c);
- if (x.isZERO()) {
- C y = a.divide(c);
- h = S.multiply(y, fe); // coeff a
- } else {
- r = r.multiply(c); // coeff ac
- h = S.multiply(a, fe); // coeff ac
- }
- r = r.subtract(h);
- } else {
- break;
- }
- }
- return r;
- }
- /**
- * GenPolynomial dense pseudo remainder. For univariate polynomials.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return remainder with ldcf(S)<sup>m</sup> P = quotient * S + remainder.
- * m == deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- */
- public static <C extends RingElem<C>> GenPolynomial<C> baseDensePseudoRemainder(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- if (S == null || S.isZERO()) {
- throw new ArithmeticException(P + " division by zero " + S);
- }
- if (P.isZERO()) {
- return P;
- }
- if (S.isConstant()) {
- return P.ring.getZERO();
- }
- long m = P.degree(0);
- long n = S.degree(0);
- C c = S.leadingBaseCoefficient();
- ExpVector e = S.leadingExpVector();
- GenPolynomial<C> h;
- GenPolynomial<C> r = P;
- for (long i = m; i >= n; i--) {
- if (r.isZERO()) {
- return r;
- }
- long k = r.degree(0);
- if (i == k) {
- ExpVector f = r.leadingExpVector();
- C a = r.leadingBaseCoefficient();
- f = f.subtract(e); // EVDIF( f, e );
- //System.out.println("red div = " + f);
- r = r.multiply(c); // coeff ac
- h = S.multiply(a, f); // coeff ac
- r = r.subtract(h);
- } else {
- r = r.multiply(c);
- }
- }
- return r;
- }
- /**
- * GenPolynomial dense pseudo quotient. For univariate polynomials.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return quotient with ldcf(S)<sup>m</sup> P = quotient * S + remainder. m
- * == deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- */
- public static <C extends RingElem<C>> GenPolynomial<C> baseDensePseudoQuotient(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- if (S == null || S.isZERO()) {
- throw new ArithmeticException(P + " division by zero " + S);
- }
- if (P.isZERO()) {
- return P;
- }
- //if (S.degree() <= 0) {
- // return l^n P; //P.ring.getZERO();
- //}
- long m = P.degree(0);
- long n = S.degree(0);
- C c = S.leadingBaseCoefficient();
- ExpVector e = S.leadingExpVector();
- GenPolynomial<C> q = P.ring.getZERO();
- GenPolynomial<C> h;
- GenPolynomial<C> r = P;
- for (long i = m; i >= n; i--) {
- if (r.isZERO()) {
- return q;
- }
- long k = r.degree(0);
- if (i == k) {
- ExpVector f = r.leadingExpVector();
- C a = r.leadingBaseCoefficient();
- f = f.subtract(e); // EVDIF( f, e );
- //System.out.println("red div = " + f);
- r = r.multiply(c); // coeff ac
- h = S.multiply(a, f); // coeff ac
- r = r.subtract(h);
- q = q.multiply(c);
- q = q.sum(a, f);
- } else {
- q = q.multiply(c);
- r = r.multiply(c);
- }
- }
- return q;
- }
- /**
- * GenPolynomial sparse pseudo divide. For univariate polynomials or exact
- * division.
- * @param <C> coefficient type.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return quotient with ldcf(S)<sup>m'</sup> P = quotient * S + remainder.
- * m' ≤ deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#divide(edu.jas.poly.GenPolynomial).
- */
- public static <C extends RingElem<C>> GenPolynomial<C> basePseudoDivide(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- if (S == null || S.isZERO()) {
- throw new ArithmeticException(P.toString() + " division by zero " + S);
- }
- //if (S.ring.nvar != 1) {
- // ok if exact division
- // throw new RuntimeException(this.getClass().getName()
- // + " univariate polynomials only");
- //}
- if (P.isZERO() || S.isONE()) {
- return P;
- }
- C c = S.leadingBaseCoefficient();
- ExpVector e = S.leadingExpVector();
- GenPolynomial<C> h;
- GenPolynomial<C> r = P;
- GenPolynomial<C> q = S.ring.getZERO().copy();
- while (!r.isZERO()) {
- ExpVector f = r.leadingExpVector();
- if (f.multipleOf(e)) {
- C a = r.leadingBaseCoefficient();
- f = f.subtract(e);
- C x = a.remainder(c);
- if (x.isZERO()) {
- C y = a.divide(c);
- q = q.sum(y, f);
- h = S.multiply(y, f); // coeff a
- } else {
- q = q.multiply(c);
- q = q.sum(a, f);
- r = r.multiply(c); // coeff ac
- h = S.multiply(a, f); // coeff ac
- }
- r = r.subtract(h);
- } else {
- break;
- }
- }
- return q;
- }
- /**
- * GenPolynomial sparse pseudo quotient and remainder. For univariate
- * polynomials or exact division.
- * @param <C> coefficient type.
- * @param P GenPolynomial.
- * @param S nonzero GenPolynomial.
- * @return [ quotient, remainder ] with ldcf(S)<sup>m'</sup> P = quotient *
- * S + remainder. m' ≤ deg(P)-deg(S)
- * @see edu.jas.poly.GenPolynomial#divide(edu.jas.poly.GenPolynomial).
- */
- @SuppressWarnings("unchecked")
- public static <C extends RingElem<C>> GenPolynomial<C>[] basePseudoQuotientRemainder(GenPolynomial<C> P,
- GenPolynomial<C> S) {
- if (S == null || S.isZERO()) {
- throw new ArithmeticException(P.toString() + " division by zero " + S);
- }
- //if (S.ring.nvar != 1) {
- // ok if exact division
- // throw new RuntimeException(this.getClass().getName()
- // + " univariate polynomials only");
- //}
- GenPolynomial<C>[] ret = new GenPolynomial[2];
- ret[0] = null;
- ret[1] = null;
- if (P.isZERO() || S.isONE()) {
- ret[0] = P;
- ret[1] = S.ring.getZERO();
- return ret;
- }
- C c = S.leadingBaseCoefficient();
- ExpVector e = S.leadingExpVector();
- GenPolynomial<C> h;
- GenPolynomial<C> r = P;
- GenPolynomial<C> q = S.ring.getZERO().copy();
- while (!r.isZERO()) {
- ExpVector f = r.leadingExpVector();
- if (f.multipleOf(e)) {
- C a = r.leadingBaseCoefficient();
- f = f.subtract(e);
- C x = a.remainder(c);
- if (x.isZERO()) {
- C y = a.divide(c);
- q = q.sum(y, f);
- h = S.multiply(y, f); // coeff a
- } else {
- q = q.multiply(c);
- q = q.sum(a, f);
- r = r.multiply(c); // coeff a c
- h = S.multiply(a, f); // coeff c a
- }
- r = r.subtract(h);
- } else {
- break;
- }
- }
- //GenPolynomial<C> rhs = q.multiply(S).sum(r);
- //GenPolynomial<C> lhs = P;
- ret[0] = q;
- ret[1] = r;
- return ret;
- }
- /**
- * Is GenPolynomial pseudo quotient and remainder. For univariate
- * polynomials.
- * @param <C> coefficient type.
- * @param P base GenPolynomial.
- * @param S nonzero base GenPolynomial.
- * @return true, if P = q * S + r, else false.
- * @see edu.jas.poly.GenPolynomial#remainder(edu.jas.poly.GenPolynomial).
- * <b>Note:</b> not always meaningful and working
- */
- public static <C extends RingElem<C>> boolean isBasePseudoQuotientRemainder(GenPolynomial<C> P,
- GenPolynomial<C> S, GenPolynomial<C> q, GenPolynomial<C> r) {
- GenPolynomial<C> rhs = q.multiply(S).sum(r);
- //System.out.println("rhs,1 = " + rhs);
- GenPolynomial<C> lhs = P;
- C ldcf = S.leadingBaseCoefficient();
- long d = P.degree(0) - S.degree(0) + 1;
- d = (d > 0 ? d : -d + 2);
- for (long i = 0; i <= d; i++) {
- //System.out.println("lhs-rhs = " + lhs.subtract(rhs));
- if (lhs.equals(rhs) || lhs.negate().equals(rhs)) {
- //System.out.println("lhs,1 = " + lhs);
- return true;
- }
- lhs = lhs.multiply(ldcf);
- }
- GenPolynomial<C> Pp = P;
- rhs = q.multiply(S);
- //System.out.println("rhs,2 = " + rhs);
- for (long i = 0; i <= d; i++) {
- lhs = Pp.subtract(r);
- //System.out.println("lhs-rhs = " + lhs.subtract(rhs));
- if (lhs.equals(rhs) || lhs.negate().equals(rhs)) {
- //System.out.println("lhs,2 = " + lhs);
- return true;
- }
- Pp = Pp.multiply(ldcf);
- }
- C a = P.leadingBaseCoefficient();
- rhs = q.multiply(S).sum(r);
- C b = rhs.leadingBaseCoefficient();
- C gcd = a.gcd(b);
- C p = a.multiply(b);
- C lcm = p.divide(gcd);
- C ap = lcm.divide(a);
- C bp = lcm.divide(b);
- if (P.multiply(ap).equals(rhs.multiply(bp))) {
- return true;
- }
- return false;
- }
- /**
- * GenPolynomial divide. For recursive polynomials. Division by coefficient
- * ring element.
- * @param <C> coefficient type.
- * @param P recursive GenPolynomial.
- * @param s GenPolynomial.
- * @return this/s.
- */
- public static <C extends RingElem<C>> GenPolynomial<GenPolynomial<C>> recursiveDivide(
- GenPolynomial<GenPolynomial<C>> P, GenPolynomial<C> s) {
- if (s == null || s.isZERO()) {
- throw new ArithmeticException("division by zero " + P + ", " + s);
- }
- if (P.isZERO()) {
- return P;
- }
- if (s.isONE()) {
- return P;
- }
- GenPolynomial<GenPolynomial<C>> p = P.ring.getZERO().copy();
- SortedMap<ExpVector, GenPolynomial<C>> pv = p.val; //getMap();
- for (Map.Entry<ExpVector, GenPolynomial<C>> m1 : P.getMap().entrySet()) {
- GenPolynomial<C> c1 = m1.getValue();
- ExpVector e1 = m1.getKey();
- GenPolynomial<C> c = PolyUtil.<C> basePseudoDivide(c1, s);
- if (!c.isZERO()) {
- pv.put(e1, c); // or m1.setValue( c )
- } else {
- logger.warn("rDiv, P = " + P);
- logger.warn("rDiv, c1 = " + c1);
- logger.warn("rDiv, s = " + s);
- logger.warn("rDiv, c = " + c);
- throw new RuntimeException("something is wrong");
- }
- }
- return p;
- }
- /**
- * GenPolynomial divide. For recursive polynomials. Division by coefficient
- * ring element.
- * @param <C> coefficient type.
- * @param P recursive GenPolynomial.
- * @param s GenPolynomial.
- * @return this/s.
- */
- public static <C extends RingElem<C>> GenWordPolynomial<GenPolynomial<C>> recursiveDivide(
- GenWordPolynomial<GenPolynomial<C>> P, GenPolynomial<C> s) {
- if (s == null || s.isZERO()) {
- throw new ArithmeticException("division by zero " + P + ", " + s);
- }
- if (P.isZERO()) {
- return P;
- }
- if (s.isONE()) {
- return P;
- }
- GenWordPolynomial<GenPolynomial<C>> p = P.ring.getZERO().copy();
- SortedMap<Word, GenPolynomial<C>> pv = p.val; //getMap();
- for (Map.Entry<Word, GenPolynomial<C>> m1 : P.getMap().entrySet()) {
- GenPolynomial<C> c1 = m1.getValue();
- Word e1 = m1.getKey();
- GenPolynomial<C> c = PolyUtil.<C> basePseudoDivide(c1, s);
- if (!c.isZERO()) {
- pv.put(e1, c); // or m1.setValue( c )
- } else {
- logger.warn("rDiv, P = " + P);
- logger.warn("rDiv, c1 = " + c1);
- logger.warn("rDiv, s = " + s);
- logger.warn("rDiv, c = " + c);
- throw new RuntimeException("something is wrong");
- }
- }
- return p;
- }
- /**
- * GenPolynomial base divide. For recursive polynomials. Division by
- * coefficient ring element.
- * @param <C> coefficient type.
- * @param P recursive GenPolynomial.
- * @param s coefficient.
- * @return this/s.
- */