Skip to content

Commit

Permalink
feat(Data/Nat/Nth): nth_mem_anti (#19169)
Browse files Browse the repository at this point in the history
Add another lemma for working with `Nat.nth`:

```lean
lemma nth_mem_anti {a b : ℕ} (hab : a ≤ b) (h : p (nth p b)) : p (nth p a) := by
```

Feel free to golf if you see a simpler way of proving this.
  • Loading branch information
jsm28 committed Nov 20, 2024
1 parent 0e836d6 commit 995c25c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Mathlib/Data/Nat/Nth.lean
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ theorem le_nth_of_lt_nth_succ {k a : ℕ} (h : a < nth p (k + 1)) (ha : p a) : a
· rcases subset_range_nth ha with ⟨n, rfl⟩
rwa [nth_lt_nth hf, Nat.lt_succ_iff, ← nth_le_nth hf] at h

lemma nth_mem_anti {a b : ℕ} (hab : a ≤ b) (h : p (nth p b)) : p (nth p a) := by
by_cases h' : ∀ hf : (setOf p).Finite, a < #hf.toFinset
· exact nth_mem a h'
· simp only [not_forall, not_lt] at h'
have h'b : ∃ hf : (setOf p).Finite, #hf.toFinset ≤ b := by
rcases h' with ⟨hf, ha⟩
exact ⟨hf, ha.trans hab⟩
have ha0 : nth p a = 0 := by simp [nth_eq_zero, h']
have hb0 : nth p b = 0 := by simp [nth_eq_zero, h'b]
rw [ha0]
rwa [hb0] at h

section Count

variable (p) [DecidablePred p]
Expand Down

0 comments on commit 995c25c

Please sign in to comment.