Class | JAS::RingElem |
In: |
examples/jas.rb
|
Parent: | Object |
Proxy for JAS ring elements.
Methods to be used as + - * ** / %.
elem | [R] | |
ring | [R] |
Constructor for ring element.
# File examples/jas.rb, line 368 368: def initialize(elem) 369: if elem.is_a? RingElem 370: @elem = elem.elem; 371: else 372: @elem = elem; 373: end 374: begin 375: @ring = @elem.factory(); 376: rescue 377: @ring = @elem; 378: end 379: @elem.freeze 380: @ring.freeze 381: self.freeze 382: end
Modular remainder of two ring elements.
# File examples/jas.rb, line 694 694: def %(other) 695: s,o = coercePair(self,other); 696: return RingElem.new( s.elem.remainder( o.elem ) ); 697: end
Multiply two ring elements.
# File examples/jas.rb, line 658 658: def *(other) 659: #puts "* self type(#{self}) = #{self.class}\n"; 660: #puts "* other type(#{other}) = #{other.class}\n"; 661: s,o = coercePair(self,other); 662: return RingElem.new( s.elem.multiply( o.elem ) ); 663: end
Power of this to other.
# File examples/jas.rb, line 709 709: def **(other) 710: #puts "pow other type(#{other}) = #{other.class}"; 711: if other.is_a? Integer 712: n = other; 713: else 714: if other.is_a? RingElem 715: n = other.elem; 716: if n.getClass().getSimpleName() == "BigRational" 717: n = n.numerator().intValue() / n.denominator().intValue(); 718: end 719: if n.getClass().getSimpleName() == "BigInteger" 720: n = n.intValue(); 721: end 722: end 723: end 724: if isFactory() 725: p = Power.new(@elem).power( @elem, n ); 726: else 727: p = Power.new(@elem.ring).power( @elem, n ); 728: end 729: return RingElem.new( p ); 730: end
Add two ring elements.
# File examples/jas.rb, line 668 668: def +(other) 669: #puts "+ self type(#{self}) = #{self.class}\n"; 670: #puts "+ other type(#{other}) = #{other.class}\n"; 671: s,o = coercePair(self,other); 672: return RingElem.new( s.elem.sum( o.elem ) ); 673: end
Subtract two ring elements.
# File examples/jas.rb, line 678 678: def -(other) 679: s,o = coercePair(self,other); 680: return RingElem.new( s.elem.subtract( o.elem ) ); 681: end
Negative value.
# File examples/jas.rb, line 469 469: def -@() 470: return RingElem.new( @elem.negate() ); 471: end
Divide two ring elements.
# File examples/jas.rb, line 686 686: def /(other) 687: s,o = coercePair(self,other); 688: return RingElem.new( s.elem.divide( o.elem ) ); 689: end
Compare two ring elements.
# File examples/jas.rb, line 628 628: def <=>(other) 629: #s,o = coercePair(other); 630: s,o = self, other 631: return s.elem.compareTo( o.elem ); 632: end
Test if two ring elements are equal.
# File examples/jas.rb, line 637 637: def ===(other) 638: return (self <=> other) == 0; 639: end
Can not be used as power.
# File examples/jas.rb, line 702 702: def ^(other) 703: return nil; 704: end
Absolute value.
# File examples/jas.rb, line 462 462: def abs() 463: return RingElem.new( @elem.abs() ); 464: end
Get the coefficients of a polynomial.
# File examples/jas.rb, line 857 857: def coefficients() 858: a = @elem; 859: #L = [ c.toScriptFactory() for c in a.coefficientIterator() ]; 860: ll = a.coefficientIterator().map { |c| RingElem.new(c) }; 861: return ll 862: end
Coerce other to self
# File examples/jas.rb, line 483 483: def coerce(other) 484: s,o = coercePair(self,other); 485: return [o,s]; # keep order for non-commutative 486: end
Coerce other to self
# File examples/jas.rb, line 514 514: def coerceElem(other) 515: #puts "self type(#{self}) = #{self.class}\n"; 516: #puts "other type(#{other}) = #{other.class}\n"; 517: if @elem.getClass().getSimpleName() == "GenVector" 518: if other.is_a? Array 519: o = rbarray2arraylist(other,@elem.factory().coFac,rec=1); 520: o = GenVector.new(@elem.factory(),o); 521: return RingElem.new( o ); 522: end 523: end 524: if @elem.getClass().getSimpleName() == "GenMatrix" 525: if other.is_a? Array 526: o = rbarray2arraylist(other,@elem.factory().coFac,rec=2); 527: o = GenMatrix.new(@elem.factory(),o); 528: return RingElem.new( o ); 529: end 530: end 531: if other.is_a? RingElem 532: if isPolynomial() and not other.isPolynomial() 533: o = @ring.parse( other.elem.toString() ); # not toScript() 534: return RingElem.new( o ); 535: end 536: return other; 537: end 538: #puts "--1"; 539: if other.is_a? Array 540: # assume BigRational or BigComplex 541: # assume self will be compatible with them. todo: check this 542: puts "other type(#{other})_3 = #{other.class}\n"; 543: o = makeJasArith(other); 544: puts "other type(#{o})_4 = #{o.class}\n"; 545: ##o = BigRational.new(other[0],other[1]); 546: if isPolynomial() 547: o = @ring.parse( o.toString() ); # not toScript(); 548: #o = o.elem; 549: elsif @elem.getClass().getSimpleName() == "BigComplex" 550: o = CC( o ); 551: o = o.elem; 552: elsif @elem.getClass().getSimpleName() == "BigQuaternion" 553: o = Quat( o ); 554: o = o.elem; 555: elsif @elem.getClass().getSimpleName() == "BigOctonion" 556: o = Oct( Quat(o) ); 557: o = o.elem; 558: elsif @elem.getClass().getSimpleName() == "Product" 559: o = RR(@ring, @elem.multiply(o) ); # valueOf 560: #puts "o = #{o}"; 561: o = o.elem; 562: end 563: puts "other type(#{o})_5 = #{o.class}\n"; 564: return RingElem.new(o); 565: end 566: # test if @elem is a factory itself 567: if isFactory() 568: if other.is_a? Integer 569: o = @elem.fromInteger(other); 570: elsif other.is_a? Rational 571: o = @elem.fromInteger( other.numerator ); 572: o = o.divide( @elem.fromInteger( other.denominator ) ); 573: elsif other.is_a? Float # ?? what to do ?? 574: o = @elem.parse( other.to_s ); 575: ##o = @elem.fromInteger( other.to_i ); 576: else 577: puts "unknown other type(#{other})_1 = #{other.class}\n"; 578: o = @elem.parse( other.to_s ); 579: end 580: return RingElem.new(o); 581: end 582: # @elem has a ring factory 583: if other.is_a? Integer 584: o = @elem.factory().fromInteger(other); 585: elsif other.is_a? Rational 586: o = @elem.factory().fromInteger( other.numerator ); 587: o = o.divide( @elem.factory().fromInteger( other.denominator ) ); 588: elsif other.is_a? Float # ?? what to do ?? 589: o = @elem.factory().parse( other.to_s ); 590: if @elem.getClass().getSimpleName() == "Product" 591: o = RR(@ring, @elem.idempotent().multiply(o) ); # valueOf 592: o = o.elem; 593: end 594: else 595: puts "unknown other type(#{other})_2 = #{other.class}\n"; 596: o = @elem.factory().parse( other.to_s ); 597: end 598: return RingElem.new(o); 599: end
Coerce type a to type b or type b to type a.
# File examples/jas.rb, line 491 491: def coercePair(a,b) 492: #puts "a type(#{a}) = #{a.class}\n"; 493: #puts "b type(#{b}) = #{b.class}\n"; 494: begin 495: if not a.isPolynomial() and b.isPolynomial() 496: s = b.coerceElem(a); 497: o = b; 498: else 499: s = a; 500: o = a.coerceElem(b); 501: end 502: rescue 503: s = a; 504: o = a.coerceElem(b); 505: end 506: #puts "s type(#{s}) = #{s.class}\n"; 507: #puts "o type(#{o}) = #{o.class}\n"; 508: return [s,o]; 509: end
Differentiate a power series.
r is for partial differentiation in variable r.
# File examples/jas.rb, line 841 841: def differentiate(r=nil) 842: begin 843: if r != nil 844: e = @elem.differentiate(r); 845: else 846: e = @elem.differentiate(); 847: end 848: rescue 849: e = @elem.factory().getZERO(); 850: end 851: return RingElem.new( e ); 852: end
Test if two ring elements are equal.
# File examples/jas.rb, line 735 735: def equal?(other) 736: o = other; 737: if other.is_a? RingElem 738: o = other.elem; 739: end 740: return @elem.equals(o) 741: end
Evaluate at a for power series.
# File examples/jas.rb, line 778 778: def evaluate(a) 779: #puts "self type(#{@elem}) = #{@elen.class}"; 780: #puts "a type(#{a}) = #{a.class}"; 781: x = nil; 782: if a.is_a? RingElem 783: x = a.elem; 784: end 785: if a.is_a? Array 786: # assume BigRational or BigComplex 787: # assume self will be compatible with them. todo: check this 788: x = makeJasArith(a); 789: end 790: begin 791: e = @elem.evaluate(x); 792: rescue 793: e = 0; 794: end 795: return RingElem.new( e ); 796: end
Get the factory of this element.
# File examples/jas.rb, line 746 746: def factory() 747: fac = @elem.factory(); 748: begin 749: nv = fac.nvar; 750: rescue 751: return RingElem.new(fac); 752: end 753: #return PolyRing(fac.coFac,fac.getVars(),fac.tord); 754: return RingElem.new(fac); 755: end
Integrate a power series with constant a or as rational function.
a is the integration constant, r is for partial integration in variable r.
# File examples/jas.rb, line 803 803: def integrate(a=0,r=nil) 804: #puts "self type(#{@elem}) = #{@elem.class}"; 805: #puts "a type(#{a}) = #{a.class}"; 806: x = nil; 807: if a.is_a? RingElem 808: x = a.elem; 809: end 810: if a.is_a? Array 811: # assume BigRational or BigComplex 812: # assume self will be compatible with them. todo: check this 813: x = makeJasArith(a); 814: end 815: begin 816: if r != nil 817: e = @elem.integrate(x,r); 818: else 819: e = @elem.integrate(x); 820: end 821: return RingElem.new( e ); 822: rescue 823: #pass; 824: end 825: cf = @elem.ring; 826: begin 827: cf = cf.ring; 828: rescue 829: #pass; 830: end 831: integrator = ElementaryIntegration.new(cf.coFac); 832: ei = integrator.integrate(@elem); 833: return ei; 834: end
Test if this is a polynomial.
# File examples/jas.rb, line 616 616: def isPolynomial() 617: begin 618: nv = @elem.ring.nvar; 619: rescue 620: return false; 621: end 622: return true; 623: end
Length of an element.
# File examples/jas.rb, line 644 644: def len() 645: return self.elem.length(); 646: end
Monic polynomial.
# File examples/jas.rb, line 771 771: def monic() 772: return RingElem.new( @elem.monic() ); 773: end
Hash value.
# File examples/jas.rb, line 651 651: def object_id() 652: return @elem.hashCode(); 653: end
One element of this ring.
# File examples/jas.rb, line 434 434: def one() 435: return RingElem.new( @elem.factory().getONE() ); 436: end
Get the sign of this element.
# File examples/jas.rb, line 455 455: def signum() 456: return @elem.signum(); 457: end
Convert to float.
# File examples/jas.rb, line 395 395: def to_f() 396: e = @elem; 397: if e.getClass().getSimpleName() == "BigInteger" 398: e = BigRational(e); 399: end 400: if e.getClass().getSimpleName() == "BigRational" 401: e = BigDecimal(e); 402: end 403: if e.getClass().getSimpleName() == "BigDecimal" 404: e = e.toString(); 405: end 406: e = e.to_f(); 407: return e; 408: end
Create a string representation.
# File examples/jas.rb, line 387 387: def to_s() 388: return @elem.toScript(); 389: #return @elem.toString(); 390: end