Inspecting calculation process

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

Case 1: Setting the verbose mode

import org.mariuszgromada.math.mxparser.*;
...
Function f = new Function("f(x) = x^2");
Expression e = new Expression("f(2)+(2+3)^2", f);
e.setDescription("Example - verbose mode");
e.setVerboseMode();

mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] 
[Example - verbose mode][f(2)+(2+3)^2] 
[Example - verbose mode][f(2)+(2+3)^2] Starting ...
[Example - verbose mode][f(2)+(2+3)^2] Starting calculation loop
[Example - verbose mode][f(2)+(2+3)^2] Parsing (1, 3)  ---> ( 2.0 )  ...  ---> f 2.0 + ( 2.0 + 3.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 1)  ---> f 2.0  ... 
[f(x) ][ x^2] 
[f(x) ][ x^2] Starting ...
[f(x) ][ x^2] x = 2.0
[f(x) ][ x^2] Starting calculation loop
[f(x) ][ x^2] Parsing (0, 2)  ---> 2.0 ^ 2.0  ...  ---> 4.0  ...  done
[f(x) ][ x^2] Calculated value: 4.0
[f(x) ][ x^2] Exiting

 ---> 4.0 + ( 2.0 + 3.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (2, 6)  ---> ( 2.0 + 3.0 )  ...  ---> 4.0 + ( 5.0 ) ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (2, 4)  ---> ( 5.0 )  ...  ---> 4.0 + 5.0 ^ 2.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 4)  ---> 4.0 + 5.0 ^ 2.0  ...  ---> 4.0 + 25.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Parsing (0, 2)  ---> 4.0 + 25.0  ...  ---> 29.0  ...  done
[Example - verbose mode][f(2)+(2+3)^2] Calculated value: 29.0
[Example - verbose mode][f(2)+(2+3)^2] Exiting

Res: f(2)+(2+3)^2 = 29.0
[mXparser-v.5.0.0] 

Case 2: Syntax checking

import org.mariuszgromada.math.mxparser.*;
...
/* Function and expression definition */
Function fib = new Function("fib(n) = if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )");
Expression e = new Expression("fib(10) + 20/sin(x)", fib);

/* 1st trial of syntax checking. */
mXparser.consolePrintln("1st trial of syntax checking.");
e.checkSyntax();
mXparser.consolePrintln(e.getErrorMessage());

/* Definition modification */
Argument x = new Argument("x = 2");
e.addDefinitions(x);

/* 2nd trial of syntax checking. */
mXparser.consolePrintln("2nd trial of syntax checking.");
e.checkSyntax();
mXparser.consolePrintln(e.getErrorMessage());
[mXparser-v.5.0.0] 1st trial of syntax checking.
[mXparser-v.5.0.0] [fib(10) + 20/sin(x)] checking ...
[fib(10) + 20/sin(x)] (fib, 0) checking user defined function ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] checking ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] no errors.
[fib(10) + 20/sin(x)] (x, 9) invalid <TOKEN>.
[fib(10) + 20/sin(x)] errors were found.
[mXparser-v.5.0.0] 2nd trial of syntax checking.
[mXparser-v.5.0.0] [fib(10) + 20/sin(x)] checking ...
[fib(10) + 20/sin(x)] (fib, 0) checking user defined function ...
[fib(10) + 20/sin(x)] -> [fib] = [ if( n>1, fib(n-1)+fib(n-2), if(n > 0, 1, 0) )] already checked - no errors!
[fib(10) + 20/sin(x)] no errors.
[mXparser-v.5.0.0] 

Case 3: Just lexical syntax checking

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("fun(1,2)+3");
mXparser.consolePrintln("checkSyntax  = " + e.checkSyntax());
mXparser.consolePrintln(e.getErrorMessage());   
mXparser.consolePrintln("checkLexSyntax = " + e.checkLexSyntax());
[mXparser-v.5.0.0] checkSyntax  = false
[mXparser-v.5.0.0] [fun(1,2)+3] checking ...
[fun(1,2)+3] (fun, 0) invalid <TOKEN>.
[fun(1,2)+3] errors were found.
[mXparser-v.5.0.0] checkLexSyntax = true

Case 4: Getting computing time

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("sum(i, 1, 1000000, 1)");
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Computing time = " + e.getComputingTime() + " s.");
[mXparser-v.5.0.0] Res : sum(i, 1, 1000000, 1) = 1000000.0
[mXparser-v.5.0.0] Computing time = 0.531 s.
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.0.6

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.0.6

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.0.6"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.0.6</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.0.6'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.0.6")

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.6 Leonis: .NET bin onlyDownload latest release – v.5.0.6 Leonis: JAVA bin onlyDownload latest release – v.5.0.6 Leonis: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE