Example2-17-Kreweras.mw

Example 2.17 (Kreweras Lattice Walks) 

with(gfun):
 

> # The minimal polynomial listed can be proven using the kernel method.
# Here we heuristically guess the minimal polynomial using gfun.
# This takes up to 30 seconds.

# Generate terms in the counting sequence
KrewWalksIJ := proc(n,i,j)
 option remember:
 if i < 0 or j < 0 then return 0:
 elif n=0 and i=0 and j=0 then return 1:
 elif n=0 then return 0:
 else return KrewWalksIJ(n-1,i+1,j) + KrewWalksIJ(n-1,i,j+1) + KrewWalksIJ(n-1,i-1,j-1):
 end if:
end:
KrewWalks := proc(n)
 return add(add(KrewWalksIJ(n,i,j),i=0..n),j=0..n):
end:

# Generate counting sequence
LST := [seq(KrewWalks(k),k=0..100)]:

P := subs(y(z)=y,listtoalgeq(LST,y(z))[1]);
 

Typesetting:-mprintslash([P := `+`(`*`(43, `*`(`^`(z, 2))), z, 2, `*`(`+`(`*`(162, `*`(`^`(z, 3))), `-`(`*`(66, `*`(`^`(z, 2)))), `*`(10, `*`(z)), `-`(2)), `*`(y)), `*`(`+`(`*`(405, `*`(`^`(z, 4))), `...
Typesetting:-mprintslash([P := `+`(`*`(43, `*`(`^`(z, 2))), z, 2, `*`(`+`(`*`(162, `*`(`^`(z, 3))), `-`(`*`(66, `*`(`^`(z, 2)))), `*`(10, `*`(z)), `-`(2)), `*`(y)), `*`(`+`(`*`(405, `*`(`^`(z, 4))), `...
(1)
 

> # Plot part of the real algebraic curve defined by P
plots[implicitplot](P,z=-10..10,y=-30..30);
 

Plot_2d
 

> # Find potential singularities of the generating function
factor(discrim(P,y)*coeff(P,y,6));
 

`+`(`-`(`*`(67108864, `*`(`+`(z, 1), `*`(`^`(`+`(`-`(1), `*`(3, `*`(z))), 12), `*`(`^`(`+`(`*`(9, `*`(`^`(z, 2))), `*`(3, `*`(z)), 1), 6), `*`(`^`(z, 33)))))))) (2)
 

> # Solutions to P(z,y) at the origin
algeqtoseries(P,z,y,3);
 

[series(`+`(`-`(`*`(2, `*`(`^`(z, -1)))), `-`(1), `-`(z))+O(`^`(z, 2)),z,2), `+`(`-`(`/`(1, `*`(z))), `/`(`*`(RootOf(`+`(`*`(`^`(_Z, 2)), 4))), `*`(`^`(z, `/`(1, 2)))), RootOf(`+`(`*`(`^`(_Z, 2)), 4))... (3)
 

> # Solutions to P(z,y) around dominant singularity z = 1/3
algeqtoseries(subs(z=(1-t)/3,P),t,y,3):
subs(t=1-3*z,%);
 

[series(`+`(`/`(`*`(RootOf(`+`(`*`(`^`(_Z, 2)), 27))), `*`(`+`(1, `-`(`*`(3, `*`(z)))))), `+`(`-`(3), `*`(`/`(1, 3), `*`(RootOf(`+`(`*`(`^`(_Z, 2)), 27))))), `*`(`+`(`-`(3), `*`(`/`(7, 27), `*`(RootOf...
[series(`+`(`/`(`*`(RootOf(`+`(`*`(`^`(_Z, 2)), 27))), `*`(`+`(1, `-`(`*`(3, `*`(z)))))), `+`(`-`(3), `*`(`/`(1, 3), `*`(RootOf(`+`(`*`(`^`(_Z, 2)), 27))))), `*`(`+`(`-`(3), `*`(`/`(7, 27), `*`(RootOf...
(4)
 

> # There are two real solutions beginning +/- 2*sqrt(2)*(1-3*z)^(-1/4) + ...
# Thus f(z) ~ 2*sqrt(2)*(1-3*z)^(-1/4), giving dominant asymptotics
ASM := 3^n * 2*sqrt(2) * n^(-3/4) / GAMMA(1/4);
 

Typesetting:-mprintslash([ASM := `+`(`/`(`*`(2, `*`(`^`(3, n), `*`(GAMMA(`/`(3, 4))))), `*`(`^`(n, `/`(3, 4)), `*`(Pi))))], [`+`(`/`(`*`(2, `*`(`^`(3, n), `*`(GAMMA(`/`(3, 4))))), `*`(`^`(n, `/`(3, 4)... (5)
 

> # Heuristically check that our asymptotic is close to the actual sequence value
PR := rectoproc(listtorec(LST,u(n))[1],u(n)):
evalf(PR(1000)/subs(n=1000,ASM));
 

.9934627899 (6)
 

>