use of edu.jas.gbufd.GroebnerBasePartial in project symja_android_library by axkr.
the class GroebnerBasis method computeGroebnerBasis.
/**
*
* @param listOfPolynomials
* a list of polynomials
* @param listOfVariables
* a list of variable symbols
* @param termOrder
* the term order
* @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
*/
private static IAST computeGroebnerBasis(IAST listOfPolynomials, IAST listOfVariables, TermOrder termOrder) {
List<ISymbol> varList = new ArrayList<ISymbol>(listOfVariables.size() - 1);
String[] pvars = new String[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));
pvars[i - 1] = ((ISymbol) listOfVariables.get(i)).toString();
}
List<GenPolynomial<BigRational>> polyList = new ArrayList<GenPolynomial<BigRational>>(listOfPolynomials.size() - 1);
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) {
return F.NIL;
}
}
if (polyList.size() == 0) {
return F.NIL;
}
GroebnerBasePartial<BigRational> gbp = new GroebnerBasePartial<BigRational>();
OptimizedPolynomialList<BigRational> opl = gbp.partialGB(polyList, pvars);
List<GenPolynomial<BigRational>> list = OrderedPolynomialList.sort(opl.list);
IAST resultList = F.List();
for (GenPolynomial<BigRational> p : list) {
// convert rational to integer coefficients and add
// polynomial to result list
resultList.append(jas.integerPoly2Expr((GenPolynomial<BigInteger>) jas.factorTerms(p)[2]));
}
return resultList;
}
Aggregations