Here is an expression

1 + (-2 + es + Cos[kx] + Cos[ky] + 
Sqrt[(-2 + es + Cos[kx] + Cos[ky])^2 + Sin[kx]^2 + Sin[ky]^2])^2/(
Sin[kx]^2 + Sin[ky]^2)]]

With the assumptions that es, kx, ky are real variables, I want to remove the head Conjugate in a safe manner with Simplify or FullSimplify. But unfortunately, Both Simplify and FullSimplify failed to do this seemingly simple job even you use MapAll

Most of the time, ComplexExpand can remove Conjugate. But not in this expression. ComplexExpand will yield

ComplexExpand result

The reason that I insist on removing Conjugate is that I have to differentiate this kind of expression. With Conjugate in an expression, I will get results containing derivatives of Conjugate.

So how do I remove Conjugate other than removing it manually?

(Note that in my actual work, such Conjugate expressions are embedded in a much larger expression and I do not know in advance whether the expression Conjugate heads is real or not until I take a careful look at it.)


rcollyer mentioned Refine, but both Jens and I found it to be inefficient. But this inspired me to investigate the function Refine, and this aroused more confusion.

According to Mathematica's documentation (the following sentences were extracted directly from the entry on Refine):

Refine gives the form of expr that would be obtained if symbols in it were replaced by explicit numerical expressions satisfying the assumptions assum. Refine must have assumptions and performs only those basic simplifications which would be automatic for numeric inputs.Refine is one of the transformations tried by Simplify

So I came up with several questions: How does Refine refine expr? Will it really try to plug several sets of possible numerical values which are satisfied by the assumptions and see what comes out after the automatic simplification? But if so, how could Refine be certain it had tried enough sets of values? If it was not like this, then what does Mathematica's documentation mean?

I've tried several examples which are very confusing (es,kx,ky are all declared real variables in $Assumptions):


