expands:= proc(x) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; eval(`expands/expands`(subs(exp=`expands/exp`,x)), `expands/exp`=exp) end; `expands/expands`:= proc(x) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local res,f; if type(x,{`+`,`^`,`*`,set,list,table,rtable}) then res:=\ map(`expands/expands`,x) elif type(x, specfunc(anything,surd)) then RETURN(`expands/surd`(op(x))) else res:= expand(x) fi; if type(res,`^`) then RETURN(`expands/power`(op(1,res),op(2,res))) fi; if type(res,`*`) then RETURN(expand(res)) fi; if type(res,function) then f:= cat(`expands/`,op(0,res)); if type(f,procedure) then RETURN(f(op(res))) fi; f:= cat(`expand/`,op(0,res)); if type(f,procedure) then RETURN(f(op(res))) fi; fi; res; end; `expands/power`:= proc(x,e) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; if type(x,`*`) then map((a,b) -> expand(a^b), x, e) elif type(x,`^`) then op(1,x)^expand(op(2,x)*e) elif type(x,specfunc(anything,`expands/exp`)) then `expands/expands/exp`(expand(op(1,x)*e)) else `expand/power`(x,e) fi end; `expands/surd`:= proc(x,n) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; if type(x,`*`) then map((a,b) -> expands(surd(a,b)),x,n) elif type(x,`^`) then op(1,x)^(op(2,x)/n) elif type(x,specfunc(anything,`expands/exp`)) then `expands/expands/exp`(expand(op(1,x)/n)) else surd(x,n) fi end; `expands/ln`:= proc(y) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local b; if type(y,`*`) then add(expand(ln(b)),b = y) elif type(y,`^`) then expand(op(2,y)*ln(op(1,y))) else ln(x) fi end; `expands/expands/exp`:= proc(x) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local r,t; if type(x,`*`) then r,t:= selectremove(type,x,specfunc(anything,ln)); if r=1 or type(r,`*`) then RETURN(`expands/exp`(x)) else RETURN(`expands/expands`(op(1,r)^t)) fi fi; if type(x,`+`) then `expands/expands`(mul(`expands/exp`(t), t= x)) else `expands/exp`(x) fi end; `expands/arctan`:= proc(x) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local xe,xn,a,b,s,P,v,S; xe:= expands(x); if patmatch(xe,a::nonunit(algebraic) + b::nonunit(algebraic),s) then P:= numer(subs(s,a*v^2+v-b)); if type(P,`*`) then P:= select(has,P,v) fi; if not irreduc(P) then S:= [solve(P,v)]; if nops(S)=2 then return `expands/arctan`(S[1])-`expands/arctan`(1/S[2]) fi; fi fi; xn:= normal(xe); if type(xn,`*`) and type(op(1,xn),negint) then return -`expands/arctan`(-x) elif type(xn,`^`) and type(op(2,xn),negint) then return Pi/2 - `expands/arctan`(1/x) fi; if patmatch(xn,2*a::nonunit(algebraic),'s') then P:= numer(subs(s,a*v^2+v-a)); if type(P,`*`) then P:= select(has,P,v) fi; if not irreduc(P) then S:= [solve(P,v)]; if nops(S)>=1 then return 2*`expands/arctan`(S[1]) fi fi fi; if patmatch(xn,a::nonunit(algebraic)/2,'s') then P:= numer(subs(s,v^2+a*v-1)); if type(P,`*`) then P:= select(has,P,v) fi; if not irreduc(P) then S:= [solve(P,v)]; if nops(S)>=1 then return Pi/2 - 2*`expands/arctan`(S[1]) fi fi fi; return arctan(x); end;