"Testing rationalize"

clear

check(rationalize(0) == 0)
check(rationalize((a,b)) == (a,b))
check(infixform(rationalize((-1)^(-1/4) + 1)) == "(1 + (-1)^(1/4)) / (-1)^(1/4)")

-- test rationalize function (this used to get stuck)

s = 4 E^2
t = -2 E^2 + E^2 exp(i theta) + E^2 exp(-i theta)
u = -2 E^2 - E^2 exp(i theta) - E^2 exp(-i theta)

A = (s^2 + u^2)/t^2
B = 2 s^2/(t u)
C = (s^2 + t^2)/u^2

X = (1 + expcos(theta/2)^4) / expsin(theta/2)^4
Y = 8 / expsin(theta)^2
Z = (1 + expsin(theta/2)^4) / expcos(theta/2)^4

check(rationalize(A + B + C - X - Y - Z) == 0)

f = 1/x + 1/(x + 1)^2
check(infixform(rationalize(f)) == "(x^2 + 3 x + 1) / (x^3 + 2 x^2 + x)")
f = exp(i x) + exp(-i x)
check(infixform(rationalize(f)) == "(exp(2 i x) + 1) exp(-i x)")
