class JAS::RingElem
Proxy for JAS
ring elements.
Methods to be used as + - * ** / %.
Attributes
the Java element object
the Java factory object
Public Class Methods
Constructor for ring element.
# File examples/jas.rb 547 def initialize(elem) 548 if elem.is_a? RingElem 549 @elem = elem.elem; 550 else 551 @elem = elem; 552 end 553 begin 554 @ring = @elem.factory(); 555 rescue 556 @ring = @elem; 557 end 558 @elem.freeze 559 @ring.freeze 560 self.freeze 561 end
Public Instance Methods
Modular remainder of two ring elements.
# File examples/jas.rb 918 def %(other) 919 s,o = coercePair(self,other); 920 return RingElem.new( s.elem.remainder( o.elem ) ); 921 end
Multiply two ring elements.
# File examples/jas.rb 873 def *(other) 874 #puts "* self type(#{self.elem}) = #{self.elem.class}\n"; 875 #puts "* other type(#{other.elem}) = #{other.elem.class}\n"; 876 s,o = coercePair(self,other); 877 #puts "* s = #{s}, o = #{o}, s*o = #{s.elem.multiply(o.elem)}\n"; 878 if s.elem.is_a? GenMatrix and o.elem.is_a? GenVector 879 return RingElem.new( BasicLinAlg.new().rightProduct(o.elem, s.elem) ); 880 end; 881 if s.elem.is_a? GenVector and o.elem.is_a? GenMatrix 882 return RingElem.new( BasicLinAlg.new().leftProduct(s.elem, o.elem) ); 883 end; 884 return RingElem.new( s.elem.multiply( o.elem ) ); 885 end
Power of this to other.
# File examples/jas.rb 957 def **(other) 958 #puts "pow other type(#{other}) = #{other.class}"; 959 if other.is_a? Integer 960 n = other; 961 else 962 if other.is_a? RingElem 963 n = other.elem; 964 if n.is_a? BigRational 965 #puts "#{n.numerator()} / #{n.denominator()}, other.elem = #{n}" 966 #todo (x**n.n)/(x**(-n.d)) 967 if n.numerator().is_a? BigInteger 968 n = n.numerator().intValue() / n.denominator().intValue(); 969 else 970 n = n.numerator() / n.denominator(); 971 end 972 end 973 if n.is_a? BigInteger 974 n = n.intValue(); 975 end 976 end 977 end 978 if isFactory() 979 p = Power.new(@elem).power( @elem, n ); 980 else 981 p = Power.new(@elem.factory()).power( @elem, n ); 982 #puts "@elem**#{n} = #{p}, @elem = #{@elem}" 983 #puts "@elem.ring = #{@elem.ring.toScript()}"; 984 end 985 return RingElem.new( p ); 986 end
Add two ring elements.
# File examples/jas.rb 890 def +(other) 891 #puts "+ self type(#{self}) = #{self.elem.class}\n"; 892 #puts "+ other type(#{other}) = #{other.elem.class}\n"; 893 s,o = coercePair(self,other); 894 return RingElem.new( s.elem.sum( o.elem ) ); 895 end
Positive value.
# File examples/jas.rb 658 def +@() 659 return self; 660 end
Subtract two ring elements.
# File examples/jas.rb 900 def -(other) 901 #puts "+ self type(#{self}) = #{self.elem.class}\n"; 902 #puts "+ other type(#{other}) = #{other.elem.class}\n"; 903 s,o = coercePair(self,other); 904 return RingElem.new( s.elem.subtract( o.elem ) ); 905 end
Negative value.
# File examples/jas.rb 651 def -@() 652 return RingElem.new( @elem.negate() ); 653 end
Divide two ring elements.
# File examples/jas.rb 910 def /(other) 911 s,o = coercePair(self,other); 912 return RingElem.new( s.elem.divide( o.elem ) ); 913 end
Compare two ring elements.
# File examples/jas.rb 840 def <=>(other) 841 #s,o = coercePair(other); 842 s,o = self, other 843 return s.elem.compareTo( o.elem ); 844 end
Test if two ring elements are equal.
# File examples/jas.rb 849 def ==(other) 850 if not other.is_a? RingElem 851 return false; 852 end 853 return (self <=> other) == 0; 854 end
Matrix entry.
# File examples/jas.rb 926 def [](i,j) 927 return get(i,j); 928 end
Can not be used as power.
# File examples/jas.rb 950 def ^(other) 951 return nil; 952 end
Absolute value.
# File examples/jas.rb 644 def abs() 645 return RingElem.new( @elem.abs() ); 646 end
Compute algebraic roots, i.e. real and complex algebraic roots of univariate polynomial.
# File examples/jas.rb 1307 def algebraicRoots(eps=nil) 1308 a = @elem; 1309 if eps.is_a? RingElem 1310 eps = eps.elem; 1311 end 1312 begin 1313 if eps == nil 1314 ar = RootFactory.algebraicRoots( a ); 1315 else 1316 ar = RootFactory.algebraicRoots( a, eps ); 1317 end 1318 #no: ar = ar.map{ |y| RingElem.new(y) }; 1319 return RingElem.new(ar); #?? 1320 rescue => e 1321 puts "error " + str(e) 1322 return nil 1323 end 1324 end
Coefficient ring of a polynomial.
# File examples/jas.rb 1650 def base_ring() 1651 begin 1652 ev = @elem.ring.coFac; 1653 rescue 1654 return nil; 1655 end 1656 return RingElem.new(ev); 1657 end
Apply this to num.
Call syntax is ringElem.(num). Only for interger num.
# File examples/jas.rb 1593 def call(num) 1594 if num == 0 1595 return zero(); 1596 end 1597 if num == 1 1598 return one(); 1599 end 1600 return RingElem.new( @ring.fromInteger(num) ); 1601 end
Get the coefficients of a polynomial.
# File examples/jas.rb 1536 def coefficients() 1537 a = @elem; 1538 ll = a.coefficientIterator().map { |c| RingElem.new(c) }; 1539 return ll 1540 end
Coerce other to self
# File examples/jas.rb 665 def coerce(other) 666 s,o = coercePair(self,other); 667 return [o,s]; # keep order for non-commutative 668 end
Coerce other to self
# File examples/jas.rb 703 def coerceElem(other) 704 #puts "self type(#{self}) = #{self.class}\n"; 705 #puts "other type(#{other}) = #{other.class}\n"; 706 #not ok: if other.is_a? RingElem other = other.elem; end 707 if @elem.is_a? GenVector 708 if other.is_a? Array 709 o = rbarray2arraylist(other,@elem.factory().coFac,rec=1); 710 o = GenVector.new(@elem.factory(),o); 711 return RingElem.new( o ); 712 end 713 end 714 if @elem.is_a? GenMatrix 715 #puts "other #{@ring} #{other.factory()}\n"; 716 if other.is_a? Array 717 o = rbarray2arraylist(other,@elem.factory().coFac,rec=2); 718 o = GenMatrix.new(@elem.factory(),o); 719 return RingElem.new( o ); 720 end 721 if other.is_a? RingElem and other.elem.is_a? GenVector 722 #puts "other vec #{other.factory()} #{other}\n"; 723 #o = rbarray2arraylist(other,other.factory().coFac,rec=1); 724 #o = GenVector.new(other.factory().coFac, o); 725 o = other; 726 return o; #RingElem.new( o ); 727 end 728 end 729 if other.is_a? RingElem 730 if (isPolynomial() and not other.isPolynomial()) or (isAlgNum() and not other.isAlgNum()) 731 #puts "other pol.parse(#{@ring})\n"; 732 o = @ring.parse( other.elem.toString() ); # not toScript() 733 return RingElem.new( o ); 734 end 735 #puts "other type(#{other}) = #{other.class}\n"; 736 return other; 737 end 738 #puts "--1"; 739 if other.is_a? Array 740 # assume BigRational or BigComplex 741 # assume self will be compatible with them. todo: check this 742 puts "other type(#{other})_3 = #{other.class}\n"; 743 o = makeJasArith(other); 744 puts "other type(#{o})_4 = #{o.class}\n"; 745 ##o = BigRational.new(other[0],other[1]); 746 if isPolynomial() 747 o = @ring.parse( o.toString() ); # not toScript(); 748 #o = o.elem; 749 elsif @elem.is_a? BigComplex 750 o = CC( o ); 751 o = o.elem; 752 elsif @elem.is_a? BigQuaternion 753 o = Quat( o ); 754 o = o.elem; 755 elsif @elem.is_a? BigOctonion 756 o = Oct( Quat(o) ); 757 o = o.elem; 758 elsif @elem.is_a? Product 759 o = RR(@ring, @elem.multiply(o) ); # valueOf 760 #puts "o = #{o}"; 761 o = o.elem; 762 end 763 puts "other type(#{o})_5 = #{o.class}\n"; 764 return RingElem.new(o); 765 end 766 # test if @elem is a factory itself 767 if isFactory() 768 if other.is_a? Integer 769 o = @elem.fromInteger(other); 770 elsif other.is_a? Rational 771 o = @elem.fromInteger( other.numerator ); 772 o = o.divide( @elem.fromInteger( other.denominator ) ); 773 elsif other.is_a? Float # ?? what to do ?? 774 o = @elem.parse( other.to_s ); 775 ##o = @elem.fromInteger( other.to_i ); 776 else 777 puts "unknown other type(#{other})_1 = #{other.class}\n"; 778 o = @elem.parse( other.to_s ); 779 end 780 return RingElem.new(o); 781 end 782 # @elem has a ring factory 783 if other.is_a? Integer 784 o = @elem.factory().fromInteger(other); 785 elsif other.is_a? Rational 786 o = @elem.factory().fromInteger( other.numerator ); 787 o = o.divide( @elem.factory().fromInteger( other.denominator ) ); 788 elsif other.is_a? Float # ?? what to do ?? 789 o = @elem.factory().parse( other.to_s ); 790 if @elem.is_a? Product 791 o = RR(@ring, @elem.idempotent().multiply(o) ); # valueOf 792 o = o.elem; 793 end 794 else 795 puts "unknown other type(#{other})_2 = #{other.class}\n"; 796 o = @elem.factory().parse( other.to_s ); 797 end 798 return RingElem.new(o); 799 end
Coerce type a to type b or type b to type a.
# File examples/jas.rb 673 def coercePair(a,b) 674 #puts "a type(#{a}) = #{a.class}\n"; 675 #puts "b type(#{b}) = #{b.class}\n"; 676 begin 677 if not a.isPolynomial() and b.isPolynomial() 678 #puts "b = " + str(b.isPolynomial()); 679 s = b.coerceElem(a); 680 o = b; 681 else if not a.isAlgNum() and b.isAlgNum() 682 #puts "b = " + str(b.isAlgNum()); 683 s = b.coerceElem(a); 684 o = b; 685 else 686 s = a; 687 o = a.coerceElem(b); 688 end 689 end 690 rescue => e 691 #puts "e #{e.message}, a = #{a}"; 692 s = a; 693 o = a.coerceElem(b); 694 end 695 #puts "s type(#{s}) = #{s.class}\n"; 696 #puts "o type(#{o}) = #{o.class}\n"; 697 return [s,o]; 698 end
Compute complex roots of univariate polynomial.
# File examples/jas.rb 1265 def complexRoots(eps=nil) 1266 a = @elem; 1267 if eps.is_a? RingElem 1268 eps = eps.elem; 1269 end 1270 cmplx = false; 1271 begin 1272 x = a.ring.coFac.getONE().getRe(); 1273 cmplx = true; 1274 rescue => e 1275 #pass; 1276 end 1277 begin 1278 if eps == nil 1279 #rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a ); 1280 if cmplx 1281 rr = RootFactory.complexAlgebraicNumbersComplex( a ); 1282 else 1283 rr = RootFactory.complexAlgebraicNumbers( a ); 1284 end 1285 #R = [ r.centerApprox() for r in R ]; 1286 else 1287 ## rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a, eps ); 1288 ## rr = [ r.centerApprox() for r in rr ]; 1289 ##rr = ComplexRootsSturm.new(a.ring.coFac).approximateRoots( a, eps ); 1290 if cmplx 1291 rr = RootFactory.complexAlgebraicNumbersComplex( a, eps ); 1292 else 1293 rr = RootFactory.complexAlgebraicNumbers( a, eps ); 1294 end 1295 end 1296 rr = rr.map{ |y| RingElem.new(y) }; 1297 return rr; 1298 rescue => e 1299 puts "error " + str(e) 1300 return nil 1301 end 1302 end
Continued fraction computation of rational and real algebraic numbers.
# File examples/jas.rb 1405 def contFrac(prec) 1406 a = @elem; 1407 if a.is_a? RealAlgebraicNumber 1408 b = prec; 1409 if b.is_a? RingElem 1410 b = b.elem; 1411 end 1412 if b < 1 1413 b = 1; 1414 end 1415 d = RealArithUtil.continuedFraction(a, b); 1416 return d; 1417 end 1418 if a.is_a? BigRational 1419 d = ArithUtil.continuedFraction(a); 1420 return d; 1421 end 1422 raise ArgumentError, "type " + str(a.class) + " not supported" 1423 end
Continued fraction expansion to approximate fraction.
# File examples/jas.rb 1429 def contFracApprox(lst) 1430 if lst == nil 1431 d = BigRational::ZERO; 1432 return RingElem.new( d ); 1433 end 1434 nb = ArithUtil.continuedFractionApprox(lst); 1435 return RingElem.new( nb ); 1436 end
(exterior) polynomial coefficient primitive part.
# File examples/jas.rb 1545 def cpp() 1546 a = @elem; 1547 r = a.coeffPrimitivePart(); 1548 return RingElem.new(r); 1549 end
Compute decimal approximation of real and complex roots of univariate polynomial.
# File examples/jas.rb 1347 def decimalRoots(eps=nil) 1348 a = @elem; 1349 if eps.is_a? RingElem 1350 eps = eps.elem; 1351 end 1352 if a.is_a? Java::EduJasRoot::AlgebraicRoots 1353 a = a.p; 1354 end 1355 begin 1356 d = RootFactory.decimalRoots( a, eps ); 1357 return RingElem.new(d); # ?? 1358 rescue => e 1359 puts "error " + str(e) 1360 return nil 1361 end 1362 end
Decompose to LU matrix. this is modified.
# File examples/jas.rb 1455 def decompLU() 1456 a = @elem; 1457 p = LinAlg.new().decompositionLU(a); 1458 uu = a.getUpper(); 1459 ll = a.getLower(); 1460 return [ RingElem.new(ll), RingElem.new(uu), RingElem.new(p) ]; 1461 end
Degree of a polynomial.
# File examples/jas.rb 1638 def degree() 1639 begin 1640 ev = @elem.degree(); 1641 rescue 1642 return nil; 1643 end 1644 return ev; 1645 end
Determinant from LU matrix.
# File examples/jas.rb 1483 def determinant(p=nil) 1484 a = @elem; 1485 la = LinAlg.new(); 1486 if p == nil 1487 p = la.decompositionLU(a); 1488 end; 1489 if p.is_a? RingElem 1490 p = p.elem; 1491 end 1492 if p.isEmpty() 1493 d = @ring.coFac.getZERO(); 1494 else 1495 d = la.determinantLU(a,p); 1496 end; 1497 return RingElem.new(d); 1498 end
Differentiate a power series.
r is for partial differentiation in variable r.
# File examples/jas.rb 1111 def differentiate(r=nil) 1112 begin 1113 if r != nil 1114 e = @elem.differentiate(r); 1115 else 1116 e = @elem.differentiate(); 1117 end 1118 rescue 1119 e = @elem.factory().getZERO(); 1120 end 1121 return RingElem.new( e ); 1122 end
Test if self divides other.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1681 def divides(other) 1682 s,o = coercePair(self,other); 1683 return o.elem.remainder( s.elem ).isZERO(); 1684 end
Test if two ring elements are equal.
# File examples/jas.rb 991 def equal?(other) 992 o = other; 993 if other.is_a? RingElem 994 o = other.elem; 995 end 996 return @elem.equals(o) 997 end
Evaluate at a for power series or polynomial.
# File examples/jas.rb 1033 def evaluate(a) 1034 #puts "self type(#{@elem}) = #{@elen.class}"; 1035 #puts "a type(#{a}) = #{a.class}"; 1036 x = nil; 1037 if a.is_a? RingElem 1038 x = a.elem; 1039 end 1040 if a.is_a? Array 1041 # assume BigRational or BigComplex 1042 # assume self will be compatible with them. todo: check this 1043 #x = makeJasArith(a); 1044 x = rbarray2arraylist(a); 1045 else 1046 x = rbarray2arraylist([a]); 1047 end 1048 begin 1049 if @elem.is_a? UnivPowerSeries 1050 e = @elem.evaluate(x[0]); 1051 else if @elem.is_a? MultiVarPowerSeries 1052 e = @elem.evaluate(x); 1053 else 1054 #puts "x = " + x[0].getClass().getSimpleName().to_s; 1055 x = x.map{ |p| p.leadingBaseCoefficient() }; 1056 e = PolyUtil.evaluateAll(@ring.coFac, @elem, x); 1057 end 1058 end 1059 rescue => e 1060 raise RuntimeError, e.to_s; 1061 e = 0; 1062 end 1063 return RingElem.new( e ); 1064 end
Compute irreducible factorization for modular, integer, rational number and algebriac number coefficients.
# File examples/jas.rb 1186 def factors() 1187 a = @elem; 1188 if isPolynomial() 1189 factor = Ring.getEngineFactor(@ring); 1190 if factor == nil 1191 raise NotImplementedError, "factors not implemented for " + @ring.to_s; 1192 end 1193 cf = @ring.coFac; 1194 if cf.is_a? GenPolynomialRing 1195 e = factor.recursiveFactors( a ); 1196 else 1197 e = factor.factors( a ); 1198 end 1199 ll = {}; 1200 for k in e.keySet() 1201 i = e.get(k); 1202 ll[ RingElem.new( k ) ] = i; 1203 end 1204 return ll; 1205 else 1206 raise NotImplementedError, "factors not implemented for " + a.to_s; 1207 end 1208 end
Compute absolute irreducible factorization for (modular,) rational number coefficients.
# File examples/jas.rb 1214 def factorsAbsolute() 1215 a = @elem; 1216 if isPolynomial() 1217 factor = Ring.getEngineFactor(@ring); 1218 if factor == nil 1219 raise NotImplementedError, "factors not implemented for " + @ring.to_s; 1220 end 1221 begin 1222 ll = factor.factorsAbsolute( a ); 1223 ## ll = {}; 1224 ## for a in e.keySet() 1225 ## i = e.get(a); 1226 ## ll[ RingElem.new( a ) ] = i; 1227 return ll; 1228 rescue => e 1229 raise RuntimeError, "error factorsAbsolute " + @ring.to_s; 1230 end 1231 else 1232 raise NotImplementedError, "factors not implemented for " + a.to_s; 1233 end 1234 end
Get the factory of this element.
# File examples/jas.rb 1002 def factory() 1003 fac = @elem.factory(); 1004 begin 1005 nv = fac.nvar; 1006 rescue 1007 return RingElem.new(fac); 1008 end 1009 #return PolyRing(fac.coFac,fac.getVars(),fac.tord); 1010 return RingElem.new(fac); 1011 end
Compute the greatest common divisor of this/self and b.
# File examples/jas.rb 1139 def gcd(b) 1140 a = @elem; 1141 if b.is_a? RingElem 1142 b = b.elem; 1143 else 1144 b = element( b ); 1145 b = b.elem; 1146 end 1147 if isPolynomial() 1148 engine = Ring.getEngineGcd(@ring); 1149 return RingElem.new( engine.gcd(a,b) ); 1150 else 1151 return RingElem.new( a.gcd(b) ); 1152 end 1153 end
Get the generators for the factory of this element.
# File examples/jas.rb 1016 def gens() 1017 ll = @elem.factory().generators(); 1018 #puts "L = #{ll}"; 1019 nn = ll.map {|e| RingElem.new(e) }; 1020 return nn; 1021 end
Matrix entry.
# File examples/jas.rb 933 def get(i,j) 934 if not elem.is_a? GenMatrix 935 raise "no matrix " + ring.to_s 936 end 937 if i.is_a? RingElem 938 i = i.elem; 939 end 940 if j.is_a? RingElem 941 j = j.elem; 942 end 943 e = elem.get(i,j); 944 return RingElem.new( e ); 945 end
Create an ideal.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1691 def ideal(list) 1692 r = Ring.new("",ring=self.ring); #,fast=true 1693 return r.ideal("",list=list); 1694 end
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 1071 def integrate(a=0,r=nil) 1072 #puts "self type(#{@elem}) = #{@elem.class}"; 1073 #puts "a type(#{a}) = #{a.class}"; 1074 x = nil; 1075 if a.is_a? RingElem 1076 x = a.elem; 1077 end 1078 if a.is_a? Array 1079 # assume BigRational or BigComplex 1080 # assume self will be compatible with them. todo: check this 1081 x = makeJasArith(a); 1082 end 1083 # power series 1084 begin 1085 if r != nil 1086 e = @elem.integrate(x,r); 1087 else 1088 e = @elem.integrate(x); 1089 end 1090 return RingElem.new( e ); 1091 rescue 1092 #pass; 1093 end 1094 cf = @elem.ring; 1095 begin 1096 cf = cf.ring; 1097 rescue 1098 #pass; 1099 end 1100 # rational function 1101 integrator = ElementaryIntegration.new(cf.coFac); 1102 ei = integrator.integrate(@elem); 1103 return ei; 1104 end
Inner left product of two exterior vectors / polynomials.
# File examples/jas.rb 1554 def interiorLeftProduct(other) 1555 #puts "* self type(#{self.elem}) = #{self.elem.class}\n"; 1556 #puts "* other type(#{other.elem}) = #{other.elem.class}\n"; 1557 s,o = coercePair(self,other); 1558 #puts "* s = #{s}, o = #{o}, s*o = #{s.elem.multiply(o.elem)}\n"; 1559 return RingElem.new( s.elem.interiorLeftProduct( o.elem ) ); 1560 end
Inner right product of two exterior vectors / polynomials.
# File examples/jas.rb 1565 def interiorRightProduct(other) 1566 #puts "* self type(#{self.elem}) = #{self.elem.class}\n"; 1567 #puts "* other type(#{other.elem}) = #{other.elem.class}\n"; 1568 s,o = coercePair(self,other); 1569 #puts "* s = #{s}, o = #{o}, s*o = #{s.elem.multiply(o.elem)}\n"; 1570 return RingElem.new( s.elem.interiorRightProduct( o.elem ) ); 1571 end
Test if this is an algebraic number.
# File examples/jas.rb 828 def isAlgNum() 829 begin 830 nv = @elem.ring.ring.nvar; #coFac 831 rescue 832 return false; 833 end 834 return true; 835 end
Test if this is itself a ring factory.
# File examples/jas.rb 804 def isFactory() 805 f = @elem.factory(); 806 if @elem == f 807 return true; 808 else 809 return false; 810 end 811 end
Test if this is the one element of the ring.
# File examples/jas.rb 623 def isONE() 624 return @elem.isONE(); 625 end
Test if this is a polynomial.
# File examples/jas.rb 816 def isPolynomial() 817 begin 818 nv = @elem.ring.coFac; #nvar; 819 rescue 820 return false; 821 end 822 return true; 823 end
Test if this is the zero element of the ring.
# File examples/jas.rb 602 def isZERO() 603 return @elem.isZERO(); 604 end
Test if this RingElem
is field.
# File examples/jas.rb 1662 def is_field() 1663 return @ring.isField(); 1664 end
Leading coefficient of a polynomial.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1619 def lc() 1620 c = @elem.leadingBaseCoefficient(); 1621 return RingElem.new(c); 1622 end
Length of an element.
# File examples/jas.rb 859 def len() 860 return self.elem.length(); 861 end
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 1609 def lm() 1610 ev = @elem.leadingExpVector(); 1611 return ev; 1612 end
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 1630 def lt() 1631 ev = @elem.leadingMonomial(); 1632 return Monomial.new(ev); 1633 end
Monic polynomial.
# File examples/jas.rb 1026 def monic() 1027 return RingElem.new( @elem.monic() ); 1028 end
Test divide of ExpVectors.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1727 def monomial_divides(a,b) 1728 #print "JAS a = " + str(a) + ", b = " + str(b); 1729 if a.is_a? RingElem 1730 a = a.elem; 1731 end 1732 if a.is_a? GenPolynomial 1733 a = a.leadingExpVector(); 1734 end 1735 if not a.is_a? ExpVector 1736 raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b) 1737 end 1738 if b == nil 1739 return False; 1740 end 1741 if b.is_a? RingElem 1742 b = b.elem; 1743 end 1744 if b.is_a? GenPolynomial 1745 b = b.leadingExpVector(); 1746 end 1747 if not b.is_a? ExpVector 1748 raise ArgumentError, "No ExpVector given " + str(a) + ", " + str(b) 1749 end 1750 return a.divides(b); 1751 end
Lcm of ExpVectors.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1775 def monomial_lcm(e,f) 1776 if e.is_a? RingElem 1777 e = e.elem; 1778 end 1779 if f.is_a? RingElem 1780 f = f.elem; 1781 end 1782 # assume JAS ExpVector 1783 c = e.lcm(f); 1784 return c; 1785 end
Test if ExpVectors are pairwise prime.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1758 def monomial_pairwise_prime(e,f) 1759 if e.is_a? RingElem 1760 e = e.elem; 1761 end 1762 if f.is_a? RingElem 1763 f = f.elem; 1764 end 1765 # assume JAS ExpVector 1766 c = e.gcd(f); 1767 return c.isZERO(); 1768 end
Quotient of ExpVectors.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1701 def monomial_quotient(a,b,coeff=false) 1702 if a.is_a? RingElem 1703 a = a.elem; 1704 end 1705 if b.is_a? RingElem 1706 b = b.elem; 1707 end 1708 if coeff == false 1709 if a.is_a? GenPolynomial 1710 return RingElem.new( a.divide(b) ); 1711 else 1712 return RingElem.new( GenPolynomial.new(@ring, a.subtract(b)) ); 1713 end 1714 else 1715 # assume JAS Monomial 1716 c = a.coefficient().divide(b.coefficient()); 1717 e = a.exponent().subtract(b.exponent()) 1718 return RingElem.new( GenPolynomial.new(@ring, c, e) ); 1719 end 1720 end
All monomials of a polynomial.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1671 def monomials() 1672 ev = @elem.getMap().keySet(); 1673 return ev; 1674 end
Null space basis. {v_i} with v_i * self = 0.
# File examples/jas.rb 1526 def nullSpace() 1527 a = @elem; 1528 r = LinAlg.new().nullSpaceBasis(a); 1529 return r; 1530 end
Hash value.
# File examples/jas.rb 866 def object_id() 867 return @elem.hashCode(); 868 end
One element of this ring.
# File examples/jas.rb 616 def one() 617 return RingElem.new( @elem.factory().getONE() ); 618 end
Test if this is the one element of the ring.
# File examples/jas.rb 630 def one?() 631 return @elem.isONE(); 632 end
Parent in Sage is factory in JAS
.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1584 def parent() 1585 return factory(); 1586 end
Random element.
n size for random element will be less than 2**n.
# File examples/jas.rb 1129 def random(n=3) 1130 if n.is_a? RingElem 1131 n = n.elem 1132 end 1133 return RingElem.new( @elem.factory().random(n) ); 1134 end
rank from row echelon form matrix.
# File examples/jas.rb 1516 def rank() 1517 a = @elem; 1518 r = LinAlg.new().rankRE(a); 1519 return r; 1520 end
Compute real roots of univariate polynomial.
# File examples/jas.rb 1239 def realRoots(eps=nil) 1240 a = @elem; 1241 if eps.is_a? RingElem 1242 eps = eps.elem; 1243 end 1244 begin 1245 if eps == nil 1246 #rr = RealRootsSturm.new().realRoots( a ); 1247 rr = RootFactory.realAlgebraicNumbers( a ) 1248 else 1249 rr = RootFactory.realAlgebraicNumbers( a, eps ); 1250 ## rr = RealRootsSturm.new().realRoots( a, eps ); 1251 ## rr = [ r.toDecimal() for r in rr ]; 1252 #rr = RealRootsSturm.new().approximateRoots(a,eps); 1253 end 1254 rr = rr.map{ |e| RingElem.new(e) }; 1255 return rr; 1256 rescue => e 1257 puts "error " + str(e) 1258 return nil 1259 end 1260 end
Compute a normal form of self with respect to ff.
Compatibility method for Sage/Singular.
# File examples/jas.rb 1792 def reduce(ff) 1793 s = @elem; 1794 fe = ff.map {|e| e.elem }; 1795 n = ReductionSeq.new().normalform(fe,s); 1796 return RingElem.new(n); 1797 end
Root reduce of real and complex algebraic numbers. Compute an extension field with a primitive element.
# File examples/jas.rb 1386 def rootReduce(other) 1387 a = @elem; 1388 b = other; 1389 if b.is_a? RingElem 1390 b = b.elem; 1391 end 1392 begin #Java::EduJasApplication:: 1393 d = RootFactoryApp.rootReduce( a, b ); 1394 return RingElem.new(d); # ?? 1395 rescue => e 1396 puts "error " + str(e) 1397 return nil 1398 end 1399 end
Compute algebraic roots refinement.
# File examples/jas.rb 1329 def rootRefine(eps=nil) 1330 r = @elem; 1331 if eps.is_a? RingElem 1332 eps = eps.elem; 1333 end 1334 begin 1335 RootFactory.rootRefine( r, eps ); 1336 #no: ar = ar.map{ |y| RingElem.new(y) }; 1337 return RingElem.new(r); # ?? 1338 rescue => e 1339 puts "error " + str(e) 1340 return nil 1341 end 1342 end
Roots of unity of real and complex algebraic numbers.
# File examples/jas.rb 1367 def rootsOfUnity() 1368 a = @elem; 1369 begin #Java::EduJasApplication:: 1370 if a.is_a? AlgebraicRootsPrimElem 1371 d = RootFactoryApp.rootsOfUnity( a ); 1372 else 1373 d = RootFactory.rootsOfUnity( a ); 1374 end 1375 return RingElem.new(d); # ?? 1376 rescue => e 1377 puts "error " + str(e) 1378 return nil 1379 end 1380 end
Row echelon form matrix.
# File examples/jas.rb 1504 def rowEchelon() 1505 a = @elem; 1506 la = LinAlg.new(); 1507 re = la.rowEchelonForm(a); 1508 res = la.rowEchelonFormSparse(re); 1509 return RingElem.new(res); 1510 end
Get the sign of this element.
# File examples/jas.rb 637 def signum() 638 return @elem.signum(); 639 end
Solve system of linear equations.
# File examples/jas.rb 1442 def solve(b) 1443 a = @elem; 1444 if b.is_a? RingElem 1445 b = b.elem; 1446 end 1447 x = LinAlg.new().solve(a,b); 1448 return RingElem.new(x); 1449 end
Solve with LU matrix.
# File examples/jas.rb 1467 def solveLU(p, b) 1468 a = @elem; 1469 if b.is_a? RingElem 1470 b = b.elem; 1471 end 1472 if p.is_a? RingElem 1473 p = p.elem; 1474 end 1475 x = LinAlg.new().solveLU(a,p,b); 1476 return RingElem.new(x); 1477 end
Compute squarefree factors of polynomial.
# File examples/jas.rb 1158 def squarefreeFactors() 1159 a = @elem; 1160 if isPolynomial() 1161 sqf = Ring.getEngineSqf(@ring); 1162 if sqf == nil 1163 raise NotImplementedError, "squarefreeFactors not implemented for " + @ring.to_s; 1164 end 1165 cf = @ring.coFac; 1166 if cf.is_a? GenPolynomialRing 1167 e = sqf.recursiveSquarefreeFactors( a ); 1168 else 1169 e = sqf.squarefreeFactors( a ); 1170 end 1171 ll = {}; 1172 for k in e.keySet() 1173 i = e.get(k); 1174 ll[ RingElem.new( k ) ] = i; 1175 end 1176 return ll; 1177 else 1178 raise NotImplementedError, "squarefreeFactors not implemented for " + a.to_s; 1179 end 1180 end
Convert to float.
# File examples/jas.rb 577 def to_f() 578 e = @elem; 579 if e.is_a? BigInteger 580 e = BigRational(e); 581 end 582 if e.is_a? BigRational 583 e = BigDecimal(e); 584 end 585 if e.is_a? BigDecimal 586 e = e.toString(); 587 end 588 e = e.to_f(); 589 return e; 590 end
Create a string representation.
# File examples/jas.rb 566 def to_s() 567 begin 568 return @elem.toScript(); 569 rescue 570 return @elem.to_s(); 571 end 572 end
Zero element of this ring.
# File examples/jas.rb 595 def zero() 596 return RingElem.new( @elem.factory().getZERO() ); 597 end
Test if this is the zero element of the ring.
# File examples/jas.rb 609 def zero?() 610 return @elem.isZERO(); 611 end