File: Mathlib/Data/Nat/ModEq.lean

full_name: Nat.ModEq
code: /-- Modular equality. `n.ModEq a b`, or `a ≡ b [MOD n]`, means that `a - b` is a multiple of `n`. -/
def ModEq (n a b : ℕ) 
goal: Prop

full_name: Nat._aux_Mathlib_Data_Nat_ModEq___unexpand_Nat_ModEq_1
code: @[inherit_doc]
notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b
goal: Lean.PrettyPrinter.Unexpander

full_name: Nat.«_aux_Mathlib_Data_Nat_ModEq___macroRules_Nat_term_≡_[MOD_]_1»
code: @[inherit_doc]
notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b
goal: Lean.Macro

full_name: Nat.instDecidableModEq
code: instance : Decidable (ModEq n a b) 
goal: Decidable (a ≡ b [MOD n])

full_name: Nat.ModEq.refl
code: @[refl]
protected theorem refl (a : ℕ) : a ≡ a [MOD n] 
goal: a ≡ a [MOD n]

full_name: Nat.ModEq.rfl
code: protected theorem rfl : a ≡ a [MOD n] 
goal: a ≡ a [MOD n]

full_name: Nat.ModEq.instIsRefl
code: instance : IsRefl _ (ModEq n) 
goal: IsRefl ℕ n.ModEq

full_name: Nat.ModEq.symm
code: @[symm]
protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] 
goal: a ≡ b [MOD n] → b ≡ a [MOD n]

full_name: Nat.ModEq.trans
code: @[trans]
protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] 
goal: a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n]

full_name: Nat.ModEq.instTrans
code: instance : Trans (ModEq n) (ModEq n) (ModEq n) 
goal: Trans n.ModEq n.ModEq n.ModEq

full_name: Nat.ModEq.comm
code: protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] 
goal: a ≡ b [MOD n] ↔ b ≡ a [MOD n]

full_name: Nat.modEq_zero_iff_dvd
code: theorem modEq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a 
goal: a ≡ 0 [MOD n] ↔ n ∣ a

full_name: Dvd.dvd.modEq_zero_nat
code: theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] 
goal: a ≡ 0 [MOD n]

full_name: Dvd.dvd.zero_modEq_nat
code: theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≡ a [MOD n] 
goal: 0 ≡ a [MOD n]

full_name: Nat.modEq_iff_dvd
code: theorem modEq_iff_dvd : a ≡ b [MOD n] ↔ (n : ℤ) ∣ b - a 
goal: a ≡ b [MOD n] ↔ ↑n ∣ ↑b - ↑a

full_name: Nat.modEq_iff_dvd'
code: /-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/
theorem modEq_iff_dvd' (h : a ≤ b) : a ≡ b [MOD n] ↔ n ∣ b - a 
goal: a ≡ b [MOD n] ↔ n ∣ b - a

full_name: Nat.mod_modEq
code: theorem mod_modEq (a n) : a % n ≡ a [MOD n] 
goal: a % n ≡ a [MOD n]

full_name: Nat.ModEq.of_dvd
code: lemma of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] 
goal: a ≡ b [MOD m]

full_name: Nat.ModEq.mul_left'
code: protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD c * n] 
goal: c * a ≡ c * b [MOD c * n]

full_name: Nat.ModEq.mul_left
code: @[gcongr]
protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] 
goal: c * a ≡ c * b [MOD n]

full_name: Nat.ModEq.mul_right'
code: protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n * c] 
goal: a * c ≡ b * c [MOD n * c]

full_name: Nat.ModEq.mul_right
code: @[gcongr]
protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] 
goal: a * c ≡ b * c [MOD n]

full_name: Nat.ModEq.mul
code: @[gcongr]
protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] 
goal: a * c ≡ b * d [MOD n]

full_name: Nat.ModEq.pow
code: @[gcongr]
protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] 
goal: a ^ m ≡ b ^ m [MOD n]

full_name: Nat.ModEq.add
code: @[gcongr]
protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] 
goal: a + c ≡ b + d [MOD n]

