Search in sources :

Example 1 with ExpVector

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

the class MonomialList method monomialListModulus.

/**
	 * Get the monomial list of a univariate polynomial with coefficients
	 * reduced by a modulo value.
	 * 
	 * @param polynomial
	 * @param variable
	 * @param termOrder
	 *            the JAS term ordering
	 * @param option
	 *            the "Modulus" option
	 * @return the list of monomials of the univariate polynomial.
	 */
private static IAST monomialListModulus(IExpr polynomial, List<IExpr> variablesList, final TermOrder termOrder, IExpr option) throws JASConversionException {
    try {
        // found "Modulus" option => use ModIntegerRing
        ModLongRing modIntegerRing = JASModInteger.option2ModLongRing((ISignedNumber) option);
        JASModInteger jas = new JASModInteger(variablesList, modIntegerRing);
        GenPolynomial<ModLong> polyExpr = jas.expr2JAS(polynomial);
        IAST list = F.List();
        for (Monomial<ModLong> monomial : polyExpr) {
            ModLong coeff = monomial.coefficient();
            ExpVector exp = monomial.exponent();
            IAST monomTimes = F.Times();
            jas.monomialToExpr(F.integer(coeff.getVal()), exp, monomTimes);
            list.append(monomTimes);
        }
        return list;
    } catch (ArithmeticException ae) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            ae.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : ModLong(edu.jas.arith.ModLong) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST) ModLongRing(edu.jas.arith.ModLongRing) JASModInteger(org.matheclipse.core.convert.JASModInteger)

Example 2 with ExpVector

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

the class JASConvert method rationalPoly2Expr.

/**
	 * Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a>
	 * polynomial to a MathEclipse AST with head <code>Plus</code>
	 * 
	 * @param poly
	 *            a JAS polynomial
	 * @param variable
	 * @return
	 * @throws ArithmeticException
	 * @throws ClassCastException
	 */
public IAST rationalPoly2Expr(final GenPolynomial<BigRational> poly) throws ArithmeticException, ClassCastException {
    if (poly.length() == 0) {
        return F.Plus(F.C0);
    }
    IAST result = F.Plus();
    for (Monomial<BigRational> monomial : poly) {
        BigRational coeff = monomial.coefficient();
        ExpVector exp = monomial.exponent();
        IAST monomTimes = F.Times();
        monomialToExpr(coeff, exp, monomTimes);
        result.append(monomTimes.getOneIdentity(F.C1));
    }
    return result;
}
Also used : BigRational(edu.jas.arith.BigRational) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST)

Example 3 with ExpVector

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

the class JASIExpr method monomialToExpr.

public boolean monomialToExpr(IExpr coeff, ExpVector exp, IAST monomTimes) {
    long lExp;
    if (!coeff.isOne()) {
        monomTimes.append(coeff);
    }
    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.integer(lExp)));
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : ExpVector(edu.jas.poly.ExpVector)

Example 4 with ExpVector

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

the class JASModInteger method monomialToExpr.

public boolean monomialToExpr(IInteger coeff, ExpVector exp, IAST monomTimes) {
    long lExp;
    ExpVector leer = fPolyFactory.evzero;
    if (!coeff.isOne()) {
        monomTimes.append(coeff);
    }
    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.integer(lExp)));
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : ExpVector(edu.jas.poly.ExpVector)

Example 5 with ExpVector

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

the class JASIExpr method exprPoly2Expr.

/**
 * Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a> polynomial to a MathEclipse
 * AST with head <code>Plus</code>
 *
 * @param poly a JAS polynomial
 * @param variable
 * @return
 * @throws ArithmeticException
 * @throws ClassCastException
 */
public IExpr exprPoly2Expr(final GenPolynomial<IExpr> poly, IExpr variable) {
    if (poly.length() == 0) {
        return F.C0;
    }
    IASTAppendable result = F.PlusAlloc(poly.length());
    for (Monomial<IExpr> monomial : poly) {
        IExpr coeff = monomial.coefficient();
        ExpVector exp = monomial.exponent();
        IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
        monomialToExpr(coeff, exp, monomTimes);
        result.append(monomTimes.oneIdentity1());
    }
    return result.oneIdentity0();
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) ExpVector(edu.jas.poly.ExpVector) IExpr(org.matheclipse.core.interfaces.IExpr)

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