# Bug in SmithDecomposition?

While trying to calculate the SmithDecomposition of an integer 293x329 matrix with less than 3000 non-zero elements in the range -4 to 3 several errors occur, none of them which seem to make any sense at all:

In[254]:= SmithDecomposition[tmat]

During evaluation of In[254]:= Part::partw: Part 296 of {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,<<245>>} does not exist.

During evaluation of In[254]:= Drop::drop: Cannot drop positions 1 through 296 in {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,<<245>>}.

During evaluation of In[254]:= Part::partw: Part 297 of {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,<<245>>} does not exist.

During evaluation of In[254]:= Part::partw: Part 298 of {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,<<245>>} does not exist.

During evaluation of In[254]:= General::stop: Further output of Part::partw will be suppressed during this calculation.

During evaluation of In[254]:= HermiteDecomposition::latm: Matrix contains an entry that is not rational.

During evaluation of In[254]:= Set::shape: Lists {SystemSmithDecompositionDumptmpu$$84833,SystemSmithDecompositionDumphnf$$84833} and HermiteDecomposition[{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<279>>},{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<279>>},{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<279>>},<<46>>,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,<<279>>},<<2546>>}] are not the same shape.

During evaluation of In[254]:= HermiteDecomposition::latm: Matrix contains an entry that is not rational.

During evaluation of In[254]:= Set::shape: Lists {SystemSmithDecompositionDumptmpv$$84833,SystemSmithDecompositionDumphnf$$84833} and HermiteDecomposition[{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},<<46>>,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,<<2546>>},<<279>>}] are not the same shape.

During evaluation of In[254]:= HermiteDecomposition::latm: Matrix contains an entry that is not rational.

During evaluation of In[254]:= General::stop: Further output of HermiteDecomposition::latm will be suppressed during this calculation.

During evaluation of In[254]:= Set::shape: Lists {SystemSmithDecompositionDumptmpu$$84833,SystemSmithDecompositionDumphnf$$84833} and HermiteDecomposition[{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<2546>>},<<46>>,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,<<2546>>},<<279>>}] are not the same shape.

During evaluation of In[254]:= General::stop: Further output of Set::shape will be suppressed during this calculation.

Out[254]= \$Aborted


I checked that all elements of the matrix are integers and interestingly the HermiteDecomposition does work. Trying to calculate the SmithDecomposition of the Hermite upper diagonal form results in the same error though.

Does anybody know what is going on?

The matrix in compressed form (use Uncompress to get the actual matrix) is the following

"1:eJztXcnO5LYRHi+XwE+RS24BWtRGHX00kFPyBE6QAeYQOJhxDnkXP2y6xarB/3d/\
bPFjiWxKzqXF1kLWzmJxqT/+/Ze/fvz+w4cPX364/vzt3z9//vLPHz9//vm/X/5w/f/\
jf3795V8///rpHx+/vb1ye+8vn778+tN314Jb+vXau+XT9fLh43dvX/n0ze3Wu68+/\
umbt3XcXrisv93663+6vd3168VdwkX+Deul78JlCpd5vQzhzWFcL6MLF/\
kX3pzCd1P4N4d/c3hzDrX48M/LvwCLX9bLMqx4dpdOrvp/DNfOyXUO1yvs4SrvOx+\
ufaBXN8jzQf6PUt8k9c1TuHr5L+07ac914blzoT3Xh/rd0MlVno9LuM7ynpf3lvC/\
7wIcfR++64fwfj8GfPpJrnNov/fC7yXUP1xCPYPAM0g9g+A1SD3DOMpV3p/lPR/+\
j0LP0YX3x17uy/fjFOofBY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QHtUMhi4f+zhjKmHN2eACkkVgy6jak7FaTh/\
GG6Esp8v6SSKYVtSJmpl1Q6QAZYhhfseRpnvR+\
hPW2e1oSko0ajdcOUgZG3gmBDninabflOJtNsYZakYk3qHQ6yVqPVMrfVsd8EmxL7iX6TV\
QywyJQcqYt/HIETDkSSiAs4pU5/\
H6Cup88no8cyp4ajW3BXSnJ4kWNlU54qK9STzGYqeJT455eK7pyVNcacDyYrPbnqLnoO28\
jShGrrz1fmaxSm3OqDVZmGQBmm+\
xkpQmg173W3s2bEQ2TIw5ePs8ddlLmoRn7HmBtOM33YAPdw/\
uGJpjrHkKWVFdWXPdOVqyJVj5diutMep5Ri2J+mPFPLt+K/\
5pnxjf3VT7iA1M2beWaNlSlOap7uzTTqJWpVGFI8SGmU01ErwxZmQvn2Q7GYps1ieLf77d\
41Aw1J0hq49dFNc5gcUnibXJZXvVRbbs7SSanEnkmZS8ZTwKz86bzp+/u/fXLcIRrfV/\
RR/rPg=="


