Implied multiplication

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.

Case 1: Numbers and parenthesis

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2(3+4)3");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.getCanonicalExpressionString());
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate())
[mXparser-v.5.0.0] 2(3+4)3 = 2*(3+4)*3
[mXparser-v.5.0.0] Res: 2(3+4)3 = 42.0

Case 2: Numbers and constants / arguments

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi+3e");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.getCanonicalExpressionString());
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] 2pi+3e = 2*pi+3*e
[mXparser-v.5.0.0] Res: 2pi+3e = 14.438030792556722

Case 3: Numbers and constants / arguments and parenthesis

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi(3+4)2e");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.getCanonicalExpressionString());
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] 2pi(3+4)2e = 2*pi*(3+4)*2*e
[mXparser-v.5.0.0] Res: 2pi(3+4)2e = 239.11255823485985

Case 4: Numbers and constants / arguments and parenthesis and functions

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi(3+4)2sin(3)e");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.getCanonicalExpressionString());
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] 2pi(3+4)2sin(3)e = 2*pi*(3+4)*2*sin(3)*e
[mXparser-v.5.0.0] Res: 2pi(3+4)2sin(3)e = 33.74356614531889

Case 5: Implied multiplication and possible ambiguity

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi2");
e.checkSyntax();
mXparser.consolePrintln(e.getExpressionString() + " = " + e.getCanonicalExpressionString());
mXparser.consolePrintln(e.getErrorMessage());
[mXparser-v.5.0.0] 2pi2 = 2*pi2
[mXparser-v.5.0.0] [2pi2] checking ...
[2pi2] (pi2, 2) invalid <TOKEN>.
[2pi2] errors were found.
[mXparser-v.5.0.0] 

Case 6: Implied multiplication and list of tokens

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi(3+4)2e");
e.consolePrintCopyOfInitialTokens();
[mXparser-v.5.0.0]  --------------------
[mXparser-v.5.0.0] | Expression tokens: |
[mXparser-v.5.0.0]  ---------------------------------------------------------------------------------------------------------------
[mXparser-v.5.0.0] |    TokenIdx |       Token |        KeyW |     TokenId | TokenTypeId |  TokenLevel |  TokenValue |   LooksLike |
[mXparser-v.5.0.0]  ---------------------------------------------------------------------------------------------------------------
[mXparser-v.5.0.0] |           0 |           2 |             |           1 |           0 |           0 |         2.0 |             |
[mXparser-v.5.0.0] |           1 |           * |             |           3 |           1 |           0 |         NaN |             |
[mXparser-v.5.0.0] |           2 |          pi |             |           1 |           9 |           0 |         NaN |             |
[mXparser-v.5.0.0] |           3 |           * |             |           3 |           1 |           0 |         NaN |             |
[mXparser-v.5.0.0] |           4 |           ( |           ( |           1 |          20 |           1 |         NaN |             |
[mXparser-v.5.0.0] |           5 |           3 |       _num_ |           1 |           0 |           1 |         3.0 |             |
[mXparser-v.5.0.0] |           6 |           + |           + |           1 |           1 |           1 |         NaN |             |
[mXparser-v.5.0.0] |           7 |           4 |       _num_ |           1 |           0 |           1 |         4.0 |             |
[mXparser-v.5.0.0] |           8 |           ) |           ) |           2 |          20 |           1 |         NaN |             |
[mXparser-v.5.0.0] |           9 |           * |             |           3 |           1 |           0 |         NaN |             |
[mXparser-v.5.0.0] |          10 |           2 |             |           1 |           0 |           0 |         2.0 |             |
[mXparser-v.5.0.0] |          11 |           * |             |           3 |           1 |           0 |         NaN |             |
[mXparser-v.5.0.0] |          12 |           e |             |           2 |           9 |           0 |         NaN |             |
[mXparser-v.5.0.0]  ---------------------------------------------------------------------------------------------------------------

Case 7: Enable / disable implied multiplication

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2pi+3e");
e.disableImpliedMultiplicationMode();
e.checkSyntax();
mXparser.consolePrintln("Disable: \n" + e.getErrorMessage());
e.enableImpliedMultiplicationMode();
e.checkSyntax();
mXparser.consolePrintln("Enable: \n" + e.getErrorMessage());
[mXparser-v.5.0.0] Disable: 
[2pi+3e] checking ...
[2pi+3e] (2pi, 0) invalid <TOKEN>.
[2pi+3e] (3e, 2) invalid <TOKEN>.
[2pi+3e] errors were found.
[mXparser-v.5.0.0] Enable: 
[2pi+3e] checking ...
[2pi+3e] no errors.
[mXparser-v.5.0.0] 
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.0

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency

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

Maven – Gradle

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

Maven – Gradle (Kotlin)

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

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.2.0 Orion: .NET bin onlyDownload latest release – v.5.2.0 Orion: JAVA bin onlyDownload latest release – v.5.2.0 Orion: 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