Skip to content

feat(Data/Nat): add prime divisibility for ascFactorial and choose#39366

Open
akiezun wants to merge 1 commit into
leanprover-community:masterfrom
akiezun:nat-prime-dvd-choose-consecutive
Open

feat(Data/Nat): add prime divisibility for ascFactorial and choose#39366
akiezun wants to merge 1 commit into
leanprover-community:masterfrom
akiezun:nat-prime-dvd-choose-consecutive

Conversation

@akiezun
Copy link
Copy Markdown

@akiezun akiezun commented May 14, 2026

Adds two prime-divisibility lemmas for natural-number factorial/binomial APIs.

The first characterizes when a prime divides an ascending factorial:
Nat.Prime.dvd_ascFactorial_iff.

The second applies this to binomial coefficients:
Nat.Prime.dvd_choose_add_sub_one_iff, using
Nat.ascFactorial_eq_factorial_mul_choose' and cancellation of the n! factor
when n < p.


Open in Gitpod

@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 May 14, 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 https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions
Copy link
Copy Markdown

PR summary e7eedc30e9

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ Prime.dvd_ascFactorial_iff
+ dvd_choose_add_sub_one_iff

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.


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

@github-actions github-actions Bot added the t-data Data (lists, quotients, numbers, etc) label May 14, 2026
Comment on lines +31 to +44
lemma Prime.dvd_ascFactorial_iff {p k n : ℕ} (hp : p.Prime) :
p ∣ k.ascFactorial n ↔ ∃ i < n, p ∣ k + i := by
induction n with
| zero => simp [Nat.ascFactorial_zero, hp.ne_one]
| succ n ih =>
rw [Nat.ascFactorial_succ, hp.dvd_mul, ih]
constructor
· rintro (h | ⟨i, hi, h⟩)
· exact ⟨n, lt_succ_self n, h⟩
· exact ⟨i, lt_succ_of_lt hi, h⟩
· rintro ⟨i, hi, h⟩
rcases lt_or_eq_of_le (Nat.le_of_lt_succ hi) with hi | rfl
· exact Or.inr ⟨i, hi, h⟩
· exact Or.inl h
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.

Suggested change
lemma Prime.dvd_ascFactorial_iff {p k n : ℕ} (hp : p.Prime) :
p ∣ k.ascFactorial n ↔ ∃ i < n, p ∣ k + i := by
induction n with
| zero => simp [Nat.ascFactorial_zero, hp.ne_one]
| succ n ih =>
rw [Nat.ascFactorial_succ, hp.dvd_mul, ih]
constructor
· rintro (h | ⟨i, hi, h⟩)
· exact ⟨n, lt_succ_self n, h⟩
· exact ⟨i, lt_succ_of_lt hi, h⟩
· rintro ⟨i, hi, h⟩
rcases lt_or_eq_of_le (Nat.le_of_lt_succ hi) with hi | rfl
· exact Or.inr ⟨i, hi, h⟩
· exact Or.inl h
lemma Prime.dvd_ascFactorial_iff {p k n : ℕ} (hp : p.Prime) :
p ∣ k.ascFactorial n ↔ ∃ i < n, p ∣ k + i := by
simp [Nat.ascFactorial_eq_prod_range, hp.prime.dvd_finsetProd_iff]

Not sure if this file has enough imports for this. If not, this can be moved to anywhere that imports Mathlib.Algebra.BigOperators.Associated and Mathlib.Data.Nat.Factorial.BigOperators

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.

It doesn't and AFAICT there's no file that imports these which is also a sensible place for such a theorem.
New file?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It doesn't and AFAICT there's no file that imports these which is also a sensible place for such a theorem. New file?

Thanks. Suggestions for file name?

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.

Maybe Data/Nat/Factorial/Prime.lean, not sure

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.

It is going to be a bit confusing if we have both Mathlib/Data/Nat/Prime/Factorial.lean and Data/Nat/Factorial/Prime.lean... what about adding more imports here and eat the cost of large imports? (assuming it is not circular)

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.

3 participants