Skip to content

feat(Data/Nat/Totient): totient of a pairwise coprime product - #45343

Open
thinkthoughts wants to merge 2 commits into
leanprover-community:masterfrom
thinkthoughts:totient-prod-primes
Open

thinkthoughts wants to merge 2 commits into
leanprover-community:masterfrom
thinkthoughts:totient-prod-primes

Conversation

@thinkthoughts

@thinkthoughts thinkthoughts commented Oct 27, 2026 •

Copy link
Copy Markdown

My PR adds a theorem for Euler's totient function over a product of natural numbers, where any two distinct factors have a greatest common divisor of 1.

It also adds a theorem for products of distinct primes, where each prime contributes its value minus one. The prime-specific result follows from the more general totient-product theorem.

Both results provide reusable statements in Mathlib using existing properties of Euler's totient function.


Validation: The revised PR passed all 12 applicable Mathlib CI checks, including build and lint checks. Two additional checks were skipped. No new imports or axioms introduced.

Research context: This comes from my work on the General Divisor Theorem and Lean prime-gap formalization; specifically consdering Euler's totient function and products of distinct primes.

General Divisor Theorem: https://github.com/thinkthoughts/general-divisor-theorem

Lean prime-gap formalization: https://github.com/thinkthoughts/lean-bgp212

Related (my initial) mathematical work: https://translatepi.ai/main.pdf

AI assistance: I used Claude to develop the Lean proofs, prepare the patch, and perform local compilation and lint checks. I used ChatGPT to review the mathematical specification and help identify a reusable Mathlib contribution. ChatGPT and DeepSeek also assisted with reviewing the sustainably optimized proof, and explaining its mathematical structure.

I read Cantor's diagonal argument in 2003 and have since directed my own work, and reviewed the results; so I'm responsible for the submitted work. And thanks for your help!

Add `Nat.totient_prod_primes`: for a finset `s` of primes,
`φ (∏ p ∈ s, p) = ∏ p ∈ s, (p - 1)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AjRwojYPe695zPRdrZ1Uik
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Oct 27, 2026
@github-actions

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to Zulip and join the Lean community.
Thank you again for joining our community.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

PR summary 3925850029

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ totient_prod_of_forall_prime
+ totient_prod_of_pairwise_coprime

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

  • +2 new declarations
  • −0 removed declarations
+Nat.totient_prod_of_forall_prime
+Nat.totient_prod_of_pairwise_coprime

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

Current commit 3925850029
Reference commit 8000f01d29

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

@github-actions github-actions Bot added the t-data Data (lists, quotients, numbers, etc) label Oct 27, 2026

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

Welcome!

Could you please add the LLM-generated label? See the contribution guide

Also could you rewrite the description yourself? It should be short and to the point. You can place any extra info below the fold (---)

Comment thread Mathlib/Data/Nat/Totient.lean Resolved
Comment thread Mathlib/Data/Nat/Totient.lean Resolved
@SnirBroshi SnirBroshi added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 27, 2026
@thinkthoughts

Copy link
Copy Markdown
Author

LLM-generated

@github-actions github-actions Bot added the LLM-generated PRs with substantial input from LLMs - review accordingly label Oct 27, 2026
Add `Nat.totient_prod_of_pairwise_coprime` and derive the prime case from
it. Rename `Nat.totient_prod_primes` to `Nat.totient_prod_of_forall_prime`,
as requested in review.
@thinkthoughts thinkthoughts changed the title feat(Data/Nat/Totient): totient of a product of distinct primes feat(Data/Nat/Totient): totient of a pairwise coprime product Oct 27, 2026
@thinkthoughts

Copy link
Copy Markdown
Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 27, 2026

/-- The totient of a product of pairwise coprime factors is the product of their totients. -/
theorem totient_prod_of_pairwise_coprime {ι : Type*} {s : Finset ι} {f : ι → ℕ}
(hs : Set.Pairwise s <| Coprime.onFun f) : φ (∏ i ∈ s, f i) = ∏ i ∈ s, φ (f i) := by

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.

Really I feel like we ought to prove this for ArithmeticFunction.IsMultiplicative rather than duplicating the proof for each multiplicative function separately. The totient as an arithmetic function is here: #46097

@tb65536 tb65536 added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Nov 20, 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. LLM-generated PRs with substantial input from LLMs - review accordingly new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants