tax is a header-only C++23 library for Truncated Algebraic eXpansions — truncated multivariate Taylor polynomials as first-class numerical objects. Write a natural mathematical expression and tax propagates the full Taylor series through it, yielding the function value and every partial derivative up to order (N) in a single evaluation pass.
📚 Full documentation: https://andreapasquale94.github.io/tax/
⚠️ Active development. APIs and behavior may change between minor versions until 1.0.
- Compile-time fixed shape —
TaylorExpansion<T, Scheme>; theSchemefixes the truncation order(s) and variable count at compile time, and the coefficients live in a stackstd::array. - Convenience aliases —
TE<N, M=1>/TEn<N, M>,NE<N, Axes...>(named),MTE<Axes...>(mixed-order named). - Comprehensive math — arithmetic, trigonometric, hyperbolic,
transcendental, square/cubic root, reciprocal, integer & real powers,
half-integer powers (
halfPow<K>for x^(K/2),invSqrtPow<K>for x^(-K/2) — the 1/r^3 gravity kernel isinvSqrtPow<3>(r2)),atan2,erf. - Vector algebra —
dot(vector·vector and matrix·vector, the latter also taking a constant real linear map),cross,angle,unitvec,unitcross,projvec,projplaneover Eigen vectors of expansions; results are full Taylor series (sogradient(angle(a, b))is meaningful). - Direct derivative access — coefficients, partial derivatives at the expansion point, full gradient / Hessian / Jacobian.
- Eigen integration —
NumTraitsspecialisation plus helpers for variables, value extraction, evaluation, gradient, Jacobian, Hessian, and formal map inversion. - Named expansions —
NamedTaylorExpansion<T, N, Axes...>attaches compile-time named axes to an expansion; values over different axis sets compose in their union, andslice/deriv/integare addressed by name.MixedTaylorExpansion<T, Axes...>gives each axis its own truncation order. The whole API is re-exported undertax(tax::NE,tax::MTE,tax::variable(s)). - Human-readable output —
std::cout << fprints the polynomial series;tax::series(...)adds tabular / per-element (Eigen) rendering.
🔌 Plugin: adaptive ODE integration and Automatic Domain Splitting are available as the optional tax-flow project, built on top of
tax.
A TaylorExpansion<T, N, M> stores the coefficients of the order-$N$ truncated
Taylor polynomial of a function of
The std::array. Every operation is a
degree-by-degree recurrence relation that writes the result coefficients
directly, so one evaluation pass yields the value and all derivatives up to
order
The same pattern covers /, sqrt, log, sin/cos, pow, atan2, erf, …
coeff(α) returns the raw derivative(α) applies the
The full per-operation recurrence catalog (univariate and multivariate forms) lives under Internals / Recurrence Relations, and the convergence behaviour under Concepts.
- C++23 compiler — GCC 13+, Clang 17+, Apple Clang 16+
- CMake 3.28+
- Eigen 3.4+
#include <tax/tax.hpp>
#include <iostream>
int main() {
auto x = tax::TE<9>::variable(0.0); // x at x₀ = 0, order 9
tax::TE<9> f = tax::sin(x);
std::cout << f.value() << "\n"; // sin(0) = 0
std::cout << f.derivative<1>() << "\n"; // cos(0) = 1
std::cout << f.derivative<3>() << "\n"; // -cos(0) = -1
std::cout << f.eval({0.3}) << "\n"; // ≈ sin(0.3)
}#include <tax/tax.hpp>
int main() {
using TE2 = tax::TE<3, 2>;
auto x = TE2::variable<0>({1.0, 2.0});
auto y = TE2::variable<1>({1.0, 2.0});
TE2 f = tax::sin(x + y);
f.value(); // sin(3)
f.derivative<1, 0>(); // ∂f/∂x = cos(3)
f.derivative<1, 1>(); // ∂²f/∂x∂y = -sin(3)
}using TE2 = tax::TE<3, 2>;
auto x = TE2::variable<0>({1.0, 2.0});
auto y = TE2::variable<1>({1.0, 2.0});
Eigen::Vector2<TE2> F = { tax::sin(x), tax::cos(y) };
auto vals = tax::la::value(F); // Eigen::Vector2d of constant terms
auto J = tax::la::jacobian(F); // 2×2 Jacobian at expansion pointauto x = tax::variable<"x", 4>(1.0); // order-4 axis "x"
auto p = tax::variable<"p", 4>(2.0); // order-4 axis "p"
auto f = tax::sin(x) + x * p; // composes in the union of axes {p, x}
auto dfdx = f.deriv<"x">(); // partial derivative by axis name
auto fx = f.slice<"x">(); // project onto a single axistax::jacobian<"x">(F) likewise takes the Jacobian of an Eigen vector of named
expansions with respect to a named axis.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
ctest --test-dir build --output-on-failure| Option | Default | Description |
|---|---|---|
TAX_BUILD_UNITTESTS |
ON |
Build the unit-test suite |
TAX_BUILD_REGRESSIONS |
OFF |
Build DACE-based regression tests |
The fast Cauchy kernel paths (TAX_USE_UNROLL for M=1, TAX_USE_STENCIL
for M≥2) are enabled by default in <tax/kernels/cauchy.hpp> itself — no
build-system configuration needed. To opt out, pre-define the macro to 0
identically in every translation unit (differing values are an ODR
violation).
cmake --install build --prefix /your/install/prefixfind_package(tax CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE tax::tax)Hosted at https://andreapasquale94.github.io/tax/.
| Section | Topic |
|---|---|
| Getting Started | Install, build, write your first Taylor expansion |
| Guide | How-to: variables & expressions, extracting results, storage, named expansions, Eigen |
| Reference | TaylorExpansion API, tax::la, tax::named, and the per-operation recurrence catalog |
| Concepts | The math: truncated Taylor polynomials, graded-lex ordering, convergence |
| Internals | Architecture, kernels, recurrences |
Source for the docs lives in docs/ and is built with MkDocs Material:
pip install mkdocs-material pymdown-extensions
mkdocs serve --strict