Computing series terms related to a multivariate walk generating function using the ring $\mathbb{Q}[x,\overline{x}][[t]]$.

*Requirements: None*

In [1]:

```
# Define the ring where the expansion takes place
A = LaurentPolynomialRing(QQ,'x')[['t']]
A
```

Out[1]:

Power Series Ring in t over Univariate Laurent Polynomial Ring in x over Rational Field

In [2]:

```
# Print the expansion of the function under consideration
print("The expansion of 1/(1-t(x+1/x)) in Q[x,1/x][[t]] is")
print(1/A("1-t*(x+1/x)").O(5))
```

In [3]:

```
# Setting x = 1 gives the GF for walks on the steps {-1,1} with no restrictions, which has coefficients 2^n
ser = 1/A("1-t*(x+1/x)").O(10)
ser(x=1)
```

Out[3]:

1 + 2*t + 4*t^2 + 8*t^3 + 16*t^4 + 32*t^5 + 64*t^6 + 128*t^7 + 256*t^8 + 512*t^9 + O(t^10)

In [4]:

```
# The counting sequence for for walks returning to the origin is
coeffs = ser.coefficients()
[k.constant_coefficient() for k in coeffs]
```

Out[4]:

[1, 0, 2, 0, 6, 0, 20, 0, 70, 0]

In [5]:

```
# This sequence is also encoded by the main power series diagonal of 1/(1-t*(1+x^2))
coeffs2 = (1/A("1-t*(1+x^2)").O(10)).coefficients()
[coeffs2[k][k] for k in range(10)]
```

Out[5]:

[1, 0, 2, 0, 6, 0, 20, 0, 70, 0]

In [6]:

```
# The counting sequence for walks ending at positive x-value is given by the diagonal of 1/(1-x)/(1-t*(1+x^2))
# Note: this rational function has a bivariate power series expansion, but does not have an expansion in QQ[x,1/x][[t]]
B = QQ[['x']][['t']]
coeffs3 = (1/B("(1-x)*(1-t*(1+x^2))").O(10)).coefficients()
print([coeffs3[k][k] for k in range(10)])
print([add([coeffs[k][j] for j in range(k+1)]) for k in range(10)])
```

[1, 1, 3, 4, 11, 16, 42, 64, 163, 256] [1, 1, 3, 4, 11, 16, 42, 64, 163, 256]

In [0]:

```
```