A fast math expression parser capable of parallel expression evaluation.

**muparsersse**- Compiling Mathematical Expressions with muparser and asmjit

# The muParserSSE math parser

muparserSSE is a mathematical expression parser that will compile a mathematical expression into machine code for Intel processors
at runtime. It will take the expression as well as variable definitions as its input and return the pointer to a just in time
compiled function made up of fast SSE instructions.
You can extend it with custom callback functions and operators. muparserSSE is based on asmjit
a just in time compiler written by *Petr Kobalicek* and the original muparser.

Since this is a fork of muparser its interface and features are pretty similar. However i had to remove some of muparsers more "esotheric" features in order to get the work done. A complete implementation would have taken to much time and muparser has some features that are rarely used anyway. On the other side i added some operators in order to expose as much of the SSE instructions to the user as possible. The following table compares muparserSSE with the other parsers of the muparser family. A detailed description of the differences is listed below.

Parser | Data types | Precision | User defined operators | User defined functions | Localization | Licence | Performance (Expr. per second) | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|

complex | scalar | string | vector | Binary | Postfix | Infix | Strings as parameters | Arbitrary number of parameters | |||||

muparser | (1) | double | BSD 2-Clause | ~10.000.000 | |||||||||

muparserSSE | float | max. 10 | BSD 2-Clause | ~20.000.000 | |||||||||

muparserX | double | BSD 2-Clause | ~1.600.000 |

Table 1: Feature comparison with other derivatives of muparser. (***** Average performance calculated using this set of expressions; (1) muparser can define strings but only as constants.)

The current release contains a DLL and Project files for 32 bit Windows only. Since both asmjit and muparser are running on Linux too compiling the library under Linux should be possible but hasn't been tested. The following features are supported by muparserSSE:

- Extensible with custom operators (binary, infix or postfix)
- Extensible with custom functions with up to 5 Parameters
- Support for an unlimited number of variables and constants
- No limit on expression complexity
- Reads binary, hexadecimal values from expressions and can be extended to read user defined values as well.
- Supports a large variety of predefined operators, functions and constants.
- Written in C++ code with no external dependencies.
- Evaluation is using fast SSE instructions for improved performance

- Data type is
*float*rather than*double*as used by the original muparser - No assignment operators
- Neither string constants nor string parameters are supported
- No callbacks for functions with unlimited number of parameters

## Features

### Predefined Constants

By default the parser supports the following mathematical constants:- The eulerian number with:

*e = 2.718281828459045235360287* - The mathematical constant equal to a circle's circumference divided by its diameter.

*pi = 3.141592653589793238462643*

### Predefined Functions

By default muparserSSE supports the following functions:- Triginometric functions:

*sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh* - Exponential and logarithmic functions:

*log2, log10, ln, exp* - Other functions:

*abs, rint, sign, ite*

### Binary operators:

- Standard operators:

*"+", "-", "*", "/", "^"* - Boolean operators:

*"==", "!=", ">", "<", "<=", ">="* - Min/max operators:

*"<?", ">?"*

### Unary operators:

The following list contains the unary operators defined by muparserSSE. Unary operators can either be postfix operators or infix operators. Postfix operators can be used to easily distinguish value quantities, whilst infix operators are used to implement the sign operator:- Postfix operators:

*"{n}", "{mu}", "{m}", "{k}", "{G}", "{M}"* - Infix operators:

*"-"*

## Credits

Special thanks to *Petr Kobalicek* for writing the asmjit just in time compiler
and making it available as open source. Writing muparserSSE wouldn't have been possible without asmjit!