Skip to content

Commit 342da0e

Browse files
committed
save all
1 parent 96dd7e5 commit 342da0e

15 files changed

Lines changed: 506 additions & 103 deletions

File tree

LATEST.md

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

33

4+
### Parser 1.1.2 has been released on maven-central!
5+
1. Fixes bugs and makes `MatrixTurboEvaluator` natively support turbo execution of the rot function. Note that the `ScalarTurboEvaluator`s already support it.
6+
2. Also `FastCompositeExpression` is now aware of its compiler as it now sports a `getCompiler` default method(which can be overriden to specify the turbo class that compiled it)
7+
48
### Parser 1.1.1 has been released on maven-central!
59
Implemented version retrieval for ParserNG
610

LOGICAL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In CLI, you can use -e/-E/--expanding switch to work with Expanding expressions.
133133
<br>
134134
Example:<br>
135135
```
136-
VALUES_PNG="1 8 5 2" java -jar target/parser-ng-1.1.1.jar -e "avg(..L{MN/2})*1.1-MN < L0 | (L1+L{MN-1})*1.3 + MN< L0" -v
136+
VALUES_PNG="1 8 5 2" java -jar target/parser-ng-1.1.2.jar -e "avg(..L{MN/2})*1.1-MN < L0 | (L1+L{MN-1})*1.3 + MN< L0" -v
137137
avg(..L{MN/2})*1.1-MN < L0 | (L1+L{MN-1})*1.3 + MN< L0
138138
Expression : avg(..L{MN/2})*1.1-MN <L0 | (L1+L{MN-1})*1.3 + MN<L0
139139
Upon : 1,8,5,2

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.1.1) 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.1.2) 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.1.1 breaks the barrier in fully featured math parser frequencies!
12-
With various other optimizations, v1.1.1 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.1.2 breaks the barrier in fully featured math parser frequencies!
12+
With various other optimizations, v1.1.2 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.1.1 is an extremely feature rich math tool which also doubles as (arguably) the fastest pure Java expression evaluator on the planet.
15+
ParserNG v1.1.2 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.1.1 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.1.2 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.1.1</version>
71+
<version>1.1.2</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.1.1.jar 1+1
104+
java -jar parser-ng-1.1.2.jar 1+1
105105
2.0
106106
```
107107
Or as logical parser
108108
```
109-
java -jar parser-ng-1.1.1.jar -l true and true
109+
java -jar parser-ng-1.1.2.jar -l true and true
110110
true
111-
java -jar parser-ng-1.1.1.jar -l "2 == (4-2)"
111+
java -jar parser-ng-1.1.2.jar -l "2 == (4-2)"
112112
true
113113
```
114114
You can get help by
115115
```
116-
java -jar parser-ng-1.1.1.jar -h
117-
ParserNG 1.1.1 math.Main
116+
java -jar parser-ng-1.1.2.jar -h
117+
ParserNG 1.1.2 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.1.1.jar -h
136136
```
137137
You can get examples by verbose help:
138138
```
139-
java -jar parser-ng-1.1.1.jar -h -v
139+
java -jar parser-ng-1.1.2.jar -h -v
140140
```
141141
you can list functions:
142142
```
143-
java -jar parser-ng-1.1.1.jar help
143+
java -jar parser-ng-1.1.2.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.1.1.jar -l help
152+
java -jar parser-ng-1.1.2.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.1.1.jar -h
167+
java -jar parser-ng-1.1.2.jar -h
168168
this help
169-
java -jar parser-ng-1.1.1.jar 1+1
169+
java -jar parser-ng-1.1.2.jar 1+1
170170
2.0
171-
java -jar parser-ng-1.1.1.jar "1+1
171+
java -jar parser-ng-1.1.2.jar "1+1
172172
+2+2"
173173
2.0
174174
4.0
175-
java -jar parser-ng-1.1.1.jar -t "1+1
175+
java -jar parser-ng-1.1.2.jar -t "1+1
176176
+2+2"
177177
6.0
178-
java -jar parser-ng-1.1.1.jar -i 1+1
178+
java -jar parser-ng-1.1.2.jar -i 1+1
179179
nothing, will expect manual output, and calculate line by line
180-
java -jar parser-ng-1.1.1.jar -i -t 1+1
180+
java -jar parser-ng-1.1.2.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.1.1.jar 1+1
182+
echo 2+2 | java -jar parser-ng-1.1.2.jar 1+1
183183
2.0
184184
echo "1+1
185-
+2+2 | java -jar parser-ng-1.1.1.jar -i
185+
+2+2 | java -jar parser-ng-1.1.2.jar -i
186186
2.0
187187
4.0
188188
echo "1+1
189-
+2+2 | java -jar parser-ng-1.1.1.jar -i -t
189+
+2+2 | java -jar parser-ng-1.1.2.jar -i -t
190190
6.0
191-
java -cp parser-ng-1.1.1.jar parser.cmd.ParserCmd "1+1
191+
java -cp parser-ng-1.1.2.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.1.1.jar parser.cmd.ParserCmd 2>/dev/null
194+
+2+2 | java -cp parser-ng-1.1.2.jar parser.cmd.ParserCmd 2>/dev/null
195195
2.0
196196
4.0
197-
java -cp parser-ng-1.1.1.jar parser.MathExpression "1+1
197+
java -cp parser-ng-1.1.2.jar parser.MathExpression "1+1
198198
+2+2"
199199
6.0
200-
java -cp parser-ng-1.1.1.jar parser.LogicalExpression "true or false"
200+
java -cp parser-ng-1.1.2.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.1.1 of ParserNG allows you to quickly compute the eigenvalues of a Matrix.
776+
Version 1.1.2 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.1.1 also, eigenvector computations have been added, do:
785+
As of ParserNG 1.1.2 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: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ParserNG 🧮⚡
22

3-
**ParserNG 1.1.1** is a **blazing-fast**, nigh zero allocation(memory wise), **pure Java**, **zero-native-dependencies** math expression parser and evaluator.
3+
**ParserNG 1.1.2** 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.1.1-success)
15+
![Latest Version](https://img.shields.io/badge/version-1.1.2-success)
1616

17-
> **1.1.1** 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.1.2** 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.1.1)
19+
## ✨ Highlights (v1.1.2)
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,12 +36,12 @@ 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.1.1</version>
39+
<version>1.1.2</version>
4040
</dependency>
4141
```
4242

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

4646
## 🧮 Standard Mode — The old way
4747

@@ -81,16 +81,84 @@ for (double t = 0; t < 10_000_000; t += 0.001) {
8181
}
8282
```
8383

84+
OR in more modern versions of Turbo, JUST
85+
```java
86+
double[] frame = new double[3];
87+
88+
for (double t = 0; t < 10_000_000; t += 0.001) {
89+
frame[0] = t;
90+
frame[1] = t * 1.5;
91+
frame[2] = t / 2.0;
92+
//the slots are auto-computed inside the applyScalar and other applyXXX methods
93+
double result = turbo.applyScalar(frame); // ← ultra-fast!
94+
}
95+
```
96+
8497
### Turbo Matrix (eigvalues, linear systems, etc.)
8598

8699
```java
100+
String expression="R=@(3,3)(5,1,3, 2,9,12, 1,5,18)"
87101
MathExpression me = new MathExpression("eigvalues(R)");
88102
FastCompositeExpression turbo = TurboEvaluatorFactory.getCompiler(me).compile();
89103

90104
Matrix result = turbo.applyMatrix(new double[0]); // works for: linear_sys, adjoint, cofactor, A/B, etc.
91105
```
92106

93-
## Quick Start (Normal Mode + Turbo)
107+
108+
### Turbo Matrix (Matrix Algebra)
109+
110+
```java
111+
String expression = "R=@(3,3)(5,1,3, 2,9,12, 1,5,18);A=@(3,3)(2,0,5, 8,9,13, 1,2,1);A+2*R-1/A;";
112+
MathExpression me = new MathExpression(expression);
113+
FastCompositeExpression turbo = TurboEvaluatorFactory.getCompiler(me).compile();
114+
double[] vars = {};
115+
MathExpression.EvalResult result = turbo.apply(vars);
116+
System.out.println("result:"+result.toString()); // works for: linear_sys, adjoint, cofactor, A/B, etc.
117+
```
118+
119+
120+
### Turbo Matrix(non-JMH Benchmark)
121+
```Java
122+
public static void benchmarkMatrixAlgebra() throws Throwable {
123+
int n = 20;
124+
Matrix t = new Matrix(n, n);
125+
t.setName("T");
126+
t.randomFill(35);
127+
t.print();
128+
System.out.println("T: After fill-----\n");
129+
130+
FunctionManager.add(new Function(t));
131+
132+
Matrix v = new Matrix(n, n);
133+
v.setName("V");
134+
v.randomFill(35);
135+
v.print();
136+
System.out.println("V: After fill-----\n");
137+
138+
FunctionManager.add(new Function(v));
139+
140+
String ex = "2*T+V";
141+
MathExpression expr = new MathExpression(ex);
142+
143+
FastCompositeExpression turbo = expr.compileTurbo();
144+
double[] vars = {};
145+
MathExpression.EvalResult er = null;
146+
147+
long start = System.nanoTime();
148+
for (int i = 0; i < 1_000_000; i++) {
149+
er = turbo.apply(vars);
150+
}
151+
long duration = System.nanoTime() - start;
152+
153+
System.out.printf("Expression: %s%n", ex);
154+
System.out.println("res: " + er);
155+
System.out.printf("Speed: %.2f ns/op%n", duration / 1_000_000.0);
156+
System.out.printf("Throughput: %.2f ops/sec%n", 1_000_000.0 / (duration / 1e9));
157+
}
158+
```
159+
160+
161+
## Go Deeper (Normal Mode + Turbo)
94162

95163
### 1. Simple expression
96164

@@ -139,13 +207,13 @@ System.out.println("Determinant = " + expr.solve());
139207
```
140208

