l3lab/ntp-mathlib huggingface dataset:
/-- In a space with the Besicovitch covering property, the set of closed balls with positive radius
forms a Vitali family. This is essentially a restatement of the measurable Besicovitch theorem. -/
protected def vitaliFamily (μ : Measure α) [SigmaFinite μ] : VitaliFamily μ where
  setsAt x := (fun r : ℝ => closedBall x r) '' Ioi (0 : ℝ)
  MeasurableSet' := by
    intro x y hy
    obtain ⟨r, _, rfl⟩ : ∃ r : ℝ, 0 < r ∧ closedBall x r = y := by
      simpa only [mem_image, mem_Ioi] using hy
    exact isClosed_ball.measurableSet
  nonempty_interior := by
    intro x y hy
    obtain ⟨r, rpos, rfl⟩ : ∃ r : ℝ, 0 < r ∧ closedBall x r = y := by
      simpa only [mem_image, mem_Ioi] using hy
    simp only [Nonempty.mono ball_subset_interior_closedBall, rpos, nonempty_ball]
  Nontrivial x ε εpos := ⟨closedBall x ε, mem_image_of_mem _ εpos, Subset.refl _⟩
  covering := by
    intro s f fsubset ffine
    let g : α → Set ℝ := fun x => {r | 0 < r ∧ closedBall x r ∈ f x}
    have A : ∀ x ∈ s, ∀ δ > 0, (g x ∩ Ioo 0 δ).Nonempty := by
      intro x xs δ δpos
      obtain ⟨t, tf, ht⟩ : ∃ (t : Set α), t ∈ f x ∧ t ⊆ closedBall x (δ / 2) :=
        ffine x xs (δ / 2) (half_pos δpos)
      obtain ⟨r, rpos, rfl⟩ : ∃ r : ℝ, 0 < r ∧ closedBall x r = t := by simpa using fsubset x xs tf
      rcases le_total r (δ / 2) with (H | H)
      · exact ⟨r, ⟨rpos, tf⟩, ⟨rpos, H.trans_lt (half_lt_self δpos)⟩⟩
      · have : closedBall x r = closedBall x (δ / 2) :=
          Subset.antisymm ht (closedBall_subset_closedBall H)
        rw [this] at tf
        refine' ⟨δ / 2, ⟨half_pos δpos, tf⟩, ⟨half_pos δpos, half_lt_self δpos⟩⟩
    obtain ⟨t, r, _, ts, tg, μt, tdisj⟩ :
      ∃ (t : Set α) (r : α → ℝ),
        t.Countable ∧
          t ⊆ s ∧
            (∀ x ∈ t, r x ∈ g x ∩ Ioo 0 1) ∧
              μ (s \ ⋃ x ∈ t, closedBall x (r x)) = 0 ∧
                t.PairwiseDisjoint fun x => closedBall x (r x) :=
      exists_disjoint_closedBall_covering_ae μ g s A (fun _ => 1) fun _ _ => zero_lt_one
    let F : α → α × Set α := fun x => (x, closedBall x (r x))
    refine' ⟨F '' t, _, _, _, _⟩
    · rintro - ⟨x, hx, rfl⟩; exact ts hx
    · rintro p ⟨x, hx, rfl⟩ q ⟨y, hy, rfl⟩ hxy
      exact tdisj hx hy (ne_of_apply_ne F hxy)
    · rintro - ⟨x, hx, rfl⟩; exact (tg x hx).1.2
    · 

Proof state:
case intro.intro.intro.intro.intro.intro.refine'_4
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
s : Set α
f : α → Set (Set α)
fsubset : ∀ x ∈ s, f x ⊆ (fun x => (fun r => closedBall x r) '' Ioi 0) x
ffine : ∀ x ∈ s, ∀ ε > 0, ∃ a ∈ f x, a ⊆ closedBall x ε
g : α → Set ℝ := fun x => {r | 0 < r ∧ closedBall x r ∈ f x}
A : ∀ x ∈ s, ∀ δ > 0, Set.Nonempty (g x ∩ Ioo 0 δ)
t : Set α
r : α → ℝ
left✝ : Set.Countable t
ts : t ⊆ s
tg : ∀ x ∈ t, r x ∈ g x ∩ Ioo 0 1
μt : ↑↑μ (s \ ⋃ x ∈ t, closedBall x (r x)) = 0
tdisj : PairwiseDisjoint t fun x => closedBall x (r x)
F : α → α × Set α := fun x => (x, closedBall x (r x))
⊢ ↑↑μ (s \ ⋃ p ∈ F '' t, p.2) = 0

Next tactic:
rwa [biUnion_image]
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  

