Skip to content

chore: replace irreducible_def with no_expose - #45063

Open
JovanGerb wants to merge 15 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-irreducible_def-no_expose
Open

JovanGerb wants to merge 15 commits into
leanprover-community:masterfrom
JovanGerb:Jovan-irreducible_def-no_expose

Conversation

@JovanGerb

@JovanGerb JovanGerb commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

The no_expose attribute can be used in place of irreducible_def, and leads to easier proofs because the definition can be unfolded the file containing the definition.

Another difference is that by using no_expose, the definition value is not exported at all, so in downstream modules it cannot be unfolded with e.g. rw [foo] or rw [foo_def]. Instead, a public lemma like foo_def needs to be added explicitly. This PR does that where necessary. If there is no such lemma, but you still need access to the definition value, import all can be used as a workaround.

Since mathlib now enforces downstream users to use the module system, we don't need to worry about downstream users that don't see the effects of no_expose.


@github-actions github-actions Bot added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

PR summary 2597daab16

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ AnalyticSet
+ DirectSum.IsInternal.sigmaOrthonormalBasisIndexEquiv
+ DirectSum.IsInternal.subordinateOrthonormalBasis
+ DirectSum.IsInternal.subordinateOrthonormalBasisIndex
+ IsBigO
+ IsBigOWith
+ IsBigOWith_def
+ IsBigO_def
+ IsKInjective.homotopyZero
+ IsKProjective.homotopyZero
+ IsLittleO
+ IsLittleO_def
+ IsMeasurableRatCDF.stieltjesFunctionAux
+ IsMeasurableRatCDF.stieltjesFunctionAux_def
+ MeasureTheory.Measure.finiteSpanningSetsInOpen'
+ Module.rank
+ Module.rank_def
+ SNormLESNormFDerivOfEqConst
+ Span.repr
+ _root_.AlternatingMap.measure
+ _root_.MeasureTheory.Measure.condKernel
+ addHaar
+ addHaar_def
+ areaForm
+ canonicalEquiv
+ cfc
+ cfcₙ
+ cfcₙ_def
+ compProd
+ condDistrib
+ condExp
+ condExpKernel
+ condKernel
+ condLExp
+ curveIntegral
+ curveIntegralFun
+ curveIntegralFun_def'
+ curveIntegral_def'
+ det
+ detAux
+ det_def
+ div
+ eLpNormLESNormFDerivOfLeConst
+ eLpNormLESNormFDerivOneConst
+ eigenvalues
+ eigenvectorBasis
+ erase
+ eval₂
+ eval₂_def
+ exp_def
+ fderiv
+ fderivWithin
+ fderivWithin_def
+ finprod
+ finprod_def'
+ firstDiff
+ firstDiff_def
+ gradedMul
+ hasLocalizationOfLocallySmall'
+ hausdorffEDist
+ hausdorffEDist_def
+ inf
+ instance (b : Basis ι ℝ E) : SigmaFinite b.addHaar
+ instance _root_.isAddHaarMeasure_basis_addHaar (b : Basis ι ℝ E) : IsAddHaarMeasure b.addHaar
+ inv'
+ killCopies
+ klDiv
+ le
+ liftAlgHom
+ liftOn
+ liftOn'
+ liftOn'_def
+ lintegral
+ lintegralPowLePowLIntegralFDerivConst
+ lintegral_def
+ lipschitzExtensionConstant
+ log
+ lt
+ map
+ map_def
+ measure
+ minSmoothness
+ mk
+ mkAlgHom
+ mkRingHom
+ mulEquiv
+ mul_def'
+ nhds
+ nhds_def
+ nonlinearRightInverseOfSurjective
+ oneTangentSpaceIcc
+ p
+ parallelComp
+ pathELength
+ pi
+ preLift
+ preLiftAlgHom
+ prod
+ prod_eq_zero_of_not_sfinite
+ riemannianEDist
+ riemannianEDist_def
+ rightAngleRotation
+ rightAngleRotationAux₁
+ rightCont
+ smeval
+ smul
+ stdOrthonormalBasis
+ sub
+ sup
+ tangentConeAt
+ tangentConeAt_def
+ toMeasurable
+ toMeasurable_def
+ toPrincipalIdeal
+ tprod
+ tprod_def
+ vitaliFamily
+ volumeForm
++ add
++ exp
++ integral
++ inv
++ lift
++ neg
++ one
++ rnDeriv
++ singularPart
++ zero
+++ mul
+++ of
+++ ι
- instance (b : Basis ι ℝ E) : SigmaFinite b.addHaar := by
- instance _root_.isAddHaarMeasure_basis_addHaar (b : Basis ι ℝ E) : IsAddHaarMeasure b.addHaar := by

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 2597daa).

  • +2 new declarations
  • −91 removed declarations
-AkraBazziRecurrence.p_def
-AlternatingMap.measure.congr_simp
-AlternatingMap.measure_def
-CategoryTheory.InjectiveResolution.of_def
-CategoryTheory.MorphismProperty.hasLocalizationOfLocallySmall'_def
-CategoryTheory.ProjectiveResolution.of_def
-CochainComplex.IsKInjective.homotopyZero_def
-CochainComplex.IsKProjective.homotopyZero_def
-ContinuousLinearMap.nonlinearRightInverseOfSurjective_def
-DirectSum.IsInternal.sigmaOrthonormalBasisIndexEquiv_def
-DirectSum.IsInternal.subordinateOrthonormalBasisIndex_def
-DirectSum.IsInternal.subordinateOrthonormalBasis_def
-FractionalIdeal.canonicalEquiv_def
-FreeAlgebra.ι_def
-InformationTheory.klDiv_def
-IsFractionRing.inv_def
-IsFreeAddGroup.addEquiv_def
-IsFreeGroup.mulEquiv_def
-IsSepClosed.lift_def
-IsUnifLocDoublingMeasure.vitaliFamily.congr_simp
-IsUnifLocDoublingMeasure.vitaliFamily_def
-LinearAlgebra.FreeProduct.of_def
-LinearAlgebra.FreeProduct.ι_def
-LinearMap.IsSymmetric.eigenvalues_def
-LinearMap.IsSymmetric.eigenvectorBasis_def
-LinearMap.detAux_def
-Manifold.pathELength_def
-MeasureTheory.AnalyticSet_def
-MeasureTheory.Filtration.rightCont_def
-MeasureTheory.L1.integral_def
-MeasureTheory.Measure.condKernel_def
-MeasureTheory.Measure.finiteSpanningSetsInOpen'_def
+MeasureTheory.Measure.nonempty_of_not_aemeasurable
-MeasureTheory.Measure.pi_def
-MeasureTheory.Measure.prod_def
+MeasureTheory.Measure.prod_eq_zero_of_not_sfinite
-MeasureTheory.Measure.rnDeriv_def
-MeasureTheory.Measure.singularPart_def
-MeasureTheory.SNormLESNormFDerivOfEqConst_def
-MeasureTheory.condExp_def
-MeasureTheory.condLExp_def
-MeasureTheory.eLpNormLESNormFDerivOfLeConst_def
-MeasureTheory.eLpNormLESNormFDerivOneConst_def
-MeasureTheory.integral_def
-MeasureTheory.lintegralPowLePowLIntegralFDerivConst_def
-NormedSpace.exp_def
-NormedSpace.log_def
-Orientation.areaForm_def
-Orientation.rightAngleRotationAux₁_def
-Orientation.rightAngleRotation_def
-Orientation.volumeForm_def
-Polynomial.erase_def
-Polynomial.smeval_def
-ProbabilityTheory.Kernel.compProd_def
-ProbabilityTheory.Kernel.condKernel_def
-ProbabilityTheory.Kernel.parallelComp_def
-ProbabilityTheory.Kernel.rnDeriv_def
-ProbabilityTheory.Kernel.singularPart_def
-ProbabilityTheory.condDistrib_def
-ProbabilityTheory.condExpKernel_def
-RatFunc.add_def
-RatFunc.div_def
-RatFunc.inv_def
-RatFunc.liftOn_def
-RatFunc.mk_def
-RatFunc.mul_def
-RatFunc.neg_def
-RatFunc.one_def
-RatFunc.smul_def
-RatFunc.sub_def
-RatFunc.zero_def
-RingQuot.liftAlgHom_def
-RingQuot.lift_def
-RingQuot.mkAlgHom_def
-RingQuot.mkRingHom_def
-RingQuot.preLift.congr_simp
-RingQuot.preLiftAlgHom.congr_simp
-RingQuot.preLiftAlgHom_def
-RingQuot.preLift_def
-SimpleGraph.killCopies_def
-Span.repr_def
-StieltjesFunction.measure_def
-TensorAlgebra.ι_def
-TensorProduct.gradedMul_def
-cfc_def
-fderiv_def
-lipschitzExtensionConstant_def
-minSmoothness_def
-oneTangentSpaceIcc_def
-pullbackTopology
-pullbackTopology_def
-stdOrthonormalBasis_def
-toPrincipalIdeal_def

