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

feat: port Mathlib 3's Nat.factors norm_num extension to a simproc #15420

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

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Aug 1, 2024

This is a partial attempt at #15410, porting #8009


Open in Gitpod

@eric-wieser eric-wieser force-pushed the eric-wieser/factors-norm_num branch from ccce0b1 to 3ad9f80 Compare August 1, 2024 22:26
Copy link

github-actions bot commented Aug 1, 2024

PR summary 3da8b59516

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Tactic 1
Mathlib.Tactic.NormNum.Factors (new file) 472

Declarations diff

+ FactorsHelper.cons
+ FactorsHelper.cons_of_le
+ FactorsHelper.cons_self
+ FactorsHelper.nil
+ FactorsHelper.primeFactorsList_eq
+ FactorsHelper.singleton
+ FactorsHelper.singleton_self
+ evalPrimeFactorsList
- factorsHelper_cons
- factorsHelper_cons'
- factorsHelper_end
- factorsHelper_nil
- factorsHelper_same
- factorsHelper_same_sn
- factorsHelper_sn

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

@grunweg grunweg added the t-meta Tactics, attributes or user commands label Aug 15, 2024
@eric-wieser eric-wieser changed the title feat: port the Nat.factors norm_num extension from Mathlib 3 feat: port Mathlib 3's Nat.factors norm_num extension to a simproc Jan 3, 2025
@leanprover-community-bot-assistant leanprover-community-bot-assistant added merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) and removed merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) labels Jan 3, 2025
@eric-wieser eric-wieser force-pushed the eric-wieser/factors-norm_num branch 2 times, most recently from 8a9e35c to 5ebced1 Compare January 3, 2025 16:12
@eric-wieser eric-wieser marked this pull request as ready for review January 3, 2025 16:15
@eric-wieser eric-wieser requested a review from digama0 January 3, 2025 16:15
@eric-wieser eric-wieser force-pushed the eric-wieser/factors-norm_num branch from 8343d39 to 16ed74f Compare January 3, 2025 16:27
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

Could you add more inline comments in the meta code? It would help maintainability

Mathlib/Tactic/NormNum/Factors.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/NormNum/Factors.lean Outdated Show resolved Hide resolved
Comment on lines 49 to 51
theorem FactorsHelper.same {n m : ℕ} (a : ℕ) {l : List ℕ}
(h : IsNat (a * m) n) (H : FactorsHelper m a l) :
FactorsHelper n a (a :: l) := fun pa =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
theorem FactorsHelper.same {n m : ℕ} (a : ℕ) {l : List ℕ}
(h : IsNat (a * m) n) (H : FactorsHelper m a l) :
FactorsHelper n a (a :: l) := fun pa =>
theorem FactorsHelper.cons_self {n m : ℕ} (a : ℕ) {l : List ℕ}
(h : IsNat (a * m) n) (H : FactorsHelper m a l) :
FactorsHelper n a (a :: l) := fun pa =>

maybe?

FactorsHelper n a (a :: l) := fun pa =>
H.cons_of_le _ h le_rfl (Nat.prime_def_minFac.1 pa).2 pa

theorem FactorsHelper.same_singleton (a : ℕ) : FactorsHelper a a [a] :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

By the same logic, this would be

Suggested change
theorem FactorsHelper.same_singleton (a : ℕ) : FactorsHelper a a [a] :=
theorem FactorsHelper.singleton_self (a : ℕ) : FactorsHelper a a [a] :=

Comment on lines 71 to 72
let ⟨hn0⟩ ← if h : 0 < n then pure <| PLift.up h else
throwError m!"{n'} must be positive"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we give up on computing primeFactorsList 0 here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the aux function, which expects the 0 and 1 cases to already have been dispatched, such that a can be chosen as a prime less than n.

I'll make it private to make this a little more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants