Documentation

CslibFrontier.Foundations.Data.Int.Residue

Integer residues as natural numbers #

Main results #

Bounds on natural residues use Mathlib's existing Int.natMod_lt.

References #

Adapted from Index.lean at anthropics/formal-math@16a5ce41304fcdaea4e0be7c132e1c361dc26da5. The existing Exact Triangle hashing client now uses these shared facts.

theorem Int.natCast_toNat_emod {p : ℕ} (hp : 0 < p) (u : ℤ) :
↑(u % ↑p).toNat = u % ↑p

Casting the natural Euclidean residue back to Int preserves its value for a positive modulus.

theorem Int.toNat_neg_emod {p : ℕ} (hp : 0 < p) (z : ℤ) :
(-z % ↑p).toNat = if (z % ↑p).toNat = 0 then 0 else p - (z % ↑p).toNat

Natural residues of negated integers use a zero test followed by natural subtraction.