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

[Merged by Bors] - feat(Factorial): k! divides the product of any k successive integers #21332

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Mathlib/Data/Nat/Factorial/BigOperators.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Pim Otte
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.Order.BigOperators.Ring.Finset

/-!
Expand Down Expand Up @@ -41,4 +42,35 @@ theorem descFactorial_eq_prod_range (n : ℕ) : ∀ k, n.descFactorial k = ∏ i
| 0 => rfl
| k + 1 => by rw [descFactorial, prod_range_succ, mul_comm, descFactorial_eq_prod_range n k]

/-- `k!` divides the product of any `k` successive non-negative integers. -/
private lemma factorial_coe_dvd_prod_of_nonneg (k : ℕ) (n : ℤ) (hn : 0 ≤ n) :
(k ! : ℤ) ∣ ∏ i ∈ range k, (n + i) := by
obtain ⟨x, hx⟩ := Int.eq_ofNat_of_zero_le hn
have hdivk := x.factorial_dvd_ascFactorial k
zify [x.ascFactorial_eq_prod_range k] at hdivk
rwa [hx]

/-- `k!` divides the product of any `k` successive integers. -/
lemma factorial_coe_dvd_prod (k : ℕ) (n : ℤ) : (k ! : ℤ) ∣ ∏ i ∈ range k, (n + i) := by
by_cases hn : n < 0
· by_cases hnk : 0 < n + k
· have : ∏ i ∈ range k, (n + ↑i) = 0 := prod_eq_zero_iff.mpr <| by
have ⟨negn, _⟩ : ∃ (negn : ℕ), -n = ↑negn := Int.eq_ofNat_of_zero_le <| by linarith
exact ⟨negn, by rw [mem_range]; omega⟩
Julian marked this conversation as resolved.
Show resolved Hide resolved
rw [this]
exact (k ! : ℤ).dvd_zero
· have prod_eq : ∏ x ∈ range k, |n + ↑x| = ∏ x ∈ range k, -(n + ↑x) := by
Julian marked this conversation as resolved.
Show resolved Hide resolved
refine prod_congr rfl fun _ hx ↦ ?_
rw [mem_range] at hx
rw [abs_of_neg]
linarith
rw [← dvd_abs, abs_prod, prod_eq, ← prod_range_reflect]
simp_rw [neg_add_rev, add_comm]
rw [show ∏ j ∈ range k, (-n + -↑(k - 1 - j)) = ∏ j ∈ range k, (-n + -↑(k - 1) + j) from ?_]
· exact factorial_coe_dvd_prod_of_nonneg k (-n + -↑(k - 1)) (by omega)
· refine prod_congr rfl fun _ ↦ ?_
rw [mem_range]
omega
· exact factorial_coe_dvd_prod_of_nonneg k n <| not_lt.mp hn

end Nat