class JAS::RingElem

Proxy for JAS ring elements.

Methods to be used as + - * ** / %.

Attributes

elem[R]

the Java element object

ring[R]

the Java factory object

Public Class Methods

new(elem) click to toggle source

Constructor for ring element.

    # File examples/jas.rb
544 def initialize(elem)
545     if elem.is_a? RingElem
546         @elem = elem.elem;
547     else
548         @elem = elem;
549     end
550     begin
551         @ring = @elem.factory();
552     rescue
553         @ring = @elem;
554     end
555     @elem.freeze
556     @ring.freeze
557     self.freeze
558 end

Public Instance Methods

%(other) click to toggle source

Modular remainder of two ring elements.

    # File examples/jas.rb
883 def %(other)
884     s,o = coercePair(self,other);
885     return RingElem.new( s.elem.remainder( o.elem ) ); 
886 end
*(other) click to toggle source

Multiply two ring elements.

    # File examples/jas.rb
844 def *(other)
845     #puts "* self  type(#{self.elem}) = #{self.elem.class}\n";
846     #puts "* other type(#{other.elem}) = #{other.elem.class}\n";
847     s,o = coercePair(self,other);
848     #puts "* s = #{s}, o = #{o}, s*o = #{s.elem.multiply(o.elem)}\n";
849     return RingElem.new( s.elem.multiply( o.elem ) ); 
850 end
**(other) click to toggle source

Power of this to other.

    # File examples/jas.rb
898 def **(other)
899     #puts "pow other type(#{other}) = #{other.class}";
900     if other.is_a? Integer
901         n = other;
902     else
903         if other.is_a? RingElem
904             n = other.elem;
905             if n.is_a? BigRational
906               #puts "#{n.numerator()} / #{n.denominator()}, other.elem = #{n}"
907               #todo (x**n.n)/(x**(-n.d))
908               if n.numerator().is_a? BigInteger
909                 n = n.numerator().intValue() / n.denominator().intValue();
910               else
911                 n = n.numerator() / n.denominator();
912               end
913             end
914             if n.is_a? BigInteger 
915                 n = n.intValue();
916             end
917         end
918     end
919     if isFactory()
920         p = Power.new(@elem).power( @elem, n );
921     else
922         p = Power.new(@elem.factory()).power( @elem, n );
923         #puts "@elem**#{n} = #{p}, @elem = #{@elem}"
924         #puts "@elem.ring = #{@elem.ring.toScript()}";
925     end
926     return RingElem.new( p ); 
927 end
+(other) click to toggle source

Add two ring elements.

    # File examples/jas.rb
855 def +(other)
856     #puts "+ self  type(#{self}) = #{self.elem.class}\n";
857     #puts "+ other type(#{other}) = #{other.elem.class}\n";
858     s,o = coercePair(self,other);
859     return RingElem.new( s.elem.sum( o.elem ) ); 
860 end
+@() click to toggle source

Positive value.

    # File examples/jas.rb
655 def +@()
656     return self; 
657 end
-(other) click to toggle source

Subtract two ring elements.

    # File examples/jas.rb
865 def -(other)
866     #puts "+ self  type(#{self}) = #{self.elem.class}\n";
867     #puts "+ other type(#{other}) = #{other.elem.class}\n";
868     s,o = coercePair(self,other);
869     return RingElem.new( s.elem.subtract( o.elem ) ); 
870 end
-@() click to toggle source

Negative value.

    # File examples/jas.rb
648 def -@()
649     return RingElem.new( @elem.negate() ); 
650 end
/(other) click to toggle source

Divide two ring elements.

    # File examples/jas.rb
875 def /(other)
876     s,o = coercePair(self,other);
877     return RingElem.new( s.elem.divide( o.elem ) ); 
878 end
<=>(other) click to toggle source

Compare two ring elements.

    # File examples/jas.rb
811 def <=>(other)
812     #s,o = coercePair(other);
813     s,o = self, other
814     return s.elem.compareTo( o.elem ); 
815 end
==(other) click to toggle source

Test if two ring elements are equal.

    # File examples/jas.rb
820 def ==(other)
821     if not other.is_a? RingElem
822        return false;
823     end
824     return (self <=> other) == 0; 
825 end
^(other) click to toggle source

Can not be used as power.

    # File examples/jas.rb
