Skip to content

Commit 7131639

Browse files
committed
chore: golf using grind (leanprover-community#36764)
The goal of this PR is to decrease the number of times lemmas are called explicitly. Any decrease in compilation time is a welcome side effect, although it is not a primary objective. Trace profiling results (differences <30 ms considered measurement noise): * `DirectSum.lequivCongrLeft_lof`: unchanged 🎉 * `AnalyticOnNhd.preimage_mem_codiscreteWithin`: unchanged 🎉 * `mem_permsOfList_of_mem`: unchanged 🎉 * `PNat.mod_le`: unchanged 🎉 * `Computation.map_parallel`: unchanged 🎉 * `Sigma.curry_update`: unchanged 🎉 Profiled using `set_option trace.profiler true in`.
1 parent 405bba7 commit 7131639

6 files changed

Lines changed: 11 additions & 41 deletions

File tree

Mathlib/Algebra/DirectSum/Module.lean

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,8 @@ lemma lequivCongrLeft_lof [DecidableEq ι] [DecidableEq κ] {e : ι ≃ κ}
333333
lequivCongrLeft R e (lof R ι M i x) = lof R _ _ k y := by
334334
subst hik hxy
335335
ext j
336-
simp_rw [lequivCongrLeft_apply, lof_eq_of, of_apply]
337-
by_cases eq : k = j
338-
· subst eq
339-
rw [dif_pos rfl, dif_pos rfl]
340-
rfl
341-
· rw [dif_neg (by aesop), dif_neg eq]
336+
simp [lof_eq_of, of_apply]
337+
lia
342338

343339
lemma lequivCongrLeft_symm_lof [DecidableEq ι] [DecidableEq κ] {h : ι ≃ κ}
344340
{k : κ} {x : M (h.symm k)} :

Mathlib/Analysis/Analytic/IsolatedZeros.lean

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,7 @@ theorem AnalyticOnNhd.preimage_mem_codiscreteWithin {U : Set 𝕜} {s : Set E} {
350350
simp_rw [mem_codiscreteWithin, disjoint_principal_right, Set.compl_diff] at *
351351
intro x hx
352352
apply mem_of_superset ((hfU x hx).preimage_of_nhdsNE (h₂f x hx) (hs (f x) (by tauto)))
353-
rw [preimage_union, preimage_compl]
354-
apply union_subset_union_right (f ⁻¹' s)
355-
intro x hx
356-
push _ ∈ _ at hx ⊢
357-
push Not at hx
358-
tauto
353+
grind
359354

360355
/-- Preimages of codiscrete sets, filter version: if `f` is analytic on a neighbourhood of `U` and
361356
not locally constant, then the push-forward of the filter of sets codiscrete within `U` is less

Mathlib/Data/Fintype/Perm.lean

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,8 @@ theorem mem_permsOfList_of_mem {l : List α} {f : Perm α} (h : ∀ x, f x ≠ x
5858
exact hx hfa
5959
have hfa' : f (f a) ≠ f a := mt (fun h => f.injective h) hfa
6060
have : ∀ x : α, (Equiv.swap a (f a) * f) x ≠ x → x ∈ l := by
61-
intro x hx
62-
have hxa : x ≠ a := by
63-
rintro rfl
64-
apply hx
65-
simp only [mul_apply, swap_apply_right]
66-
refine List.mem_of_ne_of_mem hxa (h x fun h => ?_)
67-
simp only [mul_apply, swap_apply_def, mul_apply, Ne, apply_eq_iff_eq] at hx
68-
split_ifs at hx with h_1
69-
exacts [hxa (h.symm.trans h_1), hx h]
61+
simp
62+
grind
7063
suffices f ∈ permsOfList l ∨ ∃ b ∈ l, ∃ g ∈ permsOfList l, Equiv.swap a b * g = f by
7164
simpa only [permsOfList, exists_prop, List.mem_map, mem_append, List.mem_flatMap]
7265
refine or_iff_not_imp_left.2 fun _hfl => ⟨f a, ?_, Equiv.swap a (f a) * f, IH this, ?_⟩

Mathlib/Data/PNat/Basic.lean

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,8 @@ theorem mod_le (m k : ℕ+) : mod m k ≤ m ∧ mod m k ≤ k := by
307307
split_ifs with h
308308
· have hm : (m : ℕ) > 0 := m.pos
309309
rw [← Nat.mod_add_div (m : ℕ) (k : ℕ), h, zero_add] at hm ⊢
310-
by_cases h₁ : (m : ℕ) / (k : ℕ) = 0
311-
· rw [h₁, mul_zero] at hm
312-
exact (lt_irrefl _ hm).elim
313-
· let h₂ : (k : ℕ) * 1 ≤ k * (m / k) :=
314-
Nat.mul_le_mul_left (k : ℕ) (Nat.succ_le_of_lt (Nat.pos_of_ne_zero h₁))
315-
rw [mul_one] at h₂
316-
exact ⟨h₂, le_refl (k : ℕ)⟩
310+
simp
311+
lia
317312
· exact ⟨Nat.mod_le (m : ℕ) (k : ℕ), (Nat.mod_lt (m : ℕ) k.pos).le⟩
318313

319314
theorem dvd_iff {k m : ℕ+} : k ∣ m ↔ (k : ℕ) ∣ (m : ℕ) := by

Mathlib/Data/Seq/Parallel.lean

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,8 @@ theorem map_parallel (f : α → β) (S) : map f (parallel S) = parallel (S.map
267267
= lmap f (rmap (List.map (map f)) (parallel.aux2 l)) := by
268268
simp only [parallel.aux2, rmap, lmap]
269269
induction l with
270-
| nil => simp
271-
| cons c l IH =>
272-
simp only [List.map_cons, List.foldr_cons, destruct_map, lmap, rmap]
273-
rw [IH]
274-
cases List.foldr _ _ _
275-
· simp
276-
· cases destruct c <;> simp
270+
| nil => grind
271+
| cons => grind [destruct_map, lmap, rmap]
277272
simp only [BisimO, destruct_map, lmap, rmap, corec_eq, parallel.aux1.eq_1]
278273
rw [this]
279274
rcases parallel.aux2 l with a | l'

Mathlib/Data/Sigma/Basic.lean

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ theorem Sigma.curry_update {γ : ∀ a, β a → Type*} [DecidableEq α] [∀ a,
169169
ext ja jb
170170
unfold Sigma.curry
171171
obtain rfl | ha := eq_or_ne ia ja
172-
· obtain rfl | hb := eq_or_ne ib jb
173-
· simp
174-
· simp only [update_self]
175-
rw [Function.update_of_ne (mt _ hb.symm), Function.update_of_ne hb.symm]
176-
rintro h
177-
injection h
172+
· simp
173+
grind
178174
· rw [Function.update_of_ne (ne_of_apply_ne Sigma.fst _), Function.update_of_ne]
179175
· exact ha.symm
180176
· exact ha.symm

0 commit comments

Comments
 (0)