Skip to content

Commit fb7fe52

Browse files
Merge pull request #42 from gbenroscience/methd-handles
save
2 parents 9132000 + 7f7fc9b commit fb7fe52

1 file changed

Lines changed: 102 additions & 78 deletions

File tree

README.md

Lines changed: 102 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,120 @@
11
# ParserNG 🧮⚡
22

3-
**ParserNG** is a **fast**, **pure Java**, **no-native-dependencies** math expression parser and evaluator.
3+
**ParserNG 1.0.0** is a **blazing-fast**, **pure Java**, **zero-native-dependencies** math expression parser and evaluator.
44

5-
If you need a rich, fully featured parser that can do 3 million to 10 million evaluations per second, ParserNG v0.2.5 is the one for you.
5+
It **beats Janino, exp4J, and JavaMEP on evaluation speed** across every kind of expression — from simple algebra to heavy trig, matrices, and calculus.
6+
With the new **Turbo compiled mode**, it routinely reaches **3–10 million evaluations per second**.
67

7-
It goes far beyond basic expression parsing — offering **symbolic differentiation**, **numerical integration**, **matrix operations**, **statistics**, **equation solving**, **user-defined functions**, **2D graphing**, and more — all in a lightweight, cross-platform library.
8+
It goes far beyond basic parsing — offering **symbolic differentiation**, **resilient numerical integration**, **full matrix algebra**, **statistics**, **equation solving**, **user-defined functions**, **2D graphing**, and more — all in one lightweight, cross-platform library.
89

9-
Perfect for scientific computing, education, engineering tools, Android apps, financial models, scripting engines, and anywhere you need powerful math without heavy dependencies.
10+
Perfect for scientific computing, simulations, real-time systems, education tools, Android apps, financial models, and high-performance scripting.
1011

