#M9.txt: Maple Code for Lecture 9 of Math 454,Combinatorics, Rutgers University, taught by Dr. Z. (Doron Zeilberger) Help9:=proc():print(` DiagSeq2(f,x,y,N), DiagWalks2D(S,N), DiagSeq3(f,x,y,z,N), DiagWalks3D(S,N) `): end: #We are loading two useful Maple packages, combinat, and gfun (Written by Bruno Salvy and Paul Zimmerman) with(combinat): with(gfun): #Here we are enlarging the default values of the system parameters gfun[maxdegeqn] and gfun[maxdegcoeff] of 3 and 4 #respectively so that we can discover more complicated recurrences using the command #gfun[listtorec](IntegerList, a(n)) gfun[maxdegeqn]:=10: gfun[maxdegcoeff]:=10: #DiagSeq2(f,x,y,N): Given a rational function f of the variables x and y such that the denominator does not vanish at (0,0) #outputs the list whose i-th entry is the coefficient of x^(i-1)*y^(i-1) in the 2-variable power-series expansion of f #Try: #DiagSeq2(1/(1-x-y),x,y); DiagSeq2:=proc(f,x,y,N) local i: if subs({x=0,y=0},denom(f))=0 then print(`The denominator of`, f, `should have a non-zero constant term `): RETURN(FAIL): fi: [seq(coeff(taylor(coeff(taylor(f,x=0,N+1),x,i),y=0,N+1),y,i),i=0..N)]: end: #DiagWalks2D(S,N): Inputs a set of "atomic steps" in the 2-dimenional square lattice, with positve steps, of the form [a,b] #For example for a forward moving Knight the set if {[2,1],[1,2]} for a forward moving King it is {[1,0],[0,1],[1,1]} #outputs the first N+1 terms of the sequence #Number of walks from [0,0] to [n,n] using the atomic steps. For example try: #DigSeq({[1,2],[2,1]},40); DiagWalks2D:=proc(S,N) local s,x,y: if not (type(S, set) and type(N,integer) and N>=0) then print(`Bad input`): RETURN(FAIL): fi: DiagSeq2(1/(1-add(x^s[1]*y^s[2], s in S)),x,y,N ) : end: #DiagSeq3(f,x,y,z,N): Given a rational function f of the variables x, y, and z, such that the denominator does not vanish at (0,0,0) #outputs the list whose i-th entry is the coefficient of x^(i-1)*y^(i-1)*z^(i-1) in the 3-variable power-series expansion of f #Try: #DiagSeq3(1/(1-x-y-z),x,y,z); DiagSeq3:=proc(f,x,y,z,N) local i: if subs({x=0,y=0,z=0},denom(f))=0 then print(`The denominator of`, f, `should have a non-zero constant term `): RETURN(FAIL): fi: [seq(coeff(taylor(coeff(taylor(coeff(taylor(f,x=0,N+1),x,i),y=0,N+1),y,i),z=0,N+1),z,i),i=0..N)]: end: #DiagWalks3D(S,N): Inputs a set of "atomic steps" in the 2-dimenional square lattice, with positve steps, of the form [a,b,c] #Number of walks from [0,0,0] to [n,n,n] using the atomic steps. For example try: #DiagWalks3D({[1,0,0],[0,1,0],[0,0,1]},40); DiagWalks3D:=proc(S,N) local s,x,y,z: if not (type(S, set) and type(N,integer) and N>=0) then print(`Bad input`): RETURN(FAIL): fi: DiagSeq3(1/(1-add(x^s[1]*y^s[2]*z^s[3], s in S)),x,y,z,N ) : end: