Skip to content

QR decomposition fails for qqbar matrix #40733

@fredrik-johansson

Description

@fredrik-johansson

Steps To Reproduce

This QR decomposition succeeds for n <= 18 but fails for n = 19 due to an internal error in the qqbar arithmetic.

n = 19
A = matrix(QQbar, [[1/(i+j+1) for i in range(n)] for j in range(n)])
A.QR()

Expected Behavior

The computation should succeed.

Actual Behavior

~/src$ ./sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.7, Release Date: 2025-08-09                    │
│ Using Python 3.13.5. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: n=19; A = matrix(QQbar, [[1/(i+j+1) for i in range(n)] for j in range(n)]); A.QR();
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 1
----> 1 n=Integer(19); A = matrix(QQbar, [[Integer(1)/(i+j+Integer(1)) for i in range(n)] for j in range(n)]); A.QR();

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/matrix/matrix2.pyx:11311, in sage.matrix.matrix2.Matrix.QR (build/cythonized/sage/matrix/matrix2.c:101881)()
  11309 if hip != 0:
  11310     try:
> 11311         scale = sqrt(hip)
  11312         q = (1/scale)*v
  11313         Q.append(q)

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/misc/functional.py:1982, in sqrt(x, *args, **kwds)
   1980     return sqrt(x)
   1981 try:
-> 1982     return x.sqrt(*args, **kwds)
   1983 # The following includes TypeError to catch cases where sqrt
   1984 # is called with a "prec" keyword, for example, but the sqrt
   1985 # method for x doesn't accept such a keyword.
   1986 except (AttributeError, TypeError):

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/rings/qqbar.py:4386, in AlgebraicNumber_base.sqrt(self, all, extend)
   4383     else:
   4384         return []
-> 4386 root = self ** ~ZZ(2)
   4388 if all:
   4389     return [root, -root]

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/structure/element.pyx:2058, in sage.structure.element.Element.__pow__ (build/cythonized/sage/structure/element.c:23944)()
   2056     return (<Element>left)._pow_(right)
   2057 if BOTH_ARE_ELEMENT(cl):
-> 2058     return coercion_model.bin_op(left, right, pow)
   2059 
   2060 cdef long value

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/structure/coerce.pyx:1236, in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:16548)()
   1234         return (<Action>action)._act_(x, y)
   1235     else:
-> 1236         return (<Action>action)._act_(y, x)
   1237 
   1238 # Now coerce to a common parent and do the operation there

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/categories/action.pyx:194, in sage.categories.action.Action._act_ (build/cythonized/sage/categories/action.c:6804)()
    192     return self._act_(g, x)
    193 
--> 194 cpdef _act_(self, g, x):
    195     """
    196     Let ``g`` act on ``x`` under this action.

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/rings/qqbar.py:6580, in AlgebraicNumberPowQQAction._act_(self, e, x)
   6578 val = x._interval_fast(prec)
   6579 if isinstance(val, RealIntervalFieldElement) or not val.crosses_log_branch_cut():
-> 6580     argument = val.argument()
   6581     if val.imag().is_zero() and val.real() < 0:
   6582         argument_is_pi = True

File /var/tmp/sage-10.7/local/lib/python3.13/site-packages/sage/rings/complex_interval.pyx:1681, in sage.rings.complex_interval.ComplexIntervalFieldElement.argument (build/cythonized/sage/rings/complex_interval.c:21825)()
   1679 if which_axes[i % 4] and not which_axes[(i - 1) % 4]:
   1680     if lower is not None:
-> 1681         raise ValueError("Can't take the argument of line-segment interval strictly containing zero")
   1682     lower = i
   1683 

ValueError: Can't take the argument of line-segment interval strictly containing zero

Additional Information

No response

Environment

  • OS: Ubuntu
  • Sage Version: 10.7

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