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