The canonical prime word #
An element x : ZMod p of a prime field with p ≤ 2 ^ 64 is carried on one 64-bit
word as its canonical representative BitVec.ofNat 64 x.val. This module fixes that
encoding, primeWord p, and its decoder primeDec p w = (w.toNat : ZMod p), which is
the relation of the single-limb retraction Transfer.Param.limbFieldParam: the
encoding is the section of that retraction (primeWord_eq_section), and a word is
related to a field element exactly when it decodes to it (limbFieldParam_R_iff).
The operation squares are registered along both maps.
- Along the encoding
primeWord p(field to word) the squares are total: the reference word operationsaddModW,subModW,mulModW,negModWrealize+,-,*and negation, and word equality and word order agree with equality and with the order ofZMod.val. - Along the decoder
primeDec p(word to field) the wrapping word operations realize the field operations under a no-overflow guard (+,*) or an order guard (-), and the reductionmodW prealizes the identity. Word equality agrees with field equality on canonical words.
The instances take the bound p ≤ 2 ^ 64 as a Fact, as
Transfer.Param.instTransferDomLimbField does.
Main definitions #
primeWord p,primeDec p: the canonical encoding and its decoder.addModW p,subModW p,mulModW p,negModW p,modW p: the reference word operations modulop.
Main results #
primeWord_toNat,primeWord_injective,eq_primeWord_of_toNat,primeDec_primeWord,primeWord_primeDec,primeWord_natCast: the encoding API.addRelated,subRelated,mulRelated,negRelated,eqRelated,valLtRelated: the total squares alongprimeWord p.decAddRelatedOn,decMulRelatedOn,decSubRelatedOn,decModRelated,decEqRelatedOn: the squares alongprimeDec p.
The canonical prime word: a field element as the 64-bit word of its canonical representative.
Equations
- Transfer.PrimeWord.primeWord p x = BitVec.ofNat 64 x.val
Instances For
The decoder of the canonical prime word: a 64-bit word read modulo p.
Equations
- Transfer.PrimeWord.primeDec p w = ↑w.toNat
Instances For
The word sum reduced modulo p.
Equations
- Transfer.PrimeWord.addModW p a b = BitVec.ofNat 64 ((a.toNat + b.toNat) % p)
Instances For
The word difference modulo p, computed as a + (p - b) reduced modulo p.
Equations
- Transfer.PrimeWord.subModW p a b = BitVec.ofNat 64 ((a.toNat + (p - b.toNat)) % p)
Instances For
The word product reduced modulo p.
Equations
- Transfer.PrimeWord.mulModW p a b = BitVec.ofNat 64 (a.toNat * b.toNat % p)
Instances For
The word negation modulo p, computed as p - a reduced modulo p.
Equations
- Transfer.PrimeWord.negModW p a = BitVec.ofNat 64 ((p - a.toNat) % p)
Instances For
The reduction of a word modulo p.
Equations
- Transfer.PrimeWord.modW p a = BitVec.ofNat 64 (a.toNat % p)
Instances For
The encoding and the retraction #
The canonical prime word is injective.
The canonical prime word of the cast of n < p is the word of n.
The canonical prime word is related to its field element by limbFieldParam.
Total squares along the encoding #
Guarded squares along the decoder #
The wrapping word difference realizes - along primeDec p when the subtrahend
is at most the minuend.