# Constructing a symbolic Hermitian matrix

I need to construct a symbolic Hermitian matrix like

m = {
{           n, a, b, b},
{Conjugate[a], n, b, b},
...
}


but I am not able to set the variables n, a, b in order to obtain a Hermitian matrix. I tried with $Assumptions but after that HermitianMatrixQ[m] gives me False as a result. I need that for a Cholesky decomposition of the m matrix. • You might be surprised to find that CholeskyDecomposition[{{a, b, c}, {b, d, e}, {c, e, f}}] works as expected... – J. M.'s technical difficulties May 14 '12 at 15:38 • The root cause of this problem is the issue described in this answer by @Leonid - that's at least the conclusion I drew in my answer below. – Jens May 14 '12 at 22:31 ## 3 Answers By default, Mathematica assumes symbols to be complex. However the elements on the main diagonal of a Hermitian matrix are necessarily real. To force Mathematica to interpret the elements on diagonal of m to be real you could replace them by their real part, i.e. m = {{Re[n], a, b, b}, {Conjugate[a], Re[n], b, b}, {Conjugate[b], Conjugate[b], Re[c], d}, {Conjugate[b], Conjugate[b], Conjugate[d], Re[e]}}; HermitianMatrixQ[m] (* output: True *) CholeskyDecomposition[m]  A reasonable alternative, is to construct an explicitly Hermitian matrix by exploiting the fact that any matrix,$M$, can be written as the sum of a Hermitian matrix,$H$, and a skew-Hermitian (or anti-Hermitian, if your in physics) matrix,$S$. This implies that a matrix can be made Hermitian simply by $$H = \frac{1}{2}(M + M^\dagger)$$ or skew-Hermitian via $$S = \frac{1}{2}(M - M^\dagger),$$ from which it is plainly obvious that$M = H + S$. This is implemented in Mathematica via SquareMatrixQ[m_?MatrixQ] := Equal@@Dimensions[m] SquareMatrixQ[_] := False makeHermitian[m_?SquareMatrixQ] := (m + ConjugateTranspose[m])/2 makeSkewHermitian[m_?SquareMatrixQ] := (m - ConjugateTranspose[m])/2  where I included the test SquareMatrixQ as Mathematica does not have a built-in equivalent. They give the following results m = {{a, b, c}, {d, e, f}, {g, h, i}} makeHermitian[m] // FullSimplify (*{{Re[a], 1/2 (b + Conjugate[d]), 1/2 (c + Conjugate[g])}, {1/2 (d + Conjugate[b]), Re[e], 1/2 (f + Conjugate[h])}, {1/2 (g + Conjugate[c]), 1/2 (h + Conjugate[f]), Re[i]} } *)  and makeSkewHermitian[m] // FullSimplify (*{{a - Re[a], 1/2 (b - Conjugate[d]), 1/2 (c - Conjugate[g])}, {1/2 (d - Conjugate[b]), e - Re[e], 1/2 (f - Conjugate[h])}, {1/2 (g - Conjugate[c]), 1/2 (h - Conjugate[f]), i - Re[i]} } *)  Without FullSimplify the the diagonals are left in the form j + Conjugate[j] or j - Conjugate[j], respectively. It is interesting to note that the diagonals of the skew-Hermitian matrix should be purely imaginary (and are), but FullSimplify reduces it to j - Re[j] instead of Im[j]. • The non-uniqueness of this representation could be a problem (depending on the application). As an example, consider (makeHermitian[m] == makeHermitian[m + I (# + Transpose[#]) &[RandomInteger[10, {3, 3}]]]) // FullSimplify – Jens May 14 '12 at 20:02 A Hermitian matrix of dimension$N$has$N^2$real parameters. However, in the answer by rcollyer I see a larger number of parameters in the form of complex numbers (which means the representation isn't unique). In Heike's solution (which is from the documentation for HermitianMatrixQ) we have to write Re[n] on the diagonal which is OK in principle but creates the impression as if n as a complex number has significance, which of course it doesn't. So one should be able to specify the real-valuedness of the diagonal elements as an assumption instead. That's what I'm testing below: Clear[h]; mat = Table[If[i <= j, h[i, j], Conjugate[h[j, i]]], {i, 3}, {j, 3}]; MatrixForm[mat] $\left( \begin{array}{ccc} h(1,1) & h(1,2) & h(1,3) \\ h(1,2)^* & h(2,2) & h(2,3) \\ h(1,3)^* & h(2,3)^* & h(3,3) \\ \end{array} \right)$The documentation states that HermitianMatrixQ[mat] is "effectively" equivalent to ConjugateTranspose[mat] == mat. Let's see if that is true: Assuming[{Apply[And, Map[# ∈ Reals &, Diagonal[mat]]]}, Simplify[ConjugateTranspose[mat] == mat]] (* ==> True *) Assuming[{Apply[And, Map[# ∈ Reals &, Diagonal[mat]]]}, Simplify[HermitianMatrixQ[mat]]] (* ==> False *)  It is not the same. So it may be that the problems of the OP have to do with this inconsistency. My suggestion therefore would be to avoid using HermitianMatrixQ as a test, and use the first variant instead. Edit Since HermitianMatrixQ appears to be used internally, we're stuck with it and need to follow Heike's answer, or the one I give below. The key word in the documentation is that the matrix passed to HermitianMatrixQ must be explicitly hermitian. This means that although it does evaluate its arguments, it doesn't evaluate properly with $Assumptions when attempting to Simplify. That appears to severely limit the extent to which one can do symbolic matrix manipulations. I just checked that the same behavior also happens for SymmetricMatrixQ.

Edit 2: a new solution without Re[...]

This seems to be the general policy for all conditionals that end in ...Q: the test is performed syntactically without using assumptions.

To get a neat representation of a hermitian matrix that is manifestly hermitian, one could use the following definition:

dimension = 3;
Clear[h];
diagonal = Table[Unique["h"], {dimension}];
Map[(# /: Conjugate[#] = #) &, diagonal];
mat = Table[
If[i <= j, h[i, j], Conjugate[h[j, i]]], {i, dimension}, {j,
dimension}];
mat = mat - DiagonalMatrix[Diagonal[mat]] + DiagonalMatrix[diagonal];
MatrixForm[mat]


$\left( \begin{array}{ccc} \text{h3} & h(1,2) & h(1,3) \\ h(1,2)^* & \text{h4} & h(2,3) \\ h(1,3)^* & h(2,3)^* & \text{h5} \\ \end{array} \right)$

HermitianMatrixQ[mat]


True

Here I did not have to forcibly use real parts Re on the diagonals. Instead, I used TagSet to define the complex conjugate of each diagonal element to be equal to itself. That is sufficient to convince Mathematica that it is a real number.

• @Jeans, in fact if I try a decomposition the answer is the following CholeskyDecomposition::herm: The matrix {{h[1,1],h[1,2],h[1,3]},{Conjugate[h[1,2]],h[2,2],h[2,3]},{Conjugate[h[1,3]],Conjugate[h[2,3]],h[3,3]}} is not Hermitian or real and symmetric. >>. It is not necessary to test if the matrix is symmetric but I need to use this decomposition and it works only if Mathematica feels one hermitian matrix (also positive) – Raffaele Carlone May 14 '12 at 7:37
• I'm having trouble coming up with an example of the non-uniqueness of my decomposition. Could you show me, please? – rcollyer May 14 '12 at 17:01