probability.kernel.with_densityMathlib.Probability.Kernel.WithDensity

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -206,7 +206,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn
     rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this
     · refine' this.trans (le_of_eq _)
-      rw [ENNReal.ofReal_coe_nat]
+      rw [ENNReal.ofReal_natCast]
     · norm_cast
       exact zero_le _
   have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 :=
Diff
@@ -204,7 +204,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     by
     intro a b n hn
     have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn
-    rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this 
+    rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this
     · refine' this.trans (le_of_eq _)
       rw [ENNReal.ofReal_coe_nat]
     · norm_cast
@@ -225,7 +225,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
       suffices : ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0
       exact summable_of_ne_finset_zero this
       intro n hn_not_mem
-      rw [Finset.mem_range, not_lt] at hn_not_mem 
+      rw [Finset.mem_range, not_lt] at hn_not_mem
       exact h_zero a b n hn_not_mem
     ext a b : 2
     rw [tsum_apply (pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
Diff
@@ -64,14 +64,17 @@ noncomputable def withDensity (κ : kernel α β) [IsSFiniteKernel κ] (f : α 
 
 #print ProbabilityTheory.kernel.withDensity_of_not_measurable /-
 theorem withDensity_of_not_measurable (κ : kernel α β) [IsSFiniteKernel κ]
-    (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical
+    (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf
 #align probability_theory.kernel.with_density_of_not_measurable ProbabilityTheory.kernel.withDensity_of_not_measurable
 -/
 
 #print ProbabilityTheory.kernel.withDensity_apply /-
 protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) :=
-  by classical
+  by
+  classical
+  rw [with_density, dif_pos hf]
+  rfl
 #align probability_theory.kernel.with_density_apply ProbabilityTheory.kernel.withDensity_apply
 -/
 
Diff
@@ -64,17 +64,14 @@ noncomputable def withDensity (κ : kernel α β) [IsSFiniteKernel κ] (f : α 
 
 #print ProbabilityTheory.kernel.withDensity_of_not_measurable /-
 theorem withDensity_of_not_measurable (κ : kernel α β) [IsSFiniteKernel κ]
-    (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf
+    (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical
 #align probability_theory.kernel.with_density_of_not_measurable ProbabilityTheory.kernel.withDensity_of_not_measurable
 -/
 
 #print ProbabilityTheory.kernel.withDensity_apply /-
 protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) :=
-  by
-  classical
-  rw [with_density, dif_pos hf]
-  rfl
+  by classical
 #align probability_theory.kernel.with_density_apply ProbabilityTheory.kernel.withDensity_apply
 -/
 
Diff
@@ -3,8 +3,8 @@ Copyright (c) 2023 Rémy Degenne. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
 -/
-import Mathbin.Probability.Kernel.MeasurableIntegral
-import Mathbin.MeasureTheory.Integral.SetIntegral
+import Probability.Kernel.MeasurableIntegral
+import MeasureTheory.Integral.SetIntegral
 
 #align_import probability.kernel.with_density from "leanprover-community/mathlib"@"8af7091a43227e179939ba132e54e54e9f3b089a"
 
Diff
@@ -2,15 +2,12 @@
 Copyright (c) 2023 Rémy Degenne. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
-
-! This file was ported from Lean 3 source module probability.kernel.with_density
-! leanprover-community/mathlib commit 8af7091a43227e179939ba132e54e54e9f3b089a
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Probability.Kernel.MeasurableIntegral
 import Mathbin.MeasureTheory.Integral.SetIntegral
 
+#align_import probability.kernel.with_density from "leanprover-community/mathlib"@"8af7091a43227e179939ba132e54e54e9f3b089a"
+
 /-!
 # With Density
 
Diff
@@ -117,7 +117,7 @@ theorem withDensity_add_left (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFin
     (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f :=
   by
   by_cases hf : Measurable (Function.uncurry f)
-  · ext (a s hs) : 2
+  · ext a s hs : 2
     simp only [kernel.with_density_apply _ hf, coe_fn_add, Pi.add_apply, with_density_add_measure,
       measure.add_apply]
   · simp_rw [with_density_of_not_measurable _ hf]
@@ -147,7 +147,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
   by
   have h_sum_a : ∀ a, Summable fun n => f n a := fun a => pi.summable.mpr fun b => ENNReal.summable
   have h_sum : Summable fun n => f n := pi.summable.mpr h_sum_a
-  ext (a s hs) : 2
+  ext a s hs : 2
   rw [sum_apply' _ a hs, with_density_apply' κ _ a hs]
   swap
   · have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) :=
@@ -230,7 +230,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
       intro n hn_not_mem
       rw [Finset.mem_range, not_lt] at hn_not_mem 
       exact h_zero a b n hn_not_mem
-    ext (a b) : 2
+    ext a b : 2
     rw [tsum_apply (pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
       ENNReal.tsum_eq_liminf_sum_nat]
     have h_finset_sum : ∀ n, ∑ i in Finset.range n, fs i a b = min (f a b) n :=
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
 
 ! This file was ported from Lean 3 source module probability.kernel.with_density
-! leanprover-community/mathlib commit c0d694db494dd4f9aa57f2714b6e4c82b4ebc113
+! leanprover-community/mathlib commit 8af7091a43227e179939ba132e54e54e9f3b089a
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -14,6 +14,9 @@ import Mathbin.MeasureTheory.Integral.SetIntegral
 /-!
 # With Density
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 For an s-finite kernel `κ : kernel α β` and a function `f : α → β → ℝ≥0∞` which is finite
 everywhere, we define `with_density κ f` as the kernel `a ↦ (κ a).with_density (f a)`. This is
 an s-finite kernel.
Diff
@@ -44,6 +44,7 @@ variable {α β ι : Type _} {mα : MeasurableSpace α} {mβ : MeasurableSpace 
 
 variable {κ : kernel α β} {f : α → β → ℝ≥0∞}
 
+#print ProbabilityTheory.kernel.withDensity /-
 /-- Kernel with image `(κ a).with_density (f a)` if `function.uncurry f` is measurable, and
 with image 0 otherwise. If `function.uncurry f` is measurable, it satisfies
 `∫⁻ b, g b ∂(with_density κ f hf a) = ∫⁻ b, f a b * g b ∂(κ a)`. -/
@@ -59,11 +60,15 @@ noncomputable def withDensity (κ : kernel α β) [IsSFiniteKernel κ] (f : α 
         kernel α β))
     fun hf => 0
 #align probability_theory.kernel.with_density ProbabilityTheory.kernel.withDensity
+-/
 
+#print ProbabilityTheory.kernel.withDensity_of_not_measurable /-
 theorem withDensity_of_not_measurable (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf
 #align probability_theory.kernel.with_density_of_not_measurable ProbabilityTheory.kernel.withDensity_of_not_measurable
+-/
 
+#print ProbabilityTheory.kernel.withDensity_apply /-
 protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) :=
   by
@@ -71,13 +76,17 @@ protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
   rw [with_density, dif_pos hf]
   rfl
 #align probability_theory.kernel.with_density_apply ProbabilityTheory.kernel.withDensity_apply
+-/
 
+#print ProbabilityTheory.kernel.withDensity_apply' /-
 theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) {s : Set β} (hs : MeasurableSet s) :
     withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by
   rw [kernel.with_density_apply κ hf, with_density_apply _ hs]
 #align probability_theory.kernel.with_density_apply' ProbabilityTheory.kernel.withDensity_apply'
+-/
 
+#print ProbabilityTheory.kernel.lintegral_withDensity /-
 theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
     ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a :=
@@ -86,7 +95,9 @@ theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     lintegral_with_density_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg]
   simp_rw [Pi.mul_apply]
 #align probability_theory.kernel.lintegral_with_density ProbabilityTheory.kernel.lintegral_withDensity
+-/
 
+#print ProbabilityTheory.kernel.integral_withDensity /-
 theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
     {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
     (hg : Measurable (Function.uncurry g)) :
@@ -96,7 +107,9 @@ theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace 
   · exact Measurable.of_uncurry_left hg
   · exact measurable_coe_nnreal_ennreal.comp hg
 #align probability_theory.kernel.integral_with_density ProbabilityTheory.kernel.integral_withDensity
+-/
 
+#print ProbabilityTheory.kernel.withDensity_add_left /-
 theorem withDensity_add_left (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η]
     (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f :=
   by
@@ -107,7 +120,9 @@ theorem withDensity_add_left (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFin
   · simp_rw [with_density_of_not_measurable _ hf]
     rw [zero_add]
 #align probability_theory.kernel.with_density_add_left ProbabilityTheory.kernel.withDensity_add_left
+-/
 
+#print ProbabilityTheory.kernel.withDensity_kernel_sum /-
 theorem withDensity_kernel_sum [Countable ι] (κ : ι → kernel α β) (hκ : ∀ i, IsSFiniteKernel (κ i))
     (f : α → β → ℝ≥0∞) :
     @withDensity _ _ _ _ (kernel.sum κ) (isSFiniteKernel_sum hκ) f =
@@ -120,7 +135,9 @@ theorem withDensity_kernel_sum [Countable ι] (κ : ι → kernel α β) (hκ :
   · simp_rw [with_density_of_not_measurable _ hf]
     exact sum_zero.symm
 #align probability_theory.kernel.with_density_kernel_sum ProbabilityTheory.kernel.withDensity_kernel_sum
+-/
 
+#print ProbabilityTheory.kernel.withDensity_tsum /-
 theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ] {f : ι → α → β → ℝ≥0∞}
     (hf : ∀ i, Measurable (Function.uncurry (f i))) :
     withDensity κ (∑' n, f n) = kernel.sum fun n => withDensity κ (f n) :=
@@ -146,7 +163,9 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
   congr with n
   rw [with_density_apply' _ (hf n) a hs]
 #align probability_theory.kernel.with_density_tsum ProbabilityTheory.kernel.withDensity_tsum
+-/
 
+#print ProbabilityTheory.kernel.isFiniteKernel_withDensity_of_bounded /-
 /-- If a kernel `κ` is finite and a function `f : α → β → ℝ≥0∞` is bounded, then `with_density κ f`
 is finite. -/
 theorem isFiniteKernel_withDensity_of_bounded (κ : kernel α β) [IsFiniteKernel κ] {B : ℝ≥0∞}
@@ -166,7 +185,9 @@ theorem isFiniteKernel_withDensity_of_bounded (κ : kernel α β) [IsFiniteKerne
   · rw [with_density_of_not_measurable _ hf]
     infer_instance
 #align probability_theory.kernel.is_finite_kernel_with_density_of_bounded ProbabilityTheory.kernel.isFiniteKernel_withDensity_of_bounded
+-/
 
+#print ProbabilityTheory.kernel.isSFiniteKernel_withDensity_of_isFiniteKernel /-
 /-- Auxiliary lemma for `is_s_finite_kernel_with_density`.
 If a kernel `κ` is finite, then `with_density κ f` is s-finite. -/
 theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFiniteKernel κ]
@@ -237,7 +258,9 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     _ ≤ n + 1 := (min_le_right _ _)
     _ = ↑(n + 1) := by norm_cast
 #align probability_theory.kernel.is_s_finite_kernel_with_density_of_is_finite_kernel ProbabilityTheory.kernel.isSFiniteKernel_withDensity_of_isFiniteKernel
+-/
 
+#print ProbabilityTheory.kernel.IsSFiniteKernel.withDensity /-
 /-- For a s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite,
 `with_density κ f` is s-finite. -/
 theorem IsSFiniteKernel.withDensity (κ : kernel α β) [IsSFiniteKernel κ]
@@ -253,6 +276,7 @@ theorem IsSFiniteKernel.withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     is_s_finite_kernel_sum fun n =>
       is_s_finite_kernel_with_density_of_is_finite_kernel (seq κ n) hf_ne_top
 #align probability_theory.kernel.is_s_finite_kernel.with_density ProbabilityTheory.kernel.IsSFiniteKernel.withDensity
+-/
 
 /-- For a s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `with_density κ f` is s-finite. -/
 instance (κ : kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) :
Diff
@@ -42,8 +42,6 @@ namespace ProbabilityTheory.kernel
 
 variable {α β ι : Type _} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
 
-include mα mβ
-
 variable {κ : kernel α β} {f : α → β → ℝ≥0∞}
 
 /-- Kernel with image `(κ a).with_density (f a)` if `function.uncurry f` is measurable, and
Diff
@@ -82,7 +82,7 @@ theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
 
 theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
-    (∫⁻ b, g b ∂withDensity κ f a) = ∫⁻ b, f a b * g b ∂κ a :=
+    ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a :=
   by
   rw [kernel.with_density_apply _ hf,
     lintegral_with_density_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg]
@@ -92,7 +92,7 @@ theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
 theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
     {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
     (hg : Measurable (Function.uncurry g)) :
-    (∫ b, f b ∂withDensity κ (fun a b => g a b) a) = ∫ b, g a b • f b ∂κ a :=
+    ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a :=
   by
   rw [kernel.with_density_apply, integral_withDensity_eq_integral_smul]
   · exact Measurable.of_uncurry_left hg
@@ -140,7 +140,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
       exact pi.summable.mpr fun p => ENNReal.summable
     rw [this]
     exact Measurable.ennreal_tsum' hf
-  have : (∫⁻ b in s, (∑' n, f n) a b ∂κ a) = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a :=
+  have : ∫⁻ b in s, (∑' n, f n) a b ∂κ a = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a :=
     by
     congr with b
     rw [tsum_apply h_sum, tsum_apply (h_sum_a a)]
@@ -161,7 +161,7 @@ theorem isFiniteKernel_withDensity_of_bounded (κ : kernel α β) [IsFiniteKerne
           fun a => by
           rw [with_density_apply' κ hf a MeasurableSet.univ]
           calc
-            (∫⁻ b in Set.univ, f a b ∂κ a) ≤ ∫⁻ b in Set.univ, B ∂κ a := lintegral_mono (hf_B a)
+            ∫⁻ b in Set.univ, f a b ∂κ a ≤ ∫⁻ b in Set.univ, B ∂κ a := lintegral_mono (hf_B a)
             _ = B * κ a Set.univ := by
               simp only [measure.restrict_univ, MeasureTheory.lintegral_const]
             _ ≤ B * is_finite_kernel.bound κ := mul_le_mul_left' (measure_le_bound κ a Set.univ) _⟩⟩
@@ -211,7 +211,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     ext (a b) : 2
     rw [tsum_apply (pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
       ENNReal.tsum_eq_liminf_sum_nat]
-    have h_finset_sum : ∀ n, (∑ i in Finset.range n, fs i a b) = min (f a b) n :=
+    have h_finset_sum : ∀ n, ∑ i in Finset.range n, fs i a b = min (f a b) n :=
       by
       intro n
       induction' n with n hn
Diff
@@ -164,8 +164,7 @@ theorem isFiniteKernel_withDensity_of_bounded (κ : kernel α β) [IsFiniteKerne
             (∫⁻ b in Set.univ, f a b ∂κ a) ≤ ∫⁻ b in Set.univ, B ∂κ a := lintegral_mono (hf_B a)
             _ = B * κ a Set.univ := by
               simp only [measure.restrict_univ, MeasureTheory.lintegral_const]
-            _ ≤ B * is_finite_kernel.bound κ := mul_le_mul_left' (measure_le_bound κ a Set.univ) _
-            ⟩⟩
+            _ ≤ B * is_finite_kernel.bound κ := mul_le_mul_left' (measure_le_bound κ a Set.univ) _⟩⟩
   · rw [with_density_of_not_measurable _ hf]
     infer_instance
 #align probability_theory.kernel.is_finite_kernel_with_density_of_bounded ProbabilityTheory.kernel.isFiniteKernel_withDensity_of_bounded
@@ -239,7 +238,6 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     fs n a b ≤ min (f a b) (n + 1) := tsub_le_self
     _ ≤ n + 1 := (min_le_right _ _)
     _ = ↑(n + 1) := by norm_cast
-    
 #align probability_theory.kernel.is_s_finite_kernel_with_density_of_is_finite_kernel ProbabilityTheory.kernel.isSFiniteKernel_withDensity_of_isFiniteKernel
 
 /-- For a s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite,
Diff
@@ -70,8 +70,8 @@ protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) :=
   by
   classical
-    rw [with_density, dif_pos hf]
-    rfl
+  rw [with_density, dif_pos hf]
+  rfl
 #align probability_theory.kernel.with_density_apply ProbabilityTheory.kernel.withDensity_apply
 
 theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
Diff
@@ -186,7 +186,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     by
     intro a b n hn
     have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn
-    rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this
+    rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this 
     · refine' this.trans (le_of_eq _)
       rw [ENNReal.ofReal_coe_nat]
     · norm_cast
@@ -207,7 +207,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
       suffices : ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0
       exact summable_of_ne_finset_zero this
       intro n hn_not_mem
-      rw [Finset.mem_range, not_lt] at hn_not_mem
+      rw [Finset.mem_range, not_lt] at hn_not_mem 
       exact h_zero a b n hn_not_mem
     ext (a b) : 2
     rw [tsum_apply (pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
Diff
@@ -36,7 +36,7 @@ an s-finite kernel.
 
 open MeasureTheory ProbabilityTheory
 
-open MeasureTheory ENNReal NNReal BigOperators
+open scoped MeasureTheory ENNReal NNReal BigOperators
 
 namespace ProbabilityTheory.kernel
 
Diff
@@ -180,9 +180,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
   -- functions, and decompose an s-finite kernel as a sum of finite kernels. We then use that
   -- `with_density` commutes with sums for both arguments and get a sum of finite kernels.
   by_cases hf : Measurable (Function.uncurry f)
-  swap
-  · rw [with_density_of_not_measurable _ hf]
-    infer_instance
+  swap; · rw [with_density_of_not_measurable _ hf]; infer_instance
   let fs : ℕ → α → β → ℝ≥0∞ := fun n a b => min (f a b) (n + 1) - min (f a b) n
   have h_le : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → f a b ≤ n :=
     by
@@ -232,13 +230,9 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     rw [Filter.EventuallyEq, Filter.eventually_atTop]
     exact ⟨⌈(f a b).toReal⌉₊, fun n hn => (min_eq_left (h_le a b n hn)).symm⟩
   rw [hf_eq_tsum, with_density_tsum _ fun n : ℕ => _]
-  swap
-  · exact (hf.min measurable_const).sub (hf.min measurable_const)
+  swap; · exact (hf.min measurable_const).sub (hf.min measurable_const)
   refine' is_s_finite_kernel_sum fun n => _
-  suffices is_finite_kernel (with_density κ (fs n))
-    by
-    haveI := this
-    infer_instance
+  suffices is_finite_kernel (with_density κ (fs n)) by haveI := this; infer_instance
   refine' is_finite_kernel_with_density_of_bounded _ (ENNReal.coe_ne_top : ↑n + 1 ≠ ∞) fun a b => _
   norm_cast
   calc
Diff
@@ -4,11 +4,12 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
 
 ! This file was ported from Lean 3 source module probability.kernel.with_density
-! leanprover-community/mathlib commit 28b2a92f2996d28e580450863c130955de0ed398
+! leanprover-community/mathlib commit c0d694db494dd4f9aa57f2714b6e4c82b4ebc113
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
 import Mathbin.Probability.Kernel.MeasurableIntegral
+import Mathbin.MeasureTheory.Integral.SetIntegral
 
 /-!
 # With Density
@@ -88,6 +89,16 @@ theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
   simp_rw [Pi.mul_apply]
 #align probability_theory.kernel.lintegral_with_density ProbabilityTheory.kernel.lintegral_withDensity
 
+theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
+    {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
+    (hg : Measurable (Function.uncurry g)) :
+    (∫ b, f b ∂withDensity κ (fun a b => g a b) a) = ∫ b, g a b • f b ∂κ a :=
+  by
+  rw [kernel.with_density_apply, integral_withDensity_eq_integral_smul]
+  · exact Measurable.of_uncurry_left hg
+  · exact measurable_coe_nnreal_ennreal.comp hg
+#align probability_theory.kernel.integral_with_density ProbabilityTheory.kernel.integral_withDensity
+
 theorem withDensity_add_left (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η]
     (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f :=
   by
Diff
@@ -128,7 +128,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
       rw [tsum_apply h_sum, tsum_apply (h_sum_a _), tsum_apply]
       exact pi.summable.mpr fun p => ENNReal.summable
     rw [this]
-    exact Measurable.eNNReal_tsum' hf
+    exact Measurable.ennreal_tsum' hf
   have : (∫⁻ b in s, (∑' n, f n) a b ∂κ a) = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a :=
     by
     congr with b
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
 
 ! This file was ported from Lean 3 source module probability.kernel.with_density
-! leanprover-community/mathlib commit 483dd86cfec4a1380d22b1f6acd4c3dc53f501ff
+! leanprover-community/mathlib commit 28b2a92f2996d28e580450863c130955de0ed398
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -56,7 +56,7 @@ noncomputable def withDensity (κ : kernel α β) [IsSFiniteKernel κ] (f : α 
           property := by
             refine' measure.measurable_of_measurable_coe _ fun s hs => _
             simp_rw [with_density_apply _ hs]
-            exact measurable_set_lintegral κ hf hs } :
+            exact hf.set_lintegral_kernel_prod_right hs } :
         kernel α β))
     fun hf => 0
 #align probability_theory.kernel.with_density ProbabilityTheory.kernel.withDensity

Changes in mathlib4

mathlib3
mathlib4
chore: superfluous parentheses part 2 (#12131)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -260,7 +260,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
   norm_cast
   calc
     fs n a b ≤ min (f a b) (n + 1) := tsub_le_self
-    _ ≤ n + 1 := (min_le_right _ _)
+    _ ≤ n + 1 := min_le_right _ _
     _ = ↑(n + 1) := by norm_cast
 #align probability_theory.kernel.is_s_finite_kernel_with_density_of_is_finite_kernel ProbabilityTheory.kernel.isSFiniteKernel_withDensity_of_isFiniteKernel
 
chore: Rename coe_nat/coe_int/coe_rat to natCast/intCast/ratCast (#11499)

This is less exhaustive than its sibling #11486 because edge cases are harder to classify. No fundamental difficulty, just me being a bit fast and lazy.

Reduce the diff of #11203

Diff
@@ -219,7 +219,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn
     rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this
     · refine' this.trans (le_of_eq _)
-      rw [ENNReal.ofReal_coe_nat]
+      rw [ENNReal.ofReal_natCast]
     · norm_cast
       exact zero_le _
   have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 := by
chore(*): remove empty lines between variable statements (#11418)

Empty lines were removed by executing the following Python script twice

import os
import re


# Loop through each file in the repository
for dir_path, dirs, files in os.walk('.'):
  for filename in files:
    if filename.endswith('.lean'):
      file_path = os.path.join(dir_path, filename)

      # Open the file and read its contents
      with open(file_path, 'r') as file:
        content = file.read()

      # Use a regular expression to replace sequences of "variable" lines separated by empty lines
      # with sequences without empty lines
      modified_content = re.sub(r'(variable.*\n)\n(variable(?! .* in))', r'\1\2', content)

      # Write the modified content back to the file
      with open(file_path, 'w') as file:
        file.write(modified_content)
Diff
@@ -38,7 +38,6 @@ open scoped MeasureTheory ENNReal NNReal BigOperators
 namespace ProbabilityTheory.kernel
 
 variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
-
 variable {κ : kernel α β} {f : α → β → ℝ≥0∞}
 
 /-- Kernel with image `(κ a).withDensity (f a)` if `Function.uncurry f` is measurable, and
chore: tidy various files (#11135)
Diff
@@ -150,7 +150,7 @@ lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞
     withDensity κ (f + g) = withDensity κ f + withDensity κ g := by
   ext a
   rw [coeFn_add, Pi.add_apply, kernel.withDensity_apply _ hf, kernel.withDensity_apply _ hg,
-    kernel.withDensity_apply,Pi.add_apply, MeasureTheory.withDensity_add_right]
+    kernel.withDensity_apply, Pi.add_apply, MeasureTheory.withDensity_add_right]
   · exact hg.comp measurable_prod_mk_left
   · exact hf.add hg
 
chore: move Mathlib to v4.7.0-rc1 (#11162)

This is a very large PR, but it has been reviewed piecemeal already in PRs to the bump/v4.7.0 branch as we update to intermediate nightlies.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Kyle Miller <kmill31415@gmail.com> Co-authored-by: damiano <adomani@gmail.com>

Diff
@@ -226,7 +226,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
   have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 := by
     intro a b n hn
     suffices min (f a b) (n + 1) = f a b ∧ min (f a b) n = f a b by
-      simp_rw [this.1, this.2, tsub_self (f a b)]
+      simp_rw [fs, this.1, this.2, tsub_self (f a b)]
     exact ⟨min_eq_left ((h_le a b n hn).trans (le_add_of_nonneg_right zero_le_one)),
       min_eq_left (h_le a b n hn)⟩
   have hf_eq_tsum : f = ∑' n, fs n := by
@@ -245,7 +245,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
       induction' n with n hn
       · simp
       rw [Finset.sum_range_succ, hn]
-      simp
+      simp [fs]
     simp_rw [h_finset_sum]
     refine' (Filter.Tendsto.liminf_eq _).symm
     refine' Filter.Tendsto.congr' _ tendsto_const_nhds
feat: lemmas about kernel.withDensity (#10799)

Add a few simp lemmas about withDensity of constant functions 1 and 0, and the 3 more interesting lemmas

  • withDensity_add_right: withDensity κ (f + g) = withDensity κ f + withDensity κ g
  • withDensity_sub_add_cancel: withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f
  • withDensity_mul: withDensity κ (fun a x ↦ f a x * g a x) = withDensity (withDensity κ fun a x ↦ f a x) g

Co-authored-by: Rémy Degenne <remydegenne@gmail.com>

Diff
@@ -72,6 +72,40 @@ protected theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
   rw [kernel.withDensity_apply κ hf, withDensity_apply' _ s]
 #align probability_theory.kernel.with_density_apply' ProbabilityTheory.kernel.withDensity_apply'
 
+nonrec lemma withDensity_congr_ae (κ : kernel α β) [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
+    (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g))
+    (hfg : ∀ a, f a =ᵐ[κ a] g a) :
+    withDensity κ f = withDensity κ g := by
+  ext a
+  rw [kernel.withDensity_apply _ hf,kernel.withDensity_apply _ hg, withDensity_congr_ae (hfg a)]
+
+nonrec lemma withDensity_absolutelyContinuous [IsSFiniteKernel κ]
+    (f : α → β → ℝ≥0∞) (a : α) :
+    kernel.withDensity κ f a ≪ κ a := by
+  by_cases hf : Measurable (Function.uncurry f)
+  · rw [kernel.withDensity_apply _ hf]
+    exact withDensity_absolutelyContinuous _ _
+  · rw [withDensity_of_not_measurable _ hf]
+    simp [Measure.AbsolutelyContinuous.zero]
+
+@[simp]
+lemma withDensity_one (κ : kernel α β) [IsSFiniteKernel κ] :
+    kernel.withDensity κ 1 = κ := by
+  ext; rw [kernel.withDensity_apply _ measurable_const]; simp
+
+@[simp]
+lemma withDensity_one' (κ : kernel α β) [IsSFiniteKernel κ] :
+    kernel.withDensity κ (fun _ _ ↦ 1) = κ := kernel.withDensity_one _
+
+@[simp]
+lemma withDensity_zero (κ : kernel α β) [IsSFiniteKernel κ] :
+    kernel.withDensity κ 0 = 0 := by
+  ext; rw [kernel.withDensity_apply _ measurable_const]; simp
+
+@[simp]
+lemma withDensity_zero' (κ : kernel α β) [IsSFiniteKernel κ] :
+    kernel.withDensity κ (fun _ _ ↦ 0) = 0 := kernel.withDensity_zero _
+
 theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
     ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a := by
@@ -111,6 +145,25 @@ theorem withDensity_kernel_sum [Countable ι] (κ : ι → kernel α β) (hκ :
     exact sum_zero.symm
 #align probability_theory.kernel.with_density_kernel_sum ProbabilityTheory.kernel.withDensity_kernel_sum
 
+lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
+    (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) :
+    withDensity κ (f + g) = withDensity κ f + withDensity κ g := by
+  ext a
+  rw [coeFn_add, Pi.add_apply, kernel.withDensity_apply _ hf, kernel.withDensity_apply _ hg,
+    kernel.withDensity_apply,Pi.add_apply, MeasureTheory.withDensity_add_right]
+  · exact hg.comp measurable_prod_mk_left
+  · exact hf.add hg
+
+lemma withDensity_sub_add_cancel [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
+    (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g))
+    (hfg : ∀ a, g a ≤ᵐ[κ a] f a) :
+    withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f := by
+  rw [← withDensity_add_right _ hg]
+  swap; · exact hf.sub hg
+  refine withDensity_congr_ae κ ((hf.sub hg).add hg) hf (fun a ↦ ?_)
+  filter_upwards [hfg a] with x hx
+  rwa [Pi.add_apply, Pi.add_apply, tsub_add_cancel_iff_le]
+
 theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ] {f : ι → α → β → ℝ≥0∞}
     (hf : ∀ i, Measurable (Function.uncurry (f i))) :
     withDensity κ (∑' n, f n) = kernel.sum fun n => withDensity κ (f n) := by
@@ -230,4 +283,20 @@ instance (κ : kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) :
     IsSFiniteKernel (withDensity κ fun a b => f a b) :=
   IsSFiniteKernel.withDensity κ fun _ _ => ENNReal.coe_ne_top
 
+nonrec lemma withDensity_mul [IsSFiniteKernel κ] {f : α → β → ℝ≥0} {g : α → β → ℝ≥0∞}
+    (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) :
+    withDensity κ (fun a x ↦ f a x * g a x)
+      = withDensity (withDensity κ fun a x ↦ f a x) g := by
+  ext a : 1
+  rw [kernel.withDensity_apply]
+  swap; · exact (measurable_coe_nnreal_ennreal.comp hf).mul hg
+  change (Measure.withDensity (κ a) ((fun x ↦ (f a x : ℝ≥0∞)) * (fun x ↦ (g a x : ℝ≥0∞)))) =
+      (withDensity (withDensity κ fun a x ↦ f a x) g) a
+  rw [withDensity_mul]
+  · rw [kernel.withDensity_apply _ hg, kernel.withDensity_apply]
+    exact measurable_coe_nnreal_ennreal.comp hf
+  · rw [measurable_coe_nnreal_ennreal_iff]
+    exact hf.comp measurable_prod_mk_left
+  · exact hg.comp measurable_prod_mk_left
+
 end ProbabilityTheory.kernel
chore: remove stream-of-consciousness uses of have, replace and suffices (#10640)

No changes to tactic file, it's just boring fixes throughout the library.

This follows on from #6964.

Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -179,8 +179,8 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
   have hf_eq_tsum : f = ∑' n, fs n := by
     have h_sum_a : ∀ a, Summable fun n => fs n a := by
       refine' fun a => Pi.summable.mpr fun b => _
-      suffices : ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0
-      exact summable_of_ne_finset_zero this
+      suffices ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0 from
+        summable_of_ne_finset_zero this
       intro n hn_not_mem
       rw [Finset.mem_range, not_lt] at hn_not_mem
       exact h_zero a b n hn_not_mem
feat: generalize some lemmas using withDensity_apply' (#8383)

@sgouezel added a version of withDensity_apply that does not require measurability of the set if the measure is s-finite. This PR uses that result in other files of the library.

For results about rnDeriv, I put a prime on the version that assumes measurability of the set and no prime on the version for s-finite measures, as the second one should be the main use case.

Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr> Co-authored-by: RemyDegenne <Remydegenne@gmail.com>

Diff
@@ -66,10 +66,10 @@ protected theorem withDensity_apply (κ : kernel α β) [IsSFiniteKernel κ]
   rfl
 #align probability_theory.kernel.with_density_apply ProbabilityTheory.kernel.withDensity_apply
 
-theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
-    (hf : Measurable (Function.uncurry f)) (a : α) {s : Set β} (hs : MeasurableSet s) :
+protected theorem withDensity_apply' (κ : kernel α β) [IsSFiniteKernel κ]
+    (hf : Measurable (Function.uncurry f)) (a : α) (s : Set β) :
     withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by
-  rw [kernel.withDensity_apply κ hf, withDensity_apply _ hs]
+  rw [kernel.withDensity_apply κ hf, withDensity_apply' _ s]
 #align probability_theory.kernel.with_density_apply' ProbabilityTheory.kernel.withDensity_apply'
 
 theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
@@ -117,7 +117,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
   have h_sum_a : ∀ a, Summable fun n => f n a := fun a => Pi.summable.mpr fun b => ENNReal.summable
   have h_sum : Summable fun n => f n := Pi.summable.mpr h_sum_a
   ext a s hs
-  rw [sum_apply' _ a hs, withDensity_apply' κ _ a hs]
+  rw [sum_apply' _ a hs, kernel.withDensity_apply' κ _ a s]
   swap
   · have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) := by
       ext1 p
@@ -131,7 +131,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
     rw [tsum_apply h_sum, tsum_apply (h_sum_a a)]
   rw [this, lintegral_tsum fun n => (Measurable.of_uncurry_left (hf n)).aemeasurable]
   congr with n
-  rw [withDensity_apply' _ (hf n) a hs]
+  rw [kernel.withDensity_apply' _ (hf n) a s]
 #align probability_theory.kernel.with_density_tsum ProbabilityTheory.kernel.withDensity_tsum
 
 /-- If a kernel `κ` is finite and a function `f : α → β → ℝ≥0∞` is bounded, then `withDensity κ f`
@@ -141,7 +141,7 @@ theorem isFiniteKernel_withDensity_of_bounded (κ : kernel α β) [IsFiniteKerne
   by_cases hf : Measurable (Function.uncurry f)
   · exact ⟨⟨B * IsFiniteKernel.bound κ, ENNReal.mul_lt_top hB_top (IsFiniteKernel.bound_ne_top κ),
       fun a => by
-        rw [withDensity_apply' κ hf a MeasurableSet.univ]
+        rw [kernel.withDensity_apply' κ hf a Set.univ]
         calc
           ∫⁻ b in Set.univ, f a b ∂κ a ≤ ∫⁻ _ in Set.univ, B ∂κ a := lintegral_mono (hf_B a)
           _ = B * κ a Set.univ := by
chore: bump toolchain to v4.3.0-rc1 (#8051)

This incorporates changes from

  • #7845
  • #7847
  • #7853
  • #7872 (was never actually made to work, but the diffs in nightly-testing are unexciting: we need to fully qualify a few names)

They can all be closed when this is merged.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -203,6 +203,8 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
   refine' isSFiniteKernel_sum fun n => _
   suffices IsFiniteKernel (withDensity κ (fs n)) by haveI := this; infer_instance
   refine' isFiniteKernel_withDensity_of_bounded _ (ENNReal.coe_ne_top : ↑n + 1 ≠ ∞) fun a b => _
+  -- After leanprover/lean4#2734, we need to do beta reduction before `norm_cast`
+  beta_reduce
   norm_cast
   calc
     fs n a b ≤ min (f a b) (n + 1) := tsub_le_self
feat: drop more CompleteSpace assumptions (#7691)

Also add completeSpace_prod, integrable_prod.

Diff
@@ -80,7 +80,7 @@ theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
   simp_rw [Pi.mul_apply]
 #align probability_theory.kernel.lintegral_with_density ProbabilityTheory.kernel.lintegral_withDensity
 
-theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
+theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
     {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
     (hg : Measurable (Function.uncurry g)) :
     ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -37,7 +37,7 @@ open scoped MeasureTheory ENNReal NNReal BigOperators
 
 namespace ProbabilityTheory.kernel
 
-variable {α β ι : Type _} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
+variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
 
 variable {κ : kernel α β} {f : α → β → ℝ≥0∞}
 
@@ -80,7 +80,7 @@ theorem lintegral_withDensity (κ : kernel α β) [IsSFiniteKernel κ]
   simp_rw [Pi.mul_apply]
 #align probability_theory.kernel.lintegral_with_density ProbabilityTheory.kernel.lintegral_withDensity
 
-theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
+theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
     {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
     (hg : Measurable (Function.uncurry g)) :
     ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,15 +2,12 @@
 Copyright (c) 2023 Rémy Degenne. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Rémy Degenne
-
-! This file was ported from Lean 3 source module probability.kernel.with_density
-! leanprover-community/mathlib commit c0d694db494dd4f9aa57f2714b6e4c82b4ebc113
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Probability.Kernel.MeasurableIntegral
 import Mathlib.MeasureTheory.Integral.SetIntegral
 
+#align_import probability.kernel.with_density from "leanprover-community/mathlib"@"c0d694db494dd4f9aa57f2714b6e4c82b4ebc113"
+
 /-!
 # With Density
 
chore: fix grammar in docs (#5668)
Diff
@@ -213,7 +213,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
     _ = ↑(n + 1) := by norm_cast
 #align probability_theory.kernel.is_s_finite_kernel_with_density_of_is_finite_kernel ProbabilityTheory.kernel.isSFiniteKernel_withDensity_of_isFiniteKernel
 
-/-- For a s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite,
+/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite,
 `withDensity κ f` is s-finite. -/
 nonrec theorem IsSFiniteKernel.withDensity (κ : kernel α β) [IsSFiniteKernel κ]
     (hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by
@@ -226,7 +226,7 @@ nonrec theorem IsSFiniteKernel.withDensity (κ : kernel α β) [IsSFiniteKernel
     isSFiniteKernel_withDensity_of_isFiniteKernel (seq κ n) hf_ne_top
 #align probability_theory.kernel.is_s_finite_kernel.with_density ProbabilityTheory.kernel.IsSFiniteKernel.withDensity
 
-/-- For a s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `withDensity κ f` is s-finite. -/
+/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `withDensity κ f` is s-finite. -/
 instance (κ : kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) :
     IsSFiniteKernel (withDensity κ fun a b => f a b) :=
   IsSFiniteKernel.withDensity κ fun _ _ => ENNReal.coe_ne_top
chore: remove superfluous parentheses in calls to ext (#5258)

Co-authored-by: Xavier Roblot <46200072+xroblot@users.noreply.github.com> Co-authored-by: Joël Riou <joel.riou@universite-paris-saclay.fr> Co-authored-by: Riccardo Brasca <riccardo.brasca@gmail.com> Co-authored-by: Yury G. Kudryashov <urkud@urkud.name> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Jeremy Tan Jie Rui <reddeloostw@gmail.com> Co-authored-by: Pol'tta / Miyahara Kō <pol_tta@outlook.jp> Co-authored-by: Jason Yuen <jason_yuen2007@hotmail.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com> Co-authored-by: Jireh Loreaux <loreaujy@gmail.com> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com> Co-authored-by: Kyle Miller <kmill31415@gmail.com> Co-authored-by: Heather Macbeth <25316162+hrmacbeth@users.noreply.github.com> Co-authored-by: Jujian Zhang <jujian.zhang1998@outlook.com> Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>

Diff
@@ -187,7 +187,7 @@ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : kernel α β) [IsFin
       intro n hn_not_mem
       rw [Finset.mem_range, not_lt] at hn_not_mem
       exact h_zero a b n hn_not_mem
-    ext (a b) : 2
+    ext a b : 2
     rw [tsum_apply (Pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
       ENNReal.tsum_eq_liminf_sum_nat]
     have h_finset_sum : ∀ n, ∑ i in Finset.range n, fs i a b = min (f a b) n := by
chore: bump Std4 (#5219)

Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -95,7 +95,7 @@ theorem integral_withDensity {E : Type _} [NormedAddCommGroup E] [NormedSpace 
 theorem withDensity_add_left (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η]
     (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f := by
   by_cases hf : Measurable (Function.uncurry f)
-  · ext (a s); intro
+  · ext a s
     simp only [kernel.withDensity_apply _ hf, coeFn_add, Pi.add_apply, withDensity_add_measure,
       Measure.add_apply]
   · simp_rw [withDensity_of_not_measurable _ hf]
@@ -119,7 +119,7 @@ theorem withDensity_tsum [Countable ι] (κ : kernel α β) [IsSFiniteKernel κ]
     withDensity κ (∑' n, f n) = kernel.sum fun n => withDensity κ (f n) := by
   have h_sum_a : ∀ a, Summable fun n => f n a := fun a => Pi.summable.mpr fun b => ENNReal.summable
   have h_sum : Summable fun n => f n := Pi.summable.mpr h_sum_a
-  ext (a s); intro hs
+  ext a s hs
   rw [sum_apply' _ a hs, withDensity_apply' κ _ a hs]
   swap
   · have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) := by
feat: port Probability.Kernel.WithDensity (#5027)

Dependencies 12 + 945

946 files ported (98.7%)
433472 lines ported (98.7%)
Show graph

The unported dependencies are

The following 1 dependencies have changed in mathlib3 since they were ported, which may complicate porting this file