limes (Latin: limit, boundary) is a C++20 header-only library for composable calculus expressions with symbolic differentiation and numerical integration.
Quick Example
auto x = arg<0>;
auto f = sin(x * x);
auto df = derivative(f).wrt<0>();
auto I = integral(f).over<0>(0.0, 1.0);
auto result = I.eval();
Main entry point for the limes library.
Expression layer for composable calculus.
Why limes?
Most numerical libraries treat functions as black boxes. limes treats mathematical expressions as algebraic objects that compose according to mathematical laws:
- Derivatives are computed symbolically via chain rule at compile time
- Integrals compose via linearity, Fubini's theorem, and separability
- Methods are first-class objects you can mix and match
This design enables optimizations impossible with black-box functions:
auto I = integral(sin(x)).over<0>(0.0, pi);
auto J = integral(exp(y)).over<1>(0.0, 1.0);
auto IJ = I * J;
Architecture
Documentation
Guides
- Motivation - The problem limes solves and design philosophy
- Tutorial - Step-by-step introduction
- Examples - Complete worked examples
Reference
Design
Key Features
Symbolic Differentiation
Chain rule applied at compile time:
auto f = exp(sin(x));
auto df = derivative(f).wrt<0>();
auto d2f = derivative(f).wrt<0, 0>();
auto grad = derivative(f).gradient();
See limes::expr::derivative and limes::expr::DerivativeBuilder.
Numerical Integration
Fluent builder with method selection:
auto I = integral(x*x).over<0>(0.0, 1.0);
I.eval();
I.eval(gauss<7>());
I.eval(monte_carlo(10000));
I.eval(adaptive(1e-12));
See limes::expr::Integral and limes::expr::IntegralBuilder.
Box Integration
Monte Carlo over N-dimensional rectangular regions:
auto I = integral(x*y*z).over_box({{0,1}, {0,1}, {0,1}});
auto result = I.eval(monte_carlo(100000));
See limes::expr::BoxIntegral.
Separable Composition
Multiply independent integrals for automatic factorization:
auto I = integral(sin(x)).over<0>(0, pi);
auto J = integral(exp(y)).over<1>(0, 1);
auto IJ = I * J;
See limes::expr::ProductIntegral.
Integration Methods
First-class method objects with builder configuration:
gauss<7>()
make_adaptive(gauss<5>(), 1e-10)
Adaptive integration with recursive interval subdivision until convergence.
Monte Carlo integration using random sampling. Error decreases as O(1/sqrt(n)).
See limes::methods.
Getting Started
Include the main header:
Or include specific modules:
Expression layer for composable calculus expressions.
Integration method objects for composable numerical integration.
Installation
limes is header-only. Copy include/limes to your project or use CMake:
find_package(limes REQUIRED)
target_link_libraries(your_target PRIVATE limes::limes)
Requirements
- C++20 compiler (GCC 10+, Clang 12+, MSVC 19.29+)
- CMake 3.16+