mXparser – Tutorial

MathParser.org-mXparser has been downloaded more than 3.000.000 times!

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

1. Using internal help

  • Full help content
  • Simple in-line help searching
  • Advanced help searching

2. Simple expressions

  • Simple calculation
  • Changing expression string
  • Using operators
  • Power function
  • Using numbers in scientific notation
  • Percent sign
  • Leading zeros

3. Implied multiplication

  • Numbers and parenthesis
  • Numbers and constants / arguments
  • Numbers and constants / arguments and parenthesis
  • Numbers and constants / arguments and parenthesis and functions
  • Implied multiplication and possible ambiguity
  • Implied multiplication and list of tokens
  • Enable / disable implied multiplication

4. Evaluating relations

  • Binary relation "="
  • Binary relation "<"
  • Boolean operator "OR"
  • Boolean operator "AND"

5. Using built-in functions

  • Unary function
  • Binary function
  • Function with 3 arguments
  • Function with n-arguments
  • Function with even number of arguments

6. User defined arguments

  • Dealing with free arguments
  • Defining dependent arguments
  • Implementing your own Argument Extension
  • Getting list of missing user defined arguments
  • Possible conflict between Implied Multiplication and getting list of missing user defined arguments + recommended solutions

7. User defined functions

  • Fast function definition (performance of creation)
  • Handy function constructor, but slower proces of function creation (performance of creation slower, but calculation the same)
  • Function with more parameters
  • Function in function
  • Implementing your own Function Extension
  • Getting list of missing user defined functions
  • Possible conflict between Implied Multiplication and getting list of missing user defined functions + recommended solutions

8. Expression pre-compilation

  • What is pre-compilation?
  • When is pre-compilation done?
  • When is pre-compilation done again?
  • An example of bad practice in computing the value of an expression for a changing argument value
  • An example of good practice in computing the value of an expression for a changing argument value

9. Summation & Product iterated operators

  • SIGMA summation operator
  • PI product operator
  • SIGMA summation operator - Approximating sin(x) by Taylor series
  • SIGMA summation operator - Approximating pi value by integrating sqrt(1-x^2)

10. Derivatives & Integrals

  • General derivative
  • Left / right derivative
  • Derivative from more complex function
  • Derivative - alternative syntax
  • Integrals - calculating pi by integration sqrt(1-x^2)

11. Solving equation f(x) = 0

  • Solve 2x-4 = 0 for x in [0, 10]
  • Solve cos(x) = 0 for x in [0, pi]
  • Solve cos(x) = 0 for x in [pi, pi] (root not bracketed)
  • Solve x-y = 0 for x in [0, 10] and y = 4
  • Solve sin'(x) = 0 for x in [0, pi]

12. “if” and “iff” functions

  • Mechanics of the if function
  • "if" function and arguments
  • "if" function in user defined function
  • Mechanics of the "iff" function
  • iff function is not limited in number of cases

13. Built-in constants

  • Using built-in constants
  • Estimating Moon gravitational acceleration
  • Getting list of constants

14. Built-in Units

  • Units of length / distance
  • Units of time
  • Units of information
  • Units of volume
  • Express 4 feet in inches
  • Express in square kilometers the area of a rectangle measuring 100 meters by 2 kilometers
  • List of supported units

15. Built-in Metric prefixes

  • Example: 10 Millions / Kilo
  • List of supported metric prefixes

16. Bitwise Operators

  • Bitwise unary complement
  • Bitwise AND
  • Bitwise exclusive OR
  • Bitwise inclusive OR
  • Signed left / right shift

17. Variadic user defined functions

  • Function returning number of parameters provided
  • Function returning sum of first and last parameter provided
  • Function returning parameter at position defined by the first parameter
  • Function returning sum of all parameters squared
  • Implementing your own Variadic Function Extension

18. User defined constants

  • Defining constant - various options

19. Fast (limited) user defined recursion

  • Fibonacci numbers using fast recursion

20. User defined recursion – not limited

  • Fibonacci numbers using user defined recursive function
  • Number of recursive parameters is not limited - binomial coefficient definition using user defined recursive function
  • Mixing function parameters - part causing recursive calls, other part as 'typical' parameter. Below example is presenting definition of Chebyshev polynomial using recursive function.
  • Indirect recursion - approximating sin(x) and cos(x)

21. Prime Numbers

  • Primality test function
  • Primes counting function
  • Using built-in primes cache to accelerate calculations
  • Estimating number of primes using Offset logarithmic integral function
  • Prime factorization

22. Random numbers

  • Random number from uniform continuous distribution
  • Random number from uniform discrete distribution
  • Random number from normal distribution
  • Random number from a given list
  • Estimating mean of Normal distribution
  • Estimating standard deviation of Normal distribution
  • Estimating variance of Normal distribution

23. PDF, CDF and Quantile functions

  • Expected value estimation using Probability Distribution Function
  • Probability estimation using Cumulative Distribution Function - the law of 3*SIGMA
  • Calculating quantiles using Inverse Cumulative Distribution Function - males height example assuming males height distribution N(170, 15)

24. Built-in Random Variables

  • Random integer
  • Random integer N: -10^k <= N <= 10^k for k = 1, 2, ...,9
  • Random natural number
  • Random natural number N <= 10^k for k = 1, 2, ...,9
  • Uniform continuous distribution U(0,1)
  • Normal distribution N(0,1)

25. User defined Random Variables

  • Dependent argument as user defined random variable
  • User defined function as user defined random variable - random walk example

