Skip to content

Commit 7a2ef2f

Browse files
author
Release Manager
committed
gh-40711: remove some deprecations in matrix2 after - File: src/sage/matrix/matrix2.pyx ; PR: #36394 ; Closed Date: 2023-10-14 - File: src/sage/matrix/matrix2.pyx ; PR: #29243 ; Closed Date: 2020-08-30 - File: src/sage/matrix/matrix2.pyx ; PR: #31619 ; Closed Date: 2021-06-06 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. URL: #40711 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents da0856b + 44c203b commit 7a2ef2f

File tree

7 files changed

+30
-196
lines changed

7 files changed

+30
-196
lines changed

src/doc/en/prep/Quickstarts/Linear-Algebra.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ We can easily solve linear equations using the backslash, like in Matlab.
324324
::
325325

326326
sage: A = random_matrix(QQ, 3, algorithm='unimodular')
327-
sage: v = vector([2,3,1])
328-
sage: A,v # random
327+
sage: v = vector([2, 3, 1])
328+
sage: A, v # random
329329
(
330330
[ 0 -1 1]
331331
[-1 -1 -1]
332332
[ 0 2 2], (2, 3, 1)
333333
)
334-
sage: x=A\v; x # random
334+
sage: x = A.solve_right(v); x # random
335335
(-7/2, -3/4, 5/4)
336-
sage: A*x # random
336+
sage: A * x # random
337337
(2, 3, 1)
338338

