Opened 14 years ago

Closed 13 years ago

#5347 closed defect (fixed)

[with patch, positive review] divides() may fail for 1 on the rhs.

Reported by: Martin Albrecht Owned by: somebody
Priority: major Milestone: sage-4.1.2
Component: basic arithmetic Keywords: ring element divides
Cc: Mike Hansen Merged in: Sage 4.1.2.alpha2
Authors: John Cremona Reviewers: Mike Hansen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

sage: K = GF(7)
sage: K(3).divides(1)
False
sage: K(3).divides(K(1))
Traceback (most recent call last)
...
ZeroDivisionError: reduction modulo right not defined.

This is because of this code added at http://hg.sagemath.org/sage-main/rev/0cb746e1a4bd

def divides(self, x):
    return (x % self) == 0

Attachments (1)

trac_5347-divides.patch (2.4 KB) - added by John Cremona 13 years ago.
Applies to 4.1.1

Download all attachments as: .zip

Change History (4)

Changed 13 years ago by John Cremona

Attachment: trac_5347-divides.patch added

Applies to 4.1.1

comment:1 Changed 13 years ago by John Cremona

Authors: John Cremona
Keywords: ring element divides added
Summary: divides() may fail for 1 on the rhs.[with patch, needs review] divides() may fail for 1 on the rhs.

The patch handles this by testing all the easy cases of a.divides(b) (a is 1 or a unit, b is zero) before trying the % operation. Doctest added to show that it works.

comment:2 Changed 13 years ago by Mike Hansen

Reviewers: Mike Hansen
Summary: [with patch, needs review] divides() may fail for 1 on the rhs.[with patch, positive review] divides() may fail for 1 on the rhs.

Looks good to me.

comment:3 Changed 13 years ago by Minh Van Nguyen

Merged in: Sage 4.1.2.alpha2
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.