Search in sources :

Example 1 with GroebnerBasePartial

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;
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) ISymbol(org.matheclipse.core.interfaces.ISymbol) BigRational(edu.jas.arith.BigRational) ArrayList(java.util.ArrayList) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) GroebnerBasePartial(edu.jas.gbufd.GroebnerBasePartial) JASConvert(org.matheclipse.core.convert.JASConvert) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

BigRational (edu.jas.arith.BigRational)1 GroebnerBasePartial (edu.jas.gbufd.GroebnerBasePartial)1 GenPolynomial (edu.jas.poly.GenPolynomial)1 ArrayList (java.util.ArrayList)1 JASConvert (org.matheclipse.core.convert.JASConvert)1 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)1 IAST (org.matheclipse.core.interfaces.IAST)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1