Skip to content

Commit 0da76ef

Browse files
Merge pull request #40 from gbenroscience/methd-handles
Turbo Mode
2 parents 096d338 + 9fe5348 commit 0da76ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+10684
-1908
lines changed

INTEGRATOR.md

Lines changed: 575 additions & 0 deletions
Large diffs are not rendered by default.

nb-configuration.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
10+
<word>bytecode</word>
11+
<word>Runtime</word>
12+
</spellchecker-wordlist>
13+
</project-shared-configuration>

pom.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.gbenroscience</groupId>
55
<artifactId>parser-ng</artifactId>
6-
<version>0.2.6</version>
6+
<version>1.0.0</version>
77
<packaging>jar</packaging>
88
<!--
99
I started this project 2009 and have been upgrading it since then.
@@ -12,7 +12,7 @@
1212
-->
1313

1414
<name>ParserNG</name>
15-
<description>Rich and Performant, Cross Platform Java Library(100% Java)... Major optimizations in constant folding, strength reduction, and frame(array) based argument passing to enforce O(1) (faster than Map based) passing of arguments during the evaluation phase.
15+
<description>Rich and Performant, Cross Platform Java Library(100% Java)...Version 1.0.0 explodes even higher in execution speed.
1616
</description>
1717
<url>https://github.com/gbenroscience/ParserNG</url>
1818

@@ -40,15 +40,22 @@
4040
<dependency>
4141
<groupId>org.junit.jupiter</groupId>
4242
<artifactId>junit-jupiter-api</artifactId>
43-
<version>5.8.2</version>
43+
<version>6.0.3</version>
4444
<scope>test</scope>
4545
</dependency>
4646
<dependency>
4747
<groupId>org.junit.jupiter</groupId>
4848
<artifactId>junit-jupiter-engine</artifactId>
49-
<version>5.8.2</version>
49+
<version>6.0.3</version>
5050
<scope>test</scope>
5151
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-params</artifactId>
55+
<version>6.0.3</version>
56+
<scope>test</scope>
57+
<type>jar</type>
58+
</dependency>
5259
</dependencies>
5360

5461
<build>

src/main/java/com/github/gbenroscience/math/differentialcalculus/Derivative.java

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,15 @@ public ArrayList<String> differentiateAsList() {
172172

173173
return array;
174174
}//end method
175-
176-
175+
177176
/**
178-
*
177+
*
179178
* @param name The name to check.
180-
* @return true if the name is automatically generated and
181-
* so, most likely refers to a stored Differentiable.
179+
* @return true if the name is automatically generated and so, most likely
180+
* refers to a stored Differentiable.
182181
*/
183-
public boolean isBaseVariable(String name){
184-
return name.equals(this.baseVariable);
182+
public boolean isBaseVariable(String name) {
183+
return name.equals(this.baseVariable);
185184
}//end method
186185

187186
/**
@@ -197,19 +196,17 @@ public boolean isBaseVariable(String name){
197196
* value is returned.
198197
*
199198
*/
200-
public static String eval(String expr) {
199+
public static MathExpression.EvalResult eval(String expr) {
201200
//the anonymous function to be differentiated: e.g.diff(@(p)(3*p^3+2*p^2-8*p+1),1)
202201
try {
203202
Parser p = new Parser(expr);
204-
205-
203+
206204
if (p.result == ParserResult.VALID) {
207-
205+
208206
expr = "diff(" + p.getFunction().getMathExpression().getExpression() + ")";
209207
String baseVariable = p.getFunction().getIndependentVariables().get(0).getName();
210-
211208
int orderOfDiff = p.getOrderOfDifferentiation();
212-
if(p.isNotSetOrderOfDiff()){
209+
if (p.isNotSetOrderOfDiff()) {
213210
orderOfDiff = 1;
214211
}
215212

@@ -223,33 +220,58 @@ public static String eval(String expr) {
223220
}//end for loop
224221
expr = expr.substring(5, expr.length() - 1);
225222
MathExpression me = new MathExpression(baseVariable + "=" + evalPoint + ";" + expr);
226-
return me.solve();
223+
System.out.println(baseVariable + "=" + evalPoint + ";" + expr);
224+
me.updateArgs(evalPoint);
225+
return me.solveGeneric();
227226
} else {
228227
for (int i = 1; i <= orderOfDiff; i++) {
229228
Derivative derivative = new Derivative(expr);
230229
derivative.baseVariable = baseVariable;
231230
expr = "diff(" + derivative.differentiate() + ")";
232231
}//end for loop
233232
expr = expr.substring(5, expr.length() - 1);
234-
235-
String funcExpr = "@("+baseVariable+")"+expr;
236-
233+
234+
String funcExpr = "@(" + baseVariable + ")" + expr;
235+
237236
Function f = FunctionManager.add(funcExpr);
238-
return f.getName();
237+
return f.getMathExpression().getNextResult().wrap(f.getName());
239238
//return funcExpr;
240239
}
241240
}
242-
return "Input Error!!!";
241+
return new MathExpression.EvalResult().wrap(ParserResult.STRANGE_INPUT);
243242
} catch (Exception e) {
244243
e.printStackTrace();
245-
return "Input Error";
244+
return new MathExpression.EvalResult().wrap(ParserResult.STRANGE_INPUT);
246245
}
247246
}
248247

249248
/**
250249
* @param args
251250
*/
252251
public static void main(String args[]) {
252+
String f = "10*x^5";
253+
Derivative d;
254+
try {
255+
d = new Derivative(f);
256+
System.out.println("diff(" + f + ") = " + d.differentiate());
257+
} catch (Exception ex) {
258+
Logger.getLogger(Derivative.class.getName()).log(Level.SEVERE, null, ex);
259+
}
260+
261+
262+
263+
f = "diff(@(x)10*x^5,3)";
264+
try {
265+
MathExpression.EvalResult ev = Derivative.eval(f);
266+
String res = ev.textRes;
267+
System.out.println("diff(" + f + ") = " + res);
268+
System.out.println("Grad Function = " + FunctionManager.lookUp(res));
269+
270+
} catch (Exception ex) {
271+
Logger.getLogger(Derivative.class.getName()).log(Level.SEVERE, null, ex);
272+
}
273+
274+
253275
try {
254276
//MAKE DECISION ON WHETHER TO ENABLE (-x+...
255277
//OR TO DISABLE IT. ENABLING IT WILL MEAN CONVERTING -x patterns to -1*x....

src/main/java/com/github/gbenroscience/math/differentialcalculus/Parser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public class Parser {
9797
public Parser(String expression) {
9898

9999
DataSetFormatter dsf = new DataSetFormatter(expression);
100-
List<String> scanner = dsf.getDataset();
101-
100+
List<String> scanner = dsf.getDataset();
101+
scanner = MathScanner.plusAndMinusStringHandlerHelper(scanner);
102102
MathScanner.recognizeAnonymousFunctions(scanner);
103103

104104
this.function = localParseDerivativeCommand(scanner);

0 commit comments

Comments
 (0)