141209

142-
### 6. ROTOR
210+
### 6a. ROTOR
143211
You may use the rot function to rotate functions, surfaces(plane or curved), lines and even raw points in 3D space.
144212

145213
To rotate any of these, you need the orbital center, the coordinates of the direction vector(a,b,c) and the angle of rotation.
146214

147215
The example below shows two ways to use the ParserNG library to rotate the point `p` and `q` about the orbital center (1,0,1)
148-
with the directio vector,(1,1,0). The angle of rotation is pi radians.
216+
with the direction vector(0,0,1). The angle of rotation is pi radians.
149217

150218
```Java
151219
String expression = "p=@(1,3)(4,2,5);q=@(1,3)(12,3,-1);rot(p,q, pi, @(1,3)(1,0,1),@(1,3)(1,1,0))";
@@ -162,16 +230,36 @@ with the directio vector,(1,1,0). The angle of rotation is pi radians.
162230
MathExpression.EvalResult evr = compiled.apply(vars);
163231
System.out.println("turbo: " + evr);
164232
```
233+
The result is an array of 6 elements. The first 3 represent the coordinates of the new P after rotation and the last coordinates represent the coordinates of Q after rotation.
165234

235+
The next example is even more interesting.
236+
237+
### 6b. ROTOR - A swarm or Matrix of Points
238+
ParserNG can take a Matrix of N points in 3D space(so each point has x,y,z coordinates) and rotate them through an angle, about an origin (O) in a specified direction, D. The Matrix would hence be of dimensions (N x 3) and its output will be a Matrix of similar dimensions, and each row in the initial Matrix would have its rotated result in the corresponding rows of the output Matrix.
239+
```Java
240+
String expression = "M_IN=@(5,3)(3,1,4, 2,2,8, 7,1,3, 4,5,19, 8,7,21);O=@(1,3)(0,0,0);D=@(1,3)(0,0,1);";
241+
MathExpression me = new MathExpression(expression);
242+
MathExpression m = new MathExpression("rot(M_IN,pi,O,D)");
243+
FastCompositeExpression fce = m.compileTurbo();
244+
MathExpression.EvalResult evr = fce.apply(new double[0]);
245+
System.out.println("turbo: " + evr);
246+
```
247+
OR, you could do it with one object using anonymous syntax:
248+
```Java
249+
MathExpression m = new MathExpression(" rot(@(5,3)(3,1,4, 2,2,8, 7,1,3, 4,5,19, 8,7,21), pi, @(1,3)(0,0,0), @(1,3)(0,0,1) ) ");
250+
FastCompositeExpression fce = m.compileTurbo();
251+
MathExpression.EvalResult evr = fce.apply(new double[0]);
252+
System.out.println("turbo: " + evr);
253+
```
166254

