Skip to content

Commit 108140a

Browse files
committed
chore: use grw, gcongr more (leanprover-community#30508)
Golf many proofs using `grw`, `gcongr`, `cutsat`, `linarith`... For this, tag a few more lemmas with `gcongr`, and make some existing ones stronger. The goal here is not necessarily to golf (although it usually is the case), but instead to reduce the number of explicit mentions of lemmas, as these are a maintainability concern. The precise golfs that are performed are motivated by leanprover-community#30242, where four pairs of very basic and widespread lemmas get swapped. The best way to reduce the number of swaps needed is to simply not mention the lemmas explicitly.
1 parent 5a6cfc3 commit 108140a

File tree

220 files changed

+670
-958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+670
-958
lines changed

Archive/Imo/Imo2001Q3.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ lemma card_not_easy_le_210 (hG : ∀ i, #(G i) ≤ 6) (hB : ∀ i j, ¬Disjoint
8787
exact Nat.le_of_lt_succ mp.2
8888
_ ≤ ∑ i : Fin 21, 5 * 2 := by
8989
gcongr with i
90-
rw [sum_const, smul_eq_mul]
91-
exact mul_le_mul_right' (card_not_easy_le_five (hG _) (hB _)) _
90+
grw [sum_const, smul_eq_mul, card_not_easy_le_five (hG _) (hB _)]
9291
_ = _ := by norm_num
9392

9493
theorem result (h : Condition G B) : ∃ p, Easy G p ∧ Easy B p := by

Mathlib/Algebra/AddConstMap/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected theorem rel_map_of_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddM
257257
calc
258258
y ≤ l + a + n • a := sub_le_iff_le_add.1 hny.2
259259
_ = l + (n + 1) • a := by rw [add_comm n, add_smul, one_smul, add_assoc]
260-
_ ≤ l + 0 • a := add_le_add_left (zsmul_le_zsmul_left ha.le (by cutsat)) _
260+
_ ≤ l + (0 : ℤ) • a := by gcongr; cutsat
261261
_ ≤ x := by simpa using hx.1
262262
· -- If `n = 0`, then `l < y ≤ l + a`, hence we can apply the assumption
263263
exact hf x (Ico_subset_Icc_self hx) y (by simpa using Ioc_subset_Icc_self hny) hxy

Mathlib/Algebra/AlgebraicCard.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ theorem cardinalMk_lift_le_mul :
5252

5353
theorem cardinalMk_lift_le_max :
5454
Cardinal.lift.{u} #{ x : A // IsAlgebraic R x } ≤ max (Cardinal.lift.{v} #R) ℵ₀ :=
55-
(cardinalMk_lift_le_mul R A).trans <|
56-
(mul_le_mul_right' (lift_le.2 cardinalMk_le_max) _).trans <| by simp
55+
(cardinalMk_lift_le_mul R A).trans <| by grw [lift_le.2 cardinalMk_le_max]; simp
5756

5857
@[simp]
5958
theorem cardinalMk_lift_of_infinite [Infinite R] :

Mathlib/Algebra/MonoidAlgebra/Degree.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ section AddOnly
9797
variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B]
9898
[AddLeftMono T] [AddRightMono T]
9999

100-
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
100+
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
101101
(f g : R[A]) :
102102
(f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb := by
103103
classical
104-
exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦
105-
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
104+
grw [support_mul, Finset.sup_add_le]
105+
rintro _fd fds _gd gds
106+
grw [degbm, ← Finset.le_sup fds, ← Finset.le_sup gds]
106107

107-
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
108+
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
108109
(f g : R[A]) :
109110
f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
110111
sup_support_mul_le (B := Tᵒᵈ) degtm f g
@@ -126,8 +127,7 @@ theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
126127
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
127128
| f::fs => by
128129
rw [List.prod_cons, List.map_cons, List.sum_cons]
129-
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
130-
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
130+
grw [sup_support_mul_le degbm, sup_support_list_prod_le degb0 degbm]
131131

132132
theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0)
133133
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) :

Mathlib/Algebra/MvPolynomial/Degrees.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ theorem totalDegree_add_eq_right_of_totalDegree_lt {p q : MvPolynomial σ R}
402402

403403
theorem totalDegree_mul (a b : MvPolynomial σ R) :
404404
(a * b).totalDegree ≤ a.totalDegree + b.totalDegree :=
405-
sup_support_mul_le (by exact (Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)).le) _ _
405+
sup_support_mul_le (fun _ _ ↦ (Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)).le) _ _
406406

407407
theorem totalDegree_smul_le [CommSemiring S] [DistribMulAction R S] (a : R) (f : MvPolynomial σ S) :
408408
(a • f).totalDegree ≤ f.totalDegree :=
@@ -434,8 +434,7 @@ theorem totalDegree_list_prod :
434434
∀ s : List (MvPolynomial σ R), s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum
435435
| [] => by rw [List.prod_nil, totalDegree_one, List.map_nil, List.sum_nil]
436436
| p::ps => by
437-
rw [List.prod_cons, List.map, List.sum_cons]
438-
exact le_trans (totalDegree_mul _ _) (add_le_add_left (totalDegree_list_prod ps) _)
437+
grw [List.prod_cons, List.map, List.sum_cons, totalDegree_mul, totalDegree_list_prod]
439438

