MML
MML (Minimal Math Library) - A comprehensive, single-header C++ mathematical library for numerical computing
Install / Use
/learn @zvanjak/MMLREADME
🔢 MML — Minimal Math Library
The Complete C++ Numerical Computing Toolkit
Single-header • Cross-platform • Visualization included
Mission
🚀 Just #include "MML.h" and compute — vectors, matrices, tensors, ODE solvers, eigenvalues, integration, and more!
Quick Start • Features • Documentation • Examples • Visualization
</div>🎯 What is MML?
MML is a comprehensive, single-header C++ mathematical library for numerical computing. With just one #include "MML.h" directive, you get access to a complete toolkit of mathematical objects and algorithms — from basic vectors and matrices to ODE solvers and field operations.
And as a bonus, you also get cross-platform visualization tools for plotting functions, curves, surfaces, and vector fields!
The Problem
Most C++ math libraries require:
- Complex build systems and dependencies
- Linking against multiple libraries
- Platform-specific configuration
- Steep learning curves
Result: Possibly hours of setup before writing actual code.
</td> <td width="50%">The MML Solution
Zero-friction integration:
#include "MML.h"
// That's it. Start computing.
- ✅ Single header file
- ✅ Pure C++17, no dependencies
- ✅ Works on Windows, Linux, Mac
- ✅ 4,540 tests ensure correctness
If needed, you can also use it piece-wise by including only selected headers from mml/ directory.
🏛️ Design Philosophy
MML is built on three core principles:
<table> <tr> <td align="center" width="33%">🎯 Completeness & Simplicity
A comprehensive toolkit covering vectors, matrices, tensors, ODEs, integration, field operations, and more. Intuitive syntax makes mathematical objects first-class citizens in C++.
</td> <td align="center" width="33%">🔬 Correctness & Precision
4,540 unit tests validate every algorithm against known analytical solutions. Numerical methods report achieved precision, and dedicated testbeds demonstrate accuracy.
</td> <td align="center" width="33%">⚡ Trivial Integration & Visualization
Single header, zero dependencies — just #include "MML.h" and start computing immediately. Cross-platform visualizers for functions, surfaces, vector fields, and particle systems on Windows, Linux and Mac.
Flagship Example: Verify Gauss's Divergence Theorem
// Verify ∫∫∫(∇·F)dV = ∮∮(F·n̂)dS over a unit cube
// Define vector field F(x,y,z) = (x², y², z²)
VectorFunction<3> F([](const VectorN<Real, 3>& p) {
return VectorN<Real, 3>{ p[0]*p[0], p[1]*p[1], p[2]*p[2] };
});
// Compute divergence NUMERICALLY - MML calculates ∇·F automatically!
ScalarFunctionFromStdFunc<3> divF([&F](const VectorN<Real, 3>& p) {
return VectorFieldOperations::DivCart<3>(F, p);
});
// Volume integral: ∫∫∫(∇·F)dV
auto y_lo = [](Real) { return 0.0; }; auto y_hi = [](Real) { return 1.0; };
auto z_lo = [](Real,Real) { return 0.0; }; auto z_hi = [](Real,Real) { return 1.0; };
Real volIntegral = Integrate3D(divF, GAUSS10, 0, 1, y_lo, y_hi, z_lo, z_hi).value;
// Surface integral: ∮∮(F·n̂)dS through all 6 faces
Cube3D unitCube(1.0, Point3Cartesian(0.5, 0.5, 0.5));
Real surfIntegral = SurfaceIntegration::SurfaceIntegral(F, unitCube, 1e-8);
std::cout << "Volume integral: " << volIntegral << "\n"; // 3.0000000000
std::cout << "Surface integral: " << surfIntegral << "\n"; // 3.0000000000
std::cout << "Error: " << std::abs(volIntegral - surfIntegral) << "\n"; // 9.77e-15 ✓
🚀 Quick Start
Installation
Option 1: Simply get single header (Recommended)
# Download MML.h directly from the repository
curl -O https://raw.githubusercontent.com/zvanjak/MML/master/mml/single_header/MML.h
# Include in your project
#include "MML.h"
Option 2: Get whole repository (if you need individual modules)
git clone https://github.com/zvanjak/MML.git
cd MML
cmake -B build
cmake --build build
Option 3: Visual Studio Code
- Open VS Code and press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) - Type "Git: Clone" and press Enter
- Paste the repository URL:
https://github.com/zvanjak/MML.git - Select a folder and open the cloned repository
- When prompted, install recommended extensions (C/C++, CMake Tools)
- Press
Ctrl+Shift+P→ "CMake: Configure" to set up the build - Press
F7to build or use the CMake status bar
💡 Tip: The CMake Tools extension provides IntelliSense, build buttons, and test integration out of the box.
First Program
#include "MML.h"
using namespace MML;
int main() {
// Create a matrix and solve a linear system
Matrix<Real> A{3, 3, {4, 1, 2,
1, 5, 1,
2, 1, 6}};
Vector<Real> b{1, 2, 3};
LUSolver<Real> solver(A);
Vector<Real> x = solver.Solve(b);
std::cout << "Solution: " << x << std::endl;
std::cout << "Residual: " << (A * x - b).NormL2() << std::endl;
return 0;
}
Compile:
g++ -std=c++17 -O3 myprogram.cpp -o myprogram
✨ Key Features
🏗️ Library Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ MML.h (single header) │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ mml/ │
│ ├── base/ Vectors, Matrices, Tensors, Functions, Geometry │
│ ├── core/ Derivation, Integration, Linear Solvers, Fields │
│ ├── algorithms/ ODE, Root Finding, Interpolation, Eigen Solvers │
│ ├── systems/ Dynamical Systems, Linear Systems, Attractors │
│ ├── interfaces/ Abstract interfaces │
│ └── tools/ Visualization, Serialization, Console Printing │
│ │
└─────────────────────────────────────────────────────────────────────┘
MML is organized into four main layers, each building on the previous one:
- Base — The mathematical foundation. Vectors, matrices, tensors, functions, polynomials, quaternions, and geometry primitives. These are the objects you compute with — designed with intuitive syntax so mathematical expressions in code read naturally.
- Core — Numerical operations on base objects. Numerical differentiation (up to 8th order accuracy), integration (1D/2D/3D with adaptive quadrature), linear system solvers (LU, QR, SVD, Cholesky), vector field operations (gradient, divergence, curl, Laplacian), coordinate transformations, and metric tensors.
- Algorithms — Higher-level problem-solving methods. ODE solvers (fixed and adaptive step), root finding (Bisection, Newton, Brent), eigenvalue decomposition, interpolation, curve fitting, path and surface integration, differential geometry, and function analysis.
- Tools — Bridging computation and presentation. Console printing with publication-quality formatting (6 export formats), file serialization for all mathematical objects, and cross-platform visualizers for functions, surfaces, vector fields, and particle systems.
📐 Mathematical Objects
| Category | Types | Description |
|----------|-------|-------------|
| Vectors | Vector<T>, VectorN<T,N>, 2D/3D Cartesian, Polar, Spherical | Dynamic and fixed-size vectors in multiple coordinate systems |
| Matrices | Matrix<T>, MatrixNM<N,M>, Symmetric, Tridiagonal, Band | Full matrix algebra with specialized storage |
| Tensors | Tensor2<N> through Tensor5<N> | Rank 2-5 tensors for advanced computations |
| Functions | IRealFunction, IScalarFunction<N>, IVectorFunction<N> | First-class function objects with calculus support |
| Curves & Surfaces | ParametricCurve<N>, ParametricSurface<N>, predefined 2D/3D | Parametric curves, surfaces, arc length, Frenet frames |
| Geometry | Points, Lines, Planes, Triangles, Bodies | 2D and 3D geometric primitives |
| Polynomials | Polynom<T> | Generic polynomials over any field |
| Quaternions | Full quaternion algebra | 3D rotations, SLERP interpolation |
🔢 Numerical Algorithms
| Category | Algorithms | Description | |----------|------------|-------------| | Linear Algebra | LUSolver, QRSolver, SVD, Cholesky | Matrix decompositions and solvers | | Eigensolvers | EigenSolver (symmetric & general) | Real matrix eigenvalue computation | | [Derivation](docs/core/D
