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
545 def initialize(elem)
546     if elem.is_a? RingElem
547         @elem = elem.elem;
548     else
549         @elem = elem;
550     end
551     begin
552         @ring = @elem.factory();
553     rescue
554         @ring = @elem;
555     end
556     @elem.freeze
557     @ring.freeze
558     self.freeze
559 end

Public Instance Methods

%(other) click to toggle source

Modular remainder of two ring elements.

    # File examples/jas.rb
916 def %(other)
917     s,o = coercePair(self,other);
918     return RingElem.new( s.elem.remainder( o.elem ) ); 
919 end
*(other) click to toggle source

Multiply two ring elements.

    # File examples/jas.rb
871 def *(other)
872     #puts "* self  type(#{self.elem}) = #{self.elem.class}\n";
873     #puts "* other type(#{other.elem}) = #{other.elem.class}\n";
874     s,o = coercePair(self,other);
875     #puts "* s = #{s}, o = #{o}, s*o = #{s.elem.multiply(o.elem)}\n";
876     if s.elem.is_a? GenMatrix and o.elem.is_a? GenVector
877        return RingElem.new( BasicLinAlg.new().rightProduct(o.elem, s.elem) );
878     end;
879     if s.elem.is_a? GenVector and o.elem.is_a? GenMatrix
880        return RingElem.new( BasicLinAlg.new().leftProduct(s.elem, o.elem) );
881     end;
882     return RingElem.new( s.elem.multiply( o.elem ) ); 
883 end
**(other) click to toggle source

Power of this to other.

    # File examples/jas.rb
955 def **(other)
956     #puts "pow other type(#{other}) = #{other.class}";
957     if other.is_a? Integer
958         n = other;
959     else
960         if other.is_a? RingElem
961             n = other.elem;
962             if n.is_a? BigRational
963               #puts "#{n.numerator()} / #{n.denominator()}, other.elem = #{n}"
964               #todo (x**n.n)/(x**(-n.d))
965               if n.numerator().is_a? BigInteger
966                 n = n.numerator().intValue() / n.denominator().intValue();
967               else
968                 n = n.numerator() / n.denominator();
969               end
970             end
971             if n.is_a? BigInteger 
972                 n = n.intValue();
973             end
974         end
975     end
976     if isFactory()
977         p = Power.new(@elem).power( @elem, n );
978     else
979         p = Power.new(@elem.factory()).power( @elem, n );
980         #puts "@elem**#{n} = #{p}, @elem = #{@elem}"
981         #puts "@elem.ring = #{@elem.ring.toScript()}";
982     end
983     return RingElem.new( p ); 
984 end
+(other) click to toggle source

Add two ring elements.

    # File examples/jas.rb
888 def +(other)
889     #puts "+ self  type(#{self}) = #{self.elem.class}\n";
890     #puts "+ other type(#{other}) = #{other.elem.class}\n";
891     s,o = coercePair(self,other);
892     return RingElem.new( s.elem.sum( o.elem ) ); 
893 end
+@() click to toggle source

Positive value.

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

Subtract two ring elements.

    # File examples/jas.rb
898 def -(other)
899     #puts "+ self  type(#{self}) = #{self.elem.class}\n";
900     #puts "+ other type(#{other}) = #{other.elem.class}\n";
901     s,o = coercePair(self,other);
902     return RingElem.new( s.elem.subtract( o.elem ) ); 
903 end
-@() click to toggle source

Negative value.

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

Divide two ring elements.

    # File examples/jas.rb
908 def /(other)
909     s,o = coercePair(self,other);
910     return RingElem.new( s.elem.divide( o.elem ) ); 
911 end
<=>(other) click to toggle source

Compare two ring elements.

    # File examples/jas.rb
838 def <=>(other)
839     #s,o = coercePair(other);
840     s,o = self, other
841     return s.elem.compareTo( o.elem ); 
842 end
==(other) click to toggle source

Test if two ring elements are equal.

    # File examples/jas.rb
847 def ==(other)
848     if not other.is_a? RingElem
849        return false;
850     end
851     return (self <=> other) == 0; 
852 end
[](i,j) click to toggle source

Matrix entry.

    # File examples/jas.rb
924 def [](i,j)
925     return get(i,j);
926 end
^(other) click to toggle source

Can not be used as power.

    # File examples/jas.rb
948 def ^(other)
949     return nil;
950 end
abs() click to toggle source

Absolute value.

    # File examples/jas.rb
