Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any_root is broken in characteristic 2 #33329

Closed
roed314 opened this issue Feb 13, 2022 · 1 comment
Closed

any_root is broken in characteristic 2 #33329

roed314 opened this issue Feb 13, 2022 · 1 comment

Comments

@roed314
Copy link
Contributor

roed314 commented Feb 13, 2022

The following example will hang:

sage: k = GF(2^60)
sage: R.<x> = k[]
sage: f = (x - k.random_element()) * (x - k.random_element())
sage: f.any_root()

while this will quickly succeed:

sage: f.roots(multiplicities=False)[0]

The core of the any_root implementation is the following (from poylnomial_element.pyx):

if q % 2 == 0:
    while True:
        T = R.random_element(2*degree-1)
        if T == 0:
            continue
        T = T.monic()
        C = T
        for i in range(degree-1):
            C = T + pow(C,q,self)
        h = self.gcd(C)
        hd = h.degree()
        if hd != 0 and hd != self.degree():
            if 2*hd <= self.degree():
                return h.any_root(ring, -degree, True)
            else:
                return (self//h).any_root(ring, -degree, True)

In the example above, degree=1 (since we're looking for roots in the base ring), and thus we're just randomly choosing a T and seeing if it has nontrivial gcd with the input. So we're just randomly guessing in large characteristic 2 fields, which of course takes a long time.

Sage's implementation follows the description of the Cantor-Zassenhaus algorithm in Cohen's Intro to Computational Algebraic Number Theory (Alg. 3.4.8) for example, but that exposition is focused on the case that the base ring is a prime field (GF(2) here). In order to handle other characteristic 2 finite fields you need to do more work: see the original paper or this preprint.

Two possible solutions: either implement the algorithm properly, or fall back to just using f.roots(multiplicities=False)[0] in this case.

Component: finite rings

Issue created by migration from https://trac.sagemath.org/ticket/33329

@roed314 roed314 added this to the sage-9.6 milestone Feb 13, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
@grhkm21
Copy link
Contributor

grhkm21 commented Feb 15, 2024

Fixed in #37170.

@grhkm21 grhkm21 closed this as completed Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants