Skip to content

Commit be60ca1

Browse files
committed
chore: golf using grind (leanprover-community#33286)
The goal of this golfing PR is to decrease the number of times lemmas are called explicitly (replacing calls to lemmas with calls to tactics). Any decrease in compilation time is a welcome side effect, although it is not a primary objective. Trace profiling results (shown if ≥10 ms before or after): * `AkraBazziRecurrence.GrowsPolynomially.eventually_atTop_nonneg_or_nonpos`: 1208 ms before, 917 ms after 🎉 * `Equiv.Perm.support_congr`: <10 ms before, 38 ms after * `Equiv.Perm.subtypeCongr.trans`: 13 ms before, 35 ms after * `preCantorSet_antitone`: 766 ms before, 371 ms after 🎉 This golfing PR is batched under the following guidelines: * Up to ~5 changed files per PR * Up to ~25 changed declarations per PR * Up to ~100 changed lines per PR
1 parent aa352fe commit be60ca1

4 files changed

Lines changed: 10 additions & 57 deletions

File tree

Mathlib/Computability/AkraBazzi/GrowsPolynomially.lean

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,45 +189,14 @@ lemma eventually_atTop_nonneg_or_nonpos (hf : GrowsPolynomially f) :
189189
rw [eventually_atTop]
190190
refine ⟨max n₀ 2, ?_⟩
191191
refine Real.induction_Ico_mul _ 2 (by norm_num) (by positivity) ?base ?step
192-
case base =>
193-
intro x ⟨hxlb, hxub⟩
194-
have h₁ := calc n₀ ≤ 1 * max n₀ 2 := by simp
195-
_ ≤ 2 * max n₀ 2 := by gcongr; norm_num
196-
have h₂ := hn₀ (2 * max n₀ 2) h₁ (max n₀ 2) ⟨by simp, by linarith⟩
197-
rw [h₂]
198-
exact hn₀ (2 * max n₀ 2) h₁ x ⟨by simp [hxlb], le_of_lt hxub⟩
192+
case base => grind
199193
case step =>
200-
intro n hn hyp_ind z hz
201-
have z_nonneg : 0 ≤ z := by
202-
calc (0 : ℝ) ≤ (2 : ℝ) ^ n * max n₀ 2 := by
203-
exact mul_nonneg (pow_nonneg (by norm_num) _) (by norm_num)
204-
_ ≤ z := by exact_mod_cast hz.1
194+
intro n _ _ z _
205195
have le_2n : max n₀ 2 ≤ (2 : ℝ) ^ n * max n₀ 2 := by
206-
nth_rewrite 1 [← one_mul (max n₀ 2)]
207-
gcongr
208-
exact one_le_pow₀ (by norm_num : (1 : ℝ) ≤ 2)
209-
have n₀_le_z : n₀ ≤ z := by
210-
calc n₀ ≤ max n₀ 2 := by simp
211-
_ ≤ (2 : ℝ) ^ n * max n₀ 2 := le_2n
212-
_ ≤ _ := by exact_mod_cast hz.1
213-
have fz_eq_c₂fz : f z = c₂ * f z := hn₀ z n₀_le_z z ⟨by linarith, le_rfl⟩
214-
have z_to_half_z' : f (1 / 2 * z) = c₂ * f z :=
215-
hn₀ z n₀_le_z (1 / 2 * z) ⟨le_rfl, by linarith⟩
216-
have z_to_half_z : f (1 / 2 * z) = f z := by rwa [← fz_eq_c₂fz] at z_to_half_z'
196+
simp [one_le_pow₀ (show (1 : ℝ) ≤ 2 by norm_num1)]
217197
have half_z_to_base : f (1 / 2 * z) = f (max n₀ 2) := by
218-
refine hyp_ind (1 / 2 * z) ⟨?lb, ?ub⟩
219-
case lb =>
220-
calc max n₀ 2 ≤ (1 / 2 : ℝ) * (2 : ℝ) ^ 1 * max n₀ 2 := by simp
221-
_ ≤ (1 / 2 : ℝ) * (2 : ℝ) ^ n * max n₀ 2 := by gcongr; norm_num
222-
_ ≤ _ := by rw [mul_assoc]; gcongr; exact_mod_cast hz.1
223-
case ub =>
224-
have h₁ : (2 : ℝ) ^ n = (1 / 2 : ℝ) * (2 : ℝ) ^ (n + 1) := by
225-
rw [one_div, pow_add, pow_one]
226-
ring
227-
rw [h₁, mul_assoc]
228-
gcongr
229-
exact_mod_cast hz.2
230-
rw [← z_to_half_z, half_z_to_base]
198+
grind [mul_assoc]
199+
grind
231200
obtain ⟨c, hc⟩ := hmain
232201
cases le_or_gt 0 c with
233202
| inl hpos =>

Mathlib/GroupTheory/Perm/Support.lean

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,7 @@ theorem support_refl : support (Equiv.refl α) = ∅ :=
290290
support_one
291291

292292
theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by
293-
ext x
294-
by_cases hx : x ∈ g.support
295-
· exact h' x hx
296-
· rw [notMem_support.mp hx, ← notMem_support]
297-
exact fun H => hx (h H)
293+
grind [notMem_support]
298294

299295
/-- If g and c commute, then g stabilizes the support of c -/
300296
theorem mem_support_iff_of_commute {g c : Perm α} (hgc : Commute g c) (x : α) :

Mathlib/Logic/Equiv/Basic.lean

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr e
9797
theorem Perm.subtypeCongr.trans :
9898
(ep.subtypeCongr en).trans (ep'.subtypeCongr en')
9999
= Perm.subtypeCongr (ep.trans ep') (en.trans en') := by
100-
ext x
101-
by_cases h : p x
102-
· have : p (ep ⟨x, h⟩) := Subtype.property _
103-
simp [h, this]
104-
· have : ¬p (en ⟨x, h⟩) := Subtype.property (en _)
105-
simp [h, this]
100+
grind [eq_def, coe_trans]
106101

107102
end subtypeCongr
108103

Mathlib/Topology/Instances/CantorSet.lean

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,9 @@ lemma zero_mem_preCantorSet (n : ℕ) : 0 ∈ preCantorSet n := by
8888
theorem zero_mem_cantorSet : 0 ∈ cantorSet := by simp [cantorSet, zero_mem_preCantorSet]
8989

9090
theorem preCantorSet_antitone : Antitone preCantorSet := by
91-
apply antitone_nat_of_succ_le
92-
intro m
93-
simp only [Set.le_eq_subset, preCantorSet_succ, Set.union_subset_iff]
94-
induction m with
95-
| zero =>
96-
simp only [preCantorSet_zero]
97-
constructor <;> intro x <;>
98-
simp only [Set.mem_image, Set.mem_Icc, forall_exists_index, and_imp] <;>
99-
intro y _ _ _ <;> constructor <;> linarith
100-
| succ m ih => grind [preCantorSet_succ, Set.image_union]
91+
refine antitone_nat_of_succ_le fun m ↦ ?_
92+
simp only [Set.le_eq_subset]
93+
induction m with grind [preCantorSet_zero, preCantorSet_succ]
10194

10295
lemma preCantorSet_subset_unitInterval {n : ℕ} : preCantorSet n ⊆ Set.Icc 0 1 := by
10396
rw [← preCantorSet_zero]

0 commit comments

Comments
 (0)