Ticket #9054: trac_9054part5.patch
File trac_9054part5.patch, 30.3 KB (added by , 7 years ago) 


module_list.py
# HG changeset patch # User Robert Bradshaw <robertwb@math.washington.edu> # Date 1274955005 25200 # Node ID e7e85a36d207c968c39ff85ded544cf89fabab6f # Parent c14677eee8541b3ef24eb03caea4293748ba41a3 Cythonize function field elements. diff r c14677eee854 r e7e85a36d207 module_list.py
a b 1122 1122 1123 1123 ################################ 1124 1124 ## 1125 ## sage.rings.function_field 1126 ## 1127 ################################ 1128 1129 Extension('sage.rings.function_field.function_field_element', 1130 sources = ['sage/rings/function_field/function_field_element.pyx']), 1131 1132 ################################ 1133 ## 1125 1134 ## sage.rings.number_field 1126 1135 ## 1127 1136 ################################ 
deleted file sage/rings/function_field/function_field_element.py
diff r c14677eee854 r e7e85a36d207 sage/rings/function_field/function_field_element.py
+  1 from sage.structure.element import FieldElement2 3 def is_FunctionFieldElement(x):4 """5 Return True if x is any type of function field element.6 7 EXAMPLES::8 9 sage: t = FunctionField(QQ,'t').gen()10 sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(t)11 True12 sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(0)13 False14 """15 return isinstance(x, FunctionFieldElement)16 17 class FunctionFieldElement(FieldElement):18 """19 The abstract base class for function field elements.20 21 EXAMPLES::22 23 sage: t = FunctionField(QQ,'t').gen()24 sage: isinstance(t, sage.rings.function_field.function_field_element.FunctionFieldElement)25 True26 """27 def matrix(self):28 r"""29 Return the matrix of multiplication by self.30 31 EXAMPLES::32 33 A rational function field:34 35 sage: K.<t> = FunctionField(QQ)36 sage: t.matrix()37 [t]38 sage: (1/(t+1)).matrix()39 [1/(t + 1)]40 41 Now an example in a nontrivial extension of a rational function field::42 43 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)44 sage: Y.matrix()45 [ 0 1]46 [4*x^3 x]47 sage: Y.matrix().charpoly('Z')48 Z^2  x*Z + 4*x^349 50 An example in a relative extension, where neither function51 field is rational::52 53 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)54 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x)55 sage: alpha.matrix()56 [ 0 1 0]57 [ 0 0 1]58 [ x x*Y  4*x^3 0]59 """60 try: return self._matrix61 except AttributeError:62 # Multiply each power of field generator on the left by this63 # element; make matrix whose rows are the coefficients of the64 # result, and transpose.65 K = self.parent()66 v = []67 x = K.gen()68 a = K(1)69 d = K.degree()70 for n in range(d):71 v += (a*self).list()72 a *= x73 k = K.base_ring()74 import sage.matrix.matrix_space75 M = sage.matrix.matrix_space.MatrixSpace(k, d)76 self._matrix = M(v)77 return self._matrix78 79 def trace(self):80 """81 Return the trace of this function field element.82 83 EXAMPLES::84 85 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)86 sage: Y.trace()87 x88 """89 return self.matrix().trace()90 91 def norm(self):92 """93 Return the norm of this function field element.94 95 EXAMPLES::96 97 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)98 sage: Y.norm()99 4*x^3100 101 102 The norm is relative::103 104 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)105 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x)106 sage: alpha.norm()107 x108 sage: alpha.norm().parent()109 Function field in Y defined by y^2  x*y + 4*x^3110 """111 return self.matrix().determinant()112 113 def characteristic_polynomial(self, *args, **kwds):114 """115 Return the characteristic polynomial of this function field116 element. Give an optional input string to name the variable117 in the characteristic polynomial.118 119 EXAMPLES::120 121 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)122 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x)123 sage: x.characteristic_polynomial('W')124 W  x125 sage: Y.characteristic_polynomial('W')126 W^2  x*W + 4*x^3127 sage: alpha.characteristic_polynomial('W')128 W^3 + (x*Y + 4*x^3)*W + x129 """130 return self.matrix().characteristic_polynomial(*args, **kwds)131 132 charpoly = characteristic_polynomial133 134 def minimal_polynomial(self, *args, **kwds):135 """136 Return the minimal polynomial of this function field element.137 Give an optional input string to name the variable in the138 characteristic polynomial.139 140 EXAMPLES::141 142 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)143 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x)144 sage: x.minimal_polynomial('W')145 W  x146 sage: Y.minimal_polynomial('W')147 W^2  x*W + 4*x^3148 sage: alpha.minimal_polynomial('W')149 W^3 + (x*Y + 4*x^3)*W + x150 """151 return self.matrix().minimal_polynomial(*args, **kwds)152 153 minpoly = minimal_polynomial154 155 def is_integral(self):156 r"""157 Determine if self is integral over the maximal order of the base field.158 159 EXAMPLES::160 161 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)162 sage: Y.is_integral()163 True164 sage: (Y/x).is_integral()165 True166 sage: (Y/x)^2  (Y/x) + 4*x167 0168 sage: (Y/x^2).is_integral()169 False170 sage: f = (Y/x).minimal_polynomial('W'); f171 W^2  W + 4*x172 """173 R = self.parent().base_field().maximal_order()174 return all([a in R for a in self.minimal_polynomial()])175 176 class FunctionFieldElement_polymod(FunctionFieldElement):177 """178 EXAMPLES::179 180 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)181 sage: x*Y + 1/x^3182 x*Y + 1/x^3183 """184 def __init__(self, parent, x):185 """186 EXAMPLES::187 188 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)189 sage: type(Y)190 <class 'sage.rings.function_field.function_field_element.FunctionFieldElement_polymod'>191 """192 FieldElement.__init__(self, parent)193 self._x = x194 195 def element(self):196 """197 Return the underlying polynomial that represents this element.198 199 EXAMPLES::200 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)201 sage: f = Y/x^2 + x/(x^2+1); f202 1/x^2*Y + x/(x^2 + 1)203 sage: f.element()204 1/x^2*y + x/(x^2 + 1)205 sage: type(f.element())206 <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>207 """208 return self._x209 210 def _repr_(self):211 """212 EXAMPLES::213 214 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)215 sage: Y._repr_()216 'Y'217 """218 return self._x._repr(name=self.parent().variable_name())219 220 def __nonzero__(self):221 """222 EXAMPLES::223 224 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)225 sage: bool(Y)226 True227 sage: bool(L(0))228 False229 """230 return self._x.__nonzero__()231 232 def __cmp__(self, other):233 """234 EXAMPLES::235 236 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)237 sage: cmp(L, 0)238 1239 sage: cmp(0, L)240 1241 """242 return cmp(self._x, other._x)243 244 def _add_(self, right):245 """246 EXAMPLES::247 248 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)249 sage: (2*Y + x/(1+x^3)) + (3*Y + 5*x*Y) # indirect doctest250 (5*x + 5)*Y + x/(x^3 + 1)251 """252 return self.parent()(self._x + right._x)253 254 def _sub_(self, right):255 """256 EXAMPLES::257 258 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)259 sage: (2*Y + x/(1+x^3))  (3*Y + 5*x*Y) # indirect doctest260 (5*x  1)*Y + x/(x^3 + 1)261 """262 return self.parent()(self._x  right._x)263 264 def _mul_(self, right):265 """266 EXAMPLES::267 268 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)269 sage: Y * (3*Y + 5*x*Y) # indirect doctest270 (5*x^2 + 3*x)*Y  20*x^4  12*x^3271 """272 P = self.parent()273 f = self._x * right._x274 return P(f.quo_rem(P._polynomial)[1])275 276 def _div_(self, right):277 """278 EXAMPLES::279 280 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)281 sage: (2*Y + x/(1+x^3)) / (2*Y + x/(1+x^3)) # indirect doctest282 1283 """284 return self * ~right285 286 def __invert__(self):287 """288 EXAMPLES::289 290 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)291 sage: a = ~(2*Y + 1/x); a # indirect doctest292 (x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1)293 sage: a*(2*Y + 1/x)294 1295 """296 P = self.parent()297 return P(self._x.xgcd(P._polynomial)[1])298 299 def list(self):300 """301 EXAMPLES::302 303 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3)304 sage: a = ~(2*Y + 1/x); a305 (x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1)306 sage: a.list()307 [(2*x^3 + x)/(16*x^5 + 2*x^2 + 1), x^2/(8*x^5 + x^2 + 1/2)]308 sage: (x*Y).list()309 [0, x]310 """311 return self._x.padded_list(self.parent().degree())312 313 314 class FunctionFieldElement_rational(FunctionFieldElement):315 """316 EXAMPLES::317 318 sage: FunctionField(QQ, 't')319 Rational function field in t over Rational Field320 """321 def __init__(self, parent, x):322 """323 EXAMPLES::324 325 sage: FunctionField(QQ,'t').gen()^3326 t^3327 """328 FieldElement.__init__(self, parent)329 self._x = x330 331 def element(self):332 """333 Return the underlying fraction field element that represents this element.334 335 EXAMPLES::336 337 sage: R.<a> = FunctionField(GF(7))338 sage: a.element()339 a340 sage: type(a.element())341 <type 'sage.rings.fraction_field_element.FractionFieldElement'>342 """343 return self._x344 345 def list(self):346 """347 EXAMPLES::348 349 sage: K.<t> = FunctionField(QQ)350 sage: t.list()351 [t]352 """353 return [self]354 355 def _repr_(self):356 """357 EXAMPLES::358 359 sage: K.<t> = FunctionField(QQ)360 sage: t._repr_()361 't'362 """363 return repr(self._x)364 365 def __nonzero__(self):366 """367 EXAMPLES::368 369 sage: K.<t> = FunctionField(QQ)370 sage: bool(t)371 True372 sage: bool(K(0))373 False374 sage: bool(K(1))375 True376 """377 return self._x.__nonzero__()378 379 def __cmp__(self, other):380 """381 EXAMPLES::382 383 sage: K.<t> = FunctionField(QQ)384 sage: cmp(t, 0)385 1386 sage: cmp(t, t^2)387 1388 """389 return cmp(self._x, other._x)390 391 def _add_(self, right):392 """393 EXAMPLES::394 395 sage: K.<t> = FunctionField(QQ)396 sage: t + (3*t^3) # indirect doctest397 3*t^3 + t398 """399 return self.parent()(self._x + right._x)400 401 def _sub_(self, right):402 """403 EXAMPLES::404 405 406 sage: K.<t> = FunctionField(QQ)407 sage: t  (3*t^3) # indirect doctest408 3*t^3 + t409 """410 return self.parent()(self._x  right._x)411 412 def _mul_(self, right):413 """414 EXAMPLES::415 416 sage: K.<t> = FunctionField(QQ)417 sage: (t+1) * (t^21) # indirect doctest418 t^3 + t^2  t  1419 """420 return self.parent()(self._x * right._x)421 422 def _div_(self, right):423 """424 EXAMPLES::425 426 sage: K.<t> = FunctionField(QQ)427 sage: (t+1) / (t^2  1) # indirect doctest428 1/(t  1)429 """430 return self.parent()(self._x / right._x)431 432 def numerator(self):433 """434 EXAMPLES::435 436 sage: K.<t> = FunctionField(QQ)437 sage: f = (t+1) / (t^2  1/3); f438 (t + 1)/(t^2  1/3)439 sage: f.numerator() # indirect doctest440 t + 1441 """442 return self._x.numerator()443 444 def denominator(self):445 """446 EXAMPLES::447 448 sage: K.<t> = FunctionField(QQ)449 sage: f = (t+1) / (t^2  1/3); f450 (t + 1)/(t^2  1/3)451 sage: f.denominator() # indirect doctest452 t^2  1/3453 """454 return self._x.denominator() 
new file sage/rings/function_field/function_field_element.pyx
diff r c14677eee854 r e7e85a36d207 sage/rings/function_field/function_field_element.pyx
 + 1 include "../../ext/stdsage.pxi" 2 3 from sage.structure.element cimport FieldElement, RingElement, ModuleElement, Element 4 5 def is_FunctionFieldElement(x): 6 """ 7 Return True if x is any type of function field element. 8 9 EXAMPLES:: 10 11 sage: t = FunctionField(QQ,'t').gen() 12 sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(t) 13 True 14 sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(0) 15 False 16 """ 17 return isinstance(x, FunctionFieldElement) 18 19 cdef class FunctionFieldElement(FieldElement): 20 21 cdef readonly object _x 22 cdef readonly object _matrix 23 24 """ 25 The abstract base class for function field elements. 26 27 EXAMPLES:: 28 29 sage: t = FunctionField(QQ,'t').gen() 30 sage: isinstance(t, sage.rings.function_field.function_field_element.FunctionFieldElement) 31 True 32 """ 33 34 cdef FunctionFieldElement _new_c(self): 35 cdef FunctionFieldElement x = <FunctionFieldElement>PY_NEW_SAME_TYPE(self) 36 x._parent = self._parent 37 return x 38 39 def matrix(self): 40 r""" 41 Return the matrix of multiplication by self. 42 43 EXAMPLES:: 44 45 A rational function field: 46 47 sage: K.<t> = FunctionField(QQ) 48 sage: t.matrix() 49 [t] 50 sage: (1/(t+1)).matrix() 51 [1/(t + 1)] 52 53 Now an example in a nontrivial extension of a rational function field:: 54 55 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 56 sage: Y.matrix() 57 [ 0 1] 58 [4*x^3 x] 59 sage: Y.matrix().charpoly('Z') 60 Z^2  x*Z + 4*x^3 61 62 An example in a relative extension, where neither function 63 field is rational:: 64 65 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 66 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x) 67 sage: alpha.matrix() 68 [ 0 1 0] 69 [ 0 0 1] 70 [ x x*Y  4*x^3 0] 71 """ 72 if self._matrix is None: 73 # Multiply each power of field generator on the left by this 74 # element; make matrix whose rows are the coefficients of the 75 # result, and transpose. 76 K = self.parent() 77 v = [] 78 x = K.gen() 79 a = K(1) 80 d = K.degree() 81 for n in range(d): 82 v += (a*self).list() 83 a *= x 84 k = K.base_ring() 85 import sage.matrix.matrix_space 86 M = sage.matrix.matrix_space.MatrixSpace(k, d) 87 self._matrix = M(v) 88 return self._matrix 89 90 def trace(self): 91 """ 92 Return the trace of this function field element. 93 94 EXAMPLES:: 95 96 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 97 sage: Y.trace() 98 x 99 """ 100 return self.matrix().trace() 101 102 def norm(self): 103 """ 104 Return the norm of this function field element. 105 106 EXAMPLES:: 107 108 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 109 sage: Y.norm() 110 4*x^3 111 112 113 The norm is relative:: 114 115 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 116 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x) 117 sage: alpha.norm() 118 x 119 sage: alpha.norm().parent() 120 Function field in Y defined by y^2  x*y + 4*x^3 121 """ 122 return self.matrix().determinant() 123 124 def characteristic_polynomial(self, *args, **kwds): 125 """ 126 Return the characteristic polynomial of this function field 127 element. Give an optional input string to name the variable 128 in the characteristic polynomial. 129 130 EXAMPLES:: 131 132 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 133 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x) 134 sage: x.characteristic_polynomial('W') 135 W  x 136 sage: Y.characteristic_polynomial('W') 137 W^2  x*W + 4*x^3 138 sage: alpha.characteristic_polynomial('W') 139 W^3 + (x*Y + 4*x^3)*W + x 140 """ 141 return self.matrix().characteristic_polynomial(*args, **kwds) 142 143 charpoly = characteristic_polynomial 144 145 def minimal_polynomial(self, *args, **kwds): 146 """ 147 Return the minimal polynomial of this function field element. 148 Give an optional input string to name the variable in the 149 characteristic polynomial. 150 151 EXAMPLES:: 152 153 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 154 sage: M.<T> = L[]; Z.<alpha> = L.extension(T^3  Y^2*T + x) 155 sage: x.minimal_polynomial('W') 156 W  x 157 sage: Y.minimal_polynomial('W') 158 W^2  x*W + 4*x^3 159 sage: alpha.minimal_polynomial('W') 160 W^3 + (x*Y + 4*x^3)*W + x 161 """ 162 return self.matrix().minimal_polynomial(*args, **kwds) 163 164 minpoly = minimal_polynomial 165 166 def is_integral(self): 167 r""" 168 Determine if self is integral over the maximal order of the base field. 169 170 EXAMPLES:: 171 172 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 173 sage: Y.is_integral() 174 True 175 sage: (Y/x).is_integral() 176 True 177 sage: (Y/x)^2  (Y/x) + 4*x 178 0 179 sage: (Y/x^2).is_integral() 180 False 181 sage: f = (Y/x).minimal_polynomial('W'); f 182 W^2  W + 4*x 183 """ 184 R = self.parent().base_field().maximal_order() 185 return all([a in R for a in self.minimal_polynomial()]) 186 187 cdef class FunctionFieldElement_polymod(FunctionFieldElement): 188 """ 189 EXAMPLES:: 190 191 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 192 sage: x*Y + 1/x^3 193 x*Y + 1/x^3 194 """ 195 def __init__(self, parent, x): 196 """ 197 EXAMPLES:: 198 199 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 200 sage: type(Y) 201 <type 'sage.rings.function_field.function_field_element.FunctionFieldElement_polymod'> 202 """ 203 FieldElement.__init__(self, parent) 204 self._x = x 205 206 def element(self): 207 """ 208 Return the underlying polynomial that represents this element. 209 210 EXAMPLES:: 211 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 212 sage: f = Y/x^2 + x/(x^2+1); f 213 1/x^2*Y + x/(x^2 + 1) 214 sage: f.element() 215 1/x^2*y + x/(x^2 + 1) 216 sage: type(f.element()) 217 <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'> 218 """ 219 return self._x 220 221 def _repr_(self): 222 """ 223 EXAMPLES:: 224 225 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 226 sage: Y._repr_() 227 'Y' 228 """ 229 return self._x._repr(name=self.parent().variable_name()) 230 231 def __nonzero__(self): 232 """ 233 EXAMPLES:: 234 235 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 236 sage: bool(Y) 237 True 238 sage: bool(L(0)) 239 False 240 """ 241 return not not self._x 242 243 cdef int _cmp_c_impl(self, Element other) except 2: 244 """ 245 EXAMPLES:: 246 247 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 248 sage: cmp(L, 0) 249 1 250 sage: cmp(0, L) 251 1 252 """ 253 cdef int c = cmp(type(self), type(other)) 254 if c: return c 255 cdef FunctionFieldElement left = <FunctionFieldElement>self 256 cdef FunctionFieldElement right = <FunctionFieldElement>other 257 c = cmp(left._parent, right._parent) 258 return c or cmp(left._x, right._x) 259 260 cpdef ModuleElement _add_(self, ModuleElement right): 261 """ 262 EXAMPLES:: 263 264 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 265 sage: (2*Y + x/(1+x^3)) + (3*Y + 5*x*Y) # indirect doctest 266 (5*x + 5)*Y + x/(x^3 + 1) 267 """ 268 cdef FunctionFieldElement res = self._new_c() 269 res._x = self._x + (<FunctionFieldElement>right)._x 270 return res 271 272 cpdef ModuleElement _sub_(self, ModuleElement right): 273 """ 274 EXAMPLES:: 275 276 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 277 sage: (2*Y + x/(1+x^3))  (3*Y + 5*x*Y) # indirect doctest 278 (5*x  1)*Y + x/(x^3 + 1) 279 """ 280 cdef FunctionFieldElement res = self._new_c() 281 res._x = self._x  (<FunctionFieldElement>right)._x 282 return res 283 284 cpdef RingElement _mul_(self, RingElement right): 285 """ 286 EXAMPLES:: 287 288 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 289 sage: Y * (3*Y + 5*x*Y) # indirect doctest 290 (5*x^2 + 3*x)*Y  20*x^4  12*x^3 291 """ 292 cdef FunctionFieldElement res = self._new_c() 293 res._x = (self._x * (<FunctionFieldElement>right)._x) % self._parent.polynomial() 294 return res 295 296 cpdef RingElement _div_(self, RingElement right): 297 """ 298 EXAMPLES:: 299 300 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 301 sage: (2*Y + x/(1+x^3)) / (2*Y + x/(1+x^3)) # indirect doctest 302 1 303 """ 304 return self * ~right 305 306 def __invert__(self): 307 """ 308 EXAMPLES:: 309 310 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 311 sage: a = ~(2*Y + 1/x); a # indirect doctest 312 (x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) 313 sage: a*(2*Y + 1/x) 314 1 315 """ 316 P = self._parent 317 return P(self._x.xgcd(P._polynomial)[1]) 318 319 def list(self): 320 """ 321 EXAMPLES:: 322 323 sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2  x*y + 4*x^3) 324 sage: a = ~(2*Y + 1/x); a 325 (x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) 326 sage: a.list() 327 [(2*x^3 + x)/(16*x^5 + 2*x^2 + 1), x^2/(8*x^5 + x^2 + 1/2)] 328 sage: (x*Y).list() 329 [0, x] 330 """ 331 return self._x.padded_list(self.parent().degree()) 332 333 334 cdef class FunctionFieldElement_rational(FunctionFieldElement): 335 """ 336 EXAMPLES:: 337 338 sage: FunctionField(QQ, 't') 339 Rational function field in t over Rational Field 340 """ 341 def __init__(self, parent, x): 342 """ 343 EXAMPLES:: 344 345 sage: FunctionField(QQ,'t').gen()^3 346 t^3 347 """ 348 FieldElement.__init__(self, parent) 349 self._x = x 350 351 def element(self): 352 """ 353 Return the underlying fraction field element that represents this element. 354 355 EXAMPLES:: 356 357 sage: R.<a> = FunctionField(GF(7)) 358 sage: a.element() 359 a 360 sage: type(a.element()) 361 <type 'sage.rings.fraction_field_element.FractionFieldElement'> 362 """ 363 return self._x 364 365 def list(self): 366 """ 367 EXAMPLES:: 368 369 sage: K.<t> = FunctionField(QQ) 370 sage: t.list() 371 [t] 372 """ 373 return [self] 374 375 def _repr_(self): 376 """ 377 EXAMPLES:: 378 379 sage: K.<t> = FunctionField(QQ) 380 sage: t._repr_() 381 't' 382 """ 383 return repr(self._x) 384 385 def __nonzero__(self): 386 """ 387 EXAMPLES:: 388 389 sage: K.<t> = FunctionField(QQ) 390 sage: bool(t) 391 True 392 sage: bool(K(0)) 393 False 394 sage: bool(K(1)) 395 True 396 """ 397 return not not self._x 398 399 cdef int _cmp_c_impl(self, Element other) except 2: 400 """ 401 EXAMPLES:: 402 403 sage: K.<t> = FunctionField(QQ) 404 sage: cmp(t, 0) 405 1 406 sage: cmp(t, t^2) 407 1 408 """ 409 cdef int c = cmp(type(self), type(other)) 410 if c: return c 411 cdef FunctionFieldElement left = <FunctionFieldElement>self 412 cdef FunctionFieldElement right = <FunctionFieldElement>other 413 c = cmp(left._parent, right._parent) 414 return c or cmp(left._x, right._x) 415 416 cpdef ModuleElement _add_(self, ModuleElement right): 417 """ 418 EXAMPLES:: 419 420 sage: K.<t> = FunctionField(QQ) 421 sage: t + (3*t^3) # indirect doctest 422 3*t^3 + t 423 """ 424 cdef FunctionFieldElement res = self._new_c() 425 res._x = self._x + (<FunctionFieldElement>right)._x 426 return res 427 428 cpdef ModuleElement _sub_(self, ModuleElement right): 429 """ 430 EXAMPLES:: 431 432 433 sage: K.<t> = FunctionField(QQ) 434 sage: t  (3*t^3) # indirect doctest 435 3*t^3 + t 436 """ 437 cdef FunctionFieldElement res = self._new_c() 438 res._x = self._x  (<FunctionFieldElement>right)._x 439 return res 440 441 cpdef RingElement _mul_(self, RingElement right): 442 """ 443 EXAMPLES:: 444 445 sage: K.<t> = FunctionField(QQ) 446 sage: (t+1) * (t^21) # indirect doctest 447 t^3 + t^2  t  1 448 """ 449 cdef FunctionFieldElement res = self._new_c() 450 res._x = self._x * (<FunctionFieldElement>right)._x 451 return res 452 453 cpdef RingElement _div_(self, RingElement right): 454 """ 455 EXAMPLES:: 456 457 sage: K.<t> = FunctionField(QQ) 458 sage: (t+1) / (t^2  1) # indirect doctest 459 1/(t  1) 460 """ 461 cdef FunctionFieldElement res = self._new_c() 462 res._parent = self._parent.fraction_field() 463 res._x = self._x / (<FunctionFieldElement>right)._x 464 return res 465 466 def numerator(self): 467 """ 468 EXAMPLES:: 469 470 sage: K.<t> = FunctionField(QQ) 471 sage: f = (t+1) / (t^2  1/3); f 472 (t + 1)/(t^2  1/3) 473 sage: f.numerator() # indirect doctest 474 t + 1 475 """ 476 return self._x.numerator() 477 478 def denominator(self): 479 """ 480 EXAMPLES:: 481 482 sage: K.<t> = FunctionField(QQ) 483 sage: f = (t+1) / (t^2  1/3); f 484 (t + 1)/(t^2  1/3) 485 sage: f.denominator() # indirect doctest 486 t^2  1/3 487 """ 488 return self._x.denominator()