Search in sources :

Example 1 with FactorComplex

use of edu.jas.ufd.FactorComplex 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)

Example 2 with FactorComplex

use of edu.jas.ufd.FactorComplex in project symja_android_library by axkr.

the class Algebra method factorComplex.

/**
 * @param polynomial the complex-rational polynomial which should be factored
 * @param jas
 * @param head the head of the factorization result AST (typically <code>F.Times</code> or <code>
 *     F.List</code>)
 * @param cfac
 * @return
 */
private static IExpr factorComplex(IExpr expr, GenPolynomial<Complex<BigRational>> polynomial, JASConvert<? extends RingElem<?>> jas, ISymbol head, ComplexRing<BigRational> cfac) {
    FactorComplex<BigRational> factorAbstract = new FactorComplex<BigRational>(cfac);
    SortedMap<GenPolynomial<Complex<BigRational>>, Long> map = factorAbstract.factors(polynomial);
    IASTAppendable result = F.ast(head, map.size());
    for (SortedMap.Entry<GenPolynomial<Complex<BigRational>>, Long> entry : map.entrySet()) {
        if (entry.getKey().isONE() && entry.getValue().equals(1L)) {
            continue;
        }
        final IExpr key = jas.complexPoly2Expr(entry.getKey());
        if (entry.getValue().equals(1L) && map.size() <= 2 && (key.equals(F.CNI) || key.equals(F.CI))) {
            // hack: factoring -I and I out of an expression should give no new factorized expression
            return expr;
        }
        result.append(F.Power(jas.complexPoly2Expr(entry.getKey()), F.ZZ(entry.getValue())));
    }
    return result;
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) BigRational(edu.jas.arith.BigRational) SortedMap(java.util.SortedMap) ModLong(edu.jas.arith.ModLong) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) FactorComplex(edu.jas.ufd.FactorComplex)

Aggregations

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