Search in sources :

Example 16 with BigRational

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

the class JASConvert method monomialToExpr.

public boolean monomialToExpr(Complex<BigRational> coeff, ExpVector exp, IAST monomTimes) {
    BigRational re = coeff.getRe();
    BigRational im = coeff.getIm();
    monomTimes.append(F.complex(F.fraction(re.numerator(), re.denominator()), F.fraction(im.numerator(), im.denominator())));
    return expVectorToExpr(exp, monomTimes);
}
Also used : BigRational(edu.jas.arith.BigRational)

Example 17 with BigRational

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

the class JASConvert method polyAlgebraicNumber2Expr.

public IAST polyAlgebraicNumber2Expr(final GenPolynomial<AlgebraicNumber<BigRational>> poly) throws ArithmeticException, ClassCastException {
    if (poly.length() == 0) {
        return F.Plus(F.C0);
    }
    SortedMap<ExpVector, AlgebraicNumber<BigRational>> val = poly.getMap();
    if (val.size() == 0) {
        return F.Plus(F.C0);
    } else {
        IAST result = F.Plus();
        for (Map.Entry<ExpVector, AlgebraicNumber<BigRational>> m : val.entrySet()) {
            AlgebraicNumber<BigRational> coeff = m.getValue();
            IAST monomTimes = F.Times();
            ExpVector exp = m.getKey();
            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) Map(java.util.Map) SortedMap(java.util.SortedMap) AlgebraicNumber(edu.jas.poly.AlgebraicNumber)

Example 18 with BigRational

use of edu.jas.arith.BigRational 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);
    }
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) ComplexRing(edu.jas.poly.ComplexRing) BigInteger(java.math.BigInteger) IComplex(org.matheclipse.core.interfaces.IComplex) Complex(edu.jas.poly.Complex)

Example 19 with BigRational

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

the class JASConvert method quotIntegral2Expr.

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

Example 20 with BigRational

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

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