In:=Refine[Conjugate[Sqrt[Sin[kx]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
out=Sqrt[(Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2]

Conjugate is gone.


In:=Refine[Conjugate[Sqrt[Sin[kx]^2 + Sin[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
Out=Conjugate[Sqrt[(Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2 + Sin[ky]^2]]

Add one more term under the Sqrt and Conjugate remains.


In:=Refine[Conjugate[Sqrt[Sin[kx]^2 + Cos[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
Out=Sqrt[Cos[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2]

Change the added term from Sin to Cos, Conjugate is gone again.

Although the above three examples completely confused me, I add one more.


According mathematica's documentation on ComplexExpand:

ComplexExpand expands expr assuming that all variables are real. ComplexExpand automatically threads over lists in expr

So now I let ComplexExpand do the same job:

In:=ComplexExpand[Conjugate[Sqrt[Sin[kx]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
Out=Sqrt[(Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2]

In:=ComplexExpand[Conjugate[Sqrt[Sin[kx]^2 + Sin[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
Out=Sqrt[(Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2 + Sin[ky]^2]

In:=ComplexExpand[Conjugate[Sqrt[Sin[kx]^2 + Cos[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2]]]
Out=Sqrt[Cos[ky]^2 + (Cos[kx] + Cos[ky] + Sin[es])^2 + Sin[kx]^2]

All of the Conjugates are gone.

So ComplexExpand recognized that all of the three arguments are real and Refine failed, even though they both used the same assumptions. Also, Refine did not fail consistently; it succeeded on two of the examples. This proves Refine should have the same abilities as ComplexExpand, at least in the above cases.

So how does one explain the mysterious failure of Refine in the second example? What's more, ComplexExpand too has its failures. I really hope somebody could perfectly explain the simplification procedure applied by Mathematica. Help me clear out all the clouds from my head.

  • $\begingroup$ I just wrote an answer without seeing your last edit, but I was thinking about just that problem of having other complex parts. So maybe you can actually use what I wrote - unless someone else finds a fully automatic remedy... $\endgroup$
    – Jens
    Dec 15, 2012 at 6:57
  • $\begingroup$ Given your additional information your questions turns from remove Conjugate to test whether the argument is real and then remove Conjugate. Is that right? $\endgroup$
    – Matariki
    Dec 15, 2012 at 7:55
  • $\begingroup$ yes, you're right. And if the argument is not real, the Conjugate still has to be simplified. $\endgroup$
    – matheorem
    Dec 15, 2012 at 8:01
  • $\begingroup$ Sorry if I seem to be thick here (it's probably because I am). If you remove the Conjugate regardless of whether the argument is real or complex why differentiate between the two cases? $\endgroup$
    – Matariki
    Dec 15, 2012 at 8:07
  • $\begingroup$ Yes, that's right. My purpose is of course to remove the Conjugate regardless of whether the argument is real or complex, because I have one more step to differentiate it. But now you see mathematica even can not remove Conjugate when argument is real, will you expect that it will do better with the complex argument case? It will be a fool when encounter Sqrt as Jens has said so. $\endgroup$
    – matheorem
    Dec 15, 2012 at 8:47

2 Answers 2


It's true that Conjugate can be annoying, but it's understandable that you're having difficulty removing it in an automated way. The culprit are the square roots, which are actually harmless but aren't recognized by Mathematica to be harmless.

So if you don't want to manually remove Conjugate but also don't want to waste time rewriting the expression to rearrange the square roots (which may or may not be possible), then you could interfere manually at the level of the square roots instead. This isn't really any better than manually removing Conjugate in your case, but it could be useful if you do have places where Conjugate can't be removed, but you still want to assume that square roots are real:


fakeSqrt /: Conjugate[fakeSqrt[arg_]] := fakeSqrt[arg]

  Sqrt[1 + (-2 + es + Cos[kx] + Cos[ky] + 
         Sqrt[(-2 + es + Cos[kx] + Cos[ky])^2 + Sin[kx]^2 + 
           Sin[ky]^2])^2/(Sin[kx]^2 + Sin[ky]^2)] /. 
   Sqrt[arg_] :>  fakeSqrt[arg]] /. fakeSqrt[arg_] :> Sqrt[arg]

$\sqrt{\frac{\left(\sqrt{(\text{es}+\cos (\text{kx})+\cos (\text{ky})-2)^2+\sin ^2(\text{kx})+\sin ^2(\text{ky})}+\text{es}+\cos (\text{kx})+\cos (\text{ky})-2\right)^2}{\sin ^2(\text{kx})+\sin ^2(\text{ky})}+1}$

Here I temporarily replace the Sqrt heads by fakeSqrt which has been defined to be its own complex conjugate independently of the argument. At that point Conjugate sees what we want it to see, and right after that we can undo the replacement. As I said above, this is still manual interference, but it attacks a little closer to the root of the problem.

  • $\begingroup$ It is actually interesting that Mathematica does not realise that the Sqrt are harmless. In fact, it can simplify the expression when removing the -2 and having the assumptions Im[es]==Im[kx]==Im[ky]==0. $\endgroup$
    – Fabian
    Dec 15, 2012 at 10:27
  • $\begingroup$ I've added more stuff in my original post. Would you please help me take a look at it, OK? $\endgroup$
    – matheorem
    Dec 15, 2012 at 12:57
  • 11
    $\begingroup$ Wow, I have a pun at the end of this answer that I didn't notice at first... $\endgroup$
    – Jens
    Dec 15, 2012 at 22:34

The expression is in general complex even with all variables real since if the argument of any Sqrt is negative the Sqrt will be complex.

expr = Conjugate[
   1/Sqrt[1 + (-2 + es + Cos[kx] + Cos[ky] + 
          Sqrt[(-2 + es + Cos[kx] + Cos[ky])^2 + Sin[kx]^2 + 
            Sin[ky]^2])^2/(Sin[kx]^2 + Sin[ky]^2)]];

Since the issue is ultimately just the need to differentiate the expression, specify TargetFunctions for ComplexExpand

expr = ComplexExpand[expr, TargetFunctions -> {Re, Im}] // Simplify;

Although quite complicated, the derivatives are readily available, e.g.,

{exprDes, exprDkx, exprDky} = D[expr, {{es, kx, ky}}]

Simplifying the expressions is quite slow.


Your Answer

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

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