Search in sources :

Example 1 with Options

use of org.matheclipse.core.eval.util.Options in project symja_android_library by axkr.

the class Limit method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3, 4);
    if (!ast.arg2().isRuleAST()) {
        throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: rule definition expected!");
    }
    IAST rule = (IAST) ast.arg2();
    if (!(rule.arg1().isSymbol())) {
        throw new WrongArgumentType(ast, ast.arg1(), 2, "Limit: variable symbol for rule definition expected!");
    }
    // no direction as default
    int direction = DIRECTION_AUTOMATIC;
    if (ast.isAST3()) {
        final Options options = new Options(ast.topHead(), ast, 2, engine);
        IExpr option = options.getOption("Direction");
        if (option.isPresent()) {
            if (option.isOne()) {
                direction = DIRECTION_FROM_SMALLER_VALUES;
            } else if (option.isMinusOne()) {
                direction = DIRECTION_FROM_LARGER_VALUES;
            } else if (option.equals(F.Automatic)) {
                direction = DIRECTION_AUTOMATIC;
            } else {
                throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: direction option expected!");
            }
        } else {
            throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: direction option expected!");
        }
    }
    ISymbol symbol = (ISymbol) rule.arg1();
    IExpr limit = null;
    if (rule.isFreeAt(2, symbol)) {
        limit = rule.arg2();
    } else {
        throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: limit value contains variable symbol for rule definition!");
    }
    if (ast.isAST2() && direction == DIRECTION_AUTOMATIC) {
        // check if there's a direction specific rule available in the rule database
        IExpr temp = engine.evalLoop(F.Limit(ast.arg1(), ast.arg2(), F.Rule(F.Direction, F.CN1)));
        if (temp.isPresent()) {
            return temp;
        }
    }
    LimitData data = new LimitData(symbol, limit, rule, direction);
    return evalLimit(ast.arg1(), data, true);
}
Also used : Options(org.matheclipse.core.eval.util.Options) ISymbol(org.matheclipse.core.interfaces.ISymbol) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 2 with Options

use of org.matheclipse.core.eval.util.Options in project symja_android_library by axkr.

the class Refine method determineAssumptions.

public static IAssumptions determineAssumptions(final ISymbol symbol, final IExpr arg2, EvalEngine engine) {
    final Options options = new Options(symbol, arg2, engine);
    IExpr option = options.getOption("Assumptions");
    if (option.isPresent()) {
        return Assumptions.getInstance(option);
    } else {
        return Assumptions.getInstance(arg2);
    }
}
Also used : Options(org.matheclipse.core.eval.util.Options) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 3 with Options

use of org.matheclipse.core.eval.util.Options in project symja_android_library by axkr.

the class FindRoot method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3);
    ISymbol method = Newton;
    int maxIterations = 100;
    if (ast.size() >= 4) {
        final Options options = new Options(ast.topHead(), ast, 3, engine);
        IExpr optionMaxIterations = options.getOption("MaxIterations");
        if (optionMaxIterations.isSignedNumber()) {
            maxIterations = ((ISignedNumber) optionMaxIterations).toInt();
        }
        IExpr optionMethod = options.getOption("Method");
        if (optionMethod.isSymbol()) {
            method = ((ISymbol) optionMethod);
        } else {
            if (ast.arg3().isSymbol()) {
                method = (ISymbol) ast.arg3();
            }
        }
    }
    if ((ast.arg2().isList())) {
        IAST list = (IAST) ast.arg2();
        IExpr function = ast.arg1();
        if (list.size() >= 3 && list.arg1().isSymbol()) {
            if (function.isAST(F.Equal, 3)) {
                function = F.Plus(((IAST) function).arg1(), F.Negate(((IAST) function).arg2()));
            }
            ISignedNumber min = list.arg2().evalSignedNumber();
            ISignedNumber max = null;
            if (list.size() > 3) {
                max = list.arg3().evalSignedNumber();
            }
            if (min != null) {
                return F.List(F.Rule(list.arg1(), Num.valueOf(findRoot(method, maxIterations, list, min, max, function, engine))));
            }
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) ISymbol(org.matheclipse.core.interfaces.ISymbol) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 4 with Options

use of org.matheclipse.core.eval.util.Options in project symja_android_library by axkr.

the class JavaForm method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 2, 3);
    IExpr arg1 = engine.evaluate(ast.arg1());
    boolean strictJava = false;
    if (ast.isAST2()) {
        IExpr arg2 = engine.evaluate(ast.arg2());
        final Options options = new Options(ast.topHead(), arg2, engine);
        strictJava = options.isOption("Strict");
    }
    String resultStr = javaForm(arg1, strictJava);
    return F.$str(resultStr);
}
Also used : Options(org.matheclipse.core.eval.util.Options) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 5 with Options

