All Projects → sbesada → java.math.expression.parser

sbesada / java.math.expression.parser

Licence: Apache-2.0 license
java math expression parser is faster than JEP

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to java.math.expression.parser

string-math
Evaluates a math expression from a string. Supports variables and custom operators.
Stars: ✭ 14 (-44%)
Mutual labels:  math, expression-parser, expression-evaluator
Mathjs
An extensive math library for JavaScript and Node.js
Stars: ✭ 11,861 (+47344%)
Mutual labels:  math, complex-numbers, expression-evaluator
expression-evaluator
A math expression evaluator built with JavaScript
Stars: ✭ 25 (+0%)
Mutual labels:  math, expression-evaluator
bcmath-extended
Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions.
Stars: ✭ 59 (+136%)
Mutual labels:  math, complex-numbers
Swift Complex
Complex numbers in Swift
Stars: ✭ 66 (+164%)
Mutual labels:  math, complex-numbers
NCalc2
GitHub clone of NCalc from http://ncalc.codeplex.com/
Stars: ✭ 97 (+288%)
Mutual labels:  expression-parser, expression-evaluator
decimal-eval
A tiny, safe, fast JavaScript library for decimal arithmetic expressions.
Stars: ✭ 18 (-28%)
Mutual labels:  math, expression-evaluator
Swift Numerics
Numerical APIs for Swift
Stars: ✭ 1,052 (+4108%)
Mutual labels:  math, complex-numbers
Numphp
Mathematical PHP library for scientific computing
Stars: ✭ 120 (+380%)
Mutual labels:  math, complex-numbers
Calc
C-style arbitrary precision calculator
Stars: ✭ 127 (+408%)
Mutual labels:  math, complex-numbers
pratt-calculator
A very simple expression evaluator written using a Pratt Parser
Stars: ✭ 22 (-12%)
Mutual labels:  expression-parser, expression-evaluator
nim-mathexpr
Tiny math expression evaluator library implemented in pure Nim
Stars: ✭ 58 (+132%)
Mutual labels:  math, mathematical-expressions-evaluator
Grassmann.jl
⟨Leibniz-Grassmann-Clifford⟩ differential geometric algebra / multivector simplicial complex
Stars: ✭ 289 (+1056%)
Mutual labels:  math, complex-numbers
Algebra
means completeness and balancing, from the Arabic word الجبر
Stars: ✭ 92 (+268%)
Mutual labels:  math, complex-numbers
MathImprove
Modify and Improve math expressions.
Stars: ✭ 13 (-48%)
Mutual labels:  math, math-parser
mathcore
Advanced .NET math library (.NET Standard).
Stars: ✭ 24 (-4%)
Mutual labels:  math, complex-numbers
R-stats-machine-learning
Misc Statistics and Machine Learning codes in R
Stars: ✭ 33 (+32%)
Mutual labels:  decision-trees
bewl
A DSL for the internal language of a topos
Stars: ✭ 41 (+64%)
Mutual labels:  math
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (+28%)
Mutual labels:  math
commons-statistics
Statistics
Stars: ✭ 35 (+40%)
Mutual labels:  math

java.math.expression.parser

java math expression parser is a maven project that lets you parse or evaluate math expressions.

This algorithm does not use a decision tree. It is a kind of Recursive Ascent Parser (https://en.wikipedia.org/wiki/Recursive_ascent_parser). In fact, it is LR parser (Left-Right Parser) without backtracking.

This algorithm is faster than JEP math expresion parser!!! If you compare java.math.expression.parse and JEP, this algorithm only needs 25% of the time to parse the same expression as JEP. With other algorithms that use trees like:

                                                                                   ---------
                                                                                   |   +   |
                                                                                   ---------
                                                                                       |
                                                                                ---------------
                                                                                |             |
                                                                            ---------     ---------
                                                                            |   1   |     |   *   |
                                                                            ---------     ---------

It is even faster than them. This library is 10 times faster and it is tested using matlab. The python version of this library is pymep. You can find pymep in my github repository.

Features

math functions

  • sin, cos, sinh, cosh, tan, tanh, asin, acos, atan
  • pi, e
  • ln (natural logarithm), log (decimal logarithm)
  • sqrt, cbrt
  • radians or degrees
  • complex or real numbers

parentheses

  • (...)

variables:

  • Expressions in vars

    String f_xs = "x+5*y+(3 -y)";
    final Point xo = new Point("x", "1+1");
    final Point yo = new Point("y", "0+2*0+1*5-5 +1^4")
    

Examples:

In the test package you can see more examples with different constructors

Real numbers

    Parser.simpleEval("6.5*7.8^2.3 + (3.5^3+7/2)^3 -(5*4/(2-3))*4"); --> for real functions

    String f_x = "+3 +5*5*(+1)";

    ParserResult result = Parser.eval(f_x); --> for real or complex functions
    assertTrue(result.getValue() == 28.0);

    final Point xo = new Point("x", new Double(2));
    f_x = "2.35*e^(-3)*x";

    result = Parser.eval(f_x, xo);  --> for real or complex functions with real or complex vars
    assertTrue(result.getValue() == 0.2339992213289606);

    final Point xo = new Point("x", new Double(2));
    final Point zo = new Point("z", new Double(1));
    String f_xs = " 2*(-(((z*3)*sqrt(x^(2)))+3))";        
    
    Parser.eval(f_xs, xo, zo); --> multiple vars
    
    String f_xs = "x+5*y+(3 -y)";
    final Point xo = new Point("x", "1+1");
    final Point yo = new Point("y", "0+2*0+1*5-5 +1^4"); //math expression in vars

    ParserResult result = Parser.eval(f_xs, xo, yo);

Complex numbers

    String f_x = " e^(1*x*acos((3/2-2j)^(pi)))";
    
    Point xo = new Point("x", new Complex(1, 2)); --> complex var: 1+ 2j
    ParserResult result = Parser.eval(f_x, xo);
    
    String f_x = "1+j +x";
    final Point xo = new Point("x", "2 +j"); //complex math expression in vars

    ParserResult result = Parser.eval(f_x, xo);

Execution time

   These are the results for the version 3.0 (master). You can check the speedTests in the project

   Parser.simpleEval("6.5*7.8^2.3 + (3.5^3+7/2)^3 -(5*4/(2-3))*4 + 6.5*7.8^2.3 + (3.5^3+7/2)^3 -(5*4/(2-3))*4
   + 6.5*7.8^2.3 + (3.5^3+7/2)^3 -(5*4/(2-3))*4 + 6.5*7.8^2.3 + (3.5^3+7/2)^3 -(5*4/(2-3))*4");

   CPU: i7-6500U
   
   test 1: one execution: 3ms
   test 2: 100000 executions : 2100 ms --> mean time 0.021 ms per execution 
   test 3: one million executions: 16500 ms --> mean time 0.0165 ms per execution

This version is compiled for Java 1.6

If you are interested in maths, you can visit my java numerical library in my github repository which uses java.math.expression.parser to evaluate functions.

Professional Services

If you are interested in logical parsers or any task related to parsers, you can consult my professional services page https://github.com/sbesada/professional.services

Donation

If you think that my work deserves a donation, you can do it: https://sbesada.github.io/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].