-- Mathlib/MeasureTheory/Integral/FundThmCalculus.lean
theorem integral_comp_smul_deriv''' {f f' : ℝ → ℝ} {g : ℝ → G} (hf : ContinuousOn f [[a, b]])
    (hff' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt f (f' x) (Ioi x) x)
    (hg_cont : ContinuousOn g (f '' Ioo (min a b) (max a b))) (hg1 : IntegrableOn g (f '' [[a, b]]))
    (hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]]) :
    (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u

Proof state:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
J : Set ℝ := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]
hg_cont : ContinuousOn g J
hJ : f '' [[c, d]] = J
h2x : f x ∈ J
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Tactic:
have h2g : IntervalIntegrable g volume (f a) (f x) := by
  refine hg1.mono_set ?_
  rw [← hf.image_uIcc]
  exact hf.surjOn_uIcc left_mem_uIcc (Ioo_subset_Icc_self hx)

Result:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
J : Set ℝ := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]
hg_cont : ContinuousOn g J
hJ : f '' [[c, d]] = J
h2x : f x ∈ J
h2g : IntervalIntegrable g volume (f a) (f x)
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Proof state:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
hg_cont : ContinuousOn g (f '' [[c, d]])
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Tactic:
let J := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]

Result:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
hg_cont : ContinuousOn g (f '' [[c, d]])
J : Set ℝ := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Proof state:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
J : Set ℝ := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]
hg_cont : ContinuousOn g J
hJ : f '' [[c, d]] = J
h2x : f x ∈ J
h2g : IntervalIntegrable g volume (f a) (f x)
h3g : StronglyMeasurableAtFilter g (𝓝[J] f x) volume
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Tactic:
haveI : Fact (f x ∈ J) := ⟨h2x⟩

Result:
case intro.intro
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
c : ℝ
hc : c ∈ Ioo (a ⊓ b) x
d : ℝ
hd : d ∈ Ioo x (a ⊔ b)
cdsub : [[c, d]] ⊆ Ioo (a ⊓ b) (a ⊔ b)
J : Set ℝ := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]]
hg_cont : ContinuousOn g J
hJ : f '' [[c, d]] = J
h2x : f x ∈ J
h2g : IntervalIntegrable g volume (f a) (f x)
h3g : StronglyMeasurableAtFilter g (𝓝[J] f x) volume
this : Fact (f x ∈ J)
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Proof state:
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg_cont : ContinuousOn g (f '' Ioo (a ⊓ b) (a ⊔ b))
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
⊢ ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Tactic:
intro x hx

Result:
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg_cont : ContinuousOn g (f '' Ioo (a ⊓ b) (a ⊔ b))
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
h_cont : ContinuousOn (fun u => ∫ (t : ℝ) in f a..f u, g t) [[a, b]]
x : ℝ
hx : x ∈ Ioo (a ⊓ b) (a ⊔ b)
⊢ HasDerivWithinAt (fun u => ∫ (t : ℝ) in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x

Proof state:
case refine_1
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg_cont : ContinuousOn g (f '' Ioo (a ⊓ b) (a ⊔ b))
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
⊢ f a ∈ [[sInf (f '' [[a, b]]), sSup (f '' [[a, b]])]]

Tactic:
rw [← hf.image_uIcc]

Result:
case refine_1
a b : ℝ
G : Type u_5
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace ℝ G
f f' : ℝ → ℝ
g : ℝ → G
hf : ContinuousOn f [[a, b]]
hff' : ∀ x ∈ Ioo (a ⊓ b) (a ⊔ b), HasDerivWithinAt f (f' x) (Ioi x) x
hg_cont : ContinuousOn g (f '' Ioo (a ⊓ b) (a ⊔ b))
hg1 : IntervalIntegrable g volume (sInf (f '' [[a, b]])) (sSup (f '' [[a, b]]))
hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]] volume
hG : CompleteSpace G
⊢ f a ∈ f '' [[a, b]]