full_name: Nat.ModEq.add_left
code: @[gcongr]
protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] 
goal: c + a ≡ c + b [MOD n]

full_name: Nat.ModEq.add_right
code: @[gcongr]
protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] 
goal: a + c ≡ b + c [MOD n]

full_name: Nat.ModEq.add_left_cancel
code: protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
    c ≡ d [MOD n] 
goal: c ≡ d [MOD n]

full_name: Nat.ModEq.add_left_cancel'
code: protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] 
goal: a ≡ b [MOD n]

full_name: Nat.ModEq.add_right_cancel
code: protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
    a ≡ b [MOD n] 
goal: a ≡ b [MOD n]

full_name: Nat.ModEq.add_right_cancel'
code: protected theorem add_right_cancel' (c : ℕ) (h : a + c ≡ b + c [MOD n]) : a ≡ b [MOD n] 
goal: a ≡ b [MOD n]

full_name: Nat.ModEq.mul_left_cancel'
code: /-- Cancel left multiplication on both sides of the `≡` and in the modulus.

For cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/
protected theorem mul_left_cancel' {a b c m : ℕ} (hc : c ≠ 0) :
    c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m] 
goal: c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m]

full_name: Nat.ModEq.mul_left_cancel_iff'
code: protected theorem mul_left_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) :
    c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m] 
goal: c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m]

full_name: Nat.ModEq.mul_right_cancel'
code: /-- Cancel right multiplication on both sides of the `≡` and in the modulus.

For cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/
protected theorem mul_right_cancel' {a b c m : ℕ} (hc : c ≠ 0) :
    a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m] 
goal: a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m]

full_name: Nat.ModEq.mul_right_cancel_iff'
code: protected theorem mul_right_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) :
    a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m] 
goal: a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m]

full_name: Nat.ModEq.of_mul_left
code: /-- Cancel left multiplication in the modulus.

For cancelling left multiplication on both sides of the `≡`, see `nat.modeq.mul_left_cancel'`. -/
lemma of_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] 
goal: a ≡ b [MOD n]

full_name: Nat.ModEq.of_mul_right
code: /-- Cancel right multiplication in the modulus.

For cancelling right multiplication on both sides of the `≡`, see `nat.modeq.mul_right_cancel'`. -/
lemma of_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] 
goal: a ≡ b [MOD n * m] → a ≡ b [MOD n]

full_name: Nat.ModEq.of_div
code: theorem of_div (h : a / c ≡ b / c [MOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) :
    a ≡ b [MOD m] 
goal: c ∣ b → c ∣ m → a ≡ b [MOD m]

full_name: Nat.modEq_sub
code: lemma modEq_sub (h : b ≤ a) : a ≡ b [MOD a - b] 
goal: a ≡ b [MOD a - b]

full_name: Nat.modEq_one
code: lemma modEq_one : a ≡ b [MOD 1] 
goal: a ≡ b [MOD 1]

full_name: Nat.modEq_zero_iff
code: @[simp] lemma modEq_zero_iff : a ≡ b [MOD 0] ↔ a = b 
goal: a ≡ b [MOD 0] ↔ a = b

full_name: Nat.add_modEq_left
code: @[simp] lemma add_modEq_left : n + a ≡ a [MOD n] 
goal: n + a ≡ a [MOD n]

full_name: Nat.add_modEq_right
code: @[simp] lemma add_modEq_right : a + n ≡ a [MOD n] 
goal: a + n ≡ a [MOD n]

full_name: Nat.ModEq.le_of_lt_add
code: theorem le_of_lt_add (h1 : a ≡ b [MOD m]) (h2 : a < b + m) : a ≤ b 
goal: a ≤ b

full_name: Nat.ModEq.add_le_of_lt
code: theorem add_le_of_lt (h1 : a ≡ b [MOD m]) (h2 : a < b) : a + m ≤ b 
goal: a + m ≤ b

full_name: Nat.ModEq.dvd_iff
code: theorem dvd_iff (h : a ≡ b [MOD m]) (hdm : d ∣ m) : d ∣ a ↔ d ∣ b 
goal: d ∣ a ↔ d ∣ b

full_name: Nat.ModEq.gcd_eq
code: theorem gcd_eq (h : a ≡ b [MOD m]) : gcd a m = gcd b m 
goal: a.gcd m = b.gcd m

full_name: Nat.ModEq.eq_of_abs_lt
code: lemma eq_of_abs_lt (h : a ≡ b [MOD m]) (h2 : |(b : ℤ) - a| < m) : a = b 
goal: a = b

full_name: Nat.ModEq.eq_of_lt_of_lt
code: lemma eq_of_lt_of_lt (h : a ≡ b [MOD m]) (ha : a < m) (hb : b < m) : a = b 
goal: a = b

full_name: Nat.ModEq.cancel_left_div_gcd
code: /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/
lemma cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [MOD m]) :  a ≡ b [MOD m / gcd m c] 
goal: a ≡ b [MOD m / m.gcd c]

