Quasi-Borel Spaces in Rocq

2 Probability Monad

This chapter develops the QBS probability monad \(P(X)\): the type of probability distributions on a QBS \(X\). We define the monad operations (return, bind), prove the monad laws, develop integration theory with Fubini, and establish independence and variance results.

2.1 QBS Probability Triple

Definition 75 QBS Probability
#

A QBS probability on \(X\) is a triple \((\alpha , \mu , \mathrm{proof})\) where \(\alpha \in M_X\) is a random element and \(\mu \) is a probability measure on \(\mathbb {R}\). The pushforward \(\alpha _*(\mu )\) is the induced distribution on \(X\).

Definition 76 Equivalence of Triples

Two triples \((\alpha _1, \mu _1) \sim (\alpha _2, \mu _2)\) iff they induce the same pushforward on \(\sigma _{M_X}\): \(\mu _1(\alpha _1^{-1}(U)) = \mu _2(\alpha _2^{-1}(U))\) for all \(U \in \sigma _{M_X}\).

Lemma 77 Equivalence Is an Equivalence Relation

\(\sim \) is reflexive, symmetric, and transitive.

Proof

2.2 The Probability Monad \(P(X)\)

Definition 78 Probability Monad QBS

The probability monad \(P(X)\) is a QBS on qbs_prob X, with \(\beta : \mathbb {R} \to P(X)\) random iff for all \(r\), \(\alpha _{\beta (r)} \in M_X\).

2.3 Return

Definition 79 QBS Return
#

\(\eta (x) = (\lambda r.\; x,\; \mu )\) for any probability measure \(\mu \).

Lemma 80 Return Equivalence

All returns with the same point are equivalent regardless of \(\mu \): \(\eta _{\mu _1}(x) \sim \eta _{\mu _2}(x)\).

Proof
Lemma 81 Return Is a Morphism

\(\eta ^{\mu } : X \to P(X)\) is a QBS morphism.

Proof

2.4 Bind

Definition 82 Strong Morphism

A function \(f : X \to P(Y)\) is a strong morphism if for every random \(\alpha \in M_X\), the composition \(f \circ \alpha \) is random in \(P(Y)\) (in the strong sense: sharing a single underlying \(\alpha _Y\)).

Definition 83 QBS Bind

Given \(p = (\alpha , \mu )\) on \(X\) and \(f : X \to P(Y)\), the bind \(p \mathbin {{\gt}\! \! {\gt}\! \! =} f\) is \((\lambda r.\; \alpha _{f(\alpha (r))}(r),\; \mu )\). The key obligation is that the diagonal \(r \mapsto \alpha _{f(\alpha (r))}(r)\) is random in \(Y\).

Definition 84 QBS Bind (Strong)

Specialized bind that uses the strong morphism proof to discharge the diagonal obligation.

2.5 Monad Laws

Theorem 85 Left Unit

\(\eta (x) \mathbin {{\gt}\! \! {\gt}\! \! =} f \sim f(x)\).

Proof
Theorem 86 Right Unit

\(m \mathbin {{\gt}\! \! {\gt}\! \! =} \eta \sim m\).

Proof
Theorem 87 Associativity

\((m \mathbin {{\gt}\! \! {\gt}\! \! =} f) \mathbin {{\gt}\! \! {\gt}\! \! =} g \sim m \mathbin {{\gt}\! \! {\gt}\! \! =} (\lambda x.\; f(x) \mathbin {{\gt}\! \! {\gt}\! \! =} g)\).

Proof

2.6 Integration

Definition 88 QBS Integration
#

For \(p = (\alpha , \mu )\) on \(X\) and \(h : X \to \bar{\mathbb {R}}\),

\[ \int _p h \; =\; \int _\mu h(\alpha (r))\, d\mu (r). \]
Definition 89 QBS Measurability
#

A function \(h : X \to \bar{\mathbb {R}}\) is QBS measurable if for every \(\alpha \in M_X\), \(h \circ \alpha \) is Borel measurable.