891 def ^(other)
892     return nil;
893 end
abs() click to toggle source

Absolute value.

    # File examples/jas.rb
641 def abs()
642     return RingElem.new( @elem.abs() ); 
643 end
algebraicRoots(eps=nil) click to toggle source

Compute algebraic roots, i.e. real and complex algebraic roots of univariate polynomial.

     # File examples/jas.rb
1248 def algebraicRoots(eps=nil)
1249     a = @elem;
1250     if eps.is_a? RingElem
1251         eps = eps.elem;
1252     end
1253     begin
1254         if eps == nil
1255             ar = RootFactory.algebraicRoots( a );
1256         else
1257             ar = RootFactory.algebraicRoots( a, eps );
1258         end
1259         #no: ar = ar.map{ |y| RingElem.new(y) };
1260         return RingElem.new(ar); #??
1261     rescue => e
1262         puts "error " + str(e)
1263         return nil
1264     end
1265 end
base_ring() click to toggle source

Coefficient ring of a polynomial.

     # File examples/jas.rb
1430 def base_ring()
1431     begin
1432         ev = @elem.ring.coFac;
1433     rescue
1434         return nil;
1435     end
1436     return RingElem.new(ev);
1437 end
call(num) click to toggle source

Apply this to num.

Call syntax is ringElem.(num). Only for interger num.

     # File examples/jas.rb
1373 def call(num)
1374     if num == 0 
1375         return zero();
1376     end
1377     if num == 1
1378         return one();
1379     end
1380     return RingElem.new( @ring.fromInteger(num) );
1381 end
coefficients() click to toggle source

Get the coefficients of a polynomial.

     # File examples/jas.rb
1346 def coefficients()
1347     a = @elem;
1348     #L = [ c.toScriptFactory() for c in a.coefficientIterator() ];
1349     ll = a.coefficientIterator().map { |c| RingElem.new(c) }; 
1350     return ll
1351 end
coerce(other) click to toggle source

Coerce other to self

    # File examples/jas.rb
662 def coerce(other)
663     s,o = coercePair(self,other);
664     return [o,s]; # keep order for non-commutative
665 end
coerceElem(other) click to toggle source

Coerce other to self

    # File examples/jas.rb
695 def coerceElem(other)
696     #puts "self  type(#{self}) = #{self.class}\n";
697     #puts "other type(#{other}) = #{other.class}\n";
698     if @elem.is_a? GenVector
699         if other.is_a? Array 
700             o = rbarray2arraylist(other,@elem.factory().coFac,rec=1);
701             o = GenVector.new(@elem.factory(),o);
702             return RingElem.new( o );
703             end
704     end
705     if @elem.is_a? GenMatrix
706         if other.is_a? Array 
707             o = rbarray2arraylist(other,@elem.factory().coFac,rec=2);
708             o = GenMatrix.new(@elem.factory(),o);
709             return RingElem.new( o );
710             end
711     end
712     if other.is_a? RingElem
713         if isPolynomial() and not other.isPolynomial()
714             #puts "other parse(#{@ring})\n";
715             o = @ring.parse( other.elem.toString() ); # not toScript()
716             return RingElem.new( o );
717         end
718         #puts "other type(#{other}) = #{other.class}\n";
719         return other;
720     end
721     #puts "--1";
722     if other.is_a? Array
723        # assume BigRational or BigComplex
724        # assume self will be compatible with them. todo: check this
725        puts "other type(#{other})_3 = #{other.class}\n";
726        o = makeJasArith(other);
727        puts "other type(#{o})_4 = #{o.class}\n";
728        ##o = BigRational.new(other[0],other[1]);
729        if isPolynomial()
730             o = @ring.parse( o.toString() ); # not toScript();
731             #o = o.elem;
732        elsif @elem.is_a? BigComplex
733             o = CC( o );
734             o = o.elem;
735        elsif @elem.is_a? BigQuaternion
736             o = Quat( o );
737             o = o.elem;
738        elsif @elem.is_a? BigOctonion
739             o = Oct( Quat(o) );
740             o = o.elem;
741        elsif @elem.is_a? Product
742             o = RR(@ring, @elem.multiply(o) ); # valueOf
743             #puts "o = #{o}";
744             o = o.elem;
745        end
746        puts "other type(#{o})_5 = #{o.class}\n";
747        return RingElem.new(o);
748     end
749     # test if @elem is a factory itself
750     if isFactory()
751         if other.is_a? Integer
752             o = @elem.fromInteger(other);
753         elsif other.is_a? Rational 
754             o = @elem.fromInteger( other.numerator );
755             o = o.divide( @elem.fromInteger( other.denominator ) );
756         elsif other.is_a? Float # ?? what to do ??
757             o = @elem.parse( other.to_s );
758             ##o = @elem.fromInteger( other.to_i );
759         else
760             puts "unknown other type(#{other})_1 = #{other.class}\n";
761             o = @elem.parse( other.to_s );
762         end
763         return RingElem.new(o);
764     end
765     # @elem has a ring factory
766     if other.is_a? Integer
767         o = @elem.factory().fromInteger(other);
768     elsif other.is_a? Rational 
769         o = @elem.factory().fromInteger( other.numerator );
770         o = o.divide( @elem.factory().fromInteger( other.denominator ) );
771     elsif other.is_a? Float # ?? what to do ??
772             o = @elem.factory().parse( other.to_s );
773             if @elem.is_a? Product
774                 o = RR(@ring, @elem.idempotent().multiply(o) ); # valueOf
775                 o = o.elem;
776             end
777     else
778             puts "unknown other type(#{other})_2 = #{other.class}\n";
779             o = @elem.factory().parse( other.to_s );
780     end
781     return RingElem.new(o);
782 end
coercePair(a,b) click to toggle source