full_name: Nat.ModEq.cancel_right_div_gcd
code: /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/
lemma cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m / gcd m c] 
goal: a ≡ b [MOD m / m.gcd c]

full_name: Nat.ModEq.cancel_left_div_gcd'
code: lemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : c * a ≡ d * b [MOD m]) :
    a ≡ b [MOD m / gcd m c] 
goal: a ≡ b [MOD m / m.gcd c]

full_name: Nat.ModEq.cancel_right_div_gcd'
code: lemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : a * c ≡ b * d [MOD m]) :
    a ≡ b [MOD m / gcd m c] 
goal: a ≡ b [MOD m / m.gcd c]

full_name: Nat.ModEq.cancel_left_of_coprime
code: /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/
lemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m] 
goal: a ≡ b [MOD m]

full_name: Nat.ModEq.cancel_right_of_coprime
code: /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/
lemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m] 
goal: a ≡ b [MOD m]

full_name: Nat.chineseRemainder'
code: /-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/
def chineseRemainder' (h : a ≡ b [MOD gcd n m]) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } 
goal: { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] }

full_name: Nat.chineseRemainder
code: /-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/
def chineseRemainder (co : n.Coprime m) (a b : ℕ) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } 
goal: { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] }

full_name: Nat.chineseRemainder'_lt_lcm
code: theorem chineseRemainder'_lt_lcm (h : a ≡ b [MOD gcd n m]) (hn : n ≠ 0) (hm : m ≠ 0) :
    ↑(chineseRemainder' h) < lcm n m 
goal: ↑(Nat.chineseRemainder' h) < n.lcm m

full_name: Nat.chineseRemainder_lt_mul
code: theorem chineseRemainder_lt_mul (co : n.Coprime m) (a b : ℕ) (hn : n ≠ 0) (hm : m ≠ 0) :
    ↑(chineseRemainder co a b) < n * m 
goal: ↑(Nat.chineseRemainder co a b) < n * m

full_name: Nat.mod_lcm
code: theorem mod_lcm (hn : a ≡ b [MOD n]) (hm : a ≡ b [MOD m]) : a ≡ b [MOD lcm n m] 
goal: a ≡ b [MOD n.lcm m]

full_name: Nat.chineseRemainder_modEq_unique
code: theorem chineseRemainder_modEq_unique (co : n.Coprime m) {a b z}
    (hzan : z ≡ a [MOD n]) (hzbm : z ≡ b [MOD m]) : z ≡ chineseRemainder co a b [MOD n*m] 
goal: z ≡ ↑(Nat.chineseRemainder co a b) [MOD n * m]

full_name: Nat.modEq_and_modEq_iff_modEq_mul
code: theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℕ} (hmn : m.Coprime n) :
    a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ a ≡ b [MOD m * n] 
goal: a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ a ≡ b [MOD m * n]

full_name: Nat.coprime_of_mul_modEq_one
code: theorem coprime_of_mul_modEq_one (b : ℕ) {a n : ℕ} (h : a * b ≡ 1 [MOD n]) : a.Coprime n 
goal: a.Coprime n

full_name: Nat.add_mod_add_ite
code: theorem add_mod_add_ite (a b c : ℕ) :
    ((a + b) % c + if c ≤ a % c + b % c then c else 0) = a % c + b % c 
goal: ((a + b) % c + if c ≤ a % c + b % c then c else 0) = a % c + b % c

full_name: Nat.add_mod_of_add_mod_lt
code: theorem add_mod_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
    (a + b) % c = a % c + b % c 
goal: (a + b) % c = a % c + b % c

full_name: Nat.add_mod_add_of_le_add_mod
code: theorem add_mod_add_of_le_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) :
    (a + b) % c + c = a % c + b % c 
