jep-2.4.1-ext-1.1.1-gpl/ 0000755 0000000 0000000 00000000000 10615400352 013000 5 ustar root root jep-2.4.1-ext-1.1.1-gpl/src/ 0000755 0000000 0000000 00000000000 10615400352 013567 5 ustar root root jep-2.4.1-ext-1.1.1-gpl/src/org/ 0000755 0000000 0000000 00000000000 10615400352 014356 5 ustar root root jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/ 0000755 0000000 0000000 00000000000 10615400352 015331 5 ustar root root jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/ 0000755 0000000 0000000 00000000000 10615400352 017752 5 ustar root root jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/MatrixConsole.java 0000644 0000000 0000000 00000003337 10615400352 023412 0 ustar root root /* @author rich * Created on 21-Mar-2005 * * See LICENSE.txt for license information. */ package org.lsmp.djepExamples; import org.nfunk.jep.Node; import org.nfunk.jep.ParseException; import org.lsmp.djep.matrixJep.*; /** * @author Rich Morris * Created on 21-Mar-2005 */ public class MatrixConsole extends DJepConsole { private static final long serialVersionUID = -4768856862892634425L; public static void main(String[] args) { Console c = new MatrixConsole(); c.run(args); } public String getPrompt() { return "MatrixJep > "; } public void initialise() { j = new MatrixJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true); ((MatrixJep) j).addStandardDiffRules(); } public void printHelp() { super.printHelp(); println("Dot product: [1,2,3].[4,5,6]"); println("Cross product: [1,2,3]^[4,5,6]"); println("Matrix Multiplication: [[1,2],[3,4]]*[[1,2],[3,4]]"); } public void printIntroText() { println("MatrixJep: advanced vector and matrix handling"); super.printStdHelp(); } public void processEquation(Node node) throws ParseException { MatrixJep mj = (MatrixJep) j; if(verbose) { print("Parsed:\t\t"); println(mj.toString(node)); } Node processed = mj.preprocess(node); if(verbose) { print("Processed:\t"); println(mj.toString(processed)); } Node simp = mj.simplify(processed); if(verbose) print("Simplified:\t"); println(mj.toString(simp)); Object val = mj.evaluate(simp); String s = mj.getPrintVisitor().formatValue(val); println("Value:\t\t"+s); } } jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/package.html 0000644 0000000 0000000 00000000126 10615400352 022232 0 ustar root root
Various example applications illustrating the use of most features. jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/PrintExample.java 0000644 0000000 0000000 00000002016 10615400352 023224 0 ustar root root /* @author rich * Created on 26-Feb-2004 */ package org.lsmp.djepExamples; import org.nfunk.jep.*; import org.lsmp.djep.xjep.*; /** * @author Rich Morris * Created on 26-Feb-2004 */ public class PrintExample { public static void main(String[] args) { XJep j = new XJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true); try { // parse expression Node node = j.parse("a*b+c*(d+sin(x))"); // print it j.println(node); // convert to string String str = j.toString(node); System.out.println("String is '"+str+"'"); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,true); j.println(node); j.getPrintVisitor().setMode(PrintVisitor.FULL_BRACKET,false); Node node2=j.parse("1*x^1+0"); j.println(node2); Node simp=j.simplify(node2); j.println(simp); } catch(ParseException e) { System.out.println("Parse error"); } } } jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/XJepExample.java 0000644 0000000 0000000 00000005202 10615400352 022776 0 ustar root root /* @author rich * Created on 26-Feb-2004 */ package org.lsmp.djepExamples; import org.nfunk.jep.*; import org.lsmp.djep.xjep.*; /** * Examples using differentation */ public class XJepExample { public static void main(String args[]) { /* initilisation */ XJep j = new XJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setAllowAssignment(true); j.setImplicitMul(true); try { Node node10 = j.parse("x=3"); Node node11 = j.preprocess(node10); System.out.println(j.evaluate(node11)); Node node12 = j.parse("y=x^2"); Node node13 = j.preprocess(node12); System.out.println(j.evaluate(node13)); Node node14 = j.parse("z=y+x"); Node node15 = j.simplify(j.preprocess(node14)); System.out.println(j.evaluate(node15)); // If a variable is changed then any expresion tree // it depends on needs to be re-evaluated to bring // values of other variables upto date j.setVarValue("x",new Double(4)); System.out.println(j.evaluate(node13)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); // the findVarValue method will automatically // re-calculate the value of variables specified by // equations if needed. However a lazy j.setVarValue("x",new Double(5)); System.out.println("j.setVarValue(\"x\",new Double(5));"); System.out.println("j.findVarValue(y): "+j.calcVarValue("y").toString()); System.out.println("j.findVarValue(z): "+j.calcVarValue("z").toString()); // if j.getSymbolTable().clearValues(); // is called before values of equations are set // then the values of intermediate equations // are automatically calculated, so you can jump // straight to the chase: no need to calculate // y explititly to find the value of z. j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(6)); System.out.println("j.setVarValue(\"x\",new Double(6));"); System.out.println("j.findVarValue(z): "+j.calcVarValue("z").toString()); j.getSymbolTable().clearValues(); j.setVarValue("x",new Double(7)); System.out.println(j.evaluate(node15)); System.out.println("z: "+j.getVarValue("z").toString()); // now see if reentrancy works j.restartParser("x=1; // semi colon; in comment \ny=2; z=3;"); Node node21; while((node21 = j.continueParsing()) != null) j.println(node21); } catch(ParseException e) { System.out.println("Error with parsing"); } catch(Exception e) { System.out.println("Error with evaluation"); } } } jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/XJepConsole.java 0000644 0000000 0000000 00000011323 10615400352 023006 0 ustar root root /* @author rich * Created on 21-Mar-2005 * * See LICENSE.txt for license information. */ package org.lsmp.djepExamples; import org.lsmp.djep.djep.DPrintVisitor; import org.lsmp.djep.xjep.*; import org.nfunk.jep.*; import java.text.NumberFormat; import java.util.Enumeration; /** * @author Rich Morris * Created on 21-Mar-2005 */ public class XJepConsole extends Console { private static final long serialVersionUID = -3239922790774093668L; protected NumberFormat format=null; protected boolean verbose = false; public static void main(String[] args) { Console c = new XJepConsole(); c.run(args); } public String getPrompt() { return "XJep > "; } public void initialise() { j = new XJep(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setAllowAssignment(true); j.setImplicitMul(true); } public void printHelp() { super.printHelp(); println("'setMaxLen 80'\tensures all lines and < 80 chars"); println("'setDP 3'\tonly prints 3 decimal places"); println("'setFullBrackets true'\tprints equations with full bracketing"); println("'setComplexI true'\tprint complex numbers in form x+iy"); println("'invalidate'\tmarks all variables as invalid, forcing reevaluation"); println("eg 'x=5','y=2*x' gives value 10, 'invalidate', 'x=6', 'y' gives value 12"); } public void printIntroText() { println("XJep Console"); super.printStdHelp(); } public void printOps() { println("Known operators"); Operator ops[] = j.getOperatorSet().getOperators(); int maxPrec = -1; for(int i=0;i* Sample session *
* JEP > a=5 * 5.0 * JEP > a>4 * 1.0 * JEP > TrueBlock * JEP > b=a^2 * 25.0 * JEP > c=a^3 * 125.0 * JEP > FalseBlock * JEP > b=a^3 * JEP > c=a^2 * JEP > EndBlock * JEP > b * 25.0 **This code does not allow nesting on condition statements. **/ public class BlockStatments extends Console { private static final long serialVersionUID = 9035584745289937584L; /** Sets up three possible states */ private static final int NoState = 0; private static final int TrueState = 1; private static final int FalseState = 2; /** Indicates current state where in */ private int state = NoState; private int conditionValue = 0; /** * Catches macros which are not handled by JEP * * @return false - stops further processing of the line */ public boolean testSpecialCommands(String command) { if(command.equals("TrueBlock")) { state = TrueState; return false; } if(command.equals("FalseBlock")) { state = FalseState; return false; } if(command.equals("EndBlock")) { state = NoState; return false; } return true; } /** Evaluates a node, but only if the state corresponds to the conditionValue. * Also saves the result of evaluation in conditionValue for use in subsequent calls * * @param node Node representing expression * @throws ParseException if a Parse or evaluation error */ public void processEquation(Node node) throws ParseException { if(state==NoState || ( state==TrueState && conditionValue !=0 ) || ( state==FalseState && conditionValue ==0 ) ) { Object res = j.evaluate(node); println(res); if(state==NoState) conditionValue = ((Number) res).intValue(); } } } jep-2.4.1-ext-1.1.1-gpl/src/org/lsmp/djepExamples/RpExample.java 0000644 0000000 0000000 00000007204 10615400352 022515 0 ustar root root /* @author rich * Created on 26-Feb-2004 */ package org.lsmp.djepExamples; import org.nfunk.jep.*; import org.lsmp.djep.rpe.*; /** * Examples using vectors and matricies */ public class RpExample { static JEP j; public static void main(String args[]) { j = new JEP(); j.addStandardConstants(); j.addStandardFunctions(); j.addComplex(); j.setAllowUndeclared(true); j.setImplicitMul(true); j.setAllowAssignment(true); // parse and evaluate each equation in turn doStuff("1*2*3+4*5*6+7*8*9"); doAll(new String[]{"x1=1","x2=2","x3=3","x4=4","x5=5","x6=6","x7=7","x8=8","x9=9", "x1*x2*x3+x4*x5*x6+x7*x8*x9"}); doAll(new String[]{"x=0.7","cos(x)^2+sin(x)^2"}); // vectors and matricies can be used with assignment // doStuff("x=[1,2,3]"); // Value: [1.0,2.0,3.0] // doStuff("x+x"); // Value: [2.0,4.0,6.0] // doStuff("x . x"); // Value: 14.0 // doStuff("x^x"); // Value: [0.0,0.0,0.0] // doStuff("y=[[1,2],[3,4]]"); // Value: [[1.0,2.0],[3.0,4.0]] // doStuff("y * y"); // Value: [[7.0,10.0],[15.0,22.0]] // accessing the elements on an array or vector // doStuff("ele(x,2)"); // Value: 2.0 // doStuff("ele(y,[1,2])"); // Value: 2.0 // using differentation // doStuff("x=2"); // 2.0 // doStuff("y=[x^3,x^2,x]"); // [8.0,4.0,2.0] // doStuff("z=diff(y,x)"); // [12.0,4.0,1.0] // doStuff("diff([x^3,x^2,x],x)"); // System.out.println("dim(z) "+((MatrixVariableI) j.getVar("z")).getDimensions()); } public static void extendedPrint(RpCommandList list) throws ParseException { int num = list.getNumCommands(); for(int i=0;i