Skip to content

Commit 12f9d93

Browse files
committed
save
1 parent 97d6662 commit 12f9d93

13 files changed

Lines changed: 407 additions & 672 deletions

File tree

LATEST.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# ParserNG
22

33

4+
### Parser 1.0.6 has been released on maven-central!
5+
Bug fixes and Android compatibility issues resolved.
6+
7+
8+
### Parser 1.0.5 has been released on maven-central!
9+
Features bug fixes and optimizations in the scanning/semantic analysis stages.
10+
411
### Parser 1.0.4 has been released on maven-central!
512
This version features various optimizations and turbo capability for the Function
613
class.

MORE.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ParserNG
2-
<b>ParserNG</b> is a powerful open-source math tool that parses and evaluates algebraic expressions and also knows how to handle a lot of mathematical expressions. Its latest release on mavn-central (version 1.0.5) can be used to plot 2D graphs(Geometric plots and function plots) It works seamlessly on all Java platforms.<br><br>
2+
<b>ParserNG</b> is a powerful open-source math tool that parses and evaluates algebraic expressions and also knows how to handle a lot of mathematical expressions. Its latest release on mavn-central (version 1.0.6) can be used to plot 2D graphs(Geometric plots and function plots) It works seamlessly on all Java platforms.<br><br>
33

44

55

@@ -8,15 +8,15 @@
88
Click the Sponsor button to do this.
99

1010

11-
ParserNG v1.0.5 breaks the barrier in fully featured math parser frequencies!
12-
With various other optimizations, v1.0.5 comes with inner loop optimizations which uses a blazing fast, post-fix style algorithm to quickly evaluate inner brackets with less checks and less string manipulations.
11+
ParserNG v1.0.6 breaks the barrier in fully featured math parser frequencies!
12+
With various other optimizations, v1.0.6 comes with inner loop optimizations which uses a blazing fast, post-fix style algorithm to quickly evaluate inner brackets with less checks and less string manipulations.
1313
This obviously will make graphing and other iterative tasks super responsive.
1414

15-
ParserNG v1.0.5 is an extremely feature rich math tool which also doubles as (arguably) the fastest pure Java expression evaluator on the planet.
15+
ParserNG v1.0.6 is an extremely feature rich math tool which also doubles as (arguably) the fastest pure Java expression evaluator on the planet.
1616
In benchmarks, it beats com.expression.parser(Java Math Expression Parser) by almost (10x-14x) and edges out Exp4J (which is lightweight) in many benchmarks.
1717

1818

19-
ParserNG 1.0.5 features strength reduction, constant folding and execution frame(array) based args passing(in contrast to Map based) to ensure O(1) complexity in passage of args to the evaluation stage.
19+
ParserNG 1.0.6 features strength reduction, constant folding and execution frame(array) based args passing(in contrast to Map based) to ensure O(1) complexity in passage of args to the evaluation stage.
2020

2121
[Here are a few benchmarks here](./BENCHMARK_RESULTS.md)
2222

@@ -68,7 +68,7 @@ If you need to access this library via Maven Central, do:
6868
<dependency>
6969
<groupId>com.github.gbenroscience</groupId>
7070
<artifactId>parser-ng</artifactId>
71-
<version>1.0.5</version>
71+
<version>1.0.6</version>
7272
</dependency>
7373
7474

