TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!
The tutorial consists of more than 200 live examples from 50 sections. Each of the examples can be copied and run on your own environment. In addition, mXparser provides an extensive collection of over 500 built-in math functions, expressions and symbols. Familiarize yourself with the scope and the syntax. Live testing is the best way to learn. Good luck! 🙂
Tutorial Math Collection API spec Download
Below is the code for JAVA, the code for C# is almost identical. To copy the code, double-click inside the frame.
Case 1: Primality test / Prime test function
$$\text{IsPrime}(n)$$
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
/* Primality test function used in expression. */
Expression e1 = new Expression("ispr(5)");
Expression e2 = new Expression("ispr(9)");
/* Calculation and result output */
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
[mXparser-v.5.2.1] Res 1: ispr(5) = 1.0
[mXparser-v.5.2.1] Res 2: ispr(9) = 0.0
Case 2: Primes counting function
$$\pi(n)$$
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
/* Prime counting function used in expression. */
Expression e = new Expression("Pi(10000000)");
/* Calculation and result output */
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Time: " + e.getComputingTime() + " s.");
[mXparser-v.5.2.1] Res : Pi(10000000) = 664579.0
[mXparser-v.5.2.1] Time: 10.748 s.
Case 3: Using built-in primes cache to accelerate calculations
$$\pi(n)$$
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
/* Primes cache initialization */
mXparser.initPrimesCache(10000000);
mXparser.consolePrintln("Primes cache init time: " + mXparser.primesCache.getComputingTime());
/* Prime counting function used in expression. */
Expression e = new Expression("Pi(10000000)");
/* Calculation and result output */
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Time: " + e.getComputingTime() + " s.");
[mXparser-v.5.2.1] Primes cache init time: 0.115
[mXparser-v.5.2.1] Res : Pi(10000000) = 664579.0
[mXparser-v.5.2.1] Time: 0.217 s.
Case 4: (Using case 3) Estimating number of primes using Offset logarithmic integral function
$$\frac{\pi(n)}{\text{Li}(x)}$$
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
/* Primes cache was initialized in the previous example
* and it will be used in the following calculations.
*
* mXparser.initPrimesCache(10000000);
*
* We are going to estimate the number of primes Pi(n)
* using offset logarithmic integral function Li(n)
*/
Expression e = new Expression("Pi(10000000) / Li(10000000)");
/* Calculation and result output */
mXparser.consolePrintln("Res : " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.2.1] Res : Pi(10000000) / Li(10000000) = 0.9994911249048335
Case 5: Prime factorization
// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Argument x = new Argument("x = 12345");
Expression e = new Expression("sgn(x) * prod(i, 1, nfact(x), factval(x, i)^factexp(x, i) )", x);
mXparser.consolePrintln("Res 1: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.2.1] Res 1: sgn(x) * prod(i, 1, nfact(x), factval(x, i)^factexp(x, i) ) = 12345.0
Nuget – Package Manager
Install-Package
MathParser.org-mXparser
-Version
5.2.1
dotnet add package
MathParser.org-mXparser
--version
5.2.1
<PackageReference Include=
"MathParser.org-mXparser"
Version=
"5.2.1"
/>
Maven – Dependency
<dependency>
<groupid>org.mariuszgromada.math
</groupid>
<artifactid>MathParser.org-mXparser
</artifactid>
<version>5.2.1
</version>
</dependency>
Maven – Gradle
implementation
'org.mariuszgromada.math:MathParser.org-mXparser:5.2.1'
Maven – Gradle (Kotlin)
implementation(
"org.mariuszgromada.math:MathParser.org-mXparser:5.2.1"
)
GitHub
git clone
https://github.com/mariuszgromada/MathParser.org-mXparser
OTHER DOWNLOAD OPTIONS
Download latest release – v.5.2.1 Orion: .NET bin onlyDownload latest release – v.5.2.1 Orion: JAVA bin onlyDownload latest release – v.5.2.1 Orion: bin + doc
NEWS FROM MATHPARSER.ORG
SOURCE CODE
Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl