use of edu.jas.poly.GenPolynomial in project symja_android_library by axkr.
the class PartialFractionGenerator method addSinglePartialFraction.
@Override
public void addSinglePartialFraction(GenPolynomial<BigRational> genPolynomial, GenPolynomial<BigRational> 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<edu.jas.arith.BigInteger> poly = (GenPolynomial<edu.jas.arith.BigInteger>) objects[2];
if (j == 1) {
temp = F.eval(F.Times(F.integer(gcd), jas.integerPoly2Expr(poly), F.Power(jas.rationalPoly2Expr(Di_1.multiply(BigRational.valueOf(lcm))), 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.rationalPoly2Expr(Di_1), F.integer(j * (-1L)))));
}
if (!temp.isZero()) {
if (temp.isAST()) {
((IAST) temp).addEvalFlags(IAST.IS_DECOMPOSED_PARTIAL_FRACTION);
}
result.append(temp);
}
}
use of edu.jas.poly.GenPolynomial in project symja_android_library by axkr.
the class JASModInteger method fraction2Poly.
private GenPolynomial<ModLong> fraction2Poly(final IFraction exprPoly) {
// .toJavaBigInteger();
BigInteger n = exprPoly.toBigNumerator();
// .toJavaBigInteger();
BigInteger d = exprPoly.toBigDenominator();
BigRational nr = new BigRational(n);
BigRational dr = new BigRational(d);
BigRational r = nr.divide(dr);
return new GenPolynomial(fPolyFactory, r);
}
use of edu.jas.poly.GenPolynomial in project symja_android_library by axkr.
the class JASConvert method fraction2Poly.
private GenPolynomial<C> fraction2Poly(final IFraction exprPoly) {
// .toJavaBigInteger();
BigInteger n = exprPoly.toBigNumerator();
// .toJavaBigInteger();
BigInteger d = exprPoly.toBigDenominator();
BigRational nr = new BigRational(n);
BigRational dr = new BigRational(d);
BigRational r = nr.divide(dr);
if (fRingFactory instanceof ComplexRing) {
ComplexRing ring = (ComplexRing) fRingFactory;
Complex<BigRational> c = new Complex<BigRational>(ring, r);
return new GenPolynomial(fPolyFactory, c);
} else {
return new GenPolynomial(fPolyFactory, r);
}
}
use of edu.jas.poly.GenPolynomial in project symja_android_library by axkr.
the class GroebnerBasis method solveGroebnerBasis.
/**
* Used in <code>Solve()</code> function to reduce the polynomial list of
* equations.
*
* @param listOfPolynomials
* a list of polynomials
* @param listOfVariables
* a list of variable symbols
* @return <code>F.NIL</code> if
* <code>stopUnevaluatedOnPolynomialConversionError==true</code> and
* one of the polynomials in <code>listOfPolynomials</code> are not
* convertible to JAS polynomials
*/
public static IAST solveGroebnerBasis(IAST listOfPolynomials, IAST listOfVariables) {
List<ISymbol> varList = new ArrayList<ISymbol>(listOfVariables.size() - 1);
for (int i = 1; i < listOfVariables.size(); i++) {
if (!listOfVariables.get(i).isSymbol()) {
return F.NIL;
}
varList.add((ISymbol) listOfVariables.get(i));
}
IAST rest = F.List();
List<GenPolynomial<BigRational>> polyList = new ArrayList<GenPolynomial<BigRational>>(listOfPolynomials.size() - 1);
TermOrder termOrder = TermOrderByName.IGRLEX;
JASConvert<BigRational> jas = new JASConvert<BigRational>(varList, BigRational.ZERO, termOrder);
for (int i = 1; i < listOfPolynomials.size(); i++) {
IExpr expr = F.evalExpandAll(listOfPolynomials.get(i));
try {
GenPolynomial<BigRational> poly = jas.expr2JAS(expr, false);
polyList.add(poly);
} catch (JASConversionException e) {
rest.append(expr);
}
}
if (polyList.size() == 0) {
return F.NIL;
}
GroebnerBaseAbstract<BigRational> engine = GBAlgorithmBuilder.<BigRational>polynomialRing(jas.getPolynomialRingFactory()).fractionFree().syzygyPairlist().build();
List<GenPolynomial<BigRational>> opl = engine.GB(polyList);
IAST resultList = F.List();
// polynomial to result list
for (GenPolynomial<BigRational> p : opl) {
resultList.append(jas.integerPoly2Expr((GenPolynomial<BigInteger>) jas.factorTerms(p)[2]));
}
for (int i = 1; i < rest.size(); i++) {
resultList.append(rest.get(i));
}
return resultList;
}
Aggregations