[Edu-sig] Standard Math 2001

Kirby Urner pdx4d@teleport.com
Thu, 17 May 2001 17:21:26 -0700


 >>> def pascal(n): 
 	 """
	 Simple loop for printing rows 1-n of Pascal's Triangle
	 """
       row = [1]
       for j in range(n):
          print row
          row = [1] \
	 	    + [row[i] + row[i+1] for i in range(len(row)-1)] + \
                [1]

	   
 >>> pascal(10)
 [1]
 [1, 1]
 [1, 2, 1]
 [1, 3, 3, 1]
 [1, 4, 6, 4, 1]
 [1, 5, 10, 10, 5, 1]
 [1, 6, 15, 20, 15, 6, 1]
 [1, 7, 21, 35, 35, 21, 7, 1]
 [1, 8, 28, 56, 70, 56, 28, 8, 1]
 [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

Comparing Polynomial w/ Pascal's Triangle:

 >>> from mathobjects import *
 >>> term = Poly([1,1],'t')
 >>> term
 t + 1
 >>> term**9
 t**9 + 9*t**8 + 36*t**7 + 84*t**6 + 126*t**5 
 + 126*t**4 + 84*t**3 + 36*t**2 + 9*t + 1

See:  Binomial Theorem
      http://www.inetarena.com/~pdx4d/ocn/binomial.html