A mathematical formula evaluation library https://aformula.charlespence.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Charles Pence 5696d7c94d
Just copy the README, so Codeberg can see it.
5 months ago
build Update Autoconf version and tools. 7 years ago
doc/html Entirely untested and quick modifications to build under LLVM 7. 2 years ago
include Update version number from 0.9.4 to 0.9.5. 9 years ago
lib Fixes for out-of-tree builds, capitalization. 8 years ago
src Early quick build changes for new compilers with the libjit backend. 2 years ago
tests Remove an unused variable warning in the tests. 7 years ago
.gitignore Early quick build changes for new compilers with the libjit backend. 2 years ago
AUTHORS First commit of the AFormula library, as split off from Arcus development. 10 years ago
COPYING First commit of the AFormula library, as split off from Arcus development. 10 years ago
ChangeLog Pushing 0.9.2 with that libtool fix. 10 years ago
INSTALL Update Autoconf version and tools. 7 years ago
Makefile.am Fix (downgrade, actually) many of the aclocal/automake tools, due to an OS/development toolchain upgrade. 9 years ago
NEWS Update NEWS and configure for 0.9.6. 8 years ago
README Link docs in the README. 5 months ago
README.md Just copy the README, so Codeberg can see it. 5 months ago
THANKS Updated version to 0.9, re-generated docs with a new version of Doxygen. 10 years ago
aformula-1.1.pc.in Add a unit test for the C API, forgot a destroy-formula method. 9 years ago
config.h.in Update LLVM API, don't hard-code the list of optimizations. 7 years ago
configure.ac Update LLVM API, don't hard-code the list of optimizations. 7 years ago
doxygen.cfg Update to docs; adding a pkgconfig file, changing where we install things. 10 years ago

README.md

AFormula

AFormula is a library for dynamically calculating the value of mathematical formulas, passed in as strings. It is designed to mirror roughly the API of the muParser library http://muparser.sourceforge.net/ as well as offer me a place to experiment with more advanced formula evaluation techniques such as JIT-compiling formulas.

Support is included for all the standard arithmetic and comparative operators, including <=, >=, !=, ==, <, >, +, -, *, /, and ^ (power). Arbitrary variables may be defined (as pointers to double-values), and the assignment operator (=) may be used to assign values to them. A full suite of builtin functions is supported, including:

  • Trigonometry (sin, cos, tan, asin, acos, atan, atan2)
  • Hyperbolic trigonometry (sinh, cosh, tanh, asinh, acosh, atanh)
  • Exponentials (log2, log10 [= log], ln, exp, sqrt)
  • Miscellaneous (sign, rint, abs)
  • Logical control (if(x,if-true,if-false))

Finally, the constants ‘pi’ and ‘e’ are supported.

The priority of operations is:

=                       (assignment, lowest)
<=, >=, !=, ==, <, >    (comparisons)
+, -                    (addition/subtraction)
*, /                    (multiplication/division)
^                       (exponentiation)

AFormula is designed to be quite robust to invalid formulas, and is careful to return appropriate errors when necessary.

There are two JIT backends which AFormula can use in order to compile functions on the fly: LLVM and libjit. In general, both should provide roughly the same performance, though there is a performance test included which will benchmark the library and permit selection at runtime.

Documentation

Doxygen documentation for this library is available at https://aformula.charlespence.net.

Requirements

The Boost C++ Libraries http://www.boost.org are required to build AFormula.

If you want either of the dynamic-compilation backends to be built, you will need to install either LLVM (version 3) http://www.llvm.org, or libjit http://freshmeat.net/projects/libjit/.

Note that at the time of this writing I was not able to get libjit to compile without a fair bit of hacking around on its source code. I’ve pushed my changes to an unofficial clone of libjit, available at http://github.com/cpence/libjit.

Neither of these libraries are necessary (the included muParser backend will be built regardless), but they will provide a large speed boost.

Thanks

Thanks are most obviously due to the author of muParser, Ingo Berg. Without muParser having been written, I never would have been able to start on the project that produced the need for AFormula. muParser, which is licensed under the MIT license, is Copyright (C) 2004-2006 Ingo Berg.

Also, thanks is due to the pair of massively cross-platform JIT compilation libraries, LLVM and libjit, without which a JIT-compilation backend (for something like an order of magnitude of performance) would be impossible.