Search code examples
javajavafxsymja

Abs[x] not recognized in symja math parser


I have imported the .jar files, but

DoubleEvaluator engine = new DoubleEvaluator();
engine.defineVariable("x", -1);
engine.evaluate("Abs[x]");

throws me an error: org.matheclipse.parser.client.math.ArithmeticMathException: EvalDouble#evaluateFunction(FunctionNode) not possible for: Abs(x) and

engine.evaluate("Sin[x]");

does not. What could be the reason for this?

Exception in thread "main" org.matheclipse.parser.client.math.ArithmeticMathException: EvalDouble#evaluateFunction(FunctionNode) not possible for: Abs(x)
at org.matheclipse.parser.client.eval.DoubleEvaluator.evaluateFunction(DoubleEvaluator.java:563)
at org.matheclipse.parser.client.eval.DoubleEvaluator.evaluateNode(DoubleEvaluator.java:493)
at org.matheclipse.parser.client.eval.DoubleEvaluator.evaluate(DoubleEvaluator.java:460)
at javaapplication14.JavaApplication14.main(JavaApplication14.java:24)
Java Result: 1

and the example run

import org.matheclipse.parser.client.eval.DoubleEvaluator;

public class application {

public static void main(String[] args) {

    DoubleEvaluator engine = new DoubleEvaluator();

    engine.defineVariable("x",-1);
    engine.evaluate("Abs[x]");

}

}


Solution

  • (Thanks for the stacktrace and the download address)

    This issue has been fixed some hours ago, the newest version should solve the problem:

    https://bitbucket.org/axelclk/symja_android_library/downloads/symjaMMA2016-01-09.zip

    The missing function Abs was added:

    FUNCTION_DOUBLE_MAP.put("Abs", new IDouble1Function() {
       public double evaluate(double arg1) {
          return Math.abs(arg1);
       }
     });
    

    See the difference: https://bitbucket.org/axelclk/symja_android_library/diff/symja_android_library/matheclipse-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java?diff2=c84fa1c92f83&at=master