Thanks very much for the help Salem.

In the end I used a different algortihm for the integral, but still had problems with the short form. So I forced the program to compute the answer using the long form every time, which seemed to work.