mathlib4 review helperopen PRs by @wwylele on leanprover-community/mathlib4

← queue

#38957 chore(GroupTheory/DivisibleHull): remove backward.privateInPublic

tech debt awaiting-zulip t-group-theory CI success

+5 −12 · 1 file · 7 commits · head d7b559f · updated 10 days ago · Files changed on GitHub

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

![Open in Gitpod](gitpod.io/from-referrer/)

Conversation on GitHub 4
github-actions[bot] · comment · 2026-05-05
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 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 · commented · 2026-05-05

Thanks for doing this! Looks sensible to me; let's have a domain expert double-check: maintainer merge?

github-actions[bot] · comment · 2026-05-05

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

wwylele · comment · 2026-05-05

Hmm, some CI mysteriously timed out. Let me merge master

Mathlib/GroupTheory/DivisibleHull.lean +5 −12

end Group
253section LinearOrder
254variable {M : Type*} [AddCommMonoid M] [LinearOrder M] [IsOrderedCancelAddMonoid M]
−set_option backward.privateInPublic true in
256private theorem lift_aux (m n m' n' : M) (s t s' t' : ℕ+)
257 (h : mk m s = mk m' s') (h' : mk n t = mk n' t') :
258 (t.val • m ≤ s.val • n) = (t'.val • m' ≤ s'.val • n') := by
private theorem lift_aux (m n m' n' : M) (s t s' t' : ℕ+)
264 · simp_rw [smul_smul, ← mul_rotate s'.val, ← smul_smul, ← h', smul_smul]
265 ring_nf
−set_option backward.privateInPublic true in
−set_option backward.privateInPublic.warn false in
instance (anonymous instance) changedL267–268
267instance : LE (DivisibleHull M) where
− le x y := liftOn₂ x y (fun m s n t ↦ t.val • m ≤ s.val • n) lift_aux
268 le x y := liftOn₂ x y (fun m s n t ↦ t.val • m ≤ s.val • n) (by exact lift_aux)
270@[simp]
271theorem mk_le_mk {m m' : M} {s s' : ℕ+} :
theorem archimedeanClassMk_mk_eq (m : M) (s s' : ℕ+) :
366 exact this
367 simp_rw [zsmul_mk, mk_eq_mk_iff_smul_eq_smul, natCast_zsmul, smul_smul, mul_comm s'.val]
−set_option backward.privateInPublic true in
369variable (M) in
370/-- Forward direction of `archimedeanClassOrderIso`. -/
371private noncomputable
372def archimedeanClassOrderHom : ArchimedeanClass M →o ArchimedeanClass (DivisibleHull M) :=
373 ArchimedeanClass.orderHom (coeOrderAddMonoidHom M)
−set_option backward.privateInPublic true in
375/-- See `archimedeanClassOrderIso_symm_apply` for public API. -/
376private theorem aux_archimedeanClassMk_mk (m : M) (s : ℕ+) :
377 ArchimedeanClass.mk (mk m s) = archimedeanClassOrderHom M (ArchimedeanClass.mk m) := by
private theorem aux_archimedeanClassOrderHom_injective :
383 Function.Injective (archimedeanClassOrderHom M) :=
384 ArchimedeanClass.orderHom_injective coe_injective
−set_option backward.privateInPublic true in
386variable (M) in
387/-- Backward direction of `archimedeanClassOrderIso`. -/
388private noncomputable
def archimedeanClassOrderHomInv : ArchimedeanClass (DivisibleHull M) →o Archim
399 simpa using ((archimedeanClassOrderHom M).monotone.strictMono_of_injective
400 aux_archimedeanClassOrderHom_injective).le_iff_le.mp h)
−set_option backward.privateInPublic true in
−set_option backward.privateInPublic.warn false in
402variable (M) in
403/-- The Archimedean classes of `DivisibleHull M` are the same as those of `M`. -/
−noncomputable
404@[no_expose] noncomputable
jcommelin · 2026-05-11

I'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.

wwylele · 2026-05-11

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

jcommelin · 2026-05-12

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.

wwylele · 2026-05-12

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

Komyyy · 2026-05-18

@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.

wwylele · 2026-05-18

Ok I have reverted b6026c5

jcommelin · 2026-05-19

@Komyyy I must have missed that discussion, and I am not convinced that we should hide the implementation of values.

Komyyy · 2026-05-19

@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.

Komyyy · 2026-05-26

@wwylele Sorry for the wait. Following a decision in the reviewer channel, we concluded that it is better not to expose this definition.

wwylele · 2026-05-26

Then I believe the current code is good. Thanks!

Vierkantor · 2026-07-24

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.

405def archimedeanClassOrderIso : ArchimedeanClass M ≃o ArchimedeanClass (DivisibleHull M) := by
406 apply OrderIso.ofHomInv (archimedeanClassOrderHom M) (archimedeanClassOrderHomInv M)
407 · ext a
def archimedeanClassOrderIso : ArchimedeanClass M ≃o ArchimedeanClass (Divisib
theorem archimedeanClassOrderIso_apply changedL417–419
417@[simp]
418theorem archimedeanClassOrderIso_apply (a : ArchimedeanClass M) :
− archimedeanClassOrderIso M a = ArchimedeanClass.orderHom (coeOrderAddMonoidHom M) a := rfl
419 archimedeanClassOrderIso M a = ArchimedeanClass.orderHom (coeOrderAddMonoidHom M) a := (rfl)
theorem archimedeanClassOrderIso_symm_apply changedL421–424
421@[simp]
422theorem archimedeanClassOrderIso_symm_apply (m : M) (s : ℕ+) :
− (archimedeanClassOrderIso M).symm (ArchimedeanClass.mk (mk m s)) = ArchimedeanClass.mk m := rfl
423 (archimedeanClassOrderIso M).symm (ArchimedeanClass.mk (mk m s)) = ArchimedeanClass.mk m :=
424 (rfl)
426end OrderedGroup
0/3 declarations checked

Your review, as Markdown

Paste it as a comment or a review on the PR. Line links to the head commit unfold into code snippets on GitHub.