File: Mathlib/Data/Nat/Nth.lean

full_name: Nat.nth
code: /-- Find the `n`-th natural number satisfying `p` (indexed from `0`, so `nth p 0` is the first
natural number satisfying `p`), or `0` if there is no such number. See also
`Subtype.orderIsoOfNat` for the order isomorphism with ℕ when `p` is infinitely often true. -/
noncomputable def nth (p : ℕ → Prop) (n : ℕ) : ℕ 
goal: ℕ

full_name: Nat.nth_of_card_le
code: theorem nth_of_card_le (hf : (setOf p).Finite) {n : ℕ} (hn : hf.toFinset.card ≤ n) :
    nth p n = 0 
goal: Nat.nth p n = 0

full_name: Nat.nth_eq_getD_sort
code: theorem nth_eq_getD_sort (h : (setOf p).Finite) (n : ℕ) :
    nth p n = (h.toFinset.sort (· ≤ ·)).getD n 0 
goal: Nat.nth p n = (Finset.sort (fun x x_1 => x ≤ x_1) h.toFinset).getD n 0

full_name: Nat.nth_eq_orderEmbOfFin
code: theorem nth_eq_orderEmbOfFin (hf : (setOf p).Finite) {n : ℕ} (hn : n < hf.toFinset.card) :
    nth p n = hf.toFinset.orderEmbOfFin rfl ⟨n, hn⟩ 
goal: Nat.nth p n = (hf.toFinset.orderEmbOfFin ⋯) ⟨n, hn⟩

full_name: Nat.nth_strictMonoOn
code: theorem nth_strictMonoOn (hf : (setOf p).Finite) :
    StrictMonoOn (nth p) (Set.Iio hf.toFinset.card) 
goal: StrictMonoOn (Nat.nth p) (Set.Iio hf.toFinset.card)

full_name: Nat.nth_lt_nth_of_lt_card
code: theorem nth_lt_nth_of_lt_card (hf : (setOf p).Finite) {m n : ℕ} (h : m < n)
    (hn : n < hf.toFinset.card) : nth p m < nth p n 
goal: Nat.nth p m < Nat.nth p n

full_name: Nat.nth_le_nth_of_lt_card
code: theorem nth_le_nth_of_lt_card (hf : (setOf p).Finite) {m n : ℕ} (h : m ≤ n)
    (hn : n < hf.toFinset.card) : nth p m ≤ nth p n 
goal: Nat.nth p m ≤ Nat.nth p n

full_name: Nat.lt_of_nth_lt_nth_of_lt_card
code: theorem lt_of_nth_lt_nth_of_lt_card (hf : (setOf p).Finite) {m n : ℕ} (h : nth p m < nth p n)
    (hm : m < hf.toFinset.card) : m < n 
goal: m < n

full_name: Nat.le_of_nth_le_nth_of_lt_card
code: theorem le_of_nth_le_nth_of_lt_card (hf : (setOf p).Finite) {m n : ℕ} (h : nth p m ≤ nth p n)
    (hm : m < hf.toFinset.card) : m ≤ n 
goal: m ≤ n

full_name: Nat.nth_injOn
code: theorem nth_injOn (hf : (setOf p).Finite) : (Set.Iio hf.toFinset.card).InjOn (nth p) 
goal: Set.InjOn (Nat.nth p) (Set.Iio hf.toFinset.card)

full_name: Nat.range_nth_of_finite
code: theorem range_nth_of_finite (hf : (setOf p).Finite) : Set.range (nth p) = insert 0 (setOf p) 
goal: Set.range (Nat.nth p) = insert 0 (setOf p)

full_name: Nat.image_nth_Iio_card
code: @[simp]
theorem image_nth_Iio_card (hf : (setOf p).Finite) : nth p '' Set.Iio hf.toFinset.card = setOf p 
goal: Nat.nth p '' Set.Iio hf.toFinset.card = setOf p

full_name: Nat.nth_mem_of_lt_card
code: theorem nth_mem_of_lt_card {n : ℕ} (hf : (setOf p).Finite) (hlt : n < hf.toFinset.card) :
    p (nth p n) 
goal: p (Nat.nth p n)

full_name: Nat.exists_lt_card_finite_nth_eq
code: theorem exists_lt_card_finite_nth_eq (hf : (setOf p).Finite) {x} (h : p x) :
    ∃ n, n < hf.toFinset.card ∧ nth p n = x 
goal: ∃ n < hf.toFinset.card, Nat.nth p n = x

full_name: Nat.nth_apply_eq_orderIsoOfNat
code: /-- When `s` is an infinite set, `nth` agrees with `Nat.Subtype.orderIsoOfNat`. -/
theorem nth_apply_eq_orderIsoOfNat (hf : (setOf p).Infinite) (n : ℕ) :
    nth p n = @Nat.Subtype.orderIsoOfNat (setOf p) hf.to_subtype n 
goal: Nat.nth p n = ↑((Nat.Subtype.orderIsoOfNat (setOf p)) n)

full_name: Nat.nth_eq_orderIsoOfNat
code: /-- When `s` is an infinite set, `nth` agrees with `Nat.Subtype.orderIsoOfNat`. -/
theorem nth_eq_orderIsoOfNat (hf : (setOf p).Infinite) :
    nth p = (↑) ∘ @Nat.Subtype.orderIsoOfNat (setOf p) hf.to_subtype 
goal: Nat.nth p = Subtype.val ∘ ⇑(Nat.Subtype.orderIsoOfNat (setOf p))

full_name: Nat.nth_strictMono
code: theorem nth_strictMono (hf : (setOf p).Infinite) : StrictMono (nth p) 
goal: StrictMono (Nat.nth p)

full_name: Nat.nth_injective
code: theorem nth_injective (hf : (setOf p).Infinite) : Function.Injective (nth p) 
goal: Function.Injective (Nat.nth p)

full_name: Nat.nth_monotone
code: theorem nth_monotone (hf : (setOf p).Infinite) : Monotone (nth p) 
goal: Monotone (Nat.nth p)

full_name: Nat.nth_lt_nth
code: theorem nth_lt_nth (hf : (setOf p).Infinite) {k n} : nth p k < nth p n ↔ k < n 
goal: Nat.nth p k < Nat.nth p n ↔ k < n

full_name: Nat.nth_le_nth
code: theorem nth_le_nth (hf : (setOf p).Infinite) {k n} : nth p k ≤ nth p n ↔ k ≤ n 
goal: Nat.nth p k ≤ Nat.nth p n ↔ k ≤ n

full_name: Nat.range_nth_of_infinite
code: theorem range_nth_of_infinite (hf : (setOf p).Infinite) : Set.range (nth p) = setOf p 
goal: Set.range (Nat.nth p) = setOf p

full_name: Nat.nth_mem_of_infinite
code: theorem nth_mem_of_infinite (hf : (setOf p).Infinite) (n : ℕ) : p (nth p n) 
goal: p (Nat.nth p n)

full_name: Nat.exists_lt_card_nth_eq
code: theorem exists_lt_card_nth_eq {x} (h : p x) :
    ∃ n, (∀ hf : (setOf p).Finite, n < hf.toFinset.card) ∧ nth p n = x 
goal: ∃ n, (∀ (hf : (setOf p).Finite), n < hf.toFinset.card) ∧ Nat.nth p n = x

full_name: Nat.subset_range_nth
code: theorem subset_range_nth : setOf p ⊆ Set.range (nth p) 
goal: setOf p ⊆ Set.range (Nat.nth p)

full_name: Nat.range_nth_subset
code: theorem range_nth_subset : Set.range (nth p) ⊆ insert 0 (setOf p) 
goal: Set.range (Nat.nth p) ⊆ insert 0 (setOf p)

full_name: Nat.nth_mem
code: theorem nth_mem (n : ℕ) (h : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) : p (nth p n) 
goal: p (Nat.nth p n)

full_name: Nat.nth_lt_nth'
code: theorem nth_lt_nth' {m n : ℕ} (hlt : m < n) (h : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    nth p m < nth p n 
goal: Nat.nth p m < Nat.nth p n

full_name: Nat.nth_le_nth'
code: theorem nth_le_nth' {m n : ℕ} (hle : m ≤ n) (h : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    nth p m ≤ nth p n 
goal: Nat.nth p m ≤ Nat.nth p n

full_name: Nat.le_nth
code: theorem le_nth {n : ℕ} (h : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) : n ≤ nth p n 
goal: n ≤ Nat.nth p n

