Skip to content

Rational .sqrt() should return an empty list instead of raising an error when all=True #37153

@GiacomoPope

Description

@GiacomoPope

Steps To Reproduce

sage: K = QQ[I]
sage: K(3).sqrt(extend=False, all=True)
[]
sage: ZZ(3).sqrt(extend=False, all=True)
[]
sage: QQ(3).sqrt(extend=False, all=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [19], line 1
----> 1 QQ(Integer(3)).sqrt(extend=False, all=True)

File ~/sage/sage-10.2/src/sage/rings/rational.pyx:1971, in sage.rings.rational.Rational.sqrt()
   1969 if non_square:
   1970     if not extend:
-> 1971         raise ValueError("square root of %s not a rational number" % self)
   1972     from sage.misc.functional import _do_sqrt
   1973     return _do_sqrt(self, prec=prec, all=all)

ValueError: square root of 3 not a rational number

Expected Behavior

When the all=True param is set, when there are no sqrt an empty list should be returned:

sage: QQ(3).sqrt(extend=False, all=True)
[]

Actual Behavior

When the all=True param is set, when there are no sqrt an empty list should be returned:

sage: QQ(3).sqrt(extend=False, all=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [19], line 1
----> 1 QQ(Integer(3)).sqrt(extend=False, all=True)

File ~/sage/sage-10.2/src/sage/rings/rational.pyx:1971, in sage.rings.rational.Rational.sqrt()
   1969 if non_square:
   1970     if not extend:
-> 1971         raise ValueError("square root of %s not a rational number" % self)
   1972     from sage.misc.functional import _do_sqrt
   1973     return _do_sqrt(self, prec=prec, all=all)

ValueError: square root of 3 not a rational number

Additional Information

No response

Environment

- **OS**: MacOS
- **Sage Version**: 10.2

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions