Giter Site home page Giter Site logo

mariuszgromada / mathparser.org-mxparser Goto Github PK

View Code? Open in Web Editor NEW
887.0 34.0 149.0 32.41 MB

Math Parser Java Android C# .NET/MONO (.NET Framework, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS) CLS Library - a super easy, rich and flexible mathematical expression parser (expression evaluator, expression provided as plain text / strings) for JAVA and C#. Main features: rich built-in library of operators, constants, math functions, user defined: arguments, functions, recursive functions and general recursion (direct / indirect). Additionally parser provides grammar and internal syntax checking.

Home Page: https://mathparser.org/

License: Other

C# 26.92% Java 28.20% C++ 0.01% C 0.01% F# 0.01% Visual Basic .NET 0.01% Batchfile 0.02% HTML 34.29% TypeScript 10.54%
mathematical-expressions-evaluator math-parser expression-evaluator java dotnet dotnet-core dotnet-standard pcl xamarin xamarin-android

mathparser.org-mxparser's People

Contributors

aviperl avatar bastio84 avatar bitdeli-chef avatar futurearchitec avatar mariuszgromada avatar nikolausmoll 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  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  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  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

mathparser.org-mxparser's Issues

Not a number result when adding too many arguments

Hello. I'm using mXparser with Xamarin.iOS, using latest stable Mono and here's my problem:
I'm creating a list of arguments, with names like A, B, C, D, E, F ... X, Y, Z, AA, AB, AC, AD .. AX, AY, AZ, BA, BB, BC .. etc.
Each argument has a value. Maximum number of arguments is about 150.
Expression string could be something simple like "A-50", so there could be 150 argument, but only 1, 2, 3 or 4 of them are used in expression string.
If I add just 2 arguments (example - A=65, B=0) and use expression string "A-50", I have correct result 15.
But, if I add more Arguments like A=65, B=0, C=0, D=0, E=95, ... etc, I get "not a number" result with the same expression string.
Inspecting debug, there is an error message, something connected with duplicate arguments. But I'm absolutely sure, that I have no duplicate arguments.

Trailing letter 'e' problem

Function f = new Function("Fefe(n) = 10");
System.out.println(f.getFunctionName());

Reveals
Fef

This some some general tokenization issue, for sure small bug, I will correct it soon.

Speed when debugging

Hi

I am finding your parser very useful. However, I find that when you run the .Net dll in Visual Studio it is very slow to parse a long expression when running under the debugger F5 vs running without debugger Cntrl - F5.

For example
Expression e = new Expression("VRI * (1 - MP_MatDed) * ((1 + Inv_Ret) ^ (MP_Durn - t)) / ((1 + Disc_Ret) ^ (MP_Durn - t)) - FCF");

As I am parsing lots of expressions (effectively I am allowing users to enter expressions to process) the slow speed effectively makes debugging impossible.

The actual processing without debugger is fine.

Can seethe difference if create unit test and Run vs Debug Test.

Can anything be done to improve the speed under the debugger?

Thanks
Martin

Too many C# projects

Why did you create separate projects for different platforms if netstandard1.0 supports them all?
image

Ad NaN symbol

To provide NaN constant representing Not-a-Number

Add coalesce(x1, x2, ..., xn) function

coalesce(x1, x2, ..., xn) will return first not NaN value on the list, this is equivalent to the

if ( x1 != NaN) return x1
else if ( x2 != NaN) return x2
...
else if ( x_{n-1} != NaN) return x_{n-1}
else return xn

List argument

Hello,

It would be great to make some calculation on Java Collections or Arrays of Double

Expression e = new Expression("add(x)");
e.addArguments(new Argument("x", new Double[]{1.0, 2.0 , 3.0}));

PS: Thanks for making alive this great library

String support

I think I already know the answer, but is there any way to work with strings as variables/constants and get a string result? It looks like everything is converted to doubles and there's not a way to work with strings, but I just wanted to verify.

Solving equations - help wanted

Hi,

I have a simple expression like: result = -6 + 125 * (value/(2^16)); where value is a runtime number.
This works perfect. What I want to do is calculate the value were result is known and the value must be calculated. Doing this in code is of course not an issue (change the function to calculate value), but this must be runtime. Also the formula is runtime created. What is the best approach ?

Negative in if statement

Hi

I have

Argument a = new Argument("a");
Argument b = new Argument("b");

var e = new Expression("if(a=6,-b,15)", a, b);
a.setArgumentValue(6);
b.setArgumentValue(5);
result = e.calculate();

This works fine and returns result = -5.

However it
a.setArgumentValue(1);

