File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,19 @@ theorem count_lt_card {n : ℕ} (hp : (setOf p).Finite) (hpn : p n) : count p n
146
146
(count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)
147
147
#align nat.count_lt_card Nat.count_lt_card
148
148
149
+ theorem count_of_forall {n : ℕ} (hp : ∀ n' < n, p n') : count p n = n := by
150
+ rw [count_eq_card_filter_range, filter_true_of_mem, card_range]
151
+ · simpa only [Finset.mem_range]
152
+
153
+ @[simp] theorem count_true (n : ℕ) : count (fun _ ↦ True) n = n := count_of_forall fun _ _ ↦ trivial
154
+
155
+ theorem count_of_forall_not {n : ℕ} (hp : ∀ n' < n, ¬p n') : count p n = 0 := by
156
+ rw [count_eq_card_filter_range, filter_false_of_mem, card_empty]
157
+ · simpa only [Finset.mem_range]
158
+
159
+ @[simp] theorem count_false (n : ℕ) : count (fun _ ↦ False) n = 0 :=
160
+ count_of_forall_not fun _ _ ↦ id
161
+
149
162
variable {q : ℕ → Prop }
150
163
variable [DecidablePred q]
151
164
Original file line number Diff line number Diff line change @@ -413,4 +413,20 @@ theorem lt_nth_iff_count_lt (hp : (setOf p).Infinite) {a b : ℕ} : a < count p
413
413
414
414
end Count
415
415
416
+ theorem nth_of_forall {n : ℕ} (hp : ∀ n' ≤ n, p n') : nth p n = n := by
417
+ classical nth_rw 1 [← count_of_forall (hp · ·.le), nth_count (hp n le_rfl)]
418
+
419
+ @[simp] theorem nth_true (n : ℕ) : nth (fun _ ↦ True) n = n := nth_of_forall fun _ _ ↦ trivial
420
+
421
+ theorem nth_of_forall_not {n : ℕ} (hp : ∀ n' ≥ n, ¬p n') : nth p n = 0 := by
422
+ have : setOf p ⊆ Finset.range n := by
423
+ intro n' hn'
424
+ contrapose! hp
425
+ exact ⟨n', by simpa using hp, Set.mem_setOf.mp hn'⟩
426
+ rw [nth_of_card_le ((finite_toSet _).subset this)]
427
+ · refine (Finset.card_le_card ?_).trans_eq (Finset.card_range n)
428
+ exact Set.Finite.toFinset_subset.mpr this
429
+
430
+ @[simp] theorem nth_false (n : ℕ) : nth (fun _ ↦ False) n = 0 := nth_of_forall_not fun _ _ ↦ id
431
+
416
432
end Nat
You can’t perform that action at this time.
0 commit comments