This C++ library offers a class which can be used to parse and evaluate a mathematical function from a string (which might be eg. requested from the user). The syntax of the function string is similar to mathematical expressions written in C/C++ (the exact syntax is specified in the documentation below). The function can then be evaluated with different values of variables.
For example, a function like "sin(sqrt(x*x+y*y))" can be
parsed from a string (either std::string or a C-style string)
and then evaluated with different values of x and y.
This library can be useful for evaluating user-inputted functions, or in
some cases interpreting mathematical expressions in a scripting language.
This library aims for maximum speed in both parsing and evaluation, while keeping maximum portability. The library should compile and work with any standard-conforming C++ compiler.
Different numerical types are supported: double,
float, long double, long int,
multiple-precision floating point numbers using the MPFR library, and
arbitrary precision integers using the GMP library. (Note that it's
not necessary for these two libraries to exist in the system in order
to use the Function Parser library with the other numerical types. Support
for these libraries is optionally compiled in using preprocessor settings.)
This Library is distributed under the Lesser General Public License (LGPL) version 3.
Download fparser4.0.3.zip v4.0.3 (released 19 Dec 2009)
(Older versions: v3.3.2, v3.2.1, v3.1.5, v3.0.3, v2.84, v2.8, v2.71, v2.63, v2.51, v2.4, v2.3, v2.22)
The basic library package above contains the bare minimum files intended for the usage of the library in C++ applications. If you want to simply use the library in your program, then download the package above.
The development version of the library is intended for those who want to modify and enhance the library. Besides the files contained in the basic package above, the development version contains the full optimizer sources, optimizer rule generation tools, an extensive automatic regression testbed, a Makefile and other tools.
Download the development package: fparser4.0.3_devel.tar.bz2
What's new in v4.0.3
Parse() and
Optimize().
"cosh(x^2)"
and "-x<3" were wrongly optimized.
What's new in v4.0.2
"x*4/2" to be parsed
incorrectly.
"cosh(asinh(x))" which
potentially caused a stack corruption.
What's new in v4.0.1
What's new in v4.0
double,
float, long double, long int,
multiple-precision floating point numbers using the MPFR library, and
arbitrary precision integers using the GMP library. (Note that it's
not necessary for these two libraries to exist in the system in order
to use the Function Parser library with the other numerical types.
Support for these libraries is optionally compiled in using preprocessor
settings.)
Parse() method, making it 15-30%
faster with most inputs.
Parse() method now performs significantly more
bytecode optimizations than before, without compromising parsing speed.
Optimize()
method.
You can also view the full version history.
Function Viewer: A small program I made to demonstrate the function parser.