Simplifying atan expressions



Consider the expression 4*atan(1/5)-atan(1/239) (Machin's formula).

How can we use Maxima to simplify it to %pi/4?

Well, here's one approach:

atan(trigexpand(trigexpand(tan(ex))))

And here's another way that doesn't depend on trig identities:

(%i1) ex:4*atan(1/5)-atan(1/239);
(%o1) 4*atan(1/5)-atan(1/239)
(%i2) llex: logcontract(logarc(ex));
(%o2) %i*log(-(%i-5)^4*(%i+239)/((%i-239)*(%i+5)^4))/2
(%i3) rectform(llex);
(%o3)
(atan(sin(4*atan(1/5))/cos(4*atan(1/5)))-atan(sin(4*(%pi-atan(1/5)))/cos(4*(%pi-atan(1/5))))-2*atan(1/239))/2
        <<< oops, not so helpful
(%i4) scanmap(rectform,llex,bottomup);
        <<< but reorganizing the rectform calculation gives a better result
        <<< makes me think that rectform could be improved...
(%o4) %pi/4

Are any of these techniques packaged into some analog of trigsimp?

                -s