From my Proof Systems presentation and my lean-theorem-proving README — what I built, what I learned, and how I tracked it, in date order. This page summarizes my own works and learning, not a general stance on the subject.
Watch the video: https://youtu.be/2oBB_k_ePuc
2:27 at 1.25× — the version to post. The normal-speed version (3:04) is here, and the subtitles are here. A square 1080 version for Instagram is here.
I started as a volunteer, giving knowledge transfer as a courtesy to the computer science department. The RLLab was organized by Professor Marek Petrik, for Fall 2024, and my final presentation was on December 5th, 2024. I am not affiliated with the Reinforcement Lab.
What is a proof · What is a derivation · Logic as a formal system · Propositional logic · First-order logic · Second-order logic · Decidability · Completeness · Soundness · Turing machines · Natural deduction · Tableau method · Sequent calculus · Axiomatic derivations · Lean proof systems
To understand how Mathlib implements conditional expectation, I completed two MIT OpenCourseWare courses: “Introduction to Functional Analysis” and “Measure Theory”. Each one is 8–10 hours, with 100+ pages of lecture notes. For Functional Analysis, lectures 1, 2, 4, 6, 7, 8, 9 and 10 are enough.
To build a theorem on conditional expectation, define sigma-algebras, measures, and function maps in a measure space. A random variable is a measurable function:
variable {Ω : Type*} [MeasurableSpace Ω] {X : Ω → ℝ} (hX : Measurable X)
Expectation is noncomputable — an integral over theoretical, symbolic functions. A probability mass function maps α → ℝ≥0∞ with Σf = 1.
In the discrete case, it follows from the law of marginal probability. In the continuous case, from the joint, marginal and conditional densities.
This was a smaller test of how much Lean I had understood — the main project was verifying the Principle of Optimality in Lean4.
For tactics, I studied RFL — the reflexive tactic, applied on any type, no matter how complex. Marek reviewed my DeterministicDP file, with comments on Finset sums, ranges and products. Further reading: Formalizing the Beginnings of Bayesian Probability Theory in the Lean Theorem Prover, UC San Diego.
October 24 – December 1, 2024. The main project was Automated Theorem Proving using Lean4 Prover to verify a foundational theorem of Principle of Optimality in Reinforcement Learning. The goal, set with Prof. Marek Petrik, was to implement deterministic dynamic programming theorems in Lean4 — with the expectation from the start that the proof might not be completed by the December 1 deadline.
Principle of Optimality (Theorem 0.1). If (a*₀, …, a*_{T−1}) is an optimal control sequence and (s*₀, …, s*_T) the corresponding state sequence, then the sub-sequence (a*_k, …, a*_{T−1}) is optimal from s*_k, for each k = 0, …, T−1.
Dynamic Programming Equations (Theorem 0.2). The optimal value function v*_t is the unique value satisfying v*_T(s) = r_T(s) and v*_t(s) = max_a [ r_t(s, a) + v*_{t+1}(f_t(s, a)) ], for t = 0, …, T−1.
A deterministic dynamic program: a finite state set S, a finite action set A, a horizon T, reward functions r_t: S × A → ℝ and r_T: S → ℝ, a transition function f_t: S × A → S, and an initial state s₀. The value function v_t is the sum of rewards from t to T; the optimal value function v*_t is the maximum of it over all action sequences; the objective is to maximize the return v₀(s₀). The proof is by backward induction on t — the case t = T follows directly from the definition, and assuming v*_{t+1} is the unique solution gives v*_t.
I chose only one theorem for proof, wrote down all the definitions, the proof plan, and then the axioms and functions in Lean4. The draft defines a FiniteProbability structure (a finite set Ω with a probability p — nonneg, total probability 1) and an MDP structure (finite S and A, s_0, horizon T, reward r, transition f), plus the value functions, the optimal value functions, and a max function. The proof attempt is example principle_of_optimality : v_star_t(s) = max_{a_t:A} r_t(s, a_t) + v_star_{t+1}(f_t(s, a_t)) := by rfl.
I used example rather than theorem because theorem is retained in the system and some tactics did not yet apply the underlying proofs — an example is type-checked and then deleted, which makes it a good way to test whether tactics apply correctly. I used the rfl tactic, which has 6 types of conversions, for repeated left-to-right conversions. This is only a rough draft and the proof gives errors — it is not complete, and that was the expectation from the beginning.
Lean (De Moura et al., 2015) is an interactive theorem prover bridging interactive and automated proving; Lean4 (de Moura and Ullrich, 2021) is Lean implemented in itself; Mathlib (Avigad et al., 2020) is for formalizing mathematics in Lean. I drew on proof planning (Bundy, 1998) and the Hitchhiker's Guide to Logical Verification (Baanen et al., 2021). I also found that a lot of theorems on Bayesian probability were missing from Mathlib, which mattered for Markov chains and reinforcement learning — Vaishnav (2022) formalized Bayesian probability in Lean3, but Lean3 and Lean4 are not backward compatible, so that work would need permission and rewriting.
Write the proof first, check what the prover already has, and do not reinvent the wheel.
My reinforcement learning coursework and mini project now live on a separate page: My RL Work — Homework and Mini Projects.