From b28224bb283baa22318634154c6851243927df37 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 20 Feb 2022 23:53:03 -0800 Subject: [PATCH 1/2] src/sage/matrix/matrix2.pyx: Add # optional - sage.symbolic --- src/sage/matrix/matrix2.pyx | 80 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index cf83906d253..342cdf905c9 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -402,9 +402,9 @@ cdef class Matrix(Matrix1): any are inexact, however, the ``check`` is still skipped (:trac:`29729` and :trac:`33159`):: - sage: A = matrix(SR, [[1, 1]]) - sage: b = vector(SR, [2, 3]) - sage: A.solve_left(b) + sage: A = matrix(SR, [[1, 1]]) # optional - sage.symbolic + sage: b = vector(SR, [2, 3]) # optional - sage.symbolic + sage: A.solve_left(b) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions @@ -412,7 +412,7 @@ cdef class Matrix(Matrix1): In this case, turning off the ``check`` leads to a wrong result:: - sage: A.solve_left(b, check=False) + sage: A.solve_left(b, check=False) # optional - sage.symbolic (2) """ @@ -622,21 +622,20 @@ cdef class Matrix(Matrix1): Solving a system of linear equations symbolically using symbolic matrices:: - sage: var('a,b,c,d,x,y') + sage: var('a,b,c,d,x,y') # optional - sage.symbolic (a, b, c, d, x, y) - sage: A=matrix(SR,2,[a,b,c,d]); A + sage: A = matrix(SR, 2, [a,b,c,d]); A # optional - sage.symbolic [a b] [c d] - sage: result=vector(SR,[3,5]); result + sage: result = vector(SR, [3,5]); result # optional - sage.symbolic (3, 5) - sage: soln=A.solve_right(result) - sage: soln + sage: soln = A.solve_right(result); soln # optional - sage.symbolic (-b*(3*c/a - 5)/(a*(b*c/a - d)) + 3/a, (3*c/a - 5)/(b*c/a - d)) - sage: (a*x+b*y).subs(x=soln[0],y=soln[1]).simplify_full() + sage: (a*x+b*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic 3 - sage: (c*x+d*y).subs(x=soln[0],y=soln[1]).simplify_full() + sage: (c*x+d*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic 5 - sage: (A*soln).apply_map(lambda x: x.simplify_full()) + sage: (A*soln).apply_map(lambda x: x.simplify_full()) # optional - sage.symbolic (3, 5) Over inexact rings, the output of this function may not be an exact @@ -807,31 +806,31 @@ cdef class Matrix(Matrix1): any are inexact, however, the ``check`` is still skipped (:trac:`29729` and :trac:`33159`):: - sage: m = matrix(SR, [0]) - sage: b = vector(SR, [1]) - sage: m.solve_right(b, check=True) + sage: m = matrix(SR, [0]) # optional - sage.symbolic + sage: b = vector(SR, [1]) # optional - sage.symbolic + sage: m.solve_right(b, check=True) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions In this case, turning off the ``check`` leads to a wrong result:: - sage: m.solve_right(b, check=False) + sage: m.solve_right(b, check=False) # optional - sage.symbolic (0) In the following, we have an inexact entry in the matrix, so the ``check`` is still skipped leading to a wrong result:: - sage: m = matrix(SR, [0.0]) - sage: m.solve_right(b, check=True) + sage: m = matrix(SR, [0.0]) # optional - sage.symbolic + sage: m.solve_right(b, check=True) # optional - sage.symbolic (0) :: - sage: SC = SR.subring(no_variables=True) - sage: m = matrix(SC, [0]) - sage: b = vector(SC, [1]) - sage: m.solve_right(b) + sage: SC = SR.subring(no_variables=True) # optional - sage.symbolic + sage: m = matrix(SC, [0]) # optional - sage.symbolic + sage: b = vector(SC, [1]) # optional - sage.symbolic + sage: m.solve_right(b) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions @@ -2195,14 +2194,14 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(SR, 2, lambda i, j: f'a{i}{j}'); A + sage: A = matrix(SR, 2, lambda i, j: f'a{i}{j}'); A # optional - sage.symbolic [a00 a01] [a10 a11] - sage: A.quantum_determinant() + sage: A.quantum_determinant() # optional - sage.symbolic -a01*a10*q + a00*a11 - sage: A = matrix(SR, 3, lambda i, j: f'a{i}{j}') - sage: A.quantum_determinant() + sage: A = matrix(SR, 3, lambda i, j: f'a{i}{j}') # optional - sage.symbolic + sage: A.quantum_determinant() # optional - sage.symbolic -a02*a11*a20*q^3 + (a01*a12*a20 + a02*a10*a21)*q^2 + (-a00*a12*a21 - a01*a10*a22)*q + a00*a11*a22 @@ -6990,13 +6989,18 @@ cdef class Matrix(Matrix1): the algebraic multiplicity. The following examples show that these cases are detected (:trac:`27842`):: - sage: A = matrix(SR, [(225/548, 0, -175/274*sqrt(193/1446)), (0, 1/2, 0), (-63/548*sqrt(723/386), 0, 49/548)]) - sage: A.eigenmatrix_left() + sage: A = matrix(SR, [(225/548, 0, -175/274*sqrt(193/1446)), # optional - sage.symbolic + ....: (0, 1/2, 0), + ....: (-63/548*sqrt(723/386), 0, 49/548)]) + sage: A.eigenmatrix_left() # optional - sage.symbolic Traceback (most recent call last): ... RuntimeError: failed to compute eigenvectors for eigenvalue ..., check eigenvectors_left() for partial results - sage: B = matrix(SR, [(1/2, -7/2*sqrt(1/386), 0, 49/2*sqrt(1/279078)), (-7/2*sqrt(1/386), 211/772, 0, -8425/772*sqrt(1/723)), (0, 0, 1/2, 0), (49/2*sqrt(1/279078), -8425/772*sqrt(1/723), 0, 561/772)]) - sage: B.eigenmatrix_left() # long time (1.2 seconds) + sage: B = matrix(SR, [(1/2, -7/2*sqrt(1/386), 0, 49/2*sqrt(1/279078)), # optional - sage.symbolic + ....: (-7/2*sqrt(1/386), 211/772, 0, -8425/772*sqrt(1/723)), + ....: (0, 0, 1/2, 0), + ....: (49/2*sqrt(1/279078), -8425/772*sqrt(1/723), 0, 561/772)]) + sage: B.eigenmatrix_left() # long time (1.2 seconds) # optional - sage.symbolic Traceback (most recent call last): ... RuntimeError: failed to compute eigenvectors for eigenvalue ..., check eigenvectors_left() for partial results @@ -12545,8 +12549,8 @@ cdef class Matrix(Matrix1): Even symbolic matrices can sometimes be factored:: - sage: A = matrix(SR, [[pi,0],[0,pi]]) - sage: A.cholesky() + sage: A = matrix(SR, [[pi,0], [0,pi]]) # optional - sage.symbolic + sage: A.cholesky() # optional - sage.symbolic [sqrt(pi) 0] [ 0 sqrt(pi)] @@ -14686,7 +14690,7 @@ cdef class Matrix(Matrix1): True sage: matrix.identity(CC,4).is_positive_definite() True - sage: matrix.identity(SR,4).is_positive_definite() + sage: matrix.identity(SR,4).is_positive_definite() # optional - sage.symbolic True """ result = self._is_positive_definite_or_semidefinite(False) @@ -14942,11 +14946,11 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = matrix(SR, 2, 2, [[2-I, 3+4*I], [9-6*I, 5*I]]) - sage: M.base_ring() + sage: M = matrix(SR, 2, 2, [[2-I, 3+4*I], [9-6*I, 5*I]]) # optional - sage.symbolic + sage: M.base_ring() # optional - sage.symbolic Symbolic Ring - sage: M.conjugate_transpose() - [ I + 2 6*I + 9] + sage: M.conjugate_transpose() # optional - sage.symbolic + [ I + 2 6*I + 9] [-4*I + 3 -5*I] sage: P = matrix(CC, 3, 2, [0.95-0.63*I, 0.84+0.13*I, 0.94+0.23*I, 0.23+0.59*I, 0.52-0.41*I, -0.50+0.90*I]) @@ -15171,7 +15175,7 @@ cdef class Matrix(Matrix1): :: - sage: matrix(SR, 2, 2, range(4)).n() + sage: matrix(SR, 2, 2, range(4)).n() # optional - sage.symbolic [0.000000000000000 1.00000000000000] [ 2.00000000000000 3.00000000000000] From 2f8a4890a1ca670d8282b35204c0e49ee4383e54 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 20 Feb 2022 23:53:19 -0800 Subject: [PATCH 2/2] src/sage/matrix/matrix2.pyx: Use sage.rings.abc.SymbolicRing for isinstance testing --- src/sage/matrix/matrix2.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 342cdf905c9..3ec83f779e2 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -868,8 +868,7 @@ cdef class Matrix(Matrix1): # If our field is inexact, checking the answer is doomed in # most cases. But here we handle the special ones. - from sage.symbolic.ring import SymbolicRing - if isinstance(K, SymbolicRing): + if isinstance(K, sage.rings.abc.SymbolicRing): # Elements of SR "remember" whether or not they are exact. # If every element in the system is exact, we can probably # still check the solution over the inexact ring SR.