Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter BayesInference

Definition
ChapterBayesInference

by leonardopedro · Oct 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

definitionsformalizationtimepiece

Formal definitions for the timepiece Lean 4 formalization (source chapter BookProof/ChapterBayesInference.lean): generated def bundle for ChapterBayesInference. See BookProof/ChapterBayesInference.lean for full context.

Definition code
import Mathlib


/-!
# Chapter "Wave-function parametrization of a probability measure", §2 —
Unitary inference reproduces Bayesian inference

Formalization of the self-contained finite-dimensional core of the book's central
§2 compatibility claim (`book.tex` line ~1338, chapter *"Wave-function
parametrization of a probability measure"*):

> "given a Bayesian model, a prior probability and data that allows to produce a
> posterior probability through Bayesian inference, there is a reversible model
> that produces the same posterior probability as a function of the prior
> probability."

A finite **Bayesian model** is a prior distribution `prior : X → ℝ` on the
hypotheses/parameters together with a likelihood / Markov kernel
`L : X → Y → ℝ` (each row `y ↦ L x y` a probability distribution on the data
`Y`).  Observing data `y`, the **Bayes posterior** is
`posterior y x = prior x · L x y / evidence y`, where
`evidence y = ∑_x prior x · L x y` is the marginal likelihood of the data.

The book's *reversible* (unitary) model reproduces this posterior via the **Born
rule**: the joint density `p(x,y) = prior x · L x y` is `|Ψ(x,y)|²` for the
normalized wave-function `Ψ = √p`, which — by the §3 Gram–Schmidt construction
(`ChapterJointUnitary.exists_unitary_joint`) — is a column of a *unitary* matrix
`U` on `L²(X × Y)`.  Conditioning that column on the observed data (Born-rule
conditioning) returns exactly the Bayes posterior.

Deliverables (all `sorry`-free, `axiom`-free):

* `joint_nonneg`, `joint_sum_one` — the joint density `p(x,y) = prior x · L x y`
  is a genuine probability distribution on `X × Y`;
* `evidence_eq_marginal`, `evidence_nonneg` — the evidence is the `X`-marginal;
* `posterior_nonneg`, `posterior_sum_one` — for data `y` with positive evidence
  the Bayes posterior is a probability distribution on `X`;
* `posterior_eq_joint_div_evidence` — the defining Bayes chain rule
  `posterior y x · evidence y = p(x,y)`;
* **`posterior_eq_born_conditional`** — the posterior equals the Born-rule
  conditional `|Ψ(x,y)|² / ∑_{x'} |Ψ(x',y)|²` of the wave-function `Ψ = √p`;
* **`exists_unitary_reproduces_posterior`** (headline) — there is a *unitary*
  matrix `U` on `X × Y` and a column index `i₀` with `‖U (x,y) i₀‖² = p(x,y)`
  such that for every data point `y` with positive evidence, the Bayes posterior
  is reproduced by Born-rule conditioning of that column:
  `posterior y x = ‖U (x,y) i₀‖² / ∑_{x'} ‖U (x',y) i₀‖²`.
-/

open scoped BigOperators

namespace BookProof.ChapterBayesInference

variable {X Y : Type*} [Fintype X] [Fintype Y] [DecidableEq X] [DecidableEq Y]

/-- The joint probability density `p(x,y) = prior(x) · L(x,y)` of hypothesis `x`
and data `y`. -/
def joint (prior : X → ℝ) (L : X → Y → ℝ) (x : X) (y : Y) : ℝ := prior x * L x y

/-- The evidence (marginal likelihood) `∑_x prior(x) · L(x,y)` of the data `y`. -/
def evidence (prior : X → ℝ) (L : X → Y → ℝ) (y : Y) : ℝ := ∑ x, prior x * L x y

/-- The Bayes posterior `p(x | y) = prior(x) · L(x,y) / evidence(y)`. -/
noncomputable def posterior (prior : X → ℝ) (L : X → Y → ℝ) (y : Y) (x : X) : ℝ :=
  prior x * L x y / evidence prior L y

variable {prior : X → ℝ} {L : X → Y → ℝ}

















/-
**Headline: unitary inference reproduces Bayesian inference.** Given a finite
Bayesian model — a prior `prior` and a likelihood `L` — there is a *unitary*
matrix `U` on `L²(X × Y)` and a column index `i₀` with `‖U (x,y) i₀‖² = p(x,y)`,
such that for every data point `y` with positive evidence the Bayes posterior is
reproduced by Born-rule conditioning of that column of `U`.
-/


end BookProof.ChapterBayesInference
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterBayesInference.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me