Skip to content

pow(int, int, fmpz) is always 1 #92

Description

@haru-44

In python-flint==0.4.4.

>>> from flint import fmpz
>>> pow(2, 5, 1000)
32
>>> pow(2, 5, fmpz(1000))
1
>>> pow(2, fmpz(5), fmpz(1000))
32

Activity

  1. oscarbenjamin commented on Oct 2, 2023

    @oscarbenjamin
    Collaborator

    Looks like the code here should be checking the type of s:

    def __pow__(s, t, m):
    cdef fmpz_struct tval[1]
    cdef fmpz_struct mval[1]
    cdef int ttype = FMPZ_UNKNOWN
    cdef int mtype = FMPZ_UNKNOWN
    cdef int success
    u = NotImplemented
    ttype = fmpz_set_any_ref(tval, t)
    if ttype == FMPZ_UNKNOWN:
    return NotImplemented

    I hadn't contemplated that __pow__(s, t, m) might be called with s not being an fmpz. At this line s will be an int (PyLong):
    fmpz_powm((<fmpz>u).val, (<fmpz>s).val, tval, mval)

    Presumably the bytes there look like a 1 as an fmpz_t.

    The fix is that the s argument should be handled in the same way as the t argument.

  2. oscarbenjamin commented on Oct 2, 2023

    @oscarbenjamin
    Collaborator

    Thanks for the bug report. This will be fixed in the next release.

  3. haru-44 commented on Oct 2, 2023

    @haru-44
    Author

    Thanks for the correction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions