5

The linear combination $Q$ of two Hermitian matrices $A^\dagger = A, B^\dagger = B$ with real coefficients $m,n \in \mathbb{R}$, i.e. $Q = m A + n B$ is itself a Hermitian matrix $Q^\dagger = Q$.

However, in this minimal example the function ConjugateTranspose fails to produce the correct result:

$Assumptions = _ ∈ Reals;
A = {{a, b - I*c}, {b + I*c, -a}};
B = {{0, I*d}, {-I*d, 0}};

(* Check if Hermitian ) Refine[ConjugateTranspose[A] - A] ( Result: {{0, 0}, {0, 0}} ) Refine[ConjugateTranspose[B] - B] ( Result: {{0, 0}, {0, 0}} *)

(* Linear combination is not Hermitian ) Q = A + m B; Refine[ConjugateTranspose[Q] - Q] (* Result: {{0, -2 I d m}, {2 I d m, 0}} *)

Can someone spot my mistake?

xzczd
  • 65,995
  • 9
  • 163
  • 468
qntdni
  • 95
  • 4

3 Answers3

5
Clear["Global`*"]
A = {{a, b - I*c}, {b + I*c, -a}};
B = {{0, I*d}, {-I*d, 0}};

(*Check if Hermitian*)
ComplexExpand[ConjugateTranspose[A] - A] (*Result:{{0,0},{0,0}}*)
ComplexExpand[ConjugateTranspose[B] - B] (*Result:{{0,0},{0,0}}*)

Mathematica graphics

(*Linear combination is not Hermitian*)
Q = A + m*B;
ComplexExpand[ConjugateTranspose[Q] - Q] (*Result:{{0,-2 I d m},{2 I d m,0}}*)

Mathematica graphics

I personally do not like the use of global assumptions and do not use them. I prefer to use assumptions locally when needed or just use ComplexExpand which has the Reals assumptions buildin.

So the source of the issue is this global assumption?

The issue is as the answer below by @xzczd below explains, is due to the pattern not matching the symbols you meant to match.

If you insist of using global assumptions like you did, you can make the pattern more robust as follows. But I still do not like global assumptions myself.

$Assumptions = _Symbol ∈ Reals;

And now

Q = A + m*B;
Refine[ConjugateTranspose[Q] - Q] 

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
5

This example is interesting. It shows us that:

Though pattern matching seems to work in $Assumption/Assumption in some cases, one should avoid making use of this undocumented feature coincidence, because it's rather unstable.

Let me elaborate a bit. First of all, documents of $Assumption, Assumption, Simplify, etc. never promise pattern matching is supported by Assumption. Indeed, it seems to work in some cases, for example:

Refine[Im[x], Assumptions -> _ ∈ Reals]
(* 0 *)

But I'd rather call it a coincidence, because it's easy to find example on which pattern-matching-based assumption doesn't work, for example:

Refine[Sqrt[x^2], Assumptions -> _ < 0]
(* Sqrt[x^2] *)

Then why does Refine give incorrect result in OP's case? It's not too hard to boil down the sample to the following:

$Assumptions = {b, d, m} ∈ Reals;

Conjugate[b - I d m] // Refine (* b + I d m *)

$Assumptions = _ ∈ Reals;

Conjugate[b - I d m] // Refine (* b - I d m *)

$Assumptions = b - I d m ∈ Reals;

Conjugate[b - I d m] // Refine (* b - I d m *)

As we can see, the assumption _ ∈ Reals probably makes Refine think b - I d m is Real, thus Conjugate[b - I d m] // Refine incorrectly evaluates to b - I d m.

xzczd
  • 65,995
  • 9
  • 163
  • 468
2

Instead of using global assumptions, use Block to define the assumptions locally, like this:

Block[{$Assumptions = _Symbol \[Element] Reals}, Refine[ConjugateTranspose[Q] - Q]]
(*{{0, 0}, {0, 0}}*)

Like @Nasser, I prefer not to use global assumptions.

E. Chan-López
  • 23,117
  • 3
  • 21
  • 44