Skip to content

Commit

Permalink
feat(data/nat/choose/dvd): generalize to division rings (#8997)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcommelin committed Sep 4, 2021
1 parent 4435e90 commit 18d7b74
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/data/nat/choose/dvd.lean
Expand Up @@ -38,18 +38,16 @@ end

end prime

lemma cast_choose (α : Type*) [field α] [char_zero α] {a b : ℕ} (hab : a ≤ b) :
(b.choose a : α) = b! / (a! * (b - a)!) :=
lemma cast_choose (K : Type*) [division_ring K] [char_zero K] {a b : ℕ} (h : a ≤ b) :
(b.choose a : K) = b! / (a! * (b - a)!) :=
begin
rw [eq_comm, div_eq_iff],
norm_cast,
rw [←mul_assoc, choose_mul_factorial_mul_factorial hab],
{ exact mul_ne_zero (nat.cast_ne_zero.2 $ factorial_ne_zero _)
(nat.cast_ne_zero.2 $ factorial_ne_zero _) }
have : ∀ {n : ℕ}, (n! : K) ≠ 0 := λ n, nat.cast_ne_zero.2 (factorial_ne_zero _),
rw [eq_div_iff_mul_eq (mul_ne_zero this this)],
rw_mod_cast [← mul_assoc, choose_mul_factorial_mul_factorial h],
end

lemma cast_add_choose (α : Type*) [field α] [char_zero α] {a b : ℕ} :
((a + b).choose a : α) = (a + b)! / (a! * b!) :=
by rw [cast_choose α (le_add_right le_rfl), nat.add_sub_cancel_left, mul_comm]
lemma cast_add_choose (K : Type*) [division_ring K] [char_zero K] {a b : ℕ} :
((a + b).choose a : K) = (a + b)! / (a! * b!) :=
by rw [cast_choose K (le_add_right le_rfl), nat.add_sub_cancel_left]

end nat

0 comments on commit 18d7b74

Please sign in to comment.