use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class Replace method replaceExpr.
private static IExpr replaceExpr(final IAST ast, IExpr arg1, IExpr rules, final EvalEngine engine) {
if (rules.isListOfLists()) {
IAST result = F.List();
for (IExpr list : (IAST) rules) {
IAST subList = (IAST) list;
IExpr temp = F.NIL;
for (IExpr element : subList) {
if (element.isRuleAST()) {
IAST rule = (IAST) element;
Function<IExpr, IExpr> function = Functors.rules(rule);
temp = function.apply(arg1);
if (temp.isPresent()) {
break;
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
throw wat;
}
}
if (temp.isPresent()) {
result.append(temp);
} else {
result.append(arg1);
}
}
return result;
} else if (rules.isList()) {
for (IExpr element : (IAST) rules) {
if (element.isRuleAST()) {
IAST rule = (IAST) element;
Function<IExpr, IExpr> function = Functors.rules(rule);
IExpr temp = function.apply(arg1);
if (temp.isPresent()) {
return temp;
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
throw wat;
}
}
return arg1;
}
if (rules.isRuleAST()) {
return replaceRule(arg1, (IAST) rules);
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
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 replaceExprWithLevelSpecification.
private static IExpr replaceExprWithLevelSpecification(final IAST ast, IExpr arg1, IExpr rules, IExpr exprLevelSpecification, EvalEngine engine) {
// use replaceFunction#setRule() method to set the current rules which
// are initialized with null
ReplaceFunction replaceFunction = new ReplaceFunction(ast, null, engine);
VisitorLevelSpecification level = new VisitorLevelSpecification(replaceFunction, exprLevelSpecification, false);
if (rules.isListOfLists()) {
IAST result = F.List();
for (IExpr list : (IAST) rules) {
IExpr temp = F.NIL;
IAST subList = (IAST) list;
for (IExpr element : subList) {
if (element.isRuleAST()) {
IAST rule = (IAST) element;
replaceFunction.setRule(rule);
temp = arg1.accept(level);
if (temp.isPresent()) {
break;
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
throw wat;
}
}
result.append(temp.orElse(arg1));
}
return result;
}
replaceFunction.setRule(rules);
return arg1.accept(level).orElse(arg1);
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class ReplaceList method replaceExpr.
private static IAST replaceExpr(final IAST ast, IExpr arg1, IExpr rules, IAST result, int maxNumberOfResults, final EvalEngine engine) {
if (rules.isList()) {
for (IExpr element : (IAST) rules) {
if (element.isRuleAST()) {
IAST rule = (IAST) element;
Function<IExpr, IExpr> function = Functors.rules(rule);
IExpr temp = function.apply(arg1);
if (temp.isPresent()) {
if (maxNumberOfResults <= result.size()) {
return result;
}
result.append(temp);
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
throw wat;
}
}
return result;
}
if (rules.isRuleAST()) {
Function<IExpr, IExpr> function = Functors.rules((IAST) rules);
IExpr temp = function.apply(arg1);
if (temp.isPresent()) {
if (maxNumberOfResults <= result.size()) {
return result;
}
result.append(temp);
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
engine.printMessage(wat.getMessage());
}
return result;
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class Resultant method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 4);
// TODO allow multinomials
IExpr arg3 = Validate.checkSymbolType(ast, 3);
ISymbol x = (ISymbol) arg3;
IExpr a = F.evalExpandAll(ast.arg1());
IExpr b = F.evalExpandAll(ast.arg2());
ExprPolynomialRing ring = new ExprPolynomialRing(F.List(x));
try {
// check if a is a polynomial otherwise check ArithmeticException,
// ClassCastException
ring.create(a);
} catch (RuntimeException ex) {
throw new WrongArgumentType(ast, a, 1, "Polynomial expected!");
}
try {
// check if b is a polynomial otherwise check ArithmeticException,
// ClassCastException
ring.create(b);
return F.Together(resultant(a, b, x, engine));
} catch (RuntimeException ex) {
throw new WrongArgumentType(ast, b, 2, "Polynomial expected!");
}
}
use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.
the class Solve method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 3, 4);
IAST variables = Validate.checkIsVariableOrVariableList(ast, 2, engine);
if (variables == null) {
return F.NIL;
}
IExpr domain = F.Complexes;
if (ast.isAST3()) {
domain = ast.arg3();
if (domain.equals(F.Booleans)) {
IAST resultList = F.List();
booleansSolve(ast.arg1(), variables, 0, 1, resultList);
return resultList;
}
if (domain.equals(F.Integers)) {
IAST equationsAndInequations = Validate.checkEquationsAndInequations(ast, 1);
try {
IAST resultList = Solve.integerSolve(equationsAndInequations, variables);
EvalAttributes.sort(resultList);
return resultList;
} catch (RuntimeException rex) {
if (Config.SHOW_STACKTRACE) {
rex.printStackTrace();
}
engine.printMessage("Integer solution not found: " + rex.getMessage());
}
return F.NIL;
}
if (!domain.equals(F.Reals) && !domain.equals(F.Complexes)) {
throw new WrongArgumentType(ast, ast.arg3(), 3, "Booleans or Integers expected!");
}
}
IAST termsEqualZeroList = Validate.checkEquations(ast, 1);
IAST temp = solveTimesEquationsRecursively(termsEqualZeroList, variables, engine);
if (temp.isPresent()) {
return temp;
}
temp = solveEquations(termsEqualZeroList, variables, 0, engine);
if (temp.isPresent()) {
// }
return temp;
}
return F.NIL;
// return solvePlusEquationsSimplified(termsEqualZeroList,
// variables,engine);
}
Aggregations