Skip to content

gbenroscience/ParserNG

Repository files navigation

ParserNG 2.0.5 🧮⚡

High-Performance, Interpreted Math Engine for Java

ParserNG is a blazing-fast, zero-native-dependency, pure Java math expression parser and evaluator designed for high-throughput applications—ranging from real-time simulations to scientific computing and Android apps.

Unlike compilers that introduce overhead via runtime bytecode generation (e.g., Janino), ParserNG achieves near-native speeds through mechanical sympathy, loop unrolling, and the JDK Vector API.


🚀 Performance & Throughput

  • Speed Champion: Rivals and often outperforms established engines like Janino, exp4J, and Parsii across bulk data processing tasks.

  • Throughput: Standard mode delivers 3-10 million evaluations/sec; Turbo mode reaches 10-90 million evaluations/sec.

  • Turbo Mode: A specialized compiled path for scalar and matrix operations that eliminates class-loading bottlenecks.

✨ Key Capabilities

  • Calculus & Algebra: Symbolic differentiation (diff), resilient numerical integration (intg), and comprehensive matrix algebra (det, eigvalues, linear_sys).

  • Vectorized Processing: Supports modern hardware acceleration via the jdk.incubator.vector API, with an Android-compatible scalar fallback.

  • Versatile Execution: Handles logical expressions, user-defined functions (@(x,y)…), equation solvers (Quadratic, Tartaglia cubic), and 2D geometric plotting.

  • Zero-Dependency: Portable across Java SE, Android, and JavaME.


⚡ Turbo Mode: Instant Execution

Turbo mode provides the flexibility of an interpreter with the throughput of a compiler.

// Compile once
MathExpression me = new MathExpression("x*sin(x) + y*cos(y) + z^2", false);
FastCompositeExpression turbo = me.compileTurbo();

// Evaluate millions of times with zero allocation
double[] frame = new double[3]; 
for (double t = 0; t < 10_000_000; t += 0.001) {
    frame[0] = t; frame[1] = t * 1.5; frame[2] = t / 2.0;
    double result = turbo.applyScalar(frame); 
}

⚡ Vectorized Processing: Under the Hood

When using the SIMDVectorTurboEvaluator, ParserNG automatically maps your mathematical expressions to CPU-level SIMD (Single Instruction, Multiple Data) lanes. This allows the processor to compute multiple data points simultaneously within a single clock cycle, rather than iterating through them one by one.

How it works The applyBulk method handles the complex orchestration of data alignment and lane masking for you:

SIMD Lane Utilization: The engine packs your input arrays into registers (e.g., 256-bit or 512-bit), allowing it to process multiple double values per operation.

Tail Handling: When your dataset size is not a perfect multiple of the SIMD lane width (like the 400,017 elements in the example below), the engine automatically manages the "tail" using a highly optimized scalar fallback loop, ensuring no data is missed and performance remains consistent.

Mechanical Sympathy: The evaluator uses a flat memory layout for your inputs and outputVector to minimize CPU cache misses, keeping the data pipelines full.

Example: Vectorized Bulk Evaluation This example illustrates how to process large datasets efficiently, triggering both the hardware-accelerated vector lanes and the necessary remainder logic:

public void bulkRun() throws Throwable {
    MathExpression me = new MathExpression("(1 / (x1 * sqrt(2 * 3.14159))) * exp((-(x2 - x3)^2) / (2 * x1^2))");
    SIMDVectorTurboEvaluator.SIMDVectorCompositeExpression evaluator = 
        (SIMDVectorTurboEvaluator.SIMDVectorCompositeExpression) new SIMDVectorTurboEvaluator(me).compile();

    // 400,017 datapoints: Automatically triggers SIMD lanes + tail scalar loop
    int totalElements = 400017;
    double[][] inputs = new double[3][totalElements]; 
    double[] outputVector = new double[totalElements];

    // Prepare data
    for (int i = 0; i < totalElements; i++) {
        inputs[0][i] = 1.5 + (i * 0.1); // x1
        inputs[1][i] = 2.0 + (i * 0.5); // x2
        inputs[2][i] = 0.5;             // x3
    }

    // High-throughput vectorized execution
    evaluator.applyBulk(inputs, outputVector);
    
    // Result is now stored in outputVector, processed in parallel chunks
}

📦 Installation

Add the following to your pom.xml:

<dependency>
    <groupId>com.github.gbenroscience</groupId>
    <artifactId>parser-ng</artifactId>
    <version>2.0.5</version>
</dependency>

📊 Feature Comparison

Category Supported Features Turbo Support
Arithmetic + - * / ^ % and or == != Full
Trigonometry sin cos tan asin … sinh Full
Calculus diff (symbolic), intg (resilient) Yes
Matrices det, eigvalues, eigvec, adjoint Excellent
Statistics avg, variance, rms, sort Yes

📚 Documentation & Resources

📚 More Documentation


Developed by GBENRO JIBOYE (@gbenroscience)

If ParserNG helps your project, please consider starring the repository or buying me a coffee.

About

ParserNG is a pure-Java, blazing-fast math expression parser with Vector API (JDK 21+) Turbo mode for massive bulk performance. It supports symbolic/numeric differentiation, integration, equation solving, matrices, statistics and more. Millions of ops/sec.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages