# Simplify makes Mathematica forget that a matrix is Hermitian

Using Simplify with certain trivial assumptions makes Mathematica forget that a given matrix is Hermitian. See the minimal example below:

expr = Exp[I*2*π*Re[n]]
mat = {{Re[n], a*expr}, {Conjugate[a]*Conjugate[expr], Re[n]}}
HermitianMatrixQ[mat]
simplifiedmat = Assuming[n ∈ Integers, Simplify[mat]]
HermitianMatrixQ[simplifiedmat]


Here I create a Hermitian matrix mat with some integer variable n. Mathematica correctly asserts that mat is Hermitian. After this I simplify the matrix under the assumption that n is an integer. This nicely removes the exponential expression in the matrix, as expected. However, according to Mathematica this simplified matrix simplifiedmat is no longer Hermitian.

This is clearly wrong. Thus I ask if there is any other way to simplify mat and maintaining that simplifiedmat is Hermitian?

There are two issues here. The first is that HermitianMatrixQ (in line with other Q functions) only applies quick checks that the matrix is Hermitian. It is acceptable for it to fail to recognise a matrix as Hermitian, but it must not say that a matrix is Hermitian when it is not.

Secondly, when you apply the test, your assumption for n is no longer active. HermitianMatrixQ has to assume it is complex.

Note further (I think) in general Q functions do not take account of assumptions. We have

Assuming[n ∈ Integers, HermitianMatrixQ[simplifiedmat]]
(* False *)

• Ok, I was somewhat hoping that Mathematica was keeping track of assumptions internally. Now I am aware that Simplify uses and then discards assumptions, so I need to carry them along by myself. – Hannebambel Nov 11 at 3:09
expr = Exp[I*2*π*Re[n]];
mat = {{Re[n], a*expr}, {Conjugate[a]*Conjugate[expr], Re[n]}};
HermitianMatrixQ[mat]

(* True *)

simplifiedmat = Assuming[n ∈ Integers, Simplify[mat]];


Use the SameTest option to HermitianMatrixQ to make use of Assumptions

HermitianMatrixQ[simplifiedmat,
SameTest -> (Simplify[#1 - #2 == 0, Element[n, Integers]] &)]

(* True *)

• Thanks for showing a way to use assumptions with functions which do not make use of assumptions themselves. I will keep this in mind for future applications, for now I found a different solution. – Hannebambel Nov 11 at 3:11

The essential problem is that simplifiedmat is

{{n, a}, {Conjugate[a], n}}


Note that this expression contains no hint about the nature of n. You told Simplify that n was an integer, so it naturally simplified Re[n] to n. One way to fix this is to restore the Re after simplifying:

HermitianMatrixQ[simplifiedmat /. n -> Re[n]]
(* True *)

• This does work rather well, but it requires me to restore all assumptions such as Re after every time I do Simplify, so I guess in larger projects there is quite some risk to miss one and get unexpected results. – Hannebambel Nov 11 at 3:13

From the answers above I learned that, unlike sympy, Mathematica does not keep track of assumptions and some functions simply ignore assumptions even if given explicitly.

Thus I thought some more about how to make a symbol n∈ℝ in the first place and that's surprisingly simple. Just define n as the real part of some new and otherwise unused symbol nComplex: n = Re[nComplex]. The whole code then becomes

n = Re[nComplex]
expr = Exp[I*2*π*Re[n]]
mat = {{Re[n], a*expr}, {Conjugate[a]*Conjugate[expr], Re[n]}}
HermitianMatrixQ[mat]
simplifiedmat = Assuming[n ∈ Integers, Simplify[mat]]
HermitianMatrixQ[simplifiedmat]


I have to admit that outputting matrices mat and simplifiedmat now looks rather ugly, but it does the job without me having to keep track of and reinserting all assumptions after every time I run Simplify.