Skip to content

gbenroscience/ParserNG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

230 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ParserNG ๐Ÿงฎโšก

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.

Maven Central License Java Latest Version

v0.2.5 brings strength reduction, constant folding, and O(1) argument passing via execution frames โ†’ significantly faster evaluation.

โœจ Highlights

  • 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, โ€ฆ

๐Ÿš€ Installation (Maven)

<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

Quick Start

1. Simple expression (as library)

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
    }
}

2. Reuse for high-performance loops

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
}

3. Symbolic derivative & evaluation

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=2

4. Numerical integration

MathExpression expr = new MathExpression("intg(@(x) sin(x^2), 0, 1.5)");
System.out.println("โˆซ โ‰ˆ " + expr.solve());

5. Matrix example

MathExpression expr = new MathExpression("""
    M = @(3,3)(1,2,3, 4,5,6, 7,8,9);
    det(M)
""");
System.out.println("Determinant = " + expr.solve());

โŒจ๏ธ Command-line tool (REPL-like)

# 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

๐Ÿ“Š Supported Features at a Glance

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().

๐Ÿ“š More Documentation

โค๏ธ Support the Project

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

๐Ÿ“„ License

Apache License 2.0

Happy parsing! ๐Ÿš€
โ€” GBENRO JIBOYE (@gbenroscience)

About

ParserNG is a powerful , fast math expression parser that parses and evaluates math expressions, does differential calculus(symbolic) evaluations, numerical integration, equation solving(quadratic, Tartaglia's, numerical solutions of other equations) , matrix operations and statistics amongst other functionality. It is written in pure java and hโ€ฆ

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages