hex

8.7. The Mathlib correspondence🔗

Everything above is executable and Mathlib-free. HexModArithMathlib connects it to Mathlib: every Hex.ZMod64 value corresponds to an element of Mathlib's ZMod p. The two transfer maps convert a residue to a ZMod p element and back.

🔗def

Interpret an executable ZMod64 residue as a Mathlib ZMod class.

🔗def

Rebuild an executable ZMod64 residue from a Mathlib ZMod class.

They are mutually inverse:

🔗theorem

Round-trip ZMod64 ZMod ZMod64 is the identity. This is the left-inverse law making toZMod injective; a caller that transfers a residue to Mathlib and back recovers it unchanged.

🔗theorem

Round-trip ZMod ZMod64 ZMod is the identity. Together with ofZMod_toZMod this shows the two conversions are mutually inverse, so equiv below is a genuine ring equivalence.

toZMod preserves the ring operations: addition and multiplication transfer, as do negation, subtraction, the casts, and powers (each a @[simp] lemma):

🔗theorem

toZMod is additive. This is the additive-homomorphism law underlying equiv; it lets a caller push toZMod through a sum and so transfer any additive ZMod identity back to ZMod64.

🔗theorem

toZMod is multiplicative. This is the multiplicative-homomorphism law underlying equiv; it lets a caller push toZMod through a product and so transfer any multiplicative ZMod identity back to ZMod64.

The maps and laws bundle into a ring equivalence, so the CommRing theory of ZMod p transports to the executable type:

🔗def

The executable ZMod64 representation is ring-equivalent to Mathlib's ZMod.