HermitianMatrixQ doesn't work for a symbolic matrix

I’m trying to implement the solution described in 12.4.1 Measurements on a Single Spin of this book:

sJ = (\[HBar]/2) PauliMatrix /@ {1, 2, 3};
normal = {Sin[\[Theta]] Cos[\[Phi]], Sin[\[Theta]] Sin[\[Phi]], 
   Cos[\[Theta]]};
sigmaN = normal . PauliMatrix /@ {1, 2, 3}; 
Eigensystem[sigmaN] // FullSimplify // Transpose // MatrixForm

Then I try to check the Hermitian property of the sigmaN matrix as follows, but all failed:

HermitianMatrixQ[sigmaN]
FullSimplify[
  sigmaN, { \[Theta], \[Phi]  } \[Element] Reals] // HermitianMatrixQ

For more details, please refer to the attachment.

Regards,
HZ

12.4.1-Measurements-on-a-Single-Spin.nb (8.52 KB)

According to the documentation,

HermitianMatrixQ[m]
gives True if m is explicitly Hermitian, and False otherwise.

It would seem that it was designed for speed, not for sophistication. It disregards assumptions:

In[26]:= Assuming[Element[\[Theta] | \[Phi], Reals], 
 HermitianMatrixQ[sigmaN]]

Out[26]= False

This is to be expected from functions whose name ends in Q. Compare with IntegerQ:

In[41]:= x = (1 + Sqrt[2])^2 - 2 Sqrt[2];
Expand[x]
IntegerQ[x]

Out[42]= 3

Out[43]= False

Thank you for your explanation. Let’s look at another problem:

Why can’t I get the expectation value described in 12.4.1.4, i.e., Cos[[Theta]] or -Cos[[Theta]], as shown in the following screenshot?

For more details, please refer to the attachment.

12.4.1-Measurements-on-a-Single-Spin.nb (133 KB)

Thank you for your explanation. Let’s look at another problems:

  1. Why can’t I get the expectation value described in 12.4.1.4, i.e., Cos[[Theta]] or -Cos[[Theta]]?

  1. Why the Table command works, but the Do command gives nothing?

For more details, please refer to the attachment.

12.4.1-Measurements-on-a-Single-Spin.nb (134 KB)

I don’t know what the expectation value is.

The command Do gives Null as output. To gather the results you must store the in some variable.

Concerning HermitianQ:

it seems that Conjugate works somewhat peculiar

sigmaN[[1, 2]]
Conjugate[sigmaN[[1, 2]]]
Conjugate[sigmaN[[1, 2]] /. {Sin[\[Theta]] -> st, Sin[\[Phi]] -> sp, Cos[\[Phi]] -> cp}]
sigmaN[[1, 2]] /. Complex[0, a_] -> Complex[0, -a]

Conjugate assumes that \[Theta] is a complex variable. To force \[Theta] to be treated as real you can use ComplexExpand or Simplify:

ComplexExpand[
 Conjugate[Cos[\[Phi]] Sin[\[Theta]] - I Sin[\[Theta]] Sin[\[Phi]]]]
Simplify[
 Conjugate[Cos[\[Phi]] Sin[\[Theta]] - I Sin[\[Theta]] Sin[\[Phi]]], 
 Element[\[Theta], Reals]]

@Gianluca : thanks for these hints

@Honyi Zhao :
are you sure everyting is correct in the book? I get different results:

sJ = (\[HBar]/2) PauliMatrix /@ {1, 2, 3};
normal = {Sin[\[Theta]] Cos[\[Phi]], Sin[\[Theta]] Sin[\[Phi]], Cos[\[Theta]]};
(* sigma - matrix *)
sigmaN = normal.PauliMatrix /@ {1, 2, 3};
(* Eigenvectors of sigmaN *)
ev = Eigenvectors[sigmaN] // FullSimplify // Transpose
(* complex-conjugate eigenvectors *)
evc = (ev /. {Complex[0, a_] -> Complex[0, -a]}) // FullSimplify
(* eigenvalues of sigmaN: diagonal elements of diagonalized sigmaN*)
eigvals = Transpose[evc].sigmaN.ev // FullSimplify;
% // MatrixForm

It seems the following also work:

sigmaN // Conjugate // ComplexExpand[#, _ \[Element] Reals] & // 
  FullSimplify // MatrixForm
Sn // Conjugate // ComplexExpand[#, _ \[Element] Reals] & // 
  FullSimplify // MatrixForm

For more details, please refer to the attachment.

See the relevant discussion here .

12.4.1-Measurements-on-a-Single-Spin.nb (131 KB)

@Hans Dolhaine I solved the problem discussed here and describe it as follows:

  1. In order to compare with the results provided by the book, Eigenvectors should be normalized first as follows:

     ev = Normalize /@ Eigenvectors[sigmaN] // 
     FullSimplify[#, {\[Theta] | \[Phi]} \[Element] Reals] &;
    
  2. The results given by the book and the ones generated by Mathematica are, up to a phase factor, identical:

     E^(I \[Phi])
    
  3. I tried different complex conjugate calculate methods discussed here, and they give same results.

  4. HermitianMatrixQ works as follows:

     sigmaN // MatrixForm
     HermitianMatrixQ[sigmaN, 
      SameTest -> (FullSimplify[#1 == #2, {\[Theta] | \[Phi]} \[Element] 
           Reals] &)]
     HermitianMatrixQ[sigmaN, 
      SameTest -> (FullSimplify[#1 - #2 == 
           0, {\[Theta] | \[Phi]} \[Element] Reals] &)]
    
  5. I also asked Jean Dalibard, one of the book’s authors, this question.

All relevant calculations and comments mentioned above can be found in the attachments.

Regards,
HZ

12.4.1-Measurements-on-a-Single-Spin.nb (28 KB)
answer_JD.pdf (90.6 KB)

The syntax ComplexExpand[#, _ \[Element] Reals] & does not reflect the documentation. It seems to work, but it is probably equivalent to ComplexExpand alone.

What do you mean by saying “does not reflect the documentation”?

Regards,
HZ

The second argument of ComplexExpand should be a list of symbols, not a pattern. Also, if the purpose of the pattern Element[_,Reals] was to treat everything as real, then it should apply to I too…

IMO, the pure (or “anonymous”) function based method may be more flexible or powerful for more complicated scenarios.

Regards,
HZ

Have you tried the Wolfram Quantum Framework? http://wolfr.am/wolfram-quantum
Also, we recently organized a series of hands-on seminars as part of an online study group. I invite you to access the videos as an introduction to quantum computing using our framework: https://wolfr.am/QC-course

Thank you for letting me know the wonderful Wolfram Quantum Framework, but I’d like to start with some low-level understanding of this area in plain Mathematica.

Regards,
HZ