26. Unicode math

  • The square root √
  • The square root of the square root √√
  • The square root and parenthesis √()
  • The roots of various orders ∜ ∛ √
  • SIGMA summation operator ∑
  • Unicode name of a user defined argument
  • Show all Unicode built-in keywords
  • Enable / disable Unicode built-in keywords
  • List of Unicode symbols that grammar accepts

27. Fractions

  • Fraction (proper) as Number Literal
  • Improper Fraction as Number Literal
  • Fraction (Mixed Number) as Number Literal
  • Fraction (Mixed Numer) and Improper Fraction in one Number Literal
  • Operations on Fractions
  • Represent double as Fraction

28. Various numeral systems

  • Binary number
  • Octal number 
  • Hexadecimal number
  • Unary number
  • Unary zero
  • Base 1 - 36 number literals
  • Base N numeral system

29. Working with NaN (Not-a-Number)

  • NaN in condition
  • NaN symbol
  • First non-NaN value

30. Radians Mode / Degrees Mode

  • Basic trigonometric function
  • Inverse trigonometric function
  • Using units of angle being in radians mode

31. Calculation Steps Register

  • Simple Expression
  • Dependent User Argument
  • User Function
  • Expression referencing User Argument and User Function

32. Inspecting calculation process

  • Setting the verbose mode
  • Syntax checking
  • Lexical syntax checking
  • Getting computing time
  • An Attempt To Fix Expression String

33. Playing with expression tokens

  • Printing expression tokens
  • Using tokens to print expression in a fancy way
  • Playing with invalid tokens

34. Built-in tokens (key words) manipulation

  • Removing built-in tokens
  • Modifying built-in tokens
  • Overriding built-in tokens

35. Smart rounding settings

  • A few words on Floating Point Math
  • Why mXparser is based on the double data type?
  • Smart rounding options available in mXparser
  • Check which rounding settings are currently active
  • Example – Only Canonical Rounding option is active
  • Example – Only Unit In The Last Place Rounding option is active
  • Example – Only Almost Integer Rounding option is active
  • Example – None of the rounding options are active

36. Efficient calculations in loops

  • User expression in the loop + output
  • User function in the loop + output
  • User argument (dependent) in the loop + output
  • User expression in the loop – Performance
  • Speed up calculations by turning off the smart rounding options
  • User function in the loop – Performance
  • User argument (dependent) in the loop – Performance

37. Extensive list of settings

  • Degrees / Radians Mode
  • Attempt To Fix Expression String Mode
  • Primes Cache
  • Epsilon Comparison / Exact Comparison Mode
  • Canonical Rounding Mode
  • ULP (Unit In The Last Place) Rounding Mode
  • Almost Integers Rounding Mode
  • Implied Multiplication Mode
  • Unicode Builtin Key Words Mode
  • Verbose / Silent Mode
  • Override Builtin Tokens Mode
  • Modify Builtin Tokens Mode
  • Remove Builtin Tokens Mode
  • Current Calculation Cancellation
  • Setting Console Prefix
  • Reaching Console Output String
  • Maximum Allowed Recursion Depth
  • Double to Fraction Conversion
  • Random Generator Selection
  • Maximum Threads Number
  • Default Settings

38. Serialization & Deserialization

  • SerializationUtils class
  • Binary serialization SECURITY WARNING
  • Enabling / Disabling binary serialization
  • Expression serialization / deserialization from / to byte[]
  • Expression serialization / deserialization from / to String
  • Expression serialization / deserialization from / to File
  • Serialization / Deserialization of complex objects

39. Cloning for thread safe operations

  • Why special cloning might be handy?
  • List of available options
  • Just cloning for a thread safe
  • Cloning for a thread safe + retrieving a clone of related object
  • Cloning for a thread safe + retrieving many clones of related objects
  • Cloning a sophisticated user objects with recursive dependencies

40. Exporting help in the TXT format

  • List of available options
  • Output with header and standard caption + advanced search
  • Output with header and user caption + advanced search
  • Output with no header and no caption + advanced search

41. Exporting help in the CSV format

  • List of available options
  • Output with header and ” as text quotation and ; as delimiter + advanced search
  • Output with header and ‘ as text quotation and , as delimiter + advanced search
  • Output with header and no text quotation and ; as delimiter + advanced search
  • Output with no header and ” as text quotation and ; as delimiter + advanced search

42. Exporting help in the HTML table format

  • List of available options
  • Output with header + figure tag + standard caption + CSS class + advanced search
  • Output with header + standard caption + CSS class + advanced search
  • Output with header + user caption + CSS class + advanced search
  • Output with no header and no caption and no CSS class + advanced search

44. Exporting help in the Markdown table format

  • List of available options
  • Output with header + standard caption + advanced search
  • Output with header + user caption + advanced search
  • Output with header and no caption + advanced search
  • Output with no header and no caption + advanced search

44. Exporting help in the JSON format

  • List of available options
  • Output with standard caption + advanced search
  • Output with user caption + advanced search
  • Output with no caption + advanced search

46. Accessing help programmatically

  • List of available options
  • Getting list of all keywords
  • Getting list of keywords under advanced search condition
  • Printing list of keywords

45. Configuration of your own translation

  • String Model generated based on String Resources
  • List of available options
  • Definition of text resources based on partial translation
  • Definition of text resources based on full translation

47. Validating String Model

  • To see generated descriptions by String Model
  • To see String Resources used

48. Printing the license

  • Printing the license

49. Confirming Non-Commercial / Commercial Use

  • Confirming Non-Commercial Use
  • Confirming Commercial Use

Live Java example

Live C# example

Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.1

Nuget – .NET CLI

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

Nuget – Package Reference

<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

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