Bug introduced in 10.0 and fixed in 10.2.0
I found a case where calling one built-in function (HermitianMatrixQ
) for a given matrix changes the behavior of another built-in function (AntihermitianMatrixQ
) for the same matrix object. Here is the code:
M = {{0, 1}, {-1, 0}}
AntihermitianMatrixQ[M] (* output: True *)
HermitianMatrixQ[M] (* output: False *)
AntihermitianMatrixQ[M] (* output: False -- WRONG! *)
I observed this in Mathematica 10.0.0.0 on Microsoft Windows (64-bit).
The behavior is "stateful" in the sense that re-evaluating the assignment to M
restores the correct behavior of AntihermitianMatrixQ
until the next time the function HermitianMatrixQ
is called for the same object, from which point on AntihermitianMatrixQ
gives the incorrect result again.
I did some experimentation and found the following:
- The "state" is per object: When you define several array variables, the functions behave independently for each of the array objects, in the way described above.
- The problem does not occur for all matrices, but it is not limited to the given 2x2 case, either. (In fact I found it when debugging a calculation with 4x4 Dirac gamma matrices.)
- The function
SymmetricMatrixQ
intereferes with the behavior ofAntihermitianMatrixQ
in the same way. - The result of
AntisymmetricMatrixQ
is affected in the same way. - Printing the
FullForm
of the object does not give any indication of a change to the object itself.
My question is therefore:
- Does Mathematica store any per-object data for matrices that is not displayed in
FullForm
but that can affect the behavior of functions as described above? - If so, is there any way to display or to clear this kind of additional data?
Note: I created a support request with Wolfram Research regarding this strange behavior. So far I got no response, however. I would also appreciate independent confirmation of this behavior, to exclude the possibility that something is wrong with my particular installation of Mathematica.
UPDATE: I got a response to my support request (CASE:3202743) from WRI. They confirm that AntisymmetricMatrixQ
is not behaving properly and that an incident report has been created. Many thanks also to @ilian for pursuing this matter. I would still be interested in answers to my questions as formulated -- both out of curiosity and in order to improve debugging options.
SameTest
.{AntihermitianMatrixQ[m, SameTest -> (Simplify[#1 - #2] == 0 &)], HermitianMatrixQ[m, SameTest -> (Simplify[#1 - #2] == 0 &)], AntihermitianMatrixQ[m, SameTest -> (Simplify[#1 - #2] == 0 &)]}
$\endgroup$f = (Print[Equal[##]]; Equal[##]) &; AntihermitianMatrixQ[m, SameTest -> f]
as opposed toHermitianMatrixQ[m, SameTest -> f]
. $\endgroup$