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