339339
For *lots* more (concise) information, see the Sage `Linear Algebra

src/sage/matrix/matrix2.pyx

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ from sage.matrix.matrix_misc import permanental_minor_polynomial
105105
from sage.misc.misc_c import prod
106106

107107
# used to deprecate only adjoint method
108-
from sage.misc.superseded import deprecation, deprecated_function_alias
108+
from sage.misc.superseded import deprecated_function_alias
109109

110110

111111
# temporary hack to silence the warnings from #34806
@@ -140,35 +140,6 @@ cdef class Matrix(Matrix1):
140140
[x], [0]
141141
)
142142
"""
143-
def _backslash_(self, B):
144-
r"""
145-
Used to compute `A \backslash B`, i.e., the backslash solver
146-
operator.
147-
148-
DEPRECATED
149-
150-
EXAMPLES::
151-
152-
sage: A = matrix(QQ, 3, [1,2,4,2,3,1,0,1,2])
153-
sage: B = matrix(QQ, 3, 2, [1,7,5, 2,1,3])
154-
sage: C = A._backslash_(B); C
155-
doctest:...: DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
156-
See https://github.com/sagemath/sage/issues/36394 for details.
157-
[ -1 1]
158-
[13/5 -3/5]
159-
[-4/5 9/5]
160-
sage: A*C == B
161-
True
162-
sage: A._backslash_(B) == A \ B
163-
doctest:...: DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
164-
See https://github.com/sagemath/sage/issues/36394 for details.
165-
True
166-
sage: A._backslash_(B) == A.solve_right(B)
167-
True
168-
"""
169-
deprecation(36394, 'the backslash operator has been deprecated; use A.solve_right(B) instead')
170-
return self.solve_right(B)
171-
172143
def subs(self, *args, **kwds):
173144
"""
174145
Substitute values to the variables in that matrix.
@@ -7347,14 +7318,14 @@ cdef class Matrix(Matrix1):
73477318

73487319
OUTPUT:
73497320

7350-
Returns a list of tuples of the form ``(e,V,n)``,
7351-
each tuple corresponds to a distinct eigenvalue,
7321+
A list of tuples of the form ``(e,V,n)``.
7322+
Each tuple corresponds to a distinct eigenvalue,
73527323
where ``e`` is the eigenvalue, ``V`` is a list of eigenvectors forming a
73537324
basis for the corresponding left eigenspace, and ``n`` is the algebraic
73547325
multiplicity of the eigenvalue.
73557326

7356-
If the option ``extend`` is set to ``False``, then only the eigenvalues that
7357-
live in the base ring are considered.
7327+
If the option ``extend`` is set to ``False``, then only the
7328+
eigenvalues that live in the base ring are considered.
73587329

73597330
EXAMPLES:
73607331

@@ -7396,13 +7367,6 @@ cdef class Matrix(Matrix1):
73967367
NotImplementedError: generalized eigenvector decomposition is
73977368
implemented for RDF and CDF, but not for Rational Field
73987369

7399-
Check the deprecation::
7400-
7401-
sage: matrix(QQ, [[1, 2], [3, 4]]).eigenvectors_left(False) # needs sage.rings.number_field
7402-
doctest:...: DeprecationWarning: "extend" should be used as keyword argument
7403-
See https://github.com/sagemath/sage/issues/29243 for details.
7404-
[]
7405-
74067370
Check :issue:`30518`::
74077371

74087372
sage: # needs sage.rings.number_field
@@ -7426,29 +7390,23 @@ cdef class Matrix(Matrix1):
74267390
[]
74277391
"""
74287392
if other is not None:
7429-
if isinstance(other, bool):
7430-
# for backward compatibility
7431-
from sage.misc.superseded import deprecation
7432-
deprecation(29243,
7433-
'"extend" should be used as keyword argument')
7434-
extend = other
7435-
other = None
7436-
else:
7437-
raise NotImplementedError('generalized eigenvector '
7438-
'decomposition is implemented '
7439-
'for RDF and CDF, but not for %s'
7440-
% self.base_ring())
7393+
raise NotImplementedError('generalized eigenvector '
7394+
'decomposition is implemented '
7395+
'for RDF and CDF, but not for %s'
7396+
% self.base_ring())
74417397

74427398
if algorithm is None:
74437399
R = self.base_ring()
74447400
from sage.rings.abc import RealField, ComplexField
74457401
if isinstance(R, (RealField, ComplexField)):
74467402
return self._eigenvectors_left(
7447-
other, extend=extend, algorithm='flint', suppress_future_warning=True)
7403+
other, extend=extend, algorithm='flint',
7404+
suppress_future_warning=True)
74487405
else:
74497406
algorithm = 'sage'
74507407
return self._eigenvectors_left(
7451-
other, extend=extend, algorithm=algorithm, suppress_future_warning=False)
7408+
other, extend=extend, algorithm=algorithm,
7409+
suppress_future_warning=False)
74527410

74537411
def _eigenvectors_left(self, other=None, *, extend: bool, algorithm: str,
74547412
suppress_future_warning: bool) -> list:
@@ -15921,7 +15879,7 @@ cdef class Matrix(Matrix1):
1592115879
"""
1592215880
return self._is_positive_definite_or_semidefinite(True)
1592315881

15924-
def is_positive_definite(self, certificate=False):
15882+
def is_positive_definite(self):
1592515883
r"""
1592615884
Determine if a matrix is positive-definite.
1592715885

@@ -15944,9 +15902,6 @@ cdef class Matrix(Matrix1):
1594415902
INPUT:
1594515903

1594615904
- ``self`` -- a matrix
15947-
- ``certificate`` -- boolean (default: ``False``); return the
15948-
lower-triangular and diagonal parts of the :meth:`block_ldlt`
15949-
factorization when the matrix is positive-definite. Deprecated.
1595015905

1595115906
OUTPUT:
1595215907

@@ -15959,14 +15914,6 @@ cdef class Matrix(Matrix1):
1595915914
2. Be a subring of the real numbers, complex numbers,
1596015915
or symbolic ring.
1596115916

15962-
If ``certificate`` is ``True``, a triplet ``(b, L, d)`` will
15963-
be returned instead, with ``b`` containing the result (true or
15964-
false). If the matrix is positive-definite, then ``L`` and
15965-
``d`` will contain the lower-triangular and diagonal parts of
15966-
the :meth:`block_ldlt` factorization, respectively. Or if the
15967-
matrix is not positive-definite (that is, if ``b`` is
15968-
``False``), then both ``L`` and ``d`` will be ``None``.
15969-
1597015917
.. SEEALSO::
1597115918

1597215919
:meth:`block_ldlt`, :meth:`~.Matrix.is_hermitian`,
@@ -16099,22 +16046,7 @@ cdef class Matrix(Matrix1):
1609916046
sage: matrix.identity(SR,4).is_positive_definite() # needs sage.symbolic
1610016047
True
1610116048
"""
16102-
result = self._is_positive_definite_or_semidefinite(False)
16103-
if certificate:
16104-
from sage.misc.superseded import deprecation
16105-
msg = "the 'certificate' argument is deprecated; if you "
16106-
msg += "need the corresponding factorization, you can "
16107-
msg += "simply compute it yourself (the results are cached)"
16108-
deprecation(31619, msg)
16109-
L = None
16110-
d = None
16111-
if result:
16112-
from sage.modules.free_module_element import vector
16113-
_, L, D = self.block_ldlt()
16114-
d = vector(D.base_ring(), D.diagonal())
16115-
return (result, L, d)
16116-
else:
16117-
return result
16049+
return self._is_positive_definite_or_semidefinite(False)
1611816050

1611916051
def principal_square_root(self, check_positivity=True):
1612016052
r"""

src/sage/misc/all.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
from sage.misc.all__sagemath_environment import *
66
from sage.misc.all__sagemath_repl import *
77

8-
from sage.misc.misc import (BackslashOperator,
9-
exists, forall, is_iterator,
10-
random_sublist,
11-
pad_zeros,
12-
newton_method_sizes, compose,
13-
nest)
8+
from sage.misc.misc import (
9+
exists, forall, is_iterator, random_sublist, pad_zeros,
10+
newton_method_sizes, compose, nest
11+
)
1412

1513
from sage.misc.banner import version
1614

src/sage/misc/misc.py

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -361,95 +361,9 @@ def nest(f, n, x):
361361

362362

363363
#################################################################
364-
# The A \ b operator
364+
# The A \ b operator has been removed after issue #36394
365365
#################################################################
366366

367-
368-
class BackslashOperator:
369-
r"""
370-
Implement Matlab-style backslash operator for solving systems::
371-
372-
A \ b
373-
374-
The preparser converts this to multiplications using
375-
``BackslashOperator()``.
376-
377-
EXAMPLES::
378-
379-
sage: preparse("A \\ matrix(QQ,2,1,[1/3,'2/3'])")
380-
"A * BackslashOperator() * matrix(QQ,Integer(2),Integer(1),[Integer(1)/Integer(3),'2/3'])"
381-
sage: preparse("A \\ matrix(QQ,2,1,[1/3,2*3])")
382-
'A * BackslashOperator() * matrix(QQ,Integer(2),Integer(1),[Integer(1)/Integer(3),Integer(2)*Integer(3)])'
383-
sage: preparse("A \\ B + C")
384-
'A * BackslashOperator() * B + C'
385-
sage: preparse("A \\ eval('C+D')")
386-
"A * BackslashOperator() * eval('C+D')"
387-
sage: preparse("A \\ x / 5")
388-
'A * BackslashOperator() * x / Integer(5)'
389-
sage: preparse("A^3 \\ b")
390-
'A**Integer(3) * BackslashOperator() * b'
391-
"""
392-
393-
def __rmul__(self, left):
394-
"""
395-
EXAMPLES::
396-
397-
sage: # needs sage.modules
398-
sage: A = random_matrix(ZZ, 4)
399-
sage: while A.rank() != 4:
400-
....: A = random_matrix(ZZ, 4)
401-
sage: B = random_matrix(ZZ, 4)
402-
sage: temp = A * BackslashOperator()
403-
doctest:...:
404-
DeprecationWarning: the backslash operator has been deprecated
405-
See https://github.com/sagemath/sage/issues/36394 for details.
406-
sage: temp.left is A
407-
True
408-
sage: X = temp * B
409-
doctest:...:
410-
DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
411-
See https://github.com/sagemath/sage/issues/36394 for details.
412-
sage: A * X == B
413-
True
414-
"""
415-
from sage.misc.superseded import deprecation
416-
417-
deprecation(36394, 'the backslash operator has been deprecated')
418-
self.left = left
419-
return self
420-
421-
def __mul__(self, right):
422-
r"""
423-
EXAMPLES::
424-
425-
sage: # needs scipy sage.modules
426-
sage: A = matrix(RDF, 5, 5, 2)
427-
sage: b = vector(RDF, 5, range(5))
428-
sage: v = A \ b
429-
doctest:...:
430-
DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
431-
See https://github.com/sagemath/sage/issues/36394 for details.
432-
sage: v.zero_at(1e-19) # On at least one platform, we get a "negative zero"
433-
(0.0, 0.5, 1.0, 1.5, 2.0)
434-
sage: v = A._backslash_(b)
435-
doctest:...:
436-
DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
437-
See https://github.com/sagemath/sage/issues/36394 for details.
438-
sage: v.zero_at(1e-19)
439-
(0.0, 0.5, 1.0, 1.5, 2.0)
440-
sage: v = A * BackslashOperator() * b
441-
doctest:...:
442-
DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
443-
See https://github.com/sagemath/sage/issues/36394 for details.
444-
sage: v.zero_at(1e-19)
445-
(0.0, 0.5, 1.0, 1.5, 2.0)
446-
"""
447-
from sage.misc.superseded import deprecation
448-
449-
deprecation(36394, 'the backslash operator has been deprecated')
450-
return self.left._backslash_(right)
451-
452-
453367
#################################################################
454368
# is_iterator function
455369
#################################################################
@@ -495,7 +409,7 @@ def is_iterator(it) -> bool:
495409
sage: is_iterator(iter(P)) # needs sage.combinat
496410
True
497411
"""
498-
# see trac #7398 for a discussion
412+
# see issue #7398 for a discussion
499413
try:
500414
return it is iter(it)
501415
except Exception:
@@ -538,7 +452,7 @@ def random_sublist(X, s):
538452
return [a for a in X if random.random() <= s]
539453

540454

541-
def is_sublist(X, Y):
455+
def is_sublist(X, Y) -> bool:
542456
"""
543457
Test whether ``X`` is a sublist of ``Y``.
544458

src/sage/repl/preparse.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,11 +1737,11 @@ def preparse(line, reset=True, do_time=False, ignore_prompts=False,
17371737
8
17381738
17391739
sage: preparse("A \\ B")
1740-
'A * BackslashOperator() * B'
1740+
'A \\ B'
17411741
sage: preparse("A^2 \\ B + C")
1742-
'A**Integer(2) * BackslashOperator() * B + C'
1742+
'A**Integer(2) \\ B + C'
17431743
sage: preparse("a \\ b \\") # There is really only one backslash here, it is just being escaped.
1744-
'a * BackslashOperator() * b \\'
1744+
'a \\ b \\'
17451745
17461746
sage: preparse("time R.<x> = ZZ[]", do_time=True)
17471747
'__time__ = cputime(); __wall__ = walltime(); R = ZZ[\'x\']; print("Time: CPU {:.2f} s, Wall: {:.2f} s".format(cputime(__time__), walltime(__wall__))); (x,) = R._first_ngens(1)'
@@ -1853,9 +1853,6 @@ def preparse(line, reset=True, do_time=False, ignore_prompts=False,
18531853
# f(x,y) = x^3 - sin(y)
18541854
L = preparse_calculus(L)
18551855

1856-
# Backslash
1857-
L = re.sub(r'''\\\s*([^\t ;#])''', r' * BackslashOperator() * \1', L)
1858-
18591856
if do_time:
18601857
# Time keyword
18611858
L = re.sub(r';time;(\s*)(\S[^;\n]*)',

src/sage/tests/books/computational-mathematics-with-sagemath/linalg_doctest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,6 @@
284284
[ (3*x^2 + 4*x + 3)/(x^3 + 4*x^2 + 4*x)]
285285
[ 0]
286286
287-
Sage example in ./linalg.tex, line 1855::
288-
289-
sage: A.solve_right(b) == A\b
290-
doctest:...: DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
291-
See https://github.com/sagemath/sage/issues/36394 for details.
292-
True
293-
294287
Sage example in ./linalg.tex, line 1910::
295288
296289
sage: a = matrix(QQ,3,5,[2,2,-1,-2,-1,2,-1,1,2,-1/2,2,-2,-1,2,-1/2])

src/sage/tests/books/computational-mathematics-with-sagemath/linsolve_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
....: A = matrix(QQ, [[1/(i+j-1) for j in [1..n]] for i in [1..n]])
2121
....: y = A*x
2222
....: A[n-1,n-1] = (1/(2*n-1))*(1+1/(10^5)) # modifies the matrix
23-
....: s = A\y
23+
....: s = A.solve_right(y)
2424
....: return max(abs(float(s[i]-x[i])) for i in range(0,n))
2525
2626
Sage example in ./linsolve.tex, line 396::

0 commit comments

Comments
 (0)