1112
[![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)
1213
[![License](https://img.shields.io/github/license/gbenroscience/ParserNG?color=blue)](https://github.com/gbenroscience/ParserNG/blob/master/LICENSE)
1314
![Java](https://img.shields.io/badge/Java-8%2B-orange)
14-
![Latest Version](https://img.shields.io/badge/version-0.2.5-success)
15+
![Latest Version](https://img.shields.io/badge/version-1.0.0-success)
1516

16-
> v0.2.5 brings **strength reduction**, **constant folding**, and **O(1) argument passing** via execution frames → significantly faster evaluation.
17+
> **1.0.0** introduces **Turbo Scalar** and **Turbo Matrix** compiled paths + massive speed improvements via strength reduction, constant folding, and O(1) frame-based argument passing.
1718
18-
## ✨ Highlights
19+
## ✨ Highlights (v1.0.0)
1920

20-
- Extremely fast evaluation (one of the fastest pure-Java parsers)
21-
- Symbolic differentiation (`diff`) with high accuracy
22-
- Numerical integration (`intg`)
23-
- Built-in matrix operations (`det`, `eigvalues`, `matrix_mul`, …)
24-
- Statistics (`avg`, `variance`, `cov`, `min`, `max`, …)
25-
- Equation solvers: quadratic, cubic (Tartaglia), numerical root finding
26-
- User-defined functions (`f(x) = ` or lambda `@(x) `)
27-
- Variables & persistent scope (`VariableManager`, `FunctionManager`)
21+
- **Speed champion** — beats Janino, exp4J, and JavaMEP in every benchmark (see [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md))
22+
- **Turbo Mode** — compile once, evaluate millions of times per second (Scalar + Matrix paths)
23+
- Symbolic differentiation (`diff`) + resilient numerical integration (`intg`) that handles difficult expressions
24+
- Full matrix algebra (`det`, `eigvalues`, `eigvec`, `adjoint`, `cofactor`, matrix division, `linear_sys`, …)
25+
- Statistics (`avg`, `variance`, `cov`, `min`, `max`, `rms`, `listsum`, `sort`, …)
26+
- Equation solvers: quadratic, **Tartaglia cubic**, numerical roots, linear systems
27+
- User-defined functions (`f(x)=` or lambda `@(x,y)`) + persistent `FunctionManager` / `VariableManager`
28+
- Variables with execution frames for ultra-fast loops
2829
- 2D function & geometric plotting support
29-
- Logical expression parsing (`and`, `or`, `==`, …)
30+
- Logical expressions (`and`, `or`, `==`, …)
3031
- No external dependencies — runs on Java SE, Android, JavaME, …
3132

3233
## 🚀 Installation (Maven)
3334

34-
3535
```xml
3636
<dependency>
3737
<groupId>com.github.gbenroscience</groupId>
3838
<artifactId>parser-ng</artifactId>
39-
<version>0.2.5</version>
39+
<version>1.0.0</version>
4040
</dependency>
4141
```
4242

4343
Also available on **Maven Central**:
44-
https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng/0.2.5
44+
https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng/1.0.0
45+
46+
## ⚡ Turbo Mode — The 1.0.0 Game Changer
4547

46-
## Quick Start
48+
```java
49+
import com.github.gbenroscience.parser.MathExpression;
50+
import com.github.gbenroscience.parser.turbo.tools.FastCompositeExpression;
51+
```
4752

48-
### 1. Simple expression (as library)
53+
### Turbo Scalar (tight loops / millions per second)
4954

5055
```java
51-
import net.sourceforge.parserng.MathExpression;
52-
53-
public class QuickStart {
54-
public static void main(String[] args) {
55-
MathExpression expr = new MathExpression("r = 4; 2 * pi * r");
56-
double result = expr.solve();
57-
System.out.printf("Circumference ≈ %.4f%n", result); // ≈ 25.1327
58-
}
56+
String expr = "x*sin(x) + y*cos(y) + z^2";
57+
MathExpression me = new MathExpression(expr, false); // prepare for turbo
58+
FastCompositeExpression turbo = me.compileTurbo(); // compile once
59+
60+
int xSlot = me.getVariable("x").getFrameIndex();
61+
int ySlot = me.getVariable("y").getFrameIndex();
62+
int zSlot = me.getVariable("z").getFrameIndex();
63+
64+
double[] frame = new double[3];
65+
66+
for (double t = 0; t < 10_000_000; t += 0.001) {
67+
frame[xSlot] = t;
68+
frame[ySlot] = t * 1.5;
69+
frame[zSlot] = t / 2.0;
70+
double result = turbo.applyScalar(frame); // ← ultra-fast!
5971
}
6072
```
6173

62-
### 2. Reuse for high-performance loops
74+
### Turbo Matrix (eigvalues, linear systems, etc.)
75+
76+
```java
77+
MathExpression me = new MathExpression("eigvalues(R)");
78+
FastCompositeExpression turbo = TurboEvaluatorFactory.getCompiler(me).compile();
79+
80+
Matrix result = turbo.applyMatrix(new double[0]); // works for: linear_sys, adjoint, cofactor, A/B, etc.
81+
```
82+
83+
## Quick Start (Normal Mode + Turbo)
84+
85+
### 1. Simple expression
6386

6487
```java
65-
MathExpression expr = new MathExpression("quadratic(@(x)x^2 + 5*x + sin(x))");
66-
int xSlot = expr.getVariable('x').getFrameIndex();
67-
for (double x = 0; x < 100000; x += 0.1) {
68-
expr.updateSlot(xSlot, x);
69-
double y = expr.solveGeneric().scalar; // very fast — parsing done only once
70-
// ... plot or process y
88+
MathExpression expr = new MathExpression("r = 5; 2 * pi * r");
89+
System.out.println(expr.solve()); // ≈ 31.4159
90+
```
91+
92+
### 2. High-performance loop (Turbo recommended)
93+
94+
```java
95+
MathExpression expr = new MathExpression("x^2 + 5*x + sin(x)", false);
96+
FastCompositeExpression turbo = expr.compileTurbo();
97+
int xSlot = expr.getVariable("x").getFrameIndex();
98+
double[] frame = new double[1];
99+
100+
for (double x = 0; x < 100_000; x += 0.1) {
101+
frame[xSlot] = x;
102+
double y = turbo.applyScalar(frame);
103+
// plot or process y
71104
}
72105
```
73106

74-
### 3. Symbolic derivative & evaluation
107+
### 3. Symbolic derivative
75108

76109
```java
77110
MathExpression expr = new MathExpression("f(x) = x^3 * ln(x); diff(f, 2, 1)");
78-
System.out.println(expr.solveGeneric().scalar); // derivative of f at x=2
111+
System.out.println(expr.solveGeneric().scalar);
79112
```
80113

81-
### 4. Numerical integration
114+
### 4. Numerical integration (even difficult ones work in Turbo)
82115

83116
```java
84-
MathExpression expr = new MathExpression("intg(@(x) sin(x^2), 0, 1.5)");
117+
MathExpression expr = new MathExpression("intg(@(x) 1/(x*sin(x)+3*x*cos(x)), 0.5, 1.8)");
85118
System.out.println("∫ ≈ " + expr.solve());
86119
```
87120

@@ -95,61 +128,52 @@ MathExpression expr = new MathExpression("""
95128
System.out.println("Determinant = " + expr.solve());
96129
```
97130

98-
## ⌨️ Command-line tool (REPL-like)
131+
## ⌨️ Command-line tool (REPL)
99132

100133
```bash
101-
# Simple calculation
102-
java -jar parser-ng-0.2.5.jar "2+3*4^2"
103-
104-
# With variables & functions
105-
java -jar parser-ng-0.2.5.jar "f(x)=x^2+1; f(5)"
106-
107-
# Symbolic derivative
108-
java -jar parser-ng-0.2.5.jar "diff(@(x)x^3 + 2x, x)"
109-
110-
# Show all built-in functions
111-
java -jar parser-ng-0.2.5.jar help
112-
113-
# Interactive mode
114-
java -jar parser-ng-0.2.5.jar -i
134+
java -jar parser-ng-1.0.0.jar "sin(x) + cos(x)"
135+
java -jar parser-ng-1.0.0.jar "eigvalues(R=@(5,5)(...))"
136+
java -jar parser-ng-1.0.0.jar help
137+
java -jar parser-ng-1.0.0.jar -i # interactive mode
115138
```
116139

117140
## 📊 Supported Features at a Glance
118141

119-
| Category | Examples | Notes |
120-
|-----------------------|-----------------------------------------------|------------------------------------|
121-
| Arithmetic | `+ - * / ^ %` | Standard precedence |
122-
| Trigonometry | `sin cos tan asin acos atan sinh …` | `RAD`/`DEG`/`GRAD` modes |
123-
| Statistics | `sum avg variance cov min max rms …` | Vector-aware |
124-
| Combinatorics | `fact comb perm` | |
125-
| Calculus | `diff` (symbolic), `intg` (numerical), `root` | Symbolic diff is exact where possible |
126-
| Equations | Quadratic, cubic (Tartaglia), `linear_sys` | Numerical root finding too |
127-
| Matrices | `det matrix_mul transpose eigvalues eigvec …` | Full linear algebra basics |
128-
| Logic | `and or xor == != > < <= >= !` | Use `-l` flag or logical mode |
129-
| Plotting | `plot` (see GRAPHING.md) | 2D function & geometric plots |
130-
| Custom functions | `f(x)=…` or `@(x,y)…` | Lambda & named syntax |
131-
132-
Full function list: run `help` in the parser or call `new MathExpression("help").solve()`.
142+
| Category | Key Functions | Turbo Support |
143+
|-------------------|----------------------------------------------------|---------------|
144+
| Arithmetic & Logic| `+ - * / ^ % and or == !=` | Full |
145+
| Trigonometry | `sin cos tan asin … sinh` | Full |
146+
| Calculus | `diff` (symbolic), `intg` (resilient) | Yes |
147+
| Equations | Quadratic, Tartaglia cubic, `root`, `linear_sys` | Yes |
148+
| Matrices | `det`, `eigvalues`, `eigvec`, `adjoint`, `cofactor`, `A / B` | Excellent (Turbo Matrix) |
149+
| Statistics | `avg variance cov min max rms listsum sort` | Yes |
150+
| Custom | `@(x,y)…` or named functions | Full |
151+
152+
Full list: run `help` or `new MathExpression("help").solve()`.
133153

134154
## 📚 More Documentation
135155

136-
- [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md) — performance comparisons
137-
- [GRAPHING.md](GRAPHING.md) — how to use the plotting features
138-
- [API Javadoc](https://javadoc.io/doc/com.github.gbenroscience/parser-ng/latest/index.html) (hosted on javadoc.io)
156+
- [BENCHMARK_RESULTS.md](BENCHMARK_RESULTS.md) — full speed comparisons
157+
- [GRAPHING.md](GRAPHING.md) — plotting on Swing / JavaFX / Android
158+
- [LATEST.md](LATEST.md) — what’s new in 1.0.0
159+
- Javadoc: https://javadoc.io/doc/com.github.gbenroscience/parser-ng/1.0.0
139160

140161
## ❤️ Support the Project
141162

142-
ParserNG is maintained in free time. If you find it useful:
163+
ParserNG is built with love in my free time. If it helps you:
143164

144-
- ⭐ Star the repository
145-
- 🐞 Report bugs or suggest features
146-
- 💡 Share how you use it
165+
- ⭐ Star the repository
166+
- 🐞 Report bugs or suggest features
167+
- 💡 Share what you built with it
147168
-[Buy me a coffee](https://buymeacoffee.com/gbenroscience)
148169

149170
## 📄 License
150171

151172
**Apache License 2.0**
152173

153-
Happy parsing! 🚀
154-
— GBENRO JIBOYE (@gbenroscience)
174+
---
175+
176+
**ParserNG 1.0.0** — faster than the competition, stronger on matrices, and now with real Turbo Scalar + Turbo Matrix compiled power.
155177

178+
Happy parsing! 🚀
179+
**GBENRO JIBOYE** (@gbenroscience)

0 commit comments

Comments
 (0)