The Mathlib Handbook

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

The areas / V02. Numbers

Mathlib.Data.Nat.Find

39 declarations. Mathlib docs · Source

Nat.find and Nat.findGreatest

Nat.find

Nat.findGreatest

theorem Nat.findGreatest.match_1.congr_eq_1 E1 #

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

theorem Nat.find.congr_simp E1 #

∀ {p p_1 : ℕ → Prop} (e_p : p = p_1) {inst : DecidablePred p} [inst_1 : DecidablePred p_1] (H : ∃ n, p n),
  Nat.find H = Nat.find ⋯

theorem Nat.findGreatest.match_1.congr_eq_2 E1 #

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

theorem Nat.findGreatest.congr_simp E1 #

∀ (P P_1 : ℕ → Prop),
  P = P_1 →
    ∀ {inst : DecidablePred P} [inst_1 : DecidablePred P_1] (a a_1 : ℕ),
      a = a_1 → Nat.findGreatest P a = Nat.findGreatest P_1 a_1

def Nat.findX E1 #

{p : ℕ → Prop} → [DecidablePred p] → (∃ n, p n) → { n // p n ∧ ∀ m < n, ¬p m }

Find the smallest n satisfying p n. Returns a subtype.

def Nat.find E1 #

{p : ℕ → Prop} → [DecidablePred p] → (∃ n, p n) → ℕ

If p is a (decidable) predicate on ℕ and hp : ∃ (n : ℕ), p n is a proof that there exists some natural number satisfying p, then Nat.find hp is the smallest natural number satisfying p. Note that Nat.find is protected, meaning that you can't just write find, even if the Nat namespace is open.

The API for Nat.find is:

  • Nat.find_spec is the proof that Nat.find hp satisfies p.
  • Nat.find_min is the proof that if m < Nat.find hp then m does not satisfy p.
  • Nat.find_min' is the proof that if m does satisfy p then Nat.find hp ≤ m.

theorem Nat.find_spec E1 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (H : ∃ n, p n), p (Nat.find H)

theorem Nat.find_min E1 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (H : ∃ n, p n) {m : ℕ}, m < Nat.find H → ¬p m

theorem Nat.find_min' E1 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (H : ∃ n, p n) {m : ℕ}, p m → Nat.find H ≤ m

theorem Nat.find_eq_iff E0 #

∀ {m : ℕ} {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n), Nat.find h = m ↔ p m ∧ ∀ n < m, ¬p n

theorem Nat.find_lt_iff E0 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n) (n : ℕ), Nat.find h < n ↔ ∃ m < n, p m

theorem Nat.find_le_iff E0 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n) (n : ℕ), Nat.find h ≤ n ↔ ∃ m ≤ n, p m

theorem Nat.le_find_iff E0 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n) (n : ℕ), n ≤ Nat.find h ↔ ∀ m < n, ¬p m

theorem Nat.lt_find_iff E0 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n) (n : ℕ), n < Nat.find h ↔ ∀ m ≤ n, ¬p m

theorem Nat.find_eq_zero E0 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n), Nat.find h = 0 ↔ p 0

theorem Nat.find_mono_of_le E1 #

∀ {p q : ℕ → Prop} [inst : DecidablePred p] [inst_1 : DecidablePred q] {x : ℕ} (hx : q x) (hpq : ∀ n ≤ x, q n → p n),
  Nat.find ⋯ ≤ Nat.find ⋯

If a predicate q holds at some x and implies p up to that x, then the earliest xq such that q xq is at least the smallest xp where p xp. The stronger version of Nat.find_mono, since this one needs implication only up to Nat.find _ while the other requires q implying p everywhere.

theorem Nat.find_mono E1 #

∀ {p q : ℕ → Prop} [inst : DecidablePred p] [inst_1 : DecidablePred q],
  (∀ (n : ℕ), q n → p n) → ∀ {hp : ∃ n, p n} {hq : ∃ n, q n}, Nat.find hp ≤ Nat.find hq

A weak version of Nat.find_mono_of_le, requiring q implies p everywhere.

theorem Nat.find_congr E1 #

∀ {p q : ℕ → Prop} [inst : DecidablePred p] [inst_1 : DecidablePred q] {x : ℕ} (hx : p x) (hpq : ∀ n ≤ x, p n ↔ q n),
  Nat.find ⋯ = Nat.find ⋯

If a predicate p holds at some x and agrees with q up to that x, then their Nat.find agree. The stronger version of Nat.find_congr', since this one needs agreement only up to Nat.find _ while the other requires p = q. Usage of this lemma will likely be via obtain ⟨x, hx⟩ := hp; apply Nat.find_congr hx to unify q, or provide it explicitly with rw [Nat.find_congr (q := q) hx].

theorem Nat.find_congr' E1 #