642 def abs()
643     return RingElem.new( @elem.abs() ); 
644 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
1305 def algebraicRoots(eps=nil)
1306     a = @elem;
1307     if eps.is_a? RingElem
1308         eps = eps.elem;
1309     end
1310     begin
1311         if eps == nil
1312             ar = RootFactory.algebraicRoots( a );
1313         else
1314             ar = RootFactory.algebraicRoots( a, eps );
1315         end
1316         #no: ar = ar.map{ |y| RingElem.new(y) };
1317         return RingElem.new(ar); #??
1318     rescue => e
1319         puts "error " + str(e)
1320         return nil
1321     end
1322 end
base_ring() click to toggle source

Coefficient ring of a polynomial.

     # File examples/jas.rb
1617 def base_ring()
1618     begin
1619         ev = @elem.ring.coFac;
1620     rescue
1621         return nil;
1622     end
1623     return RingElem.new(ev);
1624 end
call(num) click to toggle source

Apply this to num.

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

     # File examples/jas.rb
1560 def call(num)
1561     if num == 0 
1562         return zero();
1563     end
1564     if num == 1
1565         return one();
1566     end
1567     return RingElem.new( @ring.fromInteger(num) );
1568 end
coefficients() click to toggle source

Get the coefficients of a polynomial.

     # File examples/jas.rb
1534 def coefficients()
1535     a = @elem;
1536     ll = a.coefficientIterator().map { |c| RingElem.new(c) }; 
1537     return ll
1538 end
coerce(other) click to toggle source

Coerce other to self

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

Coerce other to self

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

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

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

Compute complex roots of univariate polynomial.

     # File examples/jas.rb
1263 def complexRoots(eps=nil)
1264     a = @elem;
1265     if eps.is_a? RingElem
1266         eps = eps.elem;
1267     end
1268     cmplx = false;
1269     begin
1270         x = a.ring.coFac.getONE().getRe();
1271         cmplx = true;
1272     rescue => e
1273         #pass;
1274     end
1275     begin
1276         if eps == nil
1277             #rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a );
1278             if cmplx
1279                rr = RootFactory.complexAlgebraicNumbersComplex( a );
1280             else 
1281                rr = RootFactory.complexAlgebraicNumbers( a );
1282             end
1283             #R = [ r.centerApprox() for r in R ];
1284         else
1285             ## rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a, eps );
1286             ## rr = [ r.centerApprox() for r in rr ];
1287             ##rr = ComplexRootsSturm.new(a.ring.coFac).approximateRoots( a, eps );
1288             if cmplx
1289                rr = RootFactory.complexAlgebraicNumbersComplex( a, eps );
1290             else
1291                rr = RootFactory.complexAlgebraicNumbers( a, eps );
1292             end
1293         end
1294         rr = rr.map{ |y| RingElem.new(y) };
1295         return rr;
1296     rescue => e
1297         puts "error " + str(e)
1298         return nil
1299     end
1300 end
contFrac(prec) click to toggle source

Continued fraction computation of rational and real algebraic numbers.

     # File examples/jas.rb
1403 def contFrac(prec)
1404     a = @elem;
1405     if a.is_a? RealAlgebraicNumber
1406        b = prec;
1407        if b.is_a? RingElem
1408           b = b.elem;
1409        end
1410        if b < 1
1411           b = 1;
1412        end
1413        d = RealArithUtil.continuedFraction(a, b);
1414        return d;
1415     end
1416     if a.is_a? BigRational
1417        d = ArithUtil.continuedFraction(a);
1418        return d;
1419     end
1420     raise ArgumentError, "type " + str(a.class) + " not supported"
1421 end
contFracApprox(lst) click to toggle source

Continued fraction expansion to approximate fraction.

     # File examples/jas.rb
1427 def contFracApprox(lst)
1428     if lst == nil
1429        d = BigRational::ZERO; 
1430        return RingElem.new( d );
1431     end
1432     nb = ArithUtil.continuedFractionApprox(lst);
1433     return RingElem.new( nb );
1434 end
decimalRoots(eps=nil) click to toggle source

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

     # File examples/jas.rb
1345 def decimalRoots(eps=nil)
1346     a = @elem;
1347     if eps.is_a? RingElem
1348         eps = eps.elem;
1349     end
1350     if a.is_a? Java::EduJasRoot::AlgebraicRoots
1351         a = a.p;
1352     end
1353     begin
1354         d = RootFactory.decimalRoots( a, eps );
1355         return RingElem.new(d); # ??
1356     rescue => e
1357         puts "error " + str(e)
1358         return nil
1359     end
1360 end
decompLU() click to toggle source

Decompose to LU matrix. this is modified.

     # File examples/jas.rb
1453 def decompLU()
1454     a = @elem;
1455     p = LinAlg.new().decompositionLU(a);
1456     uu = a.getUpper();
1457     ll = a.getLower();
1458     return [ RingElem.new(ll), RingElem.new(uu), RingElem.new(p) ];
1459 end
degree() click to toggle source

Degree of a polynomial.

     # File examples/jas.rb
1605 def degree()
1606     begin
1607         ev = @elem.degree();
1608     rescue
1609         return nil;
1610     end
1611     return ev;
1612 end
determinant(p=nil) click to toggle source

Determinant from LU matrix.

     # File examples/jas.rb
1481 def determinant(p=nil)
1482     a = @elem;
1483     la = LinAlg.new();
1484     if p == nil
1485       p = la.decompositionLU(a);
1486     end;
1487     if p.is_a? RingElem
1488        p = p.elem;
1489     end
1490     if p.isEmpty()
1491       d = @ring.coFac.getZERO();
1492     else
1493       d = la.determinantLU(a,p);
1494     end;
1495     return RingElem.new(d);
1496 end
differentiate(r=nil) click to toggle source

Differentiate a power series.

r is for partial differentiation in variable r.

     # File examples/jas.rb
1109 def differentiate(r=nil)
1110     begin
1111         if r != nil
1112             e = @elem.differentiate(r);
1113         else
1114             e = @elem.differentiate();
1115         end
1116     rescue
1117         e = @elem.factory().getZERO();
1118     end
1119     return RingElem.new( e );
1120 end
divides(other) click to toggle source

Test if self divides other.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1648 def divides(other)
1649     s,o = coercePair(self,other);
1650     return o.elem.remainder( s.elem ).isZERO(); 
1651 end
equal?(other) click to toggle source

Test if two ring elements are equal.

    # File examples/jas.rb
989 def equal?(other)
990     o = other;
991     if other.is_a? RingElem
992         o = other.elem;
993     end
994     return @elem.equals(o)
995 end
evaluate(a) click to toggle source

Evaluate at a for power series or polynomial.

     # File examples/jas.rb
1031 def evaluate(a)
1032     #puts "self  type(#{@elem}) = #{@elen.class}";
1033     #puts "a     type(#{a}) = #{a.class}";
1034     x = nil;
1035     if a.is_a? RingElem
1036         x = a.elem;
1037     end
1038     if a.is_a? Array 
1039         # assume BigRational or BigComplex
1040         # assume self will be compatible with them. todo: check this
1041         #x = makeJasArith(a);
1042         x = rbarray2arraylist(a);
1043     else
1044         x = rbarray2arraylist([a]);
1045     end
1046     begin
1047         if @elem.is_a? UnivPowerSeries
1048            e = @elem.evaluate(x[0]);
1049         else if @elem.is_a? MultiVarPowerSeries
1050               e = @elem.evaluate(x);
1051            else  
1052               #puts "x     = " + x[0].getClass().getSimpleName().to_s;
1053               x = x.map{ |p| p.leadingBaseCoefficient() };
1054               e = PolyUtil.evaluateAll(@ring.coFac, @elem, x);
1055            end
1056         end
1057     rescue => e
1058         raise RuntimeError, e.to_s; 
1059         e = 0;            
1060     end
1061     return RingElem.new( e );
1062 end
factors() click to toggle source

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

     # File examples/jas.rb
1184 def factors()
1185     a = @elem;
1186     if isPolynomial()
1187        factor = Ring.getEngineFactor(@ring); 
1188        if factor == nil 
1189           raise NotImplementedError, "factors not implemented for " + @ring.to_s;
1190        end
1191        cf = @ring.coFac;
1192        if cf.is_a? GenPolynomialRing
1193            e = factor.recursiveFactors( a );
1194        else
1195            e = factor.factors( a );
1196        end
1197        ll = {};
1198        for k in e.keySet()
1199            i = e.get(k);
1200            ll[ RingElem.new( k ) ] = i;
1201        end
1202        return ll;
1203     else
1204        raise NotImplementedError, "factors not implemented for " + a.to_s;
1205     end
1206 end
factorsAbsolute() click to toggle source

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

     # File examples/jas.rb
