45

Bug introduced in 12.0 and fixed in 12.1


The following code calculates the eigenvalues of a certain complex matrix, which come in pairs of opposite complex numbers. Therefore one can check whether the sum of all eigenvalues is equal to the trace of the matrix, which is zero.

This is indeed the case in Version 10.1 & 11.3 as far as I tested. However, Version 12.0 (Windows, Mac, Linux) gives something seriously wrong.

NN = 374; R = 0.05;
t1 = -1 + Cos[x] - I Sin[x] + I R; t1p = -1 + Cos[x] + I Sin[x] + 
  I R;
mat[x_] = 
  DiagonalMatrix[Table[If[EvenQ[n], t1, -1], {n, 0, 2 NN - 1 - 1}], 
    1] + DiagonalMatrix[
    Table[If[EvenQ[n], t1p, -1], {n, 0, 2 NN - 1 - 1}], -1] + 
   DiagonalMatrix[Table[If[EvenQ[n], -1, 0], {n, 0, 2 NN - 1 - 3}], 
    3] + DiagonalMatrix[
    Table[If[EvenQ[n], -1, 0], {n, 0, 2 NN - 1 - 3}], -3];
mat0 = mat[-0.2 \[Pi]];
Tr@mat0  (* 0. *)
Total@Eigenvalues@mat0  (* 0.394003 - 0.566499 I *)

I would rather switch back to 11.3 for a while. This looks really dangerous...


Original post of a more complex matrix with the same issue:

The code plots the real part of adding each pair. So the correct plot should be just zeros everywhere. This is the case in Version 10.1 & 11.3 as far as I tested (scattered numbers around $10^{-14}$ or so). However, Version 12.0 (Windows, Mac, Linux) gives something different as shown below.

NN = 200; R = 0.05;
xlist = Table[x, {x, -0.2 \[Pi], 0.2 \[Pi], 0.01}];
modl[n_] := 2*^-3 (Quotient[n, 2] - NN/2);
t1 = -1 + Cos[x] - I Sin[x] + I R; t1p = -1 + Cos[x] + I Sin[x] + I R;
t2a[n_] := -1 - modl[n]; t2b[n_] := -1 + modl[n];
mat[x_] = 
  DiagonalMatrix[
    Table[If[EvenQ[n], t1, t2a[n]], {n, 0, 2 NN - 1 - 1}], 1] + 
   DiagonalMatrix[
    Table[If[EvenQ[n], t1p, t2a[n]], {n, 0, 2 NN - 1 - 1}], -1] + 
   DiagonalMatrix[
    Table[If[EvenQ[n], t2b[n], 0], {n, 0, 2 NN - 1 - 3}], 3] + 
   DiagonalMatrix[
    Table[If[EvenQ[n], t2b[n], 0], {n, 0, 2 NN - 1 - 3}], -3];
list0 = Sort@Re@Eigenvalues[mat[xlist[[3]]]];
list0p = Table[list0[[i]] + list0[[2 NN - i + 1]], {i, NN}];
ListPlot[Tooltip@list0p, PlotRange -> All]

