Search in sources :

Example 1 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.longexponent.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 (ArithmeticException | ClassCastException ex) {
    // 
    }
    return false;
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.longexponent.ExprPolynomialRing) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.longexponent.ExprPolynomial)

Example 2 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.longexponent.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.longexponent.ExprPolynomialRing) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 3 with ExprPolynomialRing

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

the class MinMaxFunctions method minimizeExprPolynomial.

private static IAST minimizeExprPolynomial(final IExpr expr, IAST varList) {
    IAST result = F.NIL;
    try {
        // try to generate a common expression polynomial
        ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, varList);
        ExprPolynomial ePoly = ring.create(expr, false, false, false);
        ePoly = ePoly.multiplyByMinimumNegativeExponents();
        result = minimizeCubicPolynomial(ePoly, varList.arg1());
        // result = QuarticSolver.sortASTArguments(result);
        return result;
    } catch (ArithmeticException | JASConversionException e2) {
        LOGGER.debug("MinMaxFunctions.minimizeExprPolynomial() failed", e2);
    }
    return result;
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.longexponent.ExprPolynomialRing) IAST(org.matheclipse.core.interfaces.IAST) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomial(org.matheclipse.core.polynomials.longexponent.ExprPolynomial)

Example 4 with ExprPolynomialRing

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

the class RootsFunctions method rootsOfExprPolynomial.

public static IASTMutable rootsOfExprPolynomial(final IExpr expr, IAST varList, boolean rootsOfQuartic) {
    IASTMutable result = F.NIL;
    try {
        // try to generate a common expression polynomial
        ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, varList);
        ExprPolynomial ePoly = ring.create(expr, false, false, false);
        ePoly = ePoly.multiplyByMinimumNegativeExponents();
        if (ePoly.degree(0) >= Integer.MAX_VALUE) {
            return F.NIL;
        }
        if (ePoly.degree(0) >= 3) {
            result = unitPolynomial((int) ePoly.degree(0), ePoly);
            if (result.isPresent()) {
                result = QuarticSolver.sortASTArguments(result);
                return result;
            }
        }
        if (!rootsOfQuartic && ePoly.degree(0) > 2) {
            return F.NIL;
        }
        result = rootsOfQuarticPolynomial(ePoly);
        if (result.isPresent()) {
            if (expr.isNumericMode()) {
                for (int i = 1; i < result.size(); i++) {
                    result.set(i, F.chopExpr(result.get(i), Config.DEFAULT_ROOTS_CHOP_DELTA));
                }
            }
            result = QuarticSolver.sortASTArguments(result);
            return result;
        }
    } catch (JASConversionException e2) {
        LOGGER.debug("RootsFunctions.rootsOfExprPolynomial() failed", e2);
    }
    return F.NIL;
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.longexponent.ExprPolynomialRing) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomial(org.matheclipse.core.polynomials.longexponent.ExprPolynomial)

Example 5 with ExprPolynomialRing

use of org.matheclipse.core.polynomials.longexponent.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.eval("x^2+y+a*x+b*y+c");
        System.out.println(expr.toString());
        final IAST variables = F.List(F.symbol("x"), F.symbol("y"));
        ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, variables, variables.argSize(), 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.longexponent.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.longexponent.ExprMonomial) ExprPolynomial(org.matheclipse.core.polynomials.longexponent.ExprPolynomial) MathException(org.matheclipse.parser.client.math.MathException)

Aggregations

ExprPolynomialRing (org.matheclipse.core.polynomials.longexponent.ExprPolynomialRing)12 ExprPolynomial (org.matheclipse.core.polynomials.longexponent.ExprPolynomial)11 IAST (org.matheclipse.core.interfaces.IAST)7 IExpr (org.matheclipse.core.interfaces.IExpr)6 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)4 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)2 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)2 ExprMonomial (org.matheclipse.core.polynomials.longexponent.ExprMonomial)2 SyntaxError (org.matheclipse.parser.client.SyntaxError)2 MathException (org.matheclipse.parser.client.math.MathException)2 BigRational (edu.jas.arith.BigRational)1 Complex (edu.jas.poly.Complex)1 ComplexRing (edu.jas.poly.ComplexRing)1 FactorComplex (edu.jas.ufd.FactorComplex)1 JASConvert (org.matheclipse.core.convert.JASConvert)1 JASIExpr (org.matheclipse.core.convert.JASIExpr)1 VariablesSet (org.matheclipse.core.convert.VariablesSet)1 LimitException (org.matheclipse.core.eval.exception.LimitException)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 IComplex (org.matheclipse.core.interfaces.IComplex)1