# Possible Bug in LinearSolveFunction with Sparse Vectors

Bug introduced in 5.0 and fixed in 11.0
LinearSolveFunction is new in 5.0

Consider the following set of equations and corresponding variables:

eqns1 ={2 x == 2 - 4 y, 3 y == 4 z, 2 z + 4 t == 3, 3 t + 2 z == 5};
vars = {x, y, z, t};


We can use CoefficientArrays to get the array of coefficient of the variables, and use that to solve the set of equations:

{v1, m1} = CoefficientArrays[eqns1, vars];
LinearSolve[m1][-v1] (* This creates a LinearSolveFunction then applies it to -v1 *)


$\{-\frac{41}{3}, \frac{22}{3}, \frac{11}{2}, -2\}$

Now we make the set of equations symbolic and repeat the process:

eqns2 = {b x == 2 - c y, a y == c z, b z + c t == 3, a t + b z == 5};
{v2, m2} = CoefficientArrays[eqns2, vars];


Now we solve the equations:

LinearSolve[m2][-v2]


And Mathematica just crashes as if you typed Quit[].

Note that LinearSolveFunction is the culprit because you can still get the answer without crashing Mathematica by just using regular LinearSolve (without first creating a LinearSolveFunction) as follows:

LinearSolve[m2, -v2]


$\{\frac{2 a^2 b - 2 a b c - 3 a c^2 + 5 c^3}{a b^2 (a - c)}, \frac{ 3 a c - 5 c^2}{a b (a - c)}, \frac{3 a - 5 c}{b (a - c)}, \frac{2}{a - c}\}$

Also, note that if we pass the vector as a List, it also works fine

ls = LinearSolve[m2]; (* create a LinearSolveFunction *)
ls[{2, 0, 3, 5}] // ExpandAll // Together


Can anyone reproduce this? I get the same behavior on both Mathematica 10.3.1 and 10.4. OS is Windows 10 64-bit.

• I can reproduce the crash on 10.4. A workaround is to apply Normal[] to v2. The simpler LinearSolve[m2][SparseArray[1 -> 1, 4]] also crashes, so I'm inclined to think that the LinearSolveFunction[] chokes on sparse vectors for some reason. – J. M. is away Apr 10 '16 at 23:21
• @J.M., yeah I know Normal works which is why I stated that just using a normal List doesn't crash Mathematica. About Sparse vectors, that was my initial title, maybe I should include that back. – RunnyKine Apr 10 '16 at 23:27
• Also reproduces in v8.0.4 and v9.0.1, win10 64bit. – xzczd Apr 11 '16 at 2:31
• Just checked in 5.2; LinearSolveFunction[] chokes on sparse vectors in that version as well. Clearly an old problem. Even the (now deprecated and undocumented) function LUBackSubstitution[] chokes if given a sparse vector. – J. M. is away Apr 11 '16 at 15:01
• Bug report filed, thanks! – ilian Apr 11 '16 at 15:23

eqns2 = {b x == 2 - c y, a y == c z, b z + c t == 3, a t + b z == 5};