Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 26179cc

Browse files
feat(data/list): add some lemmas. (#11879)
1 parent dcbb59c commit 26179cc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/data/list/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,9 @@ begin
29242924
exact not_lt_of_ge (length_le_of_sublist this) (lt_succ_self _) }
29252925
end
29262926

2927+
theorem filter_length_eq_length {l} : (filter p l).length = l.length ↔ ∀ a ∈ l, p a :=
2928+
iff.trans ⟨eq_of_sublist_of_length_eq l.filter_sublist, congr_arg list.length⟩ filter_eq_self
2929+
29272930
theorem filter_eq_nil {l} : filter p l = [] ↔ ∀ a ∈ l, ¬p a :=
29282931
by simp only [eq_nil_iff_forall_not_mem, mem_filter, not_and]
29292932

src/data/list/count.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ by simp only [countp_eq_length_filter, filter_append, length_append]
5050
lemma countp_pos {l} : 0 < countp p l ↔ ∃ a ∈ l, p a :=
5151
by simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop]
5252

53+
lemma countp_eq_length {l} : countp p l = l.length ↔ ∀ a ∈ l, p a :=
54+
by rw [countp_eq_length_filter, filter_length_eq_length]
55+
5356
lemma length_filter_lt_length_iff_exists (l) : length (filter p l) < length l ↔ ∃ x ∈ l, ¬p x :=
5457
by rw [length_eq_countp_add_countp p l, ← countp_pos, countp_eq_length_filter, lt_add_iff_pos_right]
5558

@@ -122,6 +125,9 @@ decidable.by_contradiction $ λ h', h $ count_pos.1 (nat.pos_of_ne_zero h')
122125
lemma not_mem_of_count_eq_zero {a : α} {l : list α} (h : count a l = 0) : a ∉ l :=
123126
λ h', (count_pos.2 h').ne' h
124127

128+
lemma count_eq_length {a : α} {l} : count a l = l.length ↔ ∀ b ∈ l, a = b :=
129+
by rw [count, countp_eq_length]
130+
125131
@[simp] lemma count_repeat (a : α) (n : ℕ) : count a (repeat a n) = n :=
126132
by rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat];
127133
exact λ b m, (eq_of_mem_repeat m).symm
@@ -157,10 +163,7 @@ end
157163
begin
158164
induction l with y l IH generalizing x,
159165
{ simp },
160-
{ rw map_cons,
161-
by_cases h : x = y,
162-
{ simpa [h] using IH _ },
163-
{ simpa [h, hf.ne h] using IH _ } }
166+
{ simp [map_cons, count_cons', IH, hf.eq_iff] }
164167
end
165168

166169
lemma count_le_count_map [decidable_eq β] (l : list α) (f : α → β) (x : α) :

0 commit comments

Comments
 (0)