Context for Barrett reduction modulo p, specialized to the small-modulus
regime p < 2^32 where products of residues still fit in one UInt64.
- mkCtx :: (
The modulus is at least
2.The small-modulus bound
p < 2^32, so products of residues fit in one word.- pinv : UInt64
The precomputed reciprocal word
⌊R / p⌋. The reciprocal field is exactly
⌊R / p⌋.- )
Instances For
Build the executable Barrett context for a small UInt64 modulus.
Equations
- BarrettCtx.mk p hp hlt = { p_gt := hp, p_lt := hlt, pinv := UInt64.ofNat (barrettRadix / p.toNat), pinv_eq := ⋯ }
Instances For
Executable Barrett reduction on a single machine word, using the reciprocal
stored in ctx.
Equations
Instances For
The reciprocal stored in a Barrett context is the Nat-level
floor(barrettRadix / p), not just propositionally equal as a UInt64.
The executable Barrett reduction agrees with the Nat-level reduction when the input word is in the small-product range guaranteed by the context hypotheses.
The executable Barrett reducer returns the ordinary Nat remainder for every input in the small-product range guaranteed by the context.
The executable Barrett reducer returns a canonical residue.
Barrett reduction fixes inputs that are already canonical residues.
The executable Barrett reducer agrees with reducing the input word and
re-encoding the canonical residue as a UInt64.