The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.ZMod.Basic

214 declarations. Mathlib docs · Source

Integers mod n

Definition of the integers mod n, and the field structure on the integers mod p.

Definitions

  • ZMod n, which is for integers modulo a nat n : ℕ

  • val a is defined as a natural number:

    • for a : ZMod 0 it is the absolute value of a
    • for a : ZMod n with 0 < n it is the least natural number in the equivalence class
  • A coercion cast is defined from ZMod n into any ring. This is a ring hom if the ring has characteristic dividing n

If the characteristic of R divides n, then cast is a homomorphism.

Some specialised simp lemmas which apply when R has characteristic n.

Groups of bounded torsion

For G a group and n a natural number, G having torsion dividing n (∀ x : G, n • x = 0) can be derived from Module R G where R has characteristic dividing n.

It is however painful to have the API for such groups G stated in this generality, as R does not appear anywhere in the lemmas' return type. Instead of writing the API in terms of a general R, we therefore specialise to the canonical ring of order n, namely ZMod n.

This spelling Module (ZMod n) G has the extra advantage of providing the canonical action by ZMod n. It is however Type-valued, so we might want to acquire a Prop-valued version in the future.

theorem ZMod.val.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n : ℕ),
  x = n.succ →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_2 n

theorem ZMod.unitOfCoprime.congr_simp E1 #

∀ {n : ℕ} (x x_1 : ℕ) (e_x : x = x_1) (h : x.Coprime n), ZMod.unitOfCoprime x h = ZMod.unitOfCoprime x_1 ⋯

theorem ZMod.val.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
  x = 0 →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_1 ()

theorem ZMod.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
  x = 0 →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_1 ()

theorem ZMod.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n : ℕ),
  x = n.succ →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_2 n

instance ZMod.instIsDomainOfNatNat E0 #

IsDomain (ZMod 0)

def ZMod.finEquiv E1 #

(n : ℕ) → [NeZero n] → Fin n ≃+* ZMod n

For non-zero n : ℕ, the ring Fin n is equivalent to ZMod n.

instance ZMod.charZero E0 #

CharZero (ZMod 0)

def ZMod.val E1 #

{n : ℕ} → ZMod n → ℕ

val a is a natural number defined as:

  • for a : ZMod 0 it is the absolute value of a
  • for a : ZMod n with 0 < n it is the least natural number in the equivalence class

See ZMod.valMinAbs for a variant that takes values in the integers.

theorem ZMod.val_lt E0 #

∀ {n : ℕ} [NeZero n] (a : ZMod n), a.val < n

theorem ZMod.val_le E0 #

∀ {n : ℕ} [NeZero n] (a : ZMod n), a.val ≤ n

theorem ZMod.val_zero E0 #

∀ {n : ℕ}, ZMod.val 0 = 0

theorem ZMod.val_one' E0 #

ZMod.val 1 = 1

theorem ZMod.val_neg' E0 #

∀ {n : ZMod 0}, (-n).val = n.val

theorem ZMod.val_mul' E0 #

∀ {m n : ZMod 0}, (m * n).val = m.val * n.val

theorem ZMod.val_natCast E0 #

∀ (n a : ℕ), (↑a).val = a % n

theorem ZMod.val_natCast_of_lt E0 #

∀ {n a : ℕ}, a < n → (↑a).val = a

theorem ZMod.val_ofNat E0 #

∀ (n a : ℕ) [inst : a.AtLeastTwo], (OfNat.ofNat a).val = OfNat.ofNat a % n

theorem ZMod.val_ofNat_of_lt E0 #

∀ {n a : ℕ} [inst : a.AtLeastTwo], a < n → (OfNat.ofNat a).val = OfNat.ofNat a

theorem ZMod.val_unit' E0 #

∀ {n : ZMod 0}, IsUnit n ↔ n.val = 1

instance ZMod.charP E0 #

∀ (n : ℕ), CharP (ZMod n) n

theorem ZMod.addOrderOf_one E0 #

∀ (n : ℕ), addOrderOf 1 = n

theorem ZMod.addOrderOf_coe E0 #

∀ (a : ℕ) {n : ℕ}, n ≠ 0 → addOrderOf ↑a = n / n.gcd a

This lemma works in the case in which ZMod n is not infinite, i.e. n ≠ 0. The version where a ≠ 0 is addOrderOf_coe'.

theorem ZMod.addOrderOf_coe' E0 #

∀ {a : ℕ} (n : ℕ), a ≠ 0 → addOrderOf ↑a = n / n.gcd a

This lemma works in the case in which a ≠ 0. The version where ZMod n is not infinite, i.e. n ≠ 0, is addOrderOf_coe.

theorem ZMod.ringChar_zmod_n E1 #

∀ (n : ℕ), ringChar (ZMod n) = n

We have that ringChar (ZMod n) = n.

theorem ZMod.natCast_self E1 #

∀ (n : ℕ), ↑n = 0

theorem ZMod.natCast_self' E0 #

