Skip to content

Commit 355581f

Browse files
Rob23obaBergschaf
authored andcommitted
feat: add congruence lemmas for Function.update and Pi.single (leanprover-community#35423)
Adds `simp` congruence lemmas to `Function.update` and `Pi.single` that are specialized for the non-dependent case. See also [#mathlib4 > Simp fails to apply with &leanprover-community#96;Function.update&leanprover-community#96;](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Simp.20fails.20to.20apply.20with.20.60Function.2Eupdate.60/with/573889929). Co-authored-by: Rob23oba <robin.arnez@web.de>
1 parent df0f9ce commit 355581f

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

Mathlib/Algebra/Notation/Pi/Basic.lean

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ lemma mulSingle_inj (i : ι) {x y : M i} : mulSingle i x = mulSingle i y ↔ x =
8888

8989
variable {M : Type*} [One M]
9090

91+
/--
92+
A congruence lemma for `Pi.mulSingle`, specialized for the non-dependent case. Without this,
93+
`simp` can't rewrite in the first and third argument (`i` and `j`) because of dependence.
94+
See also https://github.com/leanprover/lean4/issues/12478.
95+
-/
96+
@[to_additive (attr := congr) /--
97+
A congruence lemma for `Pi.single`, specialized for the non-dependent case. Without this,
98+
`simp` can't rewrite in the first and third argument (`i` and `j`) because of dependence.
99+
See also https://github.com/leanprover/lean4/issues/12478.
100+
-/]
101+
lemma mulSingle_congr {i₁ i₂ : ι} (hi : i₁ = i₂)
102+
{x₁ x₂ : M} (hx : x₁ = x₂) {j₁ j₂ : ι} (hj : j₁ = j₂) :
103+
(mulSingle i₁ x₁ : ι → M) j₁ = (mulSingle i₂ x₂ : ι → M) j₂ :=
104+
update_congr rfl hi hx hj
105+
91106
/-- On non-dependent functions, `Pi.mulSingle` can be expressed as an `ite` -/
92107
@[to_additive (attr := grind =)
93108
/-- On non-dependent functions, `Pi.single` can be expressed as an `ite` -/]

Mathlib/Logic/Function/Basic.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,18 @@ theorem update_self (a : α) (v : β a) (f : ∀ a, β a) : update f a v a = v :
642642
theorem update_of_ne {a a' : α} (h : a ≠ a') (v : β a') (f : ∀ a, β a) : update f a' v a = f a :=
643643
dif_neg h
644644

645+
/--
646+
A congruence lemma for `Function.update`, specialized for the non-dependent case. Without this,
647+
`simp` can't rewrite in the fourth argument `a` because the result type depends on `a`.
648+
See also https://github.com/leanprover/lean4/issues/12478.
649+
-/
650+
@[congr]
651+
lemma update_congr {β : Sort*}
652+
{f₁ f₂ : α → β} (hf : f₁ = f₂) {a'₁ a'₂ : α} (ha' : a'₁ = a'₂)
653+
{v₁ v₂ : β} (hv : v₁ = v₂) {a₁ a₂ : α} (ha : a₁ = a₂) :
654+
Function.update f₁ a'₁ v₁ a₁ = Function.update f₂ a'₂ v₂ a₂ := by
655+
subst hf; subst ha'; subst hv; subst ha; rfl
656+
645657
/-- On non-dependent functions, `Function.update` can be expressed as an `ite` -/
646658
theorem update_apply {β : Sort*} (f : α → β) (a' : α) (b : β) (a : α) :
647659
update f a' b a = if a = a' then b else f a := by

Mathlib/NumberTheory/ModularForms/QExpansion.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ private lemma hasFPowerSeriesOnBall_update {f : ℍ → ℂ} (hh : 0 < h) {c :
251251
(mod_cast hr')).summable.norm
252252
· simp
253253
· intro y hy
254-
rw [zero_add]
255-
-- note the `simp`s below do not automatically apply this lemma to the argument of
256-
-- `Function.update`, because of limitations in `simp`'s support for dependent function types,
257-
-- see lean4 issue #12478.
258254
rw [← ENNReal.coe_one, Metric.eball_coe, NNReal.coe_one, mem_ball_zero_iff] at hy
259255
rcases eq_or_ne y 0 with rfl | hy'
260256
· simpa +contextual [zero_pow_eq] using hasSum_ite_eq 0 (c 0)

Mathlib/RepresentationTheory/Tannaka.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ lemma toRightFDRepComp_in_rightRegular [IsDomain k] (η : Aut (forget k G)) :
211211
congrFun congr(($nat.symm).hom (single u 1)) 1
212212
_ = evalAlgHom _ _ s (leftRegular t⁻¹ (single u 1)) :=
213213
congr($hs (leftRegular t⁻¹ (single u 1)))
214-
_ = _ := by by_cases u = t * s <;> simp_all [single_apply]
214+
_ = _ := by by_cases u = t * s <;> simp_all
215215

216216
lemma equivHom_surjective [IsDomain k] : Function.Surjective (equivHom k G) := by
217217
intro η

Mathlib/Topology/Algebra/InfiniteSum/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ protected theorem Multipliable.tprod_eq_mul_tprod_ite' [DecidableEq β] [L.LeAtT
719719
∏'[L] x, f x = f b * ∏'[L] x, ite (x = b) 1 (f x) :=
720720
calc
721721
∏'[L] x, f x = ∏'[L] x, (ite (x = b) (f x) 1 * update f b 1 x) :=
722-
tprod_congr fun n ↦ by split_ifs with h <;> simp [update_apply, h]
722+
tprod_congr fun n ↦ by split_ifs with h <;> simp [h]
723723
_ = (∏'[L] x, ite (x = b) (f x) 1) * ∏'[L] x, update f b 1 x :=
724724
Multipliable.tprod_mul ⟨ite (b = b) (f b) 1, hasProd_single b (fun _ hb ↦ if_neg hb) L⟩ hf
725725
_ = ite (b = b) (f b) 1 * ∏'[L] x, update f b 1 x := by

0 commit comments

Comments
 (0)