Integers mod n
#
Definition of the integers mod n, and the field structure on the integers mod p.
Definitions #
Ring structure on fin n
#
We define a commutative ring structure on fin n
, but we do not register it as instance.
Afterwords, when we define zmod n
in terms of fin n
, we use these definitions
to register the ring structure on zmod n
as type class instance.
Multiplicative commutative semigroup structure on fin (n+1)
.
Equations
- fin.comm_semigroup n = {mul := has_mul.mul fin.has_mul, mul_assoc := _, mul_comm := _}
Commutative ring structure on fin (n+1)
.
Equations
- fin.comm_ring n = {add := add_comm_group.add (fin.add_comm_group n), add_assoc := _, zero := add_comm_group.zero (fin.add_comm_group n), zero_add := _, add_zero := _, nsmul := add_comm_group.nsmul (fin.add_comm_group n), nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg (fin.add_comm_group n), sub := add_comm_group.sub (fin.add_comm_group n), sub_eq_add_neg := _, zsmul := add_comm_group.zsmul (fin.add_comm_group n), zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := comm_semigroup.mul (fin.comm_semigroup n), mul_assoc := _, one := 1, one_mul := _, mul_one := _, npow := ring.npow._default 1 comm_semigroup.mul fin.one_mul fin.mul_one, npow_zero' := _, npow_succ' := _, left_distrib := _, right_distrib := _, mul_comm := _}
Equations
- zmod.fintype (n + 1) = fin.fintype (n + 1)
- zmod.fintype 0 = _.elim
Equations
- zmod.decidable_eq (n + 1) = fin.decidable_eq (n.add 0 + 1)
- zmod.decidable_eq 0 = int.decidable_eq
Equations
- zmod.has_repr (n + 1) = fin.has_repr (n.add 0 + 1)
- zmod.has_repr 0 = int.has_repr
Equations
- zmod.comm_ring (n + 1) = fin.comm_ring n
- zmod.comm_ring 0 = int.comm_ring
Equations
- zmod.inhabited n = {default := 0}
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.
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) _
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 := _, mul := comm_ring.mul (zmod.comm_ring p), mul_assoc := _, one := comm_ring.one (zmod.comm_ring p), 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 := div_inv_monoid.div._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv, div_eq_mul_inv := _, zpow := div_inv_monoid.zpow._default comm_ring.mul _ comm_ring.one _ _ comm_ring.npow _ _ has_inv.inv, zpow_zero' := _, zpow_succ' := _, zpow_neg' := _, exists_pair_ne := _, mul_inv_cancel := _, inv_zero := _}
The map from zmod n
induced by f : ℤ →+ A
that maps n
to 0
.