File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ theorem countP_push {a : α} {xs : Array α} : countP p (xs.push a) = countP p x
5252 rcases xs with ⟨xs⟩
5353 simp_all
5454
55+ @[grind =]
5556theorem countP_singleton {a : α} : countP p #[a] = if p a then 1 else 0 := by
5657 simp
5758
@@ -63,6 +64,8 @@ theorem countP_eq_size_filter {xs : Array α} : countP p xs = (filter p xs).size
6364 rcases xs with ⟨xs⟩
6465 simp [List.countP_eq_length_filter]
6566
67+ grind_pattern countP_eq_size_filter => countP p xs, filter p xs
68+
6669theorem countP_eq_size_filter' : countP p = size ∘ filter p := by
6770 funext xs
6871 apply countP_eq_size_filter
@@ -189,13 +192,14 @@ theorem count_le_size {a : α} {xs : Array α} : count a xs ≤ xs.size := count
189192theorem count_le_count_push {a b : α} {xs : Array α} : count a xs ≤ count a (xs.push b) := by
190193 simp [count_push]
191194
195+ @[grind =]
192196theorem count_singleton {a b : α} : count a #[b] = if b == a then 1 else 0 := by
193197 simp [count_eq_countP]
194198
195199@[simp, grind =] theorem count_append {a : α} {xs ys : Array α} : count a (xs ++ ys) = count a xs + count a ys :=
196200 countP_append
197201
198- @[simp] theorem count_flatten {a : α} {xss : Array (Array α)} :
202+ @[simp, grind = ] theorem count_flatten {a : α} {xss : Array (Array α)} :
199203 count a xss.flatten = (xss.map (count a)).sum := by
200204 cases xss using array₂_induction
201205 simp [List.count_flatten, Function.comp_def]
Original file line number Diff line number Diff line change @@ -91,17 +91,26 @@ theorem Perm.mem_iff {a : α} {xs ys : Array α} (p : xs ~ ys) : a ∈ xs ↔ a
9191 simp only [perm_iff_toList_perm] at p
9292 simpa using p.mem_iff
9393
94+ grind_pattern Perm.mem_iff => xs ~ ys, a ∈ xs
95+ grind_pattern Perm.mem_iff => xs ~ ys, a ∈ ys
96+
9497theorem Perm.append {xs ys as bs : Array α} (p₁ : xs ~ ys) (p₂ : as ~ bs) :
9598 xs ++ as ~ ys ++ bs := by
9699 cases xs; cases ys; cases as; cases bs
97100 simp only [append_toArray, perm_iff_toList_perm] at p₁ p₂ ⊢
98101 exact p₁.append p₂
99102
103+ grind_pattern Perm.append => xs ~ ys, as ~ bs, xs ++ as
104+ grind_pattern Perm.append => xs ~ ys, as ~ bs, ys ++ bs
105+
100106theorem Perm.push (x : α) {xs ys : Array α} (p : xs ~ ys) :
101107 xs.push x ~ ys.push x := by
102108 rw [push_eq_append_singleton]
103109 exact p.append .rfl
104110
111+ grind_pattern Perm.push => xs ~ ys, xs.push x
112+ grind_pattern Perm.push => xs ~ ys, ys.push x
113+
105114theorem Perm.push_comm (x y : α) {xs ys : Array α} (p : xs ~ ys) :
106115 (xs.push x).push y ~ (ys.push y).push x := by
107116 cases xs; cases ys
Original file line number Diff line number Diff line change @@ -128,6 +128,16 @@ theorem erase_range' :
128128 simp only [← List.toArray_range', List.erase_toArray]
129129 simp [List.erase_range']
130130
131+ @[simp, grind =]
132+ theorem count_range' {a s n step} (h : 0 < step := by simp) :
133+ count a (range' s n step) = if ∃ i, i < n ∧ a = s + step * i then 1 else 0 := by
134+ rw [← List.toArray_range', List.count_toArray, ← List.count_range' h]
135+
136+ @[simp, grind =]
137+ theorem count_range_1' {a s n} :
138+ count a (range' s n) = if s ≤ a ∧ a < s + n then 1 else 0 := by
139+ rw [← List.toArray_range', List.count_toArray, ← List.count_range_1']
140+
131141/-! ### range -/
132142
133143@[grind _=_]
@@ -191,6 +201,10 @@ theorem self_mem_range_succ {n : Nat} : n ∈ range (n + 1) := by simp
191201theorem erase_range : (range n).erase i = range (min n i) ++ range' (i + 1 ) (n - (i + 1 )) := by
192202 simp [range_eq_range', erase_range']
193203
204+ @[simp, grind =]
205+ theorem count_range {a n} :
206+ count a (range n) = if a < n then 1 else 0 := by
207+ rw [← List.toArray_range, List.count_toArray, ← List.count_range]
194208
195209/-! ### zipIdx -/
196210
Original file line number Diff line number Diff line change @@ -108,9 +108,15 @@ theorem Perm.append_left {t₁ t₂ : List α} : ∀ l : List α, t₁ ~ t₂
108108theorem Perm.append {l₁ l₂ t₁ t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ++ t₁ ~ l₂ ++ t₂ :=
109109 (p₁.append_right t₁).trans (p₂.append_left l₂)
110110
111+ grind_pattern Perm.append => l₁ ~ l₂, t₁ ~ t₂, l₁ ++ t₁
112+ grind_pattern Perm.append => l₁ ~ l₂, t₁ ~ t₂, l₂ ++ t₂
113+
111114theorem Perm.append_cons (a : α) {l₁ l₂ r₁ r₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : r₁ ~ r₂) :
112115 l₁ ++ a :: r₁ ~ l₂ ++ a :: r₂ := p₁.append (p₂.cons a)
113116
117+ grind_pattern Perm.append_cons => l₁ ~ l₂, r₁ ~ r₂, l₁ ++ a :: r₁
118+ grind_pattern Perm.append_cons => l₁ ~ l₂, r₁ ~ r₂, l₂ ++ a :: r₂
119+
114120@[simp] theorem perm_middle {a : α} : ∀ {l₁ l₂ : List α}, l₁ ++ a :: l₂ ~ a :: (l₁ ++ l₂)
115121 | [], _ => .refl _
116122 | b :: _, _ => (Perm.cons _ perm_middle).trans (swap a b _)
You can’t perform that action at this time.
0 commit comments