HexTruncatedSeriesTheory gives TSeries R n Mathlib's CommRing
structure, built from the operations above, so Mathlib's lemmas apply to the
same addition and multiplication that the programs use. It defines
HexTruncatedSeriesTheory.ofPowerSeries, which keeps the first n
coefficients of a Mathlib power series, as a surjective ring homomorphism:
Truncation carries Mathlib's unit-certified inverse to executable Newton
inversion.
This turns computations into proofs about Mathlib's power series. The
theorem below determines the coefficient of x¹⁰ in the inverse of the
finite product (1 - x)(1 - x²)⋯(1 - x¹⁰). The factors beyond it do not
change that coefficient, so by Euler's identity it is p(10) = 42; the
theorem itself does not mention partitions. The proof truncates at precision
11, moves the inverse and the product across the homomorphism, and lets
decide +kernel run the Newton iteration:
The companion proves the same kind of statement for the other operations
that have a counterpart in Mathlib: substitution
(HexTruncatedSeriesTheory.ofPowerSeries_subst), the compositional
inverse (HexTruncatedSeriesTheory.ofPowerSeries_substInvOfIsUnit),
the exponential (HexTruncatedSeriesTheory.ofPowerSeries_exp) and
the logarithm (HexTruncatedSeriesTheory.ofPowerSeries_logOf), as
well as powers, truncation and the derivative. Their hypotheses differ from
Mathlib's in two places. Mathlib's substitution f.subst g needs only that
the constant coefficient of g be nilpotent, while comp needs it to be
0, and the correspondence assumes the stronger hypothesis: over ℤ/4ℤ at
precision 1, substituting g = 2 into f = X gives the constant 2,
while comp of the truncations gives 0. Mathlib's exponential and
logarithm are defined over ℚ-algebras, so those two correspondences assume
one, and the exponential and logarithm over ℤ/pℤ described above have no
Mathlib counterpart.
Mathlib has no square root of power series either. The companion proves
that, given a square root r of the constant coefficient with 2r a unit,
there is exactly one power series square root with constant coefficient r: