Search in sources :

Example 1 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.

the class Limit method timesLimit.

private static IExpr timesLimit(final IAST timesAST, LimitData data) {
    IAST isFreeResult = timesAST.partitionTimes(Predicates.isFree(data.getSymbol()), F.C1, F.C1, F.List);
    if (!isFreeResult.get(1).isOne()) {
        return F.Times(isFreeResult.get(1), data.limit(isFreeResult.get(2)));
    }
    IExpr[] parts = Algebra.fractionalPartsTimesPower(timesAST, false, false, true, true);
    if (parts != null) {
        IExpr numerator = parts[0];
        IExpr denominator = parts[1];
        IExpr limit = data.getLimitValue();
        ISymbol symbol = data.getSymbol();
        if (limit.isInfinity() || limit.isNegativeInfinity()) {
            try {
                ExprPolynomialRing ring = new ExprPolynomialRing(symbol);
                ExprPolynomial denominatorPoly = ring.create(denominator);
                ExprPolynomial numeratorPoly = ring.create(numerator);
                return limitsInfinityOfRationalFunctions(numeratorPoly, denominatorPoly, symbol, limit, data);
            } catch (RuntimeException e) {
                if (Config.DEBUG) {
                    e.printStackTrace();
                }
            }
        }
        IExpr plusResult = Algebra.partialFractionDecompositionRational(new PartialFractionGenerator(), parts, symbol);
        if (plusResult.isPlus()) {
            // if (plusResult.size() > 2) {
            return data.mapLimit((IAST) plusResult);
        // }
        }
        if (denominator.isOne()) {
            if (limit.isInfinity() || limit.isNegativeInfinity()) {
                IExpr temp = substituteInfinity(timesAST, data);
                if (temp.isPresent()) {
                    return temp;
                }
            }
        }
        IExpr temp = numeratorDenominatorLimit(numerator, denominator, data);
        if (temp.isPresent()) {
            return temp;
        }
    }
    return data.mapLimit(timesAST);
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial) PartialFractionGenerator(org.matheclipse.core.polynomials.PartialFractionGenerator)

Example 2 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.

the class CoefficientList method univariateCoefficientList.

/**
	 * 
	 * @param polynomial
	 * @param variable
	 * @param resultList
	 *            the coefficient list of the given univariate polynomial in increasing order
	 * @param resultListDiff
	 *            the coefficient list of the derivative of the given univariate polynomial
	 * @return the degree of the univariate polynomial; if <code>degree >= Short.MAX_VALUE</code>, the result list will be empty.
	 */
public static long univariateCoefficientList(IExpr polynomial, ISymbol variable, List<IExpr> resultList, List<IExpr> resultListDiff) throws JASConversionException {
    try {
        ExprPolynomialRing ring = new ExprPolynomialRing(F.List(variable));
        ExprPolynomial poly = ring.create(polynomial);
        // PolynomialOld poly = new PolynomialOld(polynomial, (ISymbol) variable);
        // if (!poly.isPolynomial()) {
        // throw new WrongArgumentType(polynomial, "Polynomial expected!");
        // }
        IAST polyExpr = poly.coefficientList();
        int degree = polyExpr.size() - 2;
        if (degree >= Short.MAX_VALUE) {
            return degree;
        }
        for (int i = 0; i <= degree; i++) {
            IExpr temp = polyExpr.get(i + 1);
            resultList.add(temp);
        }
        IAST polyDiff = poly.derivative().coefficientList();
        int degreeDiff = polyDiff.size() - 2;
        for (int i = 0; i <= degreeDiff; i++) {
            IExpr temp = polyDiff.get(i + 1);
            resultListDiff.add(temp);
        }
        return degree;
    } catch (RuntimeException ex) {
        throw new WrongArgumentType(polynomial, "Polynomial expected!");
    }
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 3 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.

the class PolynomialExample method main.

public static void main(String[] args) {
    try {
        ExprEvaluator util = new ExprEvaluator();
        IExpr expr = util.evaluate("x^2+y+a*x+b*y+c");
        System.out.println(expr.toString());
        final IAST variables = F.List(F.x, F.y);
        ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, variables, variables.size() - 1, ExprTermOrderByName.Lexicographic, false);
        ExprPolynomial poly = ring.create(expr);
        System.out.println(poly.toString());
        // x degree
        System.out.println(poly.degree(0));
        // y degree
        System.out.println(poly.degree(1));
        // show internal structure:
        System.out.println(poly.coefficientRules());
        System.out.println();
        for (ExprMonomial monomial : poly) {
            System.out.println(monomial.toString());
        }
    } catch (SyntaxError e) {
        // catch Symja parser errors here
        System.out.println(e.getMessage());
    } catch (MathException me) {
        // catch Symja math errors here
        System.out.println(me.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    } catch (final StackOverflowError soe) {
        System.out.println(soe.getMessage());
    } catch (final OutOfMemoryError oome) {
        System.out.println(oome.getMessage());
    }
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ExprEvaluator(org.matheclipse.core.eval.ExprEvaluator) SyntaxError(org.matheclipse.parser.client.SyntaxError) MathException(org.matheclipse.parser.client.math.MathException) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ExprMonomial(org.matheclipse.core.polynomials.ExprMonomial) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial) MathException(org.matheclipse.parser.client.math.MathException)

Example 4 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.

the class AbstractAST method isPolynomialOfMaxDegree.

public final boolean isPolynomialOfMaxDegree(IAST variables, long maxDegree) {
    try {
        if (isPlus() || isTimes() || isPower()) {
            IExpr expr = F.evalExpandAll(this);
            ExprPolynomialRing ring = new ExprPolynomialRing(variables);
            ExprPolynomial poly = ring.create(expr);
            return poly.degree() <= maxDegree;
        }
    } catch (RuntimeException ex) {
    //
    }
    return false;
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 5 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.

the class AbstractAST method isPolynomial.

/** {@inheritDoc} */
@Override
public final boolean isPolynomial(IAST variables) {
    if (isPlus() || isTimes() || isPower()) {
        IExpr expr = F.evalExpandAll(this);
        ExprPolynomialRing ring = new ExprPolynomialRing(variables);
        return ring.isPolynomial(expr);
    }
    return false;
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)17 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)15 IExpr (org.matheclipse.core.interfaces.IExpr)14 IAST (org.matheclipse.core.interfaces.IAST)12 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)5 VariablesSet (org.matheclipse.core.convert.VariablesSet)4 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)4 ISymbol (org.matheclipse.core.interfaces.ISymbol)4 JASIExpr (org.matheclipse.core.convert.JASIExpr)3 TermOrder (edu.jas.poly.TermOrder)2 Options (org.matheclipse.core.eval.util.Options)2 IStringX (org.matheclipse.core.interfaces.IStringX)2 ExprTermOrder (org.matheclipse.core.polynomials.ExprTermOrder)2 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)1 ASTRange (org.matheclipse.core.expression.ASTRange)1 IInteger (org.matheclipse.core.interfaces.IInteger)1 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)1 ExpVectorLong (org.matheclipse.core.polynomials.ExpVectorLong)1 ExprMonomial (org.matheclipse.core.polynomials.ExprMonomial)1 PartialFractionGenerator (org.matheclipse.core.polynomials.PartialFractionGenerator)1