function [ y ] = etetri (x)
%y=etetri (x)
%
%inverse tetration of e, see etetr(x)
P=[-0.032486264307116,...
   0.161609516997898,...
  -0.272374056966456,...
   0.365751133821221,...
  -0.310443586372316,...
   1.087943256826769,...
   0];
dP=polyder(P);

if length(x)>1
  y=zeros(size(x));
  for i=1:length(x)
    y(i)=etetri(x(i));
  end
  return
end


yi=0;
if x<0
  yi=-1;
  x=exp(x);
else
  while x>1
    x=log(x);
    yi=yi+1;
  end
end
y=yi+ipoly(x,P,dP);
return
  










function x=ipoly(y,P,dP)
xn=y;
xn1=0;
while (abs(xn-xn1)>1e-10)
  dx=(polyval(P,xn)-y)/polyval(dP,xn);
  xn1=xn;
  xn=xn-dx;
end
x=xn;
return


