Mach 9.2 Binomial Theorem

106 days ago by mpaul

Powers of Binomials

var('a b') expand((a+b)^6) 
       
show(expand((a+b)^6)) 
       
for n in [0..10]: show(expand((a+b)^n)) 
       
 
       

Binomial Coefficients

Each of the coefficients in an expansion of (a+b)^n is called a binomial coefficient.

The symbol for a binomial coefficient is {n \choose r}.

It has the same meaning as _n C _r :  the number of subsets of size r contained in a set of size n

var('n r') show(binomial(n,r)) 
       
binomial(10,3) 
       

Here is a list comprehension that will create a list of binomial coefficients for a given value of n:

n = 9 [binomial(n,r) for r in [0..n]] 
       

Pascal's Triangle

The pattern of binomial coefficients is given in Pascal's Triangle.

nrows = 10 for n in [0..nrows]: [binomial(n,r) for r in [0..n]] 
       

Recursive definition for Pascal's Triangle:

\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r}

def C(n, r): if r == 0 or r == n: return 1 return C(n-1, r-1)+C(n-1, r) 
       
C(10,3) 
       

The Binomial Theorem

(a + b)^n = \sum^{n}_{r=0} {\binom{n}{r} a^{n-r} b^{r}}

@interact def expand(a=var('a'), b=var('b'), n = 2): B = (a+b)^n show(B) show(B.expand()) show([(binomial(n, r),a^(n-r),b^r) for r in [0..n]]) 
       

Click to the left again to hide and once more to show the dynamic interactive window

Newton's Expansion:

(a+b)^n = a^{n} +  n \cdot a^{n-1} \cdot b^{1} + n \cdot \frac{n-1}{2} \cdot a^{n-2}b^{2} + \frac{n \cdot (n-1)}{2} \cdot \frac{(n-2)}{3} \cdot a^{n-3}b^{3} + \frac{n \cdot (n-1) \cdot (n-2)}{6} \cdot \frac{n-3}{4} \cdot a^{n-4} \cdot b^{4} + ...

def newton(n, a=var('a'), b=var('b')): C = 1 for r in [0..n]: yield C*a^(n-r)*b^r C = C*(n-r)/(r+1) 
       
list(newton(3)) 
       
def newton(n,a=var('a'),b=var('b')): C,r = 1,0 while r != n: yield C*a^(n-r)*b^r C = C*(n-r)/(r+1) r += 1 yield C*a^(n-r)*b^r 
       
t = newton(1/2,1,1) sum([next(t) for i in range(100)]).n(digits = 20) 
       
sqrt(2).n(digits = 20) 
       
 
       

Binomial Probabilities

If p is the probability that something will occur and q is the probability that it won't,

then the expansion of (p + q)^n is a binomial probability distribution.

var('p q') expand((p+q)^5) 
       
show(expand((p+q)^5)) 
       

Suppose you are taking a multiple choice test with 4 choices per question.

In this situationa p = \frac{1}{4} and q = \frac{3}{4}.

Each term in the expansion has the structure _{n}C_{r} \cdot (\frac{1}{4})^{r} \cdot (\frac{3}{4})^{4-r}.

_{n}C_{r} tells us how many ways we could get r questions correct and 4-r questions incorrect.

p, q = 1/4, 3/4 [binomial(5, r)*p^r*q^(5-r) for r in [0..5]] 
       
@interact def _(n = 5, p=1/3, q = 2/3): bd = [binomial(n, r)*p^r*q^(n-r) for r in [0..n]] show(bd) show([x.n(digits = 3) for x in bd]) 
       

Click to the left again to hide and once more to show the dynamic interactive window