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 thatNat.find hp
satisfiesp
.Nat.find_min
is the proof that ifm < Nat.find hp
thenm
does not satisfyp
.Nat.find_min'
is the proof that ifm
does satisfyp
thenNat.find hp ≤ m
.
Instances For
@[simp]
theorem
Nat.find_mono
{p : ℕ → Prop}
{q : ℕ → Prop}
[DecidablePred p]
[DecidablePred q]
(h : ∀ (n : ℕ), q n → p n)
{hp : ∃ (n : ℕ), p n}
{hq : ∃ (n : ℕ), q n}
:
Nat.findGreatest P n
is the largest i ≤ bound
such that P i
holds, or 0
if no such i
exists
Equations
- Nat.findGreatest P 0 = 0
- Nat.findGreatest P n.succ = if P (n + 1) then n + 1 else Nat.findGreatest P n
Instances For
@[simp]
theorem
Nat.findGreatest_succ
{P : ℕ → Prop}
[DecidablePred P]
(n : ℕ)
:
Nat.findGreatest P (n + 1) = if P (n + 1) then n + 1 else Nat.findGreatest P n
@[simp]
theorem
Nat.findGreatest_eq
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
:
P n → Nat.findGreatest P n = n
@[simp]
theorem
Nat.findGreatest_of_not
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
(h : ¬P (n + 1))
:
Nat.findGreatest P (n + 1) = Nat.findGreatest P n
@[simp]
theorem
Nat.findGreatest_spec
{m : ℕ}
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
(hmb : m ≤ n)
(hm : P m)
:
P (Nat.findGreatest P n)
theorem
Nat.le_findGreatest
{m : ℕ}
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
(hmb : m ≤ n)
(hm : P m)
:
m ≤ Nat.findGreatest P n
theorem
Nat.findGreatest_mono_right
(P : ℕ → Prop)
[DecidablePred P]
{m : ℕ}
{n : ℕ}
(hmn : m ≤ n)
:
Nat.findGreatest P m ≤ Nat.findGreatest P n
theorem
Nat.findGreatest_mono_left
{P : ℕ → Prop}
{Q : ℕ → Prop}
[DecidablePred P]
[DecidablePred Q]
(hPQ : ∀ (n : ℕ), P n → Q n)
(n : ℕ)
:
Nat.findGreatest P n ≤ Nat.findGreatest Q n
theorem
Nat.findGreatest_mono
{m : ℕ}
{P : ℕ → Prop}
{Q : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
[DecidablePred Q]
(hPQ : ∀ (n : ℕ), P n → Q n)
(hmn : m ≤ n)
:
Nat.findGreatest P m ≤ Nat.findGreatest Q n
theorem
Nat.findGreatest_is_greatest
{k : ℕ}
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
(hk : Nat.findGreatest P n < k)
(hkb : k ≤ n)
:
¬P k
theorem
Nat.findGreatest_of_ne_zero
{m : ℕ}
{P : ℕ → Prop}
[DecidablePred P]
{n : ℕ}
(h : Nat.findGreatest P n = m)
(h0 : m ≠ 0)
:
P m