Git Product home page Git Product logo

gbenroscience / parserng Goto Github PK

View Code? Open in Web Editor NEW
34.0 6.0 7.0 998 KB

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 has no native dependencies.

License: Apache License 2.0

Java 100.00%
math-expressions matrix-calculations parsing parser matrix mathematics calculus statistics mathparser math-parser

parserng's People

Contributors

gbenroscience avatar judovana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

parserng's Issues

Instructions in readme.md

The README.md file states:

MathExpression expression = new MathExpression("x^2+5*x+1");
for(int i=0; i<100000; i++){
expression.setValue("x", String.valueOf(i) );
expression.solve();//Use the value from here according to your iterative needs...e.g plot a graph , do some summation etc..
}

However, running this code results in the expression.solve() returning a syntax error each time.

In order to get it to work, I had to set the expression first with x=0;x^2+5x+1. Notice the initialization of x=0 in the expression. MathExpression expression = new MathExpression("x=0;x^2+5x+1");

Then, it worked just fine.

If the intention is to not require initialization before a loop, please correct MathExpression code. If the intention is to keep it the way it is, please update your instructions to include the fact that the expression needs to be initialized.

Excellent work, by the way!!

Add Exception to Function

Can you please extend your Library such that e.g. the Function class is throwing an excpetion if something goes wrong e.g. during parsing or calculation?

e.g. like

public Function(String input) throws Exception (or InputMissmatchException){
....
}

That would be very kind.

Thank you - cheers
Dirk

Arithmetical-Logical parser

hi!

I had started to look into ParserNG, because it seemed to be best fit for judovana/jenkins-report-generic-chart-column@52421b0 (and few following commits)

I think the best would be to contribute the

I would return it back to your project moreover as its, next to MathExpression as ArithmeticalLogicalExpression (so original code will not be alerted), where ArithmeticalLogicalExpression will enhance MathExpression with comparisons and bool algebra. My current implementation do not support brackets. TBH, I'm not super excited to add, but maybe you would be able to help. If I would be doing that, I guess I will be lazy, and will take different bracket then () :)

Before I invest time to do so, are you interested by this feature or do you rather incline to keep it in downstream project?

The tests are worthy to check i guess;

Decimal part looks strange

A simple calculation:
6249.8+7522.1+7881.7+4339.5

Returns the following result:
25993.100000000002

But expected:
25993.1

Deploy on maven central?

Hi,

is there some plans to deploy this library on maven central? Or is there another repository where it is available, such as jitpack.io?

ParserNG fails to parse a simple math expression

Hi,

I may be missing something but I tried to write the following:

MathExpression parserng = new MathExpression("x-x/y");

And I get the following error in the logs: DETECTED ERROR! IN [(, x, -, x, /, y, )]

I'm not sure what I am doing wrong :)

statistic functions can not accept single expression as input

Hello!
This is very severe issue which is prohibiting usage of parserng in deployment.

If statistic function is given eg sum(5,4) it works, when it is given sum(5) it works.
When it is given sum(1+1,2+2) it works. However when it is given sum(1+1) it fails.
Notable is, that eg sum(sin(5)) works too. However sum(sin(5)+(sin(5)) don't.

All my inputs for parserNG are generated, so it took some time to see why some of the first calls fails. Yes first, as in in first call they have just one argument. Also not all equations have expression in first argument..

The issue is reproduced here: #23
Possible workaround suggested at: #24
The issue is not related to #22 ; was jsut accidently hit there.

The fix would be harder. It seems coma is somewhere handled wrongly. I tried, but but failed. IMHO, parserNG do nto have enough juint coverage to actually affrod proepr fix. But you know internals better.

The internal isse is visibel like this:
sum(1,2) is proeperly parsed and sent to sum impelmetnation as two arguments as 1,2
sum(1+1,2+2) is proeperly parsed, evaluated and sent to sum impelmetnation as two arguments as 2,4
however sum(1+1) is wronlgy parsed and not evaluated, and send to sum implemetnation as three arguments 1,+,1

@gbenroscience @gbenrojiboye can you fix it? If not, can you please participate on workaround? On short run, the workaround is just: https://github.com/gbenroscience/ParserNG/pull/24/files#diff-7592ec3fb1f62c29d86d7c8c826fc5a684c85caee27fc35b7b6c3c5628bc47e1R101
Which can be then reused in any existing statistic function, or in any override of statistic function (see 0c7177e)

The workaround is checking the input on function. If it is all numbers, then it is passed in.
If it is not all numbers, then it is joined first and evaluated. Then result is passed in.

Unless the issue is resolved "properly" all the hardcoded statistic function can reuse above workaround.

There is acompanying issue, when hardcoded not-statistic functions eg sin or cos can actually take several argument, and missinterpret them:
sin(5) ok. sin(5+5) ok. However sin(5,5) is accepted, and evaluated as sin((5)(5)) whis is sin(5*5) which is wrong.
This issue is not fatal, and as blocking as first issue,
Still the fix for both issues seems to go deep into parsetr. On longest run the statistic an non statistc functions should be aligned.

The issue is also reproduced here: #23
and also workaround suggested at: #24 by moving non statistic sin to statistic, and properly throwing exception if more then one argument is set.

@gbenrojiboye @gbenroscience Please, look into the PRs or suggest better solution, otherwise we will need to live only in the fork of ParserNG instead of contributing back.

Important highlight: @gbenrojiboye @gbenroscience this issue is not caused by any recent commits. I had tracked it down to first public commit on this repo

I find it slow in multithreaded environment

Nice project!

When you run on a multi threaded environment , I get performance for solve() in 3 digit milliseconds and over time performance degrade to 4 digit milliseconds.
I am doing simple expression and as instructed I'm not creating the expression each time.
( using Java 11)
i would expect it to take nano seconds , am i wrong ?

static MathExpression expression = new MathExpression("a=0;b=0;sqrt(a-b)");

Any help is appreciated.

not playing nicely with java module system?

Hi there, I'm trying to use your library, but can't get it to resolve, despite being included fine in the build.gradle, I can't see any of the classes. I suspect it's something to do with the new java module system, where it needs a requires line in my module-info.java file, but it can't be resolved there either. When I look around, it seems you have odd ("math") package names, could that have to do with it, or is there something else going on? Any ideas? :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.