The representative of a modulo m in the interval (-m/2, m/2].
For the degenerate modulus zero, this returns a, matching Int.emod's
zero-modulus convention.
4.2. Symmetric representatives
An integer x with |x| < m / 2 is determined by its residue modulo m: it
is the representative of the residue in the interval (-m/2, m/2]. So
reconstructions in this library return that representative rather than the
usual one in [0, m), and negative answers come out negative.
def
#eval [symMod 17 10, symMod 15 10, symMod (-15) 10]
The uniqueness theorem needs the strict inequality 2 |x| < m. When m is
even, m / 2 and -m / 2 have the same residue, and the interval keeps only
the first of them:
theorem
Hex.Modular.symMod_unique {a x : ℤ} {m : ℕ} (h : 2 * x.natAbs < m) (hx : x % ↑m = a % ↑m) : Hex.Modular.symMod a m = xHex.Modular.symMod_unique {a x : ℤ} {m : ℕ} (h : 2 * x.natAbs < m) (hx : x % ↑m = a % ↑m) : Hex.Modular.symMod a m = x
A strictly-half-bounded integer congruent to a is the unique symmetric
representative. The strict bound excludes the two representatives at an even
tie.