Skip to content

Commit c18ef68

Browse files
DavidLedvinkaDavid Ledvinka
andcommitted
feat(Probability): Add Cauchy distribution (leanprover-community#33860)
Co-authored-by: David Ledvinka <dledvinka.ledvinka@mail.utoronto.ca>
1 parent d048652 commit c18ef68

2 files changed

Lines changed: 141 additions & 0 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,6 +5830,7 @@ public import Mathlib.Probability.Decision.Risk.Basic
58305830
public import Mathlib.Probability.Decision.Risk.Defs
58315831
public import Mathlib.Probability.Density
58325832
public import Mathlib.Probability.Distributions.Beta
5833+
public import Mathlib.Probability.Distributions.Cauchy
58335834
public import Mathlib.Probability.Distributions.Exponential
58345835
public import Mathlib.Probability.Distributions.Fernique
58355836
public import Mathlib.Probability.Distributions.Gamma
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/-
2+
Copyright (c) 2026 David Ledvinka. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: David Ledvinka
5+
-/
6+
module
7+
8+
public import Mathlib.MeasureTheory.Integral.Bochner.Basic
9+
public import Mathlib.MeasureTheory.Measure.Haar.OfBasis
10+
11+
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
12+
13+
/-! # Cauchy Distribution over ℝ
14+
15+
Define the Cauchy distribution with location parameter `x₀` and scale parameter `γ`.
16+
17+
Note that we use "location" and "scale" to refer to these parameters in theorem names.
18+
19+
## Main definition
20+
21+
* `cauchyPDFReal`: the function `x₀ γ x ↦ π⁻¹ * γ * ((x - x₀) ^ 2 + γ ^ 2)⁻¹`,
22+
which is the probability density function of a Cauchy distribution with location parameter `x₀`
23+
and scale parameter `γ` (when `γ ≠ 0`).
24+
* `cauchyPDF`: `ℝ≥0∞`-valued pdf, `cauchyPDF μ v x = ENNReal.ofReal (cauchyPDFReal μ v x)`.
25+
* `cauchyMeasure`: a Cauchy measure on `ℝ`, parametrized by a location parameter `x₀ : ℝ` and a
26+
scale parameter `γ : ℝ≥0`. If `γ = 0`, this is `dirac x₀`, otherwise it is defined as the
27+
measure with density `cauchyPDF x₀ γ` with respect to the Lebesgue measure.
28+
29+
-/
30+
31+
@[expose] public section
32+
33+
open scoped Real ENNReal NNReal
34+
35+
open MeasureTheory Measure
36+
37+
namespace Probability
38+
39+
section CauchyPDF
40+
41+
/-- The pdf of the cauchy distribution depending on its location `x₀` and scale `γ` parameters. -/
42+
noncomputable def cauchyPDFReal (x₀ : ℝ) (γ : ℝ≥0) (x : ℝ) : ℝ :=
43+
π⁻¹ * γ * ((x - x₀) ^ 2 + γ ^ 2)⁻¹
44+
45+
@[simp]
46+
lemma cauchyPDFReal_scale_zero (x₀ : ℝ) : cauchyPDFReal x₀ 0 = 0 := by
47+
ext
48+
simp [cauchyPDFReal]
49+
50+
lemma cauchyPDFReal_def (x₀ : ℝ) (γ : ℝ≥0) (x : ℝ) :
51+
cauchyPDFReal x₀ γ x = π⁻¹ * γ * ((x - x₀) ^ 2 + γ ^ 2)⁻¹ := by rfl
52+
53+
lemma cauchyPDFReal_def' (x₀ : ℝ) (γ : ℝ≥0) (x : ℝ) :
54+
cauchyPDFReal x₀ γ x = π⁻¹ * γ⁻¹ * (1 + ((x - x₀) / γ) ^ 2)⁻¹ := by
55+
rw [cauchyPDFReal_def]
56+
by_cases h : γ = 0
57+
· simp [h]
58+
simp
59+
field
60+
61+
/-- The pdf of the gamma distribution, as a function valued in `ℝ≥0∞`. -/
62+
noncomputable def cauchyPDF (x₀ : ℝ) (γ : ℝ≥0) (x : ℝ) : ℝ≥0∞ :=
63+
ENNReal.ofReal (cauchyPDFReal x₀ γ x)
64+
65+
@[simp]
66+
lemma cauchyPDF_scale_zero (x₀ : ℝ) : cauchyPDF x₀ 0 = 0 := by
67+
ext
68+
simp [cauchyPDF]
69+
70+
lemma cauchyPDF_def (x₀ : ℝ) (γ : ℝ≥0) (x : ℝ) :
71+
cauchyPDF x₀ γ x = ENNReal.ofReal (cauchyPDFReal x₀ γ x) := by rfl
72+
73+
@[fun_prop]
74+
lemma measurable_cauchyPDFReal (x₀ : ℝ) (γ : ℝ≥0) : Measurable (cauchyPDFReal x₀ γ) := by
75+
unfold cauchyPDFReal
76+
fun_prop
77+
78+
@[fun_prop]
79+
lemma stronglyMeasurable_cauchyPDFReal (x₀ : ℝ) (γ : ℝ≥0) :
80+
StronglyMeasurable (cauchyPDFReal x₀ γ) := by fun_prop
81+
82+
@[fun_prop]
83+
lemma measurable_cauchyPDF (x₀ : ℝ) (γ : ℝ≥0) : Measurable (cauchyPDF x₀ γ) := by
84+
unfold cauchyPDF
85+
fun_prop
86+
87+
@[fun_prop]
88+
lemma stronglyMeasurable_cauchyPDF (x₀ : ℝ) (γ : ℝ≥0) :
89+
StronglyMeasurable (cauchyPDF x₀ γ) := by fun_prop
90+
91+
/-- `cauchyPDFReal` is positive for `γ > 0`. -/
92+
lemma cauchyPDF_pos (x₀ : ℝ) {γ : ℝ≥0} (hγ : γ ≠ 0) (x : ℝ) : 0 < cauchyPDFReal x₀ γ x := by
93+
rw [cauchyPDFReal_def]
94+
positivity
95+
96+
lemma integral_cauchyPDFReal (x₀ : ℝ) {γ : ℝ≥0} (hγ : γ ≠ 0) :
97+
∫ x, cauchyPDFReal x₀ γ x = 1 := by
98+
simp [cauchyPDFReal_def', NNReal.coe_inv, integral_const_mul,
99+
integral_sub_right_eq_self (f := fun x : ℝ ↦ (1 + (x / ↑γ) ^ 2)⁻¹),
100+
integral_comp_div (g := fun x : ℝ ↦ (1 + x ^ 2)⁻¹)]
101+
field
102+
103+
@[fun_prop]
104+
lemma integrable_cauchyPDFReal (x₀ : ℝ) {γ : ℝ≥0} :
105+
Integrable (cauchyPDFReal x₀ γ) := by
106+
by_cases! h : γ = 0
107+
· simp only [h, cauchyPDFReal_scale_zero]
108+
exact integrable_zero _ _ _
109+
apply Integrable.of_integral_ne_zero
110+
simp [h, integral_cauchyPDFReal]
111+
112+
/-- The pdf of the cauchy distribution integrates to 1. -/
113+
@[simp]
114+
lemma lintegral_cauchyPDF_eq_one (x₀ : ℝ) {γ : ℝ≥0} (hγ : γ ≠ 0) :
115+
∫⁻ x, cauchyPDF x₀ γ x = 1 := by
116+
unfold cauchyPDF
117+
rw [← ENNReal.toReal_eq_one_iff, ← integral_eq_lintegral_of_nonneg_ae
118+
(ae_of_all _ fun x ↦ (cauchyPDF_pos x₀ hγ x).le) (by fun_prop), integral_cauchyPDFReal x₀ hγ]
119+
120+
end CauchyPDF
121+
122+
section CauchyMeasure
123+
124+
/-- A Cauchy distribution on `ℝ` with location parameter `x₀` and scale parameter `γ`. -/
125+
noncomputable def cauchyMeasure (x₀ : ℝ) (γ : ℝ≥0) : Measure ℝ :=
126+
if γ = 0 then dirac x₀ else volume.withDensity (cauchyPDF x₀ γ)
127+
128+
lemma cauchyMeasure_of_scale_ne_zero (x₀ : ℝ) {γ : ℝ≥0} (hγ : γ ≠ 0) :
129+
cauchyMeasure x₀ γ = volume.withDensity (cauchyPDF x₀ γ) := if_neg hγ
130+
131+
@[simp]
132+
lemma cauchyMeasure_zero_scale (x₀ : ℝ) : cauchyMeasure x₀ 0 = dirac x₀ := if_pos rfl
133+
134+
instance instIsProbabilityMeasure_cauchyMeasure (x₀ : ℝ) (γ : ℝ≥0) :
135+
IsProbabilityMeasure (cauchyMeasure x₀ γ) where
136+
measure_univ := by by_cases h : γ = 0 <;> simp [cauchyMeasure_of_scale_ne_zero, h]
137+
138+
end CauchyMeasure
139+
140+
end Probability

0 commit comments

Comments
 (0)