1212     def factorsAbsolute()
1213         a = @elem;
1214         if isPolynomial()
1215            factor = Ring.getEngineFactor(@ring); 
1216            if factor == nil 
1217               raise NotImplementedError, "factors not implemented for " + @ring.to_s;
1218            end
1219            begin
1220                ll = factor.factorsAbsolute( a );
1221 ##             ll = {};
1222 ##             for a in e.keySet()
1223 ##                 i = e.get(a);
1224 ##                 ll[ RingElem.new( a ) ] = i;
1225                return ll;
1226            rescue => e
1227                raise RuntimeError, "error factorsAbsolute " + @ring.to_s;
1228            end
1229         else
1230            raise NotImplementedError, "factors not implemented for " + a.to_s;
1231         end
1232     end
factory() click to toggle source

Get the factory of this element.

     # File examples/jas.rb
1000 def factory()
1001     fac = @elem.factory();
1002     begin
1003         nv = fac.nvar;
1004     rescue
1005         return RingElem.new(fac);
1006     end
1007     #return PolyRing(fac.coFac,fac.getVars(),fac.tord);
1008     return RingElem.new(fac);
1009 end
gcd(b) click to toggle source

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

     # File examples/jas.rb
1137 def gcd(b)
1138     a = @elem;
1139     if b.is_a? RingElem
1140         b = b.elem;
1141     else
1142         b = element( b );
1143         b = b.elem;
1144     end
1145     if isPolynomial()
1146        engine = Ring.getEngineGcd(@ring); 
1147        return RingElem.new( engine.gcd(a,b) );
1148     else
1149        return RingElem.new( a.gcd(b) );
1150     end
1151 end
gens() click to toggle source

Get the generators for the factory of this element.

     # File examples/jas.rb
1014 def gens()
1015     ll = @elem.factory().generators();
1016     #puts "L = #{ll}";
1017     nn = ll.map {|e| RingElem.new(e) };
1018     return nn;
1019 end
get(i,j) click to toggle source

Matrix entry.

    # File examples/jas.rb
931 def get(i,j)
932     if not elem.is_a? GenMatrix
933       raise "no matrix " + ring.to_s
934     end
935     if i.is_a? RingElem
936       i = i.elem;
937     end
938     if j.is_a? RingElem
939       j = j.elem;
940     end
941     e = elem.get(i,j);
942     return RingElem.new( e );
943 end
ideal(list) click to toggle source

Create an ideal.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1658 def ideal(list)
1659     r = Ring.new("",ring=self.ring); #,fast=true
1660     return r.ideal("",list=list);
1661 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
1069 def integrate(a=0,r=nil)
1070     #puts "self  type(#{@elem}) = #{@elem.class}";
1071     #puts "a     type(#{a}) = #{a.class}";
1072     x = nil;
1073     if a.is_a? RingElem
1074         x = a.elem;
1075     end
1076     if a.is_a? Array 
1077         # assume BigRational or BigComplex
1078         # assume self will be compatible with them. todo: check this
1079         x = makeJasArith(a);
1080     end
1081     # power series
1082     begin 
1083         if r != nil
1084             e = @elem.integrate(x,r);
1085         else
1086             e = @elem.integrate(x);
1087         end
1088         return RingElem.new( e );
1089     rescue
1090         #pass;
1091     end
1092     cf = @elem.ring;
1093     begin
1094         cf = cf.ring;
1095     rescue
1096         #pass;
1097     end
1098     # rational function
1099     integrator = ElementaryIntegration.new(cf.coFac);
1100     ei = integrator.integrate(@elem); 
1101     return ei;
1102 end
isAlgNum() click to toggle source

Test if this is an algebraic number.

    # File examples/jas.rb
826 def isAlgNum()
827     begin
828         nv = @elem.ring.ring.nvar; #coFac
829     rescue
830         return false;
831     end
832     return true;
833 end
isFactory() click to toggle source

Test if this is itself a ring factory.

    # File examples/jas.rb
802 def isFactory()
803     f = @elem.factory();
804     if @elem == f
805         return true;
806     else
807         return false;
808     end
809 end
isONE() click to toggle source

Test if this is the one element of the ring.

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

Test if this is a polynomial.

    # File examples/jas.rb
814 def isPolynomial()
815     begin
816         nv = @elem.ring.coFac; #nvar;
817     rescue
818         return false;
819     end
820     return true;
821 end
isZERO() click to toggle source

Test if this is the zero element of the ring.

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

Test if this RingElem is field.

     # File examples/jas.rb