Decrease in strong tech debt: (relative, absolute) = (1.94, 0.02)
Current number Change Type (strong)
486 -3 backward.privateInPublic
196 -2 backward.privateInPublic.warn
385 -1 adaptation notes
Decrease in weak tech debt: (relative, absolute) = (8.00, 0.00)
Current number Change Type (weak)
5095 -8 exposed public sections

Current commit 2597daab16
Reference commit d88814353f

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@grunweg grunweg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! I've reviewed the first quarter of the PR so far, and have one and a half questions.

theorem mkAlgHom_surjective (s : A → A → Prop) : Function.Surjective (mkAlgHom S s) := by
suffices Function.Surjective fun x ↦ (⟨.mk (Rel s) x⟩ : RingQuot s) by
simpa [mkAlgHom_def, mkRingHom_def]
change Function.Surjective fun x ↦ (⟨.mk (Rel s) x⟩ : RingQuot s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment on this change (no pun intended)? change is usually a bit of a code smell.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that the simpa proof could be replaced by rfl, and then suffices ... by rfl is equivalent to change ....

simp only [preLiftAlgHom_def, mkAlgHom_def, mkRingHom_def,
AlgHom.coe_comp, AlgHom.coe_mk, RingHom.coe_mk,
MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply] }
left_inv := fun f ↦ by rfl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say a word why this is fine? You're rewriting by _def lemmas, sure (no questions), but you also have the coercion composition lemmas. I worry about us creating heavy rfl's here... can you convince me otherwise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the lemmas in the simp only are basic coercion/application lemmas that are fine to unfold via rfl.

Comment thread Mathlib/Algebra/BigOperators/Finprod.lean
@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 20, 2026
@grunweg grunweg self-assigned this Oct 20, 2026

@grunweg grunweg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done reviewing except for two files: just a few more comments.


-/

@[expose] public section

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a meta def below... but I presume un-exposing that is fine.

Comment thread Mathlib/MeasureTheory/Measure/Map.lean
Comment thread Mathlib/Probability/Kernel/Disintegration/MeasurableStieltjes.lean Outdated
@grunweg

grunweg commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

(I'll be happy to review further once this passes CI; I understand there's some more work needed here.)

@grunweg grunweg added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Oct 20, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

!radar

@leanprover-radar

leanprover-radar commented Oct 22, 2026 •

Copy link
Copy Markdown

Benchmark results for 5a9dfe3 against ca99799 are in. There are significant results. @JovanGerb

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Runner for run main has different system configurations between commits.
  • ✅ build//instructions: -56.3G (-0.05%)

Large changes (1✅, 1🟥)

  • ✅ build/module/Mathlib.Analysis.Analytic.Composition//instructions: -6.1G (-11.86%)
  • 🟥 build/module/Mathlib.LinearAlgebra.TensorProduct.Graded.External//instructions: +9.2G (+22.55%)

