Search in sources :

Example 6 with ModLong

use of edu.jas.arith.ModLong in project symja_android_library by axkr.

the class Algebra method factorModulus.

public static IAST factorModulus(JASModInteger jas, ModLongRing modIntegerRing, GenPolynomial<ModLong> poly, boolean factorSquareFree) {
    FactorAbstract<ModLong> factorAbstract = FactorFactory.getImplementation(modIntegerRing);
    SortedMap<GenPolynomial<ModLong>, Long> map;
    if (factorSquareFree) {
        map = factorAbstract.squarefreeFactors(poly);
    } else {
        map = factorAbstract.factors(poly);
    }
    IAST result = F.Times();
    for (SortedMap.Entry<GenPolynomial<ModLong>, Long> entry : map.entrySet()) {
        GenPolynomial<ModLong> singleFactor = entry.getKey();
        Long val = entry.getValue();
        result.append(F.Power(jas.modLongPoly2Expr(singleFactor), F.integer(val)));
    }
    return result;
}
Also used : ModLong(edu.jas.arith.ModLong) GenPolynomial(edu.jas.poly.GenPolynomial) SortedMap(java.util.SortedMap) ModLong(edu.jas.arith.ModLong) IAST(org.matheclipse.core.interfaces.IAST)

Example 7 with ModLong

use of edu.jas.arith.ModLong 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 &quot;Modulus&quot; 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)

Aggregations

ModLong (edu.jas.arith.ModLong)7 IAST (org.matheclipse.core.interfaces.IAST)6 ExpVector (edu.jas.poly.ExpVector)5 ModLongRing (edu.jas.arith.ModLongRing)3 JASModInteger (org.matheclipse.core.convert.JASModInteger)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 GenPolynomial (edu.jas.poly.GenPolynomial)2 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 SortedMap (java.util.SortedMap)1 IFraction (org.matheclipse.core.interfaces.IFraction)1