Coerce type a to type b or type b to type a.

    # File examples/jas.rb
670 def coercePair(a,b)
671     #puts "a type(#{a}) = #{a.class}\n";
672     #puts "b type(#{b}) = #{b.class}\n";
673     begin
674         if not a.isPolynomial() and b.isPolynomial()
675            #puts "b = " + str(b.isPolynomial());
676            s = b.coerceElem(a);
677            o = b;
678         else
679            s = a;
680            o = a.coerceElem(b);
681         end
682     rescue => e
683            #puts "e #{e.message}, a = #{a}";
684         s = a;
685         o = a.coerceElem(b);
686     end
687     #puts "s type(#{s}) = #{s.class}\n";
688     #puts "o type(#{o}) = #{o.class}\n";
689     return [s,o];
690 end
complexRoots(eps=nil) click to toggle source

Compute complex roots of univariate polynomial.

     # File examples/jas.rb
1206 def complexRoots(eps=nil)
1207     a = @elem;
1208     if eps.is_a? RingElem
1209         eps = eps.elem;
1210     end
1211     cmplx = false;
1212     begin
1213         x = a.ring.coFac.getONE().getRe();
1214         cmplx = true;
1215     rescue => e
1216         #pass;
1217     end
1218     begin
1219         if eps == nil
1220             #rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a );
1221             if cmplx
1222                rr = RootFactory.complexAlgebraicNumbersComplex( a );
1223             else 
1224                rr = RootFactory.complexAlgebraicNumbers( a );
1225             end
1226             #R = [ r.centerApprox() for r in R ];
1227         else
1228             ## rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a, eps );
1229             ## rr = [ r.centerApprox() for r in rr ];
1230             ##rr = ComplexRootsSturm.new(a.ring.coFac).approximateRoots( a, eps );
1231             if cmplx
1232                rr = RootFactory.complexAlgebraicNumbersComplex( a, eps );
1233             else
1234                rr = RootFactory.complexAlgebraicNumbers( a, eps );
1235             end
1236         end
1237         rr = rr.map{ |y| RingElem.new(y) };
1238         return rr;
1239     rescue => e
1240         puts "error " + str(e)
1241         return nil
1242     end
1243 end
decimalRoots(eps=nil) click to toggle source

Compute decimal approximation of real and complex roots of univariate polynomial.

     # File examples/jas.rb
1288 def decimalRoots(eps=nil)
1289     a = @elem;
1290     if eps.is_a? RingElem
1291         eps = eps.elem;
1292     end
1293     if a.is_a? Java::EduJasRoot::AlgebraicRoots
1294         a = a.p;
1295     end
1296     begin
1297         d = RootFactory.decimalRoots( a, eps );
1298         return RingElem.new(d); # ??
1299     rescue => e
1300         puts "error " + str(e)
1301         return nil
1302     end
1303 end
degree() click to toggle source

