```正木です。続きです。とりあえず作ってみたものなので改良すべき点が

Rational#exp 等の戻り値は実数です。
Sequense#print(n,r) は n 桁の精度を保証しているものではありません。
(atan 以外はほぼ大丈夫なようですが、 atan 計算に使った級数の収斂が
あまり良くないようです。)

Rational.rb
----------
require "rational.rb"
require "Sequence.rb"
require "Sequence.sample.rb"

def (PowerOdd={}).[](x)
super || PowerOdd[x]=Sequence.new([x],x){"|n,x| x*x*self[n-1]"}
end
Odd=Sequence.new{"|n| 2*n+1"}

class Rational
def to_d(r=10)
a=@numerator
b=@denominator
Sequence.new([a],b,r){"|n,b,r| r*(self[n-1]%b)"}/b
end

def printd(n=16,r=10)
x=self
if x<0; print "-";x=-x;end
s=x.to_d(r)
print s[0],"."
for i in 1..n
printf("%x",s[i])
end
end

def exp(a=Rational(1,2))
x=self
return 1/(-x).exp if x < 0
return  ((x/2).exp)**2 if x>a
Exp[x]
end

def log
x=self
return Sequence.new{"|n| nil"} if x==0
return -((1/x).log)	if x<1
y=(x-1)/(x+1)
(PowerOdd[y]*2/Odd).Sum
end

def cos
x=self
(Sequence.new([],x){"|n,x| ExpS[x][2*n]"}*Sgn2).Sum
end

def sin
x=self
(Sequence.new([],x){"|n,x| ExpS[x][2*n+1]"}*Sgn2).Sum
end

def atan
x=self
Sequence.new([],x){"|n,x| Rational(Power[2][2*n]*Fact[n]**2,Fact[2*n+1])*P
ower[x][2*n+1]/Power[1+x**2][n+1]"}.Sum
end

def sqrt
x=self
Sequence.new([Rational(1)],x){"|n,x| a=self[n-1];(a+x/a)/2 "}
end
end
------------
Real.rb
------------
include Math
require "Rational.rb"

class Sequence
def sqrt
x=self
Sequence.new([Rational(1)],x){"|n,x| a=self[n-1];y=x[n];(a+y/a)/2 "}
end
def exp
x=self
Sequence.new([],x){"|n,x| x[n].exp[n]"}
end
def log
x=self
Sequence.new([],x){"|n,x| x[n].log[n]"}
end
def cos
x=self
Sequence.new([],x){"|n,x| x[n].cos[n]"}
end
def sin
x=self
Sequence.new([],x){"|n,x| x[n].sin[n]"}
end
def tan
sin/cos
end
def atan
x=self
Sequence.new([],x){"|n,x| x[n].atan[n]"}
end
def print(n=16,r=10)
self.succ_find{|x,y,i| (x-y).abs < Rational(1,r**n)}.printd(n,r)
end
end

class	Float
def divmod1
[self.floor,self-self.floor]
end
def to_ContFraction
a=self
s=Sequence.new([a.divmod1]){"|n|
b=self[n-1][1]
if b && b!=0
(1/b).divmod1
else
[nil,nil]
end
"}
Sequence.new([],s){"|n,s| s[n][0] "}
end

def to_Real
ContFraction_to_Real(self.to_ContFraction)
end
def print(n,r)
to_Real.print(16,10)
end
end

class Object
def Real(x)
case x
when Rational
Sequence.new([x],x){"|n,x| x"}
when Integer
Real(Rational(x))
when Float
x.to_Real
end
end

def ContFraction_to_Real(s)
a=Sequence.new([0,1],s){"|k,s|
q=s[k-2]
(q)? self[k-2]+q*self[k-1]:self[k-1] "}
b=Sequence.new([1,0],s){"|k,s|
q=s[k-2]
(q)? self[k-2]+q*self[k-1]:self[k-1] "}
Sequence.new([],a,b){"|k,a,b| Rational(a[k+2],b[k+2]) "}
end
def RealCF(list=[],&y)
s=Sequence.new(list,&y)
a=Sequence.new([0,1],s){"|k,s| q=s[k-2];self[k-2]+q*self[k-1] "}
b=Sequence.new([1,0],s){"|k,s| q=s[k-2];self[k-2]+q*self[k-1] "}
Sequence.new([],a,b){"|k,a,b| Rational(a[k+2],b[k+2]) "}
end

def GenContFraction_to_Real(s)
a=Sequence.new([0,1],s){"|k,s| p,q=s[k-2];p*self[k-2]+q*self[k-1] "}
b=Sequence.new([1,0],s){"|k,s| p,q=s[k-2];p*self[k-2]+q*self[k-1] "}
Sequence.new([],a,b){"|k,a,b| Rational(a[k+2],b[k+2]) "}
end
def RealGCF(list=[],&y)
s=Sequence.new(list,&y)
GenContFraction_to_Real(s)
end
end

class NilClass
def +(other)
other
end
def -(other)
-other
end
def <(other)
nil
end
def <(other)
nil
end
end
--------
testReal.rb
-------
#!/usr/local/bin/ruby

require "Real.rb"
require "getopts.rb"

Pi_by_GCF=RealGCF([[1,1]]){"|k| [k*k, 2*k+1] "}.inverse*4
E_GCF=RealGCF([[1,1],[2,1]]){"|k| [1,2*(2*k-1)] "}
E_CF=RealCF([2,1,2,1]){"|k| (k%3==2)? self[k-3]+2:self[k-3]"}
RealE=Exp[Rational(1)]
sqrt2=RealCF([1]){"|k| 2"}
Sqrt2=Real(2).sqrt
Pi_Ramanujan=(Sqrt2*2/9801*Sequence.new{"|n|
Rational(Fact[4*n],Fact[n]**4)*(1103+26390*n)/Power[4*99][4*n]
"}.Sum).inverse

getopts(nil,"f:sin","n:20","r:10","m:1","x:0.5")

f=\$OPT_f     # -f sqrt,exp,log,sin,cos,atan
r=\$OPT_r.to_i
n=\$OPT_n.to_i
m=\$OPT_m.to_i
x=\$OPT_x.to_f

case m
when 0
print f,"(#{x})="
eval("Real(x)."+f+".print(n,r)")
when 1
print "Real.",f,"(#{x})="
eval("Real(x)."+f+".print(n,r)")
print "\n"
print "Math.",f,"(#{x})="
eval("Real(Math."+f+"(x))").print(n,r)
when 2
print "e="
E_GCF.print(n,r)
when 3
print "e="
E_CF.print(n,r)
when 4
print "sqrt(2)="
sqrt2.print(n,r)
when 5
print "pi="
Pi_Ramanujan.print(n,r)
when 6
print "pi="
Pi_by_GCF.print(n,r)
when 7
print "pi="
((Rational(1,5).atan*4-Rational(1,239).atan)*4).print(n,r)
when 8
print "Real.pi="
Pi_Ramanujan.print(n,r)
print "\n"
print "Math.PI="
Real(Math::PI).print(n,r)
else
print "Float(#{x})="
Real(x).print(n,r)
end
print "\n"
-------

```