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

support all= keyword argument in AlgebraicClosureFiniteFieldElement.sqrt() #35280

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/sage/rings/algebraic_closure_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,34 @@ def is_square(self):
"""
return True

def sqrt(self):
def sqrt(self, all=False):
"""
Return a square root of ``self``.

If the optional keyword argument ``all`` is set to ``True``,
return a list of all square roots of ``self`` instead.

EXAMPLES::

sage: F = GF(3).algebraic_closure()
sage: F.gen(2).sqrt()
z4^3 + z4 + 1

sage: F.gen(2).sqrt(all=True)
[z4^3 + z4 + 1, 2*z4^3 + 2*z4 + 2]
sage: (F.gen(2)^2).sqrt()
z2
sage: (F.gen(2)^2).sqrt(all=True)
[z2, 2*z2]
"""
F = self.parent()
x = self._value
if x.is_square():
return self.__class__(F, x.sqrt(extend=False))
else:
if not x.is_square():
l = self._level
x = F.inclusion(l, 2*l)(x)
return self.__class__(F, x.sqrt(extend=False))
sqrt = x.sqrt(extend=False, all=all)
if all:
return [self.__class__(F, y) for y in sqrt]
return self.__class__(F, sqrt)

def nth_root(self, n):
"""
Expand Down