Medium changes (4✅, 3🟥)

  • 🟥 build/module/Mathlib.Algebra.Polynomial.Eval.Defs//instructions: +1.1G (+6.82%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.FunctionalSpaces.SobolevInequality//instructions: -1.0G (-2.20%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.PiL2//instructions: -1.2G (-1.29%)
  • 🟥 build/module/Mathlib.MeasureTheory.Constructions.Pi//instructions: +3.0G (+10.77%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Probability.Kernel.Category.SFinKer//instructions: -9.1G (-26.59%)
  • ✅ build/module/Mathlib.Topology.Algebra.InfiniteSum.ENNReal//instructions: -3.0G (-12.19%) (reduced significance based on absolute threshold)
  • 🟥 open-mathlib//maxrss: +37MiB (+1.37%)

Small changes (94✅, 9🟥)

  • ✅ build/module/Batteries.CodeAction//instructions: -214.0k (-0.03%)
  • ✅ build/module/Batteries.Control.ForInStep//instructions: -216.8k (-0.04%)
  • ✅ build/module/Batteries.Data.Array//instructions: -215.7k (-0.04%)
  • ✅ build/module/Batteries.Data.AssocList//instructions: -225.7k (-0.04%)
  • ✅ build/module/Batteries.Data.BinaryHeap//instructions: -230.3k (-0.04%)
  • ✅ build/module/Batteries.Data.BinomialHeap//instructions: -221.2k (-0.03%)
  • ✅ build/module/Batteries.Data.BitVec//instructions: -231.1k (-0.04%)
  • ✅ build/module/Batteries.Data.Char//instructions: -237.3k (-0.03%)
  • ✅ build/module/Batteries.Data.DList//instructions: -219.6k (-0.04%)
  • ✅ build/module/Batteries.Data.Float//instructions: -218.0k (-0.04%)
  • ✅ build/module/Batteries.Data.HashMap//instructions: -216.6k (-0.04%)
  • ✅ build/module/Batteries.Data.List//instructions: -222.3k (-0.04%)
  • ✅ build/module/Batteries.Data.MLList//instructions: -210.3k (-0.04%)
  • ✅ build/module/Batteries.Data.Nat.Bitwise//instructions: -233.3k (-0.04%)
  • ✅ build/module/Batteries.Data.Nat//instructions: -223.0k (-0.04%)
  • ✅ build/module/Batteries.Data.Random//instructions: -242.9k (-0.04%)
  • ✅ build/module/Batteries.Data.Range//instructions: -238.3k (-0.04%)
  • ✅ build/module/Batteries.Data.String.AsciiCasing//instructions: -219.6k (-0.04%)
  • ✅ build/module/Batteries.Data.UnionFind//instructions: -241.7k (-0.04%)
  • ✅ build/module/Batteries.Data.Vector//instructions: -230.6k (-0.04%)
  • and 83 more

@github-actions github-actions Bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Oct 22, 2026
@JovanGerb

Copy link
Copy Markdown
Contributor Author

!radar

@leanprover-radar

leanprover-radar commented Oct 22, 2026 •

Copy link
Copy Markdown

Benchmark results for 131fd44 against d888143 are in. There are significant results. @JovanGerb

  • ✅ build//instructions: -24.1G (-0.02%)

Large changes (1✅, 1🟥)

  • ✅ build/module/Mathlib.Analysis.Analytic.Composition//instructions: -6.1G (-11.85%)
  • 🟥 build/module/Mathlib.LinearAlgebra.TensorProduct.Graded.External//instructions: +9.2G (+22.55%)

Medium changes (5✅, 2🟥)

  • 🟥 build/module/Mathlib.Algebra.Polynomial.Eval.Defs//instructions: +1.1G (+6.83%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.FunctionalSpaces.SobolevInequality//instructions: -1.0G (-2.19%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.PiL2//instructions: -1.2G (-1.32%)
  • 🟥 build/module/Mathlib.MeasureTheory.Constructions.Pi//instructions: +3.0G (+10.77%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Probability.Kernel.Category.SFinKer//instructions: -9.1G (-26.56%)
  • ✅ build/module/Mathlib.Topology.Algebra.InfiniteSum.ENNReal//instructions: -3.0G (-12.12%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Topology.Algebra.InfiniteSum.Order//instructions: -2.0G (-7.57%) (reduced significance based on absolute threshold)

Small changes (65✅, 9🟥)

  • ✅ build/module/Mathlib.Algebra.BigOperators.Finprod//instructions: -85.6M (-0.24%)
  • ✅ build/module/Mathlib.Algebra.FreeAlgebra//instructions: -145.6M (-1.15%)
  • ✅ build/module/Mathlib.Algebra.Homology.HomotopyCategory.KInjective//instructions: -151.6M (-1.37%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Algebra.Homology.HomotopyCategory.KProjective//instructions: -154.1M (-2.79%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Algebra.Polynomial.Basic//instructions: -89.2M (-0.33%)
  • ✅ build/module/Mathlib.Algebra.Polynomial.Smeval//instructions: -101.3M (-1.03%)
  • ✅ build/module/Mathlib.Algebra.RingQuot//instructions: -1.1G (-7.34%) (reduced significance based on *//lines)
  • 🟥 build/module/Mathlib.Analysis.Asymptotics.Basic//instructions: +250.4M (+2.00%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.Asymptotics.Defs//instructions: -159.1M (-2.92%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.Asymptotics.Prod//instructions: -58.3M (-1.02%)
  • ✅ build/module/Mathlib.Analysis.Calculus.FDeriv.Defs//instructions: -150.4M (-2.23%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Mathlib.Analysis.Calculus.ParametricIntegral//instructions: +275.4M (+1.32%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.Calculus.TangentCone.Defs//instructions: -31.3M (-0.75%)
  • ✅ build/module/Mathlib.Analysis.Complex.CauchyIntegral//instructions: -130.6M (-0.50%)
  • 🟥 build/module/Mathlib.Analysis.Complex.Exponential//instructions: +268.8M (+0.92%) (reduced significance based on *//lines)
  • ✅ build/module/Mathlib.Analysis.Complex.Periodic//instructions: -38.4M (-0.39%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.Completion//instructions: -56.5M (-0.74%)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.Orientation//instructions: -273.0M (-1.55%) (reduced significance based on absolute threshold)
  • ✅ build/module/Mathlib.Analysis.InnerProductSpace.Spectrum//instructions: -281.4M (-0.96%) (reduced significance based on *//lines)
  • 🟥 build/module/Mathlib.Analysis.InnerProductSpace.TwoDim//instructions: +367.8M (+1.13%) (reduced significance based on absolute threshold)
  • and 54 more

@grunweg

grunweg commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Diff to this point looks good: is there anything else to do for this PR, or shall I bors it?

@JovanGerb

Copy link
Copy Markdown
Contributor Author

Yes, I think it is ready now.

There may be downstream uses that rely on some of these definitions where I haven't added a corresponding public _def lemma. Those can be added later if desired, and can be fixed short-term using import all.

@grunweg grunweg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a bit more on this:

There may be downstream uses that rely on some of these definitions

How can downstream users break? Thanks!

Comment thread Mathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/NonUnital.lean Outdated
@JovanGerb

JovanGerb commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

When using irreducible_def foo, it gives you access to rw [foo] and to rw [foo_def] in later files. However when you use no_expose, then the value is really not exported at all, so the above methods don't work. To fix this, I added foo_def lemmas for some of the unexposed definitions, but only for those that needed it in mathlib.

@grunweg

grunweg commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

I see. Can you add one sentence about this to the PR description, how this is theoretically a breaking change (and how to mitigate it)? That would be excellent.

@grunweg

grunweg commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

With the above addressed, I think this is good to go and worthwhile clean-up. I'll wait for 24 hours in case another maintainer (or reviewer) feels strongly about further details; if not, I'll merge then.
maintainer delegate?

@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by grunweg.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Oct 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants