Skip to content

refactor(Data/Nat/Factorization/Defs): redefine Nat.factorization in terms of primeFactorsList instead of padicValNat - #43581

Open
tb65536 wants to merge 3 commits into
leanprover-community:masterfrom
tb65536:tb_natfac
Open

refactor(Data/Nat/Factorization/Defs): redefine Nat.factorization in terms of primeFactorsList instead of padicValNat#43581
tb65536 wants to merge 3 commits into
leanprover-community:masterfrom
tb65536:tb_natfac

Conversation

@tb65536

@tb65536 tb65536 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This PR redefines Nat.factorization in terms of primeFactorsList instead of padicValNat. This will allow Nat.factorization to remain computable even as padicValNat is deprecated in favor of the non-computable multiplicity.


Open in Gitpod

@tb65536 tb65536 added awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. t-number-theory Number theory (also use t-algebra or t-analysis to specialize) t-algebra Algebra (groups, rings, fields, etc) labels Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

PR summary c52578998d

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

No declarations were harmed in the making of this PR! 🐙

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

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


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

Current commit c52578998d
Reference commit 1d97a98f34

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 Sep 8, 2026
@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 Sep 8, 2026
of `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/
@[simp]
theorem primeFactorsList_count_eq {n p : ℕ} : n.primeFactorsList.count p = n.factorization p := by
theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to now rename this, and deprecate this _def version?

Suggested change
theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by
theorem factorization_eq_padicValNat (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by

@tb65536 tb65536 Sep 8, 2026

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.

Well, we want both statements (connecting Nat.factorization with both Nat.primeFactorsList and padicValNat (which will eventually be replaced by multiplicity)), and I thought that renaming might be a bit confusing deprecation-wise for now.

@jcommelin jcommelin added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 8, 2026
@tb65536 tb65536 removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 8, 2026
@b-mehta

b-mehta commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

computable even as padicValNat is deprecated in favor of the non-computable multiplicity.

Hold on, can't we define Nat.factorization in terms of Nat.maxPowDvdDiv, which is the efficient one used by padicValNat anyway? Then we get computability, efficiency, and we can safely kill multiplicity.

@b-mehta

b-mehta commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

If you don't like my previous idea, then maybe Multiset.toFinsupp should be used, since you're building the finsupp out of a list (via a multiset) anyway

@SnirBroshi

Copy link
Copy Markdown
Collaborator

Multiset.toFinsupp is noncomputable

@tb65536

tb65536 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Hold on, can't we define Nat.factorization in terms of Nat.maxPowDvdDiv, which is the efficient one used by padicValNat anyway? Then we get computability, efficiency, and we can safely kill multiplicity.

It's not any more efficient unfortunately, since you still need to compute n.primeFactors.

@b-mehta

b-mehta commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Multiset.toFinsupp is noncomputable

that's so annoying - it's just because it's bundled. the .toFun field is computable :/

@SnirBroshi

Copy link
Copy Markdown
Collaborator

Yeah, maybe it should be split to toFinsupp and toFinsuppAddEquiv

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

Labels

t-algebra Algebra (groups, rings, fields, etc) t-data Data (lists, quotients, numbers, etc) t-number-theory Number theory (also use t-algebra or t-analysis to specialize)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants