```正木です。

|real|+|imag| で代用しています。

----
class Integer,Rational,Float
alias abs1 abs
def approx2(eps)
[self,eps]
end
end
class Complex
def Float?
real.type==Float || imag.type==Float
end
def abs1
if Float?
Math.sqrt!(abs2)
else
real.abs+imag.abs
end
end
def approx2(eps)
if real.type==Sequence2 || imag.type==Sequence2
re=real.approx2(eps)
im=imag.approx2(eps)
[Complex(re[0],im[0]),eps+re[1]+im[1]]
else
[self,eps]
end
end
alias mul *
def *(y)
case y
when Sequence2
y*self
else
mul y
end
end
end
class Sequence
def abs1
x=self
Sequence.new([],x){"|n,x| x[n].abs1"}
end
def inspect
"Sequence"+@list.inspect
end
end

class Sequence2
def abs1
Sequence2.new(@seq.abs1,@error)
end
def abs1max
@seq.abs1+@error
end
def abs1min
x=self
Sequence.new([],x){"|n,x|  [x[n].abs1-x.error[n],0].max "}
end
def find0
e,i=@error.find_with_index{|e,i| yield e}
[self[i],e]
end
x=self
z=[x[0]+y[0],x.error[0]+y.error[0]]
s=Sequence.new([z],x,y){"|n,x,y| e=self[n-1][1]/32
x0,x1= x.find0{|b| b<e}
y0,y1= y.find0{|b| b<e}
[x0+y0,x1+y1]
"}
Sequence2.new(s,"W")
end
def approx2(eps)
x,e=find0{|e| e <= eps }
x.approx2(eps+e)
end
def regular
x=self
s=Sequence.new([],x){"|n,x| x[n].approx2(x.error[n]) "}
Sequence2.new(s,"W")
end
def approx(eps)
regular[find_error{|e,i| e <= eps }[1]]
end
def inspect
"Sequence2("+@seq.inspect+",Error"+@error.inspect+")"
end
end

Sqrt=Function.new({0=>0}){"|x|
case x
when Float
sqrt(x)
when Sequence2
s=Sequence.new([],x){\"|n,x| Sqrt[x[n]].approx2(x.errorR[n]) \"}
RealComplex.new(s,'W')
else
a=(x<0)? Complex::I : 1
s=Sequence.new([a],x){\"|n,x| a=self[n-1];(a+x/a)/2 \"}.Shift
error=Sequence.new([],x,s){\"|n,x,s| y=s[n];(y-x/y).abs1 \"}
RealComplex.new(s,error)
end
"}
Root=Function.new{"|x|
Sequence.new([],x){'|m,x| a=1
s=Sequence.new([[a,1,1]],m,x){\"|n,m,x|
a,e,f=self[n-1]
a1=a.to_Real.approx(e**2/f)
e1=x/a1**(m-1)-a1
a2=a1+e1/m
e2=e1**2
f*=m if e<=e2
[a2,e2,f]
\"}.Shift
RealComplex.new(s,\"W\")
'}"}
Exp=Function.new({0=>1}){"|x|
case x
when Float
exp(x)
when Sequence2
s=Sequence.new([],x){\"|n,x| ex=Exp[x[n]]
ex.approx2(ex.abs1max[0]*(Exp[x.error[n]].abs1max[1]-1)) \"}
RealComplex.new(s,'W')
else
n=Integer(2*x.abs1)
RealComplex.new(ExpS[x].Sum.Shift(n),ExpS[x].abs1.Shift(n))
end
"}
Cos=Function.new({0=>1}){"|x|
case x
when Float
cos(x)
when Sequence2
s=Sequence.new([],x){\"|n,x| Cos[x[n]].approx2(x.error[n]) \"}
RealComplex.new(s,'W')
else
RealComplex.new(ExpS[x]*Double,'A')
end
"}
Sin=Function.new({0=>0}){"|x|
case x
when Float
sin(x)
when Sequence2
s=Sequence.new([],x){\"|n,x| Sin[x[n]].approx2(x.error[n]) \"}
RealComplex.new(s,'W')
else
RealComplex.new(ExpS[x].Shift*Double,'A')
end
"}
Tan=Function.new({0=>0}){"|x| Sin[x]/Cos[x] "}
AtanTerm=Function.new{"|x| OddPower[x]/Odd "}
Atan=Function.new({0=>0}){"|x|
case x
when Float
atan2(x,1)
else
(x<0)? -Atan[-x]:
(x>1)? Realpi/2-Atan[1/x] :
RealComplex.new(AtanTerm[x].alt.Sum,\"E\")
end
"}
Realpi=16*Atan[1/5]-4*Atan[1/239]
Log=Function.new({1=>0}){"|z|
case z
when Float
log(z)
when Sequence2
s=Sequence.new([],z){\"|n,z| Log[z[n]].approx2(z.errorR[n]) \"}
RealComplex.new(s,'W')
else
if z.abs1>2
Log[2]+Log[z/2]
elsif z.real>=0
RealComplex.new(2*AtanTerm[(z-1)/(z+1)].Sum,\"E\")
else
if z.imag>=0
Log[-z]+Log[Complex::I]*2
else
Log[-z]-Log[Complex::I]*2
end
end
end
"}
-----

```