Search in sources :

Example 21 with ExpVector

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

the class CoefficientRules method coefficientRulesModulus.

/**
	 * Get exponent vectors and coefficients of monomials of a polynomial
	 * expression.
	 * 
	 * @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 coefficientRulesModulus(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 resultList = F.List();
        for (Monomial<ModLong> monomial : polyExpr) {
            ModLong coeff = monomial.coefficient();
            ExpVector exp = monomial.exponent();
            IAST ruleList = F.List();
            int len = exp.length();
            for (int i = 0; i < len; i++) {
                ruleList.append(F.integer(exp.getVal(len - i - 1)));
            }
            resultList.append(F.Rule(ruleList, F.integer(coeff.getVal())));
        }
        return resultList;
    } catch (ArithmeticException ae) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            ae.printStackTrace();
        }
    }
    return null;
}
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 22 with ExpVector

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

the class CoefficientRules method coefficientRules.

/**
	 * Get exponent vectors and coefficients of monomials of a polynomial
	 * expression.
	 * 
	 * @param polynomial
	 * @param variable
	 * @param termOrder
	 *            the JAS term ordering
	 * @return the list of monomials of the univariate polynomial.
	 */
public static IAST coefficientRules(IExpr polynomial, final List<IExpr> variablesList, final TermOrder termOrder) throws JASConversionException {
    JASIExpr jas = new JASIExpr(variablesList, ExprRingFactory.CONST, termOrder, false);
    GenPolynomial<IExpr> polyExpr = jas.expr2IExprJAS(polynomial);
    IAST resultList = F.List();
    for (Monomial<IExpr> monomial : polyExpr) {
        IAST ruleList = F.List();
        IExpr coeff = monomial.coefficient();
        ExpVector exp = monomial.exponent();
        int len = exp.length();
        for (int i = 0; i < len; i++) {
            ruleList.append(F.integer(exp.getVal(len - i - 1)));
        }
        resultList.append(F.Rule(ruleList, coeff));
    }
    return resultList;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) ExpVector(edu.jas.poly.ExpVector) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

ExpVector (edu.jas.poly.ExpVector)22 IAST (org.matheclipse.core.interfaces.IAST)15 BigRational (edu.jas.arith.BigRational)6 IExpr (org.matheclipse.core.interfaces.IExpr)6 ModLong (edu.jas.arith.ModLong)5 IInteger (org.matheclipse.core.interfaces.IInteger)5 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)3 ISymbol (org.matheclipse.core.interfaces.ISymbol)3 BigInteger (edu.jas.arith.BigInteger)2 ModLongRing (edu.jas.arith.ModLongRing)2 Complex (edu.jas.poly.Complex)2 GenPolynomial (edu.jas.poly.GenPolynomial)2 Map (java.util.Map)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 JASModInteger (org.matheclipse.core.convert.JASModInteger)2 IFraction (org.matheclipse.core.interfaces.IFraction)2 AlgebraicNumber (edu.jas.poly.AlgebraicNumber)1 BigInteger (java.math.BigInteger)1 SortedMap (java.util.SortedMap)1 IComplex (org.matheclipse.core.interfaces.IComplex)1