/** * Internal helper using the mathclipse framework. * * @param aFunctionNode The node to be processed. * * @return The {@link Criteria} (tree) extracted from the provided node. * * @throws ParseException Thrown in case there were problems working with * the given node. */ private Criteria toCriteria( FunctionNode aFunctionNode ) throws ParseException { if ( aFunctionNode.size() == 3 ) { if ( (aFunctionNode.get( 0 ) instanceof SymbolNode) && (aFunctionNode.get( 1 ) instanceof SymbolNode) && (aFunctionNode.get( 2 ) instanceof SymbolNode) ) { return toCriteria( (SymbolNode) aFunctionNode.get( 0 ), (SymbolNode) aFunctionNode.get( 1 ), aFunctionNode.get( 2 ) ); } else if ( (aFunctionNode.get( 0 ) instanceof SymbolNode) && (aFunctionNode.get( 1 ) instanceof SymbolNode) && (aFunctionNode.get( 2 ) instanceof NumberNode) ) { return toCriteria( (SymbolNode) aFunctionNode.get( 0 ), (SymbolNode) aFunctionNode.get( 1 ), aFunctionNode.get( 2 ) ); } else if ( (aFunctionNode.get( 0 ) instanceof SymbolNode) && (aFunctionNode.get( 1 ) instanceof FunctionNode) && (aFunctionNode.get( 2 ) instanceof SymbolNode) ) { return toCriteria( (SymbolNode) aFunctionNode.get( 0 ), (FunctionNode) aFunctionNode.get( 1 ), (SymbolNode) aFunctionNode.get( 2 ) ); } else if ( (aFunctionNode.get( 0 ) instanceof SymbolNode) && (aFunctionNode.get( 1 ) instanceof FunctionNode) && (aFunctionNode.get( 2 ) instanceof FunctionNode) ) { return toCriteria( (SymbolNode) aFunctionNode.get( 0 ), (FunctionNode) aFunctionNode.get( 1 ), (FunctionNode) aFunctionNode.get( 2 ) ); } else if ( (aFunctionNode.get( 0 ) instanceof SymbolNode) && (aFunctionNode.get( 1 ) instanceof SymbolNode) && (aFunctionNode.get( 2 ) instanceof FunctionNode) ) { return toCriteria( (SymbolNode) aFunctionNode.get( 0 ), (SymbolNode) aFunctionNode.get( 1 ), (FunctionNode) aFunctionNode.get( 2 ) ); } } throw new ParseException( aFunctionNode.getString(), 0 ); }
public String toString() { ASTNode temp = fNodesList.get(0); final StringBuffer buf = new StringBuffer(); if (temp == null) { buf.append("<null-tag>"); } else { buf.append(temp.toString()); } buf.append('['); for (int i = 1; i < size(); i++) { temp = get(i); buf.append(temp == this ? "(this ListNode)" : String.valueOf(temp)); if (i < size() - 1) { buf.append(", "); } } buf.append(']'); return buf.toString(); }
if (f.get(2).isFree(var)) {// derive x^r ASTNode arg1Derived = derivative(f.getNode(1), var); new DoubleNode(-1.0), f.get(2)); FunctionNode fun = fASTFactory.createFunction(fASTFactory.createSymbol("Times"), f.get(2), fASTFactory.createFunction(fASTFactory.createSymbol("Power"), f.get(1), exponent)); return getDerivativeResult(arg1Derived, fun); if (f.get(1).isFree(var)) {// derive a^x ASTNode arg2Derived = derivative(f.getNode(2), var); fASTFactory.createFunction(fASTFactory.createSymbol("Log"), f.get(1)), f); return getDerivativeResult(arg2Derived, fun);
/** * {@inheritDoc} Depends on. */ @Override public boolean dependsOn( String variableName ) { for ( int i = 1; i < size(); i++ ) { if ( get( i ).dependsOn( variableName ) ) { return true; } } return false; }
public boolean dependsOn(String variableName) { for (int i = 1; i < size(); i++) { if (get(i).dependsOn(variableName)) { return true; } } return false; }
@Override public boolean dependsOn(String variableName) { for (int i = 1; i < size(); i++) { if (get(i).dependsOn(variableName)) { return true; } } return false; }
/** * To string. * * @return the string */ @Override public String toString() { ASTNode temp = fNodesList.get( 0 ); final StringBuffer buf = new StringBuffer(); if ( temp == null ) { buf.append( "<null-tag>" ); } else { buf.append( temp.toString() ); } buf.append( "[" ); for ( int i = 1; i < size(); i++ ) { temp = get( i ); buf.append( temp == this ? "(this ListNode)" : String.valueOf( temp ) ); if ( i < size() - 1 ) { buf.append( ", " ); } } buf.append( "]" ); return buf.toString(); }
@Override public ASTNode createFunction(final INodeParserFactory factory, final ASTNode lhs, final ASTNode rhs) { if (rhs instanceof FunctionNode) { FunctionNode r = (FunctionNode) rhs; if (r.size() == 3) { if (r.get(0).equals(factory.createSymbol("Set"))) { return factory.createFunction(factory.createSymbol("TagSet"), lhs, r.get(1), r.get(2)); } else if (r.get(0).equals(factory.createSymbol("SetDelayed"))) { return factory.createFunction(factory.createSymbol("TagSetDelayed"), lhs, r.get(1), r.get(2)); } } } return factory.createFunction(factory.createSymbol("TagSet"), lhs, rhs); } }
@Override public String toString() { ASTNode head = fNodesList.get(0); final StringBuilder buf = new StringBuilder(); if (head == null) { buf.append("<null-tag>"); } else { buf.append(head.toString()); } ASTNode temp; if (head instanceof FunctionNode) { buf.append('['); } else { buf.append('('); } for (int i = 1; i < size(); i++) { temp = get(i); buf.append(temp == this ? "(this ListNode)" : String.valueOf(temp)); if (i < size() - 1) { buf.append(", "); } } if (head instanceof FunctionNode) { buf.append(']'); } else { buf.append(')'); } return buf.toString(); }
/** * Converts a parsed FunctionNode expression into an IAST expression */ public IAST convert(IAST ast, FunctionNode functionNode) throws ConversionException { ast.set(0, convert(functionNode.get(0))); for (int i = 1; i < functionNode.size(); i++) { ast.add(convert(functionNode.get(i))); } return ast; }
/** * Converts a parsed FunctionNode expression into an IAST expression. * * @param functionNode * the parsed elements which should be added to the <code>IAST</code> * @param ast * the empty <code>IAST</code> instance without any elements * @return the <code>ast</code>with the added elements * @throws ConversionException */ public IAST convert(FunctionNode functionNode, IASTAppendable ast) throws ConversionException { ast.set(0, convertNode(functionNode.get(0))); for (int i = 1; i < functionNode.size(); i++) { ast.append(convertNode(functionNode.get(i))); } return ast; }
switch (size) { case 1: ast = (IASTMutable) F.headAST0(convertNode(functionNode.get(0))); break; case 2: ast = (IASTMutable) F.unaryAST1(convertNode(functionNode.get(0)), convertNode(functionNode.get(1))); break; case 3: ast = (IASTMutable) F.binaryAST2(convertNode(functionNode.get(0)), convertNode(functionNode.get(1)), convertNode(functionNode.get(2))); break; case 4: ast = (IASTMutable) F.ternaryAST3(convertNode(functionNode.get(0)), convertNode(functionNode.get(1)), convertNode(functionNode.get(2)), convertNode(functionNode.get(3))); break; default: IASTAppendable appendableAST = F.ast(convertNode(functionNode.get(0)), functionNode.size(), false); for (int i = 1; i < functionNode.size(); i++) { appendableAST.append(convertNode(functionNode.get(i))); if (EvalEngine.isApfloat(precision)) { fPrecision = precision; ast.set(1, convertNode(functionNode.get(1)));