Opened 7 years ago

Closed 7 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:

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 7 years ago.

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by jdemeyer

comment:1 Changed 7 years ago by jdemeyer

  • Status changed from new to needs_review

comment:2 follow-up: Changed 7 years ago by robertwb

  • Status changed from needs_review to positive_review

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

comment:3 Changed 7 years ago by robertwb

  • Reviewers set to Robert Bradshaw

comment:4 in reply to: ↑ 2 Changed 7 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 7 years ago by jdemeyer

  • Merged in set to sage-5.5.beta1
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.