Integers mod n
#
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Definition of the integers mod n, and the field structure on the integers mod p.
Definitions #
val a
is a natural number defined as:
- for
a : zmod 0
it is the absolute value ofa
- for
a : zmod n
with0 < n
it is the least natural number in the equivalence class
See zmod.val_min_abs
for a variant that takes values in the integers.
Cast an integer modulo n
to another semiring.
This function is a morphism if the characteristic of R
divides n
.
See zmod.cast_hom
for a bundled version.
Equations
- zmod.has_coe_t n = {coe := zmod.cast n}
If the characteristic of R
divides n
, then cast
is a homomorphism.
Some specialised simp lemmas which apply when R
has characteristic n
.
The unique ring isomorphism between zmod n
and a ring R
of characteristic n
and cardinality n
.
Equations
- zmod.ring_equiv R h = ring_equiv.of_bijective (zmod.cast_hom _ R) _
The identity between zmod m
and zmod n
when m = n
, as a ring isomorphism.
Equations
- zmod.ring_equiv_congr h = m.cases_on (λ (h : 0 = n), n.cases_on (λ (h : 0 = 0), ring_equiv.refl (zmod 0)) (λ (n : ℕ) (h : 0 = n.succ), false.rec (zmod 0 ≃+* zmod n.succ) _) h) (λ (m : ℕ) (h : m.succ = n), n.cases_on (λ (h : m.succ = 0), false.rec (zmod m.succ ≃+* zmod 0) _) (λ (n : ℕ) (h : m.succ = n.succ), {to_fun := (fin.cast h).to_equiv.to_fun, inv_fun := (fin.cast h).to_equiv.inv_fun, left_inv := _, right_inv := _, map_mul' := _, map_add' := _}) h) h
Equations
- zmod.has_inv n = {inv := zmod.inv n}
The Chinese remainder theorem. For a pair of coprime natural numbers, m
and n
,
the rings zmod (m * n)
and zmod m × zmod n
are isomorphic.
See ideal.quotient_inf_ring_equiv_pi_quotient
for the Chinese remainder theorem for ideals in any
ring.
Equations
- zmod.chinese_remainder h = let to_fun : zmod (m * n) → zmod m × zmod n := ⇑(zmod.cast_hom zmod.chinese_remainder._proof_1 (zmod m × zmod n)), inv_fun : zmod m × zmod n → zmod (m * n) := λ (x : zmod m × zmod n), ite (m * n = 0) (ite (m = 1) ↑(⇑(ring_hom.snd (zmod m) (zmod n)) x) ↑(⇑(ring_hom.fst (zmod m) (zmod n)) x)) ↑(nat.chinese_remainder h x.fst.val x.snd.val) in have inv : function.left_inverse inv_fun to_fun ∧ function.right_inverse inv_fun to_fun, from _, {to_fun := to_fun, inv_fun := inv_fun, left_inv := _, right_inv := _, map_mul' := _, map_add' := _}
Field structure on zmod p
if p
is prime.
Equations
- zmod.field p = {add := comm_ring.add (zmod.comm_ring p), add_assoc := _, zero := comm_ring.zero (zmod.comm_ring p), zero_add := _, add_zero := _, nsmul := comm_ring.nsmul (zmod.comm_ring p), nsmul_zero' := _, nsmul_succ' := _, neg := comm_ring.neg (zmod.comm_ring p), sub := comm_ring.sub (zmod.comm_ring p), sub_eq_add_neg := _, zsmul := comm_ring.zsmul (zmod.comm_ring p), zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, int_cast := comm_ring.int_cast (zmod.comm_ring p), nat_cast := comm_ring.nat_cast (zmod.comm_ring p), one := comm_ring.one (zmod.comm_ring p), nat_cast_zero := _, nat_cast_succ := _, int_cast_of_nat := _, int_cast_neg_succ_of_nat := _, mul := comm_ring.mul (zmod.comm_ring p), mul_assoc := _, one_mul := _, mul_one := _, npow := comm_ring.npow (zmod.comm_ring p), npow_zero' := _, npow_succ' := _, left_distrib := _, right_distrib := _, mul_comm := _, inv := has_inv.inv (zmod.has_inv p), div := division_ring.div._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv, div_eq_mul_inv := _, zpow := division_ring.zpow._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv, zpow_zero' := _, zpow_succ' := _, zpow_neg' := _, exists_pair_ne := _, rat_cast := division_ring.rat_cast._default comm_ring.add _ comm_ring.zero _ _ comm_ring.nsmul _ _ comm_ring.neg comm_ring.sub _ comm_ring.zsmul _ _ _ _ _ comm_ring.int_cast comm_ring.nat_cast comm_ring.one _ _ _ _ comm_ring.mul _ _ _ comm_ring.npow _ _ _ _ has_inv.inv (division_ring.div._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv) _ (division_ring.zpow._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv) _ _ _, mul_inv_cancel := _, inv_zero := _, rat_cast_mk := _, qsmul := division_ring.qsmul._default (… … _ _ _ _ comm_ring.int_cast comm_ring.nat_cast comm_ring.one _ _ _ _ comm_ring.mul _ _ _ comm_ring.npow _ _ _ _ has_inv.inv (division_ring.div._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv) _ (division_ring.zpow._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv) _ _ _) comm_ring.add _ comm_ring.zero _ _ comm_ring.nsmul _ _ comm_ring.neg comm_ring.sub _ comm_ring.zsmul _ _ _ _ _ comm_ring.int_cast comm_ring.nat_cast comm_ring.one _ _ _ _ comm_ring.mul _ _ _ comm_ring.npow _ _ _ _, qsmul_eq_mul' := _}