2 answers

This is a basic calculus question, really. It would not make sense for arctan(tan(pi/2)) to return pi/2 because tan(pi/2) is not defined. Sage returns Infinity because the limit of tan(x) as x -> pi/2 from the left is +Infinity and from the right is -Infinity. However, the limit of arctan(y) as y -> +Infinity is pi/2 but as y -> -Infinity is -pi/2. So you have to ask Sage for a limit: