Search in sources :

Example 1 with ModLongRing

use of edu.jas.arith.ModLongRing 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 ModLongRing

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

the class Algebra method factorModulus.

private static IAST factorModulus(IExpr expr, List<IExpr> varList, boolean factorSquareFree, IExpr option) throws JASConversionException {
    try {
        // found "Modulus" option => use ModIntegerRing
        ModLongRing modIntegerRing = JASModInteger.option2ModLongRing((ISignedNumber) option);
        JASModInteger jas = new JASModInteger(varList, modIntegerRing);
        GenPolynomial<ModLong> poly = jas.expr2JAS(expr);
        return factorModulus(jas, modIntegerRing, poly, factorSquareFree);
    } catch (ArithmeticException ae) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            ae.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : ModLong(edu.jas.arith.ModLong) ModLongRing(edu.jas.arith.ModLongRing) JASModInteger(org.matheclipse.core.convert.JASModInteger)

Example 3 with ModLongRing

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

the class JASModInteger method option2ModLongRing.

public static ModLongRing option2ModLongRing(ISignedNumber option) {
    // TODO convert to long value
    long longValue = option.toLong();
    final BigInteger value = BigInteger.valueOf(longValue);
    return new ModLongRing(longValue, value.isProbablePrime(32));
}
Also used : BigInteger(java.math.BigInteger) ModLongRing(edu.jas.arith.ModLongRing)

Example 4 with ModLongRing

use of edu.jas.arith.ModLongRing 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

ModLongRing (edu.jas.arith.ModLongRing)4 ModLong (edu.jas.arith.ModLong)3 JASModInteger (org.matheclipse.core.convert.JASModInteger)3 ExpVector (edu.jas.poly.ExpVector)2 IAST (org.matheclipse.core.interfaces.IAST)2 BigInteger (java.math.BigInteger)1