use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class Integrate method isQuadratic.
/**
* Check if the polynomial has maximum degree 2 in 1 variable and return the
* coefficients.
*
* @param poly
* @return <code>false</code> if the polynomials degree > 2 and number of
* variables <> 1
*/
public static boolean isQuadratic(GenPolynomial<BigRational> poly, BigRational[] result) {
if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
result[0] = BigRational.ZERO;
result[1] = BigRational.ZERO;
result[2] = BigRational.ZERO;
for (Monomial<BigRational> monomial : poly) {
BigRational coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
for (int i = 0; i < exp.length(); i++) {
result[(int) exp.getVal(i)] = coeff;
}
}
return true;
}
return false;
}
use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class JASConvert method polyAlgebraicNumber2Expr.
public IAST polyAlgebraicNumber2Expr(final GenPolynomial<AlgebraicNumber<BigRational>> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.Plus(F.C0);
}
SortedMap<ExpVector, AlgebraicNumber<BigRational>> val = poly.getMap();
if (val.size() == 0) {
return F.Plus(F.C0);
} else {
IAST result = F.Plus();
for (Map.Entry<ExpVector, AlgebraicNumber<BigRational>> m : val.entrySet()) {
AlgebraicNumber<BigRational> coeff = m.getValue();
IAST monomTimes = F.Times();
ExpVector exp = m.getKey();
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 JASConvert method integerPoly2Expr.
/**
* Convert a JAS integer polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr integerPoly2Expr(final GenPolynomial<edu.jas.arith.BigInteger> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IAST result = F.PlusAlloc(poly.length());
for (Monomial<edu.jas.arith.BigInteger> monomial : poly) {
edu.jas.arith.BigInteger coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IAST monomTimes = F.Times();
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result.getOneIdentity(F.C0);
}
use of edu.jas.poly.ExpVector in project symja_android_library by axkr.
the class JASConvert method expVectorToExpr.
private boolean expVectorToExpr(ExpVector exp, IAST monomTimes) {
long lExp;
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 JASIExpr method integerPoly2Expr.
/**
* Convert a JAS integer polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr integerPoly2Expr(final GenPolynomial<edu.jas.arith.BigInteger> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IAST result = F.Plus();
for (Monomial<edu.jas.arith.BigInteger> monomial : poly) {
edu.jas.arith.BigInteger coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IInteger coeffValue = F.integer(coeff.getVal());
IAST monomTimes = F.Times(coeffValue);
long lExp;
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
monomTimes.append(F.Power(fVariables.get(i), F.integer(lExp)));
}
}
if (monomTimes.isAST1()) {
result.append(monomTimes.arg1());
} else {
result.append(monomTimes);
}
}
if (result.isAST1()) {
return result.arg1();
} else {
return result;
}
}
Aggregations