Top Level Namespace

Defined Under Namespace

Modules: Enumerable, SGML Classes: Array, Bignum, Counting, Decimal, EmptySetClass, Fixnum, Float, Fraction, InfinityClass, Kettenbruch, List, Matrix, NANClass, Natural, NaughtClass, Numeric, Quotient, Rational, Real, ST, Sequence, Set, Sigma, String, Tensor, Zahlen

Instance Method Summary collapse

Instance Method Details

#Counting(a) ⇒ Object



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/m500.rb', line 525

def Counting(a)
  if (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) ⇒ Object



642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/m500.rb', line 642

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?(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?(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

#emptySetObject



499
500
501
# File 'lib/m500.rb', line 499

def emptySet
  EmptySetClass.new!
end

#Fraction(a, b = Quotient(0,1), c = 1) ⇒ Object



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/m500.rb', line 600

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 a.kind_of?(Zahlen) && b.kind_of?(Fraction)
#    Fraction(a,b.to_Q)
  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

#infinityObject



505
506
507
# File 'lib/m500.rb', line 505

def infinity
  InfinityClass.new!
end

#Kettenbruch(a, b = '', c = 1, leicht = true) ⇒ Object



679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/m500.rb', line 679

def Kettenbruch(a,b='',c=1,leicht=true)
  if a.kind_of?(Kettenbruch)
    a 
  elsif a.kind_of?(NANClass) or a.kind_of?(InfinityClass)
    a
  elsif a.kind_of?(String)
    a.to_a.to_K
  elsif a.kind_of?(Proc) or a.kind_of?()
    a
  elsif (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
  end
end

#List(a = nil, &b) ⇒ Object



7
8
9
# File 'lib/M500_containers.rb', line 7

def List(a=nil,&b)
  b ?  List.new!(a) {b} : List.new!(a)
end

#Matrix(m, n) ⇒ Object



698
699
700
# File 'lib/m500.rb', line 698

def Matrix(m,n)
  Matrix.instanciate(m,n)
end

#nanObject



502
503
504
# File 'lib/m500.rb', line 502

def nan
  NANClass.new!
end

#Natural(a) ⇒ Object



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/m500.rb', line 508

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?(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

#naughtObject



496
497
498
# File 'lib/m500.rb', line 496

def naught
  NaughtClass.new!
end

#Quotient(a, b = 1) ⇒ Object



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/m500.rb', line 559

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)
    unless a == b
      Quotient.new!(Zahlen(a),Natural(b)) 
    else
      Quotient.new!(Zahlen(a),Natural(b)) 
    end
  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

#RealObject



696
697
# File 'lib/m500.rb', line 696

def Real()
end

#Sequence(a) ⇒ Object



13
14
15
# File 'lib/M500_containers.rb', line 13

def Sequence(a)
  Sequence.new(a)
end

#Set(a, &b) ⇒ Object



10
11
12
# File 'lib/M500_containers.rb', line 10

def Set(a,&b)
  b ?  Set.new!(a) {b} :  Set.new!(a)
end

#Sigma(a, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/M500_containers.rb', line 16

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

#Tensor(m, *args) ⇒ Object



701
702
703
# File 'lib/m500.rb', line 701

def Tensor(m,*args)
  Tensor.new!(m,*args)
end

#Zahlen(a) ⇒ Object



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/m500.rb', line 542

def Zahlen(a)
  if a.kind_of?(Zahlen)
     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?(Fixnum) or a.kind_of?(Bignum)
    Zahlen.new!(a)
  elsif a.kind_of?(Numeric)
    a.send :to_Z
  else
    emptySet
  end
end