l3lab/ntp-mathlib huggingface dataset:
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
let w := s ∩ (u ∩ f ⁻¹' v)
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    let w := s ∩ (u ∩ f ⁻¹' v)
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
w : Set Eu := s ∩ (u ∩ f ⁻¹' v)
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    let w := s ∩ (u ∩ f ⁻¹' v)
    have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
w : Set Eu := s ∩ (u ∩ f ⁻¹' v)
wv : w ⊆ f ⁻¹' v
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
have wu : w ⊆ u := fun y hy => hy.2.1
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    let w := s ∩ (u ∩ f ⁻¹' v)
    have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
    have wu : w ⊆ u := fun y hy => hy.2.1
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
w : Set Eu := s ∩ (u ∩ f ⁻¹' v)
wv : w ⊆ f ⁻¹' v
wu : w ⊆ u
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
have ws : w ⊆ s := fun y hy => hy.1
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    let w := s ∩ (u ∩ f ⁻¹' v)
    have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
    have wu : w ⊆ u := fun y hy => hy.2.1
    have ws : w ⊆ s := fun y hy => hy.1
    

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
w : Set Eu := s ∩ (u ∩ f ⁻¹' v)
wv : w ⊆ f ⁻¹' v
wu : w ⊆ u
ws : w ⊆ s
⊢ ∃ u ∈ 𝓝[s] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt (g ∘ f) (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u

Next tactic:
refine' ⟨w, _, fun y => (g' (f y)).comp (f' y), _, _⟩
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe
assumption (but is deduced from this one). -/
private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu]
    {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu]
    [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu}
    (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
    ContDiffOn 𝕜 n (g ∘ f) s := by
  induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu
  · rw [contDiffOn_zero] at hf hg ⊢
    exact ContinuousOn.comp hg hf st
  · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢
    intro x hx
    rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩
    rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩
    rw [insert_eq_of_mem hx] at hu ⊢
    have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
    let w := s ∩ (u ∩ f ⁻¹' v)
    have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
    have wu : w ⊆ u := fun y hy => hy.2.1
    have ws : w ⊆ s := fun y hy => hy.1
    refine' ⟨w, _, fun y => (g' (f y)).comp (f' y), _, _⟩
    show w ∈ 𝓝[s] x
    · 

Proof state:
case hsuc.intro.intro.intro.intro.intro.intro.intro.intro.refine'_1
𝕜 : Type u_1
inst✝¹⁶ : NontriviallyNormedField 𝕜
D : Type uD
inst✝¹⁵ : NormedAddCommGroup D
inst✝¹⁴ : NormedSpace 𝕜 D
E : Type uE
inst✝¹³ : NormedAddCommGroup E
inst✝¹² : NormedSpace 𝕜 E
F : Type uF
inst✝¹¹ : NormedAddCommGroup F
inst✝¹⁰ : NormedSpace 𝕜 F
G : Type uG
inst✝⁹ : NormedAddCommGroup G
inst✝⁸ : NormedSpace 𝕜 G
X : Type u_2
inst✝⁷ : NormedAddCommGroup X
inst✝⁶ : NormedSpace 𝕜 X
s✝ s₁ t✝ u✝ : Set E
f✝ f₁ : E → F
g✝ : F → G
x✝ x₀ : E
c : F
b : E × F → G
m n✝ : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
n : ℕ
IH :
  ∀ {Eu : Type u} [inst : NormedAddCommGroup Eu] [inst_1 : NormedSpace 𝕜 Eu] {Fu : Type u}
    [inst_2 : NormedAddCommGroup Fu] [inst_3 : NormedSpace 𝕜 Fu] {Gu : Type u} [inst_4 : NormedAddCommGroup Gu]
    [inst_5 : NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu},
    ContDiffOn 𝕜 (↑n) g t → ContDiffOn 𝕜 (↑n) f s → s ⊆ f ⁻¹' t → ContDiffOn 𝕜 (↑n) (g ∘ f) s
Eu : Type u
inst✝⁵ : NormedAddCommGroup Eu
inst✝⁴ : NormedSpace 𝕜 Eu
Fu : Type u
inst✝³ : NormedAddCommGroup Fu
inst✝² : NormedSpace 𝕜 Fu
Gu : Type u
inst✝¹ : NormedAddCommGroup Gu
inst✝ : NormedSpace 𝕜 Gu
s : Set Eu
t : Set Fu
g : Fu → Gu
f : Eu → Fu
hg : ∀ x ∈ t, ∃ u ∈ 𝓝[insert x t] x, ∃ f', (∀ x ∈ u, HasFDerivWithinAt g (f' x) u x) ∧ ContDiffOn 𝕜 (↑n) f' u
hf : ContDiffOn 𝕜 (↑(Nat.succ n)) f s
st : s ⊆ f ⁻¹' t
x : Eu
hx : x ∈ s
u : Set Eu
hu : u ∈ 𝓝[s] x
f' : Eu → Eu →L[𝕜] Fu
hf' : ∀ x ∈ u, HasFDerivWithinAt f (f' x) u x
f'_diff : ContDiffOn 𝕜 (↑n) f' u
v : Set Fu
hv : v ∈ 𝓝[insert (f x) t] f x
g' : Fu → Fu →L[𝕜] Gu
hg' : ∀ x ∈ v, HasFDerivWithinAt g (g' x) v x
g'_diff : ContDiffOn 𝕜 (↑n) g' v
xu : x ∈ u
w : Set Eu := s ∩ (u ∩ f ⁻¹' v)
wv : w ⊆ f ⁻¹' v
wu : w ⊆ u
ws : w ⊆ s
⊢ w ∈ 𝓝[s] x

Next tactic:
apply Filter.inter_mem self_mem_nhdsWithin
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
    (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by
  /- we lift all the spaces to a common universe, as we have already proved the result in this
    situation. -/
  

Proof state:
𝕜 : Type u_1
inst✝¹⁰ : NontriviallyNormedField 𝕜
D : Type uD
inst✝⁹ : NormedAddCommGroup D
inst✝⁸ : NormedSpace 𝕜 D
E : Type uE
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : NormedSpace 𝕜 E
F : Type uF
inst✝⁵ : NormedAddCommGroup F
inst✝⁴ : NormedSpace 𝕜 F
G : Type uG
inst✝³ : NormedAddCommGroup G
inst✝² : NormedSpace 𝕜 G
X : Type u_2
inst✝¹ : NormedAddCommGroup X
inst✝ : NormedSpace 𝕜 X
s✝ s₁ t✝ u : Set E
f✝ f₁ : E → F
g✝ : F → G
x x₀ : E
c : F
b : E × F → G
m n : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
s : Set E
t : Set F
g : F → G
f : E → F
hg : ContDiffOn 𝕜 n g t
hf : ContDiffOn 𝕜 n f s
st : s ⊆ f ⁻¹' t
⊢ ContDiffOn 𝕜 n (g ∘ f) s

Next tactic:
let Eu : Type max uE uF uG := ULift.{max uF uG} E
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
    (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by
  /- we lift all the spaces to a common universe, as we have already proved the result in this
    situation. -/
  let Eu : Type max uE uF uG := ULift.{max uF uG} E
  

Proof state:
𝕜 : Type u_1
inst✝¹⁰ : NontriviallyNormedField 𝕜
D : Type uD
inst✝⁹ : NormedAddCommGroup D
inst✝⁸ : NormedSpace 𝕜 D
E : Type uE
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : NormedSpace 𝕜 E
F : Type uF
inst✝⁵ : NormedAddCommGroup F
inst✝⁴ : NormedSpace 𝕜 F
G : Type uG
inst✝³ : NormedAddCommGroup G
inst✝² : NormedSpace 𝕜 G
X : Type u_2
inst✝¹ : NormedAddCommGroup X
inst✝ : NormedSpace 𝕜 X
s✝ s₁ t✝ u : Set E
f✝ f₁ : E → F
g✝ : F → G
x x₀ : E
c : F
b : E × F → G
m n : ℕ∞
p : E → FormalMultilinearSeries 𝕜 E F
s : Set E
t : Set F
g : F → G
f : E → F
hg : ContDiffOn 𝕜 n g t
hf : ContDiffOn 𝕜 n f s
st : s ⊆ f ⁻¹' t
Eu : Type (max uE uF uG) := ULift.{max uF uG, uE} E
⊢ ContDiffOn 𝕜 n (g ∘ f) s

Next tactic:
let Fu : Type max uE uF uG := ULift.{max uE uG} F