Documentation

CslibFrontier.Foundations.Data.Nat.ChineseRemainder

Two-modulus Chinese Remainder recombination #

crtCombine D L a xL inv = a + D * ((xL - a) * inv mod L) recombines a residue a modulo D and a residue xL modulo L, given an inverse inv of D modulo L. The difference xL - a is taken modulo L and written as xL + (L - a mod L), so no natural-number subtraction truncates. The output is congruent to a modulo D for all arguments and to xL modulo L whenever inv * D ≡ 1 (mod L). Such an inverse makes D and L coprime, so crtCombine reconstructs every x < D * L from x mod D and x mod L; Mathlib's Nat.chineseRemainder gives the same value without an explicit formula.

Main definitions #

Main results #

References #

def Cslib.crtCombine (D L a xL inv : ℕ) :

Chinese Remainder Theorem combination of a = x % D and xL = x % L using an inverse inv of D modulo L; the summand L - a % L represents -a modulo L without ℕ-subtraction underflow.

theorem Cslib.crtCombine_modEq_left (D L a xL inv : ℕ) :
crtCombine D L a xL inv ≡ a [MOD D]

crtCombine D L a xL inv is congruent to a modulo D, for all arguments.

theorem Cslib.crtCombine_modEq_right {D L inv : ℕ} (hL : 0 < L) (hinv : ↑inv * ↑D = 1) (a xL : ℕ) :
crtCombine D L a xL inv ≡ xL [MOD L]

crtCombine D L a xL inv is congruent to xL modulo L when inv * D ≡ 1 (mod L), for every a and xL.

theorem Cslib.crtCombine_lt {D L a : ℕ} (ha : a < D) (hL : 0 < L) (xL inv : ℕ) :
crtCombine D L a xL inv < D * L

Whenever a < D and 0 < L, crtCombine D L a xL inv < D * L.

theorem Cslib.crtCombine_eq {D L x a xL : ℕ} (hx : x < D * L) (ha : a = x % D) (hxL : xL = x % L) (inv : ℕ) (hinv : ↑inv * ↑D = 1) :
crtCombine D L a xL inv = x

Chinese Remainder Theorem reconstruction (the two-modulus case of the CRT used in [KL20], Section 10.2.1, p. 374): for x < D * L, a = x % D, xL = x % L, and inv * D ≡ 1 (mod L), crtCombine D L a xL inv = x. Positivity of D and L follows from x < D * L, and their coprimality from the inverse.