Skip to content

fix(MeasureTheory): Section 1.4 was never in the build; add imports and repair it - #737

Merged
teorth merged 3 commits into
mainfrom
fix/section-1-4-build
Oct 18, 2026
Merged

teorth merged 3 commits into
mainfrom
fix/section-1-4-build

Conversation

@teorth

@teorth teorth commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

The problem

Analysis.lean does not import Section_1_4_1, Section_1_4_2 or Section_1_4_3. Since lake build builds the Analysis target, none of those three files has ever been compiled by lake build or by CI.

They had consequently drifted into a state where all three failed to compile. No CI run could have reported this: every PR touching Section 1.4 got a green check that never looked at the file it changed. (I merged a number of such PRs myself over the last few weeks, on exactly that false signal.)

What this does

Adds the three missing imports — the build goes from 8310 to 8313 jobs — and repairs Section_1_4_3, which was the only one still failing once #711, #694, #700 and #712 had landed. (#711 deserves credit here: it spotted the missing Section_1_4_2 import and fixed the genuinely broken compl_mem fields in 1.4.1.)

The main repair is missing API. FinitelyAdditiveMeasure and CountablyAdditiveMeasure had no @[ext] lemma, so the ext tactic did not apply to them, yet several instance proofs were written as cases …; congr 1; ext A in the hope that it would. Both are one function field plus propositions, so extensionality follows from funext and proof irrelevance:

@[ext] theorem FinitelyAdditiveMeasure.ext … (h : ∀ A, μ.measure A = ν.measure A) : μ = ν

With those registered, the AddCommMonoid and DistribMulAction instance proofs collapse to ext A plus the pointwise fact. Two other fixes:

  • FinitelyAdditiveMeasure.restrict — Disjoint.image wants an InjOn and two subset side conditions, and the image of a union needed Set.image_union.
  • lebesgue_isCountablyAdditive — Lebesgue_measure.countable_union takes its family implicitly, so the field needs it eta-expanded.

One thing left open, deliberately

smul_add is sorry in both DistribMulAction instances, with a comment, rather than papered over. Pointwise it asks for

c * (μ A + ν A) = c * μ A + c * ν A

for an arbitrary set A. But EReal is distributive only over nonnegative summands (EReal.left_distrib_of_nonneg), and FinitelyAdditiveMeasure.measure_pos constrains the sign of μ A only for B-measurable A. So as the definitions currently stand this field is not provable, and DistribMulAction ENNReal (FinitelyAdditiveMeasure B) cannot be instantiated as written. That is a design question — restrict the measure field to measurable sets, require a global sign condition, or weaken the algebraic structure — rather than something to settle in a repair PR.

Verification

lake build: 8313 jobs, no errors. Net change to sorry count in Section_1_4_3 is +2, both the smul_add fields above; everything else that previously failed to compile now compiles.

Worth considering separately: a CI check that every Analysis/**/*.lean file is reachable from Analysis.lean would have caught this at the moment Section 1.4 was added, and would stop it recurring.

Scope widened after an audit

Checking by .olean presence (the reliable test — lean_lib with no globs builds only Analysis.lean's closure, so a plain grep of the import list is misleading) turned up two more never-compiled modules, Section_1_4_4 and Section_1_4_5. Both already compile, so they just needed importing. Final build: 8315 jobs, no errors, and every file under Analysis/ except one is now in the closure.

The exception is Analysis/Misc/equational.lean, which cannot simply be added: it declares a top-level S that collides with Analysis.Misc.erdos_379, so importing it fails with environment already contains 'S'. It needs a rename or a namespace first, which seemed out of scope here.

Also included: a .gitignore entry for __pycache__, which the test suite added in #731-#735 creates on first run.

🤖 Generated with Claude Code

teorth and others added 3 commits October 17, 2026 16:47
`Analysis.lean` did not import `Section_1_4_1`, `Section_1_4_2` or
`Section_1_4_3`, so `lake build` — and therefore CI — never compiled any of
them. They had drifted into a state where none of the three compiled at all,
which no CI run could have reported.

This adds the three missing imports (the build goes from 8310 to 8313 jobs) and
fixes `Section_1_4_3`, the only one still failing once #711, #694, #700 and #712
had landed.

The main repair is API that was missing: `FinitelyAdditiveMeasure` and
`CountablyAdditiveMeasure` had no `@[ext]` lemma, so the `ext` tactic could not
be used on them, and several instance proofs were written as
`cases …; congr 1; ext A` in the hope that it would be. Both measures are a
single function field plus propositions, so extensionality follows from
`funext` and proof irrelevance; with those lemmas registered, the `AddCommMonoid`
and `DistribMulAction` instance proofs reduce to `ext A` followed by the
pointwise fact. Also fixed:

- `FinitelyAdditiveMeasure.restrict`: `Disjoint.image` takes an `InjOn` plus two
  subset side conditions, and the image of a union needed `Set.image_union`.
- `lebesgue_isCountablyAdditive`: `Lebesgue_measure.countable_union` takes its
  family implicitly, so the field needs it eta-expanded.

`smul_add` is left as `sorry` in both `DistribMulAction` instances, with a
comment, rather than papered over. Pointwise it asks for
`c * (μ A + ν A) = c * μ A + c * ν A` for an *arbitrary* set `A`, but `EReal` is
distributive only over nonnegative summands (`EReal.left_distrib_of_nonneg`) and
`measure_pos` constrains the sign of `μ A` only for measurable `A`. As the
definitions stand the field is not provable, so it needs a design decision
rather than a proof.

`lake build` passes: 8313 jobs, no errors.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The preview/build test suite added in #731-#735 writes __pycache__ directories
on first run, which were showing up as untracked files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An audit by olean presence (the reliable check, since `lean_lib` with no globs
builds only `Analysis.lean`'s import closure) found two more MeasureTheory
modules that were never compiled. Both already compile cleanly, so they just
needed importing. Build: 8313 -> 8315 jobs.

`Analysis/Misc/equational.lean` is the one remaining file outside the closure,
and it cannot simply be added: it declares a top-level `S` that collides with
`Analysis.Misc.erdos_379`, so importing it fails with "environment already
contains 'S'". Left alone; it needs a rename or a namespace first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@teorth
teorth merged commit a19a5bf into main Oct 18, 2026
1 check passed
zhikaip added a commit to zhikaip/analysis that referenced this pull request Oct 18, 2026
The MeasureTheory PRs merged since this branch was cut (teorth#694-teorth#737) were
written against v4.29.0-rc8, and teorth#737 put Section_1_4_1 through
Section_1_4_5 into the build for the first time. Under v4.35.0 they need
the same repairs as the rest of the library:

- eleven new `List.TFAE.out i j` calls in Section_1_3_2 bumped to
  1-based indices;
- Section_1_4_1: two `simpa [LebesgueMeasurable.boolean_algebra]` steps
  that relied on unfolding the `measurable` structure field now `show`
  the unfolded goal first, and two exercise statements declared as
  `instance` with non-class types are `theorem`s;
- Section_1_4_2 imports `Mathlib.MeasureTheory.MeasurableSpace.Defs` and
  Section_1_4_3 imports `Mathlib.MeasureTheory.Measure.NullMeasurable`,
  since `Mathlib.Tactic` no longer provides `MeasurableSpace`,
  `Measure`, `Measure.completion` or `NullMeasurableSet` transitively;
- `Measure.toCountablyAdditiveMeasure` is `noncomputable`, as
  `ENNReal.toEReal` now is.

No statements changed. Full `lake build` passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant