Mathematical Foundations¶
This page describes the mathematical basis of the tax library: how truncated Taylor polynomials are represented, stored, and propagated through arithmetic and transcendental operations via degree-by-degree recurrence relations.
Truncated Taylor Polynomials¶
A truncated Taylor expansion of a function \(f\) in \(M\) variables around a point \(\mathbf{x}_0\) up to order \(N\) is:
where \(\alpha = (\alpha_1, \ldots, \alpha_M)\) is a multi-index with non-negative integer entries, \(|\alpha| = \alpha_1 + \cdots + \alpha_M\) is its total degree, and
The Taylor coefficients \(f_\alpha\) are related to partial derivatives by:
In the univariate case (\(M = 1\)), the multi-index reduces to a single integer \(d\), and the expansion simplifies to:
Graded Lexicographic Ordering¶
Coefficients are stored in a contiguous std::array using graded lexicographic (grlex) ordering: monomials are grouped by total degree \(|\alpha|\), and within each degree group they are sorted lexicographically by the exponent vector \(\alpha\).
Example for \(M = 2\), \(N = 2\):
| Flat index | Multi-index \((\alpha_1, \alpha_2)\) | Monomial | Degree |
|---|---|---|---|
| 0 | (0, 0) | 1 | 0 |
| 1 | (0, 1) | \(\delta x_2\) | 1 |
| 2 | (1, 0) | \(\delta x_1\) | 1 |
| 3 | (0, 2) | \(\delta x_2^2\) | 2 |
| 4 | (1, 1) | \(\delta x_1 \delta x_2\) | 2 |
| 5 | (2, 0) | \(\delta x_1^2\) | 2 |
The total number of coefficients for \(M\) variables at order \(N\) is:
Coefficient counts for common \((N, M)\) pairs:
| \(N \backslash M\) | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 2 | 3 | 6 | 10 | 15 | 21 | 28 |
| 3 | 4 | 10 | 20 | 35 | 56 | 84 |
| 4 | 5 | 15 | 35 | 70 | 126 | 210 |
| 5 | 6 | 21 | 56 | 126 | 252 | 462 |
| 6 | 7 | 28 | 84 | 210 | 462 | 924 |
| 8 | 9 | 45 | 165 | 495 | 1287 | 3003 |
| 10 | 11 | 66 | 286 | 1001 | 3003 | 8008 |
Arithmetic Operations¶
Addition and Subtraction¶
Addition is coefficient-wise:
Subtraction is analogous. Scalar addition modifies only the constant term: \((f + c)_\alpha = f_\alpha + c \cdot \delta_{\alpha,0}\).
Cauchy Product (Multiplication)¶
Univariate. The product of two truncated series is the discrete convolution truncated at order \(N\):
Multivariate. The Cauchy product generalizes to a sum over sub-multi-indices:
where \(\beta \le \alpha\) means \(\beta_i \le \alpha_i\) for all \(i\).
The library exploits symmetry in the self-product \(f \cdot f\): only unordered pairs \((\beta, \alpha - \beta)\) with \(\beta \le \alpha - \beta\) (in flat index) are enumerated, roughly halving the number of multiplications.
Scalar Multiplication and Division¶
Scalar multiplication scales all coefficients: \((c \cdot f)_\alpha = c \cdot f_\alpha\). Division by a scalar is multiplication by \(1/c\). Division by a polynomial uses the reciprocal recurrence (see below).
Algebraic Operations¶
Reciprocal¶
Given \(f\) with \(f_0 \ne 0\), compute \(g = 1/f\) by solving \(f \cdot g = 1\) degree by degree.
Univariate:
Multivariate:
Square Root¶
Given \(f\) with \(f_0 > 0\), compute \(g = \sqrt{f}\) by solving \(g^2 = f\).
Univariate:
The inner sum exploits symmetry: for even \(d\), the middle term \(g_{d/2}^2\) is counted once; other pairs \((k, d-k)\) are counted twice.
Multivariate:
with symmetric enumeration: pairs \((\beta, \alpha - \beta)\) with flat index \(\beta < \alpha - \beta\) are counted twice; diagonal pairs (\(\beta = \alpha - \beta\)) are counted once.
Cubic Root¶
Given \(f\) with \(f_0 \ne 0\), compute \(g = \sqrt[3]{f}\) by solving \(g^3 = f\).
Univariate:
where \(q = g^2\) is maintained incrementally: \(q_d^* = \sum_{k=1}^{d-1} g_k \, g_{d-k}\) is the partial self-product (excluding the unknown \(g_d\)), then finalized as \(q_d = 2 g_0 g_d + q_d^*\). This yields \(\mathcal{O}(N^2)\) total work instead of \(\mathcal{O}(N^3)\).
Multivariate:
with \(q = g^2\) updated degree by degree using symmetric enumeration.
Absolute Value¶
Absolute value propagates as:
This is well-defined only when \(f_0 \ne 0\).
Trigonometric Functions¶
Sine and Cosine¶
The sine and cosine of a series \(f\) are computed simultaneously via the coupled recurrence. Let \(s = \sin(f)\) and \(c = \cos(f)\).
Univariate:
Multivariate:
Tangent¶
Tangent is computed by solving \(c \cdot t = s\) degree by degree, where \(s = \sin(f)\) and \(c = \cos(f)\) are obtained from the coupled recurrence above.
Univariate:
Multivariate:
Arcsine¶
Compute \(g = \arcsin(f)\) using the helper \(h = \sqrt{1 - f^2}\). This reduces to solving \(h \cdot g' = f'\) degree by degree.
Univariate:
Multivariate:
Arccosine¶
Implemented by negating the arcsine result and adding \(\pi/2\) to the constant term.
Arctangent¶
Compute \(g = \arctan(f)\) using the helper \(h = 1 + f^2\). Solves \(h \cdot g' = f'\) degree by degree.
Univariate:
Multivariate:
Arctangent (Two-Argument)¶
Compute \(g = \text{atan2}(y, x)\) using the helper \(h = x^2 + y^2\). Solves the coupled system degree by degree.
Univariate:
Multivariate:
Hyperbolic Functions¶
Hyperbolic Sine and Cosine¶
The coupled recurrence for \(\text{sh} = \sinh(f)\) and \(\text{ch} = \cosh(f)\) has the same structure as sine/cosine but with a positive sign coupling.
Univariate:
Multivariate:
Note the sign difference from the trigonometric case: both sums are positive.
Hyperbolic Tangent¶
Computed by solving \(\text{ch} \cdot t = \text{sh}\) degree by degree, identical in structure to the tangent recurrence.
Univariate:
Multivariate:
Inverse Hyperbolic Sine¶
Compute \(g = \text{asinh}(f)\) using \(h = \sqrt{1 + f^2}\). Solves \(h \cdot g' = f'\).
Univariate:
Multivariate:
Inverse Hyperbolic Cosine¶
Compute \(g = \text{acosh}(f)\) using \(h = \sqrt{f^2 - 1}\). Requires \(f_0 > 1\). Same recurrence structure as asinh.
Univariate:
Multivariate:
Inverse Hyperbolic Tangent¶
Compute \(g = \text{atanh}(f)\) using \(h = 1 - f^2\). Requires \(|f_0| < 1\). Same recurrence structure.
Univariate:
Multivariate:
Transcendental Functions¶
Exponential¶
Compute \(g = \exp(f)\).
Univariate:
Multivariate:
This recurrence follows from differentiating \(g = \exp(f)\) to get \(g' = f' \cdot g\), then matching coefficients degree by degree.
Logarithm¶
Compute \(g = \ln(f)\) with \(f_0 > 0\).
Univariate:
Multivariate:
This is derived from \(f \cdot g' = f'\), matching coefficients.
Logarithm Base 10¶
Computed by applying the natural logarithm recurrence and scaling all coefficients by \(1/\ln(10)\).
Power Functions¶
Integer Power¶
For integer exponent \(n\), \(f^n\) is computed via binary exponentiation using the Cauchy product. Special cases: \(n = 0\) returns 1, \(n = 1\) returns \(f\), \(n = -1\) uses the reciprocal recurrence, and negative \(n\) computes the reciprocal first, then raises to \(|n|\).
Real Power¶
Compute \(g = f^c\) for real exponent \(c\) with \(f_0 > 0\).
Univariate:
Multivariate:
This recurrence is derived from the identity \(f \cdot g' = c \cdot f' \cdot g\).
DA Power¶
When both base and exponent are DA objects, \(f^g\) is computed as:
using the logarithm, Cauchy product, and exponential recurrences in sequence.
Special Functions¶
Error Function¶
Compute \(g = \text{erf}(f)\) using the helper:
which is the derivative of \(\text{erf}\). Then the recurrence follows the same exponential-like pattern.
Univariate:
Multivariate:
Distance Functions¶
Hypot (2-argument): \(\text{hypot}(x, y) = \sqrt{x^2 + y^2}\). Computed by forming the Cauchy self-products \(x^2\) and \(y^2\), summing, and applying the square root recurrence.
Hypot (3-argument): \(\text{hypot}(x, y, z) = \sqrt{x^2 + y^2 + z^2}\). Same approach extended to three terms.
Multivariate Generalisation¶
All univariate recurrences presented above generalize naturally to the multivariate case. The key substitutions are:
- Scalar index \(d\) is replaced by multi-index \(\alpha\) with \(|\alpha| = d\).
- Inner sums \(\sum_{k=0}^{d}\) become sub-multi-index sums \(\sum_{\beta \le \alpha}\), iterated over all \(\beta\) with \(\beta_i \le \alpha_i\) for each component.
- Degree constraints like \(1 \le k \le d-1\) become \(1 \le |\beta| \le |\alpha|-1\) (or the appropriate range).
- The weight factor \(d - k\) generalises to \(|\alpha| - |\beta|\), and \(k\) to \(|\beta|\).
In the implementation, the function forEachSubIndex<M>(alpha, lo, hi, callback) enumerates all sub-multi-indices \(\beta \le \alpha\) with \(\text{lo} \le |\beta| \le \text{hi}\), calling callback(flatIndex(beta), flatIndex(alpha - beta), |beta|). This provides a uniform interface for both univariate and multivariate kernels, with the univariate path using simple scalar loops as a fast path via if constexpr (M == 1).