Expand description
Symbolic summation and products. Symbolic summation and products: Faulhaber, telescoping, hypergeometric, infinite sums, and closed-form products.
This module is the backend behind Ex::summation
and Ex::product_over. It works on
&mut Arena + ExprId and is also used by eval() when it encounters a
Sum node (via the thin shim in calculus::sum_eval).
§Summation strategies
For Σ_{k=lo}^{hi} f(k) the dispatcher tries, in order:
- Empty / enumerable ranges — concrete integer bounds with at most
MAX_ENUMERATION_TERMSterms are summed directly (exactly). - Constant body —
findependent ofkgivesf·(hi − lo + 1). - Rational functions of
k— partial fractions, then each pole familyc/(k+β)^mis summed with harmonic numbers / digamma, and integer-shifted poles telescope exactly (Σ 1/(k(k+1)) = 1 − 1/(n+1)). - Telescoping
g(k) − g(k+d)for two-term bodies. - Linearity — sums of terms are summed term-by-term; terms that
cannot be summed are kept as an unevaluated
Sum. - Polynomials in
k(any degree, symbolic coefficients allowed) via Faulhaber’s formula with exact Bernoulli numbers. - Binomial identities (
Σ C(n,k) = 2ⁿ,Σ k·C(n,k) = n·2ⁿ⁻¹,Σ C(n,k)² = C(2n,n),Σ C(n,k) xᵏ = (1+x)ⁿ, …). Geometric exponents may carry a symbolick-free offset, so the binomial theoremΣ C(n,k) pᵏ (1−p)ⁿ⁻ᵏ = 1closes for symbolicnandp. - Geometric / arithmetico-geometric
Σ P(k)·rᵏwith symbolicr(aPiecewisecoversr = 1). - Gosper’s algorithm for hypergeometric terms (including
C(k+c, k)-type binomials withkin both arguments).
For infinite upper bounds the engine additionally recognises p-series
(ζ(2m) in closed form), alternating p-series (η, Dirichlet β),
convergent geometric series, the negative-binomial series
Σ P(k)·C(k+c,k)·xᵏ ((1−x)^{−(c+1)} for P = 1, any c), and a
table of classical power series
(Σ xᵏ/k! = eˣ, Σ (−1)ᵏ x²ᵏ⁺¹/(2k+1)! = sin x, Σ xᵏ/k = −ln(1−x), …),
and proves divergence where it can.
Symbolic ratios. Convergence of an infinite geometric-type series
is decided only for a numeric ratio. There is no |r| < 1 assumption,
so Σ_{k≥0} rᵏ, Σ k (1−p)ᵏ⁻¹ p or Σ C(k+c,k) xᵏ with a symbolic
ratio stay unevaluated (SymPy returns a Piecewise over Abs(r) < 1
instead). Sums whose ratio is numeric but whose other parameters are
symbolic (Σ C(k+c,k) (1/3)ᵏ = (2/3)^{−c−1}) do close.
Values without an elementary closed form use the dedicated nodes:
Σ 1/k³ = ζ(3) (Zeta), Σ (−1)^k/(2k+1)² = G (Catalan).
Constants§
- MAX_
ENUMERATION_ TERMS - Maximum number of terms that will be summed / multiplied by direct enumeration when both bounds are concrete integers.