full_name: Nat.isLeast_nth
code: theorem isLeast_nth {n} (h : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    IsLeast {i | p i ∧ ∀ k < n, nth p k < i} (nth p n) 
goal: IsLeast {i | p i ∧ ∀ k < n, Nat.nth p k < i} (Nat.nth p n)

full_name: Nat.isLeast_nth_of_lt_card
code: theorem isLeast_nth_of_lt_card {n : ℕ} (hf : (setOf p).Finite) (hn : n < hf.toFinset.card) :
    IsLeast {i | p i ∧ ∀ k < n, nth p k < i} (nth p n) 
goal: IsLeast {i | p i ∧ ∀ k < n, Nat.nth p k < i} (Nat.nth p n)

full_name: Nat.isLeast_nth_of_infinite
code: theorem isLeast_nth_of_infinite (hf : (setOf p).Infinite) (n : ℕ) :
    IsLeast {i | p i ∧ ∀ k < n, nth p k < i} (nth p n) 
goal: IsLeast {i | p i ∧ ∀ k < n, Nat.nth p k < i} (Nat.nth p n)

full_name: Nat.nth_eq_sInf
code: /-- An alternative recursive definition of `Nat.nth`: `Nat.nth s n` is the infimum of `x ∈ s` such
that `Nat.nth s k < x` for all `k < n`, if this set is nonempty. We do not assume that the set is
nonempty because we use the same "garbage value" `0` both for `sInf` on `ℕ` and for `Nat.nth s n`
for `n ≥ card s`. -/
theorem nth_eq_sInf (p : ℕ → Prop) (n : ℕ) : nth p n = sInf {x | p x ∧ ∀ k < n, nth p k < x} 
goal: Nat.nth p n = sInf {x | p x ∧ ∀ k < n, Nat.nth p k < x}

full_name: Nat.nth_zero
code: theorem nth_zero : nth p 0 = sInf (setOf p) 
goal: Nat.nth p 0 = sInf (setOf p)

full_name: Nat.nth_zero_of_zero
code: @[simp]
theorem nth_zero_of_zero (h : p 0) : nth p 0 = 0 
goal: Nat.nth p 0 = 0

full_name: Nat.nth_zero_of_exists
code: theorem nth_zero_of_exists [DecidablePred p] (h : ∃ n, p n) : nth p 0 = Nat.find h 
goal: Nat.nth p 0 = Nat.find h

full_name: Nat.nth_eq_zero
code: theorem nth_eq_zero {n} :
    nth p n = 0 ↔ p 0 ∧ n = 0 ∨ ∃ hf : (setOf p).Finite, hf.toFinset.card ≤ n 
goal: Nat.nth p n = 0 ↔ p 0 ∧ n = 0 ∨ ∃ (hf : (setOf p).Finite), hf.toFinset.card ≤ n

full_name: Nat.nth_eq_zero_mono
code: theorem nth_eq_zero_mono (h₀ : ¬p 0) {a b : ℕ} (hab : a ≤ b) (ha : nth p a = 0) : nth p b = 0 
goal: Nat.nth p b = 0

full_name: Nat.le_nth_of_lt_nth_succ
code: theorem le_nth_of_lt_nth_succ {k a : ℕ} (h : a < nth p (k + 1)) (ha : p a) : a ≤ nth p k 
goal: a ≤ Nat.nth p k

full_name: Nat.count_nth_zero
code: @[simp]
theorem count_nth_zero : count p (nth p 0) = 0 
goal: Nat.count p (Nat.nth p 0) = 0

full_name: Nat.filter_range_nth_subset_insert
code: theorem filter_range_nth_subset_insert (k : ℕ) :
    (range (nth p (k + 1))).filter p ⊆ insert (nth p k) ((range (nth p k)).filter p) 
goal: Finset.filter p (Finset.range (Nat.nth p (k + 1))) ⊆ insert (Nat.nth p k) (Finset.filter p (Finset.range (Nat.nth p k)))

full_name: Nat.filter_range_nth_eq_insert
code: theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) 
goal: Finset.filter p (Finset.range (Nat.nth p (k + 1))) = insert (Nat.nth p k) (Finset.filter p (Finset.range (Nat.nth p k)))

full_name: Nat.filter_range_nth_eq_insert_of_finite
code: theorem filter_range_nth_eq_insert_of_finite (hf : (setOf p).Finite) {k : ℕ}
    (hlt : k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) 
goal: Finset.filter p (Finset.range (Nat.nth p (k + 1))) = insert (Nat.nth p k) (Finset.filter p (Finset.range (Nat.nth p k)))

