Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #12406: solve_left and solve_right should use coercion
This ticket uses coercion to find suitable parents for the arguments to `Matrix.solve_right` in order to solve these problems: {{{ sage: A = matrix(QQ, 2, [1, 2 ,3, 4]) sage: b = vector(RDF, [pi, e]); b (3.14159265359, 2.71828182846) sage: A.solve_right(b) # should return (-3.564903478720541, 3.353248066155167) (-27594871646705519/7740706532848242, 17304339474632025/5160471021898828) sage: R.<x> = QQ[] sage: b = vector(R, [1, x]); b (1, x) sage: A.solve_right(b) # should return (t - 2, -1/2*t + 3/2) [ugly traceback] TypeError: not a constant polynomial }}} This is implemented by moving the coercion code from `Matrix_double_dense.solve_right`, that was implemented in #17405, to the super class. As a result, `Matrix_double_dense.solve_right` is redundant and therefore removed. The super method `Matrix.solve_right` is refactored a lot: - the `check` parameter is ignored for inexact rings (see also #13932) - the implementation is changed so that the rank of the matrix is not computed in `solve_right`, but only in `_solve_right_nonsingular_square`; this way, inexact rings overwriting the latter method can avoid computing the rank (which would not work over inexact rings) Additionally, this ticket adds support for calling `solve_right`/`solve_left` with non-square matrices over `RDF`/`CDF`. In such cases, `solve_right` returns the least-squares solution of the equation system, similar to the !Matlab/Octave backslash operator (which our documentation already claims is implemented). This is implemented using [https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg .lstsq.html scipy.linalg.lstsq]. {{{ sage: A = matrix(RDF, 3, 2, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6, 1]) sage: x = A.solve_right(b) sage: (A * x - b).norm() 3.2692119900020438 sage: x == A \ b True }}} URL: https://trac.sagemath.org/12406 Reported by: robertwb Ticket author(s): Markus Wageringel Reviewer(s): Michael Orlitzky
- Loading branch information