Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33392: sage.matrix: Modularization fixes after #33159
Browse files Browse the repository at this point in the history
We add `# optional - sage.symbolic` doctest tags
after #33159.

URL: https://trac.sagemath.org/33392
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Michael Orlitzky
  • Loading branch information
Release Manager committed Feb 27, 2022
2 parents 5f2efac + 2f8a489 commit 0fed9a1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=f72262e6b80767f072986807eda5dedbe15495c7
md5=f82d3a2ed8e4d819884ea5b68e0b7cf9
cksum=177856930
sha1=c0df2d767b6d9346ec2ff0959d3b6d7e1681e9ae
md5=b932b425e7c2376e8530c5f9aa008169
cksum=1724034225
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ca4c2aa62c0ede2b4c2cf3c1c49e6630bbc101ed
f5430e24e093db3be4dbc44b99886815b118c72f
83 changes: 43 additions & 40 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ 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


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)

"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -869,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.
Expand Down Expand Up @@ -2195,14 +2193,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

Expand Down Expand Up @@ -6990,13 +6988,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
Expand Down Expand Up @@ -12545,8 +12548,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)]

Expand Down Expand Up @@ -14686,7 +14689,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)
Expand Down Expand Up @@ -14942,11 +14945,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])
Expand Down Expand Up @@ -15171,7 +15174,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]

Expand Down

0 comments on commit 0fed9a1

Please sign in to comment.