Opened 10 years ago

Closed 10 years ago

#13639 closed defect (fixed)

Inverting 0 mod 1

Reported by: jdemeyer Owned by: AlexGhitza
Priority: minor Milestone: sage-5.5
Component: basic arithmetic Keywords:
Cc: Merged in: sage-5.5.beta1
Authors: Jeroen Demeyer Reviewers: Robert Bradshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

sage: ~Mod(0,1)
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)

/usr/local/src/sage-5.4.rc1/<ipython console> in <module>()

/usr/local/src/sage-5.4.rc1/local/lib/python2.7/site-packages/sage/rings/finite_rings/integer_mod.so in sage.rings.finite_rings.integer_mod.IntegerMod_int.__invert__ (sage/rings/finite_rings/integer_mod.c:22320)()

ZeroDivisionError: Inverse does not exist.

But modulo 1, the inverse does exist. Note that gcd(0,1) == 1.

Attachments (1)

13639_inverse_mod_1.patch (3.4 KB) - added by jdemeyer 10 years ago.

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by jdemeyer

Attachment: 13639_inverse_mod_1.patch added

comment:1 Changed 10 years ago by jdemeyer

Status: newneeds_review

comment:2 Changed 10 years ago by robertwb

Status: needs_reviewpositive_review

Looks good to me, nice cleanup too. How did you run into this?

comment:3 Changed 10 years ago by robertwb

Reviewers: Robert Bradshaw

comment:4 in reply to:  2 Changed 10 years ago by jdemeyer

Replying to robertwb:

How did you run into this?

Quite naturally in fact. I needed some random numbers to create an exercise for students to solve which involved (amonst other things) inverting Mod(r,s). I wrote a loop to randomly generate some numbers, checking that gcd(r,s) == 1.

comment:5 Changed 10 years ago by jdemeyer

Merged in: sage-5.5.beta1
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.