@@ -101,20 +101,20 @@ ParserNG is written completely in (pure) Java and so is as cross-platform as Jav
101101
## Using ParserNG as commandline tool
102102
You can use jar directly as commandline calculus. Unless the tool is packed to your distribution:
103103
```
104-
java -jar parser-ng-1.0.5.jar 1+1
104+
java -jar parser-ng-1.0.6.jar 1+1
105105
2.0
106106
```
107107
Or as logical parser
108108
```
109-
java -jar parser-ng-1.0.5.jar -l true and true
109+
java -jar parser-ng-1.0.6.jar -l true and true
110110
true
111-
java -jar parser-ng-1.0.5.jar -l "2 == (4-2)"
111+
java -jar parser-ng-1.0.6.jar -l "2 == (4-2)"
112112
true
113113
```
114114
You can get help by
115115
```
116-
java -jar parser-ng-1.0.5.jar -h
117-
ParserNG 1.0.5 math.Main
116+
java -jar parser-ng-1.0.6.jar -h
117+
ParserNG 1.0.6 math.Main
118118
-h/-H/--help this text; do not change for help (witout dashes), which lists functions
119119
-v/-V/--verbose output is reprinted to stderr with some inter-steps
120120
-l/-L/--logic will add logical expression wrapper around the expression
@@ -136,11 +136,11 @@ java -jar parser-ng-1.0.5.jar -h
136136
```
137137
You can get examples by verbose help:
138138
```
139-
java -jar parser-ng-1.0.5.jar -h -v
139+
java -jar parser-ng-1.0.6.jar -h -v
140140
```
141141
you can list functions:
142142
```
143-
java -jar parser-ng-1.0.5.jar help
143+
java -jar parser-ng-1.0.6.jar help
144144
List of currently known methods:
145145
acos - help not yet written. See https://github.com/gbenroscience/ParserNG
146146
...
@@ -149,7 +149,7 @@ List of functions is just tip of iceberg, see: https://github.com/gbenroscience/
149149
```
150150
you can list logical operators:
151151
```
152-
java -jar parser-ng-1.0.5.jar -l help
152+
java -jar parser-ng-1.0.6.jar -l help
153153
Comparing operators: !=, ==, >=, <=, le, ge, lt, gt, <, >
154154
Logical operators: impl, xor, imp, eq, or, and, |, &
155155
As Mathematical parts are using () as brackets, Logical parts must be grouped by [] eg.
@@ -164,40 +164,40 @@ Program can work with stdin, out and err properly. Can work with multiline input
164164
### cmdline examples
165165
Following lines describes, how stdin/arguments are processed, and how different is input/output with `-t` on/off
166166
```
167-
java -jar parser-ng-1.0.5.jar -h
167+
java -jar parser-ng-1.0.6.jar -h
168168
this help
169-
java -jar parser-ng-1.0.5.jar 1+1
169+
java -jar parser-ng-1.0.6.jar 1+1
170170
2.0
171-
java -jar parser-ng-1.0.5.jar "1+1
171+
java -jar parser-ng-1.0.6.jar "1+1
172172
+2+2"
173173
2.0
174174
4.0
175-
java -jar parser-ng-1.0.5.jar -t "1+1
175+
java -jar parser-ng-1.0.6.jar -t "1+1
176176
+2+2"
177177
6.0
178-
java -jar parser-ng-1.0.5.jar -i 1+1
178+
java -jar parser-ng-1.0.6.jar -i 1+1
179179
nothing, will expect manual output, and calculate line by line
180-
java -jar parser-ng-1.0.5.jar -i -t 1+1
180+
java -jar parser-ng-1.0.6.jar -i -t 1+1
181181
nothing, will expect manual output and calcualte it all as one expression
182-
echo 2+2 | java -jar parser-ng-1.0.5.jar 1+1
182+
echo 2+2 | java -jar parser-ng-1.0.6.jar 1+1
183183
2.0
184184
echo "1+1
185-
+2+2 | java -jar parser-ng-1.0.5.jar -i
185+
+2+2 | java -jar parser-ng-1.0.6.jar -i
186186
2.0
187187
4.0
188188
echo "1+1
189-
+2+2 | java -jar parser-ng-1.0.5.jar -i -t
189+
+2+2 | java -jar parser-ng-1.0.6.jar -i -t
190190
6.0
191-
java -cp parser-ng-1.0.5.jar parser.cmd.ParserCmd "1+1
191+
java -cp parser-ng-1.0.6.jar parser.cmd.ParserCmd "1+1
192192
will ask for manual imput en evaluate per line
193193
echo "1+1
194-
+2+2 | java -cp parser-ng-1.0.5.jar parser.cmd.ParserCmd 2>/dev/null
194+
+2+2 | java -cp parser-ng-1.0.6.jar parser.cmd.ParserCmd 2>/dev/null
195195
2.0
196196
4.0
197-
java -cp parser-ng-1.0.5.jar parser.MathExpression "1+1
197+
java -cp parser-ng-1.0.6.jar parser.MathExpression "1+1
198198
+2+2"
199199
6.0
200-
java -cp parser-ng-1.0.5.jar parser.LogicalExpression "true or false"
200+
java -cp parser-ng-1.0.6.jar parser.LogicalExpression "true or false"
201201
true
202202
203203
```
@@ -773,7 +773,7 @@ This would give:
773773

774774
#### ParserNG and eigenvalues
775775

776-
Version 1.0.5 of ParserNG allows you to quickly compute the eigenvalues of a Matrix.
776+
Version 1.0.6 of ParserNG allows you to quickly compute the eigenvalues of a Matrix.
777777

778778
Do:
779779
```Java
@@ -782,7 +782,7 @@ Do:
782782
```
783783
#### ParsrNG and eigenvectors
784784

785-
As of ParserNG 1.0.5 also, eigenvector computations have been added, do:
785+
As of ParserNG 1.0.6 also, eigenvector computations have been added, do:
786786
Do:
787787
```Java
788788
MathExpression expression = new MathExpression("eigvec(@(5,5)(12,1,4,2,9,3,1,8,-5,6,13,9,7,3,5,7,3,5,4,9,13,2,4,8,6))");

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ParserNG 🧮⚡
22

