On an infinitely large chessboard, in how many paths of length $10$ can a knight take and end up in its original position?

Here is an approach using multivariate generating functions, although the final evaluation is a bit impractical without a computer, it is doable. This approach also allows for generalization to other pieces/movements and ending positions (well as long as we have finite number of possibilities for movement, of course).

Let's encode the positions in two dimensions with integer coordinates and say we start at $(0,0)$. Let $f(x,y)=\sum a_{i,j} x^iy^j$ where $a_{i,j}$ is $1$ if the piece can get to $(i,j)$ on first move, and $0$ otherwise. Then number of ways the piece can be at any position $(i,j)$ after $n$ moves is coefficient of $x^iy^j$ in $f(x,y)^n$. This is because multiplying of individual terms translates into addition on the exponents, and also because we start at $(0,0)$ (so by addition/subtraction of the first moves we generate all subsequent moves).

For the knight, the viable first moves are $(i,j)\in \{(\pm 1, \pm2), (\pm 2, \pm 1)\}$, and so $$f(x,y)=xy^2+x^2y+x^{-1}y^2+x^2y^{-1}+xy^{-2}+x^{-2}y+x^{-1}y^{-2}+x^{-2}y^{-1}.$$

So the number of ways the knight will end at position $(0,0)$ after $10$ moves is coefficient of $x^0y^0=1$ (constant) in $f(x,y)^{10}$. Now we can either use computer algebra system such as Maple to evaluate the polynomial and extract the corresponding coefficient, or we can further apply little algebra and notice $$ g(x,y)=x^2y^2f(x,y)=x(x^2+1)(y^4+1)+y(y^2+1)(x^4+1), $$ and that we are interested in coefficient of $x^{20}y^{20}$ in $g(x,y)^{10}$. Using the binomial theorem repeatedly, we can see that this is sum of all possible $$\binom{10}{k}\binom{k}{i_1}\binom{10-k}{j_1}\binom{k}{i_2}\binom{10-k}{j_2},$$ where $k+2i_1+4j_1=20,10-k+4i_2+2j_2=20$ and $k,i_1,i_2,j_1,j_2\geq 0$. The conditions imply that $k$ is even, so we want to evaluate: $$ \sum_{\substack{k,i_1,i_2,j_1,j_2 \geq 0\\i_1+2j_1=10-k\\2i_2+j_2=5+k}} \binom{10}{2k}\binom{2k}{i_1}\binom{10-2k}{j_1}\binom{2k}{i_2}\binom{10-2k}{j_2}. $$

We can further notice things that $\sum \binom{2k}{i_1}\binom{10-2k}{j_1}$ and $\sum \binom{2k}{i_2}\binom{10-2k}{j_2}$ can be evaluated independently and that they are same for $k$ and $5-k$, which slightly reduces the number of terms. Eventually you will only need to evaluate binomial coefficients $\binom{10}{5}$, $\binom{10}{4}$, $\binom{10}{2}$, $\binom{8}{4}$, $\binom{8}{2}$, $\binom{6}{3}$, $\binom{6}{2}$, $\binom{4}{2}$ (not mentioning obvious values of $\binom{m}{0}$ and $\binom{m}{1}$), so it's not that bad.

In any way, at some point in the simplification it becomes matter of calculation, I suggest to look at bof's answer for the way to do it nicely using pencil & paper way. Notice that both answers arrived at the basically the same sum by different means (one algebraic, the other one more combinatoric).

Following code can be used for evaluation in Maple:

N := 10:
S := 0:
for k from 0 to N/2 do: 
  term := binomial(N, 2*k): 
  term := term * add(binomial(2*k, N-k-2*j1)*binomial(N-2*k, j1), j1=0..(N-k)/2):
  term := term * add(binomial(2*k, i2)*binomial(N-2*k, N/2+k-2*i2), i2=0..(N/2+k)/2): 
  S := S + term 
od:
S;

or

N := 10:
coeff(coeff((x*y^2+x^2*y+y^2/x+x^2/y+x/y^2+y/x^2+1/(x*y^2)+1/(x^2*y))^N, x, 0), y, 0);

Output:

13180608

