# HG changeset patch
# User John Cremona <john.cremona@gmail.com>
# Date 1251654151 3600
# Node ID 6ca35b9f08d172b8a4fa34bf0d6b38f228c562fa
# Parent 684eea91ff224e5bc6259ca19f1576c4c082b9d3
#5347  fix divides() for generic ring elements
diff r 684eea91ff22 r 6ca35b9f08d1 sage/structure/element.pyx
a

b


1393  1393  
1394  1394  def inverse_mod(self, I): 
1395  1395  r""" 
1396   Return an inverse of self modulo the ideal $I$, if defined, 
 1396  Return an inverse of self modulo the ideal `I`, if defined, 
1397  1397  i.e., if `I` and self together generate the unit ideal. 
1398  1398  """ 
1399  1399  raise NotImplementedError 
… 
… 

1418  1418  False 
1419  1419  sage: (x^2+2).divides(x) 
1420  1420  False 
 1421  
 1422  Ticket \#5347 has been fixed:: 
 1423  
 1424  sage: K = GF(7) 
 1425  sage: K(3).divides(1) 
 1426  True 
 1427  sage: K(3).divides(K(1)) 
 1428  True 
 1429  
 1430  :: 
 1431  
 1432  sage: R = Integers(128) 
 1433  sage: R(0).divides(1) 
 1434  False 
 1435  sage: R(0).divides(0) 
 1436  True 
 1437  sage: R(0).divides(R(0)) 
 1438  True 
 1439  sage: R(1).divides(0) 
 1440  True 
 1441  sage: R(121).divides(R(120)) 
 1442  True 
 1443  sage: R(120).divides(R(121)) 
 1444  Traceback (most recent call last): 
 1445  ... 
 1446  ZeroDivisionError: reduction modulo right not defined. 
 1447  
1421  1448  """ 
 1449  # First we test some generic conditions: 
 1450  try: 
 1451  if x.is_zero(): 
 1452  return True # everything divides 0 
 1453  except (AttributeError, NotImplementedError): 
 1454  pass 
 1455  
 1456  try: 
 1457  if self.is_zero(): 
 1458  return False # 0 divides nothing else 
 1459  except (AttributeError, NotImplementedError): 
 1460  pass 
 1461  
 1462  try: 
 1463  if self.is_unit(): 
 1464  return True # units divide everything 
 1465  except (AttributeError, NotImplementedError): 
 1466  pass 
 1467  
 1468  try: 
 1469  if self.is_one(): 
 1470  return True # 1 divides everything 
 1471  # (is_unit() may not be implemented) 
 1472  except (AttributeError, NotImplementedError): 
 1473  pass 
 1474  
1422  1475  return (x % self) == 0 
1423  1476  
1424  1477  def mod(self, I): 