5
$\begingroup$

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?

$\endgroup$

3 Answers 3

5
$\begingroup$

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.

$\endgroup$
5
$\begingroup$
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

$\endgroup$
3
  • $\begingroup$ Thank you for your answer! So the source of the issue is this global assumption? I don't understand why my version doesn't work and yours does. It is the same thing, isn't it? $\endgroup$
    – qntdni
    Sep 19, 2022 at 12:11
  • $\begingroup$ @qntdni updated. $\endgroup$
    – Nasser
    Sep 19, 2022 at 14:17
  • $\begingroup$ Ah I see, thank you for your help! $\endgroup$
    – qntdni
    Sep 20, 2022 at 8:39
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.