Here is a formula for the number of closed walks of length $2T$ by a knight on an infinite chessboard, beginning and ending on a given square: $$\sum_{m+n=T}\binom{2T}{2m}\left[\sum_{h+2k=m+2n}\binom{2m}h\binom{2n}k\right]\left[\sum_{2h+k=2m+n}\binom{2m}h\binom{2n}k\right]$$ Explanation. Call a knight move "(mostly) horizontal" if it's two squares left or right and one square up or down, "(mostly) vertical" if it's one square left or right and two squares up or down. In order for the knight to return to its starting square, it must make an even number of horizontal moves and an even number of vertical moves, say $2m$ horizontal moves and $2n$ vertical moves, where $2m+2n=2T$ or more simply $m+n=T$.

The factor $\binom{2T}{2m}$ is the number of ways we can permute the $2m$ horizontal moves $(\pm2,\pm1)$ and the $2n$ vertical moves $(\pm1,\pm2)$.

The factor $\sum_{h+2k=m+2n}\binom{2m}h\binom{2n}k$ is the number of ways we can attach signs to the vertical (second) coordinates so that the net vertical displacement is zero. Namely, the total (unsigned) vertical distance traveled by the knight in making $2m$ horizontal and $2n$ vertical moves is $2m+4n$; so we have to attach $+$ signs to the second coordinates of $h$ of the $2m$ horizontal moves and $k$ of the $2n$ vertical moves, and $-$ signs to the rest, where $h+2k=(2m+4n)/2=m+2n$.

Likewise, the factor $\sum_{2h+k=2m+n}\binom{2m}h\binom{2n}k$ is the number of ways we can attach signs to the horizontal (first) coordinates so that the net horizontal displacement is zero.

Calculation. To find the number of closed knight walks of length $10$, we set $T=5$.

$m=0$, $n=5$:

$$\binom{10}0\left[\sum_{h+2k=10}\binom0h\binom{10}k\right]\left[\sum_{2h+k=5}\binom0h\binom{10}k\right]$$ $$=\binom{10}0\left[\binom00\binom{10}5\right]\left[\binom00\binom{10}5\right]=63504.$$ $m=1$, $n=4$: $$\binom{10}2\left[\sum_{h+2k=9}\binom2h\binom8k\right]\left[\sum_{2h+k=6}\binom2h\binom8k\right]$$ $$=\binom{10}2\left[\binom21\binom84\right]\left[\binom22\binom82+\binom21\binom84+\binom20\binom86\right]=1234800.$$ $m=2$, $n=3$: $$\binom{10}4\left[\sum_{h+2k=8}\binom4h\binom6k\right]\left[\sum_{2h+k=7}\binom4h\binom6k\right]$$ $$=\binom{10}4\left[\binom40\binom64+\binom42\binom63+\binom44\binom62\right]\left[\binom43\binom61+\binom42\binom63+\binom41\binom65\right]=5292000.$$ $m=3$, $n=2$: $$\binom{10}6\left[\sum_{h+2k=7}\binom6h\binom4k\right]\left[\sum_{2h+k=8}\binom6h\binom4k\right]=5292000.$$ $m=4$, $n=1$: $$\binom{10}8\left[\sum_{h+2k=6}\binom8h\binom2k\right]\left[\sum_{2h+k=9}\binom8h\binom2k\right]=1234800.$$ $m=5$, $n=0$: $$\binom{10}{10}\left[\sum_{h+2k=5}\binom{10}h\binom0k\right]\left[\sum_{2h+k=10}\binom{10}h\binom0k\right]=63504.$$ Final answer: $$63504+1234800+5292000+5292000+1234800+63504=\boxed{13180608}$$ which agrees with the value at A254129.


Here is a little program to compute it:

from collections import defaultdict

d = int(input('Number of moves: '))

dx = [2, 1, 2, 1, -2, -1, -2, -1]
dy = [1, 2, -1, -2, 1, 2, -1, -2]

pos = defaultdict(int)
pos[0, 0] = 1

for _ in range(d):
    new = defaultdict(int)
    for (x, y), c in pos.items():
        for l in range(8):
            nx = x + dx[l]
            ny = y + dy[l]
            new[nx, ny] += c
    pos = new

print(pos[0, 0])

It produces the right answer for 10 immediately and also for 100 in about 10s.