Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Here is an expression

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)]]

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.)

Edit

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):

1.

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.

2.

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.

3.

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.

In:=Refine[Conjugate[Sqrt[Tan[es]^2]]]
Out=Conjugate[Sqrt[Tan[es]^2]]

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.

share|improve this question
    
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... –  Jens Dec 15 '12 at 6:57
    
Given your additional information your questions turns from remove Conjugate to test whether the argument is real and then remove Conjugate. Is that right? –  Matariki Dec 15 '12 at 7:55
    
yes, you're right. And if the argument is not real, the Conjugate still has to be simplified. –  matheorem Dec 15 '12 at 8:01
    
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? –  Matariki Dec 15 '12 at 8:07
    
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. –  matheorem Dec 15 '12 at 8:47

1 Answer 1

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:

Clear[fakeSqrt]

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

Conjugate[
  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.

share|improve this answer
    
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. –  Fabian Dec 15 '12 at 10:27
    
I've added more stuff in my original post. Would you please help me take a look at it, OK? –  matheorem Dec 15 '12 at 12:57
1  
Wow, I have a pun at the end of this answer that I didn't notice at first... –  Jens Dec 15 '12 at 22:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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