MathExpr implements
		Function<Double[], Double>,
		Serializable { public double eval(final double... args) { final double val = apply(box(args)); return val == -0.0 ? 0.0 : val; } private  MathExpr(final Tree<? extends Op<Double>, ?> tree, boolean primary);  MathExpr(final Tree<? extends Op<Double>, ?> tree); ISeq<Var<Double>> vars(); TreeNode<Op<Double>> toTree(); @Override Double apply(final Double[] args); double eval(final double... args); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); MathExpr simplify(
		final TreeRewriter<Op<Double>> rewriter,
		final int limit
	); MathExpr simplify(final TreeRewriter<Op<Double>> rewriter); MathExpr simplify(); static String format(final Tree<? extends Op<Double>, ?> tree); static MathExpr parse(final String expression); static TreeNode<Op<Double>> parseTree(final String expression); static double eval(final String expression, final double... args); static double eval(
		final Tree<? extends Op<Double>, ?> expression,
		final double... args
	); static int rewrite(final TreeNode<Op<Double>> tree, final int limit); static int rewrite(final TreeNode<Op<Double>> tree); static final TreeRewriter<Op<Double>> CONST_REWRITER; static final TreeRewriter<Op<Double>> ARITHMETIC_REWRITER; static final TreeRewriter<Op<Double>> REWRITER; }
@Test(expectedExceptions = IllegalArgumentException.class) public void evalError1() { MathExpr.eval("x+y"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void evalError2() { MathExpr.eval("x+y", 2); }
@Test public void specialEval1() { final String expr = "(((((x - x) + (1.0*x))*((8.0 - 8.0)*(9.0*x))) + " + "(((8.0 - 9.0) + (x + x)) + ((x - 6.0)*(5.0*0.0)))) - ((((8.0 + 4.0)" + " - (x + x))*((x - x)*(6.0 - 9.0)))*(((x - 7.0) - (6.0 - x))*((2.0*x) " + "+ (x + 8.0)))))"; final double arg = new Random().nextDouble(); Assert.assertEquals( MathExpr.eval(expr, arg), MathExpr.eval("(-1.0 + (x + x))", arg) ); }
@Test public void specialEval2() { Assert.assertEquals( MathExpr.eval("2*z + 3*x - y", 3, 2, 1), 9.0 ); }
@Test public void specialEval3() { final String expr = "5 + 6*x + sin(x)^34 + (1 + sin(x*5)/4)/6"; Assert.assertEquals( MathExpr.eval(expr, 4.32), 31.170600453465315 ); Assert.assertEquals( MathExpr.eval(expr, 4.32), 5.0 + 6*4.32 + pow(sin(4.32), 34) + (1 + sin(4.32*5)/4.0)/6.0 ); }
@Test(dataProvider = "functionData") public void eval(final String expression, final F3 f, final double[] x) { Assert.assertEquals( MathExpr.eval(expression, x), f.apply(x[0], x[1], x[2]) ); Assert.assertEquals( MathExpr.eval(MathExpr.parse(expression).toString(), x), f.apply(x[0], x[1], x[2]) ); }