3-
**ParserNG 1.0.5** is a **blazing-fast**, nigh zero allocation(memory wise), **pure Java**, **zero-native-dependencies** math expression parser and evaluator.
3+
**ParserNG 1.0.6** is a **blazing-fast**, nigh zero allocation(memory wise), **pure Java**, **zero-native-dependencies** math expression parser and evaluator.
44

55
It **beats exp4J, and com.expression.parser on evaluation speed** across every kind of expression — from simple algebra to heavy trig, matrices, and calculus; and manages to beat Janino, the gold standard on some, while rivalling it on a host of other expressions
66
The normal mode routinely does about **3-10 million evaluations per second** while the new Turbo mode easily peaks at about **10 million to 90 million evaluations per second**.
@@ -12,11 +12,11 @@ Perfect for scientific computing, simulations, real-time systems, education tool
1212
[![Maven Central](https://img.shields.io/maven-central/v/com.github.gbenroscience/parser-ng.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng)
1313
[![License](https://img.shields.io/github/license/gbenroscience/ParserNG?color=blue)](https://github.com/gbenroscience/ParserNG/blob/master/LICENSE)
1414
![Java](https://img.shields.io/badge/Java-8%2B-orange)
15-
![Latest Version](https://img.shields.io/badge/version-1.0.5-success)
15+
![Latest Version](https://img.shields.io/badge/version-1.0.6-success)
1616

17-
> **1.0.5** introduces **Turbo Scalar** and **Turbo Matrix** compiled paths + massive speed improvements via strength reduction, constant folding, and O(1) frame-based argument passing.
17+
> **1.0.6** introduces **Turbo Scalar** and **Turbo Matrix** compiled paths + massive speed improvements via strength reduction, constant folding, and O(1) frame-based argument passing.
1818
19-
## ✨ Highlights (v1.0.5)
19+
## ✨ Highlights (v1.0.6)
2020

2121
- **Speed champion** — rivals Janino in most benchmarks, and beats exp4J, com.expression.parser and Parsii in every benchmark (see [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md))
2222
- **Turbo Mode** — compile once, evaluate millions of times per second (Scalar + Matrix paths)
@@ -36,14 +36,14 @@ Perfect for scientific computing, simulations, real-time systems, education tool
3636
<dependency>
3737
<groupId>com.github.gbenroscience</groupId>
3838
<artifactId>parser-ng</artifactId>
39-
<version>1.0.5</version>
39+
<version>1.0.6</version>
4040
</dependency>
4141
```
4242

4343
Also available on **Maven Central**:
44-
https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng/1.0.5
44+
https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng/1.0.6
4545

46-
## ⚡ Turbo Mode — The 1.0.5 Game Changer
46+
## ⚡ Turbo Mode — The 1.0.6 Game Changer
4747

4848
```java
4949
import com.github.gbenroscience.parser.MathExpression;
@@ -158,10 +158,10 @@ with the directio vector,(1,1,0). The angle of rotation is pi radians.
158158
## ⌨️ Command-line tool (REPL)
159159

160160
```bash
161-
java -jar parser-ng-1.0.5.jar "sin(x) + cos(x)"
162-
java -jar parser-ng-1.0.5.jar "eigvalues(R=@(5,5)(...))"
163-
java -jar parser-ng-1.0.5.jar help
164-
java -jar parser-ng-1.0.5.jar -i # interactive mode
161+
java -jar parser-ng-1.0.6.jar "sin(x) + cos(x)"
162+
java -jar parser-ng-1.0.6.jar "eigvalues(R=@(5,5)(...))"
163+
java -jar parser-ng-1.0.6.jar help
164+
java -jar parser-ng-1.0.6.jar -i # interactive mode
165165
```
166166

167167
## 📊 Supported Features at a Glance
@@ -182,8 +182,8 @@ Full list: run `help` or `new MathExpression("help").solve()`.
182182

183183
- [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md) — full speed comparisons
184184
- [GRAPHING.md](GRAPHING.md) — plotting on Swing / JavaFX / Android
185-
- [LATEST.md](LATEST.md) — what’s new in 1.0.5
186-
- Javadoc: https://javadoc.io/doc/com.github.gbenroscience/parser-ng/1.0.5
185+
- [LATEST.md](LATEST.md) — what’s new in 1.0.6
186+
- Javadoc: https://javadoc.io/doc/com.github.gbenroscience/parser-ng/1.0.6
187187

188188
## ❤️ Support the Project
189189

@@ -200,7 +200,7 @@ ParserNG is built with love in my free time. If it helps you:
200200

201201
---
202202

203-
**ParserNG 1.0.5** — faster than the competition, stronger on matrices, and now with real Turbo Scalar + Turbo Matrix compiled power.
203+
**ParserNG 1.0.6** — faster than the competition, stronger on matrices, and now with real Turbo Scalar + Turbo Matrix compiled power.
204204

205205
Happy parsing! 🚀
206206
**GBENRO JIBOYE** (@gbenroscience)

pom.xml

Lines changed: 3 additions & 3 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>1.0.5</version>
6+
<version>1.0.6</version>
77
<packaging>jar</packaging>
88
<!--
99
I started this project 2009 and have been upgrading it since then.
@@ -14,8 +14,8 @@
1414
<name>ParserNG</name>
1515
<description>Rich and Performant, Cross Platform Java Library(100% Java).No native dependencies.
1616
ParserNG is the height of interpreted Math parsing in Java. It is the fastest of all interpreted Java math parsers.
17-
Version 1.0.5 retains high frequency execution and multi-mode/multi-functional nature
18-
Fixes bugs in the rot function and optimizes some inner loops during syntax and semantic analysis for speedier parsing
17+
Version 1.0.6 retains high frequency execution and multi-mode/multi-functional nature, but targets the Android environment's limited
18+
implementation of MethodHandles and makes turbo mode work on Android.
1919
</description>
2020
<url>https://github.com/gbenroscience/ParserNG</url>
2121

src/main/java/com/github/gbenroscience/math/geom/ROTOR.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ public String rotate(String function) {
595595
// Wrapping in parentheses preserves the Order of Operations
596596
if (replacement.charAt(0) == '(' && replacement.charAt(replacement.length() - 1) == ')') {
597597
sb.append(replacement);
598-
} else {
598+
} else {
599599
sb.append("(").append(replacement).append(")");
600600
}
601601
} else {

src/main/java/com/github/gbenroscience/parser/Function.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.github.gbenroscience.util.FunctionManager;
1818
import static com.github.gbenroscience.util.FunctionManager.*;
1919
import com.github.gbenroscience.util.Serializer;
20+
import com.github.gbenroscience.util.Utils;
2021
import com.github.gbenroscience.util.VariableManager;
2122
import java.util.logging.Level;
2223
import java.util.logging.Logger;
@@ -309,8 +310,8 @@ public static boolean assignObject(String input) {
309310
} else {
310311
anonFunc.dependentVariable = new Variable(newFuncName);
311312
}
312-
313-
FunctionManager.update(anonFunc);
313+
314+
FunctionManager.update(anonFunc);
314315
return true;
315316
} else {
316317
expr = new MathExpression(rhs);
@@ -487,9 +488,9 @@ else if (Number.isNumber(tkn)) {
487488
//input = dependentVar + "="+input;
488489
anonFn.setDependentVariable(new Variable(dependentVar));
489490
anonFn.setIndependentVariables(indVars);
490-
anonFn.type = TYPE.ALGEBRAIC_EXPRESSION;
491+
anonFn.type = TYPE.ALGEBRAIC_EXPRESSION;
491492
MathExpression me = new MathExpression(expr);
492-
493+
493494
anonFn.setMathExpression(me);
494495
//FunctionManager.update(anonFn);
495496
} else if (isMatrix) {
@@ -580,20 +581,20 @@ public Variable getDependentVariable() {
580581
}
581582

582583
public void setMathExpression(MathExpression mathExpression) {
583-
MathExpression oldMe = this.mathExpression;
584584
try {
585585
this.mathExpression = mathExpression;
586-
this.turboExpr = TurboEvaluatorFactory.getCompiler(mathExpression, false).compile();
587586
this.type = TYPE.ALGEBRAIC_EXPRESSION;
587+
this.turboExpr = TurboEvaluatorFactory.getCompiler(mathExpression, false).compile();
588588
} catch (Throwable ex) {
589-
//revert
590-
this.mathExpression = oldMe;
591589
this.turboExpr = null;
592590
Logger.getLogger(Function.class.getName()).log(Level.SEVERE, null, ex);
593591
}
594592
}
595593

596594
public FastCompositeExpression getWideningArgsExpression() {
595+
if (Utils.isAndroid()) {
596+
throw new RuntimeException("Not allowed on Android! Use Function#getArrayArgsExpression()");
597+
}
597598
try {
598599
this.turboExpr = TurboEvaluatorFactory.getCompiler(mathExpression, true).compile();
599600
} catch (Throwable ex) {
@@ -1404,22 +1405,35 @@ public static void main(String args[]) {
14041405
func.updateArgs(4);
14051406
System.out.println(func.calc());
14061407

1407-
int count = 10000;
1408+
int count = 100000;
14081409

14091410
double start = System.nanoTime();
1411+
String val = null;
14101412
for (int i = 1; i <= count; i++) {
1411-
String val = func.evalArgs("p(" + i + ")");
1412-
System.out.println("val = " + val);
1413-
System.out.println(func.evalArgs(i));
1413+
val = func.evalArgs(i);
14141414
}
14151415
double duration = System.nanoTime() - start;
1416-
System.out.println("Eval took: " + (duration / (count * 1.0E6)) + "ms");
1416+
System.out.println("Std-Eval took: " + duration/count + "ns");
1417+
System.out.println("val1 = " + val);
14171418

1419+
start = System.nanoTime();
14181420
for (int i = 1; i <= count; i++) {
1419-
String val = func.evalArgs("p(" + i + ")");
1421+
val = func.evalArgs("p(" + i + ")");
14201422
}
1423+
System.out.println("val2 = " + val);
1424+
1425+
duration = System.nanoTime() - start;
1426+
System.out.println("Old-Eval took: " + (duration / (count * 1.0E6)) + "ms");
1427+
1428+
double v = 0;
1429+
start = System.nanoTime();
1430+
for (int i = 1; i <= count; i++) {
1431+
v = func.evalArgsTurbo(i);
1432+
}
1433+
System.out.println("val3 = " + v);
1434+
14211435
duration = System.nanoTime() - start;
1422-
System.out.println("Eval took: " + (duration / (count * 1.0E6)) + "ms");
1436+
System.out.println("Turbo-Eval took: " + duration/count + "ns");
14231437

14241438
}//end method
14251439

0 commit comments

Comments
 (0)