Help:=proc(): print(` Di(L) , NGF(L,x) , SumPol(P,n) `): print(`F(a,b) ,G(a,b) `): end: Di:=proc(L) local i: [ seq( L[i+1]-L[i],i=1..nops(L)-1)]: end: #NGF(L,x): The unique polynomial P(x) #expressed in terms of binomial(x,k) #such that P(i)=L[i+1] for i from 0 to nops(L)-1 NGF:=proc(L,x) local i,L1,P: L1:=L: P:=0: for i from 1 to nops(L) do P:=P+L1[1]*binomial(x,i-1): L1:=Di(L1): if convert(L1,set)={0} then RETURN(factor(expand(P))): fi: od: factor(expand(P)): end: #SumPol(P,n): an empirical yet rigorous algorithm that #inputs a polynomial expression P, of n, and outputs #the polynomial expression for the indefinite sum #add(P(i),i=0..n): SumPol:=proc(P,n) local d, L,i,j,Q: d:=degree(P,n): L:=[ seq(eval(P,n=i), i=0..d+1)]: Q:=factor(NGF([seq(add(L[j],j=1..i), i=1..nops(L))],n)): #Is Q(n)-Q(n-1)=P(n) if expand(Q-subs(n=n-1,Q)-P) <>0 then print(`WE ARE STUPID!, SHAME ON US!`): RETURN(FAIL): fi: Q: end: #F(a,b): the number of walks from [0,0] to [a,b] #using positive unit steps ([1,0], [0,1]) F:=proc(a,b) option remember: if a=0 or b=0 then 1: else F(a-1,b)+F(a,b-1): fi: end: #G(a,b): the number of walks from [0,0] to [a,b] #using positive unit steps ([1,0], [0,1]) always #staying in the safe region a>=b G:=proc(a,b) option remember: if b=0 then 1: elif b>a then 0: else G(a-1,b)+G(a,b-1): fi: end: