Repository navigation
refactor: adopt Statlib's klBerReal - #378
RemyDegenne wants to merge 2 commits into
Conversation
Import Statlib.ForMathlib.InformationTheory.KullbackLeibler.Bernoulli in LMLExplore/InformationTheory/KullbackLeibler/Bernoulli.lean and delete LMLExplore.klBerReal with the lemmas Statlib provides: klBerReal_def (now klBerReal_apply), klBerReal_self, klBerReal_one_left, klBerReal_one_sub_one_sub (now klBerReal_one_sub) and klBerReal_eq_neg_binEntropy_sub. Every other klBerReal lemma of LMLExplore is now about InformationTheory.klBerReal; files that use it open InformationTheory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0196ftMV379vy48QfzHBVNvo
There was a problem hiding this comment.
🟡 reuse — request_changes claude/claude-opus-5-5
The migration to Statlib's klBerReal is correct and leaves no compatibility surface; one edited proof step still re-derives Statlib's klBerReal_eq_of_ne by hand instead of using it.
LMLExplore/InformationTheory/KullbackLeibler/Bernoulli.lean:721— InklBer_add_klBer_le,h₃ : klBerReal q r = q * (log q - log r) + (1 - q) * (log (1 - q) - log (1 - r))is re-proved withklBerReal_applyand twolog_divrewrites. It is exactly Statlib'sInformationTheory.klBerReal_eq_of_ne, from the module this PR now imports. Fix: Replace lines 721-722 withhave h₃ := klBerReal_eq_of_ne (p := q) hr'.1.ne' hr'.2.ne(herehr' : r ∈ Set.Ioo 0 1).
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 · 49s · 227.6k in (209.9k cache read, 17.7k cache write) / 3.2k out tokens · reviewing this diff · rubric ·
There was a problem hiding this comment.
🟡 api-design — request_changes claude/claude-opus-5-5
Moving to Statlib's InformationTheory.klBerReal is right and leaves no compatibility layer behind. But the kept LMLExplore.klBerReal_nonneg now has the same name as Statlib's InformationTheory.klBerReal_nonneg, with different hypotheses, in files that open both namespaces.
LMLExplore/InformationTheory/KullbackLeibler/Bernoulli.lean:316—LMLExplore.klBerReal_nonneg(hypsp, q ∈ Icc 0 1,klBer p q ≠ ∞) has the same name as Statlib'sInformationTheory.klBerReal_nonneg(hyp0 < q < 1), and both are about the same definitionInformationTheory.klBerReal. This PR opensInformationTheoryinsidenamespace LMLExplorein six files, so a bareklBerReal_nonnegis ambiguous there and is only resolved by checking which lemma the hypotheses fit. That gives a confusing interface and fragile elaboration. Fix: Rename the LMLExplore lemma to name its hypothesis, e.g.klBerReal_nonneg_of_klBer_ne_top. Update its uses at Bernoulli.lean:474, 581, 706, 707, KLChernoff.lean:391 and BernoulliDeviation.lean:284, and the docstring reference at Bernoulli.lean:329.
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 · 98.2k in (91.4k cache read, 6.8k cache write) / 2.7k 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 |
Rename LMLExplore.klBerReal_nonneg to klBerReal_nonneg_of_klBer_ne_top so it no longer shares a name with Statlib's InformationTheory.klBerReal_nonneg, and use Statlib's klBerReal_eq_of_ne in klBer_add_klBer_le. Co-Authored-By: Claude Code <noreply@github.com>
Statlib's
Statlib/ForMathlib/InformationTheory/KullbackLeibler/Bernoulli.leandefines the real binary relative entropyInformationTheory.klBerReal p q = p * log (p / q) + (1 - p) * log ((1 - p) / (1 - q))with the same body asLMLExplore.klBerReal, and five of its basic lemmas. This PR makesLMLExplore/InformationTheory/KullbackLeibler/Bernoulli.leanimport that Statlib file, deletes the LMLExplore copies, and moves every use to the Statlib declarations. The files that useklBerRealwithout already openingInformationTheorynow open it:Bandits/Concentration.lean,Bandits/KLUCB.lean,InformationTheory/KrichevskyTrofimov.lean,Probability/Distributions/ExponentialFamily/Bernoulli.lean,Probability/Moments/KLChernoff.leanandSequentialLearning/BernoulliDeviation.lean.Now that #354 has merged, the Statlib file can be imported: it imports Statlib's Bernoulli file, which used to clash with
LMLExplore/Probability/Distributions/Bernoulli.lean.Removed public declarations
LMLExplore.klBerRealInformationTheory.klBerReal(same body, so the two are definitionally equal)LMLExplore.klBerReal_defInformationTheory.klBerReal_applyLMLExplore.klBerReal_selfInformationTheory.klBerReal_self(also@[simp])LMLExplore.klBerReal_one_leftInformationTheory.klBerReal_one_left(also@[simp])LMLExplore.klBerReal_one_sub_one_subInformationTheory.klBerReal_one_sub. Same statement, but Statlib's lemma is not@[simp]. No simp call in LMLExplore needed it.LMLExplore.klBerReal_eq_neg_binEntropy_sub(right-hand side-binEntropy p - (p * log q + (1 - p) * log (1 - q)))InformationTheory.klBerReal_eq_neg_binEntropy_sub(right-hand side-binEntropy p - p * log q - (1 - p) * log (1 - q)). The four uses, in the continuity, derivative and strict convexity proofs, recover the old form with.trans (sub_sub _ _ _).Renamed public declarations
LMLExplore.klBerReal_nonnegLMLExplore.klBerReal_nonneg_of_klBer_ne_top(same statement; renamed so that a bareklBerReal_nonnegunderopen InformationTheoryno longer has two candidates with different hypotheses)klBer_add_klBer_lenow uses Statlib'sInformationTheory.klBerReal_eq_of_neinstead of re-deriving it.What stays in LMLExplore
ℝ≥0∞-valuedLMLExplore.klBerand its whole API:klDiv_bernoulliMeasure(klDiv Ber(x, y, p) Ber(x, y, q) = klBer p qfor allp q : I, including the infinite cases, so Statlib'sklDiv_bernoulliMeasure_eq_klBerReal, which assumesq ∉ {0, 1}, is a special case of it together withklBer_eq_ofReal_klBerReal), the data processing inequalities,klUpper,klLower, monotonicity, convexity, continuity and measurability. Statlib, LML, Tau Ceti and Mathlib have noklBer.LMLExplore.klBerReal_nonneg, renamed toLMLExplore.klBerReal_nonneg_of_klBer_ne_top(see below). It only assumesp, q ∈ [0, 1]andklBer p q ≠ ∞, so it is more general than Statlib'sInformationTheory.klBerReal_nonneg(which assumes0 < q < 1).klBerReal_*lemmas, which have no Statlib counterpart:klBerReal_eq_zero_iff,klBerReal_le_sq_sub_div,two_mul_sq_le_klBerReal,mul_klBerReal_div_eq_log, continuity, derivatives, strict monotonicity and convexity,klBerReal_one_sub_right, the limits at0and1,mul_klFun_div_le_klBerReal, and so on. They are unchanged, but are now stated aboutInformationTheory.klBerReal.The module docstring now names the Statlib definition and its basic API, and its list of definitions and main statements drops the removed declarations.
Checks run
scripts/build.sh --iofailon the whole library (8551 jobs): succeeds, with no warnings.#lint in LMLExplore, run from a scratch file that imports the eight changed modules: all checks pass.lake exe axioms: no duplicate declarations against the 5613 dependency modules, and every declaration is within the allowlist.grepoverLMLExplore/:klBerReal_def,klBerReal_one_sub_one_subandLMLExplore.klBerRealno longer appear anywhere.Fixes #331
Roadmap: none
🤖 Generated with Claude Code