440439
theorem totalDegree_multiset_prod (s : Multiset (MvPolynomial σ R)) :
441440
s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum := by

Mathlib/Algebra/MvPolynomial/SchwartzZippel.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ lemma schwartz_zippel_sup_sum :
100100
calc
101101
#{x ∈ S ^^ (n + 1) | eval x p = 0 ∧ eval (tail x) pₖ = 0} / ∏ i, (#(S i) : ℚ≥0)
102102
≤ #{x ∈ S ^^ (n + 1) | eval (tail x) pₖ = 0} / ∏ i, (#(S i) : ℚ≥0) := by
103-
gcongr; exact fun x hx ↦ hx.2
103+
gcongr with x; exact And.right
104104
_ = #(S 0) * #{xₜ ∈ tail S ^^ n | eval xₜ pₖ = 0}
105105
/ (#(S 0) * (∏ i, #(S (.succ i)) : ℚ≥0)) := by
106106
rw [card_consEquiv_filter_piFinset S fun x ↦ eval x pₖ = 0, prod_univ_succ, tail_def]

Mathlib/Algebra/Order/BigOperators/Group/Finset.lean

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,13 @@ theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : S
352352
theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}
353353
(hs : (s : Set ι).PairwiseDisjoint f) : #s ≤ #(s.biUnion f) + #{i ∈ s | f i = ∅} := by
354354
rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅, add_comm]
355-
exact
356-
add_le_add_right
357-
((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦
358-
nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|
359-
card_le_card <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)
360-
_
355+
grw [card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦
356+
nonempty_of_ne_empty (mem_filter.1 hi).2, filter_subset]
361357

362358
theorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)
363-
(hs : (s : Set ι).PairwiseDisjoint f) : #s ≤ #(s.biUnion f) + 1 :=
364-
(card_le_card_biUnion_add_card_fiber hs).trans <|
365-
add_le_add_left
366-
(card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _
359+
(hs : (s : Set ι).PairwiseDisjoint f) : #s ≤ #(s.biUnion f) + 1 := by
360+
grw [card_le_card_biUnion_add_card_fiber hs,
361+
card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm]
367362

368363
end DoubleCounting
369364

Mathlib/Algebra/Order/BigOperators/Group/List.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lemma Sublist.prod_le_prod' [Preorder M] [MulRightMono M]
4545
exact (ih' h₁.2).trans (le_mul_of_one_le_left' h₁.1)
4646
| cons₂ a _ ih' =>
4747
simp only [prod_cons, forall_mem_cons] at h₁ ⊢
48-
exact mul_le_mul_left' (ih' h₁.2) _
48+
grw [ih' h₁.2]
4949

5050
@[to_additive sum_le_sum]
5151
lemma SublistForall₂.prod_le_prod' [Preorder M]

Mathlib/Algebra/Order/BigOperators/Group/Multiset.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ lemma le_prod_of_submultiplicative_on_pred (f : α → β)
8989
intro a s hs hpsa
9090
have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)
9191
have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps
92-
rw [prod_cons, map_cons, prod_cons]
93-
exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)
92+
grw [prod_cons, map_cons, prod_cons, h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod,
93+
hs hps]
9494

9595
@[to_additive le_sum_of_subadditive]
9696
lemma le_prod_of_submultiplicative (f : α → β) (h_one : f 1 = 1)
@@ -112,7 +112,7 @@ lemma le_prod_nonempty_of_submultiplicative_on_pred (f : α → β) (p : α →
112112
have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)
113113
have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict
114114
have hp_a : p a := hsa_prop a (mem_cons_self a s)
115-
exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)
115+
grw [h_mul a _ hp_a hp_sup, ← hs hs_empty hsa_restrict]
116116

117117
@[to_additive le_sum_nonempty_of_subadditive]
118118
lemma le_prod_nonempty_of_submultiplicative (f : α → β) (h_mul : ∀ a b, f (a * b) ≤ f a * f b)

Mathlib/Algebra/Order/BigOperators/Ring/Finset.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ lemma prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j
166166
(hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i ∈ s, g i) + ∏ i ∈ s, h i) ≤ ∏ i ∈ s, f i := by
167167
classical
168168
simp_rw [prod_eq_mul_prod_diff_singleton hi]
169-
refine le_trans ?_ (mul_le_mul_right' h2i _)
170-
rw [right_distrib]
169+
grw [← h2i, right_distrib]
171170
gcongr with j hj j hj <;> simp_all
172171

173172
end CanonicallyOrderedAdd

0 commit comments

Comments
 (0)