refactor: Extract general-purpose lemmas to ForMathlib for upstream contribution#13
Draft
cameronfreer wants to merge 20 commits intomainfrom
Draft
refactor: Extract general-purpose lemmas to ForMathlib for upstream contribution#13cameronfreer wants to merge 20 commits intomainfrom
cameronfreer wants to merge 20 commits intomainfrom
Conversation
Extract reusable infrastructure from the exchangeability project into ForMathlib/ subdirectories mirroring mathlib's hierarchy: - ForMathlib/Combinatorics/PermutationExtension.lean exists_perm_extending_strictMono for subsequence ↔ permutation - ForMathlib/MeasureTheory/MeasurableSpace/ComapInfima.lean iInf_comap_eq_comap_iInf_of_surjective for tail σ-algebra equality - ForMathlib/MeasureTheory/Constructions/Pi/Cylinders.lean π-system infrastructure and measure_eq_of_fin_marginals_eq - ForMathlib/MeasureTheory/Function/ConditionalExpectation/Lipschitz.lean condExp_L1_lipschitz and related operator properties Update source files to re-export from ForMathlib for backward compat. Add ForMathlib/README.md with PR tracking and sequencing strategy.
- PermutationExtension: Condense succ case induction from 10 lines to 3 - ComapInfima: Use existing mathlib lemma hf.preimage_injective
- ComapInfima: Inline comap_iInf_le proof - Cylinders: Inline isPiSystem_prefixCylinders And.intro - Lipschitz: Use Integrable.of_bound for integrable_of_bounded
Replace filter_upwards block with h_linear.mono + congrArg
Mark all 5 ForMathlib files as extracted with axiom verification. Simplify directory structure to match actual files.
Batch 1 of ForMathlib extraction Phase 2: - ComapInfima: Remove custom preimage_injective_of_surjective, use Function.Surjective.preimage_injective directly; inline hge proof using comap_iInf_le; simplify witness equality proof - Lipschitz: Use Integrable.mul_bdd directly in integrable_of_bounded_mul; simplify condExp_mul_pullout using single trans chain - Cylinders: Replace custom takePrefix with mathlib's Fin.take; import Mathlib.Data.Fin.Tuple.Take - PermutationExtension: Use Fin.castLEquiv for domain equivalence; import Mathlib.Logic.Equiv.Fin.Basic; simplify proof structure Net reduction: -82 lines across 5 files
Batch 2 of ForMathlib extraction Phase 2: ForMathlib/MeasureTheory/Function/LpHelpers.lean: - eLpNorm_two_sq_eq_integral_sq: L² norm² = integral of square - eLpNorm_lt_of_integral_sq_lt: integral bound → norm bound - memLp_of_abs_le_const: bounded functions in Lp - memLp_two_of_bounded: bounded functions in L² - setIntegral_le_eLpNorm_mul_measure: Cauchy-Schwarz on sets - abs_integral_mul_le_L2: Cauchy-Schwarz for L² - L2_tendsto_implies_L1_tendsto_of_bounded: L² → L¹ convergence - integral_pushforward_id/sq_diff/continuous: pushforward integrals ForMathlib/MeasureTheory/MeasurableSpace/SigmaAlgebraHelpers.lean: - aestronglyMeasurable_iInf_antitone: preservation under infima - aestronglyMeasurable_sub_of_tendsto_ae: preservation under limits These bridge ENNReal-valued Lp norms and Real-valued integrals for probability theory applications.
Batch 3 of ForMathlib extraction Phase 2: ForMathlib/Probability/Kernel/ProductMeasurable.lean: - measurable_prod_ennreal: product of measurable ENNReal functions - rectangles_isPiSystem: measurable rectangles form π-system - rectangles_generate_pi_sigma: product σ-algebra = generateFrom rectangles - measurable_measure_pi: key lemma for ConditionallyIID property Note: Conditional independence lemmas (CondIndep) not extracted due to project-specific dependencies on CondExpHelpers. The ProductMeasurable lemmas are the truly general-purpose content. Also updates copyright year to 2026 for new ForMathlib files.
Update tracking table and module summaries for Phase 2 extraction: - LpHelpers.lean: Lp norm/integral bridges - SigmaAlgebraHelpers.lean: AEStronglyMeasurable for infima - ProductMeasurable.lean: Product measure kernel measurability
Replace custom rectangles_isPiSystem and rectangles_generate_pi_sigma with mathlib's isPiSystem_pi and generateFrom_pi from MeasurableSpace.Pi. Also remove unneeded univ_pi_eq_setOf_forall helper.
…rable_right Use condExp_mul_of_stronglyMeasurable_right directly instead of condExp_stronglyMeasurable_mul_of_bound with double commutativity. This removes the need for SigmaFinite (μ.trim hm) and the TrimInstances import.
Replace manual Classical.choose scaffolding with Equiv.ofInjective followed by Equiv.subtypeEquivRight to convert between range and existential predicate representations.
Add explicit natural number argument to make type inference work correctly for the squared norm case.
…E bridge lemmas
Add three new ForMathlib files with general-purpose lemmas:
1. Probability/Independence/Conditional.lean
- `condIndep_of_indicator_condexp_eq`: Doob's characterization of conditional
independence (reverse direction) - projection property implies cond indep
2. MeasureTheory/Function/AEHelpers.lean
- `finset_sum_ae_eq`: Combine finitely many a.e. equalities into sum equality
3. Probability/ConditionalExpectation/Distributional.lean
- `condexp_indicator_eq_of_pair_law_eq`: If (Y,Z) and (Y',Z) have same law,
then E[1_{Y∈B}|σ(Z)] = E[1_{Y'∈B}|σ(Z)] a.e.
All files:
- Import only mathlib (no Exchangeability.* dependencies)
- Use only standard axioms (propext, Classical.choice, Quot.sound)
- Follow mathlib style (<100 char lines)
Conditional.lean (118 lines, -17): - Use `inter_indicator_one` for indicator product formula - Cleaner proof structure with consistent naming Distributional.lean (117 lines, -26): - Use `hZ.comap_le` instead of manual comap proof - Streamlined integral calculations
Distributional.lean (107 lines, -10): - Use indicator_comp_right to rewrite indicator compositions - Use setIntegral_indicator + setIntegral_const for cleaner integral calculations - Remove duplicate proof structure AEHelpers.lean (59 lines, -3): - Replace heavy ConditionalExpectation.Basic import with MeasureSpace - Remove unused ENNReal, ProbabilityTheory, Set opens
- SigmaAlgebraHelpers: Remove unused _h_le and _hm parameters - LpHelpers: Remove false positive nolint annotations, remove unused params from memLp_of_abs_le_const
- PermutationExtension: Create `exists_perm_extending_injective` as the main lemma using `Function.Injective k`, make `exists_perm_extending_strictMono` a corollary (proof only used injectivity, not order property) - ComapInfima: Generalize index type from `Type*` to `Sort*` in `iInf_comap_eq_comap_iInf_of_surjective` and helper lemmas, consistent with `comap_iInf_le` which already used `Sort*`
- Change main API from `k : Fin m → ℕ` to cleaner `k : Fin m → Fin n` - Move to `Equiv.Perm` namespace (mathlib convention) - Golf main theorem from 10+ lines to 2 lines (pure term mode) - Remove unused `strictMono_Fin_ge_id` lemma - Add backward-compatible wrappers in `Combinatorics` namespace - Simplify docstrings (remove project-specific references) Line count: 113 → 79 (mathlib PR portion: ~45 lines)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR organizes general-purpose lemmas from the exchangeability project into a
ForMathlib/directory structure mirroring mathlib's hierarchy, preparing them for potential upstream contribution.Changes
New ForMathlib Files (mathlib-only imports)
Combinatorics/PermutationExtension.leanexists_perm_extending_injective,exists_perm_extending_strictMonoMeasureTheory/MeasurableSpace/ComapInfima.leaniInf_comap_eq_comap_iInf_of_surjectiveMeasureTheory/MeasurableSpace/SigmaAlgebraHelpers.leanaestronglyMeasurable_iInf_antitoneMeasureTheory/Constructions/Pi/Cylinders.leanisPiSystem_prefixCylinders,measure_eq_of_fin_marginals_eqMeasureTheory/Function/ConditionalExpectation/Lipschitz.leancondExp_L1_lipschitzMeasureTheory/Function/LpHelpers.leaneLpNorm_two_sq_eq_integral_sq,abs_integral_mul_le_L2MeasureTheory/Function/AEHelpers.leanfinset_sum_ae_eqProbability/Kernel/ProductMeasurable.leanmeasurable_measure_piProbability/Independence/Conditional.leancondIndep_of_indicator_condexp_eqProbability/ConditionalExpectation/Distributional.leancondexp_indicator_eq_of_pair_law_eqModified Project Files
Exchangeability/Contractability.lean: Import ForMathlib, re-exportexists_perm_extending_strictMonoExchangeability/Tail/TailSigma.lean: Import ForMathlib, re-export comap/infima lemmasRecent Refinements
Generalized lemmas for better mathlib compatibility
PermutationExtension.lean:
exists_perm_extending_injectiveas the main lemma usingFunction.Injective kexists_perm_extending_strictMonoa corollary (proof only used injectivity, not order property)ComapInfima.lean:
Type*toSort*iniInf_comap_eq_comap_iInf_of_surjectivecomap_iInf_lewhich already usedSort*Removed nolint annotations and unused parameters
SigmaAlgebraHelpers.lean:
aestronglyMeasurable_iInf_antitone: Removed unused_h_le : ∀ N, m N ≤ m₀parameteraestronglyMeasurable_sub_of_tendsto_ae: Removed unused_hm : m ≤ m₀parameterLpHelpers.lean:
eLpNorm_two_sq_eq_integral_sq: Removed false positive@[nolint unusedArguments]memLp_of_abs_le_const: Removed unused(_ : 1 ≤ p) (_ : p ≠ ∞)parameters (MemLp.of_bound doesn't require them)abs_integral_mul_le_L2: Removed false positive@[nolint unusedArguments]All files now have zero nolint annotations and use only necessary parameters.
Module Summaries
Phase 3 Additions
Probability/Independence/Conditional.lean
Doob's characterization of conditional independence (reverse direction):
condIndep_of_indicator_condexp_eq: If E[1_H | mF ⊔ mG] = E[1_H | mG] a.e. for all H ∈ mH, then mF ⊥⊥ mH | mGMeasureTheory/Function/AEHelpers.lean
Utility for combining a.e. equalities:
finset_sum_ae_eq: Combine finitely many a.e. equalities into sum equalityProbability/ConditionalExpectation/Distributional.lean
Bridge from distributional equality to conditional expectation equality:
condexp_indicator_eq_of_pair_law_eq: If (Y,Z) and (Y',Z) have same law, then E[1_{Y∈B}|σ(Z)] = E[1_{Y'∈B}|σ(Z)] a.e.Earlier Phases
MeasureTheory/Function/LpHelpers.lean
Bridges ENNReal-valued Lp norms and Real-valued integrals:
eLpNorm_two_sq_eq_integral_sq: L² norm² = integral of squareabs_integral_mul_le_L2: Cauchy-Schwarz for L² functionssetIntegral_le_eLpNorm_mul_measure: |∫_A g| ≤ ‖g‖₂·√(μ A)MeasureTheory/MeasurableSpace/SigmaAlgebraHelpers.lean
Support for AEStronglyMeasurable with respect to infima:
aestronglyMeasurable_iInf_antitone: preservation under antitone infimaProbability/Kernel/ProductMeasurable.lean
Measurability of product measure kernels:
measurable_measure_pi: ω ↦ ∏ᵢ ν(ω) is measurableDesign Decisions
Exchangeability.*dependenciespropext,Classical.choice,Quot.soundisPiSystem_pi,generateFrom_pi(ProductMeasurable)condExp_mul_of_stronglyMeasurable_right(Lipschitz)Equiv.ofInjective(PermutationExtension)inter_indicator_one(Conditional)indicator_comp_right,setIntegral_indicator(Distributional)Axiom Verification
PR Sequencing (for future mathlib PRs)
Test plan
lake buildpassesReferences