Description
Meta mathematic
metamath is a tiny header-only library. It can be used for symbolic computations on single-variable functions, such as dynamic computations of derivatives. The operator precedence rules are naturally handled by the compiler. The library could be useful for building custom DSL's in C++.
func.h contains definitions for some of the cmath functions: Sin/Cos, Ln, Pow, Abs, Sqrt, Exp, more to come...
Function composition is supported.
metamath alternatives and similar libraries
Based on the "Math" category.
Alternatively, view metamath alternatives based on common mentions on social networks and blogs.
-
OpenBLAS
OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version. -
Eigen
A high-level C++ library of template headers for linear algebra, matrix and vector operations, numerical solvers and related algorithms. [MPL2] -
TinyExpr
tiny recursive descent expression parser, compiler, and evaluation engine for math expressions -
MIRACL
MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC). -
linmath.h
a lean linear math library, aimed at graphics programming. Supports vec3, vec4, mat4x4 and quaternions -
NT2
A SIMD-optimized numerical template library that provides an interface with MATLAB-like syntax. [Boost] -
ExprTK
C++ Mathematical Expression Parsing And Evaluation Library https://www.partow.net/programming/exprtk/index.html -
LibTomMath
LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C. -
muparser
muparser is a fast math parser library for C/C++ with (optional) OpenMP support. -
GMTL
Generic Math Template Library (forked from http://ggt.sourceforge.net/) -
safe_numerics
Replacements to standard numeric types which throw exceptions on errors -
blaze
high-performance C++ math library for dense and sparse arithmetic. [BSD] -
Versor
[older version] Versor 1.0 C++ library for conformal geometric algebra draw routines -
Xerus
A general purpose library for numerical calculations with higher order tensors, Tensor-Train Decompositions / Matrix Product States and other Tensor Networks -
SLIMCPP
Simple Long Integer Math for C++. Lightweight cross-platform header-only library what implements big integer arithmetic in С++17. -
Mission : Impossible (AutoDiff)
A concise C++17 implementation of automatic differentiation (operator overloading) -
ceval
A C/C++ library for parsing and evaluation of arithmetic expressions. -
Armadillo
A high quality C++ linear algebra library, aiming towards a good balance between speed and ease of use. The syntax (API) is deliberately similar to Matlab. [MPL2] -
GMP
A C/C++ library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. [LGPL3 & GPL2]
Updating dependencies is time-consuming.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of metamath or a related project?
README
metamath
Meta mathematic
metamath is a tiny header-only library. It can be used for symbolic computations on single-variable functions, such as dynamic computations of derivatives. The operator precedence rules are naturally handled by the compiler. The library could be useful for building custom DSL's in C++.
func.h contains definitions for some of the cmath functions: Sin/Cos, Ln, Pow, Abs, Sqrt, Exp, more to come... Arithmetic operations with functions are supported:
auto f1 = 3 * x;
auto f2 = Ln(x);
auto f = f1 + f2;
auto y1 = f(2);
auto y2 = f(4);
as well as function composition:
auto f = Ln(x);
auto g = 3 * x;
auto h = f(g);
auto y1 = h(2);
Examples of Functions and Derivatives
Example:
using namespace metamath;
auto f = 3 * x * x;
std::cout << "f(x) = " << f << std::endl;
std::cout << "f(4) = " << f(4.f) << std::endl;
std::cout << "------" << std::endl;
// take derivative
auto df = derivative(f);
std::cout << "f`(x) = " << df << std::endl;
std::cout << "f`(4) = " << df(4.f) << std::endl;
This will produce the following output:
f(x) = 3 * x * x
f(4) = 48
------
f`(x) = ((0 * x + 3) * x + 3 * x)
f`(4) = 24
Example:
auto f = 4 * Sin(2 * x);
std::cout << "f(x) = " << f << std::endl;
std::cout << "f(pi) = " << f(M_PI) << std::endl;
std::cout << "f(pi/4) = " << f(M_PI/4.f) << std::endl;
std::cout << "------" << std::endl;
//take derivative
auto df = derivative(f);
std::cout << "f`(x) = " << df << std::endl;
std::cout << "f`(pi) = " << df(M_PI) << std::endl;
std::cout << "f`(pi/4) = " << df(M_PI/4.f) << std::endl;
This will produce the following output:
f(x) = 4 * sin(2 * x)
f(pi) = 6.99382e-07
f(pi/4) = 4
------
f`(x) = (0 * sin(2 * x) + 4 * cos(2 * x) * (0 * x + 2))
f`(pi) = 8
f`(pi/4) = -3.49691e-07
Build
Requirements
C++14 or later
Steps to build the sample
- Suppose you cloned to [HOME]/work/metamath
For out-of-source, create a build folder in [HOME]/work, and go there.
$mkdir build $cd build
Run cmake
$cmake ../metamath
Build it
$make
You can now run a sample (the sample source is in metamath/sample/)
$./sample/mms
The sample output:
Metamath sample ====== f(x) = 3 * x * x f(4) = 48 ------ f`(x) = ((0 * x + 3) * x + 3 * x) f`(4) = 24 ====== ====== f(x) = 3 * x f(2) = 6 f(3) = 9 ------ f`(x) = (0 * x + 3) f`(2) = 3 ====== ====== f(x) = ((1) / (x)) f(2) = 0.5 f(3) = 0.333333 ------ f`(x) = (((0 * x - 1)) / (x * x)) f`(2.f) = -0.25 ====== ====== f(x) = ((2 * (x + 1)) / (x)) f(2) = 3 f(3) = 2.66667 ------ f`(x) = ((((0 * (x + 1) + 2 * 1) * x - 2 * (x + 1))) / (x * x)) f`(2) = -0.5 ====== ====== f(x) = 4 * sin(2 * x) f(pi) = 6.99382e-07 f(pi/4) = 4 ------ f`(x) = (0 * sin(2 * x) + 4 * cos(2 * x) * (0 * x + 2)) f`(pi) = 8 f`(pi/4) = -3.49691e-07 ====== ====== f(x) = sqrt(x) f(4) = 2 f(6) = 2.44949 ------ f`(x) = ((1) / (2 * sqrt(x))) f`(4) = 0.25 f`(6) = 0.204124 ====== ====== f(x) = (3 * x^2) f(4) = 144 f(6) = 324 ------ f`(x) = 2 * (3 * x^1) * (0 * x + 3) f`(4) = 72 f`(6) = 108 ====== ====== f(x) = e^(3 * x) f(4) = 162755 f(6) = 6.566e+07 ------ f`(x) = e^(3 * x) * (0 * x + 3) f`(4) = 488264 f`(6) = 1.9698e+08 ====== ====== f(x) = ln(3 * x) f(4) = 2.48491 f(6) = 2.89037 ------ f`(x) = ((1) / (3 * x)) * (0 * x + 3) f`(4) = 0.25 f`(6) = 0.166667 ====== ====== f(x) = |3 * x| f(-4) = 12 f(6) = 18 ------ f`(x) = ((3 * x) / (|3 * x|)) * (0 * x + 3) f`(-4) = -3 f`(6) = 3 ====== ====== f(x) = ln(x) g(x) = 3 * x h(x) = f(g(x)) = ln(3 * x) h(4) = 2.48491 ------ h`(x) = ((1) / (3 * x)) * (0 * x + 3) h`(4) = 0.25 ======