That is to say, figure out the general algorithm for evaluating a polynomial at sqrt(-1) (it is simple, and just has to do with the degree of each term mod 4), and write that out explicitly in some helper function, so that you can exactly get the real and imaginary part of a rational function evaluated at sqrt(-1) without ever actually evaluating it at sqrt(-1).