Class JAS::Ring
In: examples/jas.rb
Parent: Object

Represents a JAS polynomial ring: GenPolynomialRing.

Methods to create ideals and ideals with parametric coefficients.

Methods

Attributes

engine  [R] 
factor  [R] 
pset  [R] 
ring  [R] 
sqf  [R] 

Public Class methods

[Source]

     # File examples/jas.rb, line 896
896:     def initialize(ringstr="",ring=nil)
897: Ring constructor.
898: 
899:         if ring == nil
900:            sr = StringReader.new( ringstr );
901:            tok = GenPolynomialTokenizer.new(sr);
902:            @pset = tok.nextPolynomialSet();
903:            @ring = @pset.ring;
904:         else
905:            @ring = ring;
906:         end
907:         @engine = GCDFactory.getProxy(@ring.coFac);
908:         @sqf = nil;
909:         @factor = nil;
910:         begin
911:             @sqf = SquarefreeFactory.getImplementation(@ring.coFac);
912:             #puts "sqf: ", @sqf;
913:         #rescue Rescueion => e
914:             #puts "error " + str(e)
915:         rescue
916:             #pass
917:         end
918:         begin
919:             @factor = FactorFactory.getImplementation(@ring.coFac);
920:             #puts "factor: ", @factor;
921:         #rescue Rescueion => e
922:             #puts "error " + str(e)
923:         rescue
924:             #pass
925:         end
926:     end

Public Instance methods

Compute complex roots of univariate polynomial.

[Source]

      # File examples/jas.rb, line 1136
1136:     def complexRoots(a,eps=nil)
1137:         if a.is_a? RingElem
1138:             a = a.elem;
1139:         else
1140:             a = element( a );
1141:             a = a.elem;
1142:         end
1143:         if eps.is_a? RingElem
1144:             eps = eps.elem;
1145:         end
1146:         cmplx = false;
1147:         begin
1148:             x = a.ring.coFac.getONE().getRe();
1149:             cmplx = true;
1150:         rescue Exception => e
1151:             #pass;
1152:         end
1153:         begin
1154:             if eps == nil
1155:                 #rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a );
1156:                 if cmplx
1157:                    rr = RootFactory.complexAlgebraicNumbersComplex( a );
1158:                 else 
1159:                    rr = RootFactory.complexAlgebraicNumbers( a );
1160:                 end
1161:                 #R = [ r.centerApprox() for r in R ];
1162:             else
1163:                 ## rr = ComplexRootsSturm.new(a.ring.coFac).complexRoots( a, eps );
1164:                 ## rr = [ r.centerApprox() for r in rr ];
1165:                 ##rr = ComplexRootsSturm.new(a.ring.coFac).approximateRoots( a, eps );
1166:                 if cmplx
1167:                    rr = RootFactory.complexAlgebraicNumbersComplex( a, eps );
1168:                 else
1169:                    rr = RootFactory.complexAlgebraicNumbers( a, eps );
1170:                 end
1171:             end
1172:             rr = rr.map{ |e| RingElem.new(e) };
1173:             return rr;
1174:         rescue Exception => e
1175:             puts "error " + str(e)
1176:             return nil
1177:         end
1178:     end

Create an element from a string or an object.

[Source]

      # File examples/jas.rb, line 987
 987:     def element(poly)
 988:         if not poly.is_a? String 
 989:            begin
 990:               if @ring == poly.ring 
 991:                  return RingElem.new(poly);
 992:               end
 993:            rescue Exception => e
 994:               # pass
 995:            end
 996:            poly = str(poly);
 997:         end
 998:         i = SimIdeal.new( self, "( " + poly + " )" );
 999:         list = i.pset.list;
1000:         if list.size > 0
1001:            return RingElem.new( list[0] );
1002:         end
1003:     end

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

[Source]

      # File examples/jas.rb, line 1052
1052:     def factors(a)
1053:         if a.is_a? RingElem
1054:             a = a.elem;
1055:         else
1056:             a = element( a );
1057:             a = a.elem;
1058:         end
1059:         begin
1060:             cf = @ring.coFac;
1061:             if cf.getClass().getSimpleName() == "GenPolynomialRing"
1062:                 e = @factor.recursiveFactors( a );
1063:             else
1064:                 e = @factor.factors( a );
1065:             end
1066:             ll = {};
1067:             for a in e.keySet()
1068:                 i = e.get(a);
1069:                 ll[ RingElem.new( a ) ] = i;
1070:             end
1071:             return ll;
1072:         rescue Exception => e
1073:             puts "error " + str(e)
1074:             return nil
1075:         end
1076:     end

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

[Source]

      # File examples/jas.rb, line 1082
1082:     def factorsAbsolute(a)
1083:         if a.is_a? RingElem
1084:             a = a.elem;
1085:         else
1086:             a = element( a );
1087:             a = a.elem;
1088:         end
1089:         begin
1090:             ll = @factor.factorsAbsolute( a );
1091: ##             ll = {};
1092: ##             for a in e.keySet()
1093: ##                 i = e.get(a);
1094: ##                 ll[ RingElem.new( a ) ] = i;
1095:             return ll;
1096:         rescue Exception => e
1097:             puts "error in factorsAbsolute " + str(e)
1098:             return nil
1099:         end
1100:     end

