Repository navigation
feat: the method of types and Sanov's bound on a finite type - #290
Conversation
Number of types, probability of a type class and the deviation bound P(KL(p̂ₙ ‖ ν) > t) ≤ (n + 1)^(m - 1) exp (-n t) for an i.i.d. sample on a finite type, with its confidence form; the stars-and-bars count of `Finset.piAntidiag`; and the Kullback–Leibler divergence of finite measures on a finite type as a finite sum. Co-Authored-By: Claude Code <noreply@github.com>
There was a problem hiding this comment.
🟡 attribution — request_changes claude/claude-opus-5-5
The informal sources [CT] and [EV26] are cited, but neither ported file credits the formalization in RemyDegenne/Essakine2026Tight that the description says it ports from.
LMLExplore/InformationTheory/MethodOfTypes.lean:42— The module docstring does not credit the formalization this file is adapted from (Essakine2026Tight,ForLMLExplore/InformationTheory/MethodOfTypes.lean, commit 520dd39a, Apache 2.0). That source is named only in the PR description. Fix: Add a sentence before## References, e.g. "The method-of-types bounds are adapted fromForLMLExplore/InformationTheory/MethodOfTypes.leanof the formalization Essakine2026Tight (github.com/RemyDegenne/Essakine2026Tight, by Rémy Degenne, Apache 2.0) of [EV26]."LMLExplore/InformationTheory/KullbackLeibler/Finite.lean:209—toReal_klDiv_eq_sum_mul_log_divis described in the PR as a generalisation of Essakine2026Tight'sForLMLExplore/InformationTheory/KullbackLeibler/Fintype.lean, but neither the docstring nor the module doc credits that source. Fix: Add a line to the module docstring saying thattoReal_klDiv_eq_sum_mul_log_divis adapted (generalised to finite measures) fromForLMLExplore/InformationTheory/KullbackLeibler/Fintype.leanof the formalization Essakine2026Tight.
Reply in this thread to contest a finding; that re-runs only this rubric and posts an answer here. (To fix it, just push a commit — that re-reviews on its own. To contest again after an answer, post a NEW reply rather than editing an old one.)
claude/claude-opus-5-5 · 28s · 108.3k in (98.2k cache read, 10.1k cache write) / 1.9k out tokens · reviewing this diff · rubric
There was a problem hiding this comment.
🟡 api-design — request_changes claude/claude-opus-5-5
The surface is minimal and typeCount's body is hidden behind typeCount_def := (rfl), but the empirical-mass evaluation lemma has no @[simp] and typeCount lacks its positivity/zero characterization.
LMLExplore/InformationTheory/MethodOfTypes.lean:108—measureReal_empiricalFiniteMeasure_singletonis the normal form for the mass of a singleton under the empirical measure but has no@[simp], unlike the parallelmeasureReal_empiricalKernel_apply_singleton. Fix: Tag it@[simp].LMLExplore/InformationTheory/MethodOfTypes.lean:62—typeCounthas no lemma characterizing when a count is positive or zero. The proof ofmeasure_typeCount_eq_legets positivity fromcard_pos.2 ⟨k, by simp⟩(line 164), which relies on unfolding the definition in its own file; users elsewhere would have to rewrite withtypeCount_def. Fix: AddtypeCount_pos_iff : 0 < typeCount x a ↔ ∃ k, x k = aand@[simp] typeCount_eq_zero_iff : typeCount x a = 0 ↔ ∀ k, x k ≠ a, and use them at line 164.
Reply in this thread to contest a finding; that re-runs only this rubric and posts an answer here. (To fix it, just push a commit — that re-reviews on its own. To contest again after an answer, post a NEW reply rather than editing an old one.)
claude/claude-opus-5-5 · 32s · 106.1k in (95.7k cache read, 10.4k cache write) / 2.7k out tokens · reviewing this diff · rubric
There was a problem hiding this comment.
Addressed in 6876351, with one part contested.
Fixed: typeCount positivity and zero. I added typeCount_pos_iff : 0 < typeCount x a ↔ ∃ k, x k = a and @[simp] typeCount_eq_zero_iff : typeCount x a = 0 ↔ ∀ k, x k ≠ a. The proof of measure_typeCount_eq_le (and the new prod_measureReal_pow_typeCount_eq_mul_exp) now uses typeCount_pos_iff instead of card_pos.2 ⟨k, by simp⟩. simpNF accepts typeCount_eq_zero_iff.
Contested: @[simp] on measureReal_empiricalFiniteMeasure_singleton. I tried the tag, and the environment linter rejects it. Tau Ceti's TauCeti.Probability.empiricalFiniteMeasure_toMeasure is already @[simp] and rewrites the coercion (empiricalFiniteMeasure x : Measure α) inside the left-hand side, so simp never reaches this lemma:
simpNF LMLExplore.measureReal_empiricalFiniteMeasure_singleton: Left-hand side simplifies from
(↑(TauCeti.Probability.empiricalFiniteMeasure x)).real {a}
to
(∑ x_1, (↑n)⁻¹ • MeasureTheory.Measure.dirac (x x_1)).real {a}
using
simp only [*, @TauCeti.Probability.empiricalFiniteMeasure_toMeasure, Fintype.card_fin]
Try to change the left-hand side to the simplified term!
The parallel measureReal_empiricalKernel_apply_singleton can be @[simp] because nothing unfolds empiricalKernel N ω a first. Here, adding the tag would break CI (linters run with warnings as errors), and silencing the linter is not allowed. So the lemma stays untagged and is used by name with rw.
There was a problem hiding this comment.
🟡 proof-quality — request_changes claude/claude-opus-5-5
Sanov's bound ends a cast step with an undocumented rfl, and the reusable ratio identity is buried in a ~60-line proof. Several long named-lemma rewrite chains are brittle.
LMLExplore/InformationTheory/MethodOfTypes.lean:229— Afterpush_castinmeasure_lt_klDiv_empiricalFiniteMeasure_le, a barerflcloses the goal. This relies on an undocumented definitional equality between cast forms inℝ≥0∞/ℝ. Fix: Replacepush_cast; rflwithsimp/norm_castor an explicit cast lemma, or add a comment saying which defeqrfluses.LMLExplore/InformationTheory/MethodOfTypes.lean:176—hkey(with its helperhexp) proves∏ ν{a}^N a = (∏ Q{a}^N a) · exp(-n·∑ Q log(Q/ν)), the reusable identity [CT, Theorem 11.1.2]. It sits inline inmeasure_typeCount_eq_le, which runs about 60 lines (138–199). Fix: Make it a standalone lemma (e.g.prod_measureReal_pow_typeCount_eq_mul_exp) aboutxandνwith the support hypothesis, and call it frommeasure_typeCount_eq_le.LMLExplore/InformationTheory/MethodOfTypes.lean:185—hexpis closed by a 9-lemmarwchain (← mul_assoc, hQ a, mul_div_cancel₀, ← hQ a, ← mul_neg, ← log_inv, inv_div, ← log_pow, exp_log) that is fragile under Mathlib renames. The same pattern appears inhQle(lines 164–165, a 6-rewriterwa) and inmeasure_log_div_lt_klDiv_empiricalFiniteMeasure_le(lines 243–244, 8 rewrites). Fix: Provehexpasexp(-(N a * log (Q/ν))) = (ν/Q)^N aviaReal.exp_log/rpow_natCastplusfield_simp/simp. Shorten the other two chains withsimp [ENNReal.toReal_prod, ...]andReal.exp_logfollowed byfield_simp.
Reply in this thread to contest a finding; that re-runs only this rubric and posts an answer here. (To fix it, just push a commit — that re-reviews on its own. To contest again after an answer, post a NEW reply rather than editing an old one.)
claude/claude-opus-5-5 · 44s · 47.8k in (41.5k cache read, 6.3k cache write) / 3.1k out tokens · reviewing this diff · rubric
AI review — changes requestedEach rubric is judged independently by multiple review agents; the PR merges only once every rubric is green — any rubric that is not green (changes requested, blocked, errored, stale, or not yet run) blocks the merge. See the rubrics.
♻️ = approved on an earlier commit, re-run before merge. Reviewing this diff at head |
…vity lemmas, extract the type-ratio identity Co-Authored-By: Claude Code <noreply@github.com>
This PR adds the method of types on a finite type and Sanov's deviation bound for the empirical distribution of an i.i.d. sample. It is the first bullet of ReinforcementLearning Layer 3.4 ("Types and categorical KL bounds"): on a set of size
m, there are at most(n+1)^mtypes, andP(KL(p̂ₙ, p) > ε) ≤ (n+1)^m e^{-nε}. Both are proved here with the sharper exponentm - 1, which implies the roadmap'sm, and for anym, not onlym ≥ 2. Layer 19 (best policy identification, through the confidence threshold of RF-Express and of entropic BPI) lists Layer 3.4 as a prerequisite. After this PR, the rest of Layer 3.4 is its second bullet: the martingale property of the likelihood ratio of predictable predictors, and the time-uniform bound for Laplace's predictor.LMLExplore/InformationTheory/MethodOfTypes.lean(new) contains:LMLExplore.typeCount(the typea ↦ #{k | x k = a}ofx : Fin n → α, body not exposed) withtypeCount_def,typeCount_pos_iff,typeCount_eq_zero_iff,sum_typeCount,typeCount_mem_piAntidiagandprod_comp_eq_prod_pow_typeCount;card_image_typeCount_le, the number of types: at most(n + 1) ^ (m - 1)[CT, Theorem 11.1.1];measureReal_empiricalFiniteMeasure_singleton, which says Tau Ceti's empirical measure givesathe masstypeCount x a / n, andempiricalFiniteMeasure_absolutelyContinuous;pi_setOf_typeCount_eq, the product measure of a type class;prod_measureReal_pow_typeCount_eq_mul_exp, the ratioexp (-n KL)of the probabilities of a sequence underνand under its empirical distribution [CT, Theorem 11.1.2];measure_typeCount_eq_le, the probability of a type class, at mostexp (-n t)fort ≤ KL(p̂(x) ‖ ν)[CT, Theorem 11.1.4];measure_lt_klDiv_empiricalFiniteMeasure_le, Sanov's boundℙ(KL(p̂ₙ ‖ ν) > t) ≤ (n + 1) ^ (m - 1) exp (-n t)[CT, Theorem 11.2.1], [EV26, Lemma 19], and its confidence formmeasure_log_div_lt_klDiv_empiricalFiniteMeasure_le.The empirical distribution is Tau Ceti's
TauCeti.Probability.empiricalFiniteMeasure, not a new definition. The lawνis any measure on a finite type with measurable singletons; it is a probability measure by theHasLawhypotheses. The law of the sample is Mathlib'siIndepFun.hasLaw_pi.There are two supporting additions.
LMLExplore/Algebra/Order/Antidiag/FinsuppEquiv.lean(new) hasFinset.card_piAntidiag_nat_eq_choose, which is stars and bars forFinset.piAntidiag, proved from Mathlib'scard_finsuppAntidiag_nat_eq_choose, andFinset.card_piAntidiag_nat_le_pow, the bound(n + 1) ^ (#s - 1), proved from Mathlib'sNat.choose_add_le_add_one_pow.LMLExplore/InformationTheory/KullbackLeibler/Finite.leangainsLMLExplore.toReal_klDiv_eq_sum_mul_log_div: for finite measuresμ ≪ νon a finite type,(klDiv μ ν).toReal = ∑ a, μ{a} log (μ{a}/ν{a}) + ν(univ) - μ(univ). This is the bridge that file's docstring already describes between measure KL and vector relative entropy. Unlike Tau Ceti'sTauCeti.klDiv_eq_ofReal_sum_log_singleton, it allows atoms ofνwith mass zero. Its proof evaluates the Radon–Nikodym derivative at atoms with Tau Ceti'sMeasure.rnDeriv_eq_measure_singleton_div.No public declaration is removed or renamed.
Source: this ports item R20 of the paper project RemyDegenne/Essakine2026Tight (commit 520dd39a55fa4e9a62a4a2d51f48163926176a5d, Apache 2.0 license), files
ForLMLExplore/InformationTheory/MethodOfTypes.leanandForLMLExplore/InformationTheory/KullbackLeibler/Fintype.lean. It was adapted as follows:νand Tau Ceti's empirical measure, instead ofweightedMeasure pand a localempiricalFreq;KullbackLeibler/Finite.lean;klDiv_ne_top_of_finiteis inlined as Mathlib'sklDiv_ne_top;m - 1corrects themin the proof of [EV26, Lemma 19] (the paper's errata E22).Roadmap: ReinforcementLearning
Paper: RemyDegenne/Essakine2026Tight
Item: R20
🤖 Prepared with Claude Code