Lemma 90 Measurability and Sigma-Algebra

If \(h\) is QBS measurable and \(V\) is Borel measurable, then \(h^{-1}(V) \in \sigma _{M_X}\).

Proof
Lemma 91 Integration Respects Equivalence

If \(p_1 \sim p_2\) and \(h\) is QBS measurable, then \(\int _{p_1} h = \int _{p_2} h\).

Proof
Lemma 92 Integration of Constants

\(\int _p c = c\) for any constant \(c\).

Proof
Lemma 93 Integration Against Return

\(\int _{\eta (x)} h = h(x)\).

Proof
Lemma 94 Integration Against Bind

\(\int _{m \mathbin {{\gt}\! \! {\gt}\! \! =} f} h = \int _m (\lambda x.\; h(\alpha _{f(\alpha (r))}(r)))\).

Proof

2.7 Pushforward Infrastructure

Lemma 95 Integral as Pushforward

\(\int _p h = \int _{\mathrm{pushforward}(\mu , h \circ \alpha )} \mathrm{id}\).

Proof
Lemma 96 Pushforward Integrability

Integrability transfers through the pushforward.

Proof
Lemma 97 Pushforward Agreement

Equivalent triples yield the same pushforward through a QBS measurable function.

Proof

2.8 Functorial Map

Definition 98 Monad Map

For a QBS morphism \(f : X \to Y\), the functorial map \(P(f) : P(X) \to P(Y)\) sends \((\alpha , \mu )\) to \((f \circ \alpha , \mu )\).

Lemma 99 Map Is a Morphism

\(P(f)\) is a QBS morphism \(P(X) \to P(Y)\).

Proof
Lemma 100 Map Preserves Identity

\(P(\mathrm{id})(p) \sim p\).

Proof
Lemma 101 Map Preserves Composition

\(P(g \circ f)(p) \sim P(g)(P(f)(p))\).

Proof

2.9 Expectation, Events, and Variance

Definition 102 QBS Expectation
#

\(\mathbb {E}_p[h] = \int _p (h(x))^{e}\) where \((-)^{e}\) embeds \(\mathbb {R}\) into \(\bar{\mathbb {R}}\).

Definition 103 QBS Event Probability
#

\(\Pr _p[U] = \mu (\alpha ^{-1}(U))\).

Definition 104 QBS Variance
#

\(\mathrm{Var}_p[f] = \mathrm{variance}(\mu , f \circ \alpha )\), delegating to math-comp analysis.

2.10 Integrability

Definition 105 QBS Integrability
#

A function \(h : X \to \bar{\mathbb {R}}\) is integrable against \(p\) if \(h \circ \alpha \) is integrable against \(\mu \).

Lemma 106 Integrability Closure

QBS integrability is closed under addition, subtraction, negation, and scalar multiplication.

Proof
Lemma 107 Integral Linearity

QBS integration is linear: additive, subtractive, and homogeneous.

Proof

2.11 Variance Properties

Lemma 108 Variance Decomposition

\(\mathrm{Var}[f] = \mathbb {E}[f^2] - (\mathbb {E}[f])^2\).

Proof
Lemma 109 Variance Scaling

\(\mathrm{Var}[a \cdot f] = a^2 \cdot \mathrm{Var}[f]\).

Proof
Lemma 110 Markov’s Inequality

For non-negative integrable \(f\) and \(\varepsilon {\gt} 0\): \(\Pr [f(x) \geq \varepsilon ] \leq \mathbb {E}[f] / \varepsilon \).

Proof
Lemma 111 Chebyshev’s Inequality

\(\Pr [|f(x) - \mathbb {E}[f]| \geq \varepsilon ] \leq \mathrm{Var}[f] / \varepsilon ^2\).

Proof

2.12 Monad Join

Definition 112 Monad Join

