40. Number theory, combinatorics, NTT, and linear algebra (spec/lib/math.md, 2026-11-21)
- 40.1
Mod<P>.comb(limit = 0)tiesComb<P>toMod<P>without repeatingP. Aftertype Z = Mod<998_244_353>,let comb = Z.comb(n)constructsComb<998_244_353>(n)directly, keeping the modulus in one declaration (research/frictions/cf2084e.md,research/frictions/cf2150g.md).Comb<P>(limit)stays valid. Reverse: removeMod.comb.
- 40.2
cyclic: Bool = falseis a named option onconvolve,convolve_mod, andconvolve_int. Avoids separatecyclic_convolve*names and followsplan/STDLIB.md§2; bitwise convolutions (convolve_or,convolve_and,convolve_xor) andsos_sub/sos_suplive instd.nttalongside NTT so all convolution transforms share one module (research/frictions/cf2201e.md). Reverse: split bitwise transforms intostd.sosor addcyclic_convolvewrappers.
- 40.3
sieve_multiplicativetakes(n, one:, mul:, prime_pow:)explicitly. Takingmul: (T, T) -> Tworks uniformly forInt,Mod<P>, and user structs without needing new core trait constraints, and runs in strictO(n)by tracking each number's largest prime-power divisor (research/frictions/cf2135e2.md). Reverse: specialize onT: Mul.
- 40.4 Exact field elimination lives on
Mat<T>; pivotedF64elimination is*_real(..., eps: 1e-9). Floating-point Gaussian elimination requires partial pivoting byabsand a toleranceeps, whereas exact elimination overMod<P>checks== T.zero. Keeping them separate avoids hiddenF64specialization and respects CP Lang's default rejection of float equality.XorBasislives instd.matrixwith aMonoidcombinator for segment trees. Reverse: unify behind aFieldtrait once traits support associated pivoting policies.