Share how you use mXparser

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

*** If you found the software useful donation is something you might consider ๐Ÿ™‚ ***

If you found the software useful donation is something you might consider :-)

178 thoughts on “Share how you use mXparser

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

    Thanks a lot!

    Leroy

      1. 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

        1. 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

  2. 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!

      1. 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?

        1. Thank you for your message. Of course I will be happy to help ๐Ÿ™‚ I will contact you directly via email.

          Best regards

        2. 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

          1. 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.

    1. 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

    2. 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

  3. 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!

    1. 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

  4. 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.

    1. 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

        1. 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

          1. 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.

          2. 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

      1. 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!

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

          Best regards

  5. 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?

    1. Dear Michel,

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

      Kind regards

      1. 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.

  6. 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.

    1. 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

  7. 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 )

  8. 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...

    1. 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

  9. 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

    1. 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.

      1. 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

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

            - Melwin

  10. 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

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

  11. 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 ??

  12. 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?

    1. 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

      1. 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

  13. 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.

        1. 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.

  14. 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

  15. 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?

  16. 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

  17. 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?

    1. 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

  18. 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.

    1. 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

  19. 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

    1. 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

  20. 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

    1. Hi Petr,

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

      Best regards

  21. 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?

    1. 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

      1. 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

        1. "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

          1. 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

    1. Hi,

      Thank you for this feedback - I am very happy mXparser helped ๐Ÿ™‚ Thank you for sharing the links!

      Kind regards,
      Mariusz

  22. 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

      1. This works fine:

        Imports org.mariuszgromada.math.mxparser

        Module Module1

        Public Function Evaluate(ByVal pstrFormula As String) As Double

        Dim oExpression As Expression
        Dim dblResult As Double
        oExpression = New Expression(pstrFormula)
        dblResult = oExpression.calculate()
        Return dblResult

        End Function

        Sub Main()

        Console.WriteLine(Evaluate("1+2"))

        End Sub

        End Module

        1. 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

    1. 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.

  23. 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!

    1. 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)

  24. 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

    1. 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

  25. 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

    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.

    2. 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.

  26. 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.

  27. 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

  28. 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])

  29. 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."

    1. 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())

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

  30. 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...

  31. 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

  32. 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.

    1. 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

  33. 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?

    1. 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

  34. 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

    1. 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

  35. 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

      1. 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

  36. 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

  37. 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.

      1. 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 ๐Ÿ™‚

  38. 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.

      1. 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

  39. 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!

    1. 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.

  40. 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?

  41. 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.

    1. 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);

  42. 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

  43. 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.

  44. 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.

  45. 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!

  46. 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 ๐Ÿ™‚

    1. 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

      1. 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.

  47. 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

  48. 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

    1. 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

      1. 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

        1. 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

          1. 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.

  49. 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

  50. 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

  51. 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

    1. 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

  52. 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

    1. Tank you. Pls change the optipns. mXparser.disableUlpRounding()
      mXparser.disableAlmostIntRounding()
      mXparser.setEpsilon(0)
      mXparser.setExactComparison()
      Jest regards

Leave a Reply

Your email address will not be published. Required fields are marked *