1 8 package org.lsmp.djep.djep.diffRules; 9 10 import org.lsmp.djep.djep.DJep; 11 import org.lsmp.djep.djep.DiffRulesI; 12 import org.nfunk.jep.ASTFunNode; 13 import org.nfunk.jep.Node; 14 import org.nfunk.jep.ParseException; 15 16 20 public class AdditionDiffRule implements DiffRulesI 21 { 22 private String name; 23 24 private AdditionDiffRule() {} 25 public AdditionDiffRule(String inName) 26 { 27 name = inName; 29 } 30 31 public String toString() 32 { return name + " \t\tdiff(f+g,x) -> diff(f,x)+diff(g,x)"; } 33 public String getName() { return name; } 34 35 public Node differentiate(ASTFunNode node,String var,Node [] children,Node [] dchildren,DJep djep) throws ParseException 36 { 37 int nchild = node.jjtGetNumChildren(); 38 if(nchild!=2) 39 throw new ParseException("Too many children "+nchild+" for "+node+"\n"); 40 return djep.getNodeFactory().buildOperatorNode(djep.getOperatorSet().getAdd(),dchildren[0],dchildren[1]); 41 } 42 } 43 | Popular Tags |