-- Mathlib/Probability/Kernel/Disintegration/Density.lean
lemma measurable_densityProcess_countableFiltration_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ)
    (n : ℕ) {s : Set β} (hs : MeasurableSet s) :
    Measurable[mα.prod (countableFiltration γ n)] (fun (p : α × γ) ↦
      κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2))

Proof state:
case refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ ∀ (y : ↑(countablePartition γ n)), Measurable fun x => (ν (x, y).1) ↑(x, y).2

Tactic:
rintro ⟨t, ht⟩

Result:
case refine_2.mk
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
t : Set γ
ht : t ∈ countablePartition γ n
⊢ Measurable fun x => (ν (x, ⟨t, ht⟩).1) ↑(x, ⟨t, ht⟩).2

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2

Tactic:
refine Measurable.div ?_ ?_

Result:
case refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (κ p.1) (↑p.2 ×ˢ s)

case refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (ν p.1) ↑p.2

Proof state:
case refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (κ p.1) (↑p.2 ×ˢ s)

Tactic:
refine measurable_from_prod_countable (fun t ↦ ?_)

Result:
case refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
t : ↑(countablePartition γ n)
⊢ Measurable fun x => (κ (x, t).1) (↑(x, t).2 ×ˢ s)

Proof state:
case refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (ν p.1) ↑p.2

Tactic:
refine measurable_from_prod_countable ?_

Result:
case refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ ∀ (y : ↑(countablePartition γ n)), Measurable fun x => (ν (x, y).1) ↑(x, y).2

Proof state:
case refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
t : ↑(countablePartition γ n)
⊢ Measurable fun x => (κ (x, t).1) (↑(x, t).2 ×ˢ s)

Tactic:
exact Kernel.measurable_coe _ ((measurableSet_countablePartition _ t.prop).prod hs)

Result:
no goals

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
h1 : Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2
⊢ Measurable ((fun c => ⟨countablePartitionSet n c, ⋯⟩) ∘ fun p => p.2)

Tactic:
exact (measurable_countablePartitionSet_subtype n ⊤).comp measurable_snd

Result:
no goals

Proof state:
case refine_2.mk
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
t : Set γ
ht : t ∈ countablePartition γ n
⊢ Measurable fun x => (ν (x, ⟨t, ht⟩).1) ↑(x, ⟨t, ht⟩).2

Tactic:
exact Kernel.measurable_coe _ (measurableSet_countablePartition _ ht)

Result:
no goals

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
h1 : Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2
⊢ Measurable fun p => ⟨countablePartitionSet n p.2, ⋯⟩

Tactic:
change @Measurable (α × γ) (countablePartition γ n) (mα.prod (countableFiltration γ n)) ⊤
  ((fun c ↦ ⟨countablePartitionSet n c, countablePartitionSet_mem n c⟩) ∘ (fun p : α × γ ↦ p.2))

Result:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
h1 : Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2
⊢ Measurable ((fun c => ⟨countablePartitionSet n c, ⋯⟩) ∘ fun p => p.2)

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable fun p => (κ p.1) (countablePartitionSet n p.2 ×ˢ s) / (ν p.1) (countablePartitionSet n p.2)

Tactic:
change Measurable[mα.prod (countableFiltration γ n)]
    ((fun (p : α × countablePartition γ n) ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2)
      ∘ (fun (p : α × γ) ↦ (p.1, ⟨countablePartitionSet n p.2, countablePartitionSet_mem n p.2⟩)))

Result:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
⊢ Measurable ((fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2) ∘ fun p => (p.1, ⟨countablePartitionSet n p.2, ⋯⟩))

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
h1 : Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2
⊢ Measurable ((fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2) ∘ fun p => (p.1, ⟨countablePartitionSet n p.2, ⋯⟩))

Tactic:
refine h1.comp (measurable_fst.prod_mk ?_)

Result:
α : Type u_1
β : Type u_2
γ : Type u_3
mα : MeasurableSpace α
mβ : MeasurableSpace β
mγ : MeasurableSpace γ
inst✝ : CountablyGenerated γ
κ : Kernel α (γ × β)
ν : Kernel α γ
n : ℕ
s : Set β
hs : MeasurableSet s
h1 : Measurable fun p => (κ p.1) (↑p.2 ×ˢ s) / (ν p.1) ↑p.2
⊢ Measurable fun p => ⟨countablePartitionSet n p.2, ⋯⟩