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, Symbolic_Prod, Symbolic_Term, Symbolic_statment, Tensor, Zahlen
Instance Method Summary collapse
- #Counting(a) ⇒ Object
- #Decimal(a, b = nil, c = '0', d = 0, e = 1) ⇒ Object
- #emptySet ⇒ Object
- #Fraction(a, b = Quotient(0,1), c = 1) ⇒ Object
- #infinity ⇒ Object
- #Kettenbruch(a, b = '', c = 1, leicht = true) ⇒ Object
- #List(a = nil, &b) ⇒ Object
- #Matrix(m, n) ⇒ Object
- #nan ⇒ Object
- #Natural(a) ⇒ Object
- #naught ⇒ Object
- #Quotient(a, b = 1) ⇒ Object
- #Real(a, &block) ⇒ Object
- #Sequence(a) ⇒ Object
- #Set(a, &b) ⇒ Object
- #Sigma(a, &block) ⇒ Object
- #Symbolic_Prod(a, b) ⇒ Object
- #Symbolic_Term(a, b) ⇒ Object
- #Tensor(m, *args) ⇒ Object
- #Zahlen(a) ⇒ Object
Instance Method Details
#Counting(a) ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/m500.rb', line 585 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
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# 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?(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 |
#emptySet ⇒ Object
559 560 561 |
# File 'lib/m500.rb', line 559 def emptySet EmptySetClass.new! end |
#Fraction(a, b = Quotient(0,1), c = 1) ⇒ Object
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# 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 |
#infinity ⇒ Object
565 566 567 |
# File 'lib/m500.rb', line 565 def infinity InfinityClass.new! end |
#Kettenbruch(a, b = '', c = 1, leicht = true) ⇒ Object
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# 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?(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) ⇒ 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
771 772 773 |
# File 'lib/m500.rb', line 771 def Matrix(m,n) Matrix.instanciate(m,n) end |
#Natural(a) ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/m500.rb', line 568 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 |
#naught ⇒ Object
556 557 558 |
# File 'lib/m500.rb', line 556 def naught NaughtClass.new! end |
#Quotient(a, b = 1) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/m500.rb', line 619 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 |
#Real(a, &block) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/m500.rb', line 249 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) ⇒ 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 |
#Symbolic_Prod(a, b) ⇒ Object
768 769 770 |
# File 'lib/m500.rb', line 768 def Symbolic_Prod(a,b) Symbolic_Prod.new(a,b) end |
#Symbolic_Term(a, b) ⇒ Object
765 766 767 |
# File 'lib/m500.rb', line 765 def Symbolic_Term(a,b) Symbolic_Term.new(a,b) end |
#Tensor(m, *args) ⇒ Object
774 775 776 |
# File 'lib/m500.rb', line 774 def Tensor(m,*args) Tensor.new!(m,*args) end |
#Zahlen(a) ⇒ Object
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/m500.rb', line 602 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 |