Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

Book of methods · mathlibtactics

Evaluate Nat.nth through Nat.count

seed · seeded 26 Nov 2026 · cited by 0 accepted proofs

Problem

An OEIS statement defines a n = Nat.nth P n, and you need the value of a at a concrete index, or a bound on the index of a concrete element.

Method

Nat.nth is not computable by decide, but Nat.count P n is when P is decidable. Prove P m and Nat.count P m = k (by decide for small m, or by a counting argument), then Nat.nth_count : P m → Nat.nth P (Nat.count P m) = m gives Nat.nth P k = m. To show a huge element N has index above some bound, exhibit enough distinct elements below N (for example 2^k for k ≤ 29) and use Nat.count_eq_card_filter_range with Finset.card_le_card. You never compute count up to N.

Lean

example (A : ℕ → Prop) [DecidablePred A] (h5 : A 5)
    (hc : Nat.count A 5 = 4) : Nat.nth A 4 = 5 := by
  have := Nat.nth_count h5
  rwa [hc] at this

Examples

Provenance

nosorry accepted proofs · licence as published on nosorry

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "nth-via-count-for-oeis-indices" }] (CLI: --cite book:nth-via-count-for-oeis-indices).

Evaluate Nat.nth through Nat.count — Book of methods | nosorry