Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter HierarchicalBayesComposition

Definition
ChapterHierarchicalBayesComposition

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

definitionsformalizationtimepiece

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

Definition code
import Definitions.Def_ChapterHierarchicalBayes
import Mathlib


/-!
# Composition of finite Bayesian hierarchies

This module continues the formalization of §11 of "Aligned deep learning as a
random sampling method" (`book.tex` around line 10484).  The book says that a
hierarchical inference problem may have as many levels as desired.  The earlier
`ChapterHierarchicalBayes` treats two levels.  Here finite conditional kernels
are equipped with an associative composition operation.  Closure under
normalization and nonnegativity, together with associativity and the
marginalization law, makes arbitrary finite hierarchies compositional: adjacent
levels may be collapsed in any order without changing the resulting likelihood.
-/

open scoped BigOperators

namespace BookProof.ChapterHierarchicalBayesComposition

variable {A B C D : Type*}
  [Fintype A] [Fintype B] [Fintype C] [Fintype D]
  [DecidableEq A] [DecidableEq B] [DecidableEq C] [DecidableEq D]

/-- Composition of two finite conditional kernels, obtained by summing out the
intermediate state. -/
def compKernel (k₁ : A → B → ℝ) (k₂ : B → C → ℝ) (a : A) (c : C) : ℝ :=
  ∑ b, k₁ a b * k₂ b c

/-- A finite conditional kernel is normalized at every input. -/
def IsNormalizedKernel (k : A → B → ℝ) : Prop :=
  ∀ a, ∑ b, k a b = 1

/-- A finite conditional kernel is pointwise nonnegative. -/
def IsNonnegativeKernel (k : A → B → ℝ) : Prop :=
  ∀ a b, 0 ≤ k a b







/-- The identity conditional kernel. -/
def idKernel (a a' : A) : ℝ := if a = a' then 1 else 0









/-- Marginalize a terminal likelihood through one finite conditional kernel. -/
def terminalMarginal (k : A → B → ℝ) (likelihood : B → ℝ) (a : A) : ℝ :=
  ∑ b, k a b * likelihood b





end BookProof.ChapterHierarchicalBayesComposition
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterHierarchicalBayesComposition.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