If you use mXparser sharing this information is more than welcome 🙂 Please post a comment to that page describing in a few word your use case.

Thanks,

*Mariusz Gromada*

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

This parser is great, I am using it to my thesis project where solving user input formulas is the goal.

Thanks a lot!

Leroy

Thanks 🙂

Hi Mariusz Gromada,

I was looking some help to make something like this but not like yours, yours is awesome, I stopped looking any further code. Can I get your permission to use your tool in my project.

Please send me a confirmation to my email as don't want to violate any copyright law.

Thanks

Murad

Yes you can 🙂 mXparser is distributed under simplified BSD license, it means that you can use it without limitations. The only condition is to put somewhere information that you are using mXparser, i.e. in case you provide license, then please reproduce also license of mXparser.

Best regards

How to solve a multi-line equation e,g

x+y=4

2x+3y=7

i need the value of x and y

x+y = 4 is ambiguous, it gives infinitely many solutions. What do you mean to solve x+y=4?

Mariusz Gromada,

This parser is awesome! I am using it to finish a capstone class project. The user of my program can enter an equation in many formats. This parser enables me to ignore the headache of parsing the strings myself. It's almost like running the user input as code.

Thank you!

Thanks 🙂

Hope you may be able to help with this small issue I have had. I am using an array of arguments. When I want to get the value of one argument and return the double I am using getArgumentValue. However, this is returning only an estimate of the argument value.

For example, argument1 has value 748.429.

getArgumentValue returns 750.0

Is there an easier way to get the value to return accurately as a double?

Thank you for your message. Of course I will be happy to help 🙂 I will contact you directly via email.

Best regards

getArgumentValue() should be fine here, can I ask for some code example?

BR,

Mariusz

Issue reported by TW was a consequence of constructor definition. Generally speaking constructor Argument(String argumentName, String argumentExpressionString, PrimitiveElement... elements) should be used for "dependent" argument creation, where argument value depends on the expression provided in argumentExpressionString and optional other arguments, constants, functions given in the variadic PrimitiveElement list. Calling getArgumentValue() method on dependent argument will always call calculate() on the hidden expression, thus if expression is "constant" (no arguments) the value will be always the same. To avoid this situation always carefully choose the constructors, and if still not sure, check argument type calling getArgumentType().

Thank you for great question and the feedback! 🙂

Kind regards

Hello!

I need to show what he thought of the derivative function.

It's so f (x) = x ^ 3 f (x) '= 3 * x ^ 2. How to do it? Could you help me? Der function (sin (x), x) calculates only. And I need to show the derivative.

Hello!

I need to show what he considered a derivative function.

