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);
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations