Addition theorem for arctangent



 see
http://www.math.utexas.edu/pipermail/maxima/2013/033295.html
http://www.math.utexas.edu/pipermail/maxima/2013/033297.html
Thank Bart 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([],
if equal(r,%pi/2) then return(%pi/2)
elseif equal(r,-%pi/2) then return(-%pi/2),
is(abs(r)<%pi/2),
if %%=true then
(
tan(r),
trigexpand(%%),
trigexpand(%%),
atan(%%)
)
else return(r)
)$

 Examples:
 1.
(%i5) atan_contract(atan(1/2)+atan(2));
(%o5) %pi/2
(%i6) is (equal (atan(1/2)+atan(2), %pi/2));
(%o6) true
(%i7) compare(atan(1/2)+atan(2),%pi/2);
(%o7) "="

 2.
(%i8) atan_contract(atan(x)+atan(y));
(%o8) atan(y)+atan(x)
(%i9) assume(abs(atan(x)+atan(y))<%pi/2)$
(%i10) atan(x)+atan(y)=atan_contract(atan(x)+atan(y));
(%o10) atan(y)+atan(x)=atan((y+x)/(1-x*y))

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

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

 5. Machin's  formulae
(%i14) atan_contract(4*atan(1/5)-atan(1/239));
(%o14) %pi/4

 6. see http://en.wikipedia.org/wiki/Machin-like_formula
(%i15) 12*atan(1/49)+32*atan(1/57)-5*atan(1/239)+12*atan(1/110443)$
%=atan_contract(%);
(%o16) 12*atan(1/49)+32*atan(1/57)-5*atan(1/239)+12*atan(1/110443)=%pi/4

 For Machin's  formulae we need for calling trigexpand twice:
(%i17) tan(4*atan(1/5)-atan(1/239))$
(%i18) trigexpand(%);
(%o18) (tan(4*atan(1/5))-1/239)/(tan(4*atan(1/5))/239+1)
(%i19) trigexpand(%);
(%o19) 1
(%i20) atan(%);
(%o20) %pi/4

 Maple bug for combine arctan:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=combine/arctan
> restart;
> f:=arctan(x)+arctan(y);
 f := arctan(x) + arctan(y)
> assume(x>0,y>0);
> f=combine(f);
arctan(x~) + arctan(y~) = arctan((x~ + y~)/(1 - x~ y~)) + Pi
> subs({x=1/2,y=1/3},%);
arctan(1/2) + arctan(1/3) = arctan(1) + Pi
> evalf(%);
 0.7853981634 = 3.926990818

 best

Aleksas D