Theorem: exists_measurable_piecewise
File: Mathlib/MeasureTheory/MeasurableSpace.lean

tactic: inhabit ι
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: set g' : (i : ι) → t i → β := fun i => g i ∘ (↑)
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: have ht' : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), g' i ⟨x, hxi⟩ = g' j ⟨x, hxj⟩
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: set f : (⋃ i, t i) → β := iUnionLift t g' ht' _ Subset.rfl
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: have hfm : Measurable f := measurable_iUnionLift _ _ t_meas
  (fun i => (hg i).comp measurable_subtype_coe)
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
f : ↑(⋃ (i : ι), t i) → β := iUnionLift t g' ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: classical
  refine ⟨fun x => if hx : x ∈ ⋃ i, t i then f ⟨x, hx⟩ else g default x,
    hfm.dite ((hg default).comp measurable_subtype_coe) (.iUnion t_meas), fun i x hx => ?_⟩
  simp only [dif_pos (mem_iUnion.2 ⟨i, hx⟩)]
  exact iUnionLift_of_mem ⟨x, mem_iUnion.2 ⟨i, hx⟩⟩ hx
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
f : ↑(⋃ (i : ι), t i) → β := iUnionLift t g' ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
hfm : Measurable f
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: intro i j x hxi hxj
state_before: case ht'
α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
⊢ ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }

tactic: rcases eq_or_ne i j with rfl | hij
state_before: case ht'
α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
i j : ι
x : α
hxi : x ∈ t i
hxj : x ∈ t j
⊢ g' i { val := x, property := hxi } = g' j { val := x, property := hxj }

tactic: rfl
state_before: case ht'.inl
α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
i : ι
x : α
hxi hxj : x ∈ t i
⊢ g' i { val := x, property := hxi } = g' i { val := x, property := hxj }

tactic: exact ht hij ⟨hxi, hxj⟩
state_before: case ht'.inr
α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
i j : ι
x : α
hxi : x ∈ t i
hxj : x ∈ t j
hij : i ≠ j
⊢ g' i { val := x, property := hxi } = g' j { val := x, property := hxj }

tactic: refine ⟨fun x => if hx : x ∈ ⋃ i, t i then f ⟨x, hx⟩ else g default x,
  hfm.dite ((hg default).comp measurable_subtype_coe) (.iUnion t_meas), fun i x hx => ?_⟩
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
f : ↑(⋃ (i : ι), t i) → β := iUnionLift t g' ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
hfm : Measurable f
⊢ ∃ f, Measurable f ∧ ∀ (n : ι), EqOn f (g n) (t n)

tactic: simp only [dif_pos (mem_iUnion.2 ⟨i, hx⟩)]
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
f : ↑(⋃ (i : ι), t i) → β := iUnionLift t g' ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
hfm : Measurable f
i : ι
x : α
hx : x ∈ t i
⊢ (fun x => if hx : x ∈ ⋃ (i : ι), t i then f { val := x, property := hx } else g default x) x = g i x

tactic: exact iUnionLift_of_mem ⟨x, mem_iUnion.2 ⟨i, hx⟩⟩ hx
state_before: α : Type u_2
β : Type u_3
γ : Type ?u.93731
δ : Type ?u.93734
δ' : Type ?u.93737
ι✝ : Sort uι
s t✝ u : Set α
m : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
ι : Type u_1
inst✝¹ : Countable ι
inst✝ : Nonempty ι
t : ι → Set α
t_meas : ∀ (n : ι), MeasurableSet (t n)
g : ι → α → β
hg : ∀ (n : ι), Measurable (g n)
ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)
inhabited_h : Inhabited ι
g' : (i : ι) → ↑(t i) → β := fun i => g i ∘ Subtype.val
ht' :
  ∀ (i j : ι) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j),
    g' i { val := x, property := hxi } = g' j { val := x, property := hxj }
f : ↑(⋃ (i : ι), t i) → β := iUnionLift t g' ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
hfm : Measurable f
i : ι
x : α
hx : x ∈ t i
⊢ iUnionLift t (fun i => g i ∘ Subtype.val) ht' (⋃ (i : ι), t i) (_ : (⋃ (i : ι), t i) ⊆ ⋃ (i : ι), t i)
      { val := x, property := (_ : x ∈ ⋃ (i : ι), t i) } =
    g i x