use of edu.jas.poly.ExpVector 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.poly.ExpVector in project symja_android_library by axkr.
the class JASConvert method rationalPoly2Expr.
/**
* Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a>
* polynomial to a MathEclipse AST with head <code>Plus</code>
*
* @param poly
* a JAS polynomial
* @param variable
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IAST rationalPoly2Expr(final GenPolynomial<BigRational> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.Plus(F.C0);
}
IAST result = F.Plus();
for (Monomial<BigRational> monomial : poly) {
BigRational coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IAST monomTimes = F.Times();
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result;
}
use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class JASIExpr method monomialToExpr.
public boolean monomialToExpr(IExpr coeff, ExpVector exp, IAST monomTimes) {
long lExp;
if (!coeff.isOne()) {
monomTimes.append(coeff);
}
ExpVector leer = fPolyFactory.evzero;
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
int ix = leer.varIndex(i);
if (ix >= 0) {
if (lExp == 1L) {
monomTimes.append(fVariables.get(ix));
} else {
monomTimes.append(F.Power(fVariables.get(ix), F.integer(lExp)));
}
} else {
return false;
}
}
}
return true;
}
use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class JASModInteger method monomialToExpr.
public boolean monomialToExpr(IInteger coeff, ExpVector exp, IAST monomTimes) {
long lExp;
ExpVector leer = fPolyFactory.evzero;
if (!coeff.isOne()) {
monomTimes.append(coeff);
}
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
int ix = leer.varIndex(i);
if (ix >= 0) {
if (lExp == 1L) {
monomTimes.append(fVariables.get(ix));
} else {
monomTimes.append(F.Power(fVariables.get(ix), F.integer(lExp)));
}
} else {
return false;
}
}
}
return true;
}
use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class JASIExpr method exprPoly2Expr.
/**
* Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a> polynomial to a MathEclipse
* AST with head <code>Plus</code>
*
* @param poly a JAS polynomial
* @param variable
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr exprPoly2Expr(final GenPolynomial<IExpr> poly, IExpr variable) {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<IExpr> monomial : poly) {
IExpr coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.oneIdentity1());
}
return result.oneIdentity0();
}
Aggregations