then this takes a long time to execute the calculate() and then returns NaN instead of 15 as a is not equal to 6.

if however the expression is "if(a=6,b,15)" then this works fine and returns 15

Also expression = if(a=6,0-b,15)" works fine

Problem seems to be if you start with a negative sign in true condition part but your condition evaluates to false

Multiple solutions for f(x) = 0

http://mathparser.org/mxparser-tutorial/solving-equation-fx-0/

In case 3, the code's output shows that the library supports multiple solutions for f(x) = 0

Case 3: Solve cos(x) = 0 for x in [pi, pi] (root not bracketed)

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("solve( cos(x), x, -pi, pi )");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );

Output:

[mXparser-v.4.0.0] Res: solve( cos(x), x, -pi, pi ) = -1.57079633
[mXparser-v.4.0.0] Res: solve( cos(x), x, -pi, pi ) = 1.57079633

However, copying the exact code doesn't produce the same output, i.e. only showing the first solution of cos(x) = 0

Output:

[mXparser-v.4.0.0] Res: solve( cos(x), x, -pi, pi ) = -1.57079633

So, how to make this work?

P.S. I really love your library!

C# build problems

I don't seem to be able to build using VS2015, it's complaining about:

Unable to get MD5 checksum for the key file "..........\pfx-keys\mariuszgromada.org.pfx". Could not find a part of the path 'D:\git\pfx-keys\mariuszgromada.org.pfx'. mXparser-30-PCL C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets 2884

Possibility to remove built-in tokens

JAVA:
mXparser.removeBuiltinTokens(String... tokens)
mXparser.unremoveBuiltinTokens(String... tokens)
mXparser.unremoveAllBuiltinTokens()
mXparser.getBuiltinTokensToRemove()

.NET:
mXparser.removeBuiltinTokens(params String[] tokens)
mXparser.unremoveBuiltinTokens(params String[] tokens)
mXparser.unremoveAllBuiltinTokens()
mXparser.getBuiltinTokensToRemove()

Modify / Remove parser key words (tokens)

Enhancement requested by Saboureau vis email.

API extension to be able to:

  • Modify existing tokens strings (i.e. Li(x) is a function, Saboureau has a need to use "Li" keyword as user defined argument)
  • Remove given tokens to limit mXparser functionality

This will be added :-)

Leading zeros (i.e. 0002) are not recognized as numbers

Issue reported by Theodor
http://mathparser.org/share-how-you-use-mxparser/#comment-2342

Hi Mariusz,

first: thanks for this great library! It is nearly perfect!
second: I have a problem with the following expression:

Expression ex = new Expression("1-0200"); //=-199 // problem with preceding zero

In version 3 of your library everything runs fine and syntax was correct; after upgrading to your latest version the method checkSyntax returns false. I ran threw your sourcecode, but I can't figure out the position which I have to change.
Do you have any idea where I have to look or what I have to change?

Thanks
Theodor

Number literals from various base systems support - base between 1 and 36

Examples:

b2.001 - binary
b.001 - binary
b8.2313 - octal
o.123 - octal
b10.1231234 - decimal
b16.121acdf - hexadecimal
h.123cde - hexadecimal
b3.123 - base 4
....
up to 36

Digits:

0 - 0
1 - 1
2 - 2
3 - 3
4 - 4
5 - 5
6 - 6
7 - 7
8 - 8
9 - 9
10 - A
11 - B
12 - C
13 - D
14 - E
15 - F
16 - G
17 - H
18 - I
19 - J
20 - K
21 - L
22 - M
23 - N
24 - O
25 - P
26 - Q
27 - R
28 - S
29 - T
30 - U
31 - V
32 - W
33 - X
34 - Y
35 - Z

Question: get arguments from expression

Hi I have just started using this for expression parsing and it looks great.

I would like to ask if it is possible to determine from an expression what the arguments are.

For example if the user types the expression "a*x^2 +b*x +c"

I would like to be able to run the parser and automatically determine that they need to supply values for "a", "b", "c" and "x" to get the expression to calculate.

Is there a way to do that?

Thank you
Nick

Get key words list

Currently there is a getHelp() function which returns formatted help string. For users who wants to format output by themselves getKeyWords() function will be implemented.

Nuget Support

Hi, nice work! It looks pretty good!!.

i don't have any issue, only few questions:

1.- What license has? Can i use in commercial projects?
2.- Can you release this projects in Nuget? Maybe, if you don't have time, i can do it for you ;)

Regards!

User defined arguments ending in e

Hi