Proof state:
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
⊢ Tendsto (fun r => closedBall x r) (𝓝[>] 0) (VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x)

Next tactic:
intro s hs
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  

Proof state:
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
⊢ s ∈ map (fun r => closedBall x r) (𝓝[>] 0)

Next tactic:
simp only [mem_map]
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  

Proof state:
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
⊢ (fun r => closedBall x r) ⁻¹' s ∈ 𝓝[>] 0

Next tactic:
obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
  

Proof state:
case intro.intro
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
ε : ℝ
εpos : ε > 0
hε : ∀ a ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x, a ⊆ closedBall x ε → a ∈ s
⊢ (fun r => closedBall x r) ⁻¹' s ∈ 𝓝[>] 0

Next tactic:
have : Ioc (0 : ℝ) ε ∈ 𝓝[>] (0 : ℝ) := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, εpos⟩
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
  have : Ioc (0 : ℝ) ε ∈ 𝓝[>] (0 : ℝ) := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, εpos⟩
  

Proof state:
case intro.intro
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
ε : ℝ
εpos : ε > 0
hε : ∀ a ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x, a ⊆ closedBall x ε → a ∈ s
this : Ioc 0 ε ∈ 𝓝[>] 0
⊢ (fun r => closedBall x r) ⁻¹' s ∈ 𝓝[>] 0

Next tactic:
filter_upwards [this] with _ hr
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
  have : Ioc (0 : ℝ) ε ∈ 𝓝[>] (0 : ℝ) := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, εpos⟩
  filter_upwards [this] with _ hr
  

Proof state:
case h
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
ε : ℝ
εpos : ε > 0
hε : ∀ a ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x, a ⊆ closedBall x ε → a ∈ s
this : Ioc 0 ε ∈ 𝓝[>] 0
a✝ : ℝ
hr : a✝ ∈ Ioc 0 ε
⊢ a✝ ∈ (fun r => closedBall x r) ⁻¹' s

Next tactic:
apply hε
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
  have : Ioc (0 : ℝ) ε ∈ 𝓝[>] (0 : ℝ) := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, εpos⟩
  filter_upwards [this] with _ hr
  apply hε
  · 

Proof state:
case h.a
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
ε : ℝ
εpos : ε > 0
hε : ∀ a ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x, a ⊆ closedBall x ε → a ∈ s
this : Ioc 0 ε ∈ 𝓝[>] 0
a✝ : ℝ
hr : a✝ ∈ Ioc 0 ε
⊢ (fun r => closedBall x r) a✝ ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x

Next tactic:
exact mem_image_of_mem _ hr.1
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SigmaFinite μ] (x : α) :
    Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
  intro s hs
  simp only [mem_map]
  obtain ⟨ε, εpos, hε⟩ :
    ∃ (ε : ℝ), ε > 0 ∧
      ∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
    (VitaliFamily.mem_filterAt_iff _).1 hs
  have : Ioc (0 : ℝ) ε ∈ 𝓝[>] (0 : ℝ) := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, εpos⟩
  filter_upwards [this] with _ hr
  apply hε
  · exact mem_image_of_mem _ hr.1
  · 

Proof state:
case h.a
α : Type u_1
inst✝⁵ : MetricSpace α
β : Type u
inst✝⁴ : SecondCountableTopology α
inst✝³ : MeasurableSpace α
inst✝² : OpensMeasurableSpace α
inst✝¹ : HasBesicovitchCovering α
μ : Measure α
inst✝ : SigmaFinite μ
x : α
s : Set (Set α)
hs : s ∈ VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x
ε : ℝ
εpos : ε > 0
hε : ∀ a ∈ VitaliFamily.setsAt (Besicovitch.vitaliFamily μ) x, a ⊆ closedBall x ε → a ∈ s
this : Ioc 0 ε ∈ 𝓝[>] 0
a✝ : ℝ
hr : a✝ ∈ Ioc 0 ε
⊢ (fun r => closedBall x r) a✝ ⊆ closedBall x ε

