hex

4.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 Hex.ZMod64 residue as a Mathlib ZMod class.

🔗def

Rebuild an executable Hex.ZMod64 residue from a Mathlib ZMod class.

They are mutually inverse:

🔗theorem

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

🔗theorem

Round-trip ZModHex.ZMod64ZMod is the identity. Together with HexModArithMathlib.ZMod64.ofZMod_toZMod, this shows the two conversions are mutually inverse and define a ring equivalence.

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

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

🔗def

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