Search in sources :

Example 26 with ExpVector

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

the class JASConvert method expVectorToExpr.

private boolean expVectorToExpr(ExpVector exp, IASTAppendable monomTimes) {
    long lExp;
    ExpVector leer = fPolyFactory.evzero;
    for (int i = 0; i < exp.length(); i++) {
        lExp = exp.getVal(i);
        if (lExp != 0) {
            int ix = leer.varIndex(i);
            if (ix >= 0) {
                if (lExp == 1L) {
                    monomTimes.append(fVariables.get(ix));
                } else {
                    monomTimes.append(F.Power(fVariables.get(ix), F.ZZ(lExp)));
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : ExpVector(edu.jas.poly.ExpVector)

Example 27 with ExpVector

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

the class JASConvert method isQuadratic.

/**
 * Check if the polynomial has maximum degree 2 in 1 variable and return the coefficients.
 *
 * @param poly
 * @return <code>false</code> if the polynomials degree > 2 and number of variables <> 1
 */
private static boolean isQuadratic(GenPolynomial<edu.jas.arith.BigInteger> poly, edu.jas.arith.BigInteger[] result) {
    if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
        result[0] = edu.jas.arith.BigInteger.ZERO;
        result[1] = edu.jas.arith.BigInteger.ZERO;
        result[2] = edu.jas.arith.BigInteger.ZERO;
        for (Monomial<edu.jas.arith.BigInteger> monomial : poly) {
            edu.jas.arith.BigInteger coeff = monomial.coefficient();
            ExpVector exp = monomial.exponent();
            for (int i = 0; i < exp.length(); i++) {
                result[(int) exp.getVal(i)] = coeff;
            }
        }
        return true;
    }
    return false;
}
Also used : ExpVector(edu.jas.poly.ExpVector) BigInteger(java.math.BigInteger)

Example 28 with ExpVector

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

the class JASConvert method isQuadratic.

/**
 * Check if the polynomial has maximum degree 2 in 1 variable and return the coefficients.
 *
 * @param poly
 * @return <code>false</code> if the polynomials degree > 2 and number of variables <> 1
 */
private static boolean isQuadratic(GenPolynomial<BigRational> poly, BigRational[] result) {
    if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
        result[0] = BigRational.ZERO;
        result[1] = BigRational.ZERO;
        result[2] = BigRational.ZERO;
        for (Monomial<BigRational> monomial : poly) {
            BigRational coeff = monomial.coefficient();
            ExpVector exp = monomial.exponent();
            for (int i = 0; i < exp.length(); i++) {
                result[(int) exp.getVal(i)] = coeff;
            }
        }
        return true;
    }
    return false;
}
Also used : BigRational(edu.jas.arith.BigRational) ExpVector(edu.jas.poly.ExpVector)

Example 29 with ExpVector

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

the class JASConvert method polyAlgebraicNumber2Expr.

public IAST polyAlgebraicNumber2Expr(final GenPolynomial<AlgebraicNumber<BigRational>> poly) throws ArithmeticException, JASConversionException {
    if (poly.length() == 0) {
        return F.Plus(F.C0);
    }
    SortedMap<ExpVector, AlgebraicNumber<BigRational>> val = poly.getMap();
    if (val.size() == 0) {
        return F.Plus(F.C0);
    } else {
        IASTAppendable result = F.PlusAlloc(val.size());
        for (Map.Entry<ExpVector, AlgebraicNumber<BigRational>> m : val.entrySet()) {
            AlgebraicNumber<BigRational> coeff = m.getValue();
            ExpVector exp = m.getKey();
            IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
            monomialToExpr(coeff, exp, monomTimes);
            result.append(monomTimes.oneIdentity1());
        }
        return result;
    }
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) BigRational(edu.jas.arith.BigRational) ExpVector(edu.jas.poly.ExpVector) Map(java.util.Map) SortedMap(java.util.SortedMap) AlgebraicNumber(edu.jas.poly.AlgebraicNumber)

Aggregations

ExpVector (edu.jas.poly.ExpVector)29 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)9 BigRational (edu.jas.arith.BigRational)8 IAST (org.matheclipse.core.interfaces.IAST)8 IExpr (org.matheclipse.core.interfaces.IExpr)6 ModLong (edu.jas.arith.ModLong)5 IInteger (org.matheclipse.core.interfaces.IInteger)5 BigInteger (java.math.BigInteger)4 Complex (edu.jas.poly.Complex)3 GenPolynomial (edu.jas.poly.GenPolynomial)3 ISymbol (org.matheclipse.core.interfaces.ISymbol)3 BigInteger (edu.jas.arith.BigInteger)2 ModLongRing (edu.jas.arith.ModLongRing)2 Map (java.util.Map)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 JASModInteger (org.matheclipse.core.convert.JASModInteger)2 IComplex (org.matheclipse.core.interfaces.IComplex)2 IFraction (org.matheclipse.core.interfaces.IFraction)2 AlgebraicNumber (edu.jas.poly.AlgebraicNumber)1 SortedMap (java.util.SortedMap)1