ParserNG is a fast, pure Java, no-native-dependencies math expression parser and evaluator.
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.
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.
Perfect for scientific computing, education, engineering tools, Android apps, financial models, scripting engines, and anywhere you need powerful math without heavy dependencies.
v0.2.5 brings strength reduction, constant folding, and O(1) argument passing via execution frames โ significantly faster evaluation.
- Extremely fast evaluation (one of the fastest pure-Java parsers)
- Symbolic differentiation (
diff) with high accuracy - Numerical integration (
intg) - Built-in matrix operations (
det,eigvalues,matrix_mul, โฆ) - Statistics (
avg,variance,cov,min,max, โฆ) - Equation solvers: quadratic, cubic (Tartaglia), numerical root finding
- User-defined functions (
f(x) = โฆor lambda@(x) โฆ) - Variables & persistent scope (
VariableManager,FunctionManager) - 2D function & geometric plotting support
- Logical expression parsing (
and,or,==, โฆ) - No external dependencies โ runs on Java SE, Android, JavaME, โฆ
<dependency>
<groupId>com.github.gbenroscience</groupId>
<artifactId>parser-ng</artifactId>
<version>0.2.5</version>
</dependency>Also available on Maven Central:
https://central.sonatype.com/artifact/com.github.gbenroscience/parser-ng/0.2.5
import net.sourceforge.parserng.MathExpression;
public class QuickStart {
public static void main(String[] args) {
MathExpression expr = new MathExpression("r = 4; 2 * pi * r");
double result = expr.solve();
System.out.printf("Circumference โ %.4f%n", result); // โ 25.1327
}
}MathExpression expr = new MathExpression("quadratic(@(x)x^2 + 5*x + sin(x))");
int xSlot = expr.getVariable('x').getFrameIndex();
for (double x = 0; x < 100000; x += 0.1) {
expr.updateSlot(xSlot, x);
double y = expr.solveGeneric().scalar; // very fast โ parsing done only once
// ... plot or process y
}MathExpression expr = new MathExpression("f(x) = x^3 * ln(x); diff(f, 2, 1)");
System.out.println(expr.solveGeneric().scalar); // derivative of f at x=2MathExpression expr = new MathExpression("intg(@(x) sin(x^2), 0, 1.5)");
System.out.println("โซ โ " + expr.solve());MathExpression expr = new MathExpression("""
M = @(3,3)(1,2,3, 4,5,6, 7,8,9);
det(M)
""");
System.out.println("Determinant = " + expr.solve());# Simple calculation
java -jar parser-ng-0.2.5.jar "2+3*4^2"
# With variables & functions
java -jar parser-ng-0.2.5.jar "f(x)=x^2+1; f(5)"
# Symbolic derivative
java -jar parser-ng-0.2.5.jar "diff(@(x)x^3 + 2x, x)"
# Show all built-in functions
java -jar parser-ng-0.2.5.jar help
# Interactive mode
java -jar parser-ng-0.2.5.jar -i| Category | Examples | Notes |
|---|---|---|
| Arithmetic | + - * / ^ % |
Standard precedence |
| Trigonometry | sin cos tan asin acos atan sinh โฆ |
RAD/DEG/GRAD modes |
| Statistics | sum avg variance cov min max rms โฆ |
Vector-aware |
| Combinatorics | fact comb perm |
|
| Calculus | diff (symbolic), intg (numerical), root |
Symbolic diff is exact where possible |
| Equations | Quadratic, cubic (Tartaglia), linear_sys |
Numerical root finding too |
| Matrices | det matrix_mul transpose eigvalues eigvec โฆ |
Full linear algebra basics |
| Logic | and or xor == != > < <= >= ! |
Use -l flag or logical mode |
| Plotting | plot (see GRAPHING.md) |
2D function & geometric plots |
| Custom functions | f(x)=โฆ or @(x,y)โฆ |
Lambda & named syntax |
Full function list: run help in the parser or call new MathExpression("help").solve().
- BENCHMARK_RESULTS.md โ performance comparisons
- GRAPHING.md โ how to use the plotting features
- API Javadoc (hosted on javadoc.io)
ParserNG is maintained in free time. If you find it useful:
- โญ Star the repository
- ๐ Report bugs or suggest features
- ๐ก Share how you use it
- โ Buy me a coffee
Apache License 2.0
Happy parsing! ๐
โ GBENRO JIBOYE (@gbenroscience)