enter image description here

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
xiaohuamao
  • 4,728
  • 18
  • 36
  • You should redo your calculation in a fresh kernel; your code produces a scatterplot of points with near-zero y coordinates in my case (around $10^{-14}$) in both versions 11.3 and 12.0. – ulvi May 18 '19 at 00:49
  • 1
    [tag:bugs]: "This tag is reserved for questions where the problem has been vetted by this community and the observed behavior is confirmed to be a bug. Please do not use this tag for new questions." – AccidentalFourierTransform May 18 '19 at 00:50
  • What is your operating system? – Carl Woll May 18 '19 at 01:05
  • @ulvi I even restarted the computer. – xiaohuamao May 18 '19 at 01:09
  • 14
    A simpler test is comparing Tr[matrix] with Total[Eigenvalues[matrix]] which shows a large discrepancy. I think this is worth reporting to support. It happens on OSX as well. – Carl Woll May 18 '19 at 01:14
  • 1
    @Carl Woll. Interesting: On my machine (Windows 10; version 12.0) Tr[matrix] gives 0. and Total[Eigenvalues[matrix]] gives -2.23821*10^-13 - 2.66454*10^-15 I. – ulvi May 18 '19 at 04:05
  • @CarlWoll no time to test before I post this questio—(clarification?) suggestion? Someone should try to see if this carries to Eigensystem, maybe some core piece that relates these two is broken? Otherwise we could get around it (for now) with just grabbing the first portion of Eigensystem[] output – CA Trevillian May 18 '19 at 07:08
  • @ulvi what versions did you have previously? Uninstalled them to install the newest version? I’ll respond with testing results in the morning. Hope someone has found the answer by then! – CA Trevillian May 18 '19 at 07:11
  • I see this problem in V12 on Linux – mikado May 18 '19 at 10:46
  • Eigensystem is broken too. – CA Trevillian May 19 '19 at 03:38
  • @ulvi what day did you download the new version? – CA Trevillian May 19 '19 at 19:45
  • 8
    Filing a report (apparently that has not been done to date). – Daniel Lichtblau Jun 10 '19 at 23:14
  • My $Version gives 12.0.0 for Microsoft Windows (64-bit) (April 6, 2019) – ulvi Jun 19 '19 at 20:29
  • I'm under MMA12 under Windows and I got -0.551716242833052 - 0.263815420085667 I for Total[Eigenvalues[mat0]] and I also got a different picture from the above, though it is wrong too – user58955 Jul 02 '19 at 10:45
  • @DanielLichtblau Any update following the bug report? – xiaohuamao Jul 28 '19 at 19:36
  • To assist with debugging: is the result of Tr[Last[SchurDecomposition[mat0, RealBlockDiagonalForm -> False]]] the same as the result of Tr[mat0], or with Total[Eigenvalues[mat0]]? – J. M.'s missing motivation Jul 29 '19 at 03:16
  • 1
    @xiaohuamao To my understanding, the problem is with the MKL library. It has been fixed in the development version (which uses a newer version of MKL). – ilian Jul 29 '19 at 14:04
  • @ilian by development you mean prerelease? – CA Trevillian Aug 01 '19 at 13:44
  • Not in general, but this issue is also fixed in the 12.1 prerelease builds – ilian Aug 01 '19 at 14:58
  • @ilian Is there any estimated release date of the newer version? – xiaohuamao Oct 13 '19 at 19:19

4 Answers4

32

Not a solution but too big for a comment. There seems to be a catastrophic failure in Eigenvalues happening that is not due to the matrix being crazy. As a diagnostic, let's calculate the smallest (by absolute value) eigenvalue of the upper-left $n\times n$ part of the matrix

M = mat[xlist[[3]]];

For odd $n$ the answer is zero, so let's only do this for even $n$. We do this in two ways

  1. Calculate all eigenvalues and pick the one with the smallest absolute value:
    e1[n_?EvenQ] := M[[;; n, ;; n]] // Eigenvalues // Abs // Min
  1. Calculate only the smallest eigenvalue (by absolute value) with the Arnoldi algorithm:
    e2[n_?EvenQ] := Eigenvalues[M[[;; n, ;; n]], 1, 
      Method -> {"Arnoldi", "Criteria" -> "Magnitude", "Shift" -> 0}] // First // Abs

Method (2) is very reliable, whereas method (1) breaks down for $n=358$ and above:

enter image description here

Considering that the Arnoldi algorithm has no problems with this matrix, there seems to be something really strange going on in method 1.

$Version
(* 12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019) *)
Roman
  • 47,322
  • 2
  • 55
  • 121
12

Edit: Eigensystem fixed in 12.1 in addition to Eigenvalues

I attempted a workaround, to see if Eigensystem had any issues also. It does. This is very unfortunate.

(Will we have to wait for 12.1 for the fix (?!))
(We waited for 12.1 for the fix (!!))

My code here:

e3[n_?EvenQ] := Eigensystem[M[[;; n, ;; n]]][[1]] // Abs // Min

Produces the following, which matches with @Roman shows:

Issue persisting for Eigensystem

