package org.matheclipse.core.polynomials;
import org.matheclipse.core.convert.JASConvert;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import edu.jas.arith.BigRational;
import edu.jas.poly.GenPolynomial;
public class PartialFractionGenerator implements IPartialFractionGenerator {
IAST result;
JASConvert jas;
public PartialFractionGenerator() {
this.result = F.Plus();
}
public void setJAS(JASConvert jas) {
this.jas = jas;
}
@Override
public IAST getResult() {
return result;
}
@Override
public void addNonFractionalPart(GenPolynomial genPolynomial) {
IExpr temp = F.eval(jas.poly2Expr(genPolynomial, null));
if (temp.isAST()) {
((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION);
}
result.add(temp);
}
@Override
public void addSinglePartialFraction(GenPolynomial genPolynomial, GenPolynomial Di_1, int j) {
IExpr temp;
Object[] objects = jas.factorTerms(genPolynomial);
java.math.BigInteger gcd = (java.math.BigInteger) objects[0];
java.math.BigInteger lcm = (java.math.BigInteger) objects[1];
GenPolynomial poly = (GenPolynomial) objects[2];
if (j == 1) {
temp = F.eval(F.Times(F.integer(gcd), jas.integerPoly2Expr(poly),
F.Power(jas.poly2Expr(Di_1.multiply(BigRational.valueOf(lcm)), null), F.CN1)));
} else {
temp = F.eval(F.Times(F.integer(gcd), jas.integerPoly2Expr(poly), F.Power(F.integer(lcm), F.integer(-1L)),
F.Power(jas.poly2Expr(Di_1, null), F.integer(j * (-1L)))));
}
if (!temp.isZero()) {
if (temp.isAST()) {
((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION);
}
result.add(temp);
}
}
}
Ads help maintain this website.