Search in sources :

Example 11 with IStringX

use of org.matheclipse.core.interfaces.IStringX 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 IStringX

use of org.matheclipse.core.interfaces.IStringX 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

IStringX (org.matheclipse.core.interfaces.IStringX)12 IExpr (org.matheclipse.core.interfaces.IExpr)9 IAST (org.matheclipse.core.interfaces.IAST)7 IOException (java.io.IOException)5 WrongNumberOfArguments (org.matheclipse.core.eval.exception.WrongNumberOfArguments)5 TermOrder (edu.jas.poly.TermOrder)2 FileReader (java.io.FileReader)2 FileWriter (java.io.FileWriter)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 VariablesSet (org.matheclipse.core.convert.VariablesSet)2 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)2 Options (org.matheclipse.core.eval.util.Options)2 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)2 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)2 ExprTermOrder (org.matheclipse.core.polynomials.ExprTermOrder)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1