# HG changeset patch
# User Xavier Caruso <xavier.caruso@normalesup.org>
# Date 1343377288 7200
# Node ID 7c0fff7c6324e76e3667ef38197ccef7c0c481ed
# Parent 24a5b3946a1d89e176a43a9acddf205892fb530b
Skew Polynomials
diff git a/sage/rings/polynomial/polynomial_quotient_ring_element.py b/sage/rings/polynomial/polynomial_quotient_ring_element.py
a

b


16  16  
17  17  :: 
18  18  
19   sage: S.<y> = S[] 
 19  sage: S1.<y> = S[] 
20  20  
21  21  And, we quotient out that by `y^2 + a`. 
22  22  
23  23  :: 
24  24  
25   sage: T.<z> = S.quotient(y^2+a) 
 25  sage: T.<z> = S1.quotient(y^2+a) 
26  26  
27  27  In the quotient `z^2` is `a`. 
28  28  
… 
… 

288  288  """ 
289  289  return int(self._polynomial) 
290  290  
 291  def is_unit(self): 
 292  """ 
 293  Return true if self is invertible. 
 294  
 295  WARNING:: 
 296  
 297  Only implemented when the base ring is a field. 
 298  
 299  EXAMPLES:: 
 300  
 301  sage: R.<x> = QQ[] 
 302  sage: S.<y> = R.quotient(x^2 + 2*x + 1) 
 303  sage: (2*y).is_unit() 
 304  True 
 305  sage: (y+1).is_unit() 
 306  False 
 307  
 308  TESTS:: 
 309  
 310  See trac ticket #13215:: 
 311  
 312  sage: Z16x.<x> = Integers(16)[] 
 313  sage: S.<y> = Z16x.quotient(x^2 + x + 1) 
 314  sage: (2*y).is_unit() 
 315  Traceback (most recent call last): 
 316  ... 
 317  NotImplementedError: The base ring (=Ring of integers modulo 16) is not a field 
 318  """ 
 319  if self._polynomial.is_zero(): 
 320  return False 
 321  if self._polynomial.is_one(): 
 322  return True 
 323  parent = self.parent() 
 324  base = parent.base_ring() 
 325  if not base.is_field(): 
 326  raise NotImplementedError("The base ring (=%s) is not a field" % base) 
 327  g = parent.modulus().gcd(self._polynomial) 
 328  return g.degree() == 0 
 329  
291  330  def __invert__(self): 
 331  """ 
 332  Return the inverse of this element 
 333  
 334  WARNING:: 
 335  
 336  Only implemented when the base ring is a field. 
 337  
 338  EXAMPLES:: 
 339  
 340  sage: R.<x> = QQ[] 
 341  sage: S.<y> = R.quotient(x^2 + 2*x + 1) 
 342  sage: (2*y)^(1) 
 343  1/2*y  1 
 344  
 345  Sage raises a ZeroDivisionError if this element is not 
 346  a unit:: 
 347  
 348  sage: (y+1)^(1) 
 349  Traceback (most recent call last): 
 350  ... 
 351  ZeroDivisionError: element y + 1 of quotient polynomial ring not invertible 
 352  
 353  TESTS:: 
 354  
 355  See trac ticket #13215:: 
 356  
 357  sage: Z16x.<x> = Integers(16)[] 
 358  sage: S.<y> = Z16x.quotient(x^2 + x + 1) 
 359  sage: (2*y)^(1) 
 360  Traceback (most recent call last): 
 361  ... 
 362  NotImplementedError: The base ring (=Ring of integers modulo 16) is not a field 
 363  """ 
292  364  if self._polynomial.is_zero(): 
293  365  raise ZeroDivisionError, \ 
294  366  "element %s of quotient polynomial ring not invertible"%self 
295   g, _, a = self.parent().modulus().xgcd(self._polynomial) 
 367  if self._polynomial.is_one(): 
 368  return self 
 369  parent = self.parent() 
 370  base = parent.base_ring() 
 371  if not base.is_field(): 
 372  raise NotImplementedError("The base ring (=%s) is not a field" % base) 
 373  g, _, a = parent.modulus().xgcd(self._polynomial) 
296  374  if g.degree() != 0: 
297  375  raise ZeroDivisionError, \ 
298  376  "element %s of quotient polynomial ring not invertible"%self 