\(\mathrm{join} : P(P(X)) \to P(X)\) is defined as \(\mathrm{bind}(p, \mathrm{id})\), flattening nested probability.

Lemma 113 Join Is a Morphism

Join is a QBS morphism \(P(P(X)) \to P(X)\).

Proof

2.13 Monad Strength

Definition 114 Tensorial Strength

\(\mathrm{str}(w, p) = (\lambda r.\; (w, \alpha _p(r)),\; \mu _p)\), pairing a constant \(w : W\) with a probability \(p\) on \(X\).

Lemma 115 Strength Is a Morphism

Strength is a QBS morphism \(W \times P(X) \to P(W \times X)\).

Proof
Lemma 116 Strength Naturality

Strength commutes with morphisms: \(P(f \times g)(\mathrm{str}(w, p)) \sim \mathrm{str}(f(w), P(g)(p))\).

Proof
Lemma 117 Strength Unit Law

\(P(\pi _2)(\mathrm{str}(\mathtt{tt}, p)) \sim p\).

Proof
Lemma 118 Strength Associativity

\(P(\mathrm{assoc})(\mathrm{str}((u,v), p)) \sim \mathrm{str}(u, \mathrm{str}(v, p))\).

Proof
Lemma 119 Strength–Return Interaction

\(\mathrm{str}(w, \eta (x)) \sim \eta ((w, x))\).

Proof
Lemma 120 Bind Decomposes Through Strength and Join

\(m \mathbin {{\gt}\! \! {\gt}\! \! =} f \sim \mathrm{join}(P(f)(m))\) (modulo strength).

Proof

2.14 Bind Respects Equivalence

Lemma 121 Bind Congruence (Left)

If \(p_1 \sim p_2\) and the diagonal factors through a morphism \(g\), then \(p_1 \mathbin {{\gt}\! \! {\gt}\! \! =} f \sim p_2 \mathbin {{\gt}\! \! {\gt}\! \! =} f\).

Proof
Lemma 122 Bind Congruence (Strong)

Specialization of bind congruence for strong morphisms.

Proof
Lemma 123 Bind Congruence (Return)

Specialization of bind congruence when \(f(x) = \eta (g(x))\) for a morphism \(g\).

Proof

2.15 General Normalizer

Definition 124 Normalized Measure

Given \(p : P(X \times \mathbb {R})\) with weight function \(w(r) = \mathrm{snd}(\alpha _p(r)) \geq 0\) and evidence \(Z = \int w \, d\mu _p \in (0,+\infty )\), the normalized measure is \(\nu (A) = \int _A (w/Z) \, d\mu _p\). This is a probability measure (\(\nu (\Omega ) = 1\)).

Definition 125 Normalized Probability

Constructs \(q : P(X)\) with \(\alpha _q(r) = \mathrm{fst}(\alpha _p(r))\) and \(\mu _q = \nu \).

Definition 126 Option Normalizer
#

Returns Some(normalize_prob ...) when \(0 {\lt} Z {\lt} +\infty \), None otherwise. Uses classical decidability (boolp.pselect).

Lemma 127 Normalizer Totality

The normalized probability integrates to 1: \(\int 1 \, dq = 1\).

Proof
Lemma 128 Normalizer Integral

Conditional expectation formula: \(\mathbb {E}_{q}[g] = \mathbb {E}_{p}[g \cdot w] / Z\).

Proof

2.16 Quotient Type for QBS Probability

Definition 129 QBS Probability Space (Quotient)
#

A setoid-style quotient wrapping qbs_prob X, with equality given by qbs_prob_equiv.

Definition 130 Quotient Equality

\(p_1 =_Q p_2\) iff \(\mathrm{repr}(p_1) \sim \mathrm{repr}(p_2)\).

Lemma 131 Quotient Equivalence Relation
#

\(=_Q\) is reflexive, symmetric, and transitive.

Proof

Lifted operations on the quotient: return, bind, integration, functorial map, expectation, and event probability.

Lemma 133 Quotient Well-Definedness

