#M2.txt: Maple Code for Lecture 2 of Math 454,Combinatorics, Rutgers University, taught by Dr. Z. (Doron Zeilberger) Help2:=proc():print(` F(m,n) , Fformula(m,n), NuW(L), NuWformula(L) `): end: #F(m,n): The number of walks from [0,0] to [m,n] in the Manhattan lattice (w/o Broadway) using fundamental steps [1,0] and [0,1] #USING THE NATURAL RECURSION F:=proc(m,n) option remember: if m<0 or n<0 then 0: elif m=0 and n=0 then 1: else F(m-1,n)+F(m,n-1): fi: end: #Fformula(m,n): The number of walks from [0,0] to [m,n] in the Manhattan lattice (w/o Broadway) using fundamental steps [1,0] and [0,1] #USING THE EXPLICIT FORMULA (CONEJCTURED LAST TIME) Fformula:=proc(m,n): (m+n)!/(m!*n!): end: #NuW(L): inputs a list L of length k, say, (k=nops(L), in the language of Maple) whose entries are #non-negative integers, outputs the number of REARRANGEMENTS of the word with #L[1] 1's , L[2] 2's, ..., L[k] k's. USING THE NATURAL RECURRENCE. For example #to get the number of rearrangements of 1122233 type NuW([2,3,2]); NuW:=proc(L) local k,i: option remember: k:=nops(L): if min(op(L))<0 then 0: elif L=[0$k] then 1: else add(NuW([op(1..i-1,L),L[i]-1,op(i+1..k,L)]),i=1..k): fi: end: #NuWformula(L): inputs a list L of length k, say, (k=nops(L), in the language of Maple) whose entries are #non-negative integers, outputs the number of REARRANGEMENTS of the word with #L[1] 1's , L[2] 2's, ..., L[k] k's. USING THE FORMULA #to get the number of rearrangements of 1122233 type NuWformula([2,3,2]); NuWformula:=proc(L) local k,i: k:=nops(L): add(L[i],i=1..k)!/mul(L[i]!,i=1..k): end: ###The Maple Code below was not discussed in Lecture 2. It will be discussed in Lecture 3 #MyPowerSet(S): An home-made version of Maple's command combinat[powerset](S) #For example #MyPowerSet({a,b})={{},{a},{b},{a,b}} . MyPowerSet:=proc(S) local a,S1,P1,s: option remember: if S={} then RETURN({{}}): fi: a:=S[1]: S1:=S minus {a}: P1:=MyPowerSet(S1): P1 union {seq(s union {a}, s in P1)}: end: