@asmeurer : This is because in my matching code, I used isinstance(i , Rational) . Should I change it to isinstance(i, Rational) or isinstance(i, Symbol) ?