1629 def is_field()
1630     return @ring.isField();
1631 end
lc() click to toggle source

Leading coefficient of a polynomial.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1586 def lc()
1587     c = @elem.leadingBaseCoefficient();
1588     return RingElem.new(c);
1589 end
len() click to toggle source

Length of an element.

    # File examples/jas.rb
857 def len()
858     return self.elem.length(); 
859 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
1576 def lm()
1577     ev = @elem.leadingExpVector();
1578     return ev;
1579 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
1597 def lt()
1598     ev = @elem.leadingMonomial();
1599     return Monomial.new(ev);
1600 end
monic() click to toggle source

Monic polynomial.

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

Test divide of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1694 def monomial_divides(a,b)
1695     #print "JAS a = " + str(a) + ", b = " + str(b);
1696     if a.is_a? RingElem
1697         a = a.elem;
1698     end
1699     if a.is_a? GenPolynomial
1700         a = a.leadingExpVector();
1701     end
1702     if not a.is_a? ExpVector
1703         raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b)
1704     end
1705     if b == nil
1706         return False;
1707     end
1708     if b.is_a? RingElem
1709         b = b.elem;
1710     end
1711     if b.is_a? GenPolynomial
1712         b = b.leadingExpVector();
1713     end
1714     if not b.is_a? ExpVector
1715         raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b)
1716     end
1717     return a.divides(b);
1718 end
monomial_lcm(e,f) click to toggle source

Lcm of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1742 def monomial_lcm(e,f)
1743     if e.is_a? RingElem
1744         e = e.elem;
1745     end
1746     if f.is_a? RingElem
1747         f = f.elem;
1748     end
1749     # assume JAS ExpVector
1750     c = e.lcm(f);
1751     return c;
1752 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
1725 def monomial_pairwise_prime(e,f)
1726     if e.is_a? RingElem
1727         e = e.elem;
1728     end
1729     if f.is_a? RingElem
1730         f = f.elem;
1731     end
1732     # assume JAS ExpVector
1733     c = e.gcd(f);
1734     return c.isZERO();
1735 end
monomial_quotient(a,b,coeff=false) click to toggle source

Quotient of ExpVectors.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1668 def monomial_quotient(a,b,coeff=false)
1669     if a.is_a? RingElem
1670         a = a.elem;
1671     end
1672     if b.is_a? RingElem
1673         b = b.elem;
1674     end
1675     if coeff == false
1676         if a.is_a? GenPolynomial
1677             return RingElem.new( a.divide(b) );
1678         else
1679             return RingElem.new( GenPolynomial.new(@ring, a.subtract(b)) );
1680         end
1681     else
1682         # assume JAS Monomial
1683         c = a.coefficient().divide(b.coefficient());
1684         e = a.exponent().subtract(b.exponent())
1685         return RingElem.new( GenPolynomial.new(@ring, c, e) );
1686     end
1687 end
monomials() click to toggle source

All monomials of a polynomial.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1638 def monomials()
1639     ev = @elem.getMap().keySet();
1640     return ev;
1641 end
nullSpace() click to toggle source

Null space basis. {v_i} with v_i * self = 0.

     # File examples/jas.rb
1524 def nullSpace()
1525     a = @elem;
1526     r = LinAlg.new().nullSpaceBasis(a);
1527     return r;
1528 end
object_id() click to toggle source

Hash value.

    # File examples/jas.rb
864 def object_id()
865     return @elem.hashCode(); 
866 end
one() click to toggle source

One element of this ring.

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

Test if this is the one element of the ring.

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

Parent in Sage is factory in JAS.

Compatibility method for Sage/Singular.

     # File examples/jas.rb
1551 def parent()
1552     return factory();
1553 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
1127 def random(n=3)
1128     if n.is_a? RingElem
1129        n = n.elem
1130     end
1131     return RingElem.new( @elem.factory().random(n) );
1132 end
rank() click to toggle source

rank from row echelon form matrix.

     # File examples/jas.rb
1514 def rank()
1515     a = @elem;
1516     r = LinAlg.new().rankRE(a);
1517     return r;
1518 end
realRoots(eps=nil) click to toggle source

Compute real roots of univariate polynomial.

     # File examples/jas.rb
1237 def realRoots(eps=nil)
1238     a = @elem;
1239     if eps.is_a? RingElem
1240         eps = eps.elem;
1241     end
1242     begin
1243         if eps == nil
1244             #rr = RealRootsSturm.new().realRoots( a );
1245             rr = RootFactory.realAlgebraicNumbers( a )
1246         else
1247             rr = RootFactory.realAlgebraicNumbers( a, eps );
1248             ## rr = RealRootsSturm.new().realRoots( a, eps );
1249             ## rr = [ r.toDecimal() for r in rr ];
1250             #rr = RealRootsSturm.new().approximateRoots(a,eps);
1251         end
1252         rr = rr.map{ |e| RingElem.new(e) };
1253         return rr;
1254     rescue => e
1255         puts "error " + str(e)
1256         return nil
1257     end
1258 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
1759 def reduce(ff)
1760     s = @elem;
1761     fe = ff.map {|e| e.elem };
1762     n = ReductionSeq.new().normalform(fe,s);
1763     return RingElem.new(n);
1764 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
1384 def rootReduce(other)
1385     a = @elem;
1386     b = other;
1387     if b.is_a? RingElem
1388         b = b.elem;
1389     end
1390     begin #Java::EduJasApplication::
1391         d = RootFactoryApp.rootReduce( a, b );
1392         return RingElem.new(d); # ??
1393     rescue => e
1394         puts "error " + str(e)
1395         return nil
1396     end
1397 end
rootRefine(eps=nil) click to toggle source

Compute algebraic roots refinement.

     # File examples/jas.rb
1327 def rootRefine(eps=nil)
1328     r = @elem;
1329     if eps.is_a? RingElem
1330         eps = eps.elem;
1331     end
1332     begin
1333         RootFactory.rootRefine( r, eps );
1334         #no: ar = ar.map{ |y| RingElem.new(y) };
1335         return RingElem.new(r); # ??
1336     rescue => e
1337         puts "error " + str(e)
1338         return nil
1339     end
1340 end
rootsOfUnity() click to toggle source

Roots of unity of real and complex algebraic numbers.

     # File examples/jas.rb
1365 def rootsOfUnity()
1366     a = @elem;
1367     begin #Java::EduJasApplication::
1368         if a.is_a? AlgebraicRootsPrimElem
1369            d = RootFactoryApp.rootsOfUnity( a );
1370         else
1371            d = RootFactory.rootsOfUnity( a );
1372         end
1373         return RingElem.new(d); # ??
1374     rescue => e
1375         puts "error " + str(e)
1376         return nil
1377     end
1378 end
rowEchelon() click to toggle source

Row echelon form matrix.

     # File examples/jas.rb
1502 def rowEchelon()
1503     a = @elem;
1504     la = LinAlg.new();
1505     re = la.rowEchelonForm(a);
1506     res = la.rowEchelonFormSparse(re);
1507     return RingElem.new(res);
1508 end
signum() click to toggle source

Get the sign of this element.

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

Solve system of linear equations.

     # File examples/jas.rb
1440 def solve(b)
1441     a = @elem;
1442     if b.is_a? RingElem
1443        b = b.elem;
1444     end
1445     x = LinAlg.new().solve(a,b);
1446     return RingElem.new(x);
1447 end
solveLU(p, b) click to toggle source

Solve with LU matrix.

     # File examples/jas.rb
1465 def solveLU(p, b)
1466     a = @elem;
1467     if b.is_a? RingElem
1468        b = b.elem;
1469     end
1470     if p.is_a? RingElem
1471        p = p.elem;
1472     end
1473     x = LinAlg.new().solveLU(a,p,b);
1474     return RingElem.new(x);
1475 end
squarefreeFactors() click to toggle source

Compute squarefree factors of polynomial.

     # File examples/jas.rb
1156 def squarefreeFactors()
1157     a = @elem;
1158     if isPolynomial()
1159        sqf = Ring.getEngineSqf(@ring); 
1160        if sqf == nil 
1161           raise NotImplementedError, "squarefreeFactors not implemented for " + @ring.to_s;
1162        end
1163        cf = @ring.coFac;
1164        if cf.is_a? GenPolynomialRing
1165          e = sqf.recursiveSquarefreeFactors( a );
1166        else
1167          e = sqf.squarefreeFactors( a );
1168        end
1169        ll = {};
1170        for k in e.keySet()
1171            i = e.get(k);
1172            ll[ RingElem.new( k ) ] = i;
1173        end
1174        return ll;
1175     else
1176        raise NotImplementedError, "squarefreeFactors not implemented for " + a.to_s;
1177     end
1178 end
to_f() click to toggle source

Convert to float.

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

Create a string representation.

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

Zero element of this ring.

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

Test if this is the zero element of the ring.

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