∀ {p q : ℕ → Prop} [inst : DecidablePred p] [inst_1 : DecidablePred q] {hp : ∃ n, p n} {hq : ∃ n, q n},
  (∀ {n : ℕ}, p n ↔ q n) → Nat.find hp = Nat.find hq

A weak version of Nat.find_congr, requiring p = q everywhere.

theorem Nat.find_le E1 #

∀ {n : ℕ} {p : ℕ → Prop} [inst : DecidablePred p] {h : ∃ n, p n}, p n → Nat.find h ≤ n

theorem Nat.find_comp_succ E1 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h₁ : ∃ n, p n) (h₂ : ∃ n, p (n + 1)), ¬p 0 → Nat.find h₁ = Nat.find h₂ + 1

theorem Nat.find_pos E1 #

∀ {p : ℕ → Prop} [inst : DecidablePred p] (h : ∃ n, p n), 0 < Nat.find h ↔ ¬p 0

theorem Nat.find_add E1 #

∀ {n : ℕ} {p : ℕ → Prop} [inst : DecidablePred p] {hₘ : ∃ m, p (m + n)} {hₙ : ∃ n, p n},
  n ≤ Nat.find hₙ → Nat.find hₘ + n = Nat.find hₙ

def Nat.findGreatest E1 #

(P : ℕ → Prop) → [DecidablePred P] → ℕ → ℕ

Nat.findGreatest P n is the largest i ≤ n such that P i holds, or 0 if no such i exists

theorem Nat.findGreatest_zero E0 #

∀ {P : ℕ → Prop} [inst : DecidablePred P], Nat.findGreatest P 0 = 0

theorem Nat.findGreatest_succ E1 #

∀ {P : ℕ → Prop} [inst : DecidablePred P] (n : ℕ),
  Nat.findGreatest P (n + 1) = if P (n + 1) then n + 1 else Nat.findGreatest P n

theorem Nat.findGreatest_eq E0 #

∀ {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, P n → Nat.findGreatest P n = n

theorem Nat.findGreatest_of_not E0 #

∀ {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, ¬P (n + 1) → Nat.findGreatest P (n + 1) = Nat.findGreatest P n

theorem Nat.findGreatest_eq_iff E0 #

∀ {m k : ℕ} {P : ℕ → Prop} [inst : DecidablePred P],
  Nat.findGreatest P k = m ↔ m ≤ k ∧ (m ≠ 0 → P m) ∧ ∀ ⦃n : ℕ⦄, m < n → n ≤ k → ¬P n

theorem Nat.findGreatest_eq_zero_iff E0 #

∀ {k : ℕ} {P : ℕ → Prop} [inst : DecidablePred P], Nat.findGreatest P k = 0 ↔ ∀ ⦃n : ℕ⦄, 0 < n → n ≤ k → ¬P n

theorem Nat.findGreatest_pos E0 #

∀ {k : ℕ} {P : ℕ → Prop} [inst : DecidablePred P], 0 < Nat.findGreatest P k ↔ ∃ n, 0 < n ∧ n ≤ k ∧ P n

theorem Nat.findGreatest_spec E1 #

∀ {m : ℕ} {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, m ≤ n → P m → P (Nat.findGreatest P n)

theorem Nat.findGreatest_le E1 #

∀ {P : ℕ → Prop} [inst : DecidablePred P] (n : ℕ), Nat.findGreatest P n ≤ n

theorem Nat.le_findGreatest E1 #

∀ {m : ℕ} {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, m ≤ n → P m → m ≤ Nat.findGreatest P n

theorem Nat.findGreatest_mono_right E1 #

∀ (P : ℕ → Prop) [inst : DecidablePred P] {m n : ℕ}, m ≤ n → Nat.findGreatest P m ≤ Nat.findGreatest P n

theorem Nat.findGreatest_mono_left E1 #

∀ {P Q : ℕ → Prop} [inst : DecidablePred P] [inst_1 : DecidablePred Q],
  (∀ (n : ℕ), P n → Q n) → ∀ (n : ℕ), Nat.findGreatest P n ≤ Nat.findGreatest Q n

theorem Nat.findGreatest_mono E1 #

∀ {m : ℕ} {P Q : ℕ → Prop} [inst : DecidablePred P] {n : ℕ} [inst_1 : DecidablePred Q],
  (∀ (n : ℕ), P n → Q n) → m ≤ n → Nat.findGreatest P m ≤ Nat.findGreatest Q n

theorem Nat.findGreatest_is_greatest E1 #

∀ {k : ℕ} {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, Nat.findGreatest P n < k → k ≤ n → ¬P k

theorem Nat.findGreatest_of_ne_zero E1 #

∀ {m : ℕ} {P : ℕ → Prop} [inst : DecidablePred P] {n : ℕ}, Nat.findGreatest P n = m → m ≠ 0 → P m