Degree of a polynomial.

     # File examples/jas.rb
1418 def degree()
1419     begin
1420         ev = @elem.degree();
1421     rescue
1422         return nil;
1423     end
1424     return ev;
1425 end
differentiate(r=nil) click to toggle source

Differentiate a power series.

r is for partial differentiation in variable r.

     # File examples/jas.rb
1052 def differentiate(r=nil)
1053     begin
1054         if r != nil
1055             e = @elem.differentiate(r);
1056         else
1057             e = @elem.differentiate();
1058         end
1059     rescue
1060         e = @elem.factory().getZERO();
1061     end
1062     return RingElem.new( e );
1063 end
divides(other) click to toggle source

Test if self divides other.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1461 def divides(other)
1462     s,o = coercePair(self,other);
1463     return o.elem.remainder( s.elem ).isZERO(); 
1464 end
equal?(other) click to toggle source

Test if two ring elements are equal.

    # File examples/jas.rb
932 def equal?(other)
933     o = other;
934     if other.is_a? RingElem
935         o = other.elem;
936     end
937     return @elem.equals(o)
938 end
evaluate(a) click to toggle source

Evaluate at a for power series or polynomial.

     # File examples/jas.rb
 974 def evaluate(a)
 975     #puts "self  type(#{@elem}) = #{@elen.class}";
 976     #puts "a     type(#{a}) = #{a.class}";
 977     x = nil;
 978     if a.is_a? RingElem
 979         x = a.elem;
 980     end
 981     if a.is_a? Array 
 982         # assume BigRational or BigComplex
 983         # assume self will be compatible with them. todo: check this
 984         #x = makeJasArith(a);
 985         x = rbarray2arraylist(a);
 986     else
 987         x = rbarray2arraylist([a]);
 988     end
 989     begin
 990         if @elem.is_a? UnivPowerSeries
 991            e = @elem.evaluate(x[0]);
 992         else if @elem.is_a? MultiVarPowerSeries
 993               e = @elem.evaluate(x);
 994            else  
 995               #puts "x     = " + x[0].getClass().getSimpleName().to_s;
 996               x = x.map{ |p| p.leadingBaseCoefficient() };
 997               e = PolyUtil.evaluateAll(@ring.coFac, @elem, x);
 998            end
 999         end
1000     rescue => e
1001         raise RuntimeError, e.to_s; 
1002         e = 0;            
1003     end
1004     return RingElem.new( e );
1005 end
factors() click to toggle source

Compute irreducible factorization for modular, integer, rational number and algebriac number coefficients.

     # File examples/jas.rb
1127 def factors()
1128     a = @elem;
1129     if isPolynomial()
1130        factor = Ring.getEngineFactor(@ring); 
1131        if factor == nil 
1132           raise NotImplementedError, "factors not implemented for " + @ring.to_s;
1133        end
1134        cf = @ring.coFac;
1135        if cf.is_a? GenPolynomialRing
1136            e = factor.recursiveFactors( a );
1137        else
1138            e = factor.factors( a );
1139        end
1140        ll = {};
1141        for k in e.keySet()
1142            i = e.get(k);
1143            ll[ RingElem.new( k ) ] = i;
1144        end
1145        return ll;
1146     else
1147        raise NotImplementedError, "factors not implemented for " + a.to_s;
1148     end
1149 end
factorsAbsolute() click to toggle source

Compute absolute irreducible factorization for (modular,) rational number coefficients.

     # File examples/jas.rb
1155     def factorsAbsolute()
1156         a = @elem;
1157         if isPolynomial()
1158            factor = Ring.getEngineFactor(@ring); 
1159            if factor == nil 
1160               raise NotImplementedError, "factors not implemented for " + @ring.to_s;
1161            end
1162            begin
1163                ll = factor.factorsAbsolute( a );
1164 ##             ll = {};
1165 ##             for a in e.keySet()
1166 ##                 i = e.get(a);
1167 ##                 ll[ RingElem.new( a ) ] = i;
1168                return ll;
1169            rescue => e
1170                raise RuntimeError, "error factorsAbsolute " + @ring.to_s;
1171            end
1172         else
1173            raise NotImplementedError, "factors not implemented for " + a.to_s;
1174         end
1175     end
factory() click to toggle source

