Skip to content

Commit

Permalink
Deprecate the backslash operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpalmieri committed Sep 28, 2023
1 parent b8c4c03 commit 54214b8
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 139 deletions.
10 changes: 0 additions & 10 deletions src/doc/de/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ gelöst werden. Das Auswerten von ``A.solve_right(Y)`` gibt eine Matrix
sage: A * X # wir überprüfen unsere Antwort...
(0, -4, -1)

Anstelle von ``solve_right`` kann auch ein Backslash ``\`` verwendet
werden. Benutzen Sie ``A \ Y`` anstelle von ``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

Falls keine Lösung existiert, gibt Sage einen Fehler zurück:

.. skip
Expand Down
10 changes: 0 additions & 10 deletions src/doc/en/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ Evaluating ``A.solve_right(Y)`` returns a matrix (or vector)
sage: A * X # checking our answer...
(0, -4, -1)

A backslash ``\`` can be used in the place of ``solve_right``; use
``A \ Y`` instead of ``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

If there is no solution, Sage returns an error:

.. skip
Expand Down
10 changes: 0 additions & 10 deletions src/doc/es/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ Resolver ecuaciones matriciales es sencillo, usando el método
sage: A * X # comprobando la solución...
(0, -4, -1)

Se puede usar una barra invertida ``\`` en lugar de ``solve_right``;
usamos ``A \ Y`` en lugar de ``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

Si no hay solución, Sage lanza un error:

.. skip
Expand Down
11 changes: 0 additions & 11 deletions src/doc/fr/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ une matrice (ou un vecteur) :math:`X` tel que :math:`AX=Y`:
sage: A * X # vérifions la réponse...
(0, -4, -1)

Un antislash (contre-oblique) ``\`` peut être employé à la place de
``solve_right`` : il suffit d'écrire ``A \ Y`` au lieu de
``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

S'il n'y a aucune solution, Sage renvoie une erreur :

.. skip
Expand Down
12 changes: 0 additions & 12 deletions src/doc/ja/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ Sageでは,行列 :math:`A` の核空間は「左」核空間,すなわち :
(0, -4, -1)


``solve_right`` の代わりにバックスラッシュ ``\`` を使うこともできる.
つまり ``A.solve_right(Y)`` ではなく ``A \ Y`` と書くわけである.

.. link
::

sage: A \ Y
(-2, 1, 0)



解がない場合は,Sageはエラーを返してくる:

.. skip
Expand Down
10 changes: 0 additions & 10 deletions src/doc/pt/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ Calculando ``A.solve_right(Y)`` obtém-se uma matrix (ou vetor)
sage: A * X # checking our answer...
(0, -4, -1)

Uma barra invertida ``\`` pode ser usada no lugar de ``solve_right``;
use ``A \ Y`` no lugar de ``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

Se não existir solução, o Sage retorna um erro:

.. skip
Expand Down
9 changes: 0 additions & 9 deletions src/doc/ru/tutorial/tour_linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ Sage поддерживает стандартные конструкции из
sage: A * X # проверка...
(0, -4, -1)

``\`` может быть использован вместо ``solve_right``; используйте
``A \ Y`` вместо ``A.solve_right(Y)``.

.. link
::

sage: A \ Y
(-2, 1, 0)

Если решения не существует, то Sage вернет ошибку:

Expand Down
5 changes: 3 additions & 2 deletions src/sage/combinat/binary_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.family import Family
from sage.misc.cachefunc import cached_method
from sage.misc.superseded import deprecated_function_alias


