Skip to content

Commit be32fc5

Browse files
committed
feat: replace Finsupp.embDomain_apply with more general lemma
1 parent 82d756e commit be32fc5

File tree

11 files changed

+36
-28
lines changed

11 files changed

+36
-28
lines changed

Mathlib/Algebra/BigOperators/Finsupp/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ theorem sum_sub_index [AddGroup β] [AddCommGroup γ] {f g : α →₀ β} {h :
455455
theorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :
456456
(v.embDomain f).prod g = v.prod fun a b => g (f a) b := by
457457
rw [prod, prod, support_embDomain, Finset.prod_map]
458-
simp_rw [embDomain_apply]
458+
simp_rw [embDomain_apply_self]
459459

460460
@[to_additive]
461461
theorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}

Mathlib/Algebra/Polynomial/Reverse.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ theorem coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) : coeff (reflect N f) i = f
100100
calc
101101
Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by
102102
rw [revAt_invol]
103-
_ = f (revAt N i) := Finsupp.embDomain_apply _ _ _
103+
_ = f (revAt N i) := Finsupp.embDomain_apply_self _ _ _
104104

105105
@[simp]
106106
theorem reflect_zero {N : ℕ} : reflect N (0 : R[X]) = 0 :=

Mathlib/Analysis/Fourier/BoundedContinuousFunctionChar.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ lemma star_mem_range_charAlgHom (he : Continuous e) (hL : Continuous fun p : V
140140
refine ⟨z.embDomain f, ?_⟩
141141
ext1 u
142142
simp only [charAlgHom_apply, Finsupp.support_embDomain, Finset.sum_map,
143-
Finsupp.embDomain_apply, star_apply, star_sum, star_mul', Circle.star_addChar]
143+
Finsupp.embDomain_apply_self, star_apply, star_sum, star_mul', Circle.star_addChar]
144144
rw [Finsupp.support_mapRange_of_injective (star_zero _) y star_injective]
145145
simp [z, f]
146146

Mathlib/Data/Finset/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,13 @@ theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (
551551
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
552552
(choose_spec _ _ _).1
553553

554+
grind_pattern choose_mem => choose p l hp
555+
554556
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
555557
(choose_spec _ _ _).2
556558

559+
grind_pattern choose_property => choose p l hp
560+
557561
end Choose
558562

559563
end Finset

Mathlib/Data/Finsupp/Basic.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v
397397
ext a
398398
by_cases h : a ∈ Set.range f
399399
· rcases h with ⟨a, rfl⟩
400-
rw [mapDomain_apply f.injective, embDomain_apply]
400+
rw [mapDomain_apply f.injective, embDomain_apply_self]
401401
· rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption
402402

403403
@[to_additive]
@@ -512,7 +512,7 @@ lemma embDomain_comapDomain {f : α ↪ β} {g : β →₀ M} (hg : ↑g.support
512512
ext b
513513
by_cases hb : b ∈ Set.range f
514514
· obtain ⟨a, rfl⟩ := hb
515-
rw [embDomain_apply, comapDomain_apply]
515+
rw [embDomain_apply_self, comapDomain_apply]
516516
· replace hg : g b = 0 := notMem_support_iff.mp <| mt (hg ·) hb
517517
rw [embDomain_notin_range _ _ _ hb, hg]
518518

@@ -1097,14 +1097,14 @@ theorem subtypeDomain_not_piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a}
10971097
Finsupp.ext fun a => dif_neg a.prop
10981098

10991099
/-- Extend the domain of a `Finsupp` by using `0` where `P x` does not hold. -/
1100-
@[simps! support toFun]
1100+
@[simps! (attr := grind =) support toFun]
11011101
def extendDomain (f : Subtype P →₀ M) : α →₀ M := piecewise f 0
11021102

11031103
theorem extendDomain_eq_embDomain_subtype (f : Subtype P →₀ M) :
11041104
extendDomain f = embDomain (.subtype _) f := by
11051105
ext a
11061106
by_cases h : P a
1107-
· refine Eq.trans ?_ (embDomain_apply (.subtype P) f (Subtype.mk a h)).symm
1107+
· refine Eq.trans ?_ (embDomain_apply_self (.subtype P) f (Subtype.mk a h)).symm
11081108
simp [h]
11091109
· rw [embDomain_notin_range, extendDomain_toFun, dif_neg h]
11101110
simp [h]

Mathlib/Data/Finsupp/Defs.lean

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ instance instFunLike : FunLike (α →₀ M) α M :=
113113
ext a
114114
exact (hf _).trans (hg _).symm⟩
115115

116-
@[ext]
116+
@[ext, grind ext]
117117
theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g :=
118118
DFunLike.ext _ _ h
119119

@@ -299,7 +299,7 @@ def mapRange (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
299299
onFinset g.support (f ∘ g) fun a => by
300300
rw [mem_support_iff, not_imp_not]; exact fun H => (congr_arg f H).trans hf
301301

302-
@[simp]
302+
@[simp, grind =]
303303
theorem mapRange_apply {f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} :
304304
mapRange f hf g a = f (g a) :=
305305
rfl
@@ -419,8 +419,16 @@ theorem support_embDomain (f : α ↪ β) (v : α →₀ M) : (embDomain f v).su
419419
theorem embDomain_zero (f : α ↪ β) : (embDomain f 0 : β →₀ M) = 0 :=
420420
rfl
421421

422-
@[simp]
423-
theorem embDomain_apply (f : α ↪ β) (v : α →₀ M) (a : α) : embDomain f v (f a) = v a := by
422+
open Classical in
423+
@[grind =]
424+
theorem embDomain_apply (f : α ↪ β) (v : α →₀ M) (b : β) :
425+
embDomain f v b = if h : ∃ a, f a = b then v h.choose else 0 := by
426+
simp only [embDomain, mem_map, mem_support_iff, coe_mk]
427+
-- TODO: investigate why `grind` needs `split_ifs` first; this should never happen.
428+
split_ifs <;> grind
429+
430+
@[simp, grind =]
431+
theorem embDomain_apply_self (f : α ↪ β) (v : α →₀ M) (a : α) : embDomain f v (f a) = v a := by
424432
classical
425433
simp_rw [embDomain, coe_mk, mem_map']
426434
split_ifs with h
@@ -436,7 +444,7 @@ theorem embDomain_notin_range (f : α ↪ β) (v : α →₀ M) (a : β) (h : a
436444
exact Set.mem_range_self a
437445

438446
theorem embDomain_injective (f : α ↪ β) : Function.Injective (embDomain f : (α →₀ M) → β →₀ M) :=
439-
fun l₁ l₂ h => ext fun a => by simpa only [embDomain_apply] using DFunLike.ext_iff.1 h (f a)
447+
fun l₁ l₂ h => ext fun a => by simpa only [embDomain_apply_self] using DFunLike.ext_iff.1 h (f a)
440448

441449
@[simp]
442450
theorem embDomain_inj {f : α ↪ β} {l₁ l₂ : α →₀ M} : embDomain f l₁ = embDomain f l₂ ↔ l₁ = l₂ :=
@@ -447,12 +455,7 @@ theorem embDomain_eq_zero {f : α ↪ β} {l : α →₀ M} : embDomain f l = 0
447455
(embDomain_injective f).eq_iff' <| embDomain_zero f
448456

449457
theorem embDomain_mapRange (f : α ↪ β) (g : M → N) (p : α →₀ M) (hg : g 0 = 0) :
450-
embDomain f (mapRange g hg p) = mapRange g hg (embDomain f p) := by
451-
ext a
452-
by_cases h : a ∈ Set.range f
453-
· rcases h with ⟨a', rfl⟩
454-
rw [mapRange_apply, embDomain_apply, embDomain_apply, mapRange_apply]
455-
· rw [mapRange_apply, embDomain_notin_range, embDomain_notin_range, ← hg] <;> assumption
458+
embDomain f (mapRange g hg p) = mapRange g hg (embDomain f p) := by grind
456459

457460
end EmbDomain
458461

Mathlib/Data/Finsupp/Option.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : O
110110
f.sum_option_index _ (fun _ => zero_smul _ _) fun _ _ _ => add_smul _ _ _
111111

112112
@[simp] lemma some_embDomain_some [Zero M] (f : α →₀ M) : (f.embDomain .some).some = f := by
113-
ext; rw [some_apply]; exact embDomain_apply _ _ _
113+
ext; rw [some_apply]; exact embDomain_apply_self _ _ _
114114

115115
@[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some none = 0 :=
116116
embDomain_notin_range _ _ _ (by simp)

Mathlib/Data/Finsupp/Single.lean

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def single (a : α) (b : M) : α →₀ M where
6060
· simp [hb, Pi.single, update]
6161
simp [ha]
6262

63+
@[grind =]
6364
theorem single_apply [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := by
6465
classical
6566
simp_rw [@eq_comm _ a a', single, coe_mk, Pi.single_apply]
@@ -468,12 +469,8 @@ theorem single_of_embDomain_single (l : α →₀ M) (f : α ↪ β) (a : β) (b
468469
use c
469470
constructor
470471
· ext d
471-
rw [← embDomain_apply f l, h]
472-
by_cases h_cases : c = d
473-
· simp only [Eq.symm h_cases, hc₂, single_eq_same]
474-
· rw [single_apply, single_apply, if_neg, if_neg h_cases]
475-
by_contra hfd
476-
exact h_cases (f.injective (hc₂.trans hfd))
472+
rw [← embDomain_apply_self f l, h]
473+
grind
477474
· exact hc₂
478475

479476
@[simp]

Mathlib/Data/List/ToFinsupp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ theorem toFinsupp_append {R : Type*} [AddZeroClass R] (l₁ l₂ : List R)
101101
| inr h =>
102102
rcases Nat.exists_eq_add_of_le h with ⟨k, rfl⟩
103103
rw [getD_append_right _ _ _ _ h, Nat.add_sub_cancel_left, getD_eq_default _ _ h, zero_add]
104-
exact Eq.symm (Finsupp.embDomain_apply _ _ _)
104+
exact Eq.symm (Finsupp.embDomain_apply_self _ _ _)
105105

106106
theorem toFinsupp_cons_eq_single_add_embDomain {R : Type*} [AddZeroClass R] (x : R) (xs : List R)
107107
[DecidablePred (getD (x::xs) · 00)] [DecidablePred (getD xs · 00)] :

Mathlib/Logic/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ protected noncomputable def byContradiction' {α : Sort*} (H : ¬(α → False))
727727
def choice_of_byContradiction' {α : Sort*} (contra : ¬(α → False) → α) : Nonempty α → α :=
728728
fun H ↦ contra H.elim
729729

730+
-- This can be removed after https://github.com/leanprover/lean4/pull/11316
731+
-- arrives in a release candidate.
732+
grind_pattern Exists.choose_spec => P.choose
733+
730734
@[simp] lemma choose_eq (a : α) : @Exists.choose _ (· = a) ⟨a, rfl⟩ = a := @choose_spec _ (· = a) _
731735

732736
@[simp]

0 commit comments

Comments
 (0)