# Ticket #5347: trac_5347-divides.patch

File trac_5347-divides.patch, 2.4 KB (added by cremona, 12 years ago)

Applies to 4.1.1

• ## sage/structure/element.pyx

```# 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 def inverse_mod(self, I): r""" Return an inverse of self modulo the ideal \$I\$, if defined, Return an inverse of self modulo the ideal `I`, if defined, i.e., if `I` and self together generate the unit ideal. """ raise NotImplementedError False sage: (x^2+2).divides(x) False Ticket \#5347 has been fixed:: sage: K = GF(7) sage: K(3).divides(1) True sage: K(3).divides(K(1)) True :: sage: R = Integers(128) sage: R(0).divides(1) False sage: R(0).divides(0) True sage: R(0).divides(R(0)) True sage: R(1).divides(0) True sage: R(121).divides(R(120)) True sage: R(120).divides(R(121)) Traceback (most recent call last): ... ZeroDivisionError: reduction modulo right not defined. """ # First we test some generic conditions: try: if x.is_zero(): return True # everything divides 0 except (AttributeError, NotImplementedError): pass try: if self.is_zero(): return False # 0 divides nothing else except (AttributeError, NotImplementedError): pass try: if self.is_unit(): return True # units divide everything except (AttributeError, NotImplementedError): pass try: if self.is_one(): return True # 1 divides everything # (is_unit() may not be implemented) except (AttributeError, NotImplementedError): pass return (x % self) == 0 def mod(self, I):