Replies: 1 comment 5 replies
-
Can you try something like this: import org.matheclipse.core.eval.ExprEvaluator;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.expression.S;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
public class App {
public static void main(String[] args) throws Exception {
ExprEvaluator util = new ExprEvaluator(false, (short) 100);
IExpr result;
// #1+1+(#1+1)*(#1+1)
IAST f =
F.Function(F.Plus(F.Slot1, F.C1, F.Times(F.Plus(F.Slot1, F.C1), F.Plus(F.Slot1, F.C1))));
IExpr function = util.eval(f);
result = util.evalFunction(function, "1.0");
System.out.println("f: " + function.toString());
System.out.println("f(1.0) = " + result);
IExpr opt = F.unaryAST1(S.OptimizeExpression, function);
IAST list = (IAST) util.eval(opt);
System.out.println("Optimized:");
System.out.println("New expression: " + list.get(1).toString());
System.out.println("List of variables: " + list.get(2).toString());
}
} I had to define a function form for |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
OptimizeExpression
is awesome! But I'm having trouble using the Java API to call a function after it's been optimized.In this example,
f2
becomes the optimized function. I want to callf2(1.0)
and was expecting6.0
as the result, but instead it produces an unevaluated syntax tree. Could someone kindly nudge me in the right direction to evaluatef2(1.0)
? Thank you!Beta Was this translation helpful? Give feedback.
All reactions