Compute the greatest common divisor of a and b.

[Source]

      # File examples/jas.rb, line 1008
1008:     def gcd(a,b)
1009:         if a.is_a? RingElem
1010:             a = a.elem;
1011:         else
1012:             a = element( a );
1013:             a = a.elem;
1014:         end
1015:         if b.is_a? RingElem
1016:             b = b.elem;
1017:         else
1018:             b = element( b );
1019:             b = b.elem;
1020:         end
1021:         return RingElem.new( @engine.gcd(a,b) );
1022:     end

Get list of generators of the polynomial ring.

[Source]

     # File examples/jas.rb, line 953
953:     def gens()
954:         ll = @ring.generators();
955:         n = ll.map{ |e| RingElem.new(e) };
956:         return n;
957:     end

Create an ideal.

[Source]

     # File examples/jas.rb, line 939
939:     def ideal(ringstr="",list=nil)
940:         return JAS::SimIdeal.new(self,ringstr,list);
941:     end

Integrate (univariate) rational function.

[Source]

      # File examples/jas.rb, line 1183
1183:     def integrate(a)
1184:         if a.is_a? RingElem
1185:             a = a.elem;
1186:         else
1187:             a = element( a );
1188:             a = a.elem;
1189:         end
1190:         cf = @ring;
1191:         begin
1192:             cf = cf.ring;
1193:         rescue
1194:             #pass;
1195:         end
1196:         integrator = ElementaryIntegration.new(cf.coFac);
1197:         ei = integrator.integrate(a); 
1198:         return ei;
1199:     end

Get the one of the polynomial ring.

[Source]

     # File examples/jas.rb, line 962
962:     def one()
963:         return RingElem.new( @ring.getONE() );
964:     end

Create an ideal in a polynomial ring with parameter coefficients.

[Source]

     # File examples/jas.rb, line 946
946:     def paramideal(ringstr="",list=nil,gbsys=nil)
947:         return ParamIdeal.new(self,ringstr,list,gbsys);
948:     end

Get a power series ring from this ring.

[Source]

      # File examples/jas.rb, line 1204
1204:     def powerseriesRing()
1205:         pr = MultiVarPowerSeriesRing.new(@ring);
1206:         return MultiSeriesRing.new("",nil,pr);
1207:     end

Get a random polynomial.

[Source]

     # File examples/jas.rb, line 976
976:     def random(k=5,l=7,d=3,q=0.3)
977:         r = @ring.random(k,l,d,q);
978:         if @ring.coFac.isField()
979:             r = r.monic();
980:         end
981:         return RingElem.new( r );
982:     end

Compute real roots of univariate polynomial.

[Source]

      # File examples/jas.rb, line 1105
1105:     def realRoots(a,eps=nil)
1106:         if a.is_a? RingElem
1107:             a = a.elem;
1108:         else
1109:             a = element( a );
1110:             a = a.elem;
1111:         end
1112:         if eps.is_a? RingElem
1113:             eps = eps.elem;
1114:         end
1115:         begin
1116:             if eps == nil
1117:                 #rr = RealRootsSturm.new().realRoots( a );
1118:                 rr = RootFactory.realAlgebraicNumbers( a )
1119:             else
1120:                 rr = RootFactory.realAlgebraicNumbers( a, eps );
1121:                 ## rr = RealRootsSturm.new().realRoots( a, eps );
1122:                 ## rr = [ r.toDecimal() for r in rr ];
1123:                 #rr = RealRootsSturm.new().approximateRoots(a,eps);
1124:             end
1125:             rr = rr.map{ |e| RingElem.new(e) };
1126:             return rr;
1127:         rescue Exception => e
1128:             puts "error " + str(e)
1129:             return nil
1130:         end
1131:     end

Compute squarefree factors of polynomial.

[Source]

      # File examples/jas.rb, line 1027
1027:     def squarefreeFactors(a)
1028:         if a.is_a? RingElem
1029:             a = a.elem;
1030:         else
1031:             a = element( a );
1032:             a = a.elem;
1033:         end
1034:         cf = @ring.coFac;
1035:         if cf.getClass().getSimpleName() == "GenPolynomialRing"
1036:             e = @sqf.recursiveSquarefreeFactors( a );
1037:         else
1038:             e = @sqf.squarefreeFactors( a );
1039:         end
1040:         ll = {};
1041:         for a in e.keySet()
1042:             i = e.get(a);
1043:             ll[ RingElem.new( a ) ] = i;
1044:         end
1045:         return ll;
1046:     end

Create a string representation.

[Source]

     # File examples/jas.rb, line 932
932:     def to_s()
933:         return @ring.toScript();
934:     end

Get the zero of the polynomial ring.

[Source]

     # File examples/jas.rb, line 969
969:     def zero()
970:         return RingElem.new( @ring.getZERO() );
971:     end

[Validate]