Search in sources :

Example 1 with BigRational

use of edu.jas.arith.BigRational 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)

Example 2 with BigRational

use of edu.jas.arith.BigRational in project symja_android_library by axkr.

the class JASConvert method integral2Expr.

/**
	 * Convert a jas <code>Integral</code> into a matheclipse expression
	 * 
	 * @param integral
	 *            the JAS Integral
	 * @return
	 */
public IAST integral2Expr(Integral<BigRational> integral) {
    IAST sum = F.Plus();
    GenPolynomial<BigRational> pol = integral.pol;
    List<GenPolynomial<BigRational>> rational = integral.rational;
    List<LogIntegral<BigRational>> logarithm = integral.logarithm;
    if (!pol.isZERO()) {
        sum.append(rationalPoly2Expr(pol));
    }
    if (rational.size() != 0) {
        int i = 0;
        while (i < rational.size()) {
            sum.append(F.Times(rationalPoly2Expr(rational.get(i++)), F.Power(rationalPoly2Expr(rational.get(i++)), F.CN1)));
        }
    }
    if (logarithm.size() != 0) {
        for (LogIntegral<BigRational> pf : logarithm) {
            sum.append(logIntegral2Expr(pf));
        }
    }
    return sum;
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) IAST(org.matheclipse.core.interfaces.IAST) LogIntegral(edu.jas.integrate.LogIntegral)

Example 3 with BigRational

use of edu.jas.arith.BigRational in project symja_android_library by axkr.

the class JASConvert method rationalPoly2Expr.

/**
	 * Converts a <a href="http://krum.rz.uni-mannheim.de/jas/">JAS</a>
	 * polynomial to a MathEclipse AST with head <code>Plus</code>
	 * 
	 * @param poly
	 *            a JAS polynomial
	 * @param variable
	 * @return
	 * @throws ArithmeticException
	 * @throws ClassCastException
	 */
public IAST rationalPoly2Expr(final GenPolynomial<BigRational> poly) throws ArithmeticException, ClassCastException {
    if (poly.length() == 0) {
        return F.Plus(F.C0);
    }
    IAST result = F.Plus();
    for (Monomial<BigRational> monomial : poly) {
        BigRational coeff = monomial.coefficient();
        ExpVector exp = monomial.exponent();
        IAST monomTimes = F.Times();
        monomialToExpr(coeff, exp, monomTimes);
        result.append(monomTimes.getOneIdentity(F.C1));
    }
    return result;
}
Also used : BigRational(edu.jas.arith.BigRational) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST)

Example 4 with BigRational

use of edu.jas.arith.BigRational in project symja_android_library by axkr.

the class JASConvert method logIntegral2Expr.

/**
	 * Convert a jas <code>LogIntegral</code> into a matheclipse expression
	 * 
	 * @param logIntegral
	 *            the JAS LogIntegral
	 * @return
	 */
public IAST logIntegral2Expr(LogIntegral<BigRational> logIntegral) {
    IAST plus = F.Plus();
    List<BigRational> cfactors = logIntegral.cfactors;
    List<GenPolynomial<BigRational>> cdenom = logIntegral.cdenom;
    List<AlgebraicNumber<BigRational>> afactors = logIntegral.afactors;
    List<GenPolynomial<AlgebraicNumber<BigRational>>> adenom = logIntegral.adenom;
    if (cfactors.size() > 0) {
        for (int i = 0; i < cfactors.size(); i++) {
            BigRational cp = cfactors.get(i);
            GenPolynomial<BigRational> p = cdenom.get(i);
            plus.append(F.Times(F.fraction(cp.numerator(), cp.denominator()), F.Log(rationalPoly2Expr(p))));
        }
    }
    // TODO implement this conversion for AlgebraicNumbers...
    if (afactors.size() > 0) {
        for (int i = 0; i < afactors.size(); i++) {
            AlgebraicNumber<BigRational> ap = afactors.get(i);
            AlgebraicNumberRing<BigRational> ar = ap.factory();
            GenPolynomial<AlgebraicNumber<BigRational>> p = adenom.get(i);
            if (p.degree(0) < ar.modul.degree(0) && ar.modul.degree(0) > 2) {
            }
            GenPolynomial<BigRational> v = ap.getVal();
            IAST times = F.Times();
            if (p.degree(0) < ar.modul.degree(0) && ar.modul.degree(0) > 2) {
                IAST rootOf = F.ast(F.RootOf);
                rootOf.append(rationalPoly2Expr(ar.modul));
                times.append(rootOf);
                throw new UnsupportedOperationException("JASConvert#logIntegral2Expr()");
            }
            times.append(rationalPoly2Expr(v));
            times.append(F.Log(polyAlgebraicNumber2Expr(p)));
            plus.append(times);
        }
    }
    return plus;
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) AlgebraicNumber(edu.jas.poly.AlgebraicNumber) IAST(org.matheclipse.core.interfaces.IAST)

Example 5 with BigRational

use of edu.jas.arith.BigRational in project symja_android_library by axkr.

the class JASIExpr method complexPoly2Expr.

/**
	 * Convert a JAS complex polynomial to <code>IExpr</code>.
	 * 
	 * @param poly
	 * @return
	 * @throws ArithmeticException
	 * @throws ClassCastException
	 */
public IExpr complexPoly2Expr(final GenPolynomial<Complex<BigRational>> poly) throws ArithmeticException, ClassCastException {
    if (poly.length() == 0) {
        return F.C0;
    }
    IAST result = F.Plus();
    for (Monomial<Complex<BigRational>> monomial : poly) {
        Complex<BigRational> coeff = monomial.coefficient();
        ExpVector exp = monomial.exponent();
        BigRational re = coeff.getRe();
        BigRational im = coeff.getIm();
        IAST monomTimes = F.Times(F.complex(F.fraction(re.numerator(), re.denominator()), F.fraction(im.numerator(), im.denominator())));
        long lExp;
        for (int i = 0; i < exp.length(); i++) {
            lExp = exp.getVal(i);
            if (lExp != 0) {
                monomTimes.append(F.Power(fVariables.get(i), F.integer(lExp)));
            }
        }
        if (monomTimes.isAST1()) {
            result.append(monomTimes.arg1());
        } else {
            result.append(monomTimes);
        }
    }
    if (result.isAST1()) {
        return result.arg1();
    } else {
        return result;
    }
}
Also used : BigRational(edu.jas.arith.BigRational) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST) Complex(edu.jas.poly.Complex)

Aggregations

BigRational (edu.jas.arith.BigRational)20 IAST (org.matheclipse.core.interfaces.IAST)13 GenPolynomial (edu.jas.poly.GenPolynomial)9 ExpVector (edu.jas.poly.ExpVector)6 IExpr (org.matheclipse.core.interfaces.IExpr)6 Complex (edu.jas.poly.Complex)5 JASConvert (org.matheclipse.core.convert.JASConvert)5 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)5 ComplexRing (edu.jas.poly.ComplexRing)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 ASTRange (org.matheclipse.core.expression.ASTRange)3 IComplex (org.matheclipse.core.interfaces.IComplex)3 BigInteger (edu.jas.arith.BigInteger)2 ModLong (edu.jas.arith.ModLong)2 LogIntegral (edu.jas.integrate.LogIntegral)2 AlgebraicNumber (edu.jas.poly.AlgebraicNumber)2 TermOrder (edu.jas.poly.TermOrder)2 SortedMap (java.util.SortedMap)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2