Search in sources :

Example 11 with ExprPolynomialRing

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

the class MonomialList method evaluate.

@Override
public IExpr evaluate(final IAST ast, final EvalEngine engine) {
    Validate.checkRange(ast, 2, 5);
    IExpr expr = F.evalExpandAll(ast.arg1());
    VariablesSet eVar;
    IAST symbolList = F.List();
    List<IExpr> varList;
    if (ast.isAST1()) {
        // extract all variables from the polynomial expression
        eVar = new VariablesSet(ast.arg1());
        eVar.appendToList(symbolList.args());
        varList = eVar.getArrayList();
    } else {
        symbolList = Validate.checkSymbolOrSymbolList(ast, 2);
        varList = new ArrayList<IExpr>(symbolList.size() - 1);
        for (int i = 1; i < symbolList.size(); i++) {
            varList.add(symbolList.get(i));
        }
    }
    TermOrder termOrder = TermOrderByName.Lexicographic;
    try {
        if (ast.size() > 3) {
            if (ast.arg3() instanceof IStringX) {
                // NegativeLexicographic
                String orderStr = ast.arg3().toString();
                termOrder = Options.getMonomialOrder(orderStr, termOrder);
            }
            final Options options = new Options(ast.topHead(), ast, 2, engine);
            IExpr option = options.getOption("Modulus");
            if (option.isSignedNumber()) {
                return monomialListModulus(expr, varList, termOrder, option);
            }
        }
        if (USE_JAS_POLYNOMIAL) {
            return monomialList(expr, varList, termOrder);
        } else {
            ExprPolynomialRing ring = new ExprPolynomialRing(symbolList, new ExprTermOrder(termOrder.getEvord()));
            ExprPolynomial poly = ring.create(expr);
            return poly.monomialList();
        }
    } catch (JASConversionException jce) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            jce.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) VariablesSet(org.matheclipse.core.convert.VariablesSet) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 12 with ExprPolynomialRing

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

the class Limit method plusLimit.

private static IExpr plusLimit(final IAST arg1, LimitData data) {
    // Limit[a_+b_+c_,sym->lim] ->
    // Limit[a,sym->lim]+Limit[b,sym->lim]+Limit[c,sym->lim]
    // IAST rule = data.getRule();
    IExpr limit = data.getLimitValue();
    if (limit.isInfinity() || limit.isNegativeInfinity()) {
        ISymbol symbol = data.getSymbol();
        try {
            ExprPolynomialRing ring = new ExprPolynomialRing(symbol);
            ExprPolynomial poly = ring.create(arg1);
            IExpr coeff = poly.leadingBaseCoefficient();
            long oddDegree = poly.degree() % 2;
            if (oddDegree == 1) {
                // odd degree
                return data.limit(F.Times(coeff, limit));
            }
            // even degree
            return data.limit(F.Times(coeff, F.CInfinity));
        } catch (RuntimeException e) {
            if (Config.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    return data.mapLimit(arg1);
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ISymbol(org.matheclipse.core.interfaces.ISymbol) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 13 with ExprPolynomialRing

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

the class CoefficientList method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    IExpr expr = F.evalExpandAll(ast.arg1());
    ISymbol arg2 = Validate.checkSymbolType(ast, 2);
    try {
        ExprPolynomialRing ring = new ExprPolynomialRing(F.List(arg2));
        ExprPolynomial poly = ring.create(expr);
        if (poly.isZero()) {
            return F.List();
        }
        return poly.coefficientList();
    } catch (RuntimeException ex) {
        throw new WrongArgumentType(ast, expr, 1, "Polynomial expected!");
    }
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ISymbol(org.matheclipse.core.interfaces.ISymbol) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IExpr(org.matheclipse.core.interfaces.IExpr) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 14 with ExprPolynomialRing

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

the class CoefficientList method coefficientList.

/**
	 * Get the coefficient list of a univariate polynomial.
	 * 
	 * @param polynomial
	 * @param variable
	 * @return <code>null</code> if the list couldn't be evaluated.
	 */
public static double[] coefficientList(IExpr polynomial, final ISymbol variable) 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 list = poly.coefficientList();
        int degree = list.size() - 2;
        double[] result = new double[degree + 1];
        for (int i = 1; i < list.size(); i++) {
            ISignedNumber temp = list.get(i).evalSignedNumber();
            if (temp != null) {
                result[i - 1] = temp.doubleValue();
            } else {
                return null;
            }
        }
        return result;
    } catch (RuntimeException ex) {
        throw new WrongArgumentType(polynomial, "Polynomial expected!");
    }
}
Also used : ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

Example 15 with ExprPolynomialRing

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

the class CoefficientRules method evaluate.

@Override
public IExpr evaluate(final IAST ast, final EvalEngine engine) {
    Validate.checkRange(ast, 2, 5);
    IExpr expr = F.evalExpandAll(ast.arg1());
    VariablesSet eVar;
    IAST symbolList = F.List();
    List<IExpr> varList;
    if (ast.isAST1()) {
        // extract all variables from the polynomial expression
        eVar = new VariablesSet(ast.arg1());
        eVar.appendToList(symbolList.args());
        varList = eVar.getArrayList();
    } else {
        symbolList = Validate.checkSymbolOrSymbolList(ast, 2);
        varList = new ArrayList<IExpr>(symbolList.size() - 1);
        for (int i = 1; i < symbolList.size(); i++) {
            varList.add((ISymbol) symbolList.get(i));
        }
    }
    TermOrder termOrder = TermOrderByName.Lexicographic;
    try {
        if (ast.size() > 3) {
            if (ast.arg3() instanceof IStringX) {
                String orderStr = ast.arg3().toString();
                termOrder = Options.getMonomialOrder(orderStr, termOrder);
            }
            final Options options = new Options(ast.topHead(), ast, 2, engine);
            IExpr option = options.getOption("Modulus");
            if (option.isSignedNumber()) {
                return coefficientRulesModulus(expr, varList, termOrder, option);
            }
        }
        if (MonomialList.USE_JAS_POLYNOMIAL) {
            return coefficientRules(expr, varList, termOrder);
        } else {
            ExprPolynomialRing ring = new ExprPolynomialRing(symbolList, new ExprTermOrder(termOrder.getEvord()));
            ExprPolynomial poly = ring.create(expr);
            return poly.coefficientRules();
        }
    } catch (JASConversionException jce) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            jce.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) TermOrder(edu.jas.poly.TermOrder) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) VariablesSet(org.matheclipse.core.convert.VariablesSet) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) ExprPolynomialRing(org.matheclipse.core.polynomials.ExprPolynomialRing) ExprTermOrder(org.matheclipse.core.polynomials.ExprTermOrder) JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) ExprPolynomial(org.matheclipse.core.polynomials.ExprPolynomial)

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