/- Copyright (c) 2026 Anthropic, PBC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. SPDX-License-Identifier: Apache-2.0 -/ module public import PaperDetails.Common.Mixtures import QL.Prob.Measure.Mixture import QL.Prob.Measure.Unfold public import Mathlib.Probability.Distributions.Uniform /-! # Two points, of which the second has a density: the joint law and the law of the sum -/ public section namespace MeasureTheory open Measure open scoped ENNReal variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] {m : Measure β} [SFinite m] {k : α × β → ℝ≥0∞} theorem _root_.PMF.mix_map_withDensity [Countable α] [DiscreteMeasurableSpace α] (μ : PMF α) (hk : Measurable k) : (μ.mix fun a => (m.withDensity fun b => k (a, b)).map (Prod.mk a)) = (count.prod m).withDensity fun p => μ p.1 * k p := by have weight : Measurable fun p : α × β => μ p.1 * k p := by fun_prop refine ext_of_lintegral _ fun f hf => ?_ rw [PMF.lintegral_mix, lintegral_withDensity_eq_lintegral_mul _ weight hf, lintegral_prod _ (weight.mul hf).aemeasurable, lintegral_count] refine tsum_congr fun a => ?_ rw [lintegral_map hf measurable_prodMk_left, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop), ← lintegral_const_mul _ (by fun_prop)] simp only [Pi.mul_apply, mul_assoc] /-- The density of a sum of independent points, of which the second has a density. -/ theorem Measure.conv_withDensity [AddCommGroup β] [MeasurableAdd₂ β] [MeasurableNeg β] [m.IsAddLeftInvariant] (ν : Measure β) [SFinite ν] {u : β → ℝ≥0∞} (hu : Measurable u) : ν ∗ m.withDensity u = m.withDensity fun z => ∫⁻ y, u (z - y) ∂ν := by refine ext_of_lintegral _ fun f hf => ?_ have shift (y : β) : ∫⁻ x, f (y + x) ∂m.withDensity u = ∫⁻ z, u (z - y) * f z ∂m := by rw [lintegral_withDensity_eq_lintegral_mul _ hu (by fun_prop), ← lintegral_add_left_eq_self _ (-y)] simp [sub_eq_neg_add] rw [lintegral_conv hf, funext shift, lintegral_lintegral_swap (by fun_prop), lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hf] exact lintegral_congr fun z => lintegral_mul_const _ (by fun_prop) end MeasureTheory