I have a reason to believe that a certain combinatorial identity holds for even integers $n, k$ that satisfies $2 \leq k \leq n/2$ and $n\geq 4$. To test it in Sage, I denote the expression on the right- and lefthandside as the functions RHS$(n,k)$ and LHS$(n,k)$ respectively and check if they agree for a variety of values $n$ and $k$.

```
def t(n,k):
sum=0
for i in range(n-2*k+1):
sum+=binomial(n-2*k,i)
return n/k*sum*binomial(n-4,2*k-4)*catalan_number(k-2)
def LHS(n,k):
return n/2*((n/2+1-k)/(n/2+1)*t(n/2+1,k/2)+2*(k/2+1)/(n/2+1)*t(n/2+1,k/2+1))
def RHS(n,k):
return (n/k)*(2**(n/2-k))*binomial(n/2-2,k-2)*binomial(k-2,k/2-1)
```

But when run the following code

```
for n in range(6,12,2):
for k in range(2,floor(n/2)+1,2):
print("n="+str(n)+", k="+str(k))
print(bool(LHS(n,k)==RHS(n,k)))
```

I get the output

```
n=6, k=2
True
n=8, k=2
True
n=8, k=4
True
n=10, k=2
True
n=10, k=4
False
```

which would indicate that the identity does not hold for $n=10$, $k=4$. However, when I write

```
print(bool(LHS(10,4)==RHS(10,4)))
```

I get the output TRUE (I also double checked this by hand, and both sides agree and are equal to $30$ in this case).

Why does the code in the double loop yield the wrong answer?

Is there a better way to check equalities similar to this in Sage?