Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Nat): Nat factorization multiplicity #22503

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Kevew
Copy link
Collaborator

@Kevew Kevew commented Mar 3, 2025

Ported lemmas from Data/Nat/Multiplicity to into a new file called Data/Nat/Factorization/Multiplicity, re-written in terms of factorization.

Also, I'm new to this so is it fine to have a lemma copied over from another file? Like, I copied over

@[simp]
theorem Prime.factorization_self {p : ℕ} (hp : Prime p) : p.factorization p = 1 := by simp [hp]

from Dat/Nat/Factorization/Basic.


Open in Gitpod

@Kevew Kevew added awaiting-CI new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! labels Mar 3, 2025
@Kevew Kevew self-assigned this Mar 3, 2025
Copy link

github-actions bot commented Mar 3, 2025

PR summary cddbb691c5

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Data.Nat.Factorization.Multiplicity (new file) 872

Declarations diff

+ factorization_choose
+ factorization_choose'
+ factorization_choose_prime_pow
+ factorization_choose_prime_pow_add_factorization
+ factorization_eq_card_pow_dvd₀
+ factorization_factorial
+ factorization_factorial_le_div_pred
+ factorization_factorial_mul
+ factorization_factorial_mul_succ
+ factorization_le_factorization_choose_add
+ factorization_le_factorization_of_dvd_right
+ factorization_mul₀
+ factorization_pow_self
+ factorization_pow₀
+ factorization_prod₀
+ multiplicity_choose_aux
+ sub_one_mul_factorization_factorial

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh 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 t-data Data (lists, quotients, numbers, etc) and removed awaiting-CI labels Mar 3, 2025
@Paul-Lez Paul-Lez self-requested a review March 3, 2025 17:27
Comment on lines 122 to 123
have p1: n + 1 ≠ 0 := by exact Ne.symm (zero_ne_add_one n)
apply factorization_mul₀ p1 (factorial_ne_zero n)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that you should be able to avoid using new lemmas such as factorization_mul₀ by using already existing API for factorization and Finsupp.

Suggested change
have p1: n + 10 := by exact Ne.symm (zero_ne_add_one n)
apply factorization_mul₀ p1 (factorial_ne_zero n)
_ = (n + 1).factorization p + (n !).factorization p := by
rw [factorization_mul (zero_ne_add_one n).symm (factorial_ne_zero n), coe_add, Pi.add_apply]

One useful trick for finding such lemmas when you're writing proofs is to use the simp? tactic.

Copy link
Collaborator Author

@Kevew Kevew Mar 3, 2025

Choose a reason for hiding this comment

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

Is it always preferable to use old lemmas? Like is it a convention?

I feel as though: exact factorization_mul₀ ((zero_ne_add_one n).symm) (factorial_ne_zero n)
is more readable then rw [factorization_mul (zero_ne_add_one n).symm (factorial_ne_zero n), coe_add, Pi.add_apply].

Like, factorization_mul₀ was a lemma I made so that I didn't need to use coe_add, Pi.add_apply each time I apply the old one.

@Kevew Kevew requested a review from Paul-Lez March 3, 2025 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants