Help:=proc(): print(`Wnk(n,k), wnk(n,k) ,gnk(n,k), g(n), Sg(n),`): print(`Sgr(n) , wnkx(n,k,x)` ): end: #Wnk(n,k): the set of {-1,1} n-vectors that add up to to k Wnk:=proc(n,k) local S1,S2,s: option remember: if n=0 then if k=0 then RETURN({[]}): else RETURN({}): fi: fi: S1:=Wnk(n-1,k+1): S2:=Wnk(n-1,k-1): {seq([op(s),-1], s in S1), seq([op(s),1],s in S2)}: end: #wnk(n,k): the number of {-1,1} n-vectors that add up to to k wnk:=proc(n,k) option remember: if n=0 then if k=0 then RETURN(1): else RETURN(0): fi: fi: wnk(n-1,k+1)+wnk(n-1,k-1): end: #gnk(n,k): the number of {-1,1} n-vectors that add up to to k #that never venture to the left of 0 gnk:=proc(n,k) option remember: if n=0 then if k=0 then RETURN(1): else RETURN(0): fi: fi: if k=0 then RETURN(gnk(n-1,k+1)): else gnk(n-1,k+1)+gnk(n-1,k-1): fi: end: #g(n): the number of ways of walking 2n steps and #breaking even at the end, and never having to #borrow money g:=proc(n): gnk(2*n,0):end: Sg:=proc(N) local n: [seq(g(n),n=0..N)]: end: Sgr:=proc(N) local n: [seq(g(n+1)/g(n),n=0..N)]: end: #wnkx(n,k,x): the generating #polynomial of {-1,1} n-vectors that add up to to k #with the weight x^(number of steps visiting the neg. region) wnkx:=proc(n,k,x) option remember: if n=0 then if k=0 then RETURN(1): else RETURN(0): fi: fi: if k>0 then wnkx(n-1,k+1,x)+wnkx(n-1,k-1,x): elif k=0 then expand(wnkx(n-1,k+1,x)+x*wnkx(n-1,k-1,x)): else expand(x*wnkx(n-1,k+1,x)+x*wnkx(n-1,k-1,x)): fi: end: