Skip to content

feat(Algebra/Group/Units/Hom): the units of a torsion-free monoid are torsion-free - #46840

Open
MichaelStollBayreuth wants to merge 2 commits into
leanprover-community:masterfrom
MichaelStollBayreuth:MS_SUnits_2
Open

MichaelStollBayreuth wants to merge 2 commits into
leanprover-community:masterfrom
MichaelStollBayreuth:MS_SUnits_2

Conversation

@MichaelStollBayreuth

@MichaelStollBayreuth MichaelStollBayreuth commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

The units of a torsion-free monoid are torsion-free; the units of a monoid with unique roots have unique roots. We add suitable instances based on the injectivity of Mˣ →* M.

A later PR uses unique roots in (FractionalIdeal R⁰ K)ˣ for a Dedekind domain R. At present no instance finds them, although FractionalIdeal R⁰ K has unique roots.

🤖 Claude Code helped with this PR.


  • MulOpposite, Prod, Pi and Subgroup have these instances already. They are in Units/Hom.lean because Function.Injective.isMulTorsionFree needs MonoidHom.
  • Benchmarking this shows no negative impact beyond noise level.

@MichaelStollBayreuth MichaelStollBayreuth added t-algebra Algebra (groups, rings, fields, etc) LLM-generated PRs with substantial input from LLMs - review accordingly labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR summary 0557a282de

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ instance [HasUniqueRoots M] : HasUniqueRoots Mˣ
+ instance [IsMulTorsionFree M] : IsMulTorsionFree Mˣ

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 0557a28).

  • +4 new declarations
  • −0 removed declarations
+AddUnits.instIsAddTorsionFree
+AddUnits.insthasUniqueDiv
+Units.instHasUniqueRoots
+Units.instIsMulTorsionFree

No changes to strong technical debt.
No changes to weak technical debt.

Current commit 0557a282de
Reference commit 5d21013d38

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

@MichaelStollBayreuth

Copy link
Copy Markdown
Contributor Author

!radar

@leanprover-radar

leanprover-radar commented Dec 1, 2026 •

Copy link
Copy Markdown

Benchmark results for 0a54377 against 5d21013 are in. No significant results found. @MichaelStollBayreuth

  • 🟥 build//instructions: +805.3M (+0.00%)

Small changes (3✅, 9🟥)

  • 12 hidden

Comment thread Mathlib/Algebra/Group/Units/Hom.lean Outdated
Comment on lines +123 to +127
instance instIsMulTorsionFree [IsMulTorsionFree M] : IsMulTorsionFree Mˣ :=
coeHom_injective.isMulTorsionFree _

@[to_additive AddUnits.instHasUniqueDiv] -- the dictionary gives `insthasUniqueDiv`
instance instHasUniqueRoots [HasUniqueRoots M] : HasUniqueRoots Mˣ :=

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would suggest not naming them at all:

Suggested change
instance instIsMulTorsionFree [IsMulTorsionFree M] : IsMulTorsionFree Mˣ :=
coeHom_injective.isMulTorsionFree _
@[to_additive AddUnits.instHasUniqueDiv] -- the dictionary gives `insthasUniqueDiv`
instance instHasUniqueRoots [HasUniqueRoots M] : HasUniqueRoots Mˣ :=
instance [IsMulTorsionFree M] : IsMulTorsionFree Mˣ :=
coeHom_injective.isMulTorsionFree _
@[to_additive]
instance [HasUniqueRoots M] : HasUniqueRoots Mˣ :=

Unless you have a very specific use case that needs their names.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess it's not within scope of this PR, but since it's so short, why not change the second projection of line 344 in Mathlib/Tactic/Translate/ToAdditive.lean from hasUniqueDiv to HasUniqueDiv. :)

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 would suggest not naming them at all

OK; I don't think we need to refer to them explicitly.

I guess it's not within scope of this PR, but since it's so short, why not change the second projection of line 344 in Mathlib/Tactic/Translate/ToAdditive.lean from hasUniqueDiv to HasUniqueDiv. :)

I can do that, but I think this is better done separately. Claude tells me that it needs a couple further edits (e.g., in attribute [to_additive existing HasUniqueDiv] HasUniqueRoots, the existing part is then no longer necessary and in fact gives a warning or error).

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.

@Multramate

Multramate commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Opus tells me these instances give a loop:

HasUniqueRoots M ← UniqueFactorizationMonoid.instHasUniqueRoots ← IsMulTorsionFree Mˣ ← Units.instIsMulTorsionFree ← IsMulTorsionFree M ← instIsMulTorsionFreeOfHasUniqueRoots ← HasUniqueRoots M ← instIsMulTorsionFreeOfHasUniqueRoots ← HasUniqueRoots Mˣ ← Units.instHasUniqueRoots ← HasUniqueRoots M

To reproduce:

import Mathlib.Algebra.GroupWithZero.Torsion
import Mathlib.RingTheory.Int.Basic

set_option pp.explicit true in
set_option trace.Meta.synthInstance true in
example : HasUniqueRoots ℤ := inferInstance

Radar doesn't show any slowdowns, because presumably there aren't many files that import both? Maybe this is OK.

@MichaelStollBayreuth

Copy link
Copy Markdown
Contributor Author

Loops in instance search should be OK; they should be broken automatically when something repeats. (At least, this is my understanding. It used to be different (in Lean 3?).)

@Multramate Multramate left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@tb65536 tb65536 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!

maintainer merge

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

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

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Dec 2, 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

LLM-generated PRs with substantial input from LLMs - review accordingly maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-algebra Algebra (groups, rings, fields, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants