mathlib documentation

data.​zmod.​basic

data.​zmod.​basic

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.

def fin.​has_neg (n : ℕ) :

Negation on fin n

Equations

Additive commutative semigroup structure on fin (n+1).

Equations

Multiplicative commutative semigroup structure on fin (n+1).

Equations
def fin.​comm_ring (n : ℕ) :
comm_ring (fin (n + 1))

Commutative ring structure on fin (n+1).

Equations
def zmod  :
ℕ → Type

The integers modulo n : ℕ.

Equations
@[instance]
def zmod.​fintype (n : ℕ) [fact (0 < n)] :

Equations
theorem zmod.​card (n : ℕ) [fact (0 < n)] :

@[instance]
def zmod.​has_repr (n : ℕ) :

Equations
@[instance]
def zmod.​inhabited (n : ℕ) :

Equations
def zmod.​val {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.val_min_abs for a variant that takes values in the integers.

Equations
theorem zmod.​val_lt {n : ℕ} [fact (0 < n)] (a : zmod n) :
a.val < n

@[simp]
theorem zmod.​val_zero {n : ℕ} :
0.val = 0

theorem zmod.​val_cast_nat {n : ℕ} (a : ℕ) :
↑a.val = a % n

@[instance]
def zmod.​char_p (n : ℕ) :
char_p (zmod n) n

Equations
  • _ = _
@[simp]
theorem zmod.​cast_self (n : ℕ) :
↑n = 0

@[simp]
theorem zmod.​cast_self' (n : ℕ) :
↑n + 1 = 0

def zmod.​cast {R : Type u_1} [has_zero R] [has_one R] [has_add R] [has_neg 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.cast_hom for a bundled version.

Equations
@[instance]
def zmod.​has_coe_t {R : Type u_1} [has_zero R] [has_one R] [has_add R] [has_neg R] (n : ℕ) :

Equations
@[simp]
theorem zmod.​cast_zero {n : ℕ} {R : Type u_1} [has_zero R] [has_one R] [has_add R] [has_neg R] :
↑0 = 0

theorem zmod.​cast_val {n : ℕ} [fact (0 < n)] (a : zmod n) :
↑(a.val) = a

@[simp]
theorem zmod.​cast_id (n : ℕ) (i : zmod n) :
↑i = i

@[simp]
theorem zmod.​nat_cast_val {n : ℕ} {R : Type u_1} [ring R] [fact (0 < n)] (i : zmod n) :
↑(i.val) = ↑i

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

@[simp]
theorem zmod.​cast_one {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] :
m ∣ n → ↑1 = 1

theorem zmod.​cast_add {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (a b : zmod n) :
↑(a + b) = ↑a + ↑b

theorem zmod.​cast_mul {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (a b : zmod n) :
↑(a * b) = ↑a * ↑b

def zmod.​cast_hom {n m : ℕ} (h : m ∣ n) (R : Type u_1) [ring R] [char_p R m] :

The canonical ring homomorphism from zmod n to a ring of characteristic n.

Equations
@[simp]
theorem zmod.​cast_hom_apply {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] {h : m ∣ n} (i : zmod n) :

theorem zmod.​cast_sub {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (a b : zmod n) :
↑(a - b) = ↑a - ↑b

theorem zmod.​cast_pow {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (a : zmod n) (k : ℕ) :
↑(a ^ k) = ↑a ^ k

theorem zmod.​cast_nat_cast {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (k : ℕ) :

theorem zmod.​cast_int_cast {n : ℕ} {R : Type u_1} [ring R] {m : ℕ} [char_p R m] (h : m ∣ n) (k : ℤ) :

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

@[simp]
theorem zmod.​cast_one' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] :
↑1 = 1

@[simp]
theorem zmod.​cast_add' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (a b : zmod n) :
↑(a + b) = ↑a + ↑b

@[simp]
theorem zmod.​cast_mul' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (a b : zmod n) :
↑(a * b) = ↑a * ↑b

@[simp]
theorem zmod.​cast_sub' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (a b : zmod n) :
↑(a - b) = ↑a - ↑b

@[simp]
theorem zmod.​cast_pow' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (a : zmod n) (k : ℕ) :
↑(a ^ k) = ↑a ^ k

@[simp]
theorem zmod.​cast_nat_cast' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (k : ℕ) :

@[simp]
theorem zmod.​cast_int_cast' {n : ℕ} {R : Type u_1} [ring R] [char_p R n] (k : ℤ) :

theorem zmod.​int_coe_eq_int_coe_iff (a b : ℤ) (c : ℕ) :

theorem zmod.​nat_coe_eq_nat_coe_iff (a b c : ℕ) :
↑a = ↑b ↔ a ≡ b [MOD c]

theorem zmod.​cast_mod_int (a : ℤ) (b : ℕ) :
↑(a % ↑b) = ↑a

theorem zmod.​val_one_eq_one_mod (n : ℕ) :
1.val = 1 % n

theorem zmod.​val_one (n : ℕ) [fact (1 < n)] :
1.val = 1

theorem zmod.​val_add {n : ℕ} [fact (0 < n)] (a b : zmod n) :
(a + b).val = (a.val + b.val) % n

theorem zmod.​val_mul {n : ℕ} (a b : zmod n) :
(a * b).val = a.val * b.val % n

@[instance]
def zmod.​nontrivial (n : ℕ) [fact (1 < n)] :

Equations
  • _ = _
def zmod.​inv (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.

Equations
@[instance]
def zmod.​has_inv (n : ℕ) :

Equations
theorem zmod.​inv_zero (n : ℕ) :
0⁻¹ = 0

theorem zmod.​mul_inv_eq_gcd {n : ℕ} (a : zmod n) :
a * a⁻¹ = ↑(a.val.gcd n)

@[simp]
theorem zmod.​cast_mod_nat (n a : ℕ) :
↑(a % n) = ↑a

theorem zmod.​eq_iff_modeq_nat (n : ℕ) {a b : ℕ} :
↑a = ↑b ↔ a ≡ b [MOD n]

theorem zmod.​coe_mul_inv_eq_one {n : ℕ} (x : ℕ) :
x.coprime n → ↑x * (↑x)⁻¹ = 1

def zmod.​unit_of_coprime {n : ℕ} (x : ℕ) :
x.coprime n → units (zmod n)

unit_of_coprime makes an element of units (zmod n) given a natural number x and a proof that x is coprime to n

Equations
@[simp]
theorem zmod.​cast_unit_of_coprime {n : ℕ} (x : ℕ) (h : x.coprime n) :

@[simp]
theorem zmod.​inv_coe_unit {n : ℕ} (u : units (zmod n)) :

theorem zmod.​mul_inv_of_unit {n : ℕ} (a : zmod n) :
is_unit a → a * a⁻¹ = 1

theorem zmod.​inv_mul_of_unit {n : ℕ} (a : zmod n) :
is_unit a → a⁻¹ * a = 1

def zmod.​units_equiv_coprime {n : ℕ} [fact (0 < n)] :
units (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 comprime to n

Equations
@[simp]

theorem zmod.​le_div_two_iff_lt_neg (n : ℕ) [hn : fact (n % 2 = 1)] {x : zmod n} :
x ≠ 0 → (x.val ≤ n / 2 ↔ n / 2 < (-x).val)

theorem zmod.​ne_neg_self (n : ℕ) [hn : fact (n % 2 = 1)] {a : zmod n} :
a ≠ 0 → a ≠ -a

theorem zmod.​neg_one_ne_one {n : ℕ} [fact (2 < n)] :
-1 ≠ 1

@[simp]
theorem zmod.​neg_eq_self_mod_two (a : zmod 2) :
-a = a

@[simp]
theorem zmod.​nat_abs_mod_two (a : ℤ) :

@[simp]
theorem zmod.​val_eq_zero {n : ℕ} (a : zmod n) :
a.val = 0 ↔ a = 0

theorem zmod.​val_cast_of_lt {n a : ℕ} :
a < n → ↑a.val = a

theorem zmod.​neg_val' {n : ℕ} [fact (0 < n)] (a : zmod n) :
(-a).val = (n - a.val) % n

theorem zmod.​neg_val {n : ℕ} [fact (0 < n)] (a : zmod n) :
(-a).val = ite (a = 0) 0 (n - a.val)

def zmod.​val_min_abs {n : ℕ} :
zmod n → ℤ

val_min_abs x returns the integer in the same equivalence class as x that is closest to 0, The result will be in the interval (-n/2, n/2].

Equations
@[simp]

theorem zmod.​val_min_abs_def_pos {n : ℕ} [fact (0 < n)] (x : zmod n) :
x.val_min_abs = ite (x.val ≤ n / 2) ↑(x.val) (↑(x.val) - ↑n)

@[simp]
theorem zmod.​coe_val_min_abs {n : ℕ} (x : zmod n) :

theorem zmod.​nat_abs_val_min_abs_le {n : ℕ} [fact (0 < n)] (x : zmod n) :

@[simp]
theorem zmod.​val_min_abs_zero (n : ℕ) :

@[simp]
theorem zmod.​val_min_abs_eq_zero {n : ℕ} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0

theorem zmod.​cast_nat_abs_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
↑(a.val_min_abs.nat_abs) = ite (a.val ≤ n / 2) a (-a)

theorem zmod.​val_eq_ite_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
↑(a.val) = a.val_min_abs + ite (a.val ≤ n / 2) 0 ↑n

theorem zmod.​prime_ne_zero (p q : ℕ) [hp : fact (nat.prime p)] [hq : fact (nat.prime q)] :
p ≠ q → ↑q ≠ 0

@[instance]
def zmod.​field (p : ℕ) [fact (nat.prime p)] :

Field structure on zmod p if p is prime.

Equations
theorem ring_hom.​ext_zmod {n : ℕ} {R : Type u_1} [semiring R] (f g : zmod n →+* R) :
f = g

@[instance]
def zmod.​subsingleton_ring_hom {n : ℕ} {R : Type u_1} [semiring R] :

Equations
theorem zmod.​ring_hom_surjective {R : Type u_1} [comm_ring R] {n : ℕ} (f : R →+* zmod n) :

theorem zmod.​ring_hom_eq_of_ker_eq {R : Type u_1} [comm_ring R] {n : ℕ} (f g : R →+* zmod n) :
f.ker = g.ker → f = g