Skip to content

Commit 3b8def4

Browse files
grunwegReemMelamed
authored andcommitted
chore: use to_fun to auto-generated eta-expanded versions of comp declarations (leanprover-community#34361)
Rename such declarations from `comp'` to `fun_comp` (as required by the naming convention) at the same time. In several cases, eta-expanding `g ∘ f` requires using `Function.comp_def` as pull lemma: as that lemma is not a push lemma, and there is no notion of global pull lemmas which are not push lemmas, we locally add the `push` attribute in reverse direction instead.
1 parent f6fc5ed commit 3b8def4

8 files changed

Lines changed: 29 additions & 49 deletions

File tree

Mathlib/Analysis/Analytic/Composition.lean

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -850,31 +850,26 @@ lemma AnalyticOn.comp {f : F → G} {g : E → F} {s : Set F}
850850
AnalyticOn 𝕜 (f ∘ g) t :=
851851
fun x m ↦ (hf _ (h m)).comp (hg x m) h
852852

853+
-- Allow `to_fun` to eta-expand `g ∘ f`. Ideally, `Function.comp_def` would be a global pull lemma
854+
-- instead, which is not supported yet: see https://github.com/leanprover-community/mathlib4/issues/40183.
855+
attribute [local push ←] Function.comp_def
853856
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is
854857
analytic at `x`. -/
855-
@[fun_prop]
858+
@[to_fun (attr := fun_prop)]
856859
theorem AnalyticAt.comp {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x))
857860
(hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (g ∘ f) x := by
858861
rw [← analyticWithinAt_univ] at hg hf ⊢
859862
apply hg.comp hf (by simp)
860863

861-
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is
862-
analytic at `x`. -/
863-
@[fun_prop]
864-
theorem AnalyticAt.comp' {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x))
865-
(hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x :=
866-
hg.comp hf
864+
@[deprecated (since := "2026-01-24")] alias AnalyticAt.comp' := AnalyticAt.fun_comp
867865

868866
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
867+
@[to_fun]
869868
theorem AnalyticAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y)
870869
(hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (g ∘ f) x := by
871870
rw [← hy] at hg
872871
exact hg.comp hf
873-
874-
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
875-
theorem AnalyticAt.comp_of_eq' {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y)
876-
(hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x := by
877-
apply hg.comp_of_eq hf hy
872+
@[deprecated (since := "2026-05-18")] alias AnalyticAt.comp_of_eq' := AnalyticAt.fun_comp_of_eq
878873

879874
theorem AnalyticAt.comp_analyticWithinAt {g : F → G} {f : E → F} {x : E} {s : Set E}
880875
(hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticWithinAt 𝕜 f s x) :
@@ -939,6 +934,7 @@ theorem HasFiniteFPowerSeriesAt.comp {m n : ℕ} {g : F → G} {f : E → F}
939934

940935
/-- If two functions `g` and `f` are continuously polynomial respectively at `f x` and `x`,
941936
then `g ∘ f` is continuously polynomial at `x`. -/
937+
@[to_fun]
942938
theorem CPolynomialAt.comp {g : F → G} {f : E → F} {x : E}
943939
(hg : CPolynomialAt 𝕜 g (f x)) (hf : CPolynomialAt 𝕜 f x) :
944940
CPolynomialAt 𝕜 (g ∘ f) x := by
@@ -947,25 +943,13 @@ theorem CPolynomialAt.comp {g : F → G} {f : E → F} {x : E}
947943
refine ⟨q.comp p, m * (n + 1), ?_⟩
948944
exact hm.comp (hn.of_le (Nat.le_succ n)) (Nat.zero_lt_succ n)
949945

950-
/-- If two functions `g` and `f` are continuously polynomial respectively at `f x` and `x`,
951-
then `g ∘ f` is continuously polynomial at `x`. -/
952-
theorem CPolynomialAt.fun_comp {g : F → G} {f : E → F} {x : E}
953-
(hg : CPolynomialAt 𝕜 g (f x)) (hf : CPolynomialAt 𝕜 f x) :
954-
CPolynomialAt 𝕜 (fun z ↦ g (f z)) x :=
955-
hg.comp hf
956-
957946
/-- Version of `CPolynomialAt.comp` where point equality is a separate hypothesis. -/
947+
@[to_fun]
958948
theorem CPolynomialAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} (hg : CPolynomialAt 𝕜 g y)
959949
(hf : CPolynomialAt 𝕜 f x) (hy : f x = y) : CPolynomialAt 𝕜 (g ∘ f) x := by
960950
rw [← hy] at hg
961951
exact hg.comp hf
962952

963-
/-- Version of `CPolynomialAt.comp` where point equality is a separate hypothesis. -/
964-
theorem CPolynomialAt.fun_comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E}
965-
(hg : CPolynomialAt 𝕜 g y) (hf : CPolynomialAt 𝕜 f x) (hy : f x = y) :
966-
CPolynomialAt 𝕜 (fun z ↦ g (f z)) x :=
967-
hg.comp_of_eq hf hy
968-
969953
/-- If two functions `g` and `f` are continuously polynomial respectively on `s.image f` and `s`,
970954
then `g ∘ f` is continuously polynomial on `s`. -/
971955
theorem CPolynomialOn.comp' {s : Set E} {g : F → G} {f : E → F} (hg : CPolynomialOn 𝕜 g (s.image f))

Mathlib/Analysis/Calculus/DifferentialForm/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ theorem extDerivWithin_pullback {ω : F → F [⋀^Fin n]→L[𝕜] G} {f : E
250250
rw [extDerivWithin,
251251
fderivWithin_continuousAlternatingMapCompContinuousLinearMap (by exact hω.comp x hdf hst) hd2f
252252
(hs x hxs),
253-
alternatizeUncurryFin_add, fderivWithin_comp' _ hω hdf hst (hs x hxs), extDerivWithin,
253+
alternatizeUncurryFin_add, fderivWithin_fun_comp _ hω hdf hst (hs x hxs), extDerivWithin,
254254
alternatizeUncurryFin_fderivCompContinuousLinearMap_eq_zero, add_zero]
255255
· ext v
256256
simp +unfoldPartialApp [alternatizeUncurryFin_apply, Fin.removeNth, Function.comp_def]

Mathlib/Analysis/Calculus/FDeriv/Comp.lean

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,24 @@ theorem DifferentiableAt.comp_differentiableWithinAt {g : F → G} (hg : Differe
133133
(hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (g ∘ f) s x :=
134134
hg.differentiableWithinAt.comp x hf (mapsTo_univ _ _)
135135

136+
-- Allow `to_fun` to eta-expand `g ∘ f`. Ideally, `Function.comp_def` would be a global pull lemma
137+
-- instead, which is not supported yet: see https://github.com/leanprover-community/mathlib4/issues/40183.
138+
attribute [local push ←] Function.comp_def
139+
@[to_fun fderivWithin_fun_comp]
136140
theorem fderivWithin_comp {g : F → G} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t (f x))
137141
(hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) :
138142
fderivWithin 𝕜 (g ∘ f) s x = (fderivWithin 𝕜 g t (f x)).comp (fderivWithin 𝕜 f s x) :=
139143
(hg.hasFDerivWithinAt.comp x hf.hasFDerivWithinAt h).fderivWithin hxs
140144

145+
@[to_fun fderivWithin_fun_comp_of_eq]
141146
theorem fderivWithin_comp_of_eq {g : F → G} {t : Set F} {y : F}
142147
(hg : DifferentiableWithinAt 𝕜 g t y) (hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t)
143148
(hxs : UniqueDiffWithinAt 𝕜 s x) (hy : f x = y) :
144149
fderivWithin 𝕜 (g ∘ f) s x = (fderivWithin 𝕜 g t (f x)).comp (fderivWithin 𝕜 f s x) := by
145150
subst hy; exact fderivWithin_comp _ hg hf h hxs
146151

147-
/-- A variant for the derivative of a composition, written without `∘`. -/
148-
theorem fderivWithin_comp' {g : F → G} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t (f x))
149-
(hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) :
150-
fderivWithin 𝕜 (fun y ↦ g (f y)) s x
151-
= (fderivWithin 𝕜 g t (f x)).comp (fderivWithin 𝕜 f s x) :=
152-
fderivWithin_comp _ hg hf h hxs
153-
154-
/-- A variant for the derivative of a composition, written without `∘`. -/
155-
theorem fderivWithin_comp_of_eq' {g : F → G} {t : Set F} {y : F}
156-
(hg : DifferentiableWithinAt 𝕜 g t y) (hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t)
157-
(hxs : UniqueDiffWithinAt 𝕜 s x) (hy : f x = y) :
158-
fderivWithin 𝕜 (fun y ↦ g (f y)) s x
159-
= (fderivWithin 𝕜 g t (f x)).comp (fderivWithin 𝕜 f s x) := by
160-
subst hy; exact fderivWithin_comp _ hg hf h hxs
152+
@[deprecated (since := "2026-05-18")] alias fderivWithin_comp' := fderivWithin_fun_comp
153+
@[deprecated (since := "2026-05-18")] alias fderivWithin_comp_of_eq' := fderivWithin_fun_comp_of_eq
161154

162155
/-- A version of `fderivWithin_comp` that is useful to rewrite the composition of two derivatives
163156
into a single derivative. This version always applies, but creates a new side-goal `f x = y`. -/
@@ -180,14 +173,11 @@ theorem fderivWithin_comp₃ {g' : G → G'} {g : F → G} {t : Set F} {u : Set
180173
exact (hg'.hasFDerivWithinAt.comp x (hg.hasFDerivWithinAt.comp x hf.hasFDerivWithinAt h2f) <|
181174
h2g.comp h2f).fderivWithin hxs
182175

176+
@[to_fun fderiv_fun_comp]
183177
theorem fderiv_comp {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableAt 𝕜 f x) :
184178
fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) :=
185179
(hg.hasFDerivAt.comp x hf.hasFDerivAt).fderiv
186-
187-
/-- A variant for the derivative of a composition, written without `∘`. -/
188-
theorem fderiv_comp' {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableAt 𝕜 f x) :
189-
fderiv 𝕜 (fun y ↦ g (f y)) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) :=
190-
fderiv_comp x hg hf
180+
@[deprecated (since := "2026-05-18")] alias fderiv_comp' := fderiv_fun_comp
191181

192182
theorem fderiv_comp_fderivWithin {g : F → G} (hg : DifferentiableAt 𝕜 g (f x))
193183
(hf : DifferentiableWithinAt 𝕜 f s x) (hxs : UniqueDiffWithinAt 𝕜 s x) :

Mathlib/Analysis/Calculus/VectorField.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ lemma pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt
636636
have Af : DifferentiableWithinAt 𝕜 f s x := h'f.differentiableWithinAt two_ne_zero
637637
simp only [lieBracketWithin_eq, pullbackWithin_eq_of_fderivWithin_eq hMx, map_sub, AV, AW]
638638
rw [fderivWithin_clm_apply, fderivWithin_clm_apply]
639-
· simp [fderivWithin_comp' x hW Af hst (hu x hx), ← hMx,
640-
fderivWithin_comp' x hV Af hst (hu x hx), M_diff, hf.eq]
639+
· simp [fderivWithin_fun_comp x hW Af hst (hu x hx), ← hMx,
640+
fderivWithin_fun_comp x hV Af hst (hu x hx), M_diff, hf.eq]
641641
· exact hu x hx
642642
· exact M_symm_smooth.differentiableWithinAt one_ne_zero
643643
· exact hV.comp x Af hst

Mathlib/Analysis/Meromorphic/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ lemma congr {f g : 𝕜 → E} (hf : MeromorphicAt f x) (hfg : f =ᶠ[𝓝[≠]
251251
MeromorphicAt g x := by
252252
rcases hf with ⟨m, hf⟩
253253
refine ⟨m + 1, ?_⟩
254-
have : AnalyticAt 𝕜 (fun z ↦ z - x) x := analyticAt_id.sub analyticAt_const
254+
have : AnalyticAt 𝕜 (fun z ↦ z - x) x := by fun_prop
255255
refine (this.fun_smul hf).congr ?_
256256
rw [eventuallyEq_nhdsWithin_iff] at hfg
257257
filter_upwards [hfg] with z hz
@@ -449,7 +449,7 @@ lemma MeromorphicAt.comp_analyticAt {f : 𝕜' → F} {g : 𝕜 → 𝕜'}
449449
obtain ⟨h, han, hne, heq⟩ := (hg.fun_sub analyticAt_const).analyticOrderAt_eq_natCast.mp hn.symm
450450
set j := fun z ↦ (z - g x) ^ r • f z
451451
have : AnalyticAt 𝕜 (fun i ↦ (h i)⁻¹ ^ r • j (g i)) x :=
452-
((han.fun_inv hne).fun_pow r).fun_smul (hr.restrictScalars.comp' hg)
452+
((han.inv hne).pow r).smul (hr.restrictScalars.comp hg)
453453
refine ⟨n * r, this.congr ?_⟩
454454
filter_upwards [heq, han.continuousAt.tendsto.eventually_ne hne] with z hz hzne
455455
simp only [j, inv_pow, Function.comp_apply, inv_smul_eq_iff₀ (pow_ne_zero r hzne)]

Mathlib/MeasureTheory/MeasurableSpace/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ theorem measurable_id {_ : MeasurableSpace α} : Measurable (@id α) := fun _ =>
516516
@[fun_prop]
517517
theorem measurable_id' {_ : MeasurableSpace α} : Measurable fun a : α => a := measurable_id
518518

519+
-- Allow `to_fun` to eta-expand `g ∘ f`. Ideally, `Function.comp_def` would be a global pull lemma
520+
-- instead, which is not supported yet: see https://github.com/leanprover-community/mathlib4/issues/40183.
519521
attribute [local push ←] Function.comp_def
520522
@[to_fun]
521523
protected theorem Measurable.comp {_ : MeasurableSpace α} {_ : MeasurableSpace β}

Mathlib/Order/OmegaCompletePartialOrder.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ lemma ωScottContinuous_iff_map_ωSup_of_orderHom {f : α →o β} :
303303
alias ⟨ωScottContinuous.map_ωSup_of_orderHom, ωScottContinuous.of_map_ωSup_of_orderHom⟩ :=
304304
ωScottContinuous_iff_map_ωSup_of_orderHom
305305

306+
-- Allow `to_fun` to eta-expand `g ∘ f`. Ideally, `Function.comp_def` would be a global pull lemma
307+
-- instead, which is not supported yet: see https://github.com/leanprover-community/mathlib4/issues/40183.
306308
attribute [local push ←] Function.comp_def
307309
attribute [local push] Function.const_def
308310

Mathlib/Order/ScottContinuity.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ section ScottContinuous
4343
variable [Preorder α] [Preorder β] [Preorder γ] {D D₁ D₂ : Set (Set α)}
4444
{f : α → β}
4545

46+
-- Allow `to_fun` to eta-expand `g ∘ f`. Ideally, `Function.comp_def` would be a global pull lemma
47+
-- instead, which is not supported yet: see https://github.com/leanprover-community/mathlib4/issues/40183.
4648
attribute [local push ←] Function.comp_def
4749
attribute [local push] Function.const_def
4850

0 commit comments

Comments
 (0)