Addition theorem for arctangent



see http://www.math.utexas.edu/pipermail/maxima/2013/033297.html
Thank Barton for your comments

(%i1) kill(all)$

(%i1) atan(tan(x));
(%o1) atan(tan(x))

(%i2) assume(abs(x)<=%pi/2)$
(%i3) atan(tan(x));
(%o3) x
 Then function atan_contract(r) work correct if abs(r)<=pi/2.

Updated vesion of atan_contract is
(%i4) atan_contract(r):=block([],
is(abs(r)<=%pi/2),
if %%=true
then
(
tan(r),
trigexpand(%%),
trigexpand(%%),
atan(%%))
else return(r)
)$

 Examples:
 1.
(%i5) atan_contract(42);
(%o5) 42

 2.
(%i6) atan_contract(atan(x)+atan(y));
(%o6) atan(y)+atan(x)
(%i7) declare([x,y],constant)$
(%i8) assume(abs(atan(x)+atan(y))<=%pi/2)$
(%i9) atan_contract(atan(x)+atan(y));
(%o9) atan((y+x)/(1-x*y))

 3.
(%i10) atan_contract(atan(1/2)+atan(1/3)+42);
(%o10) atan(1/2)+atan(1/3)+42
 In this case we need compute manualy:
(%i11) atan_contract(atan(1/2)+atan(1/3))+42;
(%o11) %pi/4+42

 5.
(%i12) atan_contract(atan(1/3)+atan(1/5)+atan(1/7)+atan(1/8));
(%o12) %pi/4

 6. Machin's  formulae
(%i13) atan_contract(4*atan(1/5)-atan(1/239));
(%o13) %pi/4

 For Machin's  formulae we need for calling trigexpand twice:
(%i14) tan(4*atan(1/5)-atan(1/239));
(%o14) tan(4*atan(1/5)-atan(1/239))
(%i15) trigexpand(%);
(%o15) (tan(4*atan(1/5))-1/239)/(tan(4*atan(1/5))/239+1)
(%i16) trigexpand(%);
(%o16) 1
(%i17) atan(%);
(%o17) %pi/4

 best

Aleksas D