#17717: Failure to reduce int modulo large prime
--------------------------------------+------------------------
Reporter: xander.faber | Owner:
Type: defect | Status: new
Priority: minor | Milestone: sage-6.5
Component: finite rings | Resolution:
Keywords: modular arithmetic | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
--------------------------------------+------------------------
Description changed by xander.faber:
Old description:
> {{{
> sage: p = next_prime(2^32)
> sage: p
> 4294967311
> sage: GF(p)(int(p+1))
> 4294967312
> sage: GF(p)(p+1)
> 1
> }}}
>
> The issue arises in
> sage/rings/finite_rings/integer_mod.pyx
>
> class method
> IntegerMod_gmp.set_from_long
>
> On line 1732, the code reduces value (mod modulus) when value < 0 or (
> value < modulus ). The latter condition is backward. It should be
> replaced with ( modulus < value).
>
> Replace line 1732
> `if value < 0 or mpz_cmp_si(self.__modulus.sageInteger.value,
> value) >= 0:`
> with
> `if value < 0 or mpz_cmp_si(value,
> self.__modulus.sageInteger.value) >= 0:`
New description:
{{{
sage: p = next_prime(2^32)
sage: p
4294967311
sage: GF(p)(int(p+1))
4294967312
sage: GF(p)(p+1)
1
}}}
The issue arises in
sage/rings/finite_rings/integer_mod.pyx
class method
IntegerMod_gmp.set_from_long
On line 1732, the code reduces value (mod modulus) when value < 0 or (
value < modulus ). The latter condition is backward. It should be replaced
with ( modulus < value).
Replace line 1732
`if value < 0 or mpz_cmp_si(self.__modulus.sageInteger.value,
value) >= 0:`
with
`if value < 0 or mpz_cmp_si(self.__modulus.sageInteger.value,
value) <= 0:`
--
--
Ticket URL: <http://trac.sagemath.org/ticket/17717#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.