It appears that if you have an expression with a user defined argument ending in "e" (for example "a + XYZe + 3") the expression parser creates 2 tokens for XYZe ie,. XYZ and e.

This means that you can't have user defined arguments that end with an "e"

Thanks
Martin

Any change/thought regarding .Net Core?

Package MathParser.org-mXparser 3.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package MathParser.org-mXparser 3.0.0 supports: net40-client (.NETFramework,Version=v4.0,Profile=Client) One or more packages are incompatible with .NETCoreApp,Version=v1.0.

I wasn't expecting it to work just yet as .Net Core is still a WIP, but figured I would try... as well as inquire as to if there are any plans for a version that is supported?

System.format.exception - system.IO.EndOfStreamException

Hi Marius,

We have 2 (pc's) setups which have identical source code and packages.
On one pc we get System.format.exception - system.IO.EndOfStreamException several time when using
checksyntax.
We tried playing with culturesettings but we don't find were it goes wrong. The setargument value is of type double.

           Argument _inputArgumentValue = new Argument("value", 0);
           Expression _expresion;
            _inputArgumentValue.setArgumentValue(value); //value is a double
          
	_expresion = new Expression(mv.InvCalculationExpression, _inputArgumentValue);
			
            if (_expresion.checkSyntax())
            {
                double temp = _expresion.calculate();
                return double.IsNaN(temp) ? 0 : temp;
            }
            else
            {
                return 0;
            }

Detailed window
http://imgur.com/a/BzY42

Any idea ?

Regards

Simplification/expansion support

Hi,
I recently came across your xXparser project while doing some research regarding calculus and algebra. It did just fine in evaluating expressions and ran reasonably fast. What I am now interested in is support for expression simplification/expansion. Here is some illustrations of that feature:

  • "(x+1)^2 + 3x" could be expanded and simplified to "x^2 + 5x + 1"
  • "(x^2 + 3*x + 2) / (x+1)" could be simplified to "x+2"
    In here they managed to do it nicely.

It would be great if you could implement this on your project and I look forward to seeing it on action.

Exception thrown by getCopyOfInitialTokens()

As reported by Akagara http://mathparser.org/share-how-you-use-mxparser/#comment-585

The problem occurs when lexer syntax is not ok. In this case getCopyOfInitialTokens() runs the tokenizeExpressionString() method, and then the tokens level evaluation (i.e. parenthesis), which uses stack, which in some cases (lexer syntax not ok) might be empty.

This will be corrected: checkLexSyntax() method will be added. Additionally there will be an option of getting tokens without token level evaluation.

Support for custom functions

Currently addFunction only support a string expression, would it be possible to extend it to take a .NET function as well?

Ex.

Expression e = new Expression("customfunc(var1+var2)");
e.addFunction("customfunc", CustomFunc);

public static decimal CustomFunc(decimal input) {..do what ever..}

Add the Java library to Maven Central

It would be awesome if you could add this library to Maven central. As this is the go to place for most Java developers for third party libraries.

Dependent arguments and StackOverflowError

This construction has little sense, but it generates Stack Overflow Error as there is no stop condition. There is a need to introduce recursive call counter - after reaching NaN value is returned.

Argument x = new Argument("x = 2*y");
Argument y = new Argument("y = 2*x"); 
x.addDefinitions(y);
y.addDefinitions(x);
x.getArgumentValue();

Binary Operators support

Hi,
not sure if I missed it somewhere but seems like there is no support for binary operators.

few examples:

x>>15 //shift
~x //complement
x&1 //binary AND

would be great additions and make this library even more useful. Let me know what you think

Output issue

Expression ex = new Expression(mathInput);
Console.WriteLine(ex.calculate());

This simple code returns "¤¤¤" as output in the console.

mathInput is just 2 * 5, and outputs to just that in the console. It's a string too!
What the heck is wrong?! I am using the .NET 4.5 version as my application is using that version.

Possibility to change built-in token

JAVA:
mXparser.modifyBuiltinToken(String currentToken, String newToken)
mXparser.modifyBuiltinToken(String currentToken, String newToken, String newTokenDescription)
mXparser.unmodifyBuiltinTokens(String... currentOrNewTokens)
mXparser.unmodifyAllBuiltinTokens()
mXparser.getBuiltinTokensToModify()

.NET:
mXparser.modifyBuiltinToken(String currentToken, String newToken)
mXparser.modifyBuiltinToken(String currentToken, String newToken, String newTokenDescription)
mXparser.unmodifyBuiltinTokens(params String[] currentOrNewTokens)
mXparser.unmodifyAllBuiltinTokens()
mXparser.getBuiltinTokensToModify()

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.