#38957 chore(GroupTheory/DivisibleHull): remove backward.privateInPublic
In plain words
Housekeeping in Mathlib/GroupTheory/DivisibleHull.lean (the divisible hull -style construction of an ordered cancellative monoid ): removes every set_option backward.privateInPublic, the module-system escape hatch that let public declarations mention private ones. No statement changes. To make this work, the LE instance wraps the private lift_aux as (by exact lift_aux), archimedeanClassOrderIso is marked @[no_expose] (its body, built from private order homs, is no longer exposed to importers), and its two rfl simp lemmas become (rfl).
The transcriptions were written for revision 5a4b157; the PR is now at d7b559f. Check them against the code.
Transcriptions are drafted with an LLM from the diff and are a reading aid, not a verified statement: the Lean code is the reference.
PR description
Conversation on GitHub 4
PR summary d7b559f3c0
Import changes for modified files
No significant changes to the import graph
<details><summary>Import changes for all files</summary>
|Files|Import difference| |-|-|
</details>
<details><summary>
Declarations diff (regex)
</summary>
No declarations were harmed in the making of this PR! 🐙 <details> <summary>You can run this locally as follows</summary>
## 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>
</details>
The doc-module for scripts/pr_summary/declarations_diff.sh in the undefined repository contains some details about this script.
</details>
Declarations diff (Lean)
✅ Lean-aware diff — post-build, computed from the Lean environment (commit
d7b559f).
- +0 new declarations
- −0 removed declarations
No declaration differences.
<details><summary>Decrease in strong tech debt: (relative, absolute) = (3.11, 0.02)</summary>
|Current number|Change|Type (strong)| |-:|:-:|:-| |453|-6|backward.privateInPublic| |175|-2|backward.privateInPublic.warn| </details> No changes to weak technical debt.
Current commit d7b559f3c0 Reference commit 348837d3aa
This script lives in the undefined 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
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
Thanks for doing this! Looks sensible to me; let's have a domain expert double-check: maintainer merge?
🚀 Pull request has been placed on the maintainer queue by grunweg.
Hmm, some CI mysteriously timed out. Let me merge master
Mathlib/GroupTheory/DivisibleHull.lean +5 −12
end Groupprivate theorem lift_aux (m n m' n' : M) (s t s' t' : ℕ+)theorem archimedeanClassMk_mk_eq (m : M) (s s' : ℕ+) :private theorem aux_archimedeanClassOrderHom_injective :def archimedeanClassOrderHomInv : ArchimedeanClass (DivisibleHull M) →o ArchimI'm not sure that we want to hide the implementation of function-like objects, as a general pattern. The following also works:
def archimedeanClassOrderIso : ArchimedeanClass M ≃o ArchimedeanClass (DivisibleHull M) :=
OrderIso.ofHomInv (archimedeanClassOrderHom M) (archimedeanClassOrderHomInv M) (by
· ext a
induction a with | mk a
induction a with | mk m s
suffices ArchimedeanClass.mk (mk m 1) = ArchimedeanClass.mk (mk m s) by
simpa [archimedeanClassOrderHom, archimedeanClassOrderHomInv]
simp_rw [aux_archimedeanClassMk_mk]) (by
· ext a
induction a with | mk _
simp [archimedeanClassOrderHom, archimedeanClassOrderHomInv])
Except I'm not a big fan of how it looks stylistically, with the extra parentheses, and the (by tacked on to the end of the previous proof block.
Your code doesn't compile. The first error is
Unknown identifier `archimedeanClassOrderHom`
Note: A private declaration `archimedeanClassOrderHom` (from the current module) exists but would need to be public to access here.
The source of the error is that archimedeanClassOrderHom and archimedeanClassOrderHomInv are private, while archimedeanClassOrderIso, which would unfold to them with expose, is public.
As the original author of this file, my intention for declaring the first two def private was meant to make them implementation detail of the equivalence. In this particular case, I know that the two following simp lemma fully characterize the equivalence, so one doesn't need to unfold the def to use it.
I agree that we shouldn't follow the pattern to un-expose every function like def. I selected this particular one as I know it should be fine
Can you expand on what you mean with "I know it should be fine"? I think that for the sake of homogeneity of design patterns in Mathlib, both the equiv, and the two functions that implement the forward and backwards direction should be exposed.
Function applications can (and will) show up as arguments in dependent types. And in such cases, having the definition exposed will be quite important.
We are currently experimenting with how to make use of Lean's new module system, and I don't claim authoritative knowledge here. But my gut feeling is that we should only be hiding implementations of types, not of terms.
The "I know it should be fine" part was based on that it has sufficient lemma to uniquely determine such function. But I didn't think deep about the dependent type usage, and indeed I can see how it can create problem there. I'll apply your suggestion and make both forward and backward direction public for now
@jcommelin
As discussed in a reviewer channel, we should basically hide the implementation of declarations.
The lemma archimedeanClassOrderIso_apply (and *_symm_apply) is enough to identify archimedeanClassOrderIso M.
I think commit b6026c5 should be reverted.
Ok I have reverted b6026c5
@Komyyy I must have missed that discussion, and I am not convinced that we should hide the implementation of values.
@jcommelin
I think this dependent type problem can be solved by adding new cast operations like Fin.cast, Sym.cast and Path.cast.
I have opened a new toplic in the reviewer channel now.
@wwylele Please await our decision.
@wwylele Sorry for the wait. Following a decision in the reviewer channel, we concluded that it is better not to expose this definition.
Then I believe the current code is good. Thanks!
Zulip discussion is here: leanprover.zulipchat.com/#narrow/channel/345428-mathlib-reviewers/topic/Should.20we.20expose.20functions.3F
The conclusion seems to have been to wait 4 months, until 2026-11-06, until we know whether to @[no_expose]. So I'm marking this PR as awaiting-zulip until that gets resolved.
def archimedeanClassOrderIso : ArchimedeanClass M ≃o ArchimedeanClass (Divisib