class Object
Public Instance Methods
Counting(a)
click to toggle source
# File lib/m500.rb, line 591 def Counting(a) if (a.kind_of?(Integer) && a >= 0) #(a.kind_of?(Fixnum) && a >= 0) or (a.kind_of?(Bignum) && a >= 0) Counting.new!(a) elsif (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(NaughtClass)) Counting.new!(0) elsif (a.kind_of?(InfinityClass)) infinity elsif (a.kind_of?(String)) Counting.new!(a.to_i) elsif a.kind_of?(Numeric) a.send :to_N0 else emptySet end end
Decimal(a,b=nil,c='0',d=0,e=1)
click to toggle source
# File lib/m500.rb, line 700 def Decimal(a,b=nil,c='0',d=0,e=1) if a.kind_of?(Decimal) a elsif (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(InfinityClass)) infinity elsif a.kind_of?(String) a.to_Dec elsif a.kind_of?(Integer) #(a.kind_of?(Fixnum) or a.kind_of?(Bignum)) and (b.kind_of?(Fixnum) or b.kind_of?(Bignum)) if e<0 then Decimal.new!(a,b,c,d,-1) else if a<0 then Decimal.new!(a,b,c,d,-1) elsif a>0 Decimal.new!(a,b,c,d,1) else Decimal.new!(0,b,c,d,1) end end elsif (a.kind_of?(Integer) and b.nil?) #(a.kind_of?(Fixnum) or a.kind_of?(Bignum)) and b.nil? if e<0 then Decimal.new!(a,b,c,d,-1) else if a<0 then Decimal.new!(a,nil,c,0,-1) elsif a>0 Decimal.new!(a,nil,c,0,1) else Decimal.new!(0,nil,c,0,1) end end elsif a.kind_of?(Numeric) a.send :to_Dec end end
Fraction(a,b=Quotient(0,1),c=1)
click to toggle source
# File lib/m500.rb, line 660 def Fraction(a,b=Quotient(0,1),c=1) if a.kind_of?(Zahlen) && b.kind_of?(Natural) then Fraction.new!(a,b,c) elsif a.kind_of?(Zahlen) && b.kind_of?(Quotient) if a>=0 and b>=0 then Fraction.new!(a,b,c) elsif a<0 and b<0 Fraction.new!(a*(-1),b*(-1),-1) else (a+b).to_Frac end elsif Integer === a && b.kind_of?(Quotient) if a>0 then Fraction.new!(Zahlen(a),b,c) else Fraction.new!(Zahlen(a*(-1)),b,-1*c) end elsif a.kind_of?(Quotient) && b == Quotient(0,1) Fraction.new!(a.numerator,a.denominator,c) elsif a.kind_of?(Fraction) && b == Quotient(0,1) a elsif a.kind_of?(String) && b == Quotient(0,1) a.to_Frac elsif b == 1 a elsif (a.kind_of?(NaughtClass)) Fraction.new!(Zahlen(0),b) elsif (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(InfinityClass)) infinity else tmp = Quotient(a,b) unless a == b or -a==b then Fraction.new!(tmp.numerator,tmp.denominator) else a/b end end end
Kettenbruch(a,b='',c=1,leicht=true)
click to toggle source
# File lib/m500.rb, line 737 def Kettenbruch(a,b='',c=1,leicht=true) if a.kind_of?(Kettenbruch) a elsif a.kind_of?(Array) b = a.shift b<0 ? Kettenbruch.new!(-1*b,a) : Kettenbruch.new!(b,a) elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) a elsif a.kind_of?(String) a.to_K elsif a.kind_of?(Proc) a elsif (a.kind_of?(Integer) and b.kind_of?(String)) # (a.kind_of?(Fixnum) or a.kind_of?(Bignum)) and b.kind_of?(String) if (a>0 and c<0) or (a<0 and c>0) then Kettenbruch.new!(a,b,-1) else Kettenbruch.new!(a,b,1) end elsif a.kind_of?(Quotient) and b=='' if a.to_Z == emptySet then (a>0 and c<0) or (a<0 and c>0) ? Kettenbruch.new!(a.abs,b,-1): Kettenbruch.new!(a.abs,b,1) else Kettenbruch(a.to_Z,b,c) end elsif (a.kind_of?(Zahlen) or a.kind_of?(Counting) or a.kind_of?(Natural))and b=='' (a>0 and c<0) or (a<0 and c>0) ? Kettenbruch.new!(a.abs,[],-1): Kettenbruch.new!(a.abs,[],1) end end
List(a=nil,&b)
click to toggle source
# File lib/M500_containers.rb, line 6 def List(a=nil,&b) b ? List.new!(a) {b} : List.new!(a) end
Matrix(m,n)
click to toggle source
# File lib/m500.rb, line 771 def Matrix(m,n) Matrix.instanciate(m,n) end
Natural(a)
click to toggle source
# File lib/m500.rb, line 574 def Natural(a) if (a.kind_of?(Natural)) a elsif (a.kind_of?(NaughtClass)) or (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(InfinityClass)) infinity elsif (a.kind_of?(String)) Natural.new!(a.to_i) elsif (a.kind_of?(Integer) && a >= 1) #(a.kind_of?(Fixnum) && a >= 1) or (a.kind_of?(Bignum) && a >= 1) Natural.new!(a) elsif a.kind_of?(Numeric) a.send :to_N else EmptySet end end
Quotient(a,b=1)
click to toggle source
# File lib/m500.rb, line 623 def Quotient(a,b=1) if b < 0 a = -a b = -b end if b == 0 or b.kind_of?(NaughtClass) return infinity elsif (a.kind_of?(NaughtClass)) Quotient(0,1) elsif (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(InfinityClass)) infinity elsif a.kind_of?(Quotient) && b == 1 a elsif a.kind_of?(Numeric) && (b.kind_of?(Quotient)||b.kind_of?(Fraction)) # =8= a/b elsif (a.kind_of?(String)) re = /(\-*\d+)\/(\d+)/ md = re.match(a) Quotient.new!(md[1].to_i,md[2].to_i) elsif a.kind_of?(Float) tmp = a.to_s.scan(/\d+/) m= tmp.at(1).length (Quotient.new!(((tmp.at(0).to_i)*(10**m)) + tmp.at(1).to_i,10**m)/(Quotient(b,1))) elsif b.kind_of?(Quotient) && a == 1 Quotient.new!(b.denominator,b.numerator) elsif Zahlen(a).kind_of?(Numeric) and Natural(b).kind_of?(Numeric) Quotient.new!(Zahlen(a),Natural(b)) elsif a.kind_of?(Quotient) && b.kind_of?(Quotient) return a/b elsif a.kind_of?(Numeric) a.send :to_Q else emptySet end end
Real(a,&block)
click to toggle source
# File lib/m500.rb, line 251 def Real(a,&block) if a.kind_of?(Real) a elsif a.kind_of?(Array) rez = Real.new!(Quotient(0,1),block) rez.continuedFraction = a.to_s rez.update_eval = proc{|k0,k,ret,irrat| (k0..k).to_a.each{|n| n==k0 ? ret << irrat.call(n): ret << ","+ irrat.call(n)}; ret = "[" + ret + "]";eval(Real::gcontinuedFractionFactory(eval(ret)))} rez.updateApprox{ @k0 = 1 @k = 12 @rat += update_eval.call(@k0,@k,@continuedFraction,@irrat).to_Q } elsif a.kind_of?(Quotient) Real.new!(a,block) elsif a.kind_of?(Natural) or a.kind_of?(Counting) or a.kind_of?(Zahlen) or a.kind_of?(Fraction) or a.kind_of?(Decimal) elsif Real.new!(a.to_Q,block) elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptySetClass) or a.kind_of?(NilClass) a unless b new(Quotinet(0,1),block) elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) a end end
Sequence(a)
click to toggle source
# File lib/M500_containers.rb, line 12 def Sequence(a) Sequence.new(a) end
Set(a,&b)
click to toggle source
# File lib/M500_containers.rb, line 9 def Set(a,&b) b ? Set.new!(a) {b} : Set.new!(a) end
Sigma(a,&block)
click to toggle source
# File lib/M500_containers.rb, line 15 def Sigma(a,&block) if a.kind_of?(Sigma) a elsif a.kind_of?(Quotient) Sigma.new!(a,block) elsif a.kind_of?(Natural) or a.kind_of?(Counting) or a.kind_of?(Zahlen) or a.kind_of?(Fraction) or a.kind_of?(Decimal) elsif Sigma.new!(a.to_Q,block) elsif a.kind_of?(NaughtClass) or a.kind_of?(EmptyListClass) or a.kind_of?(NilClass) a unless b new(Quotinet(0,1),block) elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass) a end end
Symbolic_Prod(a,b)
click to toggle source
# File lib/m500.rb, line 768 def Symbolic_Prod(a,b) Symbolic_Prod.new(a,b) end
Symbolic_Term(a,b)
click to toggle source
# File lib/m500.rb, line 765 def Symbolic_Term(a,b) Symbolic_Term.new(a,b) end
Tensor(m,*args)
click to toggle source
# File lib/m500.rb, line 774 def Tensor(m,*args) Tensor.new!(m,*args) end
Zahlen(a)
click to toggle source
# File lib/m500.rb, line 608 def Zahlen(a) if a.kind_of?(Integer) Zahlen.new!(a) elsif (a.kind_of?(EmptySetClass)) emptySet elsif (a.kind_of?(NaughtClass)) Zahlen.new!(0) elsif (a.kind_of?(InfinityClass)) infinity elsif a.kind_of?(Numeric) a.send :to_Z else emptySet end end
emptySet()
click to toggle source
# File lib/m500.rb, line 565 def emptySet EmptySetClass.new! end
infinity()
click to toggle source
# File lib/m500.rb, line 571 def infinity InfinityClass.new! end
nan()
click to toggle source
# File lib/m500.rb, line 568 def nan NANClass.new! end
naught()
click to toggle source
# File lib/m500.rb, line 562 def naught NaughtClass.new! end