# Update

According to the customer service the bug should be resolved in the current release of version 12.0 (and was already resolved for 12.1):

Hello Gert Vercleyen,

In September 2019 you reported an issue with Mathematica wherein SmithDecomposition problem with rank deficient case. We believe that the issue has been resolved in the current 12.0 release of Mathematica.

Thank you for your report and we look forward to a continued, productive relationship with you.

• Hm. With the matrix that you posted in compressed form, I cannot reproduce the problem (running version 12). Jun 5, 2019 at 21:06
• Works here too... maybe try restarting kernel to rule out lingering definitions. Jun 5, 2019 at 23:21

You have run into a bug in SmithDecomposition, but the example you've posted doesn't trigger it.

First, the bug. It only occurs in very rare corner cases, so much so that if you sit there and feed random matrices to SmithDecomposition you'll never see it fail. This presumably explains how it got through testing. The effect of the bug is that SmithDecomposition prints the error messages you described, then hangs indefinitely in a busy loop.

Your example matrix however works fine for me, so I'm guessing you pasted the wrong one or it got corrupted somehow. The simplest matrix I know of which triggers the bug is the following, which is a 12x12 integer matrix:

"1:eJxTTMoPSuNhYGAoZgESPpnFJai8zP9AkAnkMGAl8MqimQQWFwYRIPHMDyCtAiAWB1y\
X\\
NIj4AjcTrO4HkIvNJBuQshIQMRXEZQGxguFaz/\\
wDspJArPsgMSEQkY3DTUogghdE3AYpYwOxPsFN0gIRT0HcjyAC7DpcbtoH1JZ5E+\\
izzFygRGbObyDL5wfMpG9AAzLbgNoyk74BWdY/\\
gcRsZuxuEgIRCiBiI8jCQhArBx5OfiDiCUjiJYiYCOIewXQTlePuMEjDLhABthocMG5wXa\
\\
ogwgJEXIOr24UjnE4AnZ358DmQMAaFzgs+\\
oNhFCZhJFsC4yIwEhkBmPig8U0DqeJ9hN0lwMTdDZubhlf8zOw6H/8+\\
MjxFhyPz4UpkBSXbtpk6GzAXLu4AxI332f6armB5W38U6rfif+\\
eBSGNA4q7MMmVLpCf8ze7V+/IPI7k32/p/5oTzlf2Ylrz5j5q11X/9nxi6xwWrSk/LpQN+\
\\
ZRTJkzmicxpC588nv/5nP5B2gblJaFcuQ+Vpk8v/MKzzVQIOt3v/PbPk19z8AJZFAWg=="


I reported this bug almost a year ago, and the developers responded fairly quickly. However, it doesn't look like it will actually be fixed until next release. If you really need this function to work properly, then this answer lists some possible replacements. Alternatively, here's a hacky workaround:

SmithDecomposition[{{0}}];
Unprotect[SmithDecomposition];
Clear[SmithDecomposition];
SmithDecomposition[mat_] :=
Module[{uu, dd, vv, diags, col = 0, tmpu, tmpv, ord},
{uu, dd, vv} = SystemSmithDecompositionDumpdiagonalize[mat];
diags = Select[Diagonal[dd], # != 0 &];
While[col + 1 < Length[diags],
col++;
If[SystemSmithDecompositionDumpdivides[diags[[col]],
GCD[Sequence @@ Drop[diags, col]]], Continue[]];
vv = Transpose[vv];
Do[
dd[[j, col]] = diags[[j]];
vv[[col]] += vv[[j]]
, {j, col + 1, Length[diags]}
];
vv = Transpose[vv];
{tmpu, dd, tmpv} = SystemSmithDecompositionDumpdiagonalize[dd];
uu = tmpu.uu;
vv = vv.tmpv;
diags = Select[Diagonal[dd], # != 0 &];
];
ord = OrderingBy[Diagonal[dd], # /. (0 -> Infinity) &];
If[! OrderedQ[ord], {uu, dd, vv} = {uu[[ord]], DiagonalMatrix[Diagonal[dd][[ord]]], vv[[;; , ord]]}];
{uu, dd, vv}
]
Protect[SmithDecomposition];


This is the internal code, extracted with this method, and empirically and badly tweaked to make it work.

• I have reported the bug as well and there's a big chance it will be fixed by next release. The matrix I posted triggered it on my computer at that time but meanwhile I have found many other examples that trigger it. It seems that most of the cases for which I needed it (e.g. finding cocycles of groups) consisted matrices of which the decomposition is very hard compared to the general case...
– Gert
Feb 22, 2020 at 15:29
• I'm not sure exactly when it was fixed, but it's working now in 12.1.
– PBS
Dec 31, 2020 at 16:05