Fix extend handling in FiniteField_givaroElement.sqrt - #42720
Fix extend handling in FiniteField_givaroElement.sqrt#42720bhuvan-somisetty wants to merge 2 commits into
Conversation
Fixes sagemath#42719 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
please rebase to the lastest develop |
|
Thanks for fixing the non-square if extend:
raise NotImplementedErrorThis also rejects elements whose roots already lie in the base field. For example, before this change, Could you keep the existing if all:
if self.is_square():
a = self.sqrt()
return [a, -a] if -a != a else [a]
if extend:
raise NotImplementedError
return []Please also add explicit |
Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
Good catch, thank you! I've updated the logic so extend=True is allowed on elements whose roots already lie in the base field, and only raises NotImplementedError on non-squares. I also added doctests for square elements with extend=True as well as characteristic 2 fields. |
Description
Fixes #42719
In
src/sage/rings/finite_rings/element_givaro.pyx,FiniteField_givaroElement.sqrt(extend=True, all=True)previously returned[](empty list) on non-squares instead of raisingNotImplementedError.This occurred because the
if all:check returned[]immediately whenself.is_square()wasFalse, completely bypassing theelif extend: raise NotImplementedErrorbranch. As a result,extend=Truewas silently ignored wheneverall=True, falsely claiming the element had no square roots in any extension field and violating the API contract.Proposed Solution
FiniteField_givaroElement.sqrt(), checkif extend: raise NotImplementedErrorupfront before checkingallor evaluating base-field squareness (matchingelement_pari_ffelt.pyxandelement_base.pyx).extendfrom(default: True)to(default: False)to match the method signature.(extend, all)for both squares and non-squares.Checklist
Dependencies
None.
Signed-off-by: bhuvan-somisetty somisettybhuvan5@gmail.com