Next tactic:
exact closedBall_subset_closedBall hr.2
/-- In a space with the Besicovitch covering property, the ratio of the measure of balls converges
almost surely to the Radon-Nikodym derivative. -/
theorem ae_tendsto_rnDeriv (ρ μ : Measure β) [IsLocallyFiniteMeasure μ] [IsLocallyFiniteMeasure ρ] :
    ∀ᵐ x ∂μ,
      Tendsto (fun r => ρ (closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 (ρ.rnDeriv μ x)) := by
  

Proof state:
α : Type u_1
inst✝¹¹ : MetricSpace α
β : Type u
inst✝¹⁰ : SecondCountableTopology α
inst✝⁹ : MeasurableSpace α
inst✝⁸ : OpensMeasurableSpace α
inst✝⁷ : HasBesicovitchCovering α
inst✝⁶ : MetricSpace β
inst✝⁵ : MeasurableSpace β
inst✝⁴ : BorelSpace β
inst✝³ : SecondCountableTopology β
inst✝² : HasBesicovitchCovering β
ρ μ : Measure β
inst✝¹ : IsLocallyFiniteMeasure μ
inst✝ : IsLocallyFiniteMeasure ρ
⊢ ∀ᵐ (x : β) ∂μ, Tendsto (fun r => ↑↑ρ (closedBall x r) / ↑↑μ (closedBall x r)) (𝓝[>] 0) (𝓝 (Measure.rnDeriv ρ μ x))

Next tactic:
filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (Besicovitch.vitaliFamily μ) ρ] with x hx
/-- In a space with the Besicovitch covering property, the ratio of the measure of balls converges
almost surely to the Radon-Nikodym derivative. -/
theorem ae_tendsto_rnDeriv (ρ μ : Measure β) [IsLocallyFiniteMeasure μ] [IsLocallyFiniteMeasure ρ] :
    ∀ᵐ x ∂μ,
      Tendsto (fun r => ρ (closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 (ρ.rnDeriv μ x)) := by
  filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (Besicovitch.vitaliFamily μ) ρ] with x hx
  

Proof state:
case h
α : Type u_1
inst✝¹¹ : MetricSpace α
β : Type u
inst✝¹⁰ : SecondCountableTopology α
inst✝⁹ : MeasurableSpace α
inst✝⁸ : OpensMeasurableSpace α
inst✝⁷ : HasBesicovitchCovering α
inst✝⁶ : MetricSpace β
inst✝⁵ : MeasurableSpace β
inst✝⁴ : BorelSpace β
inst✝³ : SecondCountableTopology β
inst✝² : HasBesicovitchCovering β
ρ μ : Measure β
inst✝¹ : IsLocallyFiniteMeasure μ
inst✝ : IsLocallyFiniteMeasure ρ
x : β
hx : Tendsto (fun a => ↑↑ρ a / ↑↑μ a) (VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x) (𝓝 (Measure.rnDeriv ρ μ x))
⊢ Tendsto (fun r => ↑↑ρ (closedBall x r) / ↑↑μ (closedBall x r)) (𝓝[>] 0) (𝓝 (Measure.rnDeriv ρ μ x))

Next tactic:
exact hx.comp (tendsto_filterAt μ x)
/-- Given a measurable set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges when
`r` tends to `0`, for almost every `x`. The limit is `1` for `x ∈ s` and `0` for `x ∉ s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A version for non-measurable sets holds, but it only gives the first conclusion,
see `ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div_of_measurableSet (μ : Measure β) [IsLocallyFiniteMeasure μ]
    {s : Set β} (hs : MeasurableSet s) :
    ∀ᵐ x ∂μ,
      Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0)
        (𝓝 (s.indicator 1 x)) := by
  

Proof state:
α : Type u_1
inst✝¹⁰ : MetricSpace α
β : Type u
inst✝⁹ : SecondCountableTopology α
inst✝⁸ : MeasurableSpace α
inst✝⁷ : OpensMeasurableSpace α
inst✝⁶ : HasBesicovitchCovering α
inst✝⁵ : MetricSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
inst✝² : SecondCountableTopology β
inst✝¹ : HasBesicovitchCovering β
μ : Measure β
inst✝ : IsLocallyFiniteMeasure μ
s : Set β
hs : MeasurableSet s
⊢ ∀ᵐ (x : β) ∂μ, Tendsto (fun r => ↑↑μ (s ∩ closedBall x r) / ↑↑μ (closedBall x r)) (𝓝[>] 0) (𝓝 (indicator s 1 x))

Next tactic:
filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div_of_measurableSet
      (Besicovitch.vitaliFamily μ) hs]
/-- Given a measurable set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges when
`r` tends to `0`, for almost every `x`. The limit is `1` for `x ∈ s` and `0` for `x ∉ s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A version for non-measurable sets holds, but it only gives the first conclusion,
see `ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div_of_measurableSet (μ : Measure β) [IsLocallyFiniteMeasure μ]
    {s : Set β} (hs : MeasurableSet s) :
    ∀ᵐ x ∂μ,
      Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0)
        (𝓝 (s.indicator 1 x)) := by
  filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div_of_measurableSet
      (Besicovitch.vitaliFamily μ) hs]
  

Proof state:
case h
α : Type u_1
inst✝¹⁰ : MetricSpace α
β : Type u
inst✝⁹ : SecondCountableTopology α
inst✝⁸ : MeasurableSpace α
inst✝⁷ : OpensMeasurableSpace α
inst✝⁶ : HasBesicovitchCovering α
inst✝⁵ : MetricSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
inst✝² : SecondCountableTopology β
inst✝¹ : HasBesicovitchCovering β
μ : Measure β
inst✝ : IsLocallyFiniteMeasure μ
s : Set β
hs : MeasurableSet s
⊢ ∀ (a : β),
    Tendsto (fun a => ↑↑μ (s ∩ a) / ↑↑μ a) (VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) a)
        (𝓝 (indicator s 1 a)) →
      Tendsto (fun r => ↑↑μ (s ∩ closedBall a r) / ↑↑μ (closedBall a r)) (𝓝[>] 0) (𝓝 (indicator s 1 a))

Next tactic:
intro x hx
/-- Given a measurable set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges when
`r` tends to `0`, for almost every `x`. The limit is `1` for `x ∈ s` and `0` for `x ∉ s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A version for non-measurable sets holds, but it only gives the first conclusion,
see `ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div_of_measurableSet (μ : Measure β) [IsLocallyFiniteMeasure μ]
    {s : Set β} (hs : MeasurableSet s) :
    ∀ᵐ x ∂μ,
      Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0)
        (𝓝 (s.indicator 1 x)) := by
  filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div_of_measurableSet
      (Besicovitch.vitaliFamily μ) hs]
  intro x hx
  

Proof state:
case h
α : Type u_1
inst✝¹⁰ : MetricSpace α
β : Type u
inst✝⁹ : SecondCountableTopology α
inst✝⁸ : MeasurableSpace α
inst✝⁷ : OpensMeasurableSpace α
inst✝⁶ : HasBesicovitchCovering α
inst✝⁵ : MetricSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
inst✝² : SecondCountableTopology β
inst✝¹ : HasBesicovitchCovering β
μ : Measure β
inst✝ : IsLocallyFiniteMeasure μ
s : Set β
hs : MeasurableSet s
x : β
hx : Tendsto (fun a => ↑↑μ (s ∩ a) / ↑↑μ a) (VitaliFamily.filterAt (Besicovitch.vitaliFamily μ) x) (𝓝 (indicator s 1 x))
⊢ Tendsto (fun r => ↑↑μ (s ∩ closedBall x r) / ↑↑μ (closedBall x r)) (𝓝[>] 0) (𝓝 (indicator s 1 x))

Next tactic:
exact hx.comp (tendsto_filterAt μ x)
/-- Given an arbitrary set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges
to `1` when `r` tends to `0`, for almost every `x` in `s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A stronger version holds for measurable sets, see `ae_tendsto_measure_inter_div_of_measurableSet`.

See also `IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div (μ : Measure β) [IsLocallyFiniteMeasure μ] (s : Set β) :
    ∀ᵐ x ∂μ.restrict s,
      Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1) := by
  

Proof state:
α : Type u_1
inst✝¹⁰ : MetricSpace α
β : Type u
inst✝⁹ : SecondCountableTopology α
inst✝⁸ : MeasurableSpace α
inst✝⁷ : OpensMeasurableSpace α
inst✝⁶ : HasBesicovitchCovering α
inst✝⁵ : MetricSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
inst✝² : SecondCountableTopology β
inst✝¹ : HasBesicovitchCovering β
μ : Measure β
inst✝ : IsLocallyFiniteMeasure μ
s : Set β
⊢ ∀ᵐ (x : β) ∂Measure.restrict μ s, Tendsto (fun r => ↑↑μ (s ∩ closedBall x r) / ↑↑μ (closedBall x r)) (𝓝[>] 0) (𝓝 1)

Next tactic:
filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div (Besicovitch.vitaliFamily μ) s] with x
    hx using hx.comp (tendsto_filterAt μ x)
theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) :=
  ⟨X - C x, monic_X_sub_C _, by 

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
inst✝³ : CommRing R
inst✝² : Ring A
inst✝¹ : Ring S
f : R →+* S
inst✝ : Algebra R A
x : R
⊢ eval₂ f (f x) (X - C x) = 0

Next tactic:
simp
theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C]
    [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [AlgHomClass F A B C] (f : F)
    (hb : IsIntegral R b) : IsIntegral R (f b) := by
  

Proof state:
R : Type u_1
A : Type u_2
B✝ : Type u_3
S : Type u_4
inst✝¹⁴ : CommRing R
inst✝¹³ : CommRing A
inst✝¹² : Ring B✝
inst✝¹¹ : CommRing S
inst✝¹⁰ : Algebra R A
inst✝⁹ : Algebra R B✝
f✝ : R →+* S
B : Type u_5
C : Type u_6
F : Type u_7
inst✝⁸ : Ring B
inst✝⁷ : Ring C
inst✝⁶ : Algebra R B
inst✝⁵ : Algebra A B
inst✝⁴ : Algebra R C
inst✝³ : IsScalarTower R A B
inst✝² : Algebra A C
inst✝¹ : IsScalarTower R A C
b : B
inst✝ : AlgHomClass F A B C
f : F
hb : IsIntegral R b
⊢ IsIntegral R (f b)

Next tactic:
obtain ⟨P, hP⟩ := hb
theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C]
    [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [AlgHomClass F A B C] (f : F)
    (hb : IsIntegral R b) : IsIntegral R (f b) := by
  obtain ⟨P, hP⟩ := hb
  

Proof state:
case intro
R : Type u_1
A : Type u_2
B✝ : Type u_3
S : Type u_4
inst✝¹⁴ : CommRing R
inst✝¹³ : CommRing A
inst✝¹² : Ring B✝
inst✝¹¹ : CommRing S
inst✝¹⁰ : Algebra R A
inst✝⁹ : Algebra R B✝
f✝ : R →+* S
B : Type u_5
C : Type u_6
F : Type u_7
inst✝⁸ : Ring B
inst✝⁷ : Ring C
inst✝⁶ : Algebra R B
inst✝⁵ : Algebra A B
inst✝⁴ : Algebra R C
inst✝³ : IsScalarTower R A B
inst✝² : Algebra A C
inst✝¹ : IsScalarTower R A C
b : B
inst✝ : AlgHomClass F A B C
f : F
P : R[X]
hP : Monic P ∧ eval₂ (algebraMap R B) b P = 0
⊢ IsIntegral R (f b)

Next tactic:
refine' ⟨P, hP.1, _⟩
theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C]
    [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [AlgHomClass F A B C] (f : F)
    (hb : IsIntegral R b) : IsIntegral R (f b) := by
  obtain ⟨P, hP⟩ := hb
  refine' ⟨P, hP.1, _⟩
  

Proof state:
case intro
R : Type u_1
A : Type u_2
B✝ : Type u_3
S : Type u_4
inst✝¹⁴ : CommRing R
inst✝¹³ : CommRing A
inst✝¹² : Ring B✝
inst✝¹¹ : CommRing S
inst✝¹⁰ : Algebra R A
inst✝⁹ : Algebra R B✝
f✝ : R →+* S
B : Type u_5
C : Type u_6
F : Type u_7
inst✝⁸ : Ring B
inst✝⁷ : Ring C
inst✝⁶ : Algebra R B
inst✝⁵ : Algebra A B
inst✝⁴ : Algebra R C
inst✝³ : IsScalarTower R A B
inst✝² : Algebra A C
inst✝¹ : IsScalarTower R A C
b : B
inst✝ : AlgHomClass F A B C
f : F
P : R[X]
hP : Monic P ∧ eval₂ (algebraMap R B) b P = 0
⊢ eval₂ (algebraMap R C) (f b) P = 0

Next tactic:
rw [← aeval_def, ← aeval_map_algebraMap A,
    aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero]
theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S]
    [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U)
    (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) :
    IsIntegral T (ψ a) :=
  let ⟨p, hp⟩ := ha
  ⟨p.map φ, hp.1.map _, by
    

Proof state:
R✝ : Type u_1
A : Type u_2
B : Type u_3
S✝ : Type u_4
inst✝¹¹ : CommRing R✝
inst✝¹⁰ : CommRing A
inst✝⁹ : Ring B
inst✝⁸ : CommRing S✝
inst✝⁷ : Algebra R✝ A
inst✝⁶ : Algebra R✝ B
f : R✝ →+* S✝
R : Type u_5
S : Type u_6
T : Type u_7
U : Type u_8
inst✝⁵ : CommRing R
inst✝⁴ : Ring S
inst✝³ : CommRing T
inst✝² : Ring U
inst✝¹ : Algebra R S
inst✝ : Algebra T U
φ : R →+* T
ψ : S →+* U
h : RingHom.comp (algebraMap T U) φ = RingHom.comp ψ (algebraMap R S)
a : S
ha : IsIntegral R a
p : R[X]
hp : Monic p ∧ eval₂ (algebraMap R S) a p = 0
⊢ eval₂ (algebraMap T U) (ψ a) (Polynomial.map φ p) = 0

Next tactic:
rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]