Nearest-integer modulus switching #
Scale the canonical centered integer representative by the rational ratio of target to source
modulus, round to the nearest integer, and reduce modulo the target. Half-integer ties round
toward positive infinity, as in Mathlib's round.
Main definitions #
ZMod.modulusSwitch: the canonical coefficient conversion.ZMod.modulusSwitchResidue: its integer-only implementation on a signed representative.
Main results #
ZMod.modulusSwitch_intCast: for nonzero source modulus, any integer representative gives the same converted residue, including negative representatives and half-integer ties.ZMod.modulusSwitchResidue_eq_val: integer division realizes the canonical conversion.
This is a numerical conversion, not a ring homomorphism. The intended source and target moduli are positive; the definition is total, and representative independence is stated for nonzero source modulus. No statement about plaintext preservation, hardness, or computational complexity is made.
Rounding after scaling gives the same residue from every integer representative.
Integer-only implementation of scaled nearest-integer rounding followed by reduction. Both moduli and the signed representative are runtime arithmetic inputs. At zero source or target modulus the formula is still total, using Lean's division and remainder conventions.
The integer-only implementation returns exactly the existing switch's canonical residue.