Get the factory of this element.

    # File examples/jas.rb
943 def factory()
944     fac = @elem.factory();
945     begin
946         nv = fac.nvar;
947     rescue
948         return RingElem.new(fac);
949     end
950     #return PolyRing(fac.coFac,fac.getVars(),fac.tord);
951     return RingElem.new(fac);
952 end
gcd(b) click to toggle source

Compute the greatest common divisor of this/self and b.

     # File examples/jas.rb
1080 def gcd(b)
1081     a = @elem;
1082     if b.is_a? RingElem
1083         b = b.elem;
1084     else
1085         b = element( b );
1086         b = b.elem;
1087     end
1088     if isPolynomial()
1089        engine = Ring.getEngineGcd(@ring); 
1090        return RingElem.new( engine.gcd(a,b) );
1091     else
1092        return RingElem.new( a.gcd(b) );
1093     end
1094 end
gens() click to toggle source

Get the generators for the factory of this element.

    # File examples/jas.rb
957 def gens()
958     ll = @elem.factory().generators();
959     #puts "L = #{ll}";
960     nn = ll.map {|e| RingElem.new(e) };
961     return nn;
962 end
ideal(list) click to toggle source

Create an ideal.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1471 def ideal(list)
1472     r = Ring.new("",ring=self.ring); #,fast=true
1473     return r.ideal("",list=list);
1474 end
integrate(a=0,r=nil) click to toggle source

Integrate a power series or rational function with constant a.

a is the integration constant, r is for partial integration in variable r.

     # File examples/jas.rb
1012 def integrate(a=0,r=nil)
1013     #puts "self  type(#{@elem}) = #{@elem.class}";
1014     #puts "a     type(#{a}) = #{a.class}";
1015     x = nil;
1016     if a.is_a? RingElem
1017         x = a.elem;
1018     end
1019     if a.is_a? Array 
1020         # assume BigRational or BigComplex
1021         # assume self will be compatible with them. todo: check this
1022         x = makeJasArith(a);
1023     end
1024     # power series
1025     begin 
1026         if r != nil
1027             e = @elem.integrate(x,r);
1028         else
1029             e = @elem.integrate(x);
1030         end
1031         return RingElem.new( e );
1032     rescue
1033         #pass;
1034     end
1035     cf = @elem.ring;
1036     begin
1037         cf = cf.ring;
1038     rescue
1039         #pass;
1040     end
1041     # rational function
1042     integrator = ElementaryIntegration.new(cf.coFac);
1043     ei = integrator.integrate(@elem); 
1044     return ei;
1045 end
isFactory() click to toggle source

Test if this is itself a ring factory.

    # File examples/jas.rb
787 def isFactory()
788     f = @elem.factory();
789     if @elem == f
790         return true;
791     else
792         return false;
793     end
794 end
isONE() click to toggle source

Test if this is the one element of the ring.

    # File examples/jas.rb
620 def isONE()
621     return @elem.isONE();
622 end
isPolynomial() click to toggle source

Test if this is a polynomial.

    # File examples/jas.rb
799 def isPolynomial()
800     begin
801         nv = @elem.ring.coFac; #nvar;
802     rescue
803         return false;
804     end
805     return true;
806 end
isZERO() click to toggle source

Test if this is the zero element of the ring.

    # File examples/jas.rb
599 def isZERO()
600     return @elem.isZERO();
601 end
is_field() click to toggle source

Test if this RingElem is field.

     # File examples/jas.rb
1442 def is_field()
1443     return @ring.isField();
1444 end
lc() click to toggle source

Leading coefficient of a polynomial.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1399 def lc()
1400     c = @elem.leadingBaseCoefficient();
1401     return RingElem.new(c);
1402 end
len() click to toggle source

Length of an element.

    # File examples/jas.rb
830 def len()
831     return self.elem.length(); 
832 end
lm() click to toggle source

Leading monomial of a polynomial.

Compatibility method for Sage/Singular. Note: the meaning of lt and lm is swapped compared to JAS.

     # File examples/jas.rb
1389 def lm()
1390     ev = @elem.leadingExpVector();
1391     return ev;
1392 end
lt() click to toggle source

Leading term of a polynomial.

Compatibility method for Sage/Singular. Note: the meaning of lt and lm is swapped compared to JAS.

     # File examples/jas.rb