full_name: Nat.filter_range_nth_eq_insert_of_infinite
code: theorem filter_range_nth_eq_insert_of_infinite (hp : (setOf p).Infinite) (k : ℕ) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) 
goal: Finset.filter p (Finset.range (Nat.nth p (k + 1))) = insert (Nat.nth p k) (Finset.filter p (Finset.range (Nat.nth p k)))

full_name: Nat.count_nth
code: theorem count_nth {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n) = n 
goal: Nat.count p (Nat.nth p n) = n

full_name: Nat.count_nth_of_lt_card_finite
code: theorem count_nth_of_lt_card_finite {n : ℕ} (hp : (setOf p).Finite) (hlt : n < hp.toFinset.card) :
    count p (nth p n) = n 
goal: Nat.count p (Nat.nth p n) = n

full_name: Nat.count_nth_of_infinite
code: theorem count_nth_of_infinite (hp : (setOf p).Infinite) (n : ℕ) : count p (nth p n) = n 
goal: Nat.count p (Nat.nth p n) = n

full_name: Nat.count_nth_succ
code: theorem count_nth_succ {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n + 1) = n + 1 
goal: Nat.count p (Nat.nth p n + 1) = n + 1

full_name: Nat.nth_count
code: @[simp]
theorem nth_count {n : ℕ} (hpn : p n) : nth p (count p n) = n 
goal: Nat.nth p (Nat.count p n) = n

full_name: Nat.nth_lt_of_lt_count
code: theorem nth_lt_of_lt_count {n k : ℕ} (h : k < count p n) : nth p k < n 
goal: Nat.nth p k < n

full_name: Nat.le_nth_of_count_le
code: theorem le_nth_of_count_le {n k : ℕ} (h : n ≤ nth p k) : count p n ≤ k 
goal: Nat.count p n ≤ k

full_name: Nat.nth_count_eq_sInf
code: theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} 
goal: Nat.nth p (Nat.count p n) = sInf {i | p i ∧ n ≤ i}

full_name: Nat.le_nth_count'
code: theorem le_nth_count' {n : ℕ} (hpn : ∃ k, p k ∧ n ≤ k) : n ≤ nth p (count p n) 
goal: n ≤ Nat.nth p (Nat.count p n)

full_name: Nat.le_nth_count
code: theorem le_nth_count (hp : (setOf p).Infinite) (n : ℕ) : n ≤ nth p (count p n) 
goal: n ≤ Nat.nth p (Nat.count p n)

full_name: Nat.giCountNth
code: /-- If a predicate `p : ℕ → Prop` is true for infinitely many numbers, then `Nat.count p` and
`Nat.nth p` form a Galois insertion. -/
noncomputable def giCountNth (hp : (setOf p).Infinite) : GaloisInsertion (count p) (nth p) 
goal: GaloisInsertion (Nat.count p) (Nat.nth p)

full_name: Nat.gc_count_nth
code: theorem gc_count_nth (hp : (setOf p).Infinite) : GaloisConnection (count p) (nth p) 
goal: GaloisConnection (Nat.count p) (Nat.nth p)

full_name: Nat.count_le_iff_le_nth
code: theorem count_le_iff_le_nth (hp : (setOf p).Infinite) {a b : ℕ} : count p a ≤ b ↔ a ≤ nth p b 
goal: Nat.count p a ≤ b ↔ a ≤ Nat.nth p b

full_name: Nat.lt_nth_iff_count_lt
code: theorem lt_nth_iff_count_lt (hp : (setOf p).Infinite) {a b : ℕ} : a < count p b ↔ nth p a < b 
goal: a < Nat.count p b ↔ Nat.nth p a < b

full_name: Nat.nth_of_forall
code: theorem nth_of_forall {n : ℕ} (hp : ∀ n' ≤ n, p n') : nth p n = n 
goal: Nat.nth p n = n

full_name: Nat.nth_true
code: @[simp] theorem nth_true (n : ℕ) : nth (fun _ ↦ True) n = n 
goal: Nat.nth (fun x => True) n = n

full_name: Nat.nth_of_forall_not
code: theorem nth_of_forall_not {n : ℕ} (hp : ∀ n' ≥ n, ¬p n') : nth p n = 0 
goal: Nat.nth p n = 0

full_name: Nat.nth_false
code: @[simp] theorem nth_false (n : ℕ) : nth (fun _ ↦ False) n = 0 
goal: Nat.nth (fun x => False) n = 0