Search in sources :

Example 11 with GenPolynomial

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);
    }
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 12 with GenPolynomial

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);
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) BigRational(edu.jas.arith.BigRational) BigInteger(java.math.BigInteger)

Example 13 with GenPolynomial

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);
    }
}
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 14 with GenPolynomial

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;
}
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

GenPolynomial (edu.jas.poly.GenPolynomial)14 IAST (org.matheclipse.core.interfaces.IAST)11 BigRational (edu.jas.arith.BigRational)9 IExpr (org.matheclipse.core.interfaces.IExpr)7 ModLong (edu.jas.arith.ModLong)5 ISymbol (org.matheclipse.core.interfaces.ISymbol)4 BigInteger (edu.jas.arith.BigInteger)3 ArrayList (java.util.ArrayList)3 SortedMap (java.util.SortedMap)3 JASConvert (org.matheclipse.core.convert.JASConvert)3 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)3 IFraction (org.matheclipse.core.interfaces.IFraction)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 Complex (edu.jas.poly.Complex)2 ComplexRing (edu.jas.poly.ComplexRing)2 ExpVector (edu.jas.poly.ExpVector)2 TermOrder (edu.jas.poly.TermOrder)2 BigInteger (java.math.BigInteger)2 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)2 IComplex (org.matheclipse.core.interfaces.IComplex)2