class BinaryTree(AbstractClonableTree, ClonableArray,
Expand Down Expand Up @@ -3214,7 +3215,7 @@ def under(self, bt):
sage: b1 = BinaryTree([[],[]])
sage: b2 = BinaryTree([None,[]])
sage: ascii_art((b1, b2, b1 \ b2))
sage: ascii_art((b1, b2, b1.under(b2)))
( o , o , _o_ )
( / \ \ / \ )
( o o o o o )
Expand Down Expand Up @@ -3276,7 +3277,7 @@ def under(self, bt):
else:
return B([self.under(bt[0]), bt[1]])

_backslash_ = under
_backslash_ = deprecated_function_alias(80000, under)

def under_decomposition(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/features/sagemath.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class sage__graphs(JoinFeature):
sage: M = Matroid(Matrix(QQ, [[1, 0, 0, 0, 1, 1, 1],
....: [0, 1, 0, 1, 0, 1, 1],
....: [0, 0, 1, 1, 1, 0, 1]]))
sage: N = M / [2] \ [3, 4]
sage: N = (M / [2]).delete([3, 4])
sage: sorted(N.groundset())
[0, 1, 5, 6]
Expand Down
35 changes: 21 additions & 14 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ from sage.matrix.matrix_misc import permanental_minor_polynomial
from sage.misc.misc_c import prod

# used to deprecate only adjoint method
from sage.misc.superseded import deprecated_function_alias
from sage.misc.superseded import deprecation, deprecated_function_alias


# temporary hack to silence the warnings from #34806
Expand Down Expand Up @@ -146,21 +146,28 @@ cdef class Matrix(Matrix1):
Used to compute `A \backslash B`, i.e., the backslash solver
operator.

DEPRECATED

EXAMPLES::

sage: A = matrix(QQ, 3, [1,2,4,2,3,1,0,1,2])
sage: B = matrix(QQ, 3, 2, [1,7,5, 2,1,3])
sage: C = A._backslash_(B); C
doctest:...: DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
See https://github.com/sagemath/sage/issues/80000 for details.
[ -1 1]
[13/5 -3/5]
[-4/5 9/5]
sage: A*C == B
True
sage: A._backslash_(B) == A \ B
doctest:...: DeprecationWarning: the backslash operator has been deprecated; use A.solve_right(B) instead
See https://github.com/sagemath/sage/issues/80000 for details.
True
sage: A._backslash_(B) == A.solve_right(B)
True
"""
deprecation(80000, 'the backslash operator has been deprecated; use A.solve_right(B) instead')
return self.solve_right(B)

def subs(self, *args, **kwds):
Expand Down Expand Up @@ -462,7 +469,7 @@ cdef class Matrix(Matrix1):

.. NOTE::

In Sage one can also write ``A \ B`` for
DEPRECATED. In Sage one can also write ``A \ B`` for
``A.solve_right(B)``, that is, Sage implements "the
MATLAB/Octave backslash operator".

Expand Down Expand Up @@ -506,7 +513,7 @@ cdef class Matrix(Matrix1):

sage: A = matrix(QQ, 3, [1,2,3,-1,2,5,2,3,1])
sage: b = vector(QQ,[1,2,3])
sage: x = A \ b; x
sage: x = A.solve_right(b); x
(-13/12, 23/12, -7/12)
sage: A * x
(1, 2, 3)
Expand All @@ -525,21 +532,21 @@ cdef class Matrix(Matrix1):
Another nonsingular example::

sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([-1/2,-1])
sage: x = A \ v; x
sage: x = A.solve_right(v); x
(-1/2, 0, 0)
sage: A*x == v
True

Same example but over `\ZZ`::

sage: A = matrix(ZZ,2,3, [1,2,3,2,4,6]); v = vector([-1,-2])
sage: A \ v
sage: A.solve_right(v)
(-1, 0, 0)

An example in which there is no solution::

sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([1,1])
sage: A \ v
sage: A.solve_right(v)
Traceback (most recent call last):
...
ValueError: matrix equation has no solutions
Expand All @@ -564,24 +571,24 @@ cdef class Matrix(Matrix1):
sage: A*X == B
True

We illustrate left associativity, etc., of the backslash operator.
We illustrate left associativity, etc., of the ``solve_right`` operator.

::

sage: A = matrix(QQ, 2, [1,2,3,4])
sage: A \ A
sage: A.solve_right(A)
[1 0]
[0 1]
sage: A \ A \ A
sage: (A.solve_right(A)).solve_right(A)
[1 2]
[3 4]
sage: A.parent()(1) \ A
sage: A.parent()(1).solve_right(A)
[1 2]
[3 4]
sage: A \ (A \ A)
sage: A.solve_right(A.solve_right(A))
[ -2 1]
[ 3/2 -1/2]
sage: X = A \ (A - 2); X
sage: X = A.solve_right(A - 2); X
[ 5 -2]
[-3 2]
sage: A * X
Expand All @@ -593,7 +600,7 @@ cdef class Matrix(Matrix1):
sage: x = polygen(QQ, 'x')
sage: A = matrix(2, [x,2*x,-5*x^2+1,3])
sage: v = vector([3,4*x - 2])
sage: X = A \ v
sage: X = A.solve_right(v)
sage: X
((-4/5*x^2 + 2/5*x + 9/10)/(x^3 + 1/10*x), (19/10*x^2 - 1/5*x - 3/10)/(x^3 + 1/10*x))
sage: A * X == v
Expand Down Expand Up @@ -635,7 +642,7 @@ cdef class Matrix(Matrix1):
[ 2 + O(5^4) 5 + O(5^5) 4 + O(5^4)]
[ 1 + O(5^4) 1 + O(5^4) 2 + O(5^4)]
sage: v = vector(k, 3, [1,2,3])
sage: x = a \ v; x
sage: x = a.solve_right(v); x
(4 + 5 + 5^2 + 3*5^3 + O(5^4), 2 + 5 + 3*5^2 + 5^3 + O(5^4), 1 + 5 + O(5^4))
sage: a * x == v
True
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matrix/matrix_complex_ball_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,14 @@ cdef class Matrix_complex_ball_dense(Matrix_dense):
r"""
TESTS::
sage: matrix(CBF, [[1/2, 1/3], [1, 1]]) \ vector([-1, 1])
sage: matrix(CBF, [[1/2, 1/3], [1, 1]]).solve_right(vector([-1, 1]))
([-8.00000000000000 +/- ...], [9.00000000000000 +/- ...])
sage: matrix(CBF, 2, 2, 0) \ vector([-1, 1])
sage: matrix(CBF, 2, 2, 0).solve_right(vector([-1, 1]))
Traceback (most recent call last):
...
ValueError: unable to invert this matrix
sage: b = CBF(0, RBF(0, rad=.1r))
sage: matrix(CBF, [[1, 1], [0, b]]) \ vector([-1, 1])
sage: matrix(CBF, [[1, 1], [0, b]]).solve_right(vector([-1, 1]))
Traceback (most recent call last):
...
ValueError: unable to invert this matrix
Expand Down
12 changes: 6 additions & 6 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4138,7 +4138,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
.. NOTE::
In Sage one can also write ``A \ B`` for
DEPRECATED. In Sage one can also write ``A \ B`` for
``A.solve_right(B)``, i.e., Sage implements the "the
MATLAB/Octave backslash operator".
Expand All @@ -4162,15 +4162,15 @@ cdef class Matrix_integer_dense(Matrix_dense):
sage: a = matrix(ZZ, 2, [0, -1, 1, 0])
sage: v = vector(ZZ, [2, 3])
sage: a \ v
sage: a.solve_right(v)
(3, -2)
Note that the output vector or matrix is always over
`\QQ`.
::
sage: parent(a\v)
sage: parent(a.solve_right(v))
Vector space of dimension 2 over Rational Field
We solve a bigger system where the answer is over the rationals.
Expand All @@ -4179,7 +4179,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
sage: a = matrix(ZZ, 3, 3, [1,2,3,4, 5, 6, 8, -2, 3])
sage: v = vector(ZZ, [1,2,3])
sage: w = a \ v; w
sage: w = a.solve_right(v); w
(2/15, -4/15, 7/15)
sage: parent(w)
Vector space of dimension 3 over Rational Field
Expand All @@ -4193,7 +4193,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
sage: a = matrix(ZZ, 3, 3, [1,2,3,4, 5, 6, 8, -2, 3])
sage: b = matrix(ZZ, 3, 2, [1,5, 2, -3, 3, 0])
sage: w = a \ b; w
sage: w = a.solve_right(b); w
[ 2/15 -19/5]
[-4/15 -27/5]
[ 7/15 98/15]
Expand All @@ -4214,7 +4214,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
sage: n = 100
sage: a = random_matrix(ZZ,n)
sage: v = vector(ZZ,n,range(n))
sage: x = a \ v
sage: x = a.solve_right(v)
sage: a * x == v
True
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matrix/matrix_integer_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
.. NOTE::
In Sage one can also write ``A \ B`` for
DEPRECATED. In Sage one can also write ``A \ B`` for
``A.solve_right(B)``, i.e., Sage implements the "the
MATLAB/Octave backslash operator".
Expand Down Expand Up @@ -1019,14 +1019,14 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
sage: A = matrix(ZZ, 3, [1,2,3,-1,2,5,2,3,1], sparse=True)
sage: b = vector(ZZ, [1,2,3])
sage: x = A \ b
sage: x = A.solve_right(b)
sage: x
(-13/12, 23/12, -7/12)
sage: A * x
(1, 2, 3)
sage: u = matrix(ZZ, 3, 2, [0,1,1,1,0,2])
sage: x = A \ u
sage: x = A.solve_right(u)
sage: x
[-7/12 -1/6]
[ 5/12 5/6]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_modn_dense_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ EXAMPLES::
sage: A.rank()
4
sage: v = vector(GF(127), 4, (100, 93, 47, 110))
sage: x = A\v
sage: x = A.solve_right(v)
sage: A*x == v
True
Expand Down
Loading

0 comments on commit 54214b8

Please sign in to comment.