goal: (a + b) % c + c = a % c + b % c

full_name: Nat.add_div
code: theorem add_div {a b c : ℕ} (hc0 : 0 < c) :
    (a + b) / c = a / c + b / c + if c ≤ a % c + b % c then 1 else 0 
goal: (a + b) / c = a / c + b / c + if c ≤ a % c + b % c then 1 else 0

full_name: Nat.add_div_eq_of_add_mod_lt
code: theorem add_div_eq_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
    (a + b) / c = a / c + b / c 
goal: (a + b) / c = a / c + b / c

full_name: Nat.add_div_of_dvd_right
code: protected theorem add_div_of_dvd_right {a b c : ℕ} (hca : c ∣ a) : (a + b) / c = a / c + b / c 
goal: (a + b) / c = a / c + b / c

full_name: Nat.add_div_of_dvd_left
code: protected theorem add_div_of_dvd_left {a b c : ℕ} (hca : c ∣ b) : (a + b) / c = a / c + b / c 
goal: (a + b) / c = a / c + b / c

full_name: Nat.add_div_eq_of_le_mod_add_mod
code: theorem add_div_eq_of_le_mod_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) (hc0 : 0 < c) :
    (a + b) / c = a / c + b / c + 1 
goal: (a + b) / c = a / c + b / c + 1

full_name: Nat.add_div_le_add_div
code: theorem add_div_le_add_div (a b c : ℕ) : a / c + b / c ≤ (a + b) / c 
goal: a / c + b / c ≤ (a + b) / c

full_name: Nat.le_mod_add_mod_of_dvd_add_of_not_dvd
code: theorem le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : ℕ} (h : c ∣ a + b) (ha : ¬c ∣ a) :
    c ≤ a % c + b % c 
goal: c ≤ a % c + b % c

full_name: Nat.odd_mul_odd
code: theorem odd_mul_odd {n m : ℕ} : n % 2 = 1 → m % 2 = 1 → n * m % 2 = 1 
goal: n % 2 = 1 → m % 2 = 1 → n * m % 2 = 1

full_name: Nat.odd_mul_odd_div_two
code: theorem odd_mul_odd_div_two {m n : ℕ} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) :
    m * n / 2 = m * (n / 2) + m / 2 
goal: m * n / 2 = m * (n / 2) + m / 2

full_name: Nat.odd_of_mod_four_eq_one
code: theorem odd_of_mod_four_eq_one {n : ℕ} : n % 4 = 1 → n % 2 = 1 
goal: n % 4 = 1 → n % 2 = 1

full_name: Nat.odd_of_mod_four_eq_three
code: theorem odd_of_mod_four_eq_three {n : ℕ} : n % 4 = 3 → n % 2 = 1 
goal: n % 4 = 3 → n % 2 = 1

full_name: Nat.odd_mod_four_iff
code: /-- A natural number is odd iff it has residue `1` or `3` mod `4`-/
theorem odd_mod_four_iff {n : ℕ} : n % 2 = 1 ↔ n % 4 = 1 ∨ n % 4 = 3 
goal: n % 2 = 1 ↔ n % 4 = 1 ∨ n % 4 = 3

full_name: Nat.mod_eq_of_modEq
code: lemma mod_eq_of_modEq {a b n} (h : a ≡ b [MOD n]) (hb : b < n) : a % n = b 
goal: a % n = b