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;
}
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;
}
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));
}
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 "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;
}
Aggregations