Documentation

CslibFrontier.Foundations.Data.ZMod.NatCast

Casts of natural-number expressions to ZMod #

Programs that work on natural numbers subtract a residue b modulo q as q - b % q, which avoids truncated subtraction below zero. This module shows that the cast of q - b % q to ZMod q is -b, and that the cast of q - 1 is -1.

Main results #

theorem ZMod.natCast_sub_mod_eq_neg (q b : ℕ) [NeZero q] :
↑(q - b % q) = -↑b

For q ≠ 0, the natural number q - b % q casts to -b in ZMod q.

theorem ZMod.natCast_self_sub_one (q : ℕ) [NeZero q] :
↑(q - 1) = -1

For q ≠ 0, the natural number q - 1 casts to -1 in ZMod q.