167255

168256
## ⌨️ Command-line tool (REPL)
169257

170258
```bash
171-
java -jar parser-ng-1.1.1.jar "sin(x) + cos(x)"
172-
java -jar parser-ng-1.1.1.jar "eigvalues(R=@(5,5)(...))"
173-
java -jar parser-ng-1.1.1.jar help
174-
java -jar parser-ng-1.1.1.jar -i # interactive mode
259+
java -jar parser-ng-1.1.2.jar "sin(x) + cos(x)"
260+
java -jar parser-ng-1.1.2.jar "eigvalues(R=@(5,5)(...))"
261+
java -jar parser-ng-1.1.2.jar help
262+
java -jar parser-ng-1.1.2.jar -i # interactive mode
175263
```
176264

177265
## 📊 Supported Features at a Glance
@@ -192,8 +280,8 @@ Full list: run `help` or `new MathExpression("help").solve()`.
192280

193281
- [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md) — full speed comparisons
194282
- [GRAPHING.md](GRAPHING.md) — plotting on Swing / JavaFX / Android
195-
- [LATEST.md](LATEST.md) — what’s new in 1.1.1
196-
- Javadoc: https://javadoc.io/doc/com.github.gbenroscience/parser-ng/1.1.1
283+
- [LATEST.md](LATEST.md) — what’s new in 1.1.2
284+
- Javadoc: https://javadoc.io/doc/com.github.gbenroscience/parser-ng/1.1.2
197285
- [Hello world and original readme](src/main/java/com/github/gbenroscience/README.md) — Original readme for pre-1.0 versions with a lot of, still valid, examples
198286

199287
## ❤️ Support the Project
@@ -211,7 +299,7 @@ ParserNG is built with love in my free time. If it helps you:
211299

212300
---
213301

214-
**ParserNG 1.1.1** — faster than the competition, stronger on matrices, and now with real Turbo Scalar + Turbo Matrix compiled power.
302+
**ParserNG 1.1.2** — faster than the competition, stronger on matrices, and now with real Turbo Scalar + Turbo Matrix compiled power.
215303

216304
Happy parsing! 🚀
217305
**GBENRO JIBOYE** (@gbenroscience)

pom.xml

Lines changed: 3 additions & 2 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.1.1</version>
6+
<version>1.1.2</version>
77
<packaging>jar</packaging>
88
<!--
99
I started this project 2009 and have been upgrading it since then.
@@ -14,7 +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.1.1 implements the dynamic version read of ParserNG jar executable
17+
Version 1.1.2 fixes bugs and makes MatrixTurboEvaluator natively support turbo execution of the rot function. Note that the ScalarTurboEvaluators already support it
18+
Also FastCompositeExpression is now aware of its compiler as it now sports a getCompiler default method(which can be overriden to specify the turbo class that compiled it)
1819
</description>
1920
<url>https://github.com/gbenroscience/ParserNG</url>
2021

0 commit comments

Comments
 (0)