Skip to content

Commit 1b30cee

Browse files
committed
refactor(MeasureTheory/Integral/IntervalAverage): golf
1 parent 1d6104e commit 1b30cee

1 file changed

Lines changed: 24 additions & 71 deletions

File tree

Mathlib/MeasureTheory/Integral/IntervalAverage.lean

Lines changed: 24 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ formulas for this average:
2222
* `exists_eq_interval_average_of_noAtoms`:
2323
`∃ c ∈ uIoo a b, f c = ⨍ x in (Ι a b), f x ∂μ`.
2424
* `exists_eq_interval_average`:
25-
`∃ c ∈ uIoo a b, f c = ⨍ (x : ℝ) in a..b, f x`.
25+
`∃ c ∈ uIoo a b, f c = ⨍ x in a..b, f x`.
2626
2727
We also prove that `⨍ x in a..b, f x = ⨍ x in b..a, f x`, see `interval_average_symm`.
2828
@@ -73,26 +73,9 @@ then `∃ c ∈ Ι a b, f c = ⨍ x in (Ι a b), f x ∂μ`. -/
7373
theorem exists_eq_interval_average_of_measure
7474
(hf : ContinuousOn f (uIcc a b)) (hμfin : μ (Ι a b) ≠ ⊤) (hμ0 : μ (Ι a b) ≠ 0) :
7575
∃ c ∈ Ι a b, f c = ⨍ x in (Ι a b), f x ∂μ := by
76-
wlog h : a ≤ b generalizing a b
77-
· simp at h
78-
specialize this (by rwa [uIcc_comm]) (by rwa [uIoc_comm]) (by rwa [uIoc_comm]) h.le
79-
rcases this with ⟨c, hc, heq⟩
80-
refine ⟨c, by rwa [uIoc_comm], by rwa [uIoc_comm]⟩
81-
have hint : IntegrableOn f (Ι a b) μ := by
82-
have hsubset : Ι a b ⊆ uIcc a b := uIoc_subset_uIcc
83-
have hcomp : IsCompact (uIcc a b) := isCompact_uIcc
84-
obtain ⟨c, hc, hmax⟩ := hcomp.exists_isMaxOn nonempty_uIcc hf.norm
85-
apply IntegrableOn.of_bound ?_ ?_ (|f c|) ?_
86-
· rwa [lt_top_iff_ne_top]
87-
· apply ContinuousOn.aestronglyMeasurable
88-
· exact hf.mono hsubset
89-
· exact measurableSet_uIoc
90-
· rw [ae_restrict_iff' measurableSet_uIoc]
91-
apply ae_of_all
92-
intro m hm
93-
apply hmax
94-
exact hsubset hm
95-
have hs_prec : IsPreconnected (Ι a b) := by simpa [h] using isPreconnected_Ioc
76+
have hint : IntegrableOn f (Ι a b) μ := hf.integrableOn_of_subset_isCompact
77+
isCompact_uIcc measurableSet_uIoc uIoc_subset_uIcc hμfin
78+
have hs_prec : IsPreconnected (Ι a b) := isPreconnected_Ioc
9679
have hs_nemp : (Ι a b).Nonempty := by exact nonempty_of_measure_ne_zero hμ0
9780
exact exists_eq_setAverage ⟨hs_nemp, hs_prec⟩ (hf.mono uIoc_subset_uIcc) hint hμfin hμ0
9881

@@ -101,64 +84,34 @@ and `μ` has no atoms, then `∃ c ∈ uIoo a b, f c = ⨍ x in (Ι a b), f x
10184
theorem exists_eq_interval_average_of_noAtoms
10285
[NoAtoms μ] (hf : ContinuousOn f (uIcc a b)) (hμfin : μ (Ι a b) ≠ ⊤) (hμ0 : μ (Ι a b) ≠ 0) :
10386
∃ c ∈ uIoo a b, f c = ⨍ x in (Ι a b), f x ∂μ := by
104-
wlog h : a ≤ b generalizing a b
105-
· simp at h
106-
specialize this
107-
(a := b) (b := a) (by rwa [uIcc_comm])
108-
(by rwa [uIoc_comm]) (by rwa [uIoc_comm]) (h.le)
109-
rcases this with ⟨c, hc, heq⟩
110-
refine ⟨c, ?_, ?_⟩
111-
· simpa [uIoo_comm] using hc
112-
· have hswap : Ι a b = Ι b a := uIoc_comm a b
113-
rwa [hswap]
114-
have hint : IntegrableOn f (Ι a b) μ := by
115-
have hsubset : Ι a b ⊆ uIcc a b := uIoc_subset_uIcc
116-
have hcomp : IsCompact (uIcc a b) := isCompact_uIcc
117-
obtain ⟨c, hc, hmax⟩ := hcomp.exists_isMaxOn nonempty_uIcc hf.norm
118-
apply IntegrableOn.of_bound ?_ ?_ (|f c|) ?_
119-
· rwa [lt_top_iff_ne_top]
120-
· apply ContinuousOn.aestronglyMeasurable
121-
· exact hf.mono hsubset
122-
· exact measurableSet_uIoc
123-
· rw [ae_restrict_iff' measurableSet_uIoc]
124-
apply ae_of_all
125-
intro m hm
126-
apply hmax
127-
exact hsubset hm
128-
have h' : a ≠ b := by
129-
intro hab
130-
subst hab
131-
simp at hμ0
132-
have hab : a < b := lt_of_le_of_ne h h'
133-
let s := Ioo a b
134-
have hs_conn : IsConnected s := isConnected_Ioo hab
135-
have hab' : s = uIoo a b := by rw [uIoo_of_le h]
136-
have hs : s ⊆ [[a, b]] := by simpa [hab'] using uIoo_subset_uIcc_self
137-
have hf' : ContinuousOn f s := hf.mono hs
138-
have hs' : s ⊆ Ι a b := by simpa [uIoc_of_le h] using Ioo_subset_Ioc_self
139-
have hint' : IntegrableOn f s μ := hint.mono_set hs'
87+
have hint : IntegrableOn f (Ι a b) μ := hf.integrableOn_of_subset_isCompact
88+
isCompact_uIcc measurableSet_uIoc uIoc_subset_uIcc hμfin
89+
have h : a ≠ b := by intro hab; subst hab; simp at hμ0
90+
let s := uIoo a b
91+
have hs' : s ⊆ Ι a b := by intro x hx; rcases hx with ⟨h1, h2⟩; grind
14092
have hμfin' : μ s ≠ ⊤ := measure_ne_top_of_subset hs' hμfin
93+
have hs_ev : s =ᵐ[μ] Ι a b := by simpa using Ioo_ae_eq_Ioc
14194
have0' : μ s ≠ 0 := by
142-
have hμ : μ s = μ (Ι a b) := by rw [uIoc_of_le h, measure_congr Ioo_ae_eq_Ioc]
95+
have hμ : μ s = μ (Ι a b) := by rw [measure_congr hs_ev]
14396
rwa [hμ]
144-
obtain ⟨c, hc, heq⟩ := exists_eq_setAverage hs_conn hf' hint' hμfin' hμ0'
145-
refine ⟨c, by rwa [uIoo_of_le h], ?_⟩
146-
have hs_ev : s =ᵐ[μ] Ι a b := by simpa [uIoc_of_le h] using Ioo_ae_eq_Ioc
147-
rwa [← setAverage_congr hs_ev]
97+
obtain ⟨c, hc, heq⟩ := exists_eq_setAverage (isConnected_uIoo h) (hf.mono uIoo_subset_uIcc_self)
98+
(hint.mono_set hs') (measure_ne_top_of_subset hs' hμfin) hμ0'
99+
exact ⟨c, hc, by rwa [← setAverage_congr hs_ev]⟩
148100

149101
/-- The mean value theorem for integrals:
150102
There exists a point in an interval such that the mean of a continuous function over the interval
151103
equals the value of the function at the point. -/
152104
theorem exists_eq_interval_average
153105
(hab : a ≠ b) (hf : ContinuousOn f (uIcc a b)) :
154-
∃ c ∈ uIoo a b, f c = ⨍ (x : ℝ) in a..b, f x := by
155-
wlog hle : a ≤ b generalizing a b
156-
· rw [uIoo_comm, uIoc_comm]
157-
apply this hab.symm ?_ (by grind)
158-
rwa [uIcc_comm]
159-
have : Ι a b = Ioc a b := uIoc_of_le hle
106+
∃ c ∈ uIoo a b, f c = ⨍ x in a..b, f x := by
160107
apply exists_eq_interval_average_of_noAtoms hf
161-
· simp [this]
108+
· apply ne_of_lt
109+
calc
110+
_ ≤ volume [[a, b]] := measure_mono uIoc_subset_uIcc
111+
_ < _ := by simp
162112
· apply ne_of_gt
163-
rw [this, Real.volume_Ioc, ENNReal.ofReal_pos]
164-
grind
113+
have h : (uIoo a b) ⊆ (Ι a b) := by intro x hx; rcases hx with ⟨h1, h2⟩; grind
114+
calc
115+
0 < volume (uIoo a b) := by
116+
rwa [Real.volume_uIoo, ENNReal.ofReal_pos, abs_sub_comm, abs_sub_pos]
117+
_ ≤ _ := measure_mono h

0 commit comments

Comments
 (0)