(Apologies the colors/styles don't match with the plot from @Roman !!)

$Version
(* 12.0.0 for Microsoft Windows (64-bit) (April 6, 2019) *)
CA Trevillian
  • 3,342
  • 2
  • 8
  • 26
  • The generated eigenvectors aren't even really eigenvectors of the matrix, so the error is not just in the eigenvalues. – Roman May 19 '19 at 10:32
  • If I understand what you mean, this would be some fundamental (internal) issue with the eigensolver being used? Maybe some error in the linear decomposition being used? – CA Trevillian May 19 '19 at 17:48
  • Yes it looks like a serious foul in the default "Direct" diagonalizer. This is very surprising for something that's been around for such a long time (coded in LAPACK). – Roman May 19 '19 at 19:35
  • @Roman Perhaps we should have a chat room to discuss this, but the last stable release of LAPACK was in September of 2017? So either there is some issue with the implementation within this version of mma or we have the same issues as we downloaded 12.0 on adjacent days, very near release. – CA Trevillian May 19 '19 at 19:47
  • Let's let WR debug this one for themselves. Maybe they aren't using LAPACK. – Roman May 19 '19 at 20:09
  • @Roman very true. The issue exists on “Wolfram Cloud” also, which, apparently is now not Mathematica Online....so maybe there is some other issue occurring? My concern/want to fix this is that this method is a primary part of my current research, and I do not entirely understand how to, in a generalized way, replace the Arnoldi method. I enjoyed that Eigensystem produces orthogonalized vectors and values.....I don’t know how to ask a question on this, as I cannot do the necessary research, but I fear my datasets are wrong now. – CA Trevillian May 19 '19 at 20:14
  • 6
    No need to fear, there are easy sanity checks, as @CarlWoll has already posted one (trace rule). A sanity check for the eigenvectors is to compute {eval, evec} = Eigensystem[M] and then go evec.Transpose[M].Inverse[evec] - DiagonalMatrix[eval] // Norm which should give zero (or something close to it) if the eigenvectors evec truly diagonalize the matrix M. – Roman May 19 '19 at 20:44
  • @Roman perfect! Thank you :) you rock! My matrix methods skills on the other hand....need work! I’ll be checking ~30000 of them this evening, I’ll report back with success or fail. Here’s to hoping sizes of ~100x100 or 200x200 go relatively unaffected! – CA Trevillian May 19 '19 at 20:48
  • Ill see about posting more code to the answer here in the morning, but I wanted to notify you all that for at least a numeric & very well defined functional matrix (meaning I had a 50x50 matrix that was programmatically defined) I get consistent EigInSanityChecks of ~.000008 give or take a zero (don’t hurt me! Hah!) But even this is troubling, although likely just a numerical error in this case, and not contributions from the eigensolver discrepancies. – CA Trevillian May 21 '19 at 04:49
  • 13
    This sort of breakage of previously working code now happens so frequently on major updates that I've decided to keep one or more old executables of Mathematica on hand. Note: test suites should be catching all of these! – Ralph Dratman May 22 '19 at 02:29
10

Fixed in 12.1


Mathematica graphics


ClearAll[x, n];
NN = 374; R = 0.05;
t1 = -1 + Cos[x] - I Sin[x] + I R; t1p = -1 + Cos[x] + I Sin[x] + I R;
mat[x_] = 
  DiagonalMatrix[Table[If[EvenQ[n], t1, -1], {n, 0, 2 NN - 1 - 1}], 
    1] + DiagonalMatrix[
    Table[If[EvenQ[n], t1p, -1], {n, 0, 2 NN - 1 - 1}], -1] + 
   DiagonalMatrix[Table[If[EvenQ[n], -1, 0], {n, 0, 2 NN - 1 - 3}], 
    3] + DiagonalMatrix[
    Table[If[EvenQ[n], -1, 0], {n, 0, 2 NN - 1 - 3}], -3];
mat0 = mat[-0.2 \[Pi]];
Tr@mat0  (*0.*)
(Total@Eigenvalues@mat0) // Chop
Nasser
  • 143,286
  • 11
  • 154
  • 359
4

I am not qualified to be at this site because the last time I used eigenvectors was well over half a century ago. The word "stiff matrix" came back to me, so I increased the precision of the author's code by rounding the two real numbers to 50 places. It took forever to compute, but Mathematica solved the problem accurately. That is, R = N[5/100, 50]; and mat0 = mat[N[-2/10 [Pi], 50]]; I ended up with zero to 47 places.

Occasionally--when solving differential equations numerically--I came across stiff systems, so I checked for this condition prior to working with them (I forget the method I used).

Again, sorry for my layman's interjection.

Nick Bagley

  • 4
    Charles, according to Wikipedia, "[...] the eigenvalue problem for all normal matrices is well-conditioned." So stiffness should not play a role here, unless a bad algorithm is being used. – Roman Jan 26 '20 at 17:09