use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class Roots method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 3);
IExpr arg1 = ast.arg1();
if (arg1.isAST(F.Equal, 3)) {
IAST eq = (IAST) arg1;
if (eq.arg2().isZero()) {
arg1 = eq.arg1();
} else {
arg1 = engine.evaluate(F.Subtract(eq.arg1(), eq.arg2()));
}
} else {
throw new WrongArgumentType(ast, ast.arg1(), 1, "Equal() expression expected!");
}
VariablesSet eVar = null;
if (ast.arg2().isList()) {
eVar = new VariablesSet(ast.arg2());
} else {
eVar = new VariablesSet();
eVar.add(ast.arg2());
}
if (!eVar.isSize(1)) {
// factorization only possible for univariate polynomials
throw new WrongArgumentType(ast, ast.arg2(), 2, "Only one variable expected");
}
IAST variables = eVar.getVarList();
IExpr variable = variables.arg1();
IAST list = roots(arg1, false, variables, engine);
if (list.isPresent()) {
IAST or = F.Or();
for (int i = 1; i < list.size(); i++) {
or.append(F.Equal(variable, list.get(i)));
}
return or;
}
return F.NIL;
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class ReplaceAll method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (ast.isAST1()) {
return F.operatorFormAST1(ast);
}
Validate.checkSize(ast, 3);
try {
if (ast.arg2().isListOfLists()) {
IAST result = F.List();
for (IExpr subList : (IAST) ast.arg2()) {
result.append(F.subst(ast.arg1(), (IAST) subList));
}
return result;
}
if (ast.arg2().isAST()) {
return F.subst(ast.arg1(), (IAST) ast.arg2());
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
engine.printMessage(wat.getMessage());
}
} catch (WrongArgumentType wat) {
engine.printMessage(wat.getMessage());
}
return F.NIL;
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class ReplaceList method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (!ToggleFeature.REPLACE_LIST) {
return F.NIL;
}
Validate.checkRange(ast, 3, 4);
IAST result = F.List();
try {
int maxNumberOfResults = Integer.MAX_VALUE;
IExpr arg1 = ast.arg1();
IExpr rules = F.eval(ast.arg2());
if (ast.isAST3()) {
IExpr arg3 = F.eval(ast.arg3());
if (arg3.isSignedNumber()) {
maxNumberOfResults = ((ISignedNumber) arg3).toInt();
}
}
return replaceExpr(ast, arg1, rules, result, maxNumberOfResults, engine);
} catch (ArithmeticException ae) {
engine.printMessage(ae.getMessage());
} catch (WrongArgumentType wat) {
engine.printMessage(wat.getMessage());
}
return result;
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class ReplaceRepeated method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
try {
Validate.checkSize(ast, 3);
if (ast.arg2().isListOfLists()) {
IAST result = F.List();
for (IExpr subList : (IAST) ast.arg2()) {
result.append(ast.arg1().replaceRepeated((IAST) subList));
}
return result;
}
if (ast.arg2().isAST()) {
return ast.arg1().replaceRepeated((IAST) ast.arg2());
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
engine.printMessage(wat.getMessage());
}
} catch (WrongArgumentType wat) {
engine.printMessage(wat.getMessage());
}
return F.NIL;
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class Replace method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (ast.isAST1()) {
return F.operatorFormAST1(ast);
}
Validate.checkRange(ast, 3, 4);
try {
IExpr arg1 = ast.arg1();
IExpr rules = F.eval(ast.arg2());
if (ast.isAST3()) {
// arg3 should contain a "level specification":
return replaceExprWithLevelSpecification(ast, arg1, rules, ast.arg3(), engine);
}
return replaceExpr(ast, arg1, rules, engine);
} catch (WrongArgumentType wat) {
engine.printMessage(wat.getMessage());
}
return F.NIL;
}
Aggregations