Search in sources :

Example 1 with GenPolynomialRing

use of edu.jas.poly.GenPolynomialRing in project symja_android_library by axkr.

the class Algebra method factorComplex.

public static IAST factorComplex(GenPolynomial<BigRational> polyRat, JASConvert<BigRational> jas, List<IExpr> varList, ISymbol head, boolean noGCDLCM) {
    TermOrder termOrder = TermOrderByName.Lexicographic;
    // Object[] objects = jas.factorTerms(polyRat);
    String[] vars = new String[varList.size()];
    for (int i = 0; i < varList.size(); i++) {
        vars[i] = varList.get(i).toString();
    }
    Object[] objects = JASConvert.rationalFromRationalCoefficientsFactor(new GenPolynomialRing<BigRational>(BigRational.ZERO, varList.size(), termOrder, vars), polyRat);
    java.math.BigInteger gcd = (java.math.BigInteger) objects[0];
    java.math.BigInteger lcm = (java.math.BigInteger) objects[1];
    GenPolynomial<BigRational> poly = (GenPolynomial<BigRational>) objects[2];
    ComplexRing<BigRational> cfac = new ComplexRing<BigRational>(BigRational.ZERO);
    GenPolynomialRing<Complex<BigRational>> cpfac = new GenPolynomialRing<Complex<BigRational>>(cfac, 1, termOrder);
    GenPolynomial<Complex<BigRational>> a = PolyUtil.complexFromAny(cpfac, poly);
    FactorComplex<BigRational> factorAbstract = new FactorComplex<BigRational>(cfac);
    SortedMap<GenPolynomial<Complex<BigRational>>, Long> map = factorAbstract.factors(a);
    IAST result = F.ast(head);
    if (!noGCDLCM) {
        if (!gcd.equals(java.math.BigInteger.ONE) || !lcm.equals(java.math.BigInteger.ONE)) {
            result.append(F.fraction(gcd, lcm));
        }
    }
    GenPolynomial<Complex<BigRational>> temp;
    for (SortedMap.Entry<GenPolynomial<Complex<BigRational>>, Long> entry : map.entrySet()) {
        if (entry.getKey().isONE() && entry.getValue().equals(1L)) {
            continue;
        }
        temp = entry.getKey();
        result.append(F.Power(jas.complexPoly2Expr(entry.getKey()), F.integer(entry.getValue())));
    }
    return result;
}
Also used : TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) IComplex(org.matheclipse.core.interfaces.IComplex) FactorComplex(edu.jas.ufd.FactorComplex) Complex(edu.jas.poly.Complex) IAST(org.matheclipse.core.interfaces.IAST) FactorComplex(edu.jas.ufd.FactorComplex) GenPolynomialRing(edu.jas.poly.GenPolynomialRing) ComplexRing(edu.jas.poly.ComplexRing) SortedMap(java.util.SortedMap) ModLong(edu.jas.arith.ModLong) BigInteger(edu.jas.arith.BigInteger)

Aggregations

BigInteger (edu.jas.arith.BigInteger)1 BigRational (edu.jas.arith.BigRational)1 ModLong (edu.jas.arith.ModLong)1 Complex (edu.jas.poly.Complex)1 ComplexRing (edu.jas.poly.ComplexRing)1 GenPolynomial (edu.jas.poly.GenPolynomial)1 GenPolynomialRing (edu.jas.poly.GenPolynomialRing)1 TermOrder (edu.jas.poly.TermOrder)1 FactorComplex (edu.jas.ufd.FactorComplex)1 SortedMap (java.util.SortedMap)1 IAST (org.matheclipse.core.interfaces.IAST)1 IComplex (org.matheclipse.core.interfaces.IComplex)1 ExprTermOrder (org.matheclipse.core.polynomials.ExprTermOrder)1