doc-next-gen

Init.Data.Nat.Lemmas

Module docstring

{"# Basic lemmas about natural numbers

The primary purpose of the lemmas in this file is to assist with reasoning about sizes of objects, array indices and such.

This file was upstreamed from Std, and later these lemmas should be organised into other files more systematically. ","## add ","## sub ","### min/max ","### mul ","### div/mod ","### pow ","### log2 ","### dvd ","### shiftLeft and shiftRight ","### Decidability of predicates ","### Results about List.sum specialized to Nat "}

Nat.exists_ne_zero theorem
{P : Nat → Prop} : (∃ n, ¬n = 0 ∧ P n) ↔ ∃ n, P (n + 1)
Full source
@[simp] theorem exists_ne_zero {P : Nat → Prop} : (∃ n, ¬ n = 0 ∧ P n) ↔ ∃ n, P (n + 1) :=
  ⟨fun ⟨n, h, w⟩ => by cases n with | zero => simp at h | succ n => exact ⟨n, w⟩,
    fun ⟨n, w⟩ => ⟨n + 1, by simp, w⟩⟩
Existence of Nonzero Natural Number Satisfying Predicate is Equivalent to Existence of Successor Satisfying Predicate
Informal description
For any predicate $P$ on natural numbers, there exists a nonzero natural number $n$ satisfying $P(n)$ if and only if there exists a natural number $n$ such that $P(n+1)$ holds.
Nat.forall_lt_succ_right' theorem
{p : (m : Nat) → (m < n + 1) → Prop} : (∀ m (h : m < n + 1), p m h) ↔ (∀ m (h : m < n), p m (by omega)) ∧ p n (by omega)
Full source
/-- Dependent variant of `forall_lt_succ_right`. -/
theorem forall_lt_succ_right' {p : (m : Nat) → (m < n + 1) → Prop} :
    (∀ m (h : m < n + 1), p m h) ↔ (∀ m (h : m < n), p m (by omega)) ∧ p n (by omega) := by
  simp only [Nat.lt_succ_iff, Nat.le_iff_lt_or_eq]
  constructor
  · intro w
    constructor
    · intro m h
      exact w _ (.inl h)
    · exact w _ (.inr rfl)
  · rintro w m (h|rfl)
    · exact w.1 _ h
    · exact w.2
Universal Quantification over Natural Numbers Less Than Successor is Equivalent to Conjunction of Quantification Over Predecessor and Base Case
Informal description
For any natural number $n$ and predicate $p$ depending on a natural number $m$ and a proof that $m < n + 1$, the following equivalence holds: $(\forall m < n + 1, p(m)) \leftrightarrow (\forall m < n, p(m)) \land p(n)$.
Nat.forall_lt_succ_right theorem
{p : Nat → Prop} : (∀ m, m < n + 1 → p m) ↔ (∀ m, m < n → p m) ∧ p n
Full source
/-- See `forall_lt_succ_right'` for a variant where `p` takes the bound as an argument. -/
theorem forall_lt_succ_right {p : Nat → Prop} :
    (∀ m, m < n + 1 → p m) ↔ (∀ m, m < n → p m) ∧ p n := by
  simpa using forall_lt_succ_right' (p := fun m _ => p m)
Universal Quantification over Natural Numbers Less Than Successor is Equivalent to Conjunction of Quantification Over Predecessor and Base Case
Informal description
For any natural number $n$ and predicate $p$ on natural numbers, the following equivalence holds: \[ (\forall m < n + 1, p(m)) \leftrightarrow (\forall m < n, p(m)) \land p(n) \]
Nat.forall_lt_succ_left' theorem
{p : (m : Nat) → (m < n + 1) → Prop} : (∀ m (h : m < n + 1), p m h) ↔ p 0 (by omega) ∧ (∀ m (h : m < n), p (m + 1) (by omega))
Full source
/-- Dependent variant of `forall_lt_succ_left`. -/
theorem forall_lt_succ_left' {p : (m : Nat) → (m < n + 1) → Prop} :
    (∀ m (h : m < n + 1), p m h) ↔ p 0 (by omega) ∧ (∀ m (h : m < n), p (m + 1) (by omega)) := by
  constructor
  · intro w
    constructor
    · exact w 0 (by omega)
    · intro m h
      exact w (m + 1) (by omega)
  · rintro ⟨h₀, h₁⟩ m h
    cases m with
    | zero => exact h₀
    | succ m => exact h₁ m (by omega)
Universal Quantification over Natural Numbers Less Than Successor (Left Variant)
Informal description
For any predicate $p$ on natural numbers depending on a proof that $m < n + 1$, the following equivalence holds: \[ (\forall m < n + 1, p(m)) \leftrightarrow p(0) \land (\forall m < n, p(m + 1)) \]
Nat.forall_lt_succ_left theorem
{p : Nat → Prop} : (∀ m, m < n + 1 → p m) ↔ p 0 ∧ (∀ m, m < n → p (m + 1))
Full source
/-- See `forall_lt_succ_left'` for a variant where `p` takes the bound as an argument. -/
theorem forall_lt_succ_left {p : Nat → Prop} :
    (∀ m, m < n + 1 → p m) ↔ p 0 ∧ (∀ m, m < n → p (m + 1)) := by
  simpa using forall_lt_succ_left' (p := fun m _ => p m)
Universal Quantification over Natural Numbers Less Than Successor (Left Variant)
Informal description
For any natural number $n$ and predicate $p$ on natural numbers, the following equivalence holds: \[ (\forall m < n + 1, p(m)) \leftrightarrow p(0) \land (\forall m < n, p(m + 1)) \]
Nat.exists_lt_succ_right' theorem
{p : (m : Nat) → (m < n + 1) → Prop} : (∃ m, ∃ (h : m < n + 1), p m h) ↔ (∃ m, ∃ (h : m < n), p m (by omega)) ∨ p n (by omega)
Full source
/-- Dependent variant of `exists_lt_succ_right`. -/
theorem exists_lt_succ_right' {p : (m : Nat) → (m < n + 1) → Prop} :
    (∃ m, ∃ (h : m < n + 1), p m h) ↔ (∃ m, ∃ (h : m < n), p m (by omega)) ∨ p n (by omega) := by
  simp only [Nat.lt_succ_iff, Nat.le_iff_lt_or_eq]
  constructor
  · rintro ⟨m, (h|rfl), w⟩
    · exact .inl ⟨m, h, w⟩
    · exact .inr w
  · rintro (⟨m, h, w⟩ | w)
    · exact ⟨m, by omega, w⟩
    · exact ⟨n, by omega, w⟩
Existence of Element Satisfying Predicate in Extended Interval: $(\exists m < n + 1, p(m)) \leftrightarrow (\exists m < n, p(m)) \lor p(n)$
Informal description
For any natural number $n$ and predicate $p$ depending on a natural number $m$ and a proof that $m < n + 1$, the following equivalence holds: \[ (\exists m < n + 1, p(m)) \leftrightarrow (\exists m < n, p(m)) \lor p(n) \]
Nat.exists_lt_succ_right theorem
{p : Nat → Prop} : (∃ m, m < n + 1 ∧ p m) ↔ (∃ m, m < n ∧ p m) ∨ p n
Full source
/-- See `exists_lt_succ_right'` for a variant where `p` takes the bound as an argument. -/
theorem exists_lt_succ_right {p : Nat → Prop} :
    (∃ m, m < n + 1 ∧ p m) ↔ (∃ m, m < n ∧ p m) ∨ p n := by
  simpa using exists_lt_succ_right' (p := fun m _ => p m)
Existence of Satisfying Element in Extended Interval: $(\exists m < n + 1, p(m)) \leftrightarrow (\exists m < n, p(m)) \lor p(n)$
Informal description
For any natural number $n$ and predicate $p$ on natural numbers, there exists a natural number $m < n + 1$ satisfying $p(m)$ if and only if either there exists $m < n$ satisfying $p(m)$ or $p(n)$ holds. In other words: \[ (\exists m < n + 1, p(m)) \leftrightarrow (\exists m < n, p(m)) \lor p(n) \]
Nat.exists_lt_succ_left' theorem
{p : (m : Nat) → (m < n + 1) → Prop} : (∃ m, ∃ (h : m < n + 1), p m h) ↔ p 0 (by omega) ∨ (∃ m, ∃ (h : m < n), p (m + 1) (by omega))
Full source
/-- Dependent variant of `exists_lt_succ_left`. -/
theorem exists_lt_succ_left' {p : (m : Nat) → (m < n + 1) → Prop} :
    (∃ m, ∃ (h : m < n + 1), p m h) ↔ p 0 (by omega) ∨ (∃ m, ∃ (h : m < n), p (m + 1) (by omega)) := by
  constructor
  · rintro ⟨_|m, h, w⟩
    · exact .inl w
    · exact .inr ⟨m, by omega, w⟩
  · rintro (w|⟨m, h, w⟩)
    · exact ⟨0, by omega, w⟩
    · exact ⟨m + 1, by omega, w⟩
Existence of Elements Less Than Successor: Base Case or Successor Case
Informal description
For any predicate $p$ on natural numbers $m$ with a proof that $m < n + 1$, there exists an $m$ such that $m < n + 1$ and $p(m, h)$ holds if and only if either $p(0, h_0)$ holds (where $h_0$ is a proof that $0 < n + 1$), or there exists an $m < n$ such that $p(m + 1, h_1)$ holds (where $h_1$ is a proof that $m + 1 < n + 1$).
Nat.exists_lt_succ_left theorem
{p : Nat → Prop} : (∃ m, m < n + 1 ∧ p m) ↔ p 0 ∨ (∃ m, m < n ∧ p (m + 1))
Full source
/-- See `exists_lt_succ_left'` for a variant where `p` takes the bound as an argument. -/
theorem exists_lt_succ_left {p : Nat → Prop} :
    (∃ m, m < n + 1 ∧ p m) ↔ p 0 ∨ (∃ m, m < n ∧ p (m + 1)) := by
  simpa using exists_lt_succ_left' (p := fun m _ => p m)
Existence of Elements Less Than Successor: Base Case or Successor Case (Simplified)
Informal description
For any natural number $n$ and predicate $p$ on natural numbers, there exists an $m < n + 1$ such that $p(m)$ holds if and only if either $p(0)$ holds or there exists an $m < n$ such that $p(m + 1)$ holds.
Nat.add_add_add_comm theorem
(a b c d : Nat) : (a + b) + (c + d) = (a + c) + (b + d)
Full source
protected theorem add_add_add_comm (a b c d : Nat) : (a + b) + (c + d) = (a + c) + (b + d) := by
  rw [Nat.add_assoc, Nat.add_assoc, Nat.add_left_comm b]
Commutative Rearrangement of Double Addition in Natural Numbers: $(a + b) + (c + d) = (a + c) + (b + d)$
Informal description
For any natural numbers $a$, $b$, $c$, and $d$, the following equality holds: $$(a + b) + (c + d) = (a + c) + (b + d).$$
Nat.one_add theorem
(n) : 1 + n = succ n
Full source
theorem one_add (n) : 1 + n = succ n := Nat.add_comm ..
One Plus Natural Number Equals Successor: $1 + n = \text{succ}(n)$
Informal description
For any natural number $n$, the sum of $1$ and $n$ is equal to the successor of $n$, i.e., $1 + n = \text{succ}(n)$.
Nat.succ_eq_one_add theorem
(n) : succ n = 1 + n
Full source
theorem succ_eq_one_add (n) : succ n = 1 + n := (one_add _).symm
Successor as One Plus Natural Number: $\text{succ}(n) = 1 + n$
Informal description
For any natural number $n$, the successor of $n$ is equal to $1 + n$, i.e., $\text{succ}(n) = 1 + n$.
Nat.succ_add_eq_add_succ theorem
(a b) : succ a + b = a + succ b
Full source
theorem succ_add_eq_add_succ (a b) : succ a + b = a + succ b := Nat.succ_add ..
Successor Addition Commutativity: $(a + 1) + b = a + (b + 1)$
Informal description
For any natural numbers $a$ and $b$, the successor of $a$ plus $b$ equals $a$ plus the successor of $b$, i.e., $(a + 1) + b = a + (b + 1)$.
Nat.add_left_eq_self theorem
{a b : Nat} : a + b = b ↔ a = 0
Full source
@[simp] protected theorem add_left_eq_self  {a b : Nat} : a + b = b ↔ a = 0 := by omega
Left Addition Equals Identity if and only if Addend is Zero: $a + b = b \leftrightarrow a = 0$
Informal description
For any natural numbers $a$ and $b$, the equality $a + b = b$ holds if and only if $a = 0$.
Nat.add_right_eq_self theorem
{a b : Nat} : a + b = a ↔ b = 0
Full source
@[simp] protected theorem add_right_eq_self {a b : Nat} : a + b = a ↔ b = 0 := by omega
Right Addition Identity in Natural Numbers: $a + b = a \leftrightarrow b = 0$
Informal description
For any natural numbers $a$ and $b$, the equality $a + b = a$ holds if and only if $b = 0$.
Nat.self_eq_add_right theorem
{a b : Nat} : a = a + b ↔ b = 0
Full source
@[simp] protected theorem self_eq_add_right {a b : Nat} : a = a + b ↔ b = 0 := by omega
Right Additive Identity in Natural Numbers: $a = a + b \leftrightarrow b = 0$
Informal description
For any natural numbers $a$ and $b$, the equality $a = a + b$ holds if and only if $b = 0$.
Nat.self_eq_add_left theorem
{a b : Nat} : a = b + a ↔ b = 0
Full source
@[simp] protected theorem self_eq_add_left  {a b : Nat} : a = b + a ↔ b = 0 := by omega
Right Additive Identity in Natural Numbers: $a = b + a \leftrightarrow b = 0$
Informal description
For any natural numbers $a$ and $b$, the equality $a = b + a$ holds if and only if $b = 0$.
Nat.lt_of_add_lt_add_right theorem
: ∀ {n : Nat}, k + n < m + n → k < m
Full source
protected theorem lt_of_add_lt_add_right : ∀ {n : Nat}, k + n < m + n → k < m
  | 0, h => h
  | _+1, h => Nat.lt_of_add_lt_add_right (Nat.lt_of_succ_lt_succ h)
Right Cancellation of Addition Preserves Strict Inequality in Natural Numbers
Informal description
For any natural numbers $k$, $m$, and $n$, if $k + n < m + n$, then $k < m$.
Nat.lt_of_add_lt_add_left theorem
{n : Nat} : n + k < n + m → k < m
Full source
protected theorem lt_of_add_lt_add_left {n : Nat} : n + k < n + m → k < m := by
  rw [Nat.add_comm n, Nat.add_comm n]; exact Nat.lt_of_add_lt_add_right
Left Cancellation of Addition Preserves Strict Inequality in Natural Numbers
Informal description
For any natural numbers $n$, $k$, and $m$, if $n + k < n + m$, then $k < m$.
Nat.add_lt_add_of_le_of_lt theorem
{a b c d : Nat} (hle : a ≤ b) (hlt : c < d) : a + c < b + d
Full source
protected theorem add_lt_add_of_le_of_lt {a b c d : Nat} (hle : a ≤ b) (hlt : c < d) :
    a + c < b + d :=
  Nat.lt_of_le_of_lt (Nat.add_le_add_right hle _) (Nat.add_lt_add_left hlt _)
Addition Preserves Mixed Inequalities in Natural Numbers
Informal description
For any natural numbers $a, b, c, d$, if $a \leq b$ and $c < d$, then $a + c < b + d$.
Nat.add_lt_add_of_lt_of_le theorem
{a b c d : Nat} (hlt : a < b) (hle : c ≤ d) : a + c < b + d
Full source
protected theorem add_lt_add_of_lt_of_le {a b c d : Nat} (hlt : a < b) (hle : c ≤ d) :
    a + c < b + d :=
  Nat.lt_of_le_of_lt (Nat.add_le_add_left hle _) (Nat.add_lt_add_right hlt _)
Addition Preserves Mixed Inequalities in Natural Numbers
Informal description
For any natural numbers $a, b, c, d$, if $a < b$ and $c \leq d$, then $a + c < b + d$.
Nat.pos_of_lt_add_right theorem
(h : n < n + k) : 0 < k
Full source
protected theorem pos_of_lt_add_right (h : n < n + k) : 0 < k :=
  Nat.lt_of_add_lt_add_left h
Positivity from Right Addition Inequality in Natural Numbers
Informal description
For any natural numbers $n$ and $k$, if $n < n + k$, then $0 < k$.
Nat.pos_of_lt_add_left theorem
: n < k + n → 0 < k
Full source
protected theorem pos_of_lt_add_left : n < k + n → 0 < k := by
  rw [Nat.add_comm]; exact Nat.pos_of_lt_add_right
Positivity from Left Addition Inequality in Natural Numbers
Informal description
For any natural numbers $n$ and $k$, if $n < k + n$, then $0 < k$.
Nat.add_pos_left theorem
(h : 0 < m) (n) : 0 < m + n
Full source
protected theorem add_pos_left (h : 0 < m) (n) : 0 < m + n :=
  Nat.lt_of_lt_of_le h (Nat.le_add_right ..)
Positivity of Sum with Positive Left Term in Natural Numbers
Informal description
For any natural numbers $m$ and $n$, if $0 < m$, then $0 < m + n$.
Nat.add_pos_right theorem
(m) (h : 0 < n) : 0 < m + n
Full source
protected theorem add_pos_right (m) (h : 0 < n) : 0 < m + n :=
  Nat.lt_of_lt_of_le h (Nat.le_add_left ..)
Positivity of Sum with Positive Right Term in Natural Numbers
Informal description
For any natural numbers $m$ and $n$, if $0 < n$, then $0 < m + n$.
Nat.add_self_ne_one theorem
: ∀ n, n + n ≠ 1
Full source
protected theorem add_self_ne_one : ∀ n, n + n ≠ 1
  | n+1, h => by rw [Nat.succ_add, Nat.succ.injEq] at h; contradiction
Sum of a Natural Number with Itself is Not One ($n + n \neq 1$)
Informal description
For any natural number $n$, the sum $n + n$ is not equal to $1$.
Nat.le_iff_lt_add_one theorem
: x ≤ y ↔ x < y + 1
Full source
theorem le_iff_lt_add_one : x ≤ y ↔ x < y + 1 := by
  omega
Natural Order Characterization: $x \leq y \leftrightarrow x < y + 1$
Informal description
For any natural numbers $x$ and $y$, the inequality $x \leq y$ holds if and only if $x$ is strictly less than $y + 1$.
Nat.sub_one theorem
(n) : n - 1 = pred n
Full source
protected theorem sub_one (n) : n - 1 = pred n := rfl
Subtraction of One Equals Predecessor in Natural Numbers
Informal description
For any natural number $n$, the difference $n - 1$ is equal to the predecessor of $n$, i.e., $n - 1 = \mathrm{pred}(n)$.
Nat.one_sub theorem
: ∀ n, 1 - n = if n = 0 then 1 else 0
Full source
protected theorem one_sub : ∀ n, 1 - n = if n = 0 then 1 else 0
  | 0 => rfl
  | _+1 => by rw [if_neg (Nat.succ_ne_zero _), Nat.succ_sub_succ, Nat.zero_sub]
Truncated Subtraction of One Minus Natural Number: $1 - n = \text{if } n = 0 \text{ then } 1 \text{ else } 0$
Informal description
For any natural number $n$, the truncated subtraction $1 - n$ equals $1$ if $n = 0$ and $0$ otherwise.
Nat.succ_sub_sub_succ theorem
(n m k) : succ n - m - succ k = n - m - k
Full source
theorem succ_sub_sub_succ (n m k) : succ n - m - succ k = n - m - k := by
  rw [Nat.sub_sub, Nat.sub_sub, add_succ, succ_sub_succ]
Successor Subtraction Identity: $(n+1) - m - (k+1) = n - m - k$
Informal description
For any natural numbers $n$, $m$, and $k$, the expression $(n + 1) - m - (k + 1)$ equals $n - m - k$.
Nat.add_sub_sub_add_right theorem
(n m k l : Nat) : (n + l) - m - (k + l) = n - m - k
Full source
theorem add_sub_sub_add_right (n m k l : Nat) :
    (n + l) - m - (k + l) = n - m - k := by
  rw [Nat.sub_sub, Nat.sub_sub, ←Nat.add_assoc, Nat.add_sub_add_right]
Subtraction Identity with Added Terms: $(n + l) - m - (k + l) = n - m - k$
Informal description
For any natural numbers $n$, $m$, $k$, and $l$, the following equality holds: $$(n + l) - m - (k + l) = n - m - k$$
Nat.sub_right_comm theorem
(m n k : Nat) : m - n - k = m - k - n
Full source
protected theorem sub_right_comm (m n k : Nat) : m - n - k = m - k - n := by
  rw [Nat.sub_sub, Nat.sub_sub, Nat.add_comm]
Right Commutativity of Subtraction: $m - n - k = m - k - n$
Informal description
For any natural numbers $m$, $n$, and $k$, the difference $m - n - k$ is equal to $m - k - n$.
Nat.add_sub_cancel_right theorem
(n m : Nat) : (n + m) - m = n
Full source
protected theorem add_sub_cancel_right (n m : Nat) : (n + m) - m = n := Nat.add_sub_cancel ..
Right Cancellation of Addition and Subtraction: $(n + m) - m = n$
Informal description
For any natural numbers $n$ and $m$, the difference $(n + m) - m$ equals $n$.
Nat.add_sub_cancel' theorem
{n m : Nat} (h : m ≤ n) : m + (n - m) = n
Full source
@[simp] protected theorem add_sub_cancel' {n m : Nat} (h : m ≤ n) : m + (n - m) = n := by
  rw [Nat.add_comm, Nat.sub_add_cancel h]
Additive-Subtractive Cancellation for Natural Numbers: $m + (n - m) = n$ when $m \leq n$
Informal description
For any natural numbers $n$ and $m$ such that $m \leq n$, the sum of $m$ and the difference $n - m$ equals $n$, i.e., $m + (n - m) = n$.
Nat.succ_sub_one theorem
(n) : succ n - 1 = n
Full source
theorem succ_sub_one (n) : succ n - 1 = n := rfl
Successor Minus One Identity: $(n + 1) - 1 = n$
Informal description
For any natural number $n$, the successor of $n$ minus one equals $n$, i.e., $(n + 1) - 1 = n$.
Nat.one_add_sub_one theorem
(n : Nat) : (1 + n) - 1 = n
Full source
protected theorem one_add_sub_one (n : Nat) : (1 + n) - 1 = n := Nat.add_sub_cancel_left 1 _
One Plus Minus One Identity: $(1 + n) - 1 = n$
Informal description
For any natural number $n$, the expression $(1 + n) - 1$ equals $n$.
Nat.sub_sub_self theorem
{n m : Nat} (h : m ≤ n) : n - (n - m) = m
Full source
protected theorem sub_sub_self {n m : Nat} (h : m ≤ n) : n - (n - m) = m :=
  (Nat.sub_eq_iff_eq_add (Nat.sub_le ..)).2 (Nat.add_sub_of_le h).symm
Double Subtraction Identity: $n - (n - m) = m$ when $m \leq n$
Informal description
For any natural numbers $n$ and $m$ such that $m \leq n$, the expression $n - (n - m)$ equals $m$.
Nat.sub_add_comm theorem
{n m k : Nat} (h : k ≤ n) : n + m - k = n - k + m
Full source
protected theorem sub_add_comm {n m k : Nat} (h : k ≤ n) : n + m - k = n - k + m := by
  rw [Nat.sub_eq_iff_eq_add (Nat.le_trans h (Nat.le_add_right ..))]
  rwa [Nat.add_right_comm, Nat.sub_add_cancel]
Subtraction-Additive Commutativity: $(n + m) - k = (n - k) + m$ when $k \leq n$
Informal description
For any natural numbers $n$, $m$, and $k$ such that $k \leq n$, the expression $(n + m) - k$ equals $(n - k) + m$.
Nat.sub_pos_iff_lt theorem
: 0 < n - m ↔ m < n
Full source
protected theorem sub_pos_iff_lt : 0 < n - m ↔ m < n :=
  ⟨Nat.lt_of_sub_pos, Nat.sub_pos_of_lt⟩
Positivity of Difference Equivalent to Strict Inequality in Natural Numbers
Informal description
For any natural numbers $n$ and $m$, the truncated difference $n - m$ is positive if and only if $m$ is strictly less than $n$, i.e., $0 < n - m \leftrightarrow m < n$.
Nat.le_sub_iff_add_le theorem
{n : Nat} (h : k ≤ m) : n ≤ m - k ↔ n + k ≤ m
Full source
protected theorem le_sub_iff_add_le {n : Nat} (h : k ≤ m) : n ≤ m - k ↔ n + k ≤ m :=
  ⟨Nat.add_le_of_le_sub h, Nat.le_sub_of_add_le⟩
Inequality Relating Subtraction and Addition in Natural Numbers: $n \leq m - k \leftrightarrow n + k \leq m$
Informal description
For any natural numbers $n$, $k$, and $m$ such that $k \leq m$, the inequality $n \leq m - k$ holds if and only if $n + k \leq m$.
Nat.add_lt_iff_lt_sub_right theorem
{a b c : Nat} : a + b < c ↔ a < c - b
Full source
theorem add_lt_iff_lt_sub_right {a b c : Nat} : a + b < c ↔ a < c - b := by
  omega
Addition-Subtraction Inequality: $a + b < c \leftrightarrow a < c - b$
Informal description
For any natural numbers $a$, $b$, and $c$, the inequality $a + b < c$ holds if and only if $a < c - b$.
Nat.add_le_of_le_sub' theorem
{n k m : Nat} (h : m ≤ k) : n ≤ k - m → m + n ≤ k
Full source
protected theorem add_le_of_le_sub' {n k m : Nat} (h : m ≤ k) : n ≤ k - m → m + n ≤ k :=
  Nat.add_comm .. ▸ Nat.add_le_of_le_sub h
Addition Preserves Order Under Truncated Subtraction: $m \leq k \land n \leq k - m \implies m + n \leq k$
Informal description
For any natural numbers $n$, $k$, and $m$ such that $m \leq k$, if $n \leq k - m$, then $m + n \leq k$.
Nat.le_sub_of_add_le' theorem
{n k m : Nat} : m + n ≤ k → n ≤ k - m
Full source
protected theorem le_sub_of_add_le' {n k m : Nat} : m + n ≤ k → n ≤ k - m :=
  Nat.add_comm .. ▸ Nat.le_sub_of_add_le
Subtraction Preserves Order Under Addition: $m + n \leq k \implies n \leq k - m$
Informal description
For any natural numbers $n$, $k$, and $m$, if $m + n \leq k$, then $n \leq k - m$.
Nat.le_sub_iff_add_le' theorem
{n : Nat} (h : k ≤ m) : n ≤ m - k ↔ k + n ≤ m
Full source
protected theorem le_sub_iff_add_le' {n : Nat} (h : k ≤ m) : n ≤ m - k ↔ k + n ≤ m :=
  ⟨Nat.add_le_of_le_sub' h, Nat.le_sub_of_add_le'⟩
Inequality Equivalence for Truncated Subtraction and Addition: $n \leq m - k \leftrightarrow k + n \leq m$
Informal description
For any natural numbers $n$, $k$, and $m$ such that $k \leq m$, the inequality $n \leq m - k$ holds if and only if $k + n \leq m$.
Nat.le_of_sub_le_sub_left theorem
: ∀ {n k m : Nat}, n ≤ k → k - m ≤ k - n → n ≤ m
Full source
protected theorem le_of_sub_le_sub_left : ∀ {n k m : Nat}, n ≤ k → k - m ≤ k - n → n ≤ m
  | 0, _, _, _, _ => Nat.zero_le ..
  | _+1, _, 0, h₀, h₁ =>
    absurd (Nat.sub_lt (Nat.zero_lt_of_lt h₀) (Nat.zero_lt_succ _)) (Nat.not_lt.2 h₁)
  | _+1, _+1, _+1, h₀, h₁ => by
    simp only [Nat.succ_sub_succ] at h₁
    exact succ_le_succ <| Nat.le_of_sub_le_sub_left (Nat.le_of_succ_le_succ h₀) h₁
Order Reversal in Truncated Subtraction: $n \leq k \land k - m \leq k - n \to n \leq m$
Informal description
For any natural numbers $n$, $k$, and $m$, if $n \leq k$ and $k - m \leq k - n$, then $n \leq m$.
Nat.sub_le_sub_iff_left theorem
{n m k : Nat} (h : n ≤ k) : k - m ≤ k - n ↔ n ≤ m
Full source
protected theorem sub_le_sub_iff_left {n m k : Nat} (h : n ≤ k) : k - m ≤ k - n ↔ n ≤ m :=
  ⟨Nat.le_of_sub_le_sub_left h, fun h => Nat.sub_le_sub_left h _⟩
Truncated Subtraction Order Reversal Criterion: $k - m \leq k - n \leftrightarrow n \leq m$ (given $n \leq k$)
Informal description
For any natural numbers $n$, $m$, and $k$ such that $n \leq k$, the inequality $k - m \leq k - n$ holds if and only if $n \leq m$.
Nat.sub_lt_of_pos_le theorem
(h₀ : 0 < a) (h₁ : a ≤ b) : b - a < b
Full source
protected theorem sub_lt_of_pos_le (h₀ : 0 < a) (h₁ : a ≤ b) : b - a < b :=
  Nat.sub_lt (Nat.lt_of_lt_of_le h₀ h₁) h₀
Truncated Subtraction Decreases Natural Numbers Under Positive Subtrahend
Informal description
For any natural numbers $a$ and $b$ such that $0 < a$ and $a \leq b$, the truncated subtraction $b - a$ is strictly less than $b$.
Nat.sub_lt_self abbrev
Full source
protected abbrev sub_lt_self := @Nat.sub_lt_of_pos_le
Truncated Subtraction Decreases Natural Numbers Under Positive Conditions
Informal description
For any natural numbers $a$ and $b$ such that $0 < a$ and $0 < b$, the truncated subtraction $a - b$ is strictly less than $a$.
Nat.add_lt_of_lt_sub' theorem
{a b c : Nat} : b < c - a → a + b < c
Full source
theorem add_lt_of_lt_sub' {a b c : Nat} : b < c - a → a + b < c := by
  rw [Nat.add_comm]; exact Nat.add_lt_of_lt_sub
Addition Preserves Strict Inequality Under Reverse Subtraction: $b < c - a \implies a + b < c$
Informal description
For any natural numbers $a$, $b$, and $c$, if $b < c - a$, then $a + b < c$.
Nat.sub_add_lt_sub theorem
(h₁ : m + k ≤ n) (h₂ : 0 < k) : n - (m + k) < n - m
Full source
protected theorem sub_add_lt_sub (h₁ : m + k ≤ n) (h₂ : 0 < k) : n - (m + k) < n - m := by
  rw [← Nat.sub_sub]; exact Nat.sub_lt_of_pos_le h₂ (Nat.le_sub_of_add_le' h₁)
Subtraction Inequality: $n - (m + k) < n - m$ under $m + k \leq n$ and $0 < k$
Informal description
For any natural numbers $m$, $k$, and $n$ such that $m + k \leq n$ and $0 < k$, the difference $n - (m + k)$ is strictly less than $n - m$.
Nat.sub_one_lt_of_le theorem
(h₀ : 0 < a) (h₁ : a ≤ b) : a - 1 < b
Full source
theorem sub_one_lt_of_le (h₀ : 0 < a) (h₁ : a ≤ b) : a - 1 < b :=
  Nat.lt_of_lt_of_le (Nat.pred_lt_of_lt h₀) h₁
Predecessor Inequality for Natural Numbers: $a - 1 < b$ when $0 < a \leq b$
Informal description
For any natural numbers $a$ and $b$ such that $0 < a$ and $a \leq b$, we have $a - 1 < b$.
Nat.sub_lt_succ theorem
(a b) : a - b < succ a
Full source
theorem sub_lt_succ (a b) : a - b < succ a := lt_succ_of_le (sub_le a b)
Truncated Subtraction is Less Than Successor: $a - b < a + 1$
Informal description
For any natural numbers $a$ and $b$, the truncated subtraction $a - b$ is strictly less than the successor of $a$, i.e., $a - b < a + 1$.
Nat.sub_lt_add_one theorem
(a b) : a - b < a + 1
Full source
theorem sub_lt_add_one (a b) : a - b < a + 1 := lt_add_one_of_le (sub_le a b)
Truncated Subtraction is Less Than Successor: $a - b < a + 1$
Informal description
For any natural numbers $a$ and $b$, the truncated subtraction $a - b$ is strictly less than $a + 1$.
Nat.sub_one_sub_lt theorem
(h : i < n) : n - 1 - i < n
Full source
theorem sub_one_sub_lt (h : i < n) : n - 1 - i < n := by
  rw [Nat.sub_right_comm]; exact Nat.sub_one_lt_of_le (Nat.sub_pos_of_lt h) (Nat.sub_le ..)
Difference of Predecessor and Index is Less Than Original Number: $n - 1 - i < n$ when $i < n$
Informal description
For any natural numbers $i$ and $n$ such that $i < n$, it holds that $n - 1 - i < n$.
Nat.exists_eq_add_of_le theorem
(h : m ≤ n) : ∃ k : Nat, n = m + k
Full source
protected theorem exists_eq_add_of_le (h : m ≤ n) : ∃ k : Nat, n = m + k :=
  ⟨n - m, (add_sub_of_le h).symm⟩
Existence of Difference as Natural Number for $m \leq n$
Informal description
For any natural numbers $m$ and $n$ such that $m \leq n$, there exists a natural number $k$ such that $n = m + k$.
Nat.exists_eq_add_of_le' theorem
(h : m ≤ n) : ∃ k : Nat, n = k + m
Full source
protected theorem exists_eq_add_of_le' (h : m ≤ n) : ∃ k : Nat, n = k + m :=
  ⟨n - m, (Nat.sub_add_cancel h).symm⟩
Existence of Additive Decomposition for Natural Numbers with $m \leq n$
Informal description
For any natural numbers $m$ and $n$ such that $m \leq n$, there exists a natural number $k$ such that $n = k + m$.
Nat.succ_min_succ theorem
(x y) : min (succ x) (succ y) = succ (min x y)
Full source
theorem succ_min_succ (x y) : min (succ x) (succ y) = succ (min x y) := by
  cases Nat.le_total x y with
  | inl h => rw [Nat.min_eq_left h, Nat.min_eq_left (Nat.succ_le_succ h)]
  | inr h => rw [Nat.min_eq_right h, Nat.min_eq_right (Nat.succ_le_succ h)]
Successor Preserves Minimum: $\min(x+1, y+1) = \min(x, y) + 1$
Informal description
For any natural numbers $x$ and $y$, the minimum of their successors equals the successor of their minimum, i.e., $\min(x+1, y+1) = (\min(x, y)) + 1$.
Nat.min_self theorem
(a : Nat) : min a a = a
Full source
@[simp] protected theorem min_self (a : Nat) : min a a = a := Nat.min_eq_left (Nat.le_refl _)
Idempotence of Minimum on Natural Numbers
Informal description
For any natural number $a$, the minimum of $a$ and itself is equal to $a$, i.e., $\min(a, a) = a$.
Nat.instIdempotentOpMin instance
: Std.IdempotentOp (α := Nat) min
Full source
instance : Std.IdempotentOp (α := Nat) min := ⟨Nat.min_self⟩
Idempotence of the Minimum Operation on Natural Numbers
Informal description
The minimum operation $\min$ on natural numbers is idempotent, meaning that for any natural number $a$, $\min(a, a) = a$.
Nat.min_assoc theorem
: ∀ (a b c : Nat), min (min a b) c = min a (min b c)
Full source
@[simp] protected theorem min_assoc : ∀ (a b c : Nat), min (min a b) c = min a (min b c)
  | 0, _, _ => by rw [Nat.zero_min, Nat.zero_min, Nat.zero_min]
  | _, 0, _ => by rw [Nat.zero_min, Nat.min_zero, Nat.zero_min]
  | _, _, 0 => by rw [Nat.min_zero, Nat.min_zero, Nat.min_zero]
  | _+1, _+1, _+1 => by simp only [Nat.succ_min_succ]; exact congrArg succ <| Nat.min_assoc ..
Associativity of Minimum Operation on Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, the minimum operation is associative, i.e., $\min(\min(a, b), c) = \min(a, \min(b, c))$.
Nat.instAssociativeMin instance
: Std.Associative (α := Nat) min
Full source
instance : Std.Associative (α := Nat) min := ⟨Nat.min_assoc⟩
Associativity of Minimum Operation on Natural Numbers
Informal description
The minimum operation $\min$ on natural numbers is associative. That is, for any natural numbers $a$, $b$, and $c$, we have $\min(\min(a, b), c) = \min(a, \min(b, c))$.
Nat.min_self_assoc theorem
{m n : Nat} : min m (min m n) = min m n
Full source
@[simp] protected theorem min_self_assoc {m n : Nat} : min m (min m n) = min m n := by
  rw [← Nat.min_assoc, Nat.min_self]
Idempotence of Minimum Operation: $\min(m, \min(m, n)) = \min(m, n)$
Informal description
For any natural numbers $m$ and $n$, the minimum of $m$ and the minimum of $m$ and $n$ equals the minimum of $m$ and $n$, i.e., $\min(m, \min(m, n)) = \min(m, n)$.
Nat.min_self_assoc' theorem
{m n : Nat} : min n (min m n) = min n m
Full source
@[simp] protected theorem min_self_assoc' {m n : Nat} : min n (min m n) = min n m := by
  rw [Nat.min_comm m n, ← Nat.min_assoc, Nat.min_self]
Associative Property of Minimum Operation: $\min(n, \min(m, n)) = \min(n, m)$
Informal description
For any natural numbers $m$ and $n$, the minimum of $n$ and the minimum of $m$ and $n$ equals the minimum of $n$ and $m$, i.e., $\min(n, \min(m, n)) = \min(n, m)$.
Nat.min_add_left_self theorem
{a b : Nat} : min a (b + a) = a
Full source
@[simp] theorem min_add_left_self {a b : Nat} : min a (b + a) = a := by
  rw [Nat.min_def]
  simp
Minimum of a Number and its Sum with Another Equals the Number
Informal description
For any natural numbers $a$ and $b$, the minimum of $a$ and $b + a$ equals $a$, i.e., $\min(a, b + a) = a$.
Nat.min_add_right_self theorem
{a b : Nat} : min a (a + b) = a
Full source
@[simp] theorem min_add_right_self {a b : Nat} : min a (a + b) = a := by
  rw [Nat.min_def]
  simp
Minimum of a Number and Its Sum with Another Number
Informal description
For any natural numbers $a$ and $b$, the minimum of $a$ and $a + b$ is equal to $a$, i.e., $\min(a, a + b) = a$.
Nat.add_left_min_self theorem
{a b : Nat} : min (b + a) a = a
Full source
@[simp] theorem add_left_min_self {a b : Nat} : min (b + a) a = a := by
  rw [Nat.min_comm, min_add_left_self]
Minimum of Sum and Number Equals the Number (Left Addition Variant)
Informal description
For any natural numbers $a$ and $b$, the minimum of $b + a$ and $a$ equals $a$, i.e., $\min(b + a, a) = a$.
Nat.add_right_min_self theorem
{a b : Nat} : min (a + b) a = a
Full source
@[simp] theorem add_right_min_self {a b : Nat} : min (a + b) a = a := by
  rw [Nat.min_comm, min_add_right_self]
Minimum of Sum and First Term Equals First Term
Informal description
For any natural numbers $a$ and $b$, the minimum of $a + b$ and $a$ is equal to $a$, i.e., $\min(a + b, a) = a$.
Nat.sub_sub_eq_min theorem
: ∀ (a b : Nat), a - (a - b) = min a b
Full source
protected theorem sub_sub_eq_min : ∀ (a b : Nat), a - (a - b) = min a b
  | 0, _ => by rw [Nat.zero_sub, Nat.zero_min]
  | _, 0 => by rw [Nat.sub_zero, Nat.sub_self, Nat.min_zero]
  | _+1, _+1 => by
    rw [Nat.succ_sub_succ, Nat.succ_min_succ, Nat.succ_sub (Nat.sub_le ..)]
    exact congrArg succ <| Nat.sub_sub_eq_min ..
Difference of Differences Equals Minimum: $a - (a - b) = \min(a, b)$
Informal description
For any natural numbers $a$ and $b$, the difference $a - (a - b)$ equals the minimum of $a$ and $b$, i.e., $a - (a - b) = \min(a, b)$.
Nat.sub_add_min_cancel theorem
(n m : Nat) : n - m + min n m = n
Full source
@[simp] protected theorem sub_add_min_cancel (n m : Nat) : n - m + min n m = n := by
  rw [Nat.sub_eq_sub_min, Nat.sub_add_cancel (Nat.min_le_left ..)]
Subtraction-Minimum Cancellation for Natural Numbers: $(n - m) + \min(n, m) = n$
Informal description
For any natural numbers $n$ and $m$, the sum of the difference $n - m$ and the minimum of $n$ and $m$ equals $n$, i.e., $(n - m) + \min(n, m) = n$.
Nat.succ_max_succ theorem
(x y) : max (succ x) (succ y) = succ (max x y)
Full source
protected theorem succ_max_succ (x y) : max (succ x) (succ y) = succ (max x y) := by
  cases Nat.le_total x y with
  | inl h => rw [Nat.max_eq_right h, Nat.max_eq_right (Nat.succ_le_succ h)]
  | inr h => rw [Nat.max_eq_left h, Nat.max_eq_left (Nat.succ_le_succ h)]
Successor Commutes with Maximum: $\max(x+1, y+1) = \max(x, y) + 1$
Informal description
For any natural numbers $x$ and $y$, the maximum of their successors equals the successor of their maximum, i.e., $\max(x+1, y+1) = (\max(x, y)) + 1$.
Nat.max_self theorem
(a : Nat) : max a a = a
Full source
@[simp] protected theorem max_self (a : Nat) : max a a = a := Nat.max_eq_right (Nat.le_refl _)
Idempotence of Maximum for Natural Numbers: $\max(a, a) = a$
Informal description
For any natural number $a$, the maximum of $a$ and itself is equal to $a$, i.e., $\max(a, a) = a$.
Nat.instIdempotentOpMax instance
: Std.IdempotentOp (α := Nat) max
Full source
instance : Std.IdempotentOp (α := Nat) max := ⟨Nat.max_self⟩
Idempotence of Maximum on Natural Numbers
Informal description
The maximum operation $\max$ on natural numbers is idempotent, meaning that for any natural number $a$, we have $\max(a, a) = a$.
Nat.instLawfulIdentityMaxOfNat instance
: Std.LawfulIdentity (α := Nat) max 0
Full source
instance : Std.LawfulIdentity (α := Nat) max 0 where
  left_id := Nat.zero_max
  right_id := Nat.max_zero
Zero as Identity for Maximum on Natural Numbers
Informal description
The natural number $0$ is a verified left and right identity element for the maximum operation $\max$ on $\mathbb{N}$. That is, for any natural number $a$, we have $\max(0, a) = a$ and $\max(a, 0) = a$.
Nat.max_assoc theorem
: ∀ (a b c : Nat), max (max a b) c = max a (max b c)
Full source
@[simp] protected theorem max_assoc : ∀ (a b c : Nat), max (max a b) c = max a (max b c)
  | 0, _, _ => by rw [Nat.zero_max, Nat.zero_max]
  | _, 0, _ => by rw [Nat.zero_max, Nat.max_zero]
  | _, _, 0 => by rw [Nat.max_zero, Nat.max_zero]
  | _+1, _+1, _+1 => by simp only [Nat.succ_max_succ]; exact congrArg succ <| Nat.max_assoc ..
Associativity of Maximum Operation on Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, the maximum operation satisfies the associativity property: $$\max(\max(a, b), c) = \max(a, \max(b, c))$$
Nat.instAssociativeMax instance
: Std.Associative (α := Nat) max
Full source
instance : Std.Associative (α := Nat) max := ⟨Nat.max_assoc⟩
Associativity of Maximum on Natural Numbers
Informal description
The maximum operation $\max$ on natural numbers is associative.
Nat.max_add_left_self theorem
{a b : Nat} : max a (b + a) = b + a
Full source
@[simp] theorem max_add_left_self {a b : Nat} : max a (b + a) = b + a := by
  rw [Nat.max_def]
  simp
Maximum of a Natural Number and its Sum with Another is the Sum
Informal description
For any natural numbers $a$ and $b$, the maximum of $a$ and $b + a$ is equal to $b + a$.
Nat.max_add_right_self theorem
{a b : Nat} : max a (a + b) = a + b
Full source
@[simp] theorem max_add_right_self {a b : Nat} : max a (a + b) = a + b := by
  rw [Nat.max_def]
  simp
Maximum of a Number and its Sum with Another Equals the Sum
Informal description
For any natural numbers $a$ and $b$, the maximum of $a$ and $a + b$ equals $a + b$, i.e., $\max(a, a + b) = a + b$.
Nat.add_left_max_self theorem
{a b : Nat} : max (b + a) a = b + a
Full source
@[simp] theorem add_left_max_self {a b : Nat} : max (b + a) a = b + a := by
  rw [Nat.max_comm, max_add_left_self]
Maximum of Sum and Term Equals Sum: $\max(b + a, a) = b + a$
Informal description
For any natural numbers $a$ and $b$, the maximum of $b + a$ and $a$ is equal to $b + a$, i.e., $\max(b + a, a) = b + a$.
Nat.add_right_max_self theorem
{a b : Nat} : max (a + b) a = a + b
Full source
@[simp] theorem add_right_max_self {a b : Nat} : max (a + b) a = a + b := by
  rw [Nat.max_comm, max_add_right_self]
Maximum of Sum and Term Equals Sum for Natural Numbers
Informal description
For any natural numbers $a$ and $b$, the maximum of $a + b$ and $a$ equals $a + b$, i.e., $\max(a + b, a) = a + b$.
Nat.sub_add_eq_max theorem
(a b : Nat) : a - b + b = max a b
Full source
protected theorem sub_add_eq_max (a b : Nat) : a - b + b = max a b := by
  match Nat.le_total a b with
  | .inl hl => rw [Nat.max_eq_right hl, Nat.sub_eq_zero_iff_le.mpr hl, Nat.zero_add]
  | .inr hr => rw [Nat.max_eq_left hr, Nat.sub_add_cancel hr]
Truncated Subtraction-Additive Cancellation Equals Maximum: $(a - b) + b = \max(a, b)$
Informal description
For any natural numbers $a$ and $b$, the sum of the truncated difference $a - b$ and $b$ equals the maximum of $a$ and $b$, i.e., $(a - b) + b = \max(a, b)$.
Nat.sub_eq_max_sub theorem
(n m : Nat) : n - m = max n m - m
Full source
protected theorem sub_eq_max_sub (n m : Nat) : n - m = max n m - m := by
  cases Nat.le_total m n with
  | inl h => rw [Nat.max_eq_left h]
  | inr h => rw [Nat.max_eq_right h, Nat.sub_eq_zero_of_le h, Nat.sub_self]
Difference Equals Maximum Minus Second Argument: $n - m = \max(n, m) - m$
Informal description
For any natural numbers $n$ and $m$, the difference $n - m$ equals the difference between the maximum of $n$ and $m$ and $m$, i.e., $n - m = \max(n, m) - m$.
Nat.max_min_distrib_left theorem
: ∀ (a b c : Nat), max a (min b c) = min (max a b) (max a c)
Full source
protected theorem max_min_distrib_left : ∀ (a b c : Nat), max a (min b c) = min (max a b) (max a c)
  | 0, _, _ => by simp only [Nat.zero_max]
  | _, 0, _ => by
    rw [Nat.zero_min, Nat.max_zero]
    exact Nat.min_eq_left (Nat.le_max_left ..) |>.symm
  | _, _, 0 => by
    rw [Nat.min_zero, Nat.max_zero]
    exact Nat.min_eq_right (Nat.le_max_left ..) |>.symm
  | _+1, _+1, _+1 => by
    simp only [Nat.succ_max_succ, Nat.succ_min_succ]
    exact congrArg succ <| Nat.max_min_distrib_left ..
Left Distributivity of Maximum over Minimum for Natural Numbers: $\max(a, \min(b, c)) = \min(\max(a, b), \max(a, c))$
Informal description
For any natural numbers $a$, $b$, and $c$, the maximum of $a$ and the minimum of $b$ and $c$ equals the minimum of the maximum of $a$ and $b$ and the maximum of $a$ and $c$, i.e., $$\max(a, \min(b, c)) = \min(\max(a, b), \max(a, c)).$$
Nat.min_max_distrib_left theorem
: ∀ (a b c : Nat), min a (max b c) = max (min a b) (min a c)
Full source
protected theorem min_max_distrib_left : ∀ (a b c : Nat), min a (max b c) = max (min a b) (min a c)
  | 0, _, _ => by simp only [Nat.zero_min, Nat.max_self]
  | _, 0, _ => by simp only [Nat.min_zero, Nat.zero_max]
  | _, _, 0 => by simp only [Nat.min_zero, Nat.max_zero]
  | _+1, _+1, _+1 => by
    simp only [Nat.succ_max_succ, Nat.succ_min_succ]
    exact congrArg succ <| Nat.min_max_distrib_left ..
Left Distributivity of Minimum over Maximum for Natural Numbers: $\min(a, \max(b, c)) = \max(\min(a, b), \min(a, c))$
Informal description
For any natural numbers $a$, $b$, and $c$, the minimum of $a$ and the maximum of $b$ and $c$ equals the maximum of the minimum of $a$ and $b$ and the minimum of $a$ and $c$, i.e., $$\min(a, \max(b, c)) = \max(\min(a, b), \min(a, c)).$$
Nat.max_min_distrib_right theorem
(a b c : Nat) : max (min a b) c = min (max a c) (max b c)
Full source
protected theorem max_min_distrib_right (a b c : Nat) :
    max (min a b) c = min (max a c) (max b c) := by
  repeat rw [Nat.max_comm _ c]
  exact Nat.max_min_distrib_left ..
Right Distributivity of Maximum over Minimum for Natural Numbers: $\max(\min(a, b), c) = \min(\max(a, c), \max(b, c))$
Informal description
For any natural numbers $a$, $b$, and $c$, the maximum of the minimum of $a$ and $b$ with $c$ is equal to the minimum of the maximum of $a$ and $c$ with the maximum of $b$ and $c$, i.e., $$\max(\min(a, b), c) = \min(\max(a, c), \max(b, c)).$$
Nat.min_max_distrib_right theorem
(a b c : Nat) : min (max a b) c = max (min a c) (min b c)
Full source
protected theorem min_max_distrib_right (a b c : Nat) :
    min (max a b) c = max (min a c) (min b c) := by
  repeat rw [Nat.min_comm _ c]
  exact Nat.min_max_distrib_left ..
Right Distributivity of Minimum over Maximum for Natural Numbers: $\min(\max(a, b), c) = \max(\min(a, c), \min(b, c))$
Informal description
For any natural numbers $a$, $b$, and $c$, the minimum of the maximum of $a$ and $b$ with $c$ equals the maximum of the minimum of $a$ and $c$ with the minimum of $b$ and $c$, i.e., $$\min(\max(a, b), c) = \max(\min(a, c), \min(b, c)).$$
Nat.pred_min_pred theorem
: ∀ (x y), min (pred x) (pred y) = pred (min x y)
Full source
protected theorem pred_min_pred : ∀ (x y), min (pred x) (pred y) = pred (min x y)
  | 0, _ => by simp only [Nat.pred_zero, Nat.zero_min]
  | _, 0 => by simp only [Nat.pred_zero, Nat.min_zero]
  | _+1, _+1 => by simp only [Nat.pred_succ, Nat.succ_min_succ]
Predecessor Preserves Minimum: $\min(x-1, y-1) = \min(x, y) - 1$
Informal description
For any natural numbers $x$ and $y$, the minimum of their predecessors equals the predecessor of their minimum, i.e., $\min(x-1, y-1) = \min(x, y) - 1$ (where subtraction by 1 is interpreted as the predecessor function, with $0-1 = 0$).
Nat.pred_max_pred theorem
: ∀ (x y), max (pred x) (pred y) = pred (max x y)
Full source
protected theorem pred_max_pred : ∀ (x y), max (pred x) (pred y) = pred (max x y)
  | 0, _ => by simp only [Nat.pred_zero, Nat.zero_max]
  | _, 0 => by simp only [Nat.pred_zero, Nat.max_zero]
  | _+1, _+1 => by simp only [Nat.pred_succ, Nat.succ_max_succ]
Predecessor Commutes with Maximum: $\max(x-1, y-1) = \max(x, y) - 1$
Informal description
For any natural numbers $x$ and $y$, the maximum of their predecessors equals the predecessor of their maximum, i.e., $\max(x-1, y-1) = \max(x, y) - 1$ (where subtraction by 1 is defined as the predecessor function, with $\mathrm{pred}(0) = 0$).
Nat.sub_min_sub_right theorem
: ∀ (a b c : Nat), min (a - c) (b - c) = min a b - c
Full source
protected theorem sub_min_sub_right : ∀ (a b c : Nat), min (a - c) (b - c) = min a b - c
  | _, _, 0 => rfl
  | _, _, _+1 => Eq.trans (Nat.pred_min_pred ..) <| congrArg _ (Nat.sub_min_sub_right ..)
Minimum of Differences Equals Difference of Minimums: $\min(a-c, b-c) = \min(a,b) - c$
Informal description
For any natural numbers $a$, $b$, and $c$, the minimum of the differences $a - c$ and $b - c$ equals the difference between the minimum of $a$ and $b$ and $c$, i.e., $\min(a - c, b - c) = \min(a, b) - c$.
Nat.sub_max_sub_right theorem
: ∀ (a b c : Nat), max (a - c) (b - c) = max a b - c
Full source
protected theorem sub_max_sub_right : ∀ (a b c : Nat), max (a - c) (b - c) = max a b - c
  | _, _, 0 => rfl
  | _, _, _+1 => Eq.trans (Nat.pred_max_pred ..) <| congrArg _ (Nat.sub_max_sub_right ..)
Maximum Commutes with Subtraction: $\max(a - c, b - c) = \max(a, b) - c$
Informal description
For any natural numbers $a$, $b$, and $c$, the maximum of the differences $a - c$ and $b - c$ equals the difference between the maximum of $a$ and $b$ and $c$, i.e., $\max(a - c, b - c) = \max(a, b) - c$.
Nat.sub_min_sub_left theorem
(a b c : Nat) : min (a - b) (a - c) = a - max b c
Full source
protected theorem sub_min_sub_left (a b c : Nat) : min (a - b) (a - c) = a - max b c := by
  omega
Minimum of Left Differences Equals Difference with Maximum: $\min(a-b, a-c) = a - \max(b,c)$
Informal description
For any natural numbers $a$, $b$, and $c$, the minimum of the differences $a - b$ and $a - c$ equals the difference between $a$ and the maximum of $b$ and $c$, i.e., $\min(a - b, a - c) = a - \max(b, c)$.
Nat.sub_max_sub_left theorem
(a b c : Nat) : max (a - b) (a - c) = a - min b c
Full source
protected theorem sub_max_sub_left (a b c : Nat) : max (a - b) (a - c) = a - min b c := by
  omega
Maximum of Differences Equals Difference with Minimum: $\max(a - b, a - c) = a - \min(b, c)$
Informal description
For any natural numbers $a$, $b$, and $c$, the maximum of the differences $a - b$ and $a - c$ equals the difference between $a$ and the minimum of $b$ and $c$, i.e., $$\max(a - b, a - c) = a - \min(b, c).$$
Nat.mul_right_comm theorem
(n m k : Nat) : n * m * k = n * k * m
Full source
protected theorem mul_right_comm (n m k : Nat) : n * m * k = n * k * m := by
  rw [Nat.mul_assoc, Nat.mul_comm m, ← Nat.mul_assoc]
Right Commutativity of Multiplication in Natural Numbers: $n \cdot m \cdot k = n \cdot k \cdot m$
Informal description
For any natural numbers $n$, $m$, and $k$, the product $n \cdot m \cdot k$ is equal to $n \cdot k \cdot m$.
Nat.mul_mul_mul_comm theorem
(a b c d : Nat) : (a * b) * (c * d) = (a * c) * (b * d)
Full source
protected theorem mul_mul_mul_comm (a b c d : Nat) : (a * b) * (c * d) = (a * c) * (b * d) := by
  rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_left_comm b]
Commutativity of Nested Multiplication: $(ab)(cd) = (ac)(bd)$
Informal description
For any natural numbers $a$, $b$, $c$, and $d$, the following equality holds: $$(a \cdot b) \cdot (c \cdot d) = (a \cdot c) \cdot (b \cdot d).$$
Nat.mul_eq_zero theorem
: ∀ {m n}, n * m = 0 ↔ n = 0 ∨ m = 0
Full source
theorem mul_eq_zero : ∀ {m n}, n * m = 0 ↔ n = 0 ∨ m = 0
  | 0, _ => ⟨fun _ => .inr rfl, fun _ => rfl⟩
  | _, 0 => ⟨fun _ => .inl rfl, fun _ => Nat.zero_mul ..⟩
  | _+1, _+1 => ⟨nofun, nofun⟩
Zero Product Property for Natural Numbers: $n \cdot m = 0 \leftrightarrow n = 0 \lor m = 0$
Informal description
For any natural numbers $m$ and $n$, the product $n \cdot m$ equals zero if and only if either $n$ equals zero or $m$ equals zero, i.e., $n \cdot m = 0 \leftrightarrow n = 0 \lor m = 0$.
Nat.mul_ne_zero_iff theorem
: n * m ≠ 0 ↔ n ≠ 0 ∧ m ≠ 0
Full source
protected theorem mul_ne_zero_iff : n * m ≠ 0n * m ≠ 0 ↔ n ≠ 0 ∧ m ≠ 0 := by rw [ne_eq, mul_eq_zero, not_or]
Nonzero Product Property for Natural Numbers: $n \cdot m \neq 0 \leftrightarrow n \neq 0 \land m \neq 0$
Informal description
For any natural numbers $n$ and $m$, the product $n \cdot m$ is nonzero if and only if both $n$ and $m$ are nonzero, i.e., $n \cdot m \neq 0 \leftrightarrow n \neq 0 \land m \neq 0$.
Nat.mul_ne_zero theorem
: n ≠ 0 → m ≠ 0 → n * m ≠ 0
Full source
protected theorem mul_ne_zero : n ≠ 0m ≠ 0n * m ≠ 0 := (Nat.mul_ne_zero_iff.2 ⟨·,·⟩)
Nonzero Product of Nonzero Natural Numbers
Informal description
For any natural numbers $n$ and $m$, if $n \neq 0$ and $m \neq 0$, then their product $n \cdot m \neq 0$.
Nat.ne_zero_of_mul_ne_zero_left theorem
(h : n * m ≠ 0) : n ≠ 0
Full source
protected theorem ne_zero_of_mul_ne_zero_left (h : n * m ≠ 0) : n ≠ 0 :=
  (Nat.mul_ne_zero_iff.1 h).1
Nonzero Factor in Nonzero Product for Natural Numbers
Informal description
For any natural numbers $n$ and $m$, if the product $n \cdot m$ is nonzero, then $n$ is nonzero, i.e., $n \cdot m \neq 0$ implies $n \neq 0$.
Nat.mul_left_cancel theorem
{n m k : Nat} (np : 0 < n) (h : n * m = n * k) : m = k
Full source
protected theorem mul_left_cancel {n m k : Nat} (np : 0 < n) (h : n * m = n * k) : m = k := by
  match Nat.lt_trichotomy m k with
  | Or.inl p =>
    have r : n * m < n * k := Nat.mul_lt_mul_of_pos_left p np
    simp [h] at r
  | Or.inr (Or.inl p) => exact p
  | Or.inr (Or.inr p) =>
    have r : n * k < n * m := Nat.mul_lt_mul_of_pos_left p np
    simp [h] at r
Left Cancellation of Multiplication for Positive Natural Numbers: $n > 0 \land n \cdot m = n \cdot k \Rightarrow m = k$
Informal description
For any natural numbers $n$, $m$, and $k$, if $n > 0$ and $n \cdot m = n \cdot k$, then $m = k$.
Nat.mul_right_cancel theorem
{n m k : Nat} (mp : 0 < m) (h : n * m = k * m) : n = k
Full source
protected theorem mul_right_cancel {n m k : Nat} (mp : 0 < m) (h : n * m = k * m) : n = k := by
  simp [Nat.mul_comm _ m] at h
  apply Nat.mul_left_cancel mp h
Right Cancellation of Multiplication for Positive Natural Numbers: $n \cdot m = k \cdot m \Rightarrow n = k$ when $m > 0$
Informal description
For any natural numbers $n$, $m$, and $k$, if $m > 0$ and $n \cdot m = k \cdot m$, then $n = k$.
Nat.mul_left_cancel_iff theorem
{n : Nat} (p : 0 < n) {m k : Nat} : n * m = n * k ↔ m = k
Full source
protected theorem mul_left_cancel_iff {n : Nat} (p : 0 < n) {m k : Nat} : n * m = n * k ↔ m = k :=
  ⟨Nat.mul_left_cancel p, fun | rfl => rfl⟩
Left Cancellation Law for Multiplication of Natural Numbers: $n > 0 \Rightarrow (n \cdot m = n \cdot k \leftrightarrow m = k)$
Informal description
For any natural numbers $n$, $m$, and $k$ with $n > 0$, the equality $n \cdot m = n \cdot k$ holds if and only if $m = k$.
Nat.mul_right_cancel_iff theorem
{m : Nat} (p : 0 < m) {n k : Nat} : n * m = k * m ↔ n = k
Full source
protected theorem mul_right_cancel_iff {m : Nat} (p : 0 < m) {n k : Nat} : n * m = k * m ↔ n = k :=
  ⟨Nat.mul_right_cancel p, fun | rfl => rfl⟩
Right Cancellation Law for Multiplication of Natural Numbers: $n \cdot m = k \cdot m \leftrightarrow n = k$ when $m > 0$
Informal description
For any natural numbers $n$, $k$, and $m$ with $m > 0$, the equality $n \cdot m = k \cdot m$ holds if and only if $n = k$.
Nat.ne_zero_of_mul_ne_zero_right theorem
(h : n * m ≠ 0) : m ≠ 0
Full source
protected theorem ne_zero_of_mul_ne_zero_right (h : n * m ≠ 0) : m ≠ 0 :=
  (Nat.mul_ne_zero_iff.1 h).2
Nonzero Product Implies Nonzero Right Factor in Natural Numbers
Informal description
For any natural numbers $n$ and $m$, if the product $n \cdot m$ is nonzero, then $m$ is nonzero, i.e., $n \cdot m \neq 0$ implies $m \neq 0$.
Nat.le_mul_of_pos_left theorem
(m) (h : 0 < n) : m ≤ n * m
Full source
protected theorem le_mul_of_pos_left (m) (h : 0 < n) : m ≤ n * m :=
  Nat.le_trans (Nat.le_of_eq (Nat.one_mul _).symm) (Nat.mul_le_mul_right _ h)
Left Multiplication by Positive Number Increases Natural Number
Informal description
For any natural numbers $m$ and $n$ such that $n > 0$, it holds that $m \leq n \cdot m$.
Nat.le_mul_of_pos_right theorem
(n) (h : 0 < m) : n ≤ n * m
Full source
protected theorem le_mul_of_pos_right (n) (h : 0 < m) : n ≤ n * m :=
  Nat.le_trans (Nat.le_of_eq (Nat.mul_one _).symm) (Nat.mul_le_mul_left _ h)
Right Multiplication by Positive Number Increases Natural Number
Informal description
For any natural numbers $n$ and $m$ such that $m > 0$, it holds that $n \leq n \cdot m$.
Nat.mul_lt_mul_of_lt_of_le theorem
(hac : a < c) (hbd : b ≤ d) (hd : 0 < d) : a * b < c * d
Full source
protected theorem mul_lt_mul_of_lt_of_le (hac : a < c) (hbd : b ≤ d) (hd : 0 < d) :
    a * b < c * d :=
  Nat.lt_of_le_of_lt (Nat.mul_le_mul_left _ hbd) (Nat.mul_lt_mul_of_pos_right hac hd)
Multiplication Preserves Strict Inequality Under Nonzero Right Condition
Informal description
For any natural numbers $a, b, c, d$ such that $a < c$, $b \leq d$, and $d > 0$, it holds that $a \cdot b < c \cdot d$.
Nat.mul_lt_mul_of_lt_of_le' theorem
(hac : a < c) (hbd : b ≤ d) (hb : 0 < b) : a * b < c * d
Full source
protected theorem mul_lt_mul_of_lt_of_le' (hac : a < c) (hbd : b ≤ d) (hb : 0 < b) :
    a * b < c * d :=
  Nat.mul_lt_mul_of_lt_of_le hac hbd (Nat.lt_of_lt_of_le hb hbd)
Multiplication Preserves Strict Inequality Under Nonzero Left Factor Condition (Variant)
Informal description
For any natural numbers $a, b, c, d$ such that $a < c$, $b \leq d$, and $b > 0$, it holds that $a \cdot b < c \cdot d$.
Nat.mul_lt_mul_of_le_of_lt theorem
(hac : a ≤ c) (hbd : b < d) (hc : 0 < c) : a * b < c * d
Full source
protected theorem mul_lt_mul_of_le_of_lt (hac : a ≤ c) (hbd : b < d) (hc : 0 < c) :
    a * b < c * d :=
  Nat.lt_of_le_of_lt (Nat.mul_le_mul_right _ hac) (Nat.mul_lt_mul_of_pos_left hbd hc)
Multiplication Preserves Inequality Under Nonzero Conditions
Informal description
For any natural numbers $a, b, c, d$ such that $a \leq c$, $b < d$, and $c > 0$, it holds that $a \cdot b < c \cdot d$.
Nat.mul_lt_mul_of_le_of_lt' theorem
(hac : a ≤ c) (hbd : b < d) (ha : 0 < a) : a * b < c * d
Full source
protected theorem mul_lt_mul_of_le_of_lt' (hac : a ≤ c) (hbd : b < d) (ha : 0 < a) :
    a * b < c * d :=
  Nat.mul_lt_mul_of_le_of_lt hac hbd (Nat.lt_of_lt_of_le ha hac)
Multiplication Preserves Inequality Under Nonzero Left Factor Condition
Informal description
For any natural numbers $a, b, c, d$ such that $a \leq c$, $b < d$, and $a > 0$, it holds that $a \cdot b < c \cdot d$.
Nat.mul_lt_mul_of_lt_of_lt theorem
{a b c d : Nat} (hac : a < c) (hbd : b < d) : a * b < c * d
Full source
protected theorem mul_lt_mul_of_lt_of_lt {a b c d : Nat} (hac : a < c) (hbd : b < d) :
    a * b < c * d :=
  Nat.mul_lt_mul_of_le_of_lt (Nat.le_of_lt hac) hbd (Nat.zero_lt_of_lt hac)
Multiplication Preserves Strict Inequality in Natural Numbers
Informal description
For any natural numbers $a, b, c, d$ such that $a < c$ and $b < d$, it holds that $a \cdot b < c \cdot d$.
Nat.succ_mul_succ theorem
(a b) : succ a * succ b = a * b + a + b + 1
Full source
theorem succ_mul_succ (a b) : succ a * succ b = a * b + a + b + 1 := by
  rw [succ_mul, mul_succ]; rfl
Successor Multiplication Identity: $(a+1)(b+1) = ab + a + b + 1$
Informal description
For any natural numbers $a$ and $b$, the product of the successors of $a$ and $b$ equals $a \cdot b + a + b + 1$, i.e., $(a + 1) \cdot (b + 1) = a \cdot b + a + b + 1$.
Nat.add_one_mul_add_one theorem
(a b : Nat) : (a + 1) * (b + 1) = a * b + a + b + 1
Full source
theorem add_one_mul_add_one (a b : Nat) : (a + 1) * (b + 1) = a * b + a + b + 1 := by
  rw [add_one_mul, mul_add_one]; rfl
Product of Successors Identity: $(a+1)(b+1) = ab + a + b + 1$
Informal description
For any natural numbers $a$ and $b$, the product of $(a + 1)$ and $(b + 1)$ is equal to $a \cdot b + a + b + 1$, i.e., $(a + 1)(b + 1) = ab + a + b + 1$.
Nat.mul_le_add_right theorem
{m k n : Nat} : k * m ≤ m + n ↔ (k - 1) * m ≤ n
Full source
theorem mul_le_add_right {m k n : Nat} : k * m ≤ m + n ↔ (k-1) * m ≤ n := by
  match k with
  | 0 =>
    simp
  | succ k =>
    simp [succ_mul, Nat.add_comm _ m, Nat.add_le_add_iff_left]
Multiplication-Additive Inequality for Natural Numbers: $k \cdot m \leq m + n \leftrightarrow (k - 1) \cdot m \leq n$
Informal description
For any natural numbers $m, k, n$, the inequality $k \cdot m \leq m + n$ holds if and only if $(k - 1) \cdot m \leq n$.
Nat.succ_mul_succ_eq theorem
(a b : Nat) : succ a * succ b = a * b + a + b + 1
Full source
theorem succ_mul_succ_eq (a b : Nat) : succ a * succ b = a * b + a + b + 1 := by
  rw [mul_succ, succ_mul, Nat.add_right_comm _ a]; rfl
Product of Successors Identity: $(a+1)(b+1) = ab + a + b + 1$
Informal description
For any natural numbers $a$ and $b$, the product of the successors of $a$ and $b$ equals $a \cdot b + a + b + 1$, i.e., $(a + 1)(b + 1) = ab + a + b + 1$.
Nat.mul_self_sub_mul_self_eq theorem
(a b : Nat) : a * a - b * b = (a + b) * (a - b)
Full source
protected theorem mul_self_sub_mul_self_eq (a b : Nat) : a * a - b * b = (a + b) * (a - b) := by
  rw [Nat.mul_sub_left_distrib, Nat.right_distrib, Nat.right_distrib, Nat.mul_comm b a,
    Nat.sub_add_eq, Nat.add_sub_cancel]
Difference of Squares Identity for Natural Numbers: $a^2 - b^2 = (a + b)(a - b)$
Informal description
For any natural numbers $a$ and $b$, the difference of squares $a^2 - b^2$ equals the product $(a + b)(a - b)$.
Nat.pos_of_mul_pos_left theorem
{a b : Nat} (h : 0 < a * b) : 0 < b
Full source
protected theorem pos_of_mul_pos_left {a b : Nat} (h : 0 < a * b) : 0 < b := by
  apply Decidable.by_contra
  intros
  simp_all
Positivity of Second Factor in Positive Product of Natural Numbers
Informal description
For any natural numbers $a$ and $b$, if the product $a \cdot b$ is positive, then $b$ is positive.
Nat.pos_of_mul_pos_right theorem
{a b : Nat} (h : 0 < a * b) : 0 < a
Full source
protected theorem pos_of_mul_pos_right {a b : Nat} (h : 0 < a * b) : 0 < a := by
  apply Decidable.by_contra
  intros
  simp_all
Positivity of Factors Implies Positivity of Right Factor in Natural Numbers
Informal description
For any natural numbers $a$ and $b$, if the product $a \cdot b$ is positive, then $a$ is positive.
Nat.mul_pos_iff_of_pos_left theorem
{a b : Nat} (h : 0 < a) : 0 < a * b ↔ 0 < b
Full source
@[simp] protected theorem mul_pos_iff_of_pos_left {a b : Nat} (h : 0 < a) :
    0 < a * b ↔ 0 < b :=
  ⟨Nat.pos_of_mul_pos_left, Nat.mul_pos h⟩
Positivity of Product with Positive Left Factor in Natural Numbers
Informal description
For any natural numbers $a$ and $b$ with $a > 0$, the product $a \cdot b$ is positive if and only if $b$ is positive.
Nat.pos_of_lt_mul_left theorem
{a b c : Nat} (h : a < b * c) : 0 < c
Full source
protected theorem pos_of_lt_mul_left {a b c : Nat} (h : a < b * c) : 0 < c := by
  replace h : 0 < b * c := by omega
  exact Nat.pos_of_mul_pos_left h
Positivity of Right Factor in Strict Inequality with Product of Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ is strictly less than the product $b \cdot c$, then $c$ is positive, i.e., $0 < c$.
Nat.pos_of_lt_mul_right theorem
{a b c : Nat} (h : a < b * c) : 0 < b
Full source
protected theorem pos_of_lt_mul_right {a b c : Nat} (h : a < b * c) : 0 < b := by
  replace h : 0 < b * c := by omega
  exact Nat.pos_of_mul_pos_right h
Positivity of Right Factor from Strict Inequality with Product in Natural Numbers
Informal description
For any natural numbers $a$, $b$, and $c$, if $a$ is strictly less than the product $b \cdot c$, then $b$ is positive, i.e., $0 < b$.
Nat.mod_two_eq_zero_or_one theorem
(n : Nat) : n % 2 = 0 ∨ n % 2 = 1
Full source
theorem mod_two_eq_zero_or_one (n : Nat) : n % 2 = 0 ∨ n % 2 = 1 :=
  match n % 2, @Nat.mod_lt n 2 (by decide) with
  | 0, _ => .inl rfl
  | 1, _ => .inr rfl
Remainder Modulo Two is Zero or One for Natural Numbers
Informal description
For any natural number $n$, the remainder when $n$ is divided by 2 is either 0 or 1, i.e., $n \% 2 = 0 \lor n \% 2 = 1$.
Nat.mod_two_bne_zero theorem
: ((a % 2) != 0) = (a % 2 == 1)
Full source
@[simp] theorem mod_two_bne_zero : ((a % 2) != 0) = (a % 2 == 1) := by
  cases mod_two_eq_zero_or_one a <;> simp_all
Modulo Two Inequality to Equality Conversion: $(a \% 2) \neq 0 \leftrightarrow (a \% 2) = 1$
Informal description
For any natural number $a$, the boolean inequality $(a \% 2) \neq 0$ is equivalent to the boolean equality $(a \% 2) = 1$.
Nat.mod_two_bne_one theorem
: ((a % 2) != 1) = (a % 2 == 0)
Full source
@[simp] theorem mod_two_bne_one : ((a % 2) != 1) = (a % 2 == 0) := by
  cases mod_two_eq_zero_or_one a <;> simp_all
Boolean Equivalence for Remainder Modulo Two: $(a \% 2) \neq 1 \leftrightarrow (a \% 2) = 0$
Informal description
For any natural number $a$, the boolean inequality $(a \% 2) \neq 1$ is equivalent to the boolean equality $(a \% 2) = 0$.
Nat.le_of_mod_lt theorem
{a b : Nat} (h : a % b < a) : b ≤ a
Full source
theorem le_of_mod_lt {a b : Nat} (h : a % b < a) : b ≤ a :=
  Nat.not_lt.1 fun hf => (ne_of_lt h).elim (Nat.mod_eq_of_lt hf)
Remainder Inequality Implies Divisor Bound: $a \% b < a \implies b \leq a$
Informal description
For any natural numbers $a$ and $b$, if the remainder of $a$ divided by $b$ is strictly less than $a$, then $b$ is less than or equal to $a$, i.e., $a \% b < a \implies b \leq a$.
Nat.mul_mod_mul_right theorem
(z x y : Nat) : (x * z) % (y * z) = (x % y) * z
Full source
theorem mul_mod_mul_right (z x y : Nat) : (x * z) % (y * z) = (x % y) * z := by
  rw [Nat.mul_comm x z, Nat.mul_comm y z, Nat.mul_comm (x % y) z]; apply mul_mod_mul_left
Right Multiplication Preserves Modulo Operation: $(xz) \% (yz) = (x \% y)z$
Informal description
For any natural numbers $x$, $y$, and $z$, the remainder of the product $x \cdot z$ divided by $y \cdot z$ is equal to the product of the remainder of $x$ divided by $y$ and $z$, i.e., \[ (x \cdot z) \% (y \cdot z) = (x \% y) \cdot z. \]
Nat.sub_mul_mod theorem
{x k n : Nat} (h₁ : n * k ≤ x) : (x - n * k) % n = x % n
Full source
theorem sub_mul_mod {x k n : Nat} (h₁ : n*k ≤ x) : (x - n*k) % n = x % n := by
  match k with
  | 0 => rw [Nat.mul_zero, Nat.sub_zero]
  | succ k =>
    have h₂ : n * k ≤ x := Nat.le_trans (le_add_right _ n) h₁
    have h₄ : x - n * k ≥ n := by
      apply Nat.le_of_add_le_add_right (b := n * k)
      rw [Nat.sub_add_cancel h₂]
      simp [mul_succ, Nat.add_comm] at h₁; simp [h₁]
    rw [mul_succ, ← Nat.sub_sub, ← mod_eq_sub_mod h₄, sub_mul_mod h₂]
Modulo Invariance Under Subtraction of Multiple: $(x - n \cdot k) \% n = x \% n$ when $n \cdot k \leq x$
Informal description
For any natural numbers $x$, $k$, and $n$ such that $n \cdot k \leq x$, the remainder when $(x - n \cdot k)$ is divided by $n$ is equal to the remainder when $x$ is divided by $n$, i.e., $(x - n \cdot k) \% n = x \% n$.
Nat.mod_mod theorem
(a n : Nat) : (a % n) % n = a % n
Full source
@[simp] theorem mod_mod (a n : Nat) : (a % n) % n = a % n :=
  match eq_zero_or_pos n with
  | .inl n0 => by simp [n0, mod_zero]
  | .inr npos => Nat.mod_eq_of_lt (mod_lt _ npos)
Idempotence of Modulo Operation: $(a \% n) \% n = a \% n$
Informal description
For any natural numbers $a$ and $n$, the remainder when $a \% n$ is divided by $n$ is equal to $a \% n$, i.e., $(a \% n) \% n = a \% n$.
Nat.mul_mod theorem
(a b n : Nat) : a * b % n = (a % n) * (b % n) % n
Full source
theorem mul_mod (a b n : Nat) : a * b % n = (a % n) * (b % n) % n := by
  rw (occs := [1]) [← mod_add_div a n]
  rw (occs := [1]) [← mod_add_div b n]
  rw [Nat.add_mul, Nat.mul_add, Nat.mul_add,
    Nat.mul_assoc, Nat.mul_assoc, ← Nat.mul_add n, add_mul_mod_self_left,
    Nat.mul_comm _ (n * (b / n)), Nat.mul_assoc, add_mul_mod_self_left]
Modulo Multiplication Identity: $(a \cdot b) \% n = ((a \% n) \cdot (b \% n)) \% n$
Informal description
For any natural numbers $a$, $b$, and $n$, the remainder when $a \cdot b$ is divided by $n$ is equal to the remainder when $(a \% n) \cdot (b \% n)$ is divided by $n$, i.e., \[ (a \cdot b) \% n = ((a \% n) \cdot (b \% n)) \% n. \]
Nat.mod_add_mod theorem
(m n k : Nat) : (m % n + k) % n = (m + k) % n
Full source
@[simp] theorem mod_add_mod (m n k : Nat) : (m % n + k) % n = (m + k) % n := by
  have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm
  rwa [Nat.add_right_comm, mod_add_div] at this
Modulo-Addition Identity: $(m \% n + k) \% n = (m + k) \% n$
Informal description
For any natural numbers $m$, $n$, and $k$, the following equality holds: \[ (m \% n + k) \% n = (m + k) \% n. \]
Nat.mul_mod_mod theorem
(m n l : Nat) : (m * (n % l)) % l = (m * n) % l
Full source
@[simp] theorem mul_mod_mod (m n l : Nat) : (m * (n % l)) % l = (m * n) % l := by
  rw [mul_mod, mod_mod, ← mul_mod]
Modulo-Multiplication Identity: $(m \cdot (n \% l)) \% l = (m \cdot n) \% l$
Informal description
For any natural numbers $m$, $n$, and $l$, the following equality holds: \[ (m \cdot (n \% l)) \% l = (m \cdot n) \% l. \]
Nat.add_mod_mod theorem
(m n k : Nat) : (m + n % k) % k = (m + n) % k
Full source
@[simp] theorem add_mod_mod (m n k : Nat) : (m + n % k) % k = (m + n) % k := by
  rw [Nat.add_comm, mod_add_mod, Nat.add_comm]
Modulo-Addition Identity: $(m + n \% k) \% k = (m + n) \% k$
Informal description
For any natural numbers $m$, $n$, and $k$, the following equality holds: \[ (m + n \% k) \% k = (m + n) \% k. \]
Nat.mod_mul_mod theorem
(m n l : Nat) : ((m % l) * n) % l = (m * n) % l
Full source
@[simp] theorem mod_mul_mod (m n l : Nat) : ((m % l) * n) % l = (m * n) % l := by
  rw [Nat.mul_comm, mul_mod_mod, Nat.mul_comm]
Modulo-Multiplication Identity: $((m \% l) \cdot n) \% l = (m \cdot n) \% l$
Informal description
For any natural numbers $m$, $n$, and $l$, the following equality holds: \[ ((m \% l) \cdot n) \% l = (m \cdot n) \% l. \]
Nat.add_mod theorem
(a b n : Nat) : (a + b) % n = ((a % n) + (b % n)) % n
Full source
theorem add_mod (a b n : Nat) : (a + b) % n = ((a % n) + (b % n)) % n := by
  rw [add_mod_mod, mod_add_mod]
Modulo Addition Identity: $(a + b) \% n = ((a \% n) + (b \% n)) \% n$
Informal description
For any natural numbers $a$, $b$, and $n$, the remainder of the sum $a + b$ modulo $n$ is equal to the remainder of the sum of the remainders of $a$ modulo $n$ and $b$ modulo $n$, modulo $n$. In other words: \[ (a + b) \% n = ((a \% n) + (b \% n)) \% n. \]
Nat.self_sub_mod theorem
(n k : Nat) [NeZero k] : (n - k) % n = n - k
Full source
@[simp] theorem self_sub_mod (n k : Nat) [NeZero k] : (n - k) % n = n - k := by
  cases n with
  | zero => simp
  | succ n =>
    rw [mod_eq_of_lt]
    cases k with
    | zero => simp_all
    | succ k => omega
Remainder of Self-Subtraction: $(n - k) \% n = n - k$ for $k \neq 0$
Informal description
For any natural numbers $n$ and $k$ with $k \neq 0$, the remainder of $(n - k)$ divided by $n$ equals $n - k$, i.e., $(n - k) \% n = n - k$.
Nat.mod_eq_sub theorem
(x w : Nat) : x % w = x - w * (x / w)
Full source
theorem mod_eq_sub (x w : Nat) : x % w = x - w * (x / w) := by
  conv => rhs; congr; rw [← mod_add_div x w]
  simp
Remainder as Difference: $x \% w = x - w \cdot (x / w)$
Informal description
For any natural numbers $x$ and $w$, the remainder of $x$ divided by $w$ equals $x$ minus $w$ multiplied by the integer division of $x$ by $w$, i.e., \[ x \% w = x - w \cdot (x / w). \]
Nat.pow_succ' theorem
{m n : Nat} : m ^ n.succ = m * m ^ n
Full source
theorem pow_succ' {m n : Nat} : m ^ n.succ = m * m ^ n := by
  rw [Nat.pow_succ, Nat.mul_comm]
Power Recursion: $m^{n+1} = m \cdot m^n$
Informal description
For any natural numbers $m$ and $n$, the power $m^{n+1}$ is equal to $m$ multiplied by $m^n$.
Nat.pow_add_one' theorem
{m n : Nat} : m ^ (n + 1) = m * m ^ n
Full source
theorem pow_add_one' {m n : Nat} : m ^ (n + 1) = m * m ^ n := by
  rw [Nat.pow_add_one, Nat.mul_comm]
Recursive Power Formula: $m^{n+1} = m \cdot m^n$
Informal description
For any natural numbers $m$ and $n$, the power $m^{n+1}$ is equal to $m$ multiplied by $m^n$, i.e., $m^{n+1} = m \cdot m^n$.
Nat.pow_eq theorem
{m n : Nat} : m.pow n = m ^ n
Full source
@[simp] theorem pow_eq {m n : Nat} : m.pow n = m ^ n := rfl
Equivalence of `pow` and Exponentiation for Natural Numbers
Informal description
For any natural numbers $m$ and $n$, the result of the `pow` function applied to $m$ and $n$ is equal to $m$ raised to the power of $n$, i.e., $m.\text{pow}\,n = m^n$.
Nat.one_shiftLeft theorem
(n : Nat) : 1 <<< n = 2 ^ n
Full source
theorem one_shiftLeft (n : Nat) : 1 <<< n = 2 ^ n := by rw [shiftLeft_eq, Nat.one_mul]
Left Shift of One Equals Power of Two: $1 \ll n = 2^n$
Informal description
For any natural number $n$, the left shift of $1$ by $n$ positions equals $2$ raised to the power of $n$, i.e., $1 \ll n = 2^n$.
Nat.zero_pow theorem
{n : Nat} (H : 0 < n) : 0 ^ n = 0
Full source
protected theorem zero_pow {n : Nat} (H : 0 < n) : 0 ^ n = 0 := by
  match n with
  | 0 => contradiction
  | n+1 => rw [Nat.pow_succ, Nat.mul_zero]
Zero to Positive Power is Zero: $0^n = 0$ for $n > 0$
Informal description
For any natural number $n > 0$, the power $0^n$ equals $0$.
Nat.one_pow theorem
(n : Nat) : 1 ^ n = 1
Full source
@[simp] protected theorem one_pow (n : Nat) : 1 ^ n = 1 := by
  induction n with
  | zero => rfl
  | succ _ ih => rw [Nat.pow_succ, Nat.mul_one, ih]
Power of One: $1^n = 1$
Informal description
For any natural number $n$, the power of $1$ raised to $n$ equals $1$, i.e., $1^n = 1$.
Nat.pow_two theorem
(a : Nat) : a ^ 2 = a * a
Full source
protected theorem pow_two (a : Nat) : a ^ 2 = a * a := by rw [Nat.pow_succ, Nat.pow_one]
Square of a Natural Number: $a^2 = a \cdot a$
Informal description
For any natural number $a$, the square of $a$ is equal to $a$ multiplied by itself, i.e., $a^2 = a \cdot a$.
Nat.pow_add theorem
(a m n : Nat) : a ^ (m + n) = a ^ m * a ^ n
Full source
protected theorem pow_add (a m n : Nat) : a ^ (m + n) = a ^ m * a ^ n := by
  induction n with
  | zero => rw [Nat.add_zero, Nat.pow_zero, Nat.mul_one]
  | succ _ ih => rw [Nat.add_succ, Nat.pow_succ, Nat.pow_succ, ih, Nat.mul_assoc]
Exponent Addition Law: $a^{m+n} = a^m \cdot a^n$
Informal description
For any natural numbers $a$, $m$, and $n$, the power $a$ raised to the sum $m + n$ equals the product of $a^m$ and $a^n$, i.e., $a^{m+n} = a^m \cdot a^n$.
Nat.pow_add' theorem
(a m n : Nat) : a ^ (m + n) = a ^ n * a ^ m
Full source
protected theorem pow_add' (a m n : Nat) : a ^ (m + n) = a ^ n * a ^ m := by
  rw [← Nat.pow_add, Nat.add_comm]
Exponent Addition Law (Reversed): $a^{m+n} = a^n \cdot a^m$
Informal description
For any natural numbers $a$, $m$, and $n$, the power $a$ raised to the sum $m + n$ equals the product of $a^n$ and $a^m$, i.e., $a^{m+n} = a^n \cdot a^m$.
Nat.pow_mul theorem
(a m n : Nat) : a ^ (m * n) = (a ^ m) ^ n
Full source
protected theorem pow_mul (a m n : Nat) : a ^ (m * n) = (a ^ m) ^ n := by
  induction n with
  | zero => rw [Nat.mul_zero, Nat.pow_zero, Nat.pow_zero]
  | succ _ ih => rw [Nat.mul_succ, Nat.pow_add, Nat.pow_succ, ih]
Exponent Multiplication Law: $a^{m \cdot n} = (a^m)^n$
Informal description
For any natural numbers $a$, $m$, and $n$, the power $a$ raised to the product $m \cdot n$ equals the $n$-th power of $a^m$, i.e., $a^{m \cdot n} = (a^m)^n$.
Nat.pow_mul' theorem
(a m n : Nat) : a ^ (m * n) = (a ^ n) ^ m
Full source
protected theorem pow_mul' (a m n : Nat) : a ^ (m * n) = (a ^ n) ^ m := by
  rw [← Nat.pow_mul, Nat.mul_comm]
Exponent Multiplication Law (Reversed): $a^{m \cdot n} = (a^n)^m$
Informal description
For any natural numbers $a$, $m$, and $n$, the power $a$ raised to the product $m \cdot n$ equals the $m$-th power of $a^n$, i.e., $a^{m \cdot n} = (a^n)^m$.
Nat.pow_right_comm theorem
(a m n : Nat) : (a ^ m) ^ n = (a ^ n) ^ m
Full source
protected theorem pow_right_comm (a m n : Nat) : (a ^ m) ^ n = (a ^ n) ^ m := by
  rw [← Nat.pow_mul, Nat.pow_mul']
Power Commutation Law: $(a^m)^n = (a^n)^m$
Informal description
For any natural numbers $a$, $m$, and $n$, the $n$-th power of $a^m$ equals the $m$-th power of $a^n$, i.e., $(a^m)^n = (a^n)^m$.
Nat.one_lt_two_pow theorem
(h : n ≠ 0) : 1 < 2 ^ n
Full source
protected theorem one_lt_two_pow (h : n ≠ 0) : 1 < 2 ^ n :=
  match n, h with
  | n+1, _ => by
    rw [Nat.pow_succ', ← Nat.one_mul 1]
    exact Nat.mul_lt_mul_of_lt_of_le' (by decide) (Nat.two_pow_pos n) (by decide)
Powers of Two Greater Than One: $1 < 2^n$ for $n \neq 0$
Informal description
For any natural number $n \neq 0$, the power $2^n$ is strictly greater than 1, i.e., $1 < 2^n$.
Nat.one_mod_two_pow_eq_one theorem
: 1 % 2 ^ n = 1 ↔ 0 < n
Full source
@[simp] theorem one_mod_two_pow_eq_one : 1 % 2 ^ n = 1 ↔ 0 < n := by
  cases n with
  | zero => simp
  | succ n =>
    rw [mod_eq_of_lt (a := 1) (Nat.one_lt_two_pow (by omega))]
    simp
Remainder of One Modulo Power of Two: $1 \% 2^n = 1 \leftrightarrow n > 0$
Informal description
For any natural number $n$, the remainder when $1$ is divided by $2^n$ equals $1$ if and only if $n$ is positive, i.e., $1 \% 2^n = 1 \leftrightarrow n > 0$.
Nat.one_mod_two_pow theorem
(h : 0 < n) : 1 % 2 ^ n = 1
Full source
@[simp] theorem one_mod_two_pow (h : 0 < n) : 1 % 2 ^ n = 1 :=
  one_mod_two_pow_eq_one.mpr h
Remainder of One Modulo Power of Two: $1 \bmod 2^n = 1$ for $n > 0$
Informal description
For any positive natural number $n$, the remainder when $1$ is divided by $2^n$ equals $1$, i.e., $1 \bmod 2^n = 1$.
Nat.pow_lt_pow_of_lt theorem
{a n m : Nat} (h : 1 < a) (w : n < m) : a ^ n < a ^ m
Full source
protected theorem pow_lt_pow_of_lt {a n m : Nat} (h : 1 < a) (w : n < m) : a ^ n < a ^ m := by
  have := Nat.exists_eq_add_of_lt w
  cases this
  case intro k p =>
  rw [Nat.add_right_comm] at p
  subst p
  rw [Nat.pow_add, ← Nat.mul_one (a^n)]
  have t : 0 < a ^ k := Nat.pow_pos (Nat.lt_trans Nat.zero_lt_one h)
  exact Nat.mul_lt_mul_of_lt_of_le (Nat.pow_lt_pow_succ h) t t
Strict Monotonicity of Natural Number Exponentiation: $a^n < a^m$ when $1 < a$ and $n < m$
Informal description
For any natural numbers $a$, $n$, and $m$, if $1 < a$ and $n < m$, then $a^n < a^m$.
Nat.pow_le_pow_of_le theorem
{a n m : Nat} (h : 1 < a) (w : n ≤ m) : a ^ n ≤ a ^ m
Full source
protected theorem pow_le_pow_of_le {a n m : Nat} (h : 1 < a) (w : n ≤ m) : a ^ n ≤ a ^ m := by
  cases Nat.lt_or_eq_of_le w
  case inl lt =>
    exact Nat.le_of_lt (Nat.pow_lt_pow_of_lt h lt)
  case inr eq =>
    subst eq
    exact Nat.le_refl _
Monotonicity of Natural Number Exponentiation: $a^n \leq a^m$ when $1 < a$ and $n \leq m$
Informal description
For any natural numbers $a$, $n$, and $m$, if $1 < a$ and $n \leq m$, then $a^n \leq a^m$.
Nat.pow_le_pow_iff_right theorem
{a n m : Nat} (h : 1 < a) : a ^ n ≤ a ^ m ↔ n ≤ m
Full source
protected theorem pow_le_pow_iff_right {a n m : Nat} (h : 1 < a) :
    a ^ n ≤ a ^ m ↔ n ≤ m := by
  constructor
  · apply Decidable.by_contra
    intros w
    simp [Decidable.not_imp_iff_and_not] at w
    apply Nat.lt_irrefl (a ^ n)
    exact Nat.lt_of_le_of_lt w.1 (Nat.pow_lt_pow_of_lt h w.2)
  · intro w
    cases Nat.eq_or_lt_of_le w
    case inl eq => subst eq; apply Nat.le_refl
    case inr lt => exact Nat.le_of_lt (Nat.pow_lt_pow_of_lt h lt)
Exponentiation Monotonicity Criterion: $a^n \leq a^m \leftrightarrow n \leq m$ for $a > 1$
Informal description
For any natural numbers $a > 1$, $n$, and $m$, the inequality $a^n \leq a^m$ holds if and only if $n \leq m$.
Nat.pow_lt_pow_iff_right theorem
{a n m : Nat} (h : 1 < a) : a ^ n < a ^ m ↔ n < m
Full source
protected theorem pow_lt_pow_iff_right {a n m : Nat} (h : 1 < a) :
    a ^ n < a ^ m ↔ n < m := by
  constructor
  · apply Decidable.by_contra
    intros w
    simp at w
    apply Nat.lt_irrefl (a ^ n)
    exact Nat.lt_of_lt_of_le w.1 (Nat.pow_le_pow_of_le h w.2)
  · intro w
    exact Nat.pow_lt_pow_of_lt h w
Strict Monotonicity Criterion for Natural Number Exponentiation: $a^n < a^m \leftrightarrow n < m$ when $a > 1$
Informal description
For any natural numbers $a > 1$, $n$, and $m$, the strict inequality $a^n < a^m$ holds if and only if $n < m$.
Nat.pow_pred_mul theorem
{x w : Nat} (h : 0 < w) : x ^ (w - 1) * x = x ^ w
Full source
@[simp]
protected theorem pow_pred_mul {x w : Nat} (h : 0 < w) :
    x ^ (w - 1) * x = x ^ w := by
  simp [← Nat.pow_succ, succ_eq_add_one, Nat.sub_add_cancel h]
Power Reduction Identity: $x^{w-1} \cdot x = x^w$ for $w > 0$
Informal description
For any natural numbers $x$ and $w$ with $w > 0$, the product of $x$ raised to the power of $w-1$ and $x$ equals $x$ raised to the power of $w$, i.e., $x^{w-1} \cdot x = x^w$.
Nat.pow_pred_lt_pow theorem
{x w : Nat} (h₁ : 1 < x) (h₂ : 0 < w) : x ^ (w - 1) < x ^ w
Full source
protected theorem pow_pred_lt_pow {x w : Nat} (h₁ : 1 < x) (h₂ : 0 < w) :
    x ^ (w - 1) < x ^ w :=
  Nat.pow_lt_pow_of_lt h₁ (by omega)
Strict Monotonicity of Natural Powers: $x^{w-1} < x^w$ for $x > 1$ and $w > 0$
Informal description
For any natural numbers $x$ and $w$ such that $x > 1$ and $w > 0$, we have $x^{w-1} < x^w$.
Nat.two_pow_pred_lt_two_pow theorem
{w : Nat} (h : 0 < w) : 2 ^ (w - 1) < 2 ^ w
Full source
protected theorem two_pow_pred_lt_two_pow {w : Nat} (h : 0 < w) :
    2 ^ (w - 1) < 2 ^ w :=
  Nat.pow_pred_lt_pow (by omega) h
Strict Monotonicity of Powers of Two: $2^{w-1} < 2^w$ for $w > 0$
Informal description
For any natural number $w > 0$, the inequality $2^{w-1} < 2^w$ holds.
Nat.two_pow_pred_add_two_pow_pred theorem
(h : 0 < w) : 2 ^ (w - 1) + 2 ^ (w - 1) = 2 ^ w
Full source
@[simp]
protected theorem two_pow_pred_add_two_pow_pred (h : 0 < w) :
    2 ^ (w - 1) + 2 ^ (w - 1) = 2 ^ w := by
  rw [← Nat.pow_pred_mul h]
  omega
Sum of Two Powers of Two: $2^{w-1} + 2^{w-1} = 2^w$ for $w > 0$
Informal description
For any natural number $w$ such that $w > 0$, the sum of $2^{w-1}$ and $2^{w-1}$ equals $2^w$, i.e., $2^{w-1} + 2^{w-1} = 2^w$.
Nat.two_pow_sub_two_pow_pred theorem
(h : 0 < w) : 2 ^ w - 2 ^ (w - 1) = 2 ^ (w - 1)
Full source
@[simp]
protected theorem two_pow_sub_two_pow_pred (h : 0 < w) :
    2 ^ w - 2 ^ (w - 1) = 2 ^ (w - 1) := by
  simp [← Nat.two_pow_pred_add_two_pow_pred h]
Difference of Consecutive Powers of Two: $2^w - 2^{w-1} = 2^{w-1}$ for $w > 0$
Informal description
For any natural number $w$ such that $w > 0$, the difference $2^w - 2^{w-1}$ equals $2^{w-1}$.
Nat.two_pow_pred_mod_two_pow theorem
(h : 0 < w) : 2 ^ (w - 1) % 2 ^ w = 2 ^ (w - 1)
Full source
@[simp]
protected theorem two_pow_pred_mod_two_pow (h : 0 < w) :
    2 ^ (w - 1) % 2 ^ w = 2 ^ (w - 1) := by
  rw [mod_eq_of_lt]
  apply Nat.pow_pred_lt_pow (by omega) h
Modulo Identity for Powers of Two: $2^{w-1} \mod 2^w = 2^{w-1}$ for $w > 0$
Informal description
For any natural number $w > 0$, the remainder when $2^{w-1}$ is divided by $2^w$ is equal to $2^{w-1}$, i.e., $2^{w-1} \mod 2^w = 2^{w-1}$.
Nat.pow_lt_pow_iff_pow_mul_le_pow theorem
{a n m : Nat} (h : 1 < a) : a ^ n < a ^ m ↔ a ^ n * a ≤ a ^ m
Full source
protected theorem pow_lt_pow_iff_pow_mul_le_pow {a n m : Nat} (h : 1 < a) :
    a ^ n < a ^ m ↔ a ^ n * a ≤ a ^ m := by
  rw [←Nat.pow_add_one, Nat.pow_le_pow_iff_right (by omega), Nat.pow_lt_pow_iff_right (by omega)]
  omega
Exponentiation Inequality Criterion: $a^n < a^m \leftrightarrow a^{n+1} \leq a^m$ for $a > 1$
Informal description
For any natural numbers $a > 1$, $n$, and $m$, the strict inequality $a^n < a^m$ holds if and only if $a^{n+1} \leq a^m$.
Nat.lt_pow_self theorem
{n a : Nat} (h : 1 < a) : n < a ^ n
Full source
protected theorem lt_pow_self {n a : Nat} (h : 1 < a) : n < a ^ n := by
  induction n with
  | zero => exact Nat.zero_lt_one
  | succ _ ih => exact Nat.lt_of_lt_of_le (Nat.add_lt_add_right ih 1) (Nat.pow_lt_pow_succ h)
Natural Number Inequality: $n < a^n$ for $a > 1$
Informal description
For any natural numbers $n$ and $a$ such that $1 < a$, it holds that $n < a^n$.
Nat.lt_two_pow_self theorem
: n < 2 ^ n
Full source
protected theorem lt_two_pow_self : n < 2 ^ n :=
  Nat.lt_pow_self Nat.one_lt_two
Exponential Growth Inequality: $n < 2^n$ for Natural Numbers
Informal description
For any natural number $n$, it holds that $n < 2^n$.
Nat.mod_two_pow_self theorem
: n % 2 ^ n = n
Full source
@[simp]
protected theorem mod_two_pow_self : n % 2 ^ n = n :=
  Nat.mod_eq_of_lt Nat.lt_two_pow_self
Modulo Identity: $n \bmod 2^n = n$ for Natural Numbers
Informal description
For any natural number $n$, the remainder when $n$ is divided by $2^n$ is equal to $n$ itself, i.e., $n \bmod 2^n = n$.
Nat.two_pow_pred_mul_two theorem
(h : 0 < w) : 2 ^ (w - 1) * 2 = 2 ^ w
Full source
@[simp]
theorem two_pow_pred_mul_two (h : 0 < w) :
    2 ^ (w - 1) * 2 = 2 ^ w := by
  simp [← Nat.pow_succ, Nat.sub_add_cancel h]
Exponentiation Identity: $2^{w-1} \cdot 2 = 2^w$ for $w > 0$
Informal description
For any natural number $w$ such that $0 < w$, the product of $2^{w-1}$ and $2$ equals $2^w$, i.e., $2^{w-1} \cdot 2 = 2^w$.
Nat.le_pow theorem
{a b : Nat} (h : 0 < b) : a ≤ a ^ b
Full source
theorem le_pow {a b : Nat} (h : 0 < b) : a ≤ a ^ b := by
  refine (eq_zero_or_pos a).elim (by rintro rfl; simp) (fun ha => ?_)
  rw [(show b = b - 1 + 1 by omega), Nat.pow_succ]
  exact Nat.le_mul_of_pos_left _ (Nat.pow_pos ha)
Natural number inequality: $a \leq a^b$ for $b > 0$
Informal description
For any natural numbers $a$ and $b$ such that $b > 0$, it holds that $a \leq a^b$.
Nat.log2_zero theorem
: Nat.log2 0 = 0
Full source
@[simp]
theorem log2_zero : Nat.log2 0 = 0 := by
  simp [Nat.log2]
$\log_2 0 = 0$
Informal description
The base 2 logarithm of 0 is 0, i.e., $\log_2 0 = 0$.
Nat.le_log2 theorem
(h : n ≠ 0) : k ≤ n.log2 ↔ 2 ^ k ≤ n
Full source
theorem le_log2 (h : n ≠ 0) : k ≤ n.log2 ↔ 2 ^ k ≤ n := by
  match k with
  | 0 => simp [show 1 ≤ n from Nat.pos_of_ne_zero h]
  | k+1 =>
    rw [log2]; split
    · have n0 : 0 < n / 2 := (Nat.le_div_iff_mul_le (by decide)).2 ‹_›
      simp only [Nat.add_le_add_iff_right, le_log2 (Nat.ne_of_gt n0), le_div_iff_mul_le,
        Nat.pow_succ]
      exact Nat.le_div_iff_mul_le (by decide)
    · simp only [le_zero_eq, succ_ne_zero, false_iff]
      refine mt (Nat.le_trans ?_) ‹_›
      exact Nat.pow_le_pow_right Nat.zero_lt_two (Nat.le_add_left 1 k)
Logarithmic Inequality: $k \leq \log_2 n \leftrightarrow 2^k \leq n$ for $n \neq 0$
Informal description
For any natural numbers $n$ and $k$ with $n \neq 0$, the inequality $k \leq \log_2 n$ holds if and only if $2^k \leq n$.
Nat.log2_two_pow theorem
: (2 ^ n).log2 = n
Full source
@[simp]
theorem log2_two_pow : (2 ^ n).log2 = n := by
  apply Nat.eq_of_le_of_lt_succ <;> simp [le_log2, log2_lt, NeZero.ne, Nat.pow_lt_pow_iff_right]
Logarithm Identity: $\log_2(2^n) = n$ for Natural Numbers
Informal description
For any natural number $n$, the base 2 logarithm of $2^n$ is equal to $n$, i.e., $\log_2(2^n) = n$.
Nat.log2_self_le theorem
(h : n ≠ 0) : 2 ^ n.log2 ≤ n
Full source
theorem log2_self_le (h : n ≠ 0) : 2 ^ n.log2 ≤ n := (le_log2 h).1 (Nat.le_refl _)
$2^{\log_2 n} \leq n$ for nonzero $n$
Informal description
For any nonzero natural number $n$, the inequality $2^{\log_2 n} \leq n$ holds.
Nat.lt_log2_self theorem
: n < 2 ^ (n.log2 + 1)
Full source
theorem lt_log2_self : n < 2 ^ (n.log2 + 1) :=
  match n with
  | 0 => by simp
  | n+1 => (log2_lt n.succ_ne_zero).1 (Nat.le_refl _)
Upper Bound on Natural Numbers via Logarithm: $n < 2^{\log_2 n + 1}$
Informal description
For any natural number $n$, the inequality $n < 2^{\log_2 n + 1}$ holds.
Nat.div_eq_iff_eq_mul_right theorem
{a b c : Nat} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = b * c
Full source
protected theorem div_eq_iff_eq_mul_right {a b c : Nat} (H : 0 < b) (H' : b ∣ a) :
    a / b = c ↔ a = b * c :=
  ⟨Nat.eq_mul_of_div_eq_right H', Nat.div_eq_of_eq_mul_right H⟩
Division Equivalence: $a / b = c \leftrightarrow a = b \cdot c$ for $b > 0$ and $b \mid a$
Informal description
For any natural numbers $a$, $b$, and $c$ with $b > 0$ and $b$ dividing $a$, the division $a / b$ equals $c$ if and only if $a$ equals $b \cdot c$.
Nat.div_eq_iff_eq_mul_left theorem
{a b c : Nat} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = c * b
Full source
protected theorem div_eq_iff_eq_mul_left {a b c : Nat} (H : 0 < b) (H' : b ∣ a) :
    a / b = c ↔ a = c * b := by
  rw [Nat.mul_comm]; exact Nat.div_eq_iff_eq_mul_right H H'
Division Equivalence: $a / b = c \leftrightarrow a = c \cdot b$ for $b > 0$ and $b \mid a$
Informal description
For any natural numbers $a$, $b$, and $c$ with $b > 0$ and $b$ dividing $a$, the division $a / b$ equals $c$ if and only if $a$ equals $c \cdot b$.
Nat.pow_dvd_pow_iff_pow_le_pow theorem
{k l : Nat} : ∀ {x : Nat}, 0 < x → (x ^ k ∣ x ^ l ↔ x ^ k ≤ x ^ l)
Full source
theorem pow_dvd_pow_iff_pow_le_pow {k l : Nat} :
    ∀ {x : Nat}, 0 < x → (x ^ k ∣ x ^ lx ^ k ∣ x ^ l ↔ x ^ k ≤ x ^ l)
  | x + 1, w => by
    constructor
    · intro a
      exact le_of_dvd (Nat.pow_pos (succ_pos x)) a
    · intro a
      cases x
      case zero => simp
      case succ x =>
        have le :=
          (Nat.pow_le_pow_iff_right (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _)))).mp a
        refine ⟨(x + 2) ^ (l - k), ?_⟩
        rw [← Nat.pow_add, Nat.add_comm k, Nat.sub_add_cancel le]
Divisibility of Powers: $x^k \mid x^l \leftrightarrow x^k \leq x^l$ for $x > 0$
Informal description
For any natural numbers $k$, $l$, and $x$ with $x > 0$, the power $x^k$ divides $x^l$ if and only if $x^k \leq x^l$.
Nat.pow_dvd_pow_iff_le_right theorem
{x k l : Nat} (w : 1 < x) : x ^ k ∣ x ^ l ↔ k ≤ l
Full source
/-- If `1 < x`, then `x^k` divides `x^l` if and only if `k` is at most `l`. -/
theorem pow_dvd_pow_iff_le_right {x k l : Nat} (w : 1 < x) : x ^ k ∣ x ^ lx ^ k ∣ x ^ l ↔ k ≤ l := by
  rw [pow_dvd_pow_iff_pow_le_pow (lt_of_succ_lt w), Nat.pow_le_pow_iff_right w]
Divisibility of Powers: $x^k \mid x^l \leftrightarrow k \leq l$ for $x > 1$
Informal description
For any natural numbers $x > 1$, $k$, and $l$, the power $x^k$ divides $x^l$ if and only if $k \leq l$.
Nat.pow_dvd_pow theorem
{m n : Nat} (a : Nat) (h : m ≤ n) : a ^ m ∣ a ^ n
Full source
protected theorem pow_dvd_pow {m n : Nat} (a : Nat) (h : m ≤ n) : a ^ m ∣ a ^ n := by
  cases Nat.exists_eq_add_of_le h
  case intro k p =>
    subst p
    rw [Nat.pow_add]
    apply Nat.dvd_mul_right
Divisibility of Powers: $a^m \mid a^n$ for $m \leq n$
Informal description
For any natural numbers $a$, $m$, and $n$ such that $m \leq n$, the power $a^m$ divides $a^n$.
Nat.pow_sub_mul_pow theorem
(a : Nat) {m n : Nat} (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n
Full source
protected theorem pow_sub_mul_pow (a : Nat) {m n : Nat} (h : m ≤ n) :
    a ^ (n - m) * a ^ m = a ^ n := by
  rw [← Nat.pow_add, Nat.sub_add_cancel h]
Exponent Subtraction-Multiplication Identity: $a^{n-m} \cdot a^m = a^n$ for $m \leq n$
Informal description
For any natural numbers $a$, $m$, and $n$ with $m \leq n$, we have $a^{n-m} \cdot a^m = a^n$.
Nat.pow_dvd_of_le_of_pow_dvd theorem
{p m n k : Nat} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k
Full source
theorem pow_dvd_of_le_of_pow_dvd {p m n k : Nat} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k :=
  Nat.dvd_trans (Nat.pow_dvd_pow _ hmn) hdiv
Divisibility of Power Factors: $p^m \mid k$ when $m \leq n$ and $p^n \mid k$
Informal description
For any natural numbers $p$, $m$, $n$, and $k$, if $m \leq n$ and $p^n$ divides $k$, then $p^m$ divides $k$.
Nat.dvd_of_pow_dvd theorem
{p k m : Nat} (hk : 1 ≤ k) (hpk : p ^ k ∣ m) : p ∣ m
Full source
theorem dvd_of_pow_dvd {p k m : Nat} (hk : 1 ≤ k) (hpk : p ^ k ∣ m) : p ∣ m := by
  rw [← Nat.pow_one p]; exact pow_dvd_of_le_of_pow_dvd hk hpk
Divisibility by Base When Power Divides: $p \mid m$ if $p^k \mid m$ and $k \geq 1$
Informal description
For any natural numbers $p$, $k$, and $m$, if $1 \leq k$ and $p^k$ divides $m$, then $p$ divides $m$.
Nat.pow_div theorem
{x m n : Nat} (h : n ≤ m) (hx : 0 < x) : x ^ m / x ^ n = x ^ (m - n)
Full source
protected theorem pow_div {x m n : Nat} (h : n ≤ m) (hx : 0 < x) : x ^ m / x ^ n = x ^ (m - n) := by
  rw [Nat.div_eq_iff_eq_mul_left (Nat.pow_pos hx) (Nat.pow_dvd_pow _ h), Nat.pow_sub_mul_pow _ h]
Power Division Identity: $x^m / x^n = x^{m-n}$ for $n \leq m$ and $x > 0$
Informal description
For any natural numbers $x$, $m$, and $n$ such that $n \leq m$ and $x > 0$, the division of $x^m$ by $x^n$ equals $x^{m-n}$.
Nat.shiftLeft_zero theorem
: n <<< 0 = n
Full source
@[simp] theorem shiftLeft_zero : n <<< 0 = n := rfl
Left Shift by Zero Preserves Natural Number
Informal description
For any natural number $n$, the left shift operation by zero bits leaves $n$ unchanged, i.e., $n \ll 0 = n$.
Nat.shiftLeft_succ_inside theorem
(m n : Nat) : m <<< (n + 1) = (2 * m) <<< n
Full source
/-- Shiftleft on successor with multiple moved inside. -/
theorem shiftLeft_succ_inside (m n : Nat) : m <<< (n+1) = (2*m) <<< n := rfl
Left Shift Recursion: $m \ll (n+1) = (2m) \ll n$
Informal description
For any natural numbers $m$ and $n$, the left shift operation applied to $m$ with shift amount $n+1$ is equal to the left shift operation applied to $2 \cdot m$ with shift amount $n$, i.e., $$ m \ll (n + 1) = (2 \cdot m) \ll n. $$
Nat.shiftLeft_succ theorem
: ∀ (m n), m <<< (n + 1) = 2 * (m <<< n)
Full source
/-- Shiftleft on successor with multiple moved to outside. -/
theorem shiftLeft_succ : ∀(m n), m <<< (n + 1) = 2 * (m <<< n)
| _, 0 => rfl
| _, k + 1 => by
  rw [shiftLeft_succ_inside _ (k+1)]
  rw [shiftLeft_succ _ k, shiftLeft_succ_inside]
Left Shift Recursion: $m \ll (n+1) = 2(m \ll n)$
Informal description
For any natural numbers $m$ and $n$, the left shift operation applied to $m$ with shift amount $n+1$ is equal to twice the left shift operation applied to $m$ with shift amount $n$, i.e., $$ m \ll (n + 1) = 2 \cdot (m \ll n). $$
Nat.shiftRight_succ_inside theorem
: ∀ m n, m >>> (n + 1) = (m / 2) >>> n
Full source
/-- Shiftright on successor with division moved inside. -/
theorem shiftRight_succ_inside : ∀m n, m >>> (n+1) = (m/2) >>> n
| _, 0 => rfl
| _, k + 1 => by
  rw [shiftRight_succ _ (k+1)]
  rw [shiftRight_succ_inside _ k, shiftRight_succ]
Right Shift Recursion: $m \gg (n+1) = \lfloor m/2 \rfloor \gg n$
Informal description
For any natural numbers $m$ and $n$, the right shift operation applied to $m$ with shift amount $n+1$ is equal to the right shift operation applied to $\lfloor m/2 \rfloor$ with shift amount $n$, i.e., $$ m \gg (n + 1) = \left\lfloor \frac{m}{2} \right\rfloor \gg n. $$
Nat.zero_shiftLeft theorem
: ∀ n, 0 <<< n = 0
Full source
@[simp] theorem zero_shiftLeft : ∀ n, 0 <<< n = 0
  | 0 => by simp [shiftLeft]
  | n + 1 => by simp [shiftLeft, zero_shiftLeft n, shiftLeft_succ]
Left Shift of Zero Yields Zero: $0 \ll n = 0$
Informal description
For any natural number $n$, the left shift operation applied to $0$ with shift amount $n$ results in $0$, i.e., $0 \ll n = 0$.
Nat.zero_shiftRight theorem
: ∀ n, 0 >>> n = 0
Full source
@[simp] theorem zero_shiftRight : ∀ n, 0 >>> n = 0
  | 0 => by simp [shiftRight]
  | n + 1 => by simp [shiftRight, zero_shiftRight n, shiftRight_succ]
Right Shift of Zero Yields Zero: $0 \gg n = 0$
Informal description
For any natural number $n$, the right shift operation applied to $0$ with shift amount $n$ results in $0$, i.e., $0 \gg n = 0$.
Nat.shiftLeft_add theorem
(m n : Nat) : ∀ k, m <<< (n + k) = (m <<< n) <<< k
Full source
theorem shiftLeft_add (m n : Nat) : ∀ k, m <<< (n + k) = (m <<< n) <<< k
  | 0 => rfl
  | k + 1 => by simp [← Nat.add_assoc, shiftLeft_add _ _ k, shiftLeft_succ]
Additive Property of Left Shift: $m \ll (n + k) = (m \ll n) \ll k$
Informal description
For any natural numbers $m$, $n$, and $k$, the left shift operation satisfies the additive property: $$ m \ll (n + k) = (m \ll n) \ll k $$ where $\ll$ denotes the left shift operation.
Nat.shiftLeft_shiftRight theorem
(x n : Nat) : x <<< n >>> n = x
Full source
@[simp] theorem shiftLeft_shiftRight (x n : Nat) : x <<< nx <<< n >>> n = x := by
  rw [Nat.shiftLeft_eq, Nat.shiftRight_eq_div_pow, Nat.mul_div_cancel _ (Nat.two_pow_pos _)]
Left Shift Followed by Right Shift Returns Original Number: $(x \ll n) \gg n = x$
Informal description
For any natural numbers $x$ and $n$, performing a left shift by $n$ bits followed by a right shift by $n$ bits on $x$ returns $x$ itself, i.e., $(x \ll n) \gg n = x$.
Nat.mul_add_div theorem
{m : Nat} (m_pos : m > 0) (x y : Nat) : (m * x + y) / m = x + y / m
Full source
theorem mul_add_div {m : Nat} (m_pos : m > 0) (x y : Nat) : (m * x + y) / m = x + y / m := by
  match x with
  | 0 => simp
  | x + 1 =>
    rw [Nat.mul_succ, Nat.add_assoc _ m, mul_add_div m_pos x (m+y), div_eq]
    simp +arith [m_pos]; rw [Nat.add_comm, Nat.add_sub_cancel]
Division of Linear Combination: $\frac{mx + y}{m} = x + \frac{y}{m}$ for $m > 0$
Informal description
For any positive natural number $m$ and any natural numbers $x$ and $y$, the division of $m \cdot x + y$ by $m$ equals $x$ plus the division of $y$ by $m$, i.e., $$ \frac{m \cdot x + y}{m} = x + \frac{y}{m}. $$
Nat.mul_add_mod theorem
(m x y : Nat) : (m * x + y) % m = y % m
Full source
theorem mul_add_mod (m x y : Nat) : (m * x + y) % m = y % m := by
  match x with
  | 0 => simp
  | x + 1 =>
    simp [Nat.mul_succ, Nat.add_assoc _ m, mul_add_mod _ x]
Modulo Identity for Linear Combinations: $(m \cdot x + y) \% m = y \% m$
Informal description
For any natural numbers $m$, $x$, and $y$, the remainder when $m \cdot x + y$ is divided by $m$ equals the remainder when $y$ is divided by $m$, i.e., $$ (m \cdot x + y) \% m = y \% m. $$
Nat.mod_div_self theorem
(m n : Nat) : m % n / n = 0
Full source
@[simp] theorem mod_div_self (m n : Nat) : m % n / n = 0 := by
  cases n
  · exact (m % 0).div_zero
  · case succ n => exact Nat.div_eq_of_lt (m.mod_lt n.succ_pos)
Division of Remainder by Divisor Yields Zero: $(m \% n)/n = 0$
Informal description
For any natural numbers $m$ and $n$, the division of the remainder $m \% n$ by $n$ equals zero, i.e., $(m \% n) / n = 0$.
Nat.mod_eq_iff theorem
{a b c : Nat} : a % b = c ↔ (b = 0 ∧ a = c) ∨ (c < b ∧ Exists fun k => a = b * k + c)
Full source
theorem mod_eq_iff {a b c : Nat} :
    a % b = c ↔ (b = 0 ∧ a = c) ∨ (c < b ∧ Exists fun k => a = b * k + c) :=
  ⟨fun h =>
    if w : b = 0 then
      .inl ⟨w, by simpa [w] using h⟩
    else
      .inr ⟨by subst h; exact Nat.mod_lt a (zero_lt_of_ne_zero w),
        a / b, by subst h; exact (div_add_mod a b).symm⟩,
   by
     rintro (⟨rfl, rfl⟩ | ⟨w, h, rfl⟩)
     · simp_all
     · rw [mul_add_mod, mod_eq_of_lt w]⟩
Characterization of Natural Number Modulo Operation: $a \% b = c \iff (b=0 \land a=c) \lor (c
Informal description
For any natural numbers $a$, $b$, and $c$, the equality $a \% b = c$ holds if and only if either: 1. $b = 0$ and $a = c$, or 2. $c < b$ and there exists a natural number $k$ such that $a = b \cdot k + c$.
Nat.mod_eq_sub_iff theorem
{a b c : Nat} (h₁ : 0 < c) (h : c ≤ b) : a % b = b - c ↔ b ∣ a + c
Full source
theorem mod_eq_sub_iff {a b c : Nat} (h₁ : 0 < c) (h : c ≤ b) : a % b = b - c ↔ b ∣ a + c := by
  rw [Nat.mod_eq_iff]
  refine ⟨?_, ?_⟩
  · rintro (⟨rfl, rfl⟩|⟨hlt, ⟨k, hk⟩⟩)
    · simp; omega
    · refine ⟨k + 1, ?_⟩
      rw [← Nat.add_sub_assoc h] at hk
      rw [Nat.mul_succ, eq_comm]
      apply Nat.eq_add_of_sub_eq (by omega) hk.symm
  · rintro ⟨k, hk⟩
    obtain (rfl|hb) := Nat.eq_zero_or_pos b
    · obtain rfl : c = 0 := by omega
      refine Or.inl ⟨rfl, by simpa using hk⟩
    · have : k ≠ 0 := by rintro rfl; omega
      refine Or.inr ⟨by omega, ⟨k - 1, ?_⟩⟩
      rw [← Nat.add_sub_assoc h, eq_comm]
      apply Nat.sub_eq_of_eq_add
      rw [mul_sub_one, Nat.sub_add_cancel (Nat.le_mul_of_pos_right _ (by omega)), hk]
Modulo Equals Difference iff Divisor Condition: $a \% b = b - c \iff b \mid a + c$
Informal description
For any natural numbers $a$, $b$, and $c$ such that $0 < c$ and $c \leq b$, the remainder of $a$ modulo $b$ equals $b - c$ if and only if $b$ divides $a + c$. In other words: $$a \% b = b - c \iff b \mid (a + c)$$
Nat.succ_mod_succ_eq_zero_iff theorem
{a b : Nat} : (a + 1) % (b + 1) = 0 ↔ a % (b + 1) = b
Full source
theorem succ_mod_succ_eq_zero_iff {a b : Nat} :
    (a + 1) % (b + 1) = 0 ↔ a % (b + 1) = b := by
  symm
  rw [mod_eq_iff, mod_eq_iff]
  simp only [add_one_ne_zero, false_and, Nat.lt_add_one, true_and, false_or, and_self, zero_lt_succ,
    Nat.add_zero]
  constructor
  · rintro ⟨k, rfl⟩
    refine ⟨k + 1, ?_⟩
    simp [Nat.add_mul, Nat.mul_add, Nat.add_assoc]
  · rintro ⟨k, h⟩
    cases k with
    | zero => simp at h
    | succ k =>
      refine ⟨k, ?_⟩
      simp only [Nat.mul_add, Nat.add_mul, Nat.one_mul, Nat.mul_one, ← Nat.add_assoc,
        Nat.add_right_cancel_iff] at h
      subst h
      simp [Nat.add_mul]
Characterization of Successor Modulo Zero Condition: $(a+1) \mod (b+1) = 0 \leftrightarrow a \mod (b+1) = b$
Informal description
For any natural numbers $a$ and $b$, the remainder of $(a + 1)$ divided by $(b + 1)$ is zero if and only if the remainder of $a$ divided by $(b + 1)$ equals $b$.
Nat.decidableBallLT instance
: ∀ (n : Nat) (P : ∀ k, k < n → Prop) [∀ n h, Decidable (P n h)], Decidable (∀ n h, P n h)
Full source
instance decidableBallLT :
  ∀ (n : Nat) (P : ∀ k, k < n → Prop) [∀ n h, Decidable (P n h)], Decidable (∀ n h, P n h)
| 0, _, _ => isTrue fun _ => (by cases ·)
| n + 1, P, H =>
  match decidableBallLT n (P · <| lt_succ_of_lt ·) with
  | isFalse h => isFalse (h fun _ _ => · _ _)
  | isTrue h =>
    match H n Nat.le.refl with
    | isFalse p => isFalse (p <| · _ _)
    | isTrue p => isTrue fun _ h' => (Nat.lt_succ_iff_lt_or_eq.1 h').elim (h _) fun hn => hn ▸ p
Decidability of Universal Quantification over Bounded Natural Numbers
Informal description
For any natural number $n$ and predicate $P$ on natural numbers $k < n$ with decidable instances, the proposition $\forall k < n, P(k)$ is decidable.
Nat.decidableForallFin instance
(P : Fin n → Prop) [DecidablePred P] : Decidable (∀ i, P i)
Full source
instance decidableForallFin (P : Fin n → Prop) [DecidablePred P] : Decidable (∀ i, P i) :=
  decidable_of_iff (∀ k h, P ⟨k, h⟩) ⟨fun m ⟨k, h⟩ => m k h, fun m k h => m ⟨k, h⟩⟩
Decidability of Universal Quantification over Finite Types
Informal description
For any natural number $n$ and decidable predicate $P$ on the finite type $\mathrm{Fin}\ n$, the universal statement $\forall i \in \mathrm{Fin}\ n, P(i)$ is decidable.
Nat.decidableBallLE instance
(n : Nat) (P : ∀ k, k ≤ n → Prop) [∀ n h, Decidable (P n h)] : Decidable (∀ n h, P n h)
Full source
instance decidableBallLE (n : Nat) (P : ∀ k, k ≤ n → Prop) [∀ n h, Decidable (P n h)] :
    Decidable (∀ n h, P n h) :=
  decidable_of_iff (∀ (k) (h : k < succ n), P k (le_of_lt_succ h))
    ⟨fun m k h => m k (lt_succ_of_le h), fun m k _ => m k _⟩
Decidability of Universal Quantification over Bounded Natural Numbers with Upper Bound
Informal description
For any natural number $n$ and predicate $P$ on natural numbers $k \leq n$ with decidable instances, the proposition $\forall k \leq n, P(k)$ is decidable.
Nat.decidableExistsLT instance
[h : DecidablePred p] : DecidablePred fun n => ∃ m : Nat, m < n ∧ p m
Full source
instance decidableExistsLT [h : DecidablePred p] : DecidablePred fun n => ∃ m : Nat, m < n ∧ p m
  | 0 => isFalse (by simp only [not_lt_zero, false_and, exists_const, not_false_eq_true])
  | n + 1 =>
    @decidable_of_decidable_of_iff _ _ (@instDecidableOr _ _ (decidableExistsLT (p := p) n) (h n))
      (by simp only [Nat.lt_succ_iff_lt_or_eq, or_and_right, exists_or, exists_eq_left])
Decidability of Bounded Existential Quantification over Natural Numbers
Informal description
For any decidable predicate $p$ on natural numbers, the predicate $\exists m < n, p(m)$ is also decidable for any natural number $n$.
Nat.decidableExistsLE instance
[DecidablePred p] : DecidablePred fun n => ∃ m : Nat, m ≤ n ∧ p m
Full source
instance decidableExistsLE [DecidablePred p] : DecidablePred fun n => ∃ m : Nat, m ≤ n ∧ p m :=
  fun n => decidable_of_iff (∃ m, m < n + 1 ∧ p m)
    (exists_congr fun _ => and_congr_left' Nat.lt_succ_iff)
Decidability of Bounded Existential Quantification with Upper Bound on Natural Numbers
Informal description
For any decidable predicate $p$ on natural numbers, the predicate $\exists m \leq n, p(m)$ is also decidable for any natural number $n$.
Nat.decidableExistsLT' instance
{p : (m : Nat) → m < k → Prop} [I : ∀ m h, Decidable (p m h)] : Decidable (∃ m : Nat, ∃ h : m < k, p m h)
Full source
/-- Dependent version of `decidableExistsLT`. -/
instance decidableExistsLT' {p : (m : Nat) → m < k → Prop} [I : ∀ m h, Decidable (p m h)] :
    Decidable (∃ m : Nat, ∃ h : m < k, p m h) :=
  match k, p, I with
  | 0, _, _ => isFalse (by simp)
  | (k + 1), p, I => @decidable_of_iff _ ((∃ m, ∃ h : m < k, p m (by omega)) ∨ p k (by omega))
      ⟨by rintro (⟨m, h, w⟩ | w); exact ⟨m, by omega, w⟩; exact ⟨k, by omega, w⟩,
        fun ⟨m, h, w⟩ => if h' : m < k then .inl ⟨m, h', w⟩ else
          by obtain rfl := (by omega : m = k); exact .inr w⟩
      (@instDecidableOr _ _
        (decidableExistsLT' (p := fun m h => p m (by omega)) (I := fun m h => I m (by omega)))
        inferInstance)
Decidability of Bounded Existential Quantifiers over Natural Numbers
Informal description
For any natural number $k$ and any predicate $p$ on pairs $(m, h)$ where $m$ is a natural number and $h$ is a proof that $m < k$, if $p$ is decidable for all such pairs, then the existential statement $\exists m < k, p(m, h)$ is decidable.
Nat.decidableExistsLE' instance
{p : (m : Nat) → m ≤ k → Prop} [I : ∀ m h, Decidable (p m h)] : Decidable (∃ m : Nat, ∃ h : m ≤ k, p m h)
Full source
/-- Dependent version of `decidableExistsLE`. -/
instance decidableExistsLE' {p : (m : Nat) → m ≤ k → Prop} [I : ∀ m h, Decidable (p m h)] :
    Decidable (∃ m : Nat, ∃ h : m ≤ k, p m h) :=
  decidable_of_iff (∃ m, ∃ h : m < k + 1, p m (by omega)) (exists_congr fun _ =>
    ⟨fun ⟨h, w⟩ => ⟨le_of_lt_succ h, w⟩, fun ⟨h, w⟩ => ⟨lt_add_one_of_le h, w⟩⟩)
Decidability of Bounded Existential Quantifiers over Natural Numbers with Upper Bound
Informal description
For any natural number $k$ and any predicate $p$ on pairs $(m, h)$ where $m$ is a natural number and $h$ is a proof that $m \leq k$, if $p$ is decidable for all such pairs, then the existential statement $\exists m \leq k, p(m, h)$ is decidable.
Nat.sum_pos_iff_exists_pos theorem
{l : List Nat} : 0 < l.sum ↔ ∃ x ∈ l, 0 < x
Full source
protected theorem sum_pos_iff_exists_pos {l : List Nat} : 0 < l.sum ↔ ∃ x ∈ l, 0 < x := by
  induction l with
  | nil => simp
  | cons x xs ih =>
    simp [← ih]
    omega
Sum of Natural Numbers is Positive if and only if List Contains a Positive Element
Informal description
For any list $l$ of natural numbers, the sum of the elements in $l$ is positive if and only if there exists an element $x$ in $l$ that is positive. In other words, $0 < \sum l \leftrightarrow \exists x \in l, 0 < x$.