doc-next-gen

Init.Data.Nat.Dvd

Module docstring

{"Helper theorems for dvd simproc "}

Nat.dvd_refl theorem
(a : Nat) : a ∣ a
Full source
@[simp] protected theorem dvd_refl (a : Nat) : a ∣ a := ⟨1, by simp⟩
Reflexivity of Divisibility for Natural Numbers
Informal description
For any natural number $a$, $a$ divides itself, i.e., $a \mid a$.
Nat.dvd_zero theorem
(a : Nat) : a ∣ 0
Full source
@[simp] protected theorem dvd_zero (a : Nat) : a ∣ 0 := ⟨0, by simp⟩
Every Natural Number Divides Zero
Informal description
For any natural number $a$, $a$ divides $0$.
Nat.dvd_mul_left theorem
(a b : Nat) : a ∣ b * a
Full source
protected theorem dvd_mul_left (a b : Nat) : a ∣ b * a := ⟨b, Nat.mul_comm b a⟩
Divisibility of Product by Second Factor: $a \mid b \times a$
Informal description
For any natural numbers $a$ and $b$, the number $a$ divides the product $b \times a$.
Nat.dvd_mul_right theorem
(a b : Nat) : a ∣ a * b
Full source
protected theorem dvd_mul_right (a b : Nat) : a ∣ a * b := ⟨b, rfl⟩
Divisibility of Product by First Factor: $a \mid a \times b$
Informal description
For any natural numbers $a$ and $b$, the number $a$ divides the product $a \times b$.
Nat.dvd_trans theorem
{a b c : Nat} (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c
Full source
protected theorem dvd_trans {a b c : Nat} (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c :=
  match h₁, h₂ with
  | ⟨d, (h₃ : b = a * d)⟩, ⟨e, (h₄ : c = b * e)⟩ =>
    ⟨d * e, show c = a * (d * e) by simp[h₃,h₄, Nat.mul_assoc]⟩
Transitivity of Divisibility for Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ divides $b$ and $b$ divides $c$, then $a$ divides $c$.
Nat.dvd_mul_left_of_dvd theorem
{a b : Nat} (h : a ∣ b) (c : Nat) : a ∣ c * b
Full source
protected theorem dvd_mul_left_of_dvd {a b : Nat} (h : a ∣ b) (c : Nat) : a ∣ c * b :=
  Nat.dvd_trans h (Nat.dvd_mul_left _ _)
Divisibility of Scalar Multiple: $a \mid b \Rightarrow a \mid c \times b$
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ divides $b$, then $a$ divides the product $c \times b$.
Nat.dvd_mul_right_of_dvd theorem
{a b : Nat} (h : a ∣ b) (c : Nat) : a ∣ b * c
Full source
protected theorem dvd_mul_right_of_dvd {a b : Nat} (h : a ∣ b) (c : Nat) : a ∣ b * c :=
  Nat.dvd_trans h (Nat.dvd_mul_right _ _)
Divisibility of Product by Divisor: $a \mid b \implies a \mid b \times c$
Informal description
For any natural numbers $a$ and $b$ such that $a$ divides $b$, and for any natural number $c$, it holds that $a$ divides the product $b \times c$.
Nat.dvd_add theorem
{a b c : Nat} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c
Full source
protected theorem dvd_add {a b c : Nat} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c :=
  let ⟨d, hd⟩ := h₁; let ⟨e, he⟩ := h₂; ⟨d + e, by simp [Nat.left_distrib, hd, he]⟩
Divisibility is Preserved Under Addition
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ divides $b$ and $a$ divides $c$, then $a$ divides $b + c$.
Nat.dvd_add_iff_right theorem
{k m n : Nat} (h : k ∣ m) : k ∣ n ↔ k ∣ m + n
Full source
protected theorem dvd_add_iff_right {k m n : Nat} (h : k ∣ m) : k ∣ nk ∣ n ↔ k ∣ m + n :=
  ⟨Nat.dvd_add h,
    match m, h with
    | _, ⟨d, rfl⟩ => fun ⟨e, he⟩ =>
      ⟨e - d, by rw [Nat.mul_sub_left_distrib, ← he, Nat.add_sub_cancel_left]⟩⟩
Divisibility of Sum by Divisor Conditioned on One Term
Informal description
For any natural numbers $k$, $m$, and $n$, if $k$ divides $m$, then $k$ divides $n$ if and only if $k$ divides $m + n$.
Nat.dvd_add_iff_left theorem
{k m n : Nat} (h : k ∣ n) : k ∣ m ↔ k ∣ m + n
Full source
protected theorem dvd_add_iff_left {k m n : Nat} (h : k ∣ n) : k ∣ mk ∣ m ↔ k ∣ m + n := by
  rw [Nat.add_comm]; exact Nat.dvd_add_iff_right h
Divisibility of Sum by Divisor Conditioned on Right Term
Informal description
For any natural numbers $k$, $m$, and $n$, if $k$ divides $n$, then $k$ divides $m$ if and only if $k$ divides $m + n$.
Nat.dvd_mod_iff theorem
{k m n : Nat} (h : k ∣ n) : k ∣ m % n ↔ k ∣ m
Full source
theorem dvd_mod_iff {k m n : Nat} (h: k ∣ n) : k ∣ m % nk ∣ m % n ↔ k ∣ m := by
  have := Nat.dvd_add_iff_left (m := m % n) <| Nat.dvd_trans h <| Nat.dvd_mul_right n (m / n)
  rwa [mod_add_div] at this
Divisibility of Modulo: $k \mid (m \bmod n) \leftrightarrow k \mid m$ when $k \mid n$
Informal description
For any natural numbers $k$, $m$, and $n$ such that $k$ divides $n$, the number $k$ divides $m \bmod n$ if and only if $k$ divides $m$.
Nat.le_of_dvd theorem
{m n : Nat} (h : 0 < n) : m ∣ n → m ≤ n
Full source
theorem le_of_dvd {m n : Nat} (h : 0 < n) : m ∣ n → m ≤ n
  | ⟨k, e⟩ => by
    revert h
    rw [e]
    match k with
    | 0 => intro hn; simp at hn
    | pk+1 =>
      intro
      have := Nat.mul_le_mul_left m (succ_pos pk)
      rwa [Nat.mul_one] at this
Divisor of Positive Natural Number is Less Than or Equal to It
Informal description
For any natural numbers $m$ and $n$ with $n > 0$, if $m$ divides $n$, then $m \leq n$.
Nat.dvd_antisymm theorem
: ∀ {m n : Nat}, m ∣ n → n ∣ m → m = n
Full source
protected theorem dvd_antisymm : ∀ {m n : Nat}, m ∣ nn ∣ m → m = n
  | _, 0, _, h₂ => Nat.eq_zero_of_zero_dvd h₂
  | 0, _, h₁, _ => (Nat.eq_zero_of_zero_dvd h₁).symm
  | _+1, _+1, h₁, h₂ => Nat.le_antisymm (le_of_dvd (succ_pos _) h₁) (le_of_dvd (succ_pos _) h₂)
Antisymmetry of Divisibility on Natural Numbers: $m \mid n \land n \mid m \implies m = n$
Informal description
For any natural numbers $m$ and $n$, if $m$ divides $n$ and $n$ divides $m$, then $m = n$.
Nat.pos_of_dvd_of_pos theorem
{m n : Nat} (H1 : m ∣ n) (H2 : 0 < n) : 0 < m
Full source
theorem pos_of_dvd_of_pos {m n : Nat} (H1 : m ∣ n) (H2 : 0 < n) : 0 < m :=
  Nat.pos_of_ne_zero fun m0 => Nat.ne_of_gt H2 <| Nat.eq_zero_of_zero_dvd (m0 ▸ H1)
Positivity of Divisors of Positive Natural Numbers
Informal description
For any natural numbers $m$ and $n$, if $m$ divides $n$ and $n$ is positive, then $m$ is positive.
Nat.one_dvd theorem
(n : Nat) : 1 ∣ n
Full source
@[simp] protected theorem one_dvd (n : Nat) : 1 ∣ n := ⟨n, n.one_mul.symm⟩
One Divides All Natural Numbers
Informal description
For any natural number $n$, the number $1$ divides $n$.
Nat.mod_eq_zero_of_dvd theorem
{m n : Nat} (H : m ∣ n) : n % m = 0
Full source
theorem mod_eq_zero_of_dvd {m n : Nat} (H : m ∣ n) : n % m = 0 := by
  let ⟨z, H⟩ := H; rw [H, mul_mod_right]
Remainder Zero under Divisibility in Natural Numbers
Informal description
For any natural numbers $m$ and $n$, if $m$ divides $n$ (i.e., $m \mid n$), then the remainder of $n$ divided by $m$ is zero (i.e., $n \bmod m = 0$).
Nat.dvd_of_mod_eq_zero theorem
{m n : Nat} (H : n % m = 0) : m ∣ n
Full source
theorem dvd_of_mod_eq_zero {m n : Nat} (H : n % m = 0) : m ∣ n := by
  exists n / m
  have := (mod_add_div n m).symm
  rwa [H, Nat.zero_add] at this
Divisibility Criterion via Remainder Zero: $n \bmod m = 0 \implies m \mid n$
Informal description
For any natural numbers $m$ and $n$, if the remainder of $n$ divided by $m$ is zero (i.e., $n \bmod m = 0$), then $m$ divides $n$ (i.e., $m \mid n$).
Nat.decidable_dvd instance
: @DecidableRel Nat Nat (· ∣ ·)
Full source
instance decidable_dvd : @DecidableRel Nat Nat (·∣·) :=
  fun _ _ => decidable_of_decidable_of_iff dvd_iff_mod_eq_zero.symm
Decidability of Divisibility on Natural Numbers
Informal description
The divisibility relation on natural numbers is decidable. That is, for any two natural numbers $m$ and $n$, it is constructively decidable whether $m$ divides $n$ (denoted $m \mid n$).
Nat.emod_pos_of_not_dvd theorem
{a b : Nat} (h : ¬a ∣ b) : 0 < b % a
Full source
theorem emod_pos_of_not_dvd {a b : Nat} (h : ¬ a ∣ b) : 0 < b % a := by
  rw [dvd_iff_mod_eq_zero] at h
  exact Nat.pos_of_ne_zero h
Positivity of Remainder for Non-Divisible Natural Numbers
Informal description
For any natural numbers $a$ and $b$, if $a$ does not divide $b$, then the remainder of $b$ divided by $a$ is positive, i.e., $0 < b \bmod a$.
Nat.mul_div_cancel' theorem
{n m : Nat} (H : n ∣ m) : n * (m / n) = m
Full source
protected theorem mul_div_cancel' {n m : Nat} (H : n ∣ m) : n * (m / n) = m := by
  have := mod_add_div m n
  rwa [mod_eq_zero_of_dvd H, Nat.zero_add] at this
Divisibility implies $n \times (m / n) = m$ for natural numbers
Informal description
For any natural numbers $n$ and $m$ such that $n$ divides $m$, the product of $n$ and the quotient $m / n$ equals $m$, i.e., $n \times (m / n) = m$.
Nat.div_mul_cancel theorem
{n m : Nat} (H : n ∣ m) : m / n * n = m
Full source
protected theorem div_mul_cancel {n m : Nat} (H : n ∣ m) : m / n * n = m := by
  rw [Nat.mul_comm, Nat.mul_div_cancel' H]
Quotient-Multiplication Cancellation for Natural Numbers under Divisibility
Informal description
For any natural numbers $n$ and $m$ such that $n$ divides $m$, the product of the quotient $m / n$ and $n$ equals $m$, i.e., $(m / n) \times n = m$.
Nat.mod_mod_of_dvd theorem
(a : Nat) (h : c ∣ b) : a % b % c = a % c
Full source
@[simp] theorem mod_mod_of_dvd (a : Nat) (h : c ∣ b) : a % b % c = a % c := by
  rw (occs := [2]) [← mod_add_div a b]
  have ⟨x, h⟩ := h
  subst h
  rw [Nat.mul_assoc, add_mul_mod_self_left]
Nested Modulo Identity under Divisibility: $(a \bmod b) \bmod c = a \bmod c$ when $c \mid b$
Informal description
For any natural numbers $a$, $b$, and $c$ such that $c$ divides $b$, the remainder of $a$ modulo $b$ modulo $c$ equals the remainder of $a$ modulo $c$, i.e., $(a \bmod b) \bmod c = a \bmod c$.
Nat.dvd_of_mul_dvd_mul_right theorem
(kpos : 0 < k) (H : m * k ∣ n * k) : m ∣ n
Full source
protected theorem dvd_of_mul_dvd_mul_right (kpos : 0 < k) (H : m * k ∣ n * k) : m ∣ n := by
  rw [Nat.mul_comm m k, Nat.mul_comm n k] at H; exact Nat.dvd_of_mul_dvd_mul_left kpos H
Right Cancellation of Multiplication in Divisibility for Natural Numbers
Informal description
For any natural numbers $k$, $m$, and $n$ such that $k > 0$, if $m \cdot k$ divides $n \cdot k$, then $m$ divides $n$.
Nat.dvd_sub theorem
{k m n : Nat} (h₁ : k ∣ m) (h₂ : k ∣ n) : k ∣ m - n
Full source
theorem dvd_sub {k m n : Nat} (h₁ : k ∣ m) (h₂ : k ∣ n) : k ∣ m - n :=
  if H : n ≤ m then
    (Nat.dvd_add_iff_left h₂).2 <| by rwa [Nat.sub_add_cancel H]
  else
    Nat.sub_eq_zero_of_le (Nat.le_of_not_le H) ▸ Nat.dvd_zero k
Divisibility of Difference by Common Divisor in Natural Numbers
Informal description
For any natural numbers $k$, $m$, and $n$, if $k$ divides both $m$ and $n$, then $k$ divides the difference $m - n$.
Nat.dvd_sub_iff_right theorem
{m n k : Nat} (hkn : k ≤ n) (h : m ∣ n) : m ∣ n - k ↔ m ∣ k
Full source
theorem dvd_sub_iff_right {m n k : Nat} (hkn : k ≤ n) (h : m ∣ n) : m ∣ n - km ∣ n - k ↔ m ∣ k := by
  refine ⟨?_, dvd_sub h⟩
  let ⟨x, hx⟩ := h
  cases hx
  intro hy
  let ⟨y, hy⟩ := hy
  have hk : k = m * (x - y) := by
    rw [Nat.sub_eq_iff_eq_add hkn] at hy
    rw [Nat.mul_sub, hy, Nat.add_comm, Nat.add_sub_cancel]
  exact hk ▸ Nat.dvd_mul_right _ _
Divisibility of Difference Conditioned on Right Term: $m \mid (n - k) \leftrightarrow m \mid k$ when $k \leq n$ and $m \mid n$
Informal description
For any natural numbers $m$, $n$, and $k$ such that $k \leq n$ and $m$ divides $n$, we have that $m$ divides $n - k$ if and only if $m$ divides $k$.
Nat.dvd_sub_iff_left theorem
{m n k : Nat} (hkn : k ≤ n) (h : m ∣ k) : m ∣ n - k ↔ m ∣ n
Full source
theorem dvd_sub_iff_left {m n k : Nat} (hkn : k ≤ n) (h : m ∣ k) : m ∣ n - km ∣ n - k ↔ m ∣ n := by
  rw (occs := [2]) [← Nat.sub_add_cancel hkn]
  exact Nat.dvd_add_iff_left h
Divisibility of Difference Conditioned on Left Term: $m \mid (n - k) \leftrightarrow m \mid n$ when $k \leq n$ and $m \mid k$
Informal description
For any natural numbers $m$, $n$, and $k$ such that $k \leq n$ and $m$ divides $k$, we have that $m$ divides $n - k$ if and only if $m$ divides $n$.
Nat.mul_dvd_mul theorem
{a b c d : Nat} : a ∣ b → c ∣ d → a * c ∣ b * d
Full source
protected theorem mul_dvd_mul {a b c d : Nat} : a ∣ bc ∣ da * c ∣ b * d
  | ⟨e, he⟩, ⟨f, hf⟩ =>
    ⟨e * f, by simp [he, hf, Nat.mul_assoc, Nat.mul_left_comm, Nat.mul_comm]⟩
Product Divisibility: $a \mid b \land c \mid d \to a \cdot c \mid b \cdot d$
Informal description
For any natural numbers $a, b, c, d$, if $a$ divides $b$ and $c$ divides $d$, then the product $a \cdot c$ divides the product $b \cdot d$.
Nat.mul_dvd_mul_left theorem
(a : Nat) (h : b ∣ c) : a * b ∣ a * c
Full source
protected theorem mul_dvd_mul_left (a : Nat) (h : b ∣ c) : a * b ∣ a * c :=
  Nat.mul_dvd_mul (Nat.dvd_refl a) h
Left Multiplication Preserves Divisibility: $b \mid c \Rightarrow a \cdot b \mid a \cdot c$
Informal description
For any natural numbers $a, b, c$, if $b$ divides $c$, then the product $a \cdot b$ divides the product $a \cdot c$.
Nat.mul_dvd_mul_right theorem
(h : a ∣ b) (c : Nat) : a * c ∣ b * c
Full source
protected theorem mul_dvd_mul_right (h: a ∣ b) (c : Nat) : a * c ∣ b * c :=
  Nat.mul_dvd_mul h (Nat.dvd_refl c)
Right Multiplication Preserves Divisibility in Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ divides $b$, then $a \cdot c$ divides $b \cdot c$.
Nat.mul_div_assoc theorem
(m : Nat) (H : k ∣ n) : m * n / k = m * (n / k)
Full source
protected theorem mul_div_assoc (m : Nat) (H : k ∣ n) : m * n / k = m * (n / k) := by
  match Nat.eq_zero_or_pos k with
  | .inl h0 => rw [h0, Nat.div_zero, Nat.div_zero, Nat.mul_zero]
  | .inr hpos =>
    have h1 : m * n / k = m * (n / k * k) / k := by rw [Nat.div_mul_cancel H]
    rw [h1, ← Nat.mul_assoc, Nat.mul_div_cancel _ hpos]
Associativity of Multiplication and Division under Divisibility: $(m \cdot n) / k = m \cdot (n / k)$ when $k \mid n$
Informal description
For any natural numbers $m$, $n$, and $k$ such that $k$ divides $n$, the expression $(m \cdot n) / k$ is equal to $m \cdot (n / k)$.
Nat.dvd_eq_true_of_mod_eq_zero theorem
{m n : Nat} (h : n % m == 0) : (m ∣ n) = True
Full source
protected theorem dvd_eq_true_of_mod_eq_zero {m n : Nat} (h : n % m == 0) : (m ∣ n) = True := by
  simp [Nat.dvd_of_mod_eq_zero, eq_of_beq h]
Divisibility Criterion via Zero Remainder: $m \mid n \leftrightarrow n \bmod m = 0$
Informal description
For any natural numbers $m$ and $n$, if the remainder of $n$ divided by $m$ is zero (i.e., $n \bmod m = 0$), then the divisibility relation $m \mid n$ holds (i.e., $m \mid n$ is true).
Nat.dvd_eq_false_of_mod_ne_zero theorem
{m n : Nat} (h : n % m != 0) : (m ∣ n) = False
Full source
protected theorem dvd_eq_false_of_mod_ne_zero {m n : Nat} (h : n % m != 0) : (m ∣ n) = False := by
  simp [eq_of_beq] at h
  simp [dvd_iff_mod_eq_zero, h]
Non-divisibility Criterion via Non-zero Remainder
Informal description
For any natural numbers $m$ and $n$, if the remainder of $n$ divided by $m$ is not zero (i.e., $n \bmod m \neq 0$), then the proposition "$m$ divides $n$" is false.