# Why does MATLAB have left division/solve?

In MATLAB (and Octave), the \ (or mldivide) and \. operators are provided with the exact same functionality as / (or mrdivide) and /., except their arguments are commuted.

I'm looking for any background to this unusual design.

• There are other languages supporting rdiv and rsub; it's not just Matlab. Commented Jul 21, 2023 at 10:56
• I may have been thinking of processor instructions (or virtual processor bytecode); no references come to mind. Python allows objects to implement reverse-division and reverse-subtraction protocols - but that's invoked by the ordinary (forward) operators when the first operand isn't suited, so not the same thing. Commented Jul 21, 2023 at 14:12
• \. or .\? Commented Jul 22, 2023 at 9:33
• If you want to know why Python does not have that operator, you can read PEP 211. TL;DR: they were afraid users would mix up b \ A and A \ b. Commented Jul 24, 2023 at 13:06
• Besides linear algebra, this kind of thing makes sense in any non-commutative residuated lattice. The left residual of division on the right, B / A, is like an implication AB: informally it’s the least you can pair with A to get up to B, without going above B. The right residual of left division, A \ B, is like a difference BA, or the most you can remove from B without going below A. Commented Jul 24, 2023 at 19:14

# Non-commutativity of multiplication

a/b calculates $$a \cdot b^{-1}$$, whereas b\a calculates $$b^{-1} \cdot a$$. Since matrix multiplication is not commutative, those are different operations.

• Correct, and since systems of linear equations are usually presented like $Ax=b$, then solving by computing $x=A^{-1}b$ is actually the standard operation, so \ makes sense in that context. Commented Jul 22, 2023 at 10:30
• @ChrisHaug I thought the standard operation was Gaussian elimination Commented Jul 22, 2023 at 10:31
• @RodrigodeAzevedo Gaussian elimination is a specific algorithm for finding 𝐴⁻¹ 𝑏. Commented Jul 22, 2023 at 10:59
• @RodrigodeAzevedo I didn't say anything specific about how it's computed (in particular, I did not say that you first compute the inverse, and then the product). Symbolically, yes, the standard problem is to compute $A^{-1}b$, as opposed to something like $bA^{-1}$, which is what you would use / for. Commented Jul 22, 2023 at 15:15
• @RodrigodeAzevedo Matlab needs to handle a number of cases including overdetermined, underdetermined, Hessenberg (almost-triangular), and sparse systems, and as a result the operator automatically selects from a number of algorithms. The textbook Gaussian elimination, a.k.a. LU, is used when favorable. Commented Jul 23, 2023 at 17:37

## Solving linear systems is better than inverting

The main reason is the one in xigoi's answer, noncommutativity, but let me add that a separate operator is handy to have for matrix operations: computing the matrix K = inverse(A) and then multiplying x = K * b is inferior from the point of view of both stability and computational cost. So considering A \ b as a single operation with two operands is more effective than thinking about it as "first invert $A$, then multiply by $b$".

## Proxy object

An alternative design choice that solves the same problem and has some advantages is having a method K = factorize(A) which computes an LU factorization (or another more convenient factorization) of the matrix $A$, and returns an "inverse-like" object K for which a method K * b is defined. This choice is very convenient because it allows one to separate and reuse the most expensive part of linear system solution, which is the $O(n^3)$ factorization. So you can write the clearer and more efficient

K = factorize(A); % 2/3*n^3 + O(n^2) for a general nxn matrix A
x1 = K * b1;  % O(n^2) if b1 is a length-n vector
x2 = K * b2;  % O(n^2) if b2 is a length-n vector


rather than

x1 = A \ b1;  % 2/3*n^3 + O(n^2)
x2 = A \ b2;  % 2/3*n^3 + O(n^2)
% total cost 4/3*n^3: the factorization is computed twice.
% Also, with this syntax the factorization cannot be precomputed
% before knowing b1, b2


or

K = inv(A);  % 2*n^3 + O(n^2)
x1 = K * b1; % O(n^2)
x2 = K * b2; % O(n^2)
% x1, x2 computed in this way typically have a higher
% numerical error than A \ b, in floating point.


This "implicit inverse" trick is implemented in Matlab's decomposition, and (with more generality and more methods defined) in Julia's factorize.

In a new language. I can see arguments for going even further and calling this function inverse(A), making it the preferred syntax to perform matrix inversion and linear system solution.

I'm not familiar with MATLAB/Octave, but this could be used for operator overloading in custom classes (if that's supported in MATLAB/Octave).

## Simplifying syntax

If you have something like x = y/x, this could be shortened to x \= y with a left division operator. This might not come up much, but it's still useful to have.

• MatLab does indeed support overloading, and yes, / and \ can be overloaded separately.
• No your answer is totally wrong. I haven't downvoted because I believe in commenting first and giving people a chance to improve or remove their answers first. The answer has nothing to do with custom classes nor simplifying expressions. The \= in your answer has nothing to do with ldivide. Also, if it's just a guess, why not write a comment rather than an answer? Commented Jul 22, 2023 at 11:23