use of edu.jas.arith.BigInteger in project symja_android_library by axkr.
the class Algebra method factorRational.
public static IAST factorRational(GenPolynomial<BigRational> polyRat, JASConvert<BigRational> jas, ISymbol head) {
Object[] objects = jas.factorTerms(polyRat);
GenPolynomial<edu.jas.arith.BigInteger> poly = (GenPolynomial<edu.jas.arith.BigInteger>) objects[2];
FactorAbstract<edu.jas.arith.BigInteger> factorAbstract = FactorFactory.getImplementation(edu.jas.arith.BigInteger.ONE);
SortedMap<GenPolynomial<edu.jas.arith.BigInteger>, Long> map;
map = factorAbstract.factors(poly);
IASTAppendable result = F.ast(head, map.size() + 1);
java.math.BigInteger gcd = (java.math.BigInteger) objects[0];
java.math.BigInteger lcm = (java.math.BigInteger) objects[1];
if (!gcd.equals(java.math.BigInteger.ONE) || !lcm.equals(java.math.BigInteger.ONE)) {
result.append(F.fraction(gcd, lcm));
}
for (SortedMap.Entry<GenPolynomial<edu.jas.arith.BigInteger>, Long> entry : map.entrySet()) {
final GenPolynomial<BigInteger> key = entry.getKey();
final Long value = entry.getValue();
if (key.isONE() && value.equals(1L)) {
continue;
}
if (value == 1L) {
result.append(jas.integerPoly2Expr(key));
} else {
result.append(F.Power(jas.integerPoly2Expr(key), F.ZZ(value)));
}
}
return result;
}
use of edu.jas.arith.BigInteger in project symja_android_library by axkr.
the class PartialFractionIntegrateGenerator method isQuadratic.
/**
* Check if the polynomial has maximum degree 2 in 1 variable and return the coefficients.
*
* @param poly
* @return <code>null</code> if the polynomials degree > 2 and number of variables <> 1
*/
public static boolean isQuadratic(GenPolynomial<BigInteger> poly, BigInteger[] result) {
if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
result[0] = BigInteger.ZERO;
result[1] = BigInteger.ZERO;
result[2] = BigInteger.ZERO;
for (Monomial<BigInteger> monomial : poly) {
BigInteger 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.arith.BigInteger 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<BigInteger> poly, BigInteger[] result) {
if (poly.degree() <= 2 && poly.numberOfVariables() == 1) {
result[0] = BigInteger.ZERO;
result[1] = BigInteger.ZERO;
result[2] = BigInteger.ZERO;
for (Monomial<BigInteger> monomial : poly) {
BigInteger 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;
}
Aggregations