Return, integration, map, and event probability respect quotient equality.

Proof
Theorem 134 Quotient Monad Laws

The monad laws hold on the quotient (as \(=_Q\) equalities): left unit, right unit, and associativity.

Proof

2.17 Product Measures and Fubini

Definition 135 Product Probability

For independent probabilities \(p\) on \(X\) and \(q\) on \(Y\), the product probability on \(X \times Y\) uses the product measure \(\mu _p \otimes \mu _q\) and the paired random element \(r \mapsto (\alpha _p(r_1), \alpha _q(r_2))\).

Definition 136 Product Integration

\(\int _{p \otimes q} h = \int _{\mu _p \otimes \mu _q} h(\alpha _p(r_1), \alpha _q(r_2))\).

Theorem 137 Iterated Integration on QBS Product Measure

The joint integral equals the iterated integral: \(\int _{p \otimes q} h = \int _p \int _q h(x, y)\). This is a special case of Fubini for the specific QBS product measure construction, not the full Fubini theorem on arbitrary product measures.

Proof

By Fubini’s theorem on the product measure \(\mu _p \otimes \mu _q\).

Lemma 138 First Marginal Integration

Integration over the first component marginalizes the second.

Proof
Lemma 139 Second Marginal Integration

Integration over the second component marginalizes the first.

Proof
Lemma 140 Commutativity of Product Integration

\(\int _{p \otimes q} h = \int _{q \otimes p} h \circ \mathrm{swap}\).

Proof

2.18 Independence

Definition 141 QBS Independence

Random variables \(f : Z \to X\) and \(g : Z \to Y\) are independent under \(p\) if the joint distribution \((f, g)_*(p)\) equals the product \(f_*(p) \otimes g_*(p)\).

Lemma 142 Product-Measure Factorization

For functions \(f, g\) depending on disjoint coordinates of a product measure: \(\int _{p_X \otimes p_Y} f(x) \cdot g(y) = \mathbb {E}_{p_X}[f] \cdot \mathbb {E}_{p_Y}[g]\). This is a tautology of products, not a non-trivial statistical independence theorem – the lemma has no independence hypothesis. The actual qbs_indep predicate is defined separately but is not yet connected to a non-trivial independence theorem.

Proof

2.19 Variance of Independent Sums

Definition 143 Pair Variance

\(\mathrm{Var}_{p \otimes q}[f + g] = \mathrm{variance}(\mu _p \otimes \mu _q,\; r \mapsto f(\alpha _p(r_1)) + g(\alpha _q(r_2)))\).

Lemma 144 Product Marginal Expectations

\(\mathbb {E}_{p \otimes q}[h \circ \pi _1] = \mathbb {E}_p[h]\), and symmetrically for \(\pi _2\). For independent variables, \(\mathbb {E}_{p \otimes q}[h_1 \circ \pi _1 \cdot h_2 \circ \pi _2] = \mathbb {E}_p[h_1] \cdot \mathbb {E}_q[h_2]\).

Proof
Lemma 145 Product Marginal Variances

\(\mathrm{Var}_{p \otimes q}[h \circ \pi _1] = \mathrm{Var}_p[h]\), and symmetrically for \(\pi _2\).

Proof
Theorem 146 Variance of Independent Sum

For independent random variables \(f\) and \(g\): \(\mathrm{Var}[f + g] = \mathrm{Var}[f] + \mathrm{Var}[g]\).

Proof

Decompose \(\mathrm{Var}(f+g) = \mathrm{Var}(f) + \mathrm{Var}(g) + 2\, \mathrm{Cov}(f,g)\), then show \(\mathrm{Cov}(f,g) = 0\) because \(\mathbb {E}[fg] = \mathbb {E}[f] \cdot \mathbb {E}[g]\) by Fubini.

Lemma 147 Product–Bind Equivalence

The product probability equals bind composed with strength (Prop. 22 of HKSY17).

Proof