This is so f(x) = x ^ 3 f(x) `= 3 * x ^ 2. How to do it? Can you help me?

Thanks a lot for this great work.

I found a problem :

Expression a= new Expression("0.1+0.1+0.1");

System.out.println("Res : "+a.calculate());

result:

Res : 0.30000000000000004

...................................................

i think you can use bigdecimal instead of double.

more information:

http://floating-point-gui.de/

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Thank you very much for the feedback! I am aware of double disadvantages, but still decided to stick with double as my parser is implemented also in C#/.NET where BigDecimal is not available (or it was not present before). Additionally parser was written from the mathematician point of view. I understand that in case of money calculation it might be an issue. In the next release there will we delivered nice "round" function with "precision" parameter.

Best regards,

Mariusz

3.0.0 will bring intelligent automatics ulp rounding, this will minimize issues similar to the 0.1 + 0.1 + 0.1 = 0.30000000000000004

Nest regards

0.1+0.1+0.1=0.3 since 3.0.0 🙂

I found this today on the internet 🙂 Nice online calculator based on mXparser.

http://mxcalc.somee.com/

Hello Mr Gromada, thank you for the useful product you are developing. I wanted to ask whether the parser will support complex numbers, vectors or cubic/quadratic equation solving in the future?

Thank you very much in advance!

Dear Theme,

Thank you for your feedback - it is very important to me!

Regarding complex number - I am thinking about that - it would be great as mXparser supports user defined recursion. Other things like vectors ... we will see.

Kind regards

I am very thankful for your effort, but:

1. when I calculate sin(pi), it gave a very small number (order to 10^-16) but not zero

2. when I install 3.0.0 to my package in xamarin via NuGet, the following error came out:

Could not install package 'MathParser.org-mXparser 3.0.0'. You are trying to install this package into a project that targets 'portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

I will be glad if you can fix that

Thanks.

Dear Nat Chen,

Thanks a lot for your feedback!

Referring to the point 1 - I am guessing this is the double precision issue as pi is represented as double number. But yes i can extend sine function definition to check whether argument is equal to numerically defined n*pi then set to 0.

In case of point 2 - nuget package was prepared targeting .NET framework 4.0 client profile. I assume I should prepare some other version of nuget package?

Best regards

Really glad to see your reply. I am happy to wait for your update =)

Thanks,

Nat

Dear Nat Chen,

I need few days to manage that. I know what needs to be done (Portable Class Library for .NET). Initially I tested mXparser for PCL - after few minor changes it worked, but requires some small API changes.

Best regards

I do think that is a problem of your program setting in NuGet that you say you support Android but not iOS. However, this problem was not happening in 2.4.0 version. Please check. Thanks.

Currently Android is supported only in JAVA library. I am working on the PCL version for .NET - according to Visual Studio PCL will work with Xamarin.

Best regards

Hi here is me again

Do you have plan in implement complex number calculation?

Thanks that 🙂

I am thinking about that - but this is bigger change.

Best regards

AFAIK, in .NET it should not be so complicated since System.Numerics supports Complex numbers after NET 4.0. If you plan to build the Complex structure from scratch, it will take a lot of time.

Best Regards!

mXparser provides API for JAVA and .NET - I plan to keep this, so thinking about development I need to consider this.

Best regards

I am looking into using mxparser into evaluating expression (rules) that match binary expressions in data with is in a Map. So functionally something like map.get('key')[0].equals('something'). Would this be possible with mxparser?

Dear Michel,

Thank you for your feedback. Can you please provide more details on this specific use case?

Kind regards

I have Map<String,List> and expressions on that map. The values (typically a list with length 1, can be a string, integer, or even date. What I would like to be happening is defining an expression alike 'property[a] = property[b] && properyty[start-date] >= date-calc[now - day[1]].

For now I'm taking the approach that I'm parsing the expression above and end up with a math expression that mxparser can handle.

Greetings,

I am developing an android math application. It will be free. I will, however, put in adverts on the app. I wont alter the code in any way. I only want to use the .jar to parse mathematical expressions. Should I issue out the source code? What do I need to do not to infringe on the license. I looked everywhere for your email and I could not find it.

Hi,

You can use mXparser without limitations (binary, source, changing source - everything is allowed). You do not need to publish your source code. The only requirement according to the license is to retain / redistribute copyright notice - please follow: http://mathparser.org/mxparser-license/

Best rgards

I'm using it for a calculator and it's great. I would like to indicate some bugs

Expression relating factorial " ! " cause the application to hang and stop working.

For example

A. 5!^2 (where power symbol comes immediately after factorial )

B. 5!-3 and 5!+3 or similar expressions

C. 10/5-(5!) and 10/5+(5!) or similar expressions (though 10/5+5! works fine, but when I put brackets around factorial it stops responding )

Thanks! I will find and correct those bugs!

I made test using Apache POI formula evaluater and mxparser and testing the same expression, the result was that, mxparser was 4 times slower than Apache POI...

Thank you for your opinion. I do not claim mXparser is the fastest. Please check some options that can speed up calculation process:

mXparser.disableUlpRounding();

mXparser.setExactComparison();

Best regards

Hey Mariusz,

I had a quick query.

We are planning to use your library in one of our application and while doing the POC, we came across a scenario wherein we are required to validate if the expression is a valid expression (For eg : (2=3) | (2<3) should show as correct but (2=3) | (2<3 should throw an error since the closing bracket is missing. Is there any support for such validation in the library? Also, we need to validate the expression before it is actually executed.

Thanks in advance!

-Melwin

Hi Melwin,

This is already supported. Please refer to checkSyntax() and getErrorMessage() in Expression class. Please find below example:

Expression e = new Expression("(2=3) | (2<3)");

System.out.println("-------------- Case 1 --------------");

System.out.println("Syntax : " + e.checkSyntax());

System.out.println("Message : " + e.getErrorMessage());

System.out.println("-------------- Case 2 --------------");

e.setExpressionString("(2=3) | (2<3");

System.out.println("Syntax : " + e.checkSyntax());

System.out.println("Message : " + e.getErrorMessage());

-------------- Case 1 --------------

Syntax : true

Message : [(2=3) | (2<3)] checking ...

[(2=3) | (2<3)] no errors.

-------------- Case 2 --------------

Syntax : false

Message : [(2=3) | (2<3] checking ...

[(2=3) | (2<3] lexical error

Encountered "" at line 1, column 12.

...

...

...

...

...

...

...

...

...

...

...

...

Was expecting one of:

")" ...

"+" ...

"-" ...

"*" ...

"/" ...

"^" ...

"%" ...

"!" ...

"< " ... "<=" ... ">" ...

">=" ...

[(2=3) | (2<3] errors were found.

Best regards.

Hey Mariusz,

Thanks a lot for the reply!

I have one addition problem as well.

We have an expression as - IF(arg1="ABC",1,0)

wherein we need to compare the argument to a String, is this supported?

I tried writing the expression as ,

Expression exp = new Expression("if(arg1='ABC',1,0)",arg1);

(But it didn't work)

I did try other methods as well, but no success 🙁

So , is such a comparison supported?

Thanks again in advance !

Regards,

Melwin

Hi Melwin,

Unfortunately (as of now) operations on strings are not supported.

Best regards

Oh! I see. Nonetheless, it's a really good parser and also thank you Mariusz for your super quick responses!

- Melwin

Hi Mariusz,

We were using your library to build an expression.

And we used the checkSyntax() method to validate our expression.

- We accept the expression from the user Eg : ((_d1+(_d^_g)))

- Also, we extract the variable name from the expression using getCopyOfInitialTokens() and identify the variables by matching tokens having underscore in the token name

- Then we assign value to variables and then create an Expression as ,

Expression ex = new Expression(formula,argumentList.toArray(new Argument[argumentList.size()] ));

where argumentList is the list of arguments

- Then we check the syntax of the expression

So, the issue here is,

- if the user places an extra parenthesis at the beginning, the getCopyOfInitialTokens() works fine but checkSyntax() gives false

- however, if the user places an extra parenthesis at the end, the getCopyOfInitialTokens() throws an exception (java.util.EmptyStackException)

- Unfortunately it is a catch 22 situation, because to check the syntax we need the arguments and to get the arguments we need to use getCopyOfInitialTokens().

Any help?

Thanks.

- Akagra

Hi Akagra,

Thank you for your feedback. I will check and try to solve.

Kind regards

It seems this is related to stack issue. Lexer analysis has to be ok for getCopyOfInitialTokens - i will add checkLexerSytnatx() method.

Hi Mariuz,

Excellent work, thanks..

I need to obtain values from a nested sum, is it possible to call an external function (web service) to get this values?

Constant a = new Constant("w = 3");

Constant b = new Constant("z = 2");

Function g = new Function("NR(x,s) = ???"); // matrix values or web service call

Function f = new Function("NP(x,s) = ???");

Function i = new Function("f(x,s) = NR(x,s) + NP(x,s)", g, f);

Function h = new Function("func(s) = (1/z) * sum(x, 1, z, f(x,s))", b, i);

String expStr = "(1/w) * sum(s, 1, w, func(s))";

or maybe call a web service and define an array or matrix of arguments...

Any help ??

Hi Mariuz

I am loving this so far but, I need a bit of help with something.

I am trying to make a calculator for Android but I can't figure this out.

I have a String with the literal expresion to be solved. I'm using the mxparser to solve it but, how can you display the result on the textView?

Hi Darío,

Assuming you have string s with expression, i.e.:

String s = "1+2";

Expression e = new Expression(s);

String result = Double.toString(e.calculate());

You can then send result to the textView.

Best regards

Hi.

Thanks for attending my Comment.

I'm getting some errors while trying to run the app.

The report says:

-Error:Error converting bytecode to dex:

Cause: java.lang.RuntimeException: Exception parsing classes

-Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_71\bin\java.exe'' finished with non-zero exit value 1.

I wrote the method as you said. In case it might help, I'll write it too.

The operation is in the String named result

public void solve (View view){

Expression solution = new Expression(result);

String finalAnswer = Double.toString(solution.calculate());

display(finalAnswer);

}

Thanks for your time

Hi Mariusz,

Thanks for sharing this great library.

I'm thinking of adopting this library for custom added function parsing tool.

By the way after I reviewed the API document I couldn't find any aggregate functions which support arguments as a list or array format.

I'd like to parse the following equation

eq = abs(max(y)-min(y))

At this time y is type of array

Am I missed somthing?

Thnanks in advance.

Hi,

Unfortunately - vectors are not supported.

Best regards

Thanks for your reply.

If you use JAVA, try this:

String expression = "max(" + StringUtils.join(array,",") + ")";

Expression e = new Expression(expression);

I had the same problem and this works for me.

Best regards.

How can I calculate an N root in an expression with C#?

Hi Mariusz,

I have a hash table Map<Object, List> and I need to aggregate each array of Double.

As a sample, I created a map with one key and an array with 365 values.

The time to find the maximun among these 365 values is 18 secs.

Here the code:

final_map = map_as_list.entrySet()

.stream()

.collect(

Collectors.toMap(entry -> entry.getKey(),

entry -> {

List list = entry.getValue().stream()

.collect(Collectors.toList());

Double[] array = list.toArray(new Double[list.size()]);

String expression = "max"+"(" + StringUtils.join(array,",") + ")";

Expression e = new Expression(expression);

double value = e.calculate();

value = Math.round(value * 1000); value = value / 1000;

return value;

}));

How could I increase the performance? Is there a better way to use this library over a hash table?

Thanks.

Besta Regards,

Fabrizio

VB.net, VS 2012, stepping through the "Hello World!" demo(and my own project) I get the following error "Cannot find Expression.cs". When I let the program run normally, it does function but extremely slow. What is going on?

Hi Mariusz. I have a question. How to shown in the console derivative of the function. Example:

Input: x ^ 2-4 * sin (x)

Output in the console: 2 * x-4 * cos (x)

Here is the code

public static double derivative (String f, double znach) {

String znak = Double.toString (znach);

Argument x = new Argument ( "x =" + znak);

Expression e = new Expression ( "der (" + f + ", x)", x);

mXparser.consolePrintln ( "Res:" + e.getExpressionString () + "=" + e.calculate ());

return e.calculate ();

}

Thank's

mXparser provides only numerical differentiation - it means you can calculate the derivative value.

Thank you Mariusz. Your lib is great!!

Hello,

Thank you for making your parser freely available! I'm using it in a (free) Android app: https://play.google.com/store/apps/details?id=atorch.statspuzzles.

Cheers,

Adrian

Thanks for sharing! Great! 🙂

Someone who uses the app found a bug: 1!^1 appears to crash the parser. Has this been reported before?

It was fixed in v.4.0, current version is v.4.1, pls see the issue details

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/17

Which mXparser version are you using?

Hi, Mariusz

Thanks for your great parser! I have used it in Jdeveloper IDE - all work fine. Today I have tried the same code in Eclipse IDE.

import org.mariuszgromada.math.mxparser.Expression;

public class CalculatorImpl {

Expression e = new Expression("2+2");

And eclipse hightlight constructor - "The constructor Expression(String) is undefined"

Could you help me?

Hi,

Thanks for sharing opinion! 🙂 In case of your problem - looks like IDE issue. Have you been trying to recreate / refresh the project?

Best regards

Hi Mariusz,

Ma

I have a query regarding the usage of mxparser. We need a parser which works for both dotnet and objective-c. I know mxparser works for dotnet provide.

Let us know whether mxparser supports objective-c.

I do not see documentation for objective-c.

Best Regards,

Madhu.

Hi,

Unfortunately Objective-C is not supported. Library binaries are provided for JAVA and .NET/MON, including Xamarin.iOS. The only option to use mXparser on iOS is through JAVA or MONO (MONO meaning Xamarin.iOS).

Best regards

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

Hi Theodor,

Thanks for your feedback. Indeed i changed the grammar cleaning some patterns in regular expression. This is impossible to reverse without JavaCC. Please let me know your use case, why you need this leading '0' - If you have reasonable arguments I may consider allowing leading zeros.

Best regards

Support will be added again in 4.1

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/36

Hi Mariusz

Can I use the "AND" operator except for the operators "&", "&&", "/ \\" .

for example: Expression e = new Expression(" 3+2=10") ;

I've tried to change boolean operator && on a "AND" but don't this work.

Thank's

Hi Petr,

Currently unfortunately not. But still you have 3 additional tokens for boolean AND operation.

Best regards

The parser is truly amazing, it's exactly what I needed! I was just wondering if there was a way to represent large numbers in a normal decimal form rather than in a scientific form when doing calculations?

Thx Anon for your feedback 🙂 It is really important to me 🙂

In terms of very large numbers, in upcoming mXparser v.4.1 "Aeries" you will get full support for scientific notations + other numeral systems with different bases.

https://github.com/mariuszgromada/MathParser.org-mXparser/milestone/1

Referring to your problem - you always can input very large numbers directly (without scientific notation), but the output is always type double. In v.4.1 I will introduce some simple / nice function to format double as string, but still double will have its own limitation regarding numbers representation (meaning loosing precision on very huge numbers).

Best regards

Thanks for the reply, secondly one of the other issues is that a string like "3pi" will evaluate to NaN, instead of 3*pi. This goes for all other symbols and functions too, ie, "5sin(50)" evaluates to NaN. Can you also please address this in your update?

Lastly I've noticed that Logs and natural Logs of powers of multiples of 3 do not evaluate to precise numbers. ie, Log(1000) is 2.99999998 instead of 3, and Ln(e^6) is 5.999998 instead of 6.

Best Regards

"3pi" this is implicit multiplication, currently this is syntax error. I have doubts with introducing implicit multiplication... as this might be confusing. Byt will think on that.

Can you let me know what framework are you using (java, .net, ...)? mXparser is for numerical computation, not symbolical, and this small "rounding" error might occur. For java "ln(e^6)" gives perfect 6.0

Best regards

I'm using Java,

This is my code:

----------------------------------------------------

Expression e = new Expression("log(10,1000)");

String ms = String.valueOf(e.calculate());

System.out.println(ms);

----------------------------------------------------

The output is 2.9999999999998

For base 10 logarithm you also have log10 function.

Fixed, added automatic rounding on final result if result is very similar to the int

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/69

Hi Mariusz,

Thanks for developing the parser! I'm using it in this Android app I made: https://play.google.com/store/apps/details?id=com.kumailn.calculator

Regards,

Kumail

Thx for sharing 🙂

Hi Mariusz,

thank you for this great library. I now build an App Inventor extension to use your library in App Inventor projects. For more information about App Inventor see here http://appinventor.mit.edu. See the extension here: https://puravidaapps.com/math.php

Kind Regards,

Taifun,

puravidaapps.com

Hi,

Thank you for this feedback - I am very happy mXparser helped 🙂 Thank you for sharing the links!

Kind regards,

Mariusz

Hi Mariusz,

I'm developing in VB.Net and testing mXparser. I always get the following error when I try to evaluate a simple formula.

"System.IO.IOException" in mxparser.dll

The error occurs 4 times for every formula. I use the following code:

Imports org.mariuszgromada.math.mxparser

Public Function Evaluate(ByVal pstrFormula As String) As String

Dim oExpression As Expression

Dim dblExpression As Double

oExpression = New Expression(pstrFormula)

dblResult = oExpression.calculate()

pstrFormula can be any formula, like "1+2".

Seems straightforward, but at the last line I get the error 4 times.

Do you see anything I'm doing wrong here?

Thank you,

Anders

Sorry, of course the declaration is

Dim dblResult as Double

This works fine:

Hi Mariusz,

thank you for your answer!

As far as I can see your solution, starting with "Dim oExpression As Expression", is exactly what I'm doing. And yes: after "dblResult = oExpression.calculate()" the correct result is stored in "dblResult".

But nevertheless the error "System.IO.IOException in mxparser.dll" is thrown 4 times at that line. I see it in the debugging window when I step through the code. So I think, if I'm not doing anything wrong, there must be a reason why mXparser throws that error. Even if it returns the correct result.

Aside from this error: as far as I can see mXparser is a very fine peace of work. Thank you!

Anders

Thanks. What version of mXparser are you using?

This is not a bug, this is the way how JavaCC was designed, and then ported to C#. In auto-generated code of the parser the throwing / catching System.IO.IOException is very common.

The impact on the performance might be only in DEBUG mode, but still very limited, as you can use "Just My Code" option.

Hi Mariusz,

Can you please help me ? I need to create functions, for example:

highest(volume,3) : return the highests 3 values stored in a XML file.

If the user enter highest(volume,3) in the system, the program need to identify this function. Can you please tell me if this is possible with mXparser ?

Greetings from Brazil!

Hi Phelipe,

This is possible. You have to implement FunctionExtension interface to read the value from XML file. Then using implemented FunctionExtension you are just creating user defined function. Plese refer to the example #5 "Case 5: Implementing your own Function Extension" in "User defined functions" section of mXparser tutorial.

http://mathparser.org/mxparser-tutorial/user-defined-functions/

If this helps - please start the repo in GitHub 🙂

https://github.com/mariuszgromada/MathParser.org-mXparser

Best regards from Poland (currently on vacation in Spain - Canary Islands)

Hi Mariusz,

Can you please help me ? I need to get g(x) from f(x)=0.

For example

f(x) = x^2 − x − 2 = 0,

g(x) = x^2 − 2,

g(x) = 1 + 2/x,

g(x) = (x^2 + 2)/(2*x − 1)

g(x)=x

g(x) actually what is x

Hi,

I think I do not understand your question... Is the question about mXparser? It is not clear what your are trying to solve.

Best regards

Hi Mariusz

I'm also getting the IO Exception every time I calculate. (Same as Anders 1 August 2017)

The answer is correct but the throwing and catching of the exception causes the system to run quite slowly especially if I'm doing a large number of calculations.

I'm using version 4.1

Further investigation into the source code, I have found that the exception is coming from the SyntaxCheckerTokenManager.

Its trying to call BeginToken on the input_stream but it has been disposed and thus will throw an exception and in the catch statement handle the defaulting etc.

Though this is quite unnoticeable when calling calculate() once. It has a tremendous impact on performance if you are using the parser to calculate numerous times.

Issue was registered on GitHub

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/86

This part is auto-generated by CSJavaCC - C# port of JavaCC.

This is not a bug, this is the way how JavaCC was designed, and then ported to C#. In auto-generated code of the parser the throwing / catching System.IO.IOException is very common.

The impact on the performance might be only in DEBUG mode, but still very limited, as you can use "Just My Code" option.

Hi Mariusz, Could you please explain, why does this expression give an error?

Time to time I may have variables with leading zeros, and this is what I got:

[1000+0001000] checking ...

[1000+0001000] lexical error

Encountered " "0 "" at line 1, column 7.

Hi,

Which version of mXparser are use using? Leading zeros are supported since 4.1.

Best regards

Hi,

You are right. I've been using 4.0

4.1.1 works well 🙂

I had old version , coz I followed your links here http://mathparser.org/release-notes/mathparser-org-mxparser-on-maven-central/

Perhaps you could change it to mvnrepository.com ?

Hi Mariusz,

Is this parser is compatible with .net core 2. When the expression "if(sum(1,0,0,0,0) = 0,1,0) +if(sum(1,0,0,0,0) = 1,3,0) + if(sum(1,0,0,0,0) > 1,10,0)" it return NaN

Hi,

Please use checkSyntax() + getErrorMessage().

Best regards

Hi Mariusz,

I would like to thank you first for the wonderful tool!

One question: Can I change from rad to deg at the angle functions like sin (). I would like to write sin (45) and not sin (45 * [deg])

Hi,

This was already implemented, but not released yet - you can find the change on GitHub

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/87

Best regards

Hi Mariusz,

How can I use the derived functions to vb.net?

Dim e As Expression = New Expression("cos(1) - der(sin(x), x, 1)")

Console.WriteLine("Res: " + e.getExpressionString() + " = " + e.calculate())

Error: System.InvalidCastException: "Bringing the string" Res: cos (1) - der (sin (x), x, 1) "to the" Double "type is invalid."

In vb.net you need to add ToString() to cast double to string

Dim e As Expression = New Expression("cos(1) - der(sin(x), x, 1)")

Console.WriteLine("Res: " + e.getExpressionString() + " = " + e.calculate().ToString())

Thank You!

1 more question: How to make that e.calculate() return the value in type of Decimal (1e-28)?

mXparser always returns double. You need to cast / convert to decimal. If you want such a big precision pls also use mXparser.setEpsilon(0)

Hi,

How do I show the equation or expression of math in my android . do we have any separate view or how?.. Iam developing an application of maths which we will show the questions and options as objective Q&A test. So how do I use This to show in my applilcation. If now can we use with webView ..(Suggest Plz..) thanks...

Hi,

mXparser works on strings, so any component using string will be ok.

Best regards

Hello Mariusz, One wish I had is to write a App for Android Systems. Now I' ve done it. I wrote a little Calculator and use your excellent parser for the calculation part. I hope you'll enjoy it. At the moment I had the BetaTest in Google Play store for Germany and Poland. You will find the App under the following link.

https://play.google.com/apps/testing/noSpy.taschenrechner

Hello Mariusz,

I wrote a little Calculator App for Android with your excellent parser. Thank you very much. Your parser helps a lot.

At the moment the App is in BetaTest. If you would like to see, what I am doing there please click the following link

https://play.google.com/apps/testing/noSpy.taschenrechner

epsilon ist set to 10E-299, and it works with Double very good.

Best wishes

Peter

I wrote the email false , sorry. Now it is correct.

Hello Mariusz,

I'm a little confused. I wrote a Comment a few hours before and I thought I had made an error. I couldnt see it. So I wrote a new Comment now. But now there is my formerly comment. Whats going on??

But no matter ....

Best regards

Peter

I've built up an management indicators app (java + angular web app) with you package (to help managing the university where I work in Brazil). Amazing work!!!

Unfortunately the app is protected by login and password so I cannot share with you.

Thx for the feedback 🙂 You can still share the app name and description 🙂

If you like the package github star would be nice 🙂

Best regards

I've just starred it in Github.

Thx 🙂

Mariusz, is "prod" a reserved word in mxparser? I tried to create a formula using this string with a parameter and it mark it as invalid. Well, if so, where can I get a list of the reserved words in mxparser?

BTW, I think this isn't the right place to post doubts... is there a more appropriate channel for doing it?

The best place is the issue list on GitHUb

https://github.com/mariuszgromada/MathParser.org-mXparser

Yes, this is built-in keyword for product iterated operator. But you cna easily change it - there is an option for that.

mXparser.setToOverrideBuiltinTokens();

mXparser.setNotToOverrideBuiltinTokens();

mXparser.checkIfsetToOverrideBuiltinTokens();

mXparser.modifyBuiltinToken(String currentToken, String newToken)

mXparser.modifyBuiltinToken(String currentToken, String newToken, String newTokenDescription)

mXparser.unmodifyBuiltinTokens(String... currentOrNewTokens)

mXparser.unmodifyAllBuiltinTokens()

mXparser.getBuiltinTokensToModify()

mXparser.removeBuiltinTokens(String... tokens)

mXparser.unremoveBuiltinTokens(String... tokens)

mXparser.unremoveAllBuiltinTokens()

mXparser.getBuiltinTokensToRemove()

Best regards

Thanks, man! Once more: great job!

How can i use mXparser with android studio?

Just grab the jar file and copy it into the libs folder, then add dependencies.

Great Work Mariusz !

Is there way in this library to replace patterns such as (#1 * #2)/#3

when passed a Map ("1",25) ("2",2) ("3",10) should return 5

Thanks

Peter

Why not to use arguments?

Argument x1 = new Argument("x1");

Argument x2 = new Argument("x2");

Argument x3 = new Argument("x3");

Expression e = new Expression("(x1 * x2)/x3", x1, x2, x3);

x1.setArgumentValue(25);

x2.setArgumentValue(2);

x3.setArgumentValue(10);

mXparser.consolePrintln(e.calculate());

x1.setArgumentValue(20);

mXparser.consolePrintln(e.calculate());

Result:

[mXparser-v.4.2.0] 5.0

[mXparser-v.4.2.0] 4.0

The other option is via function, i.e.

Function f = new Function("f(x1, x2, x3) = (x1 * x2) / x3");

mXparser.consolePrintln(f.calculate(25, 2, 10));

mXparser.consolePrintln(f.calculate(20, 2, 10));

Result:

[mXparser-v.4.2.0] 5.0

[mXparser-v.4.2.0] 4.0

Bes regards

Great product Mariusz!

I am wrapping mXparser (Java version) with restful web service code to create "calculation services". These can be accessed by other applications or standalone, with a web browser or http requesting tool. I work for a scientific laboratory and by using this I can pull all the calculations out of the code of the various existing applications and put them all in one place for auditing and cataloging purposes.

So far it is working great and I really like it. I did encounter an issue when working with very small (and probably very large numbers), however. If I run this Java code, using ordinary Java double's (not even BigDecimal's):

double ad1 = 2500;

double ad2 = 1.0013826583317465947599675784203E-15;

double ad3 = 30;

double ad4 = 35;

double ad5 = 40;

double ad6 = 1;

System.out.println("ad2 = " + ad2);

double calc = ((ad1 * ad2) / (ad3 * ad4 * ad5 * ad6));

System.out.println("calc = " + calc);

As expected, I get this output:

ad2 = 1.0013826583317466E-15

calc = 5.960611061498491E-17

However, when I try to do the same thing in mXparser:

Function function = new Function("S(a1,a2,a3,a4,a5,a6) = (a1 * a2) / (a3 * a4 * a5 * a6)");

Expression expression = new Expression("S(a1,a2,a3,a4,a5,a6)", function);

Argument a1 = new Argument("a1 = " + ad1);

Argument a2 = new Argument("a2 = " + ad2);

Argument a3 = new Argument("a3 = " + ad3);

Argument a4 = new Argument("a4 = " + ad4);

Argument a5 = new Argument("a5 = " + ad5);

Argument a6 = new Argument("a6 = " + ad6);

expression.addArguments(a1, a2, a3, a4, a5, a6);

System.out.println("mxParser result = " + expression.calculate());

I get zero back:

mxParser result = 0.0

Am I using mxParser correctly or is this a limitation? It seems like it should be able to handle these numbers, especially since the top code works with Java doubles.

Thanks very much,

Mike

Hi. Thx for your feedback. It is related to default almost int rounding. v.4.2 will introduce new options for that, see the github issues:

https://github.com/mariuszgromada/MathParser.org-mXparser/issues/116

As of now - run this:

mXparser.disableUlpRounding()

mXparser.setEpsilon(0)

Pls let me know how it works.

Hi Mariusz,

Thanks very much for your reply. What you gave me didn't work but when I switched it to this:

mXparser.disableUlpRounding();

mXparser.setEpsilon(.0000000000000000000000000000000000000000000000001);

It works. Thanks very much!

Mike

Hi Mariusz,

I need some help regarding the usage of the mXparser.

I would like to use it with mingw compiler (gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.3.0) .

My question is where can I find the appropriate lib dll and header files for build the mXparser into my project?

Thanks in advance.

Best regards,

Attila

mXparser is written in Java and the ported to C#. This is not C/C++ project.

Best regards

Hello Mr Gromada, thank you for the useful product you are developing.

I wanted to ask how can i solve 3(x-5)=2x+6 with mxparser in android?

Expression d = new Expression("solve(3*(x-5)=2*x+6)");

double c = d.calculate();

Toast.makeText(getApplicationContext(),"Solution "+c, Toast.LENGTH_LONG).show();

The code above did not worked.

Hi. Thx for your feedback. Please follow the code examples given in the tutorial.

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

Best regards

If you want to solve f(x)=0 please use

solve( f(x), x, a, b)

where x is argument, [a,b] is the interval where the root is.

This is numerical solve, so you need to give a and b. In your case

solve( 3*(x-5) - (2*x+6) , x, -100, 100)

should work 🙂

Thanks.

Can i use

solve( 3*(x-5) - (2*x+6) , x, -infinite, infinite)

becasuse we don't know solution interval.

Unfortunately no - this is numerical solve, this is not algebra parser.

Hi. I wanted to ask a question. I have a list of arguments. Is there any option that we could populate a dictionary with all the possible arguments and the parser could then evaluate the algebraic expression based on the values in the dictionary. (My list of arguments are user defined. I cannot hard code.) Thanks.

Hi,

Please check the tutorial, section on user defined arguments.

http://mathparser.org/mxparser-tutorial/user-defined-arguments/

Best regards

What if the number of arguments are different after each instance.

i.e. For first time: x,y,z

For Second time: r,t,y

I does not matter. Pls share a piece of code - then I will help you.

Hi, could you upload a version 4.1.x which has checkSyntax() method in Function working. Non of currently uploaded version on maven central have this method working and I've seen that bug has been fixed on gitHub in one of recent commits. Thank you!

Yes, I have a plan for that. But this will be 4.2, not 4.1, as the change was made only in 4.2 src.

Hi,

Do you have any plants to support vector/arrays?

I means that an expression will get nXm (n arguments for m different calculation)

and return double[] of m answers?

Hi Mariusz,

I am writing program in C# using your library but I have problem with n-th derivative.

Code:

Argument x = new Argument("x", 2);

Expression e = new Expression("dern(x^3, 2, x)",x);

mXparser.consolePrintln("e: " + e.calculate());

Output:

[mXparser-v.4.1.1] e: -8.796093022208E+16

As you can see the result incorrect.

Could you kindly tell me where I am making a mistake?

Thanks.

I suppose there is a bug in dern operator, for second derivative you can use this one

Argument x = new Argument("x = 2");

Expression e = new Expression("der( der(x^3, x), x)", x);

Or this one - this is shorter

Expression e = new Expression("der( der(x^3, x, x), x, 2)");

hello

im a beginner developer

im developing a scientific calculator android app for practice

as i found making a regular one so easy

i made a code that parse some of regular expressions

but i want more and it takes me too much time for it

i dont know how to impliment this program

can somebody help

and thank you for making this program it looks to me its very helpful

though i need help in how to use it in android studio

as i said im beginner

How can i evaluate ((STC-1 != WTC-3 || STC-1!= STC-1) || 9<= 8).

Here STC-1 and WTC-3 is a string.

PLease help.

STC-1 is calculated as STC - 1

You should name your argument as STC1

I would like to evaluate (STC-1 != WTC-3 || STC-1!= STC-1) || 9<= 8), but the problem here is the string part STC-1 and WTC-3 are string. I am not getting desired output.

Please help.

STC-1 is calculated as STC - 1

You should name your argument as STC1

I'm writing a virtual reality tool for data visualization and modeling, and needed an equation parser for comparing functions to data. This was just what I was looking for, and was drag and drop implementation into my Unity project. I really appreciate the C# support!

Thank you for your feedback 🙂

Hey Mariusz,

its possible to evaluate "nested" expressions?

Like the following:

var weightArgument = new Argument("Weight", "Length * Height");

var result = new Expression("Amount*Price*Weight", constAmount, constPrice);

result.addArguments(weightArgument);

If I like to get ExpressionString I ike to get:

Amount * Price * (Length * Height)

Is this possible?

Thanks 🙂

Sure - see the code

var lengthArgument = new Argument("Length = 2");

var heightArgument = new Argument("Height = 3");

var weightArgument = new Argument("Weight = Length * Height", lengthArgument, heightArgument);

var constAmount = new Constant("Amount = 4");

var constPrice = new Constant("Price = 5");

var result = new Expression("Amount * Price * Weight", constAmount, constPrice, weightArgument);

Console.WriteLine(result.calculate());

lengthArgument.setArgumentValue(20);

heightArgument.setArgumentValue(30);

Console.WriteLine(result.calculate());

Best regards

Hi Mariusz, thanks for your answer 🙂

Yes I already know that I am able to calculate this.

But my wish is for info purposes to display the full formula.

I like to modulize it in code, but print all nested "variables".

Its about: getExpressionString()..

It shouldn't display Amount * Price * Weight.

It should display Amount * Price * (Length * Height) (Brackets are optional)

So. Automatically replace expression for Weight with given Argument.

You got? 😮 I saw in hidden properties, that there is a relation. I could build it by myself in my code, but I like to be ready for updates and I think it could help other people also.

no soy mucho de usar java.... pero estaba probando tu programa con ANDROID STUDIO, me parece genial tu mXparser, realiza un sin fin de cosas. pero me parece que debes de solucionar lo siguiente:

-b+5 (OK)

+b+5 (SE CUELGA EL PROGRAMA )

EL SIGNO "+" al principio de una variable provoca un cuelgue... pruebalo y me comentas

Gracias por la respuesta. Voy a probar y solucionar esto en un futuro muy cercano 🙂

Muy pequeño error, gracias. Ya corregido 🙂

Hi Mariusz,

I'm working on a virtual reality calculus educational app. I'm working with Unity and C#. I am trying to be able to graph implicit equations, i.e. "x^2+y^2+z^2-4=0". My question is, if that was the equation that is input, how could I create a new function with everything but the "=0". I need to be able to evaluate that function to see whether the value is +/-.

Thanks

Hi Randal,

Can you clarify a bit? "x^2+y^2+z^2-4=0" is the string provided by the end user? Does it always end with "=0"? There are many option to do that. Pls send more info and I will prepare a code snippet 🙂

Best regards,

Mariusz

Mariusz,

That is correct, the string will be input from the end user in that form. That is the most basic form of an implicit function. It will always end in "=0".

Thank you

Randal,

I assume you want to evaluate z = f(x,y), so that f(x,y) - z = 0. I understand it might be impossible to ask user for the f(x,y), as in many cases finding f(x,y) might be hard. You just want an equation for the surface.

One possible approach is to set x and y values then solve numerically f(x,y) - z = 0 for argument 'z'. Here we have few risks:

- there is not solution

- solution is not unique

But in general it will work.

mXparser provides 'solve' function - I can prepare a code showing how to do that.

In case when it is possible to ask the user for f(x,y) such that z = f(x,y) the whole issue is a lot easier.

Best regards,

Mariusz

I have been trying to post a question for a while but am not seeing it being displayed so i will try and ask here.

Please, how do i implement - cuberoot(27) - is there a function for this?

Its urgent please.

Thank you.

Please how do I implement 3√27 using this parser which is cube root function

I need some more information on how I can implement 3√27 which is the cube root of 27.

I check all the tutorials couldn't find it

Please can I know how to implement 3√27 which happens to be cuberoot(27)?

Hi,

Pls use root(rootorder, number)

Best regards

Please, how do you implement, cuberoot - I have been going about it for days now.. I have used cbrt(27), 3sqrt(27) or doesnt the parser support cuberoot??

Thanks

Hi,

Pls use root(rootorder, number)

Best regards

Hello Mariusz,

Thank you very much for the greate library. I am using it for claculating simple formulas, in a a way that the user defines some parameters and writes the formula, and my application calculates it using mXparser.

Now I noticed -as the library is very powerful-, the user cannot define a parameter named "e"! I was wondering if it is possible to limit the library to simple basic math.

Thank you very much,

Yvonnila

Hi,

Thanks for your feedback. Please use below option

mXparser.setToOverrideBuiltinTokens();

It will trigger the behavior you expect, meaning keywords provided by the user will have priority.

If you just want to remove some keywords for the parser please use

mXparser.removeBuiltinTokens(list of tokens);

Please verify documentation.

Best regards,

Mariusz

Thank you very much for your reply!

Hello Mariusz,

Thank you very much for you powerful math library.

We are using it very often for complex Problems.

Unfortunately i have a Problem with the Digits.

When I use the e1.calcuate() function the double value it

Returns "only" has 14 after comma Digits.

When i calculate the same Expression in matlab i get 16 after comma Digits.

Is that a C#.toString Problem or where do i lose the precision?

Thank you very much.

Philipp

Tank you. Pls change the optipns. mXparser.disableUlpRounding()

mXparser.disableAlmostIntRounding()

mXparser.setEpsilon(0)

mXparser.setExactComparison()

Jest regards

Hi Mariusz,

Thanks for sharing this powerful library with us.

I'm just wondering if you have a NuGet package that does not include the docs folder.

Thank you,

Calvin

Hi, thank you for your feedback. Nuget package was updated to no contain html documentation.

Best regards

Hi Mariusz,

Thank you very much for the library.

I'm using your library for calculation and also for checking if the string representation of the formula is correct. But for formulas "+2+3" and "2+3+" I got 'true' from checkSyntax() function.

Best Regards,

Elena

Can you share the code? Which version of mXparser are you using?

Hi, I installed the library using NugetPackage but when typing "using org. ... " it doesnt exist. Dont know whats the problem. Do i need to install something additionally ?

Using VS 2015 coding android app with xamarin

Did you use Install-Package MathParser.org-mXparser?

Hi,

First of all, You All did a great work in MXParser, Thanks for this,

I have a query, do we support underscore in number? As it is supported in java 7.

Like if we have expression like ".2/2.0+3-1*(5_000_000-3) + 7^2" then google calculates it properly. but with mxparser we are getting NAN as result.

Underscore in mXparser is used to recognize fractions, i.e. 1_3 = 1/3, 2_2_3 = 2+2/3

Best regards

Hello,

It is my first time using mXparser. I want to solve the equation: "x*tan(x) = y".

So i'll give a value to y argument and I want to get the multiples values of x.

Is this possible through mXparser?

Thank you in advance for your time.

Hi,

Please use "solve" functions, sample code below:

Argument y = new Argument("y = 5");

Expression e = new Expression("solve(x*tan(x) - y, x, -pi/2, pi/2)", y);

mXparser.consolePrintln(y.getArgumentName() + " = " + y.getArgumentValue());

mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());

mXparser.consolePrintHelp("solve");

Result:

[mXparser-v.4.3.0] y = 5.0

[mXparser-v.4.3.0] solve(x*tan(x) - y, x, -pi/2, pi/2) = 1.31383772

[mXparser-v.4.3.0] Help content:

# key word type syntax since description solve( expr, a, b ) 4.0 f(x) = 0 equation solving, function root finding

- -------- ---- ------ ----- -----------

223. solve

Best regards