ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 Aug 2019 15:42:42 -0500Checking identity of two combinatorial expressionshttp://ask.sagemath.org/question/47535/checking-identity-of-two-combinatorial-expressions/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).
1. Why does the code in the double loop yield the wrong answer? EDIT: answered by rburing
2. Is there a better way to check equalities similar to this in Sage?joakim_uhlinTue, 20 Aug 2019 15:42:42 -0500http://ask.sagemath.org/question/47535/How to test an identity of rational numbers?http://ask.sagemath.org/question/38274/how-to-test-an-identity-of-rational-numbers/ Hi,
Why is there a difference in output between:
print 5-1 == 0
print 3^(1/3) - 3^(1/5) == 0
False
3^(1/3) - 3^(1/5) == 0
What can I do if $x,y,s,t \in \mathbb Q$, and I want to test $x^y == s^t$?
Thanks for your support!
RolandrolandSat, 15 Jul 2017 06:17:59 -0500http://ask.sagemath.org/question/38274/