Ticket #10217 (closed defect: fixed)

Opened 3 years ago

Last modified 13 months ago

bug in rings/fast_arith.pyx

Reported by: was Owned by: AlexGhitza
Priority: minor Milestone: sage-5.1
Component: basic arithmetic Keywords:
Cc: Work issues:
Report Upstream: N/A Reviewers: Mike Hansen, André Apitzsch
Authors: Mike Hansen, André Apitzsch Merged in: sage-5.1.beta0
Dependencies: Stopgaps:

Description (last modified by aapitzsch) (diff)

This chunk of code in fast_arith.pyx:

    cdef public long long c_inverse_mod_longlong(self, long long a, long long m) except -1:
        cdef long long g, s, t
        g = self.c_xgcd_longlong(a,m, &s, &t)
        s = s % m
        if s < 0:
            s = s + m
        return s

should raise an exception if g != 1, so should be

    cdef public long long c_inverse_mod_longlong(self, long long a, long long m) except -1:
        cdef long long g, s, t
        g = self.c_xgcd_longlong(a,m, &s, &t)
        if g != 1: raise ZeroDivisionError
        s = s % m
        if s < 0:
            s = s + m
        return s

Apply only trac_10217_rebased.patch Download

Attachments

trac_10217.patch Download (782 bytes) - added by aapitzsch 2 years ago.
trac_10217-2.patch Download (2.1 KB) - added by mhansen 14 months ago.
trac_10217_merged.patch Download (3.2 KB) - added by aapitzsch 14 months ago.
trac_10217_rebased.patch Download (3.3 KB) - added by aapitzsch 14 months ago.
rebased to sage-5.0.beta12

Change History

Changed 2 years ago by aapitzsch

comment:1 Changed 2 years ago by aapitzsch

  • Status changed from new to needs_review

If g!=1 then Arithmetic Error is raised like in c_inverse_mod_int

comment:2 Changed 2 years ago by zimmerma

  • Status changed from needs_review to needs_work
  • Work issues set to deal with new exception

I started to look at this. I had difficulties trying to find a test that could hit the case g != 1. I found the following:

from sage.ext.multi_modular import MultiModularBasis_base
mm = MultiModularBasis_base([6, 10])

which raises another problem, since the new exception is not trapped:

sage: mm.crt([1,2])
13

This is wrong since 13 is not equal to 2 mod 10...

Paul

comment:3 Changed 17 months ago by mhansen

  • Status changed from needs_work to needs_info

MultiModularBasis?_base requires that it's inputs actually be prime so mm = MultiModularBasis_base([6, 10]) shouldn't produce a valid object.

Changed 14 months ago by mhansen

comment:4 Changed 14 months ago by mhansen

  • Status changed from needs_info to needs_review
  • Work issues deal with new exception deleted
  • Authors set to Mike Hansen, Andre Apitzsch

I've added some code which adds a doctest for this functionality.

Last edited 14 months ago by mhansen (previous) (diff)

Changed 14 months ago by aapitzsch

comment:5 Changed 14 months ago by aapitzsch

  • Description modified (diff)

I've replaced the deprecated raise syntax by a Python 3 compatible one.

comment:6 Changed 14 months ago by mhansen

Looks good to me. If you're okay with my changes, could you mark it as positive review?

comment:7 Changed 14 months ago by mhansen

Apply only trac_10217_merged.patch

comment:8 Changed 14 months ago by aapitzsch

  • Status changed from needs_review to positive_review

comment:9 Changed 14 months ago by jdemeyer

  • Status changed from positive_review to needs_work
  • Description modified (diff)

This should be rebased to sage-5.0.beta12:

applying trac_10217_merged.patch
patching file sage/ext/multi_modular.pyx
Hunk #1 FAILED at 156
1 out of 2 hunks FAILED -- saving rejects to file sage/ext/multi_modular.pyx.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working dir
errors during apply, please fix and refresh trac_10217_merged.patch

Also the Reviewer field needs to be filled in.

Changed 14 months ago by aapitzsch

rebased to sage-5.0.beta12

comment:10 Changed 14 months ago by aapitzsch

  • Status changed from needs_work to positive_review
  • Reviewers set to Mike Hansen, Andre Apitzsch
  • Description modified (diff)

comment:11 Changed 14 months ago by aapitzsch

Apply only trac_10217_rebased.patch

comment:12 Changed 13 months ago by jdemeyer

  • Reviewers changed from Mike Hansen, Andre Apitzsch to Mike Hansen, André Apitzsch
  • Authors changed from Mike Hansen, Andre Apitzsch to Mike Hansen, André Apitzsch

comment:13 Changed 13 months ago by jdemeyer

  • Milestone changed from sage-5.0 to sage-5.1

comment:14 Changed 13 months ago by jdemeyer

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