public double evaluate(DoubleEvaluator engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); double result = engine.evaluateNode(function.getNode(2)); IDoubleValue dv = engine.getVariable(variableName); if (dv == null) { dv = new DoubleVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }
public Complex evaluate(IEvaluator<Complex, ComplexVariable> engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticException("SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticException("SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); Complex result = engine.evaluateNode(function.getNode(2)); ComplexVariable dv = engine.getVariable(variableName); if (dv == null) { dv = new ComplexVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }
/** * Evaluate. * * @param engine the engine * @param function the function * @return the double */ @Override public double evaluate( DoubleEvaluator engine, FunctionNode function ) { if ( function.size() != 3 ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString() ); } if ( !(function.getNode( 1 ) instanceof SymbolNode) ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString() ); } String variableName = ((SymbolNode) function.getNode( 1 )).getString(); double result = engine.evaluateNode( function.getNode( 2 ) ); IDoubleValue dv = engine.getVariable( variableName ); if ( dv == null ) { dv = new DoubleVariable( result ); } else { dv.setValue( result ); } engine.defineVariable( variableName, dv ); return result; } }
/** * Evaluate. * * @param engine the engine * @param function the function * @return the complex */ @Override public Complex evaluate( IEvaluator<Complex, ComplexVariable> engine, FunctionNode function ) { if ( function.size() != 3 ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString() ); } if ( !(function.getNode( 1 ) instanceof SymbolNode) ) { throw new ArithmeticException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString() ); } String variableName = ((SymbolNode) function.getNode( 1 )).getString(); Complex result = engine.evaluateNode( function.getNode( 2 ) ); ComplexVariable dv = engine.getVariable( variableName ); if ( dv == null ) { dv = new ComplexVariable( result ); } else { dv.setValue( result ); } engine.defineVariable( variableName, dv ); return result; } }
@Override public double evaluate(DoubleEvaluator engine, FunctionNode function) { if (function.size() != 3) { throw new ArithmeticMathException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) needs 2 arguments: " + function.toString()); } if (!(function.getNode(1) instanceof SymbolNode)) { throw new ArithmeticMathException( "SetFunction#evaluate(DoubleEvaluator,FunctionNode) symbol required on the left hand side: " + function.toString()); } String variableName = ((SymbolNode) function.getNode(1)).getString(); double result = engine.evaluateNode(function.getNode(2)); IDoubleValue dv = engine.getVariable(variableName); if (dv == null) { dv = new DoubleVariable(result); } else { dv.setValue(result); } engine.defineVariable(variableName, dv); return result; } }
public boolean evaluateFunctionLogical(final FunctionNode functionNode) { if (functionNode.size() > 0 && functionNode.getNode(0) instanceof SymbolNode) { String symbol = functionNode.getNode(0).toString(); if (functionNode.size() == 2) { Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); if (obj instanceof IBooleanBoolean1Function) { return ((IBooleanBoolean1Function) obj).evaluate(evaluateNodeLogical(functionNode.getNode(1))); } } else if (functionNode.size() == 3) { Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); if (obj instanceof IBooleanComplex2Function) { return ((IBooleanComplex2Function) obj).evaluate(evaluateNode(functionNode.getNode(1)), evaluateNode(functionNode.getNode(2))); } else if (obj instanceof IBooleanBoolean2Function) { return ((IBooleanBoolean2Function) obj).evaluate(evaluateNodeLogical(functionNode.getNode(1)), evaluateNodeLogical(functionNode.getNode(2))); } // } else { // Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); // if (obj instanceof IBooleanDoubleFunction) { // return ((IBooleanDoubleFunction) obj).evaluate(this, functionNode); // } } } throw new ArithmeticException("EvalDouble#evaluateFunctionLogical(FunctionNode) not possible for: " + functionNode.toString()); }
+ functionNode.toString());
throw new ArithmeticException( "EvalDouble#evaluateFunctionLogical(FunctionNode) not possible for: " + functionNode.toString() );
throw new ArithmeticException( "EvalDouble#evaluateFunctionLogical(FunctionNode) not possible for: " + functionNode.toString() );
public boolean evaluateFunctionLogical(final FunctionNode functionNode) { if (functionNode.size() > 0 && functionNode.getNode(0) instanceof SymbolNode) { String symbol = functionNode.getNode(0).toString(); if (functionNode.size() == 2) { Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); if (obj instanceof IBooleanBoolean1Function) { return ((IBooleanBoolean1Function) obj).evaluate(evaluateNodeLogical(functionNode.getNode(1))); } } else if (functionNode.size() == 3) { Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); if (obj instanceof IBooleanDouble2Function) { return ((IBooleanDouble2Function) obj).evaluate(evaluateNode(functionNode.getNode(1)), evaluateNode(functionNode.getNode(2))); } else if (obj instanceof IBooleanBoolean2Function) { return ((IBooleanBoolean2Function) obj).evaluate(evaluateNodeLogical(functionNode.getNode(1)), evaluateNodeLogical(functionNode.getNode(2))); } // } else { // Object obj = FUNCTION_BOOLEAN_MAP.get(symbol); // if (obj instanceof IBooleanDoubleFunction) { // return ((IBooleanDoubleFunction) obj).evaluate(this, // functionNode); // } } } throw new ArithmeticMathException( "EvalDouble#evaluateFunctionLogical(FunctionNode) not possible for: " + functionNode.toString()); }
+ functionNode.toString());
throw new MathException("EvalDouble#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString());
throw new ArithmeticException( "EvalDouble#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString() );
@Override public double evaluate(DoubleEvaluator doubleEngine, FunctionNode functionNode, double[] args) { ASTNode node = functionNode.getNode(0); if (node instanceof SymbolNode) { AST2Expr ast2Expr = new AST2Expr(); IExpr head = ast2Expr.convert(node); IASTAppendable fun = F.ast(head, args.length, false); fun.appendArgs(0, args.length, i -> F.num(args[i])); // for (int i = 0; i < args.length; i++) { // fun.append(F.num(args[i])); // } final IExpr result = F.evaln(fun); if (result.isReal()) { return ((ISignedNumber) result).doubleValue(); } } else if (node instanceof FunctionNode) { AST2Expr ast2Expr = new AST2Expr(); IExpr head = ast2Expr.convert(node); IASTAppendable fun = F.ast(head); for (int i = 0; i < args.length; i++) { fun.append(F.num(args[i])); } final IExpr result = F.evaln(fun); if (result.isReal()) { return ((ISignedNumber) result).doubleValue(); } } throw new MathException("CoreCallbackFunction#evaluate() not possible for: " + functionNode.toString()); }
throw new MathException( "EvalDouble#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString() );
"EvalDouble#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString());