l3lab/ntp-mathlib huggingface dataset:
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
⊢ ↑↑ρ (Prod.map id f ⁻¹' {x | x.2 ∈ (range f)ᶜ}) = 0
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
⊢ MeasurableSet {x | x.2 ∈ (range f)ᶜ}

Next tactic:
swap
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · 

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
⊢ MeasurableSet {x | x.2 ∈ (range f)ᶜ}

Next tactic:
exact measurable_snd hf.measurableSet_range.compl
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · exact measurable_snd hf.measurableSet_range.compl
    

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
⊢ ↑↑ρ (Prod.map id f ⁻¹' {x | x.2 ∈ (range f)ᶜ}) = 0

Next tactic:
convert measure_empty (α := α × Ω)
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · exact measurable_snd hf.measurableSet_range.compl
    convert measure_empty (α := α × Ω)
    

Proof state:
case h.e'_2.h.e'_3
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
⊢ Prod.map id f ⁻¹' {x | x.2 ∈ (range f)ᶜ} = ∅

Next tactic:
ext1 x
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · exact measurable_snd hf.measurableSet_range.compl
    convert measure_empty (α := α × Ω)
    ext1 x
    

Proof state:
case h.e'_2.h.e'_3.h
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
x : α × Ω
⊢ x ∈ Prod.map id f ⁻¹' {x | x.2 ∈ (range f)ᶜ} ↔ x ∈ ∅

Next tactic:
simp only [mem_compl_iff, mem_range, preimage_setOf_eq, Prod_map, mem_setOf_eq,
      mem_empty_iff_false, iff_false_iff, Classical.not_not, exists_apply_eq_apply]
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · exact measurable_snd hf.measurableSet_range.compl
    convert measure_empty (α := α × Ω)
    ext1 x
    simp only [mem_compl_iff, mem_range, preimage_setOf_eq, Prod_map, mem_setOf_eq,
      mem_empty_iff_false, iff_false_iff, Classical.not_not, exists_apply_eq_apply]
  classical
  

Proof state:
case intro
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
h_ae : ∀ᵐ (a : α) ∂Measure.fst ρ, a ∈ ρ_set
⊢ ∃ η, ∃ (_ : IsMarkovKernel η), kernel.const γ ρ = kernel.const γ (Measure.fst ρ) ⊗ₖ kernel.prodMkLeft γ η

Next tactic:
obtain ⟨x₀, hx₀⟩ : ∃ x, x ∈ range f := range_nonempty _
/-- Existence of a conditional kernel. Use the definition `condKernel` to get that kernel. -/
theorem exists_cond_kernel (γ : Type*) [MeasurableSpace γ] :
    ∃ (η : kernel α Ω) (_h : IsMarkovKernel η), kernel.const γ ρ =
      (kernel.const γ ρ.fst) ⊗ₖ (kernel.prodMkLeft γ η) := by
  obtain ⟨f, hf⟩ := exists_measurableEmbedding_real Ω
  let ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f)
  -- The general idea is to define `η = kernel.comapRight (condKernelReal ρ') hf`. There is
  -- however an issue: that `η` may not be a Markov kernel since its value is only a
  -- probability distribution almost everywhere with respect to `ρ.fst`, not everywhere.
  -- We modify it to obtain a Markov kernel which is almost everywhere equal.
  let ρ_set := (toMeasurable ρ.fst {a | condKernelReal ρ' a (range f) = 1}ᶜ)ᶜ
  have hm : MeasurableSet ρ_set := (measurableSet_toMeasurable _ _).compl
  have h_eq_one_of_mem : ∀ a ∈ ρ_set, condKernelReal ρ' a (range f) = 1 := by
    intro a ha
    rw [mem_compl_iff] at ha
    have h_ss := subset_toMeasurable ρ.fst {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    suffices ha' : a ∉ {a : α | condKernelReal ρ' a (range f) = 1}ᶜ
    · rwa [not_mem_compl_iff] at ha'
    exact not_mem_subset h_ss ha
  have h_prod_embed : MeasurableEmbedding (Prod.map (id : α → α) f) :=
    MeasurableEmbedding.id.prod_mk hf
  have h_fst : ρ'.fst = ρ.fst := by
    ext1 u hu
    rw [Measure.fst_apply hu, Measure.fst_apply hu,
      Measure.map_apply h_prod_embed.measurable (measurable_fst hu)]
    rfl
  have h_ae : ∀ᵐ a ∂ρ.fst, a ∈ ρ_set := by
    rw [ae_iff]
    simp only [not_mem_compl_iff, setOf_mem_eq, measure_toMeasurable]
    change ρ.fst {a : α | a ∉ {a' : α | condKernelReal ρ' a' (range f) = 1}} = 0
    rw [← ae_iff, ← h_fst]
    refine' ae_condKernelReal_eq_one ρ' hf.measurableSet_range _
    rw [Measure.map_apply h_prod_embed.measurable]
    swap; · exact measurable_snd hf.measurableSet_range.compl
    convert measure_empty (α := α × Ω)
    ext1 x
    simp only [mem_compl_iff, mem_range, preimage_setOf_eq, Prod_map, mem_setOf_eq,
      mem_empty_iff_false, iff_false_iff, Classical.not_not, exists_apply_eq_apply]
  classical
  obtain ⟨x₀, hx₀⟩ : ∃ x, x ∈ range f := range_nonempty _
  

Proof state:
case intro.intro
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁴ : MeasurableSpace Ω
inst✝³ : StandardBorelSpace Ω
inst✝² : Nonempty Ω
ρ : Measure (α × Ω)
inst✝¹ : IsFiniteMeasure ρ
γ : Type u_3
inst✝ : MeasurableSpace γ
f : Ω → ℝ
hf : MeasurableEmbedding f
ρ' : Measure (α × ℝ) := Measure.map (Prod.map id f) ρ
ρ_set : Set α := (toMeasurable (Measure.fst ρ) {a | ↑↑((condKernelReal ρ') a) (range f) = 1}ᶜ)ᶜ
hm : MeasurableSet ρ_set
h_eq_one_of_mem : ∀ a ∈ ρ_set, ↑↑((condKernelReal ρ') a) (range f) = 1
h_prod_embed : MeasurableEmbedding (Prod.map id f)
h_fst : Measure.fst ρ' = Measure.fst ρ
h_ae : ∀ᵐ (a : α) ∂Measure.fst ρ, a ∈ ρ_set
x₀ : ℝ
hx₀ : x₀ ∈ range f
⊢ ∃ η, ∃ (_ : IsMarkovKernel η), kernel.const γ ρ = kernel.const γ (Measure.fst ρ) ⊗ₖ kernel.prodMkLeft γ η

Next tactic:
let η' :=
    kernel.piecewise hm (condKernelReal ρ') (kernel.deterministic (fun _ => x₀) measurable_const)
theorem condKernel_def : ρ.condKernel = (exists_cond_kernel ρ Unit).choose := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ Measure.condKernel ρ =
    Exists.choose
      (_ :
        ∃ η,
          ∃ (_ : IsMarkovKernel η), kernel.const Unit ρ = kernel.const Unit (Measure.fst ρ) ⊗ₖ kernel.prodMkLeft Unit η)

Next tactic:
rw [MeasureTheory.Measure.condKernel]
instance : IsMarkovKernel ρ.condKernel := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ IsMarkovKernel (Measure.condKernel ρ)

Next tactic:
rw [condKernel_def]
instance : IsMarkovKernel ρ.condKernel := by
  rw [condKernel_def]; 

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ IsMarkovKernel
    (Exists.choose
      (_ :
        ∃ η,
          ∃ (_ : IsMarkovKernel η),
            kernel.const Unit ρ = kernel.const Unit (Measure.fst ρ) ⊗ₖ kernel.prodMkLeft Unit η))

Next tactic:
exact (exists_cond_kernel ρ Unit).choose_spec.choose
theorem kernel.const_unit_eq_compProd :
    kernel.const Unit ρ = kernel.const Unit ρ.fst ⊗ₖ kernel.prodMkLeft Unit ρ.condKernel := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ const Unit ρ = const Unit (Measure.fst ρ) ⊗ₖ prodMkLeft Unit (Measure.condKernel ρ)

Next tactic:
simp_rw [condKernel_def]
theorem kernel.const_unit_eq_compProd :
    kernel.const Unit ρ = kernel.const Unit ρ.fst ⊗ₖ kernel.prodMkLeft Unit ρ.condKernel := by
  simp_rw [condKernel_def]; 

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ const Unit ρ =
    const Unit (Measure.fst ρ) ⊗ₖ
      prodMkLeft Unit
        (Exists.choose
          (_ : ∃ η, ∃ (_ : IsMarkovKernel η), const Unit ρ = const Unit (Measure.fst ρ) ⊗ₖ prodMkLeft Unit η))

Next tactic:
exact (exists_cond_kernel ρ Unit).choose_spec.choose_spec
/-- **Disintegration** of finite product measures on `α × Ω`, where `Ω` is standard Borel. Such a
measure can be written as the composition-product of the constant kernel with value `ρ.fst`
(marginal measure over `α`) and a Markov kernel from `α` to `Ω`. We call that Markov kernel
`ProbabilityTheory.condKernel ρ`. -/
theorem measure_eq_compProd : ρ = ρ.fst ⊗ₘ ρ.condKernel := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝³ : MeasurableSpace Ω
inst✝² : StandardBorelSpace Ω
inst✝¹ : Nonempty Ω
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ ρ = Measure.fst ρ ⊗ₘ Measure.condKernel ρ

Next tactic:
rw [Measure.compProd, ← kernel.const_unit_eq_compProd, kernel.const_apply]
/-- **Disintegration** of constant kernels. A constant kernel on a product space `α × Ω`, where `Ω`
is standard Borel, can be written as the composition-product of the constant kernel with
value `ρ.fst` (marginal measure over `α`) and a Markov kernel from `α` to `Ω`. We call that
Markov kernel `ProbabilityTheory.condKernel ρ`. -/
theorem kernel.const_eq_compProd (γ : Type*) [MeasurableSpace γ] (ρ : Measure (α × Ω))
    [IsFiniteMeasure ρ] :
    kernel.const γ ρ = kernel.const γ ρ.fst ⊗ₖ kernel.prodMkLeft γ ρ.condKernel := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
Ω : Type u_2
inst✝⁵ : MeasurableSpace Ω
inst✝⁴ : StandardBorelSpace Ω
inst✝³ : Nonempty Ω
ρ✝ : Measure (α × Ω)
inst✝² : IsFiniteMeasure ρ✝
γ : Type u_3
inst✝¹ : MeasurableSpace γ
ρ : Measure (α × Ω)
inst✝ : IsFiniteMeasure ρ
⊢ const γ ρ = const γ (Measure.fst ρ) ⊗ₖ prodMkLeft γ (Measure.condKernel ρ)

Next tactic:
ext a s hs : 2