Skip to content

Commit 9e101ac

Browse files
committed
Generalize to rational algebras.
1 parent bfcc3fb commit 9e101ac

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Mathlib/RingTheory/Binomial.lean

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,20 @@ instance Int.instBinomialRing : BinomialRing ℤ where
177177

178178
end Nat_Int
179179

180-
section Real
180+
section Rat_Algebra
181+
182+
variable {R : Type*} [CommRing R] [CharZero R] [IsLeftCancelMulZero R] [Algebra ℚ R]
183+
181184
/-- Inductive definition of the multichoose function. -/
182-
noncomputable def Real.multichoose: → ℕ →
185+
noncomputable def multichoose: R → ℕ → R
183186
| _, 0 => 1
184-
| r, k+1 => (r+k)/(k+1)*(Real.multichoose r k)
187+
| r, k+1 => ((k+1)⁻¹:ℚ)•(r+k)*(multichoose r k)
185188

186-
noncomputable instance Real.instBinomialRing : BinomialRing where
189+
noncomputable instance instBinomialRing : BinomialRing R where
187190
nsmul_right_injective n hn r s hrs := by
188-
simp only [nsmul_eq_mul, mul_eq_mul_left_iff, Nat.cast_eq_zero, hn, or_false] at hrs
189-
exact hrs
190-
multichoose := Real.multichoose
191+
simp only [nsmul_eq_mul] at hrs
192+
exact (mul_left_cancel₀ (Nat.cast_ne_zero.mpr hn) hrs)
193+
multichoose := multichoose
191194
factorial_nsmul_multichoose r n := by
192195
induction' n with n ih
193196
case zero =>
@@ -197,9 +200,12 @@ noncomputable instance Real.instBinomialRing : BinomialRing ℝ where
197200
rw [Polynomial.ascPochhammer_smeval_eq_eval] at ih
198201
rw [Polynomial.ascPochhammer_smeval_eq_eval, ascPochhammer_succ_eval, ← ih, multichoose,
199202
Nat.factorial]
200-
field_simp; ring_nf
201-
end Real
202-
203+
nth_rewrite 1 [← (one_smul ℚ (multichoose r n))]
204+
rw [smul_mul_smul, ← smul_assoc, ← smul_mul_smul]
205+
field_simp
206+
rw [Algebra.smul_def', map_natCast]
207+
ring_nf
208+
end Rat_Algebra
203209
section Choose
204210

205211
namespace Ring

0 commit comments

Comments
 (0)