∀ (n : ℕ), ↑n + 1 = 0

theorem ZMod.natCast_pow_eq_zero_of_le E1 #

∀ (p : ℕ) {m n : ℕ}, n ≤ m → ↑p ^ m = 0

def ZMod.cast E1 #

{R : Type u_1} → [AddGroupWithOne R] → {n : ℕ} → ZMod n → R

Cast an integer modulo n to another semiring. This function is a morphism if the characteristic of R divides n. See ZMod.castHom for a bundled version.

theorem ZMod.cast_zero E0 #

∀ {n : ℕ} {R : Type u_1} [inst : AddGroupWithOne R], ZMod.cast 0 = 0

theorem ZMod.cast_eq_val E0 #

∀ {n : ℕ} {R : Type u_1} [inst : AddGroupWithOne R] [NeZero n] (a : ZMod n), a.cast = ↑a.val

theorem Prod.fst_zmod_cast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : AddGroupWithOne R] {S : Type u_2} [inst_1 : AddGroupWithOne S] (a : ZMod n),
  a.cast.1 = a.cast

theorem Prod.snd_zmod_cast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : AddGroupWithOne R] {S : Type u_2} [inst_1 : AddGroupWithOne S] (a : ZMod n),
  a.cast.2 = a.cast

theorem ZMod.natCast_zmod_val E0 #

∀ {n : ℕ} [NeZero n] (a : ZMod n), ↑a.val = a

So-named because the coercion is Nat.cast into ZMod. For Nat.cast into an arbitrary ring, see ZMod.natCast_val.

theorem ZMod.natCast_rightInverse E1 #

∀ {n : ℕ} [NeZero n], Function.RightInverse ZMod.val Nat.cast

theorem ZMod.natCast_zmod_surjective E1 #

∀ {n : ℕ} [NeZero n], Function.Surjective Nat.cast

theorem ZMod.intCast_zmod_cast E1 #

∀ {n : ℕ} (a : ZMod n), ↑a.cast = a

So-named because the outer coercion is Int.cast into ZMod. For Int.cast into an arbitrary ring, see ZMod.intCast_cast.

theorem ZMod.intCast_rightInverse E1 #

∀ {n : ℕ}, Function.RightInverse ZMod.cast Int.cast

theorem ZMod.intCast_surjective E1 #

∀ {n : ℕ}, Function.Surjective Int.cast

theorem ZMod.forall E1 #

∀ {n : ℕ} {P : ZMod n → Prop}, (∀ (x : ZMod n), P x) ↔ ∀ (x : ℤ), P ↑x

theorem ZMod.exists E1 #

∀ {n : ℕ} {P : ZMod n → Prop}, (∃ x, P x) ↔ ∃ x, P ↑x

theorem ZMod.cast_id E1 #

∀ (n : ℕ) (i : ZMod n), i.cast = i

theorem ZMod.cast_id' E0 #

∀ {n : ℕ}, ZMod.cast = id

theorem ZMod.natCast_comp_val E0 #

∀ {n : ℕ} (R : Type u_1) [inst : Ring R] [NeZero n], Nat.cast ∘ ZMod.val = ZMod.cast

The coercions are respectively Nat.cast and ZMod.cast.

theorem ZMod.intCast_comp_cast E0 #

∀ {n : ℕ} (R : Type u_1) [inst : Ring R], Int.cast ∘ ZMod.cast = ZMod.cast

The coercions are respectively Int.cast, ZMod.cast, and ZMod.cast.

theorem ZMod.natCast_val E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [NeZero n] (i : ZMod n), ↑i.val = i.cast

theorem ZMod.intCast_cast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] (i : ZMod n), ↑i.cast = i.cast

theorem ZMod.cast_add_eq_ite E1 #

∀ {n : ℕ} (a b : ZMod n), (a + b).cast = if ↑n ≤ a.cast + b.cast then a.cast + b.cast - ↑n else a.cast + b.cast

theorem ZMod.cast_one E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ZMod.cast 1 = 1

theorem ZMod.cast_add E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (a b : ZMod n), (a + b).cast = a.cast + b.cast

theorem ZMod.cast_mul E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (a b : ZMod n), (a * b).cast = a.cast * b.cast

def ZMod.castHom E1 #

{n m : ℕ} → m ∣ n → (R : Type u_2) → [inst : Ring R] → [CharP R m] → ZMod n →+* R

The canonical ring homomorphism from ZMod n to a ring of characteristic dividing n.

See also ZMod.lift for a generalized version working in AddGroups.

theorem ZMod.castHom_apply E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [inst_1 : CharP R m] {h : m ∣ n} (i : ZMod n),
  (ZMod.castHom h R) i = i.cast

theorem ZMod.cast_sub E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (a b : ZMod n), (a - b).cast = a.cast - b.cast

theorem ZMod.cast_neg E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (a : ZMod n), (-a).cast = -a.cast

theorem ZMod.cast_pow E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (a : ZMod n) (k : ℕ), (a ^ k).cast = a.cast ^ k

theorem ZMod.cast_natCast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (k : ℕ), (↑k).cast = ↑k

theorem ZMod.cast_intCast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] {m : ℕ} [CharP R m], m ∣ n → ∀ (k : ℤ), (↑k).cast = ↑k

theorem ZMod.castHom_surjective E1 #

∀ {n m : ℕ} (h : m ∣ n), Function.Surjective ⇑(ZMod.castHom h (ZMod m))

theorem ZMod.cast_one' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n], ZMod.cast 1 = 1

theorem ZMod.cast_add' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (a b : ZMod n), (a + b).cast = a.cast + b.cast

theorem ZMod.cast_mul' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (a b : ZMod n), (a * b).cast = a.cast * b.cast

theorem ZMod.cast_sub' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (a b : ZMod n), (a - b).cast = a.cast - b.cast

theorem ZMod.cast_pow' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (a : ZMod n) (k : ℕ), (a ^ k).cast = a.cast ^ k

theorem ZMod.cast_natCast' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (k : ℕ), (↑k).cast = ↑k

theorem ZMod.cast_intCast' E1 #

∀ {n : ℕ} {R : Type u_1} [inst : Ring R] [CharP R n] (k : ℤ), (↑k).cast = ↑k

theorem ZMod.castHom_injective E1 #

∀ {n : ℕ} (R : Type u_1) [inst : Ring R] [inst_1 : CharP R n], Function.Injective ⇑(ZMod.castHom ⋯ R)

theorem ZMod.castHom_bijective E1 #

∀ {n : ℕ} (R : Type u_1) [inst : Ring R] [inst_1 : CharP R n] [inst_2 : Fintype R],
  Fintype.card R = n → Function.Bijective ⇑(ZMod.castHom ⋯ R)

def ZMod.ringEquiv E1 #

{n : ℕ} → (R : Type u_1) → [inst : Ring R] → [CharP R n] → [inst_2 : Fintype R] → Fintype.card R = n → ZMod n ≃+* R

The unique ring isomorphism between ZMod n and a ring R of characteristic n and cardinality n.

def ZMod.ringEquivOfPrime E1 #

(R : Type u_1) → [inst : Ring R] → [inst_1 : Fintype R] → {p : ℕ} → Nat.Prime p → Fintype.card R = p → ZMod p ≃+* R

The unique ring isomorphism between ZMod p and a ring R of cardinality a prime p.

If you need any property of this isomorphism, first of all use ringEquivOfPrime_eq_ringEquiv below (after have : CharP R p := ...) and deduce it by the results about ZMod.ringEquiv.

theorem ZMod.ringEquivOfPrime_eq_ringEquiv E0 #

∀ (R : Type u_1) [inst : Ring R] [inst_1 : Fintype R] {p : ℕ} [inst_2 : CharP R p] (hp : Nat.Prime p)
  (hR : Fintype.card R = p), ZMod.ringEquivOfPrime R hp hR = ZMod.ringEquiv R hR

def ZMod.ringEquivCongr E1 #

{m n : ℕ} → m = n → ZMod m ≃+* ZMod n

The identity between ZMod m and ZMod n when m = n, as a ring isomorphism.

theorem ZMod.ringEquivCongr_refl E0 #

∀ (a : ℕ), ZMod.ringEquivCongr ⋯ = RingEquiv.refl (ZMod a)

theorem ZMod.ringEquivCongr_refl_apply E0 #

∀ {a : ℕ} (x : ZMod a), (ZMod.ringEquivCongr ⋯) x = x

theorem ZMod.ringEquivCongr_symm E1 #

∀ {a b : ℕ} (hab : a = b), (ZMod.ringEquivCongr hab).symm = ZMod.ringEquivCongr ⋯

theorem ZMod.ringEquivCongr_trans E1 #

∀ {a b c : ℕ} (hab : a = b) (hbc : b = c),
  (ZMod.ringEquivCongr hab).trans (ZMod.ringEquivCongr hbc) = ZMod.ringEquivCongr ⋯

theorem ZMod.ringEquivCongr_ringEquivCongr_apply E0 #

∀ {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a),
  (ZMod.ringEquivCongr hbc) ((ZMod.ringEquivCongr hab) x) = (ZMod.ringEquivCongr ⋯) x

theorem ZMod.ringEquivCongr_val E0 #

∀ {a b : ℕ} (h : a = b) (x : ZMod a), ((ZMod.ringEquivCongr h) x).val = x.val

theorem ZMod.ringEquivCongr_intCast E1 #

∀ {a b : ℕ} (h : a = b) (z : ℤ), (ZMod.ringEquivCongr h) ↑z = ↑z

theorem ZMod.val_eq_zero E0 #

∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0

theorem ZMod.intCast_eq_intCast_iff E0 #

∀ (a b : ℤ) (c : ℕ), ↑a = ↑b ↔ a ≡ b [ZMOD ↑c]

theorem ZMod.intCast_eq_intCast_iff' E1 #

∀ (a b : ℤ) (c : ℕ), ↑a = ↑b ↔ a % ↑c = b % ↑c

theorem ZMod.val_intCast E0 #

∀ {n : ℕ} (a : ℤ) [NeZero n], ↑(↑a).val = a % ↑n

theorem ZMod.natCast_eq_natCast_iff E0 #

∀ (a b c : ℕ), ↑a = ↑b ↔ a ≡ b [MOD c]

theorem ZMod.natCast_eq_natCast_iff' E1 #

∀ (a b c : ℕ), ↑a = ↑b ↔ a % c = b % c

theorem ZMod.intCast_zmod_eq_zero_iff_dvd E1 #

∀ (a : ℤ) (b : ℕ), ↑a = 0 ↔ ↑b ∣ a

theorem ZMod.intCast_eq_intCast_iff_dvd_sub E1 #

∀ (a b : ℤ) (c : ℕ), ↑a = ↑b ↔ ↑c ∣ b - a

theorem ZMod.natCast_eq_zero_iff E0 #

∀ (a b : ℕ), ↑a = 0 ↔ b ∣ a

theorem ZMod.neg_one_eq_one_iff E0 #

∀ {n : ℕ}, -1 = 1 ↔ n = 1 ∨ n = 2

theorem ZMod.coe_intCast E0 #

∀ {n : ℕ} (a : ℤ), (↑a).cast = a % ↑n

theorem ZMod.intCast_cast_add E1 #

∀ {n : ℕ} (x y : ZMod n), (x + y).cast = (x.cast + y.cast) % ↑n

theorem ZMod.intCast_cast_mul E1 #

∀ {n : ℕ} (x y : ZMod n), (x * y).cast = x.cast * y.cast % ↑n

theorem ZMod.intCast_cast_sub E1 #

∀ {n : ℕ} (x y : ZMod n), (x - y).cast = (x.cast - y.cast) % ↑n

theorem ZMod.intCast_cast_neg E1 #

∀ {n : ℕ} (x : ZMod n), (-x).cast = -x.cast % ↑n

theorem ZMod.val_neg_one E0 #

∀ (n : ℕ), (-1).val = n

theorem ZMod.cast_neg_one E1 #

∀ {R : Type u_1} [inst : Ring R] (n : ℕ), (-1).cast = ↑n - 1

-1 : ZMod n lifts to n - 1 : R. This avoids the characteristic assumption in cast_neg.

theorem ZMod.cast_sub_one E1 #

∀ {R : Type u_1} [inst : Ring R] {n : ℕ} (k : ZMod n), (k - 1).cast = (if k = 0 then ↑n else k.cast) - 1

theorem ZMod.natCast_eq_iff E0 #

∀ (p n : ℕ) (z : ZMod p) [NeZero p], ↑n = z ↔ ∃ k, n = z.val + p * k

theorem ZMod.intCast_eq_iff E0 #

∀ (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p], ↑n = z ↔ ∃ k, n = ↑z.val + ↑p * k

theorem ZMod.intCast_mod E0 #

∀ (a : ℤ) (b : ℕ), ↑(a % ↑b) = ↑a

theorem ZMod.ker_intCastAddHom E1 #

∀ (n : ℕ), (Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples ↑n

theorem ZMod.cast_injective_of_le E1 #

∀ {m n : ℕ} [nzm : NeZero m], m ≤ n → Function.Injective ZMod.cast

theorem ZMod.cast_zmod_eq_zero_iff_of_le E1 #

∀ {m n : ℕ} [NeZero m], m ≤ n → ∀ (a : ZMod m), a.cast = 0 ↔ a = 0

theorem ZMod.natCast_toNat E0 #

∀ (p : ℕ) {z : ℤ}, 0 ≤ z → ↑z.toNat = ↑z

theorem ZMod.val_injective E0 #

∀ (n : ℕ) [NeZero n], Function.Injective ZMod.val

theorem ZMod.val_one_eq_one_mod E0 #

∀ (n : ℕ), ZMod.val 1 = 1 % n

theorem ZMod.val_two_eq_two_mod E0 #

∀ (n : ℕ), ZMod.val 2 = 2 % n

theorem ZMod.val_one E0 #

∀ (n : ℕ) [Fact (1 < n)], ZMod.val 1 = 1

theorem ZMod.val_one'' E0 #

∀ {n : ℕ}, n ≠ 1 → ZMod.val 1 = 1

theorem ZMod.val_add E0 #

∀ {n : ℕ} [NeZero n] (a b : ZMod n), (a + b).val = (a.val + b.val) % n

theorem ZMod.val_add_of_lt E0 #

∀ {n : ℕ} {a b : ZMod n}, a.val + b.val < n → (a + b).val = a.val + b.val

theorem ZMod.val_add_val_of_le E0 #

∀ {n : ℕ} [NeZero n] {a b : ZMod n}, n ≤ a.val + b.val → a.val + b.val = (a + b).val + n

theorem ZMod.val_add_of_le E0 #

∀ {n : ℕ} [NeZero n] {a b : ZMod n}, n ≤ a.val + b.val → (a + b).val = a.val + b.val - n

theorem ZMod.val_add_le E0 #

∀ {n : ℕ} (a b : ZMod n), (a + b).val ≤ a.val + b.val

theorem ZMod.val_mul E0 #

∀ {n : ℕ} (a b : ZMod n), (a * b).val = a.val * b.val % n

theorem ZMod.val_mul_le E0 #

∀ {n : ℕ} (a b : ZMod n), (a * b).val ≤ a.val * b.val

theorem ZMod.val_mul_of_lt E0 #

∀ {n : ℕ} {a b : ZMod n}, a.val * b.val < n → (a * b).val = a.val * b.val

theorem ZMod.val_mul_iff_lt E0 #

∀ {n : ℕ} [NeZero n] (a b : ZMod n), (a * b).val = a.val * b.val ↔ a.val * b.val < n

instance ZMod.nontrivial E0 #

∀ (n : ℕ) [Fact (1 < n)], Nontrivial (ZMod n)

instance ZMod.nontrivial' E0 #

Nontrivial (ZMod 0)

theorem ZMod.one_eq_zero_iff E0 #

∀ {n : ℕ}, 1 = 0 ↔ n = 1

def ZMod.inv E1 #

(n : ℕ) → ZMod n → ZMod n

The inversion on ZMod n. It is setup in such a way that a * a⁻¹ is equal to gcd a.val n. In particular, if a is coprime to n, and hence a unit, a * a⁻¹ = 1.

instance ZMod.instInv E0 #

(n : ℕ) → Inv (ZMod n)

theorem ZMod.inv_zero E1 #

∀ (n : ℕ), 0⁻¹ = 0

theorem ZMod.mul_inv_eq_gcd E1 #

∀ {n : ℕ} (a : ZMod n), a * a⁻¹ = ↑(a.val.gcd n)

theorem ZMod.inv_one E0 #

∀ (n : ℕ), 1⁻¹ = 1

theorem ZMod.natCast_mod E0 #

∀ (a n : ℕ), ↑(a % n) = ↑a

theorem ZMod.intCast_eq_zero_iff_even E1 #

∀ {n : ℤ}, ↑n = 0 ↔ Even n

theorem Even.intCast_zmod_two E1 #

∀ {n : ℤ}, Even n → ↑n = 0

Alias of the reverse direction of ZMod.intCast_eq_zero_iff_even.

theorem ZMod.natCast_eq_zero_iff_even E1 #

∀ {n : ℕ}, ↑n = 0 ↔ Even n

theorem Even.natCast_zmod_two E1 #

∀ {n : ℕ}, Even n → ↑n = 0

Alias of the reverse direction of ZMod.natCast_eq_zero_iff_even.

theorem ZMod.intCast_eq_one_iff_odd E1 #

∀ {n : ℤ}, ↑n = 1 ↔ Odd n

theorem Odd.intCast_zmod_two E1 #

∀ {n : ℤ}, Odd n → ↑n = 1

Alias of the reverse direction of ZMod.intCast_eq_one_iff_odd.

theorem ZMod.natCast_eq_one_iff_odd E1 #

∀ {n : ℕ}, ↑n = 1 ↔ Odd n

theorem Odd.natCast_zmod_two E1 #

∀ {n : ℕ}, Odd n → ↑n = 1

Alias of the reverse direction of ZMod.natCast_eq_one_iff_odd.

theorem ZMod.natCast_ne_zero_iff_odd E1 #

∀ {n : ℕ}, ↑n ≠ 0 ↔ Odd n

theorem ZMod.coe_mul_inv_eq_one E0 #

∀ {n : ℕ} (x : ℕ), x.Coprime n → ↑x * (↑x)⁻¹ = 1

theorem ZMod.mul_val_inv E1 #

∀ {m n : ℕ}, m.Coprime n → ↑m * ↑(↑m)⁻¹.val = 1

theorem ZMod.val_inv_mul E0 #

∀ {m n : ℕ}, m.Coprime n → ↑(↑m)⁻¹.val * ↑m = 1

def ZMod.unitOfCoprime E3 #

{n : ℕ} → (x : ℕ) → x.Coprime n → (ZMod n)ˣ

unitOfCoprime makes an element of (ZMod n)ˣ given a natural number x and a proof that x is coprime to n

theorem ZMod.coe_unitOfCoprime E0 #

∀ {n : ℕ} (x : ℕ) (h : x.Coprime n), ↑(ZMod.unitOfCoprime x h) = ↑x

theorem ZMod.val_coe_unit_coprime E0 #

∀ {n : ℕ} (u : (ZMod n)ˣ), (↑u).val.Coprime n

theorem ZMod.isUnit_iff_coprime E1 #

∀ (m n : ℕ), IsUnit ↑m ↔ m.Coprime n

theorem ZMod.coprime_mod_iff_coprime E0 #

∀ (m n : ℕ), (m % n).Coprime n ↔ m.Coprime n

theorem ZMod.isUnit_prime_iff_not_dvd E1 #

∀ {n p : ℕ}, Nat.Prime p → (IsUnit ↑p ↔ ¬p ∣ n)

theorem ZMod.isUnit_prime_of_not_dvd E1 #

∀ {n p : ℕ}, Nat.Prime p → ¬p ∣ n → IsUnit ↑p

theorem ZMod.isUnit_natCast_iff_not_dvd_pow E1 #

∀ {p d a : ℕ}, Nat.Prime p → 0 < d → (IsUnit ↑a ↔ ¬p ∣ a)

In ZMod (p ^ d) with 0 < d, a natural number is a unit iff p does not divide it.

theorem ZMod.prime_natCast_not_isUnit_pow E1 #

∀ {p d : ℕ}, Nat.Prime p → 0 < d → ¬IsUnit ↑p

In ZMod (p ^ d) with 0 < d, the prime p is not a unit.

theorem ZMod.inv_coe_unit E0 #

∀ {n : ℕ} (u : (ZMod n)ˣ), (↑u)⁻¹ = ↑u⁻¹

theorem ZMod.mul_inv_of_unit E1 #

∀ {n : ℕ} (a : ZMod n), IsUnit a → a * a⁻¹ = 1

theorem ZMod.inv_mul_of_unit E1 #

∀ {n : ℕ} (a : ZMod n), IsUnit a → a⁻¹ * a = 1

theorem ZMod.inv_eq_of_mul_eq_one E1 #

∀ (n : ℕ) (a b : ZMod n), a * b = 1 → a⁻¹ = b

theorem ZMod.inv_neg_one E0 #

∀ (n : ℕ), (-1)⁻¹ = -1

theorem ZMod.inv_mul_eq_one_of_isUnit E1 #

∀ {n : ℕ} {a : ZMod n}, IsUnit a → ∀ (b : ZMod n), a⁻¹ * b = 1 ↔ a = b

def ZMod.unitsEquivCoprime E1 #

{n : ℕ} → [NeZero n] → (ZMod n)ˣ ≃ { x // x.val.Coprime n }

Equivalence between the units of ZMod n and the subtype of terms x : ZMod n for which x.val is coprime to n

def ZMod.chineseRemainder E3 #

{m n : ℕ} → m.Coprime n → ZMod (m * n) ≃+* ZMod m × ZMod 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.quotientInfRingEquivPiQuotient for the Chinese remainder theorem for ideals in any ring.

theorem ZMod.subsingleton_iff E0 #

∀ {n : ℕ}, Subsingleton (ZMod n) ↔ n = 1

theorem ZMod.nontrivial_iff E0 #

∀ {n : ℕ}, Nontrivial (ZMod n) ↔ n ≠ 1

instance ZMod.instUniqueUnitsOfNatNat E0 #

Unique (ZMod 2)ˣ

theorem ZMod.add_self_eq_zero_iff_eq_zero E0 #

∀ {n : ℕ}, Odd n → ∀ {a : ZMod n}, a + a = 0 ↔ a = 0

theorem ZMod.ne_neg_self E1 #

∀ {n : ℕ}, Odd n → ∀ {a : ZMod n}, a ≠ 0 → a ≠ -a

theorem ZMod.neg_one_ne_one E1 #

∀ {n : ℕ} [Fact (2 < n)], -1 ≠ 1

theorem ZMod.neg_eq_self_mod_two E0 #

∀ (a : ZMod 2), -a = a

theorem ZMod.intCast_abs_mod_two E0 #

∀ (a : ℤ), ↑|a| = ↑a

theorem ZMod.natAbs_mod_two E1 #

∀ (a : ℤ), ↑a.natAbs = ↑a

theorem ZMod.val_ne_zero E0 #

∀ {n : ℕ} (a : ZMod n), a.val ≠ 0 ↔ a ≠ 0

theorem ZMod.val_pos E0 #

∀ {n : ℕ} {a : ZMod n}, 0 < a.val ↔ a ≠ 0

theorem ZMod.val_eq_one E0 #

∀ {n : ℕ}, 1 < n → ∀ (a : ZMod n), a.val = 1 ↔ a = 1

theorem ZMod.neg_eq_self_iff E0 #

∀ {n : ℕ} (a : ZMod n), -a = a ↔ a = 0 ∨ 2 * a.val = n

theorem ZMod.val_cast_of_lt E0 #

∀ {n a : ℕ}, a < n → (↑a).val = a

theorem ZMod.val_cast_zmod_lt E0 #

∀ {m : ℕ} [NeZero m] (n : ℕ) [NeZero n] (a : ZMod m), a.cast.val < m

theorem ZMod.neg_val' E1 #

∀ {n : ℕ} [NeZero n] (a : ZMod n), (-a).val = (n - a.val) % n

theorem ZMod.neg_val E0 #

∀ {n : ℕ} [NeZero n] (a : ZMod n), (-a).val = if a = 0 then 0 else n - a.val

theorem ZMod.val_neg_of_ne_zero E0 #

∀ {n : ℕ} [nz : NeZero n] (a : ZMod n) [na : NeZero a], (-a).val = n - a.val

theorem ZMod.val_sub E0 #

∀ {n : ℕ} [NeZero n] {a b : ZMod n}, b.val ≤ a.val → (a - b).val = a.val - b.val

theorem ZMod.val_cast_eq_val_of_lt E0 #

∀ {m n : ℕ} [nzm : NeZero m] {a : ZMod m}, a.val < n → a.cast.val = a.val

theorem ZMod.cast_cast_zmod_of_le E1 #

∀ {m n : ℕ} [hm : NeZero m], m ≤ n → ∀ (a : ZMod m), a.cast.cast = a

theorem ZMod.val_pow E0 #

∀ {m n : ℕ} {a : ZMod n} [ilt : Fact (1 < n)], a.val ^ m < n → (a ^ m).val = a.val ^ m

theorem ZMod.val_pow_le E0 #

∀ {m n : ℕ} [Fact (1 < n)] {a : ZMod n}, (a ^ m).val ≤ a.val ^ m

theorem ZMod.natAbs_min_of_le_div_two E1 #

∀ (n : ℕ) (x y : ℤ), ↑x = ↑y → x.natAbs ≤ n / 2 → x.natAbs ≤ y.natAbs

theorem RingHom.ext_zmod E1 #

∀ {n : ℕ} {R : Type u_1} [inst : NonAssocSemiring R] (f g : ZMod n →+* R), f = g

instance ZMod.subsingleton_ringHom E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Semiring R], Subsingleton (ZMod n →+* R)

instance ZMod.subsingleton_ringEquiv E0 #

∀ {n : ℕ} {R : Type u_1} [inst : Semiring R], Subsingleton (ZMod n ≃+* R)

theorem ZMod.ringHom_map_cast E0 #

∀ {n : ℕ} {R : Type u_1} [inst : NonAssocRing R] (f : R →+* ZMod n) (k : ZMod n), f k.cast = k

theorem ZMod.ringHom_rightInverse E1 #

∀ {n : ℕ} {R : Type u_1} [inst : NonAssocRing R] (f : R →+* ZMod n), Function.RightInverse ZMod.cast ⇑f

Any ring homomorphism into ZMod n has a right inverse.

theorem ZMod.ringHom_surjective E1 #

∀ {n : ℕ} {R : Type u_1} [inst : NonAssocRing R] (f : R →+* ZMod n), Function.Surjective ⇑f

Any ring homomorphism into ZMod n is surjective.

theorem ZMod.castHom_self E0 #

∀ {n : ℕ}, ZMod.castHom ⋯ (ZMod n) = RingHom.id (ZMod n)

theorem ZMod.castHom_comp E0 #

∀ {n m d : ℕ} (hm : n ∣ m) (hd : m ∣ d),
  (ZMod.castHom hm (ZMod n)).comp (ZMod.castHom hd (ZMod m)) = ZMod.castHom ⋯ (ZMod n)

def ZMod.lift E1 #

(n : ℕ) → {A : Type u_2} → [inst : AddGroup A] → { f // f ↑n = 0 } ≃ (ZMod n →+ A)

The map from ZMod n induced by f : ℤ →+ A that maps n to 0.

theorem ZMod.lift_coe E0 #

∀ (n : ℕ) {A : Type u_2} [inst : AddGroup A] (f : { f // f ↑n = 0 }) (x : ℤ), ((ZMod.lift n) f) ↑x = ↑f x

theorem ZMod.lift_castAddHom E1 #

∀ (n : ℕ) {A : Type u_2} [inst : AddGroup A] (f : { f // f ↑n = 0 }) (x : ℤ),
  ((ZMod.lift n) f) ((Int.castAddHom (ZMod n)) x) = ↑f x

theorem ZMod.lift_comp_coe E0 #

∀ (n : ℕ) {A : Type u_2} [inst : AddGroup A] (f : { f // f ↑n = 0 }), ⇑((ZMod.lift n) f) ∘ Int.cast = ⇑↑f

theorem ZMod.lift_comp_castAddHom E0 #

∀ (n : ℕ) {A : Type u_2} [inst : AddGroup A] (f : { f // f ↑n = 0 }),
  ((ZMod.lift n) f).comp (Int.castAddHom (ZMod n)) = ↑f

theorem ZMod.lift_injective E1 #

∀ (n : ℕ) {A : Type u_2} [inst : AddGroup A] {f : { f // f ↑n = 0 }},
  Function.Injective ⇑((ZMod.lift n) f) ↔ ∀ (m : ℤ), ↑f m = 0 → ↑m = 0

theorem zmod_smul_mem E1 #

∀ {n : ℕ} {S : Type u_1} {G : Type u_2} [inst : AddCommGroup G] [inst_1 : SetLike S G] [AddSubgroupClass S G] {K : S}
  [inst_3 : Module (ZMod n) G] {x : G}, x ∈ K → ∀ (a : ZMod n), a • x ∈ K

theorem smulMemClass E1 #

∀ {n : ℕ} {S : Type u_1} {G : Type u_2} [inst : AddCommGroup G] [inst_1 : SetLike S G] [AddSubgroupClass S G]
  [inst_3 : Module (ZMod n) G], SMulMemClass S (ZMod n) G

This cannot be made an instance because of the [Module (ZMod n) G] argument and the fact that n only appears in the second argument of SMulMemClass, which is an OutParam.

instance AddSubgroupClass.instZModSMul E0 #

{n : ℕ} →
  {S : Type u_1} →
    {G : Type u_2} →
      [inst : AddCommGroup G] →
        [inst_1 : SetLike S G] → [AddSubgroupClass S G] → {K : S} → [Module (ZMod n) G] → SMul (ZMod n) ↥K

theorem AddSubgroupClass.coe_zmod_smul E0 #

∀ {n : ℕ} {S : Type u_1} {G : Type u_2} [inst : AddCommGroup G] [inst_1 : SetLike S G] [inst_2 : AddSubgroupClass S G]
  {K : S} [inst_3 : Module (ZMod n) G] (a : ZMod n) (x : ↥K), ↑(a • x) = a • ↑x

instance AddSubgroupClass.instZModModule E0 #

{n : ℕ} →
  {S : Type u_1} →
    {G : Type u_2} →
      [inst : AddCommGroup G] →
        [inst_1 : SetLike S G] → [inst_2 : AddSubgroupClass S G] → {K : S} → [Module (ZMod n) G] → Module (ZMod n) ↥K

theorem ZModModule.char_nsmul_eq_zero E1 #

∀ (n : ℕ) {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod n) G] (x : G), n • x = 0

theorem ZModModule.char_ne_one E1 #

∀ (n : ℕ) (G : Type u_2) [inst : AddCommGroup G] [Module (ZMod n) G] [Nontrivial G], n ≠ 1

theorem ZModModule.two_le_char E1 #

∀ (n : ℕ) (G : Type u_2) [inst : AddCommGroup G] [Module (ZMod n) G] [NeZero n] [Nontrivial G], 2 ≤ n

theorem ZModModule.periodicPts_add_left E1 #

∀ (n : ℕ) {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod n) G] [NeZero n] (x : G),
  (Function.periodicPts fun x_1 ↦ x + x_1) = Set.univ

theorem ZModModule.add_self E1 #

∀ {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod 2) G] (x : G), x + x = 0

theorem ZModModule.neg_eq_self E1 #

∀ {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod 2) G] (x : G), -x = x

theorem ZModModule.sub_eq_add E1 #

∀ {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod 2) G] (x y : G), x - y = x + y

theorem ZModModule.add_add_add_cancel E1 #

∀ {G : Type u_2} [inst : AddCommGroup G] [Module (ZMod 2) G] (x y z : G), x + y + (y + z) = x + z

theorem pow_zmod_val_inv_pow E0 #

∀ {α : Type u_1} [inst : Group α] {n : ℕ}, (Nat.card α).gcd n = 1 → ∀ (a : α), (a ^ (↑n)⁻¹.val) ^ n = a

theorem nsmul_zmod_val_inv_nsmul E0 #

∀ {α : Type u_1} [inst : AddGroup α] {n : ℕ}, (Nat.card α).gcd n = 1 → ∀ (a : α), n • (↑n)⁻¹.val • a = a

theorem zmod_val_inv_nsmul_nsmul E0 #

∀ {α : Type u_1} [inst : AddGroup α] {n : ℕ}, (Nat.card α).gcd n = 1 → ∀ (a : α), (↑n)⁻¹.val • n • a = a

theorem pow_pow_zmod_val_inv E0 #

∀ {α : Type u_1} [inst : Group α] {n : ℕ}, (Nat.card α).gcd n = 1 → ∀ (a : α), (a ^ n) ^ (↑n)⁻¹.val = a

theorem Nat.range_mul_add E1 #

∀ (m k : ℕ), (Set.range fun n ↦ m * n + k) = {n | ↑n = ↑k ∧ k ≤ n}

The range of (m * · + k) on natural numbers is the set of elements ≥ k in the residue class of k mod m.

def Nat.residueClassesEquiv E1 #

(N : ℕ) → [NeZero N] → ℕ ≃ ZMod N × ℕ

Equivalence between ℕ and ZMod N × ℕ, sending n to (n mod N, n / N).

instance ZMod.instSubsingletonModule E0 #

∀ (n : ℕ) (M : Type u_1) [inst : AddCommMonoid M], Subsingleton (Module (ZMod n) M)