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 import org.nfunk.jep.function.PostfixMathCommandI; 16 17 18 21 public class PassThroughDiffRule implements DiffRulesI 22 { 23 private String name; 24 private PostfixMathCommandI pfmc; 25 26 private PassThroughDiffRule() {} 27 public PassThroughDiffRule(DJep djep,String inName) 28 { 29 name = inName; 30 pfmc = djep.getFunctionTable().get(name); 31 } 32 public PassThroughDiffRule(String inName,PostfixMathCommandI inPfmc) 33 { 34 name = inName; 35 pfmc = inPfmc; 36 } 37 public String toString() 38 { 39 if(pfmc==null) 40 { 41 return "" + name +"\t\tPassthrough but no math command!"; 42 } 43 switch(pfmc.getNumberOfParameters()) 44 { 45 case 0: 46 return name + " \t\tdiff("+name+",x) -> "+name; 47 case 1: 48 return name + " \tdiff("+name+"(a),x) -> "+name+"(da/dx)"; 49 case 2: 50 return name + " \tdiff("+name+"(a,b),x) -> "+name+"(da/dx,db/dx)"; 51 default: 52 return name + " \tdiff("+name+"(a,b,...),x) -> "+name+"(da/dx,db/dx,...)"; 53 } 54 } 55 public String getName() { return name; } 56 57 public Node differentiate(ASTFunNode node,String var,Node [] children,Node [] dchildren,DJep djep) throws ParseException 58 { 59 return djep.getNodeFactory().buildFunctionNode(node,dchildren); 60 } 61 } 62 | Popular Tags |