use of org.matheclipse.core.eval.util.Options in project symja_android_library by axkr.

the class NIntegrate method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3);
    ISymbol method = LegendreGauss;
    int maxPoints = DEFAULT_MAX_POINTS;
    int maxIterations = DEFAULT_MAX_ITERATIONS;
    // automatic scale value
    int precisionGoal = 16;
    if (ast.size() >= 4) {
        final Options options = new Options(ast.topHead(), ast, 3, engine);
        IExpr option = options.getOption("Method");
        if (option.isSymbol()) {
            method = (ISymbol) option;
        }
        option = options.getOption("MaxPoints");
        if (option.isSignedNumber()) {
            try {
                maxPoints = ((ISignedNumber) option).toInt();
            } catch (ArithmeticException ae) {
                engine.printMessage("Error in option MaxPoints. Using default value: " + maxPoints);
            }
        }
        option = options.getOption("MaxIterations");
        if (option.isSignedNumber()) {
            try {
                maxIterations = ((ISignedNumber) option).toInt();
            } catch (ArithmeticException ae) {
                engine.printMessage("Error in option MaxIterations. Using default value: " + maxIterations);
            }
        }
        option = options.getOption("PrecisionGoal");
        if (option.isSignedNumber()) {
            try {
                precisionGoal = ((ISignedNumber) option).toInt();
            } catch (ArithmeticException ae) {
                engine.printMessage("Error in option PrecisionGoal. Using default value: " + precisionGoal);
            }
        }
    }
    if (ast.arg2().isList()) {
        IAST list = (IAST) ast.arg2();
        IExpr function = ast.arg1();
        if (list.isAST3() && list.arg1().isSymbol()) {
            ISignedNumber min = list.arg2().evalSignedNumber();
            ISignedNumber max = list.arg3().evalSignedNumber();
            if (min != null && max != null) {
                if (function.isAST(F.Equal, 3)) {
                    function = F.Plus(((IAST) function).arg1(), F.Negate(((IAST) function).arg2()));
                }
                try {
                    double result = integrate(method.getSymbolName(), list, min.doubleValue(), max.doubleValue(), function, maxPoints, maxIterations);
                    result = Precision.round(result, precisionGoal);
                    return Num.valueOf(result);
                } catch (Exception e) {
                    throw new WrappedException(e);
                }
            }
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) WrappedException(org.matheclipse.core.eval.exception.WrappedException) ISymbol(org.matheclipse.core.interfaces.ISymbol) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) WrappedException(org.matheclipse.core.eval.exception.WrappedException) MathIllegalStateException(org.hipparchus.exception.MathIllegalStateException)

Aggregations

Options (org.matheclipse.core.eval.util.Options)9 IExpr (org.matheclipse.core.interfaces.IExpr)8 IAST (org.matheclipse.core.interfaces.IAST)6 ISymbol (org.matheclipse.core.interfaces.ISymbol)4 TermOrder (edu.jas.poly.TermOrder)3 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 VariablesSet (org.matheclipse.core.convert.VariablesSet)2 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)2 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)2 IStringX (org.matheclipse.core.interfaces.IStringX)2 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)2 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)2 ExprTermOrder (org.matheclipse.core.polynomials.ExprTermOrder)2 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)1 MathIllegalStateException (org.hipparchus.exception.MathIllegalStateException)1 FastFourierTransformer (org.hipparchus.transform.FastFourierTransformer)1 WrappedException (org.matheclipse.core.eval.exception.WrappedException)1 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)1 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)1