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.

Mathematica really struggles to simplify complex conjugates of complicated expressions - even given assumptions for every symbol in the expression being real. Often times I've found that I can actually accomplish what I want better by doing my own conjugation using replaceall and manually switching all the i's to -i.

For example, I'll have psi = Exp[I k x] (well, a more complicated mixture of things like that), so to get psi* I just do

psi /. I -> -I

This works quite well - but apparently I, 2I, 3I and so on are all different, so I have to look at the expression, pick out all the I's, then do something like this:

psi /.{I->myi,2I-> 2 myi, 3I-> 3 myi}
psiconj = % /.{myi->-I}

This seems to work, usually.

Is there any way I can do this without individually specifying each form of I that appears? Like psi /. x_I :> -x I ? (That doesn't work). Or maybe /. x?ImaginaryQ:>-x or something?

I'm also open to other suggestions. The problem here is that mathematica is being very careful - and that keeps it from doing things incorrectly in certain situations... but in most cases, I know what I want, and I just want a simple straightforward conjugation that switches all visible I's to -I's.

EDIT: I edited to clear up confusion about i vs I in code snippets. As for why I wouldn't want to use Conjugate - if it's not clear enough above, than see other issues such as these:

Remove annoying Conjugate

http://stackoverflow.com/questions/13337630/mathematica-simplify-conjugate-expresion

Conjugates often cause expressions to not simplify - best case scenario it will work as long as I explicitly tell mathematic to assume that every symbol in the expression is real and positive, but with lots of symbols this is cumbersome - and when I know the expression well enough to know that a simple switching of just the visible I's to -I's will work, I don't really want to spend time doing something more complicated.

ComplexExpand and Refine sometimes can help - but sometimes not. What does work for me in my situations is what I described above - but they're not very general.

I've toyed around with what I said above, and this seems to work, though it's not very elegant (still much better that using Conjugate, Simplify and having to explicitly tell mathematica to assume a bunch of symbols are real and positive):

psi = Exp[3 I k x + 5 x + Sqrt[2 I m]]
psi /. {x_?(NumberQ[#] && Element[#, Complexes] &) :>  Conjugate[x]}

EDIT 2: Szabolcs suggestion is simpler/better than what I that above:

psi = Exp[3 I k x + 5 x + Sqrt[2 I m]]
psi /. x_Complex :>  Conjugate[x]
share|improve this question
    
What is wrong with Conjugate? Trying to replace I by -I (note the difference between i and I and please format your post to avoid confusion about this!) won't work because Complex numbers are atomic. Try AtomQ[1+I]. –  Szabolcs Dec 20 '13 at 0:10
    
Conjugate often results in expressions that don't simplify, or only do with a ton of Assumptions. In this case I just want to bypass Mathematica's carefull ways and do the simple and obvious thing - because it's all I need to do. Perhaps there is a way to tell Conjugate/Simplify to assume everything is Real other than numbers? –  argentum2f Dec 20 '13 at 0:37
    
Oh, and trying to replace I by -I does work - it's just a little more complicated. See my edit. I would still like to know if there are better/elegant ways of doing that , or other simpler ways to accomplish what I want (simplifyable Conjugation of complicated expressions) –  argentum2f Dec 20 '13 at 0:41
    
No, replacing I by -I does not work, it seems you haven't tried it on my example: 1+I /. I -> -I. You have to replace (atomic) Complexes by their conjugate: ... /. z_Complex :> Conjugate[z] does work. –  Szabolcs Dec 20 '13 at 0:50
    
Lol. It does work... as your code shows - or rather, what I wanted to do does work. (I already get that just doing I->-I doesn't work by itself. That was the whole point of the original post!) And yes, I did try your example with what I gave, and it does work (though in the code I originally posted there was a typo). Anyway, the _Complex addon is what I was looking for - wasn't sure how to make mathematica do that (my way was ugly, as you can see above), thanks. –  argentum2f Dec 20 '13 at 3:14
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.