1410 def lt()
1411     ev = @elem.leadingMonomial();
1412     return Monomial.new(ev);
1413 end
monic() click to toggle source

Monic polynomial.

    # File examples/jas.rb
967 def monic()
968     return RingElem.new( @elem.monic() ); 
969 end
monomial_divides(a,b) click to toggle source

Test divide of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1507 def monomial_divides(a,b)
1508     #print "JAS a = " + str(a) + ", b = " + str(b);
1509     if a.is_a? RingElem
1510         a = a.elem;
1511     end
1512     if a.is_a? GenPolynomial
1513         a = a.leadingExpVector();
1514     end
1515     if not a.is_a? ExpVector
1516         raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b)
1517     end
1518     if b == nil
1519         return False;
1520     end
1521     if b.is_a? RingElem
1522         b = b.elem;
1523     end
1524     if b.is_a? GenPolynomial
1525         b = b.leadingExpVector();
1526     end
1527     if not b.is_a? ExpVector
1528         raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b)
1529     end
1530     return a.divides(b);
1531 end
monomial_lcm(e,f) click to toggle source

Lcm of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1555 def monomial_lcm(e,f)
1556     if e.is_a? RingElem
1557         e = e.elem;
1558     end
1559     if f.is_a? RingElem
1560         f = f.elem;
1561     end
1562     # assume JAS ExpVector
1563     c = e.lcm(f);
1564     return c;
1565 end
monomial_pairwise_prime(e,f) click to toggle source

Test if ExpVectors are pairwise prime.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1538 def monomial_pairwise_prime(e,f)
1539     if e.is_a? RingElem
1540         e = e.elem;
1541     end
1542     if f.is_a? RingElem
1543         f = f.elem;
1544     end
1545     # assume JAS ExpVector
1546     c = e.gcd(f);
1547     return c.isZERO();
1548 end
monomial_quotient(a,b,coeff=false) click to toggle source

Quotient of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1481 def monomial_quotient(a,b,coeff=false)
1482     if a.is_a? RingElem
1483         a = a.elem;
1484     end
1485     if b.is_a? RingElem
1486         b = b.elem;
1487     end
1488     if coeff == false
1489         if a.is_a? GenPolynomial
1490             return RingElem.new( a.divide(b) );
1491         else
1492             return RingElem.new( GenPolynomial.new(@ring, a.subtract(b)) );
1493         end
1494     else
1495         # assume JAS Monomial
1496         c = a.coefficient().divide(b.coefficient());
1497         e = a.exponent().subtract(b.exponent())
1498         return RingElem.new( GenPolynomial.new(@ring, c, e) );
1499     end
1500 end
monomials() click to toggle source

All monomials of a polynomial.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1451 def monomials()
1452     ev = @elem.getMap().keySet();
1453     return ev;
1454 end
object_id() click to toggle source

Hash value.

    # File examples/jas.rb
837 def object_id()
838     return @elem.hashCode(); 
839 end
one() click to toggle source

One element of this ring.

    # File examples/jas.rb
613 def one()
614     return RingElem.new( @elem.factory().getONE() );
615 end
one?() click to toggle source

Test if this is the one element of the ring.

    # File examples/jas.rb
627 def one?()
628     return @elem.isONE();
629 end
parent() click to toggle source

Parent in Sage is factory in JAS.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1364 def parent()
1365     return factory();
1366 end
random(n=3) click to toggle source

Random element.

n size for random element will be less than 2**n.

     # File examples/jas.rb
1070 def random(n=3)
1071     if n.is_a? RingElem
1072        n = n.elem
1073     end
1074     return RingElem.new( @elem.factory().random(n) );
1075 end
realRoots(eps=nil) click to toggle source

Compute real roots of univariate polynomial.

     # File examples/jas.rb
1180 def realRoots(eps=nil)
1181     a = @elem;
1182     if eps.is_a? RingElem
1183         eps = eps.elem;
1184     end
1185     begin
1186         if eps == nil
1187             #rr = RealRootsSturm.new().realRoots( a );
1188             rr = RootFactory.realAlgebraicNumbers( a )
1189         else
1190             rr = RootFactory.realAlgebraicNumbers( a, eps );
1191             ## rr = RealRootsSturm.new().realRoots( a, eps );
1192             ## rr = [ r.toDecimal() for r in rr ];
1193             #rr = RealRootsSturm.new().approximateRoots(a,eps);
1194         end
1195         rr = rr.map{ |e| RingElem.new(e) };
1196         return rr;
1197     rescue => e
1198         puts "error " + str(e)
1199         return nil
1200     end
1201 end
reduce(ff) click to toggle source

Compute a normal form of self with respect to ff.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1572 def reduce(ff)
1573     s = @elem;
1574     fe = ff.map {|e| e.elem };
1575     n = ReductionSeq.new().normalform(fe,s);
1576     return RingElem.new(n);
1577 end
rootReduce(other) click to toggle source

Root reduce of real and complex algebraic numbers. Compute an extension field with a primitive element.

     # File examples/jas.rb
1327 def rootReduce(other)
1328     a = @elem;
1329     b = other;
1330     if b.is_a? RingElem
1331         b = b.elem;
1332     end
1333     begin #Java::EduJasApplication::
1334         d = RootFactoryApp.rootReduce( a, b );
1335         return RingElem.new(d); # ??
1336     rescue => e
1337         puts "error " + str(e)
1338         return nil
1339     end
1340 end
rootRefine(eps=nil) click to toggle source

Compute algebraic roots refinement.

     # File examples/jas.rb
1270 def rootRefine(eps=nil)
1271     r = @elem;
1272     if eps.is_a? RingElem
1273         eps = eps.elem;
1274     end
1275     begin
1276         RootFactory.rootRefine( r, eps );
1277         #no: ar = ar.map{ |y| RingElem.new(y) };
1278         return RingElem.new(r); # ??
1279     rescue => e
1280         puts "error " + str(e)
1281         return nil
1282     end
1283 end
rootsOfUnity() click to toggle source

Roots of unity of real and complex algebraic numbers.

     # File examples/jas.rb
1308 def rootsOfUnity()
1309     a = @elem;
1310     begin #Java::EduJasApplication::
1311         if a.is_a? AlgebraicRootsPrimElem
1312            d = RootFactoryApp.rootsOfUnity( a );
1313         else
1314            d = RootFactory.rootsOfUnity( a );
1315         end
1316         return RingElem.new(d); # ??
1317     rescue => e
1318         puts "error " + str(e)
1319         return nil
1320     end
1321 end
signum() click to toggle source

Get the sign of this element.

    # File examples/jas.rb
634 def signum()
635     return @elem.signum();
636 end
squarefreeFactors() click to toggle source

Compute squarefree factors of polynomial.

     # File examples/jas.rb
1099 def squarefreeFactors()
1100     a = @elem;
1101     if isPolynomial()
1102        sqf = Ring.getEngineSqf(@ring); 
1103        if sqf == nil 
1104           raise NotImplementedError, "squarefreeFactors not implemented for " + @ring.to_s;
1105        end
1106        cf = @ring.coFac;
1107        if cf.is_a? GenPolynomialRing
1108          e = sqf.recursiveSquarefreeFactors( a );
1109        else
1110          e = sqf.squarefreeFactors( a );
1111        end
1112        ll = {};
1113        for k in e.keySet()
1114            i = e.get(k);
1115            ll[ RingElem.new( k ) ] = i;
1116        end
1117        return ll;
1118     else
1119        raise NotImplementedError, "squarefreeFactors not implemented for " + a.to_s;
1120     end
1121 end
to_f() click to toggle source

Convert to float.

    # File examples/jas.rb
574 def to_f()
575     e = @elem;
576     if e.is_a? BigInteger
577         e = BigRational(e);
578     end
579     if e.is_a? BigRational
580         e = BigDecimal(e);
581     end
582     if e.is_a? BigDecimal
583         e = e.toString();
584     end
585     e = e.to_f();
586     return e;
587 end
to_s() click to toggle source

Create a string representation.

    # File examples/jas.rb
563 def to_s()
564     begin 
565        return @elem.toScript();
566     rescue 
567        return @elem.to_s(); 
568     end
569 end
zero() click to toggle source

Zero element of this ring.

    # File examples/jas.rb
592 def zero()
593     return RingElem.new( @elem.factory().getZERO() );
594 end
zero?() click to toggle source

Test if this is the zero element of the ring.

    # File examples/jas.rb
606 def zero?()
607     return @elem.isZERO();
608 end