# Extract real part of a complex expression better than Re does

I have a complex expression with real positive variables only.

Mathematica Input Style:

PP = -((α (γ Cosh[y1 α] + α Sinh[y1 α])(-γ Cosh[(-L +  y2) α] + α Sinh[(-L + y2) α]))
/(s (2 α γ Cosh[L α] + (α^2 + γ^2) Sinh[L α]))) /. α -> Sqrt[s/d] /.
γ -> (kd + s)/ka /. s -> -ω*I


which leads to

$PP=-\frac{i \sqrt{-\frac{i \omega }{d}} \left(\frac{(\text{kd}-i \omega ) \text{Cosh}\left[\text{y1} \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\sqrt{-\frac{i \omega }{d}} \text{Sinh}\left[\text{y1} \sqrt{-\frac{i \omega }{d}}\right]\right) \left(-\frac{(\text{kd}-i \omega ) \text{Cosh}\left[(-L+\text{y2}) \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\sqrt{-\frac{i \omega }{d}} \text{Sinh}\left[(-L+\text{y2}) \sqrt{-\frac{i \omega }{d}}\right]\right)}{\omega \left(\frac{2 (\text{kd}-i \omega ) \sqrt{-\frac{i \omega }{d}} \text{Cosh}\left[L \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\left(\frac{(\text{kd}-i \omega )^2}{\text{ka}^2}-\frac{i \omega }{d}\right) \text{Sinh}\left[L \sqrt{-\frac{i \omega }{d}}\right]\right)}$

Now I want to extract the real part of this by assuming real only variables and then Re[PP]. Mathematica 8 can't extract it.

I saw on different forums that many people have had difficulties with extracting real or imaginary parts of expressions with built-in Re.

Some propose to replace Re by ComplexExpand[ ( PP + Conjugate[PP] )/2 ], which seems to work well in some cases. Do you have other suggestions?

All the variables are real and positive, so that I define at the beginning of my Mathematica notebook:

$Assumptions = ω > 0 && d > 0 && L > 0 && y1 > 0 && y2 > 0 && y1 < y2 && ka > 0 && kd > 0 && s > 0 && y1 < L && y2 < L  My version of Mathematica is $Version = "8.0 for Linux x86 (64-bit) (October 10, 2011)"

-
Could you post an example where ComplexExpand does not work well ? –  b.gatessucks Mar 21 '12 at 10:57
ComplexExpand[Re[PP]] will work. If you want Conjugate in the answer use ComplexExpand[Re[PP], TargetFunctions -> {Conjugate}]. Whatever you do, you will get a very long and complicated expression. Using Re alone is never going to "work" (well, it actually does "work", but does not expand - a different matter) except when dealing with numbers - how could it? The answers depends on which symbols are real and which are not. –  Andrzej Kozlowski Mar 21 '12 at 11:24
ComplexExpand[Re[PP]] does return a result. The output is ugly because the result also depends on the sign of variables. –  Szabolcs Mar 21 '12 at 11:26
Can we assume {d>0,ka>0,kd>0,L>0,y1>0,y2>0,\[Omega]>0} ? –  Rolf Mertig Mar 21 '12 at 11:55
Every variable is real and >0. I just edited my original post accordingly. –  max Mar 21 '12 at 13:08
show 4 more comments

## 1 Answer

Removing the imaginary portion of an expression is done by doing

ComplexExpand[Re[expression]].


Using just Re alone will not work as Re does no evaluation on symbols with unknown complex parts.

Now as stated in the problem and the comments above this particular problem requires a fair amount of assumptions. The simplest way to add local assumptions is to use Assuming. But this will not work, so we must instead make use of Simplify. For example:

Simplify[ComplexExpand[Re[expression]], a > 0]


where a is a symbol used in expression and is a real number greater than zero.

-
Indeed, the expression is too large for Mathematica 8 to output everything, but I am not sure that is related to the real part extraction. thanks anyway for this clear answer. –  max Mar 26 '12 at 8:43
This part about Assuming is completely wrong. Assuming has no effect on ComplexExpand. You will need to add Simplify, FullSimplify or Refine. Assuming alone does nothing when applied to functions that do not accept Assumptions. –  Andrzej Kozlowski Mar 26 '12 at 18:56
It is also untrue that Re does no evaluation. Try for example Re[Pi + I E]. Obviously it can't do any evaluation if an expression contains symbols about which it is not known if they have non-zero imaginary parts. –  Andrzej Kozlowski Mar 26 '12 at 19:07
Oops, in that case feel free to improve the answer. It is a community wiki thing, I don't get any rep or credit from it. I simply attempted to summarize the comments with the purported answers. :) I'll get to correcting it myself soon otherwise. –  nixeagle Mar 26 '12 at 20:11
add comment