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

  • 1
    $\begingroup$ Could you post an example where ComplexExpand does not work well ? $\endgroup$ Mar 21, 2012 at 10:57
  • 1
    $\begingroup$ 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. $\endgroup$ Mar 21, 2012 at 11:24
  • $\begingroup$ ComplexExpand[Re[PP]] does return a result. The output is ugly because the result also depends on the sign of variables. $\endgroup$
    – Szabolcs
    Mar 21, 2012 at 11:26
  • 1
    $\begingroup$ Can we assume {d>0,ka>0,kd>0,L>0,y1>0,y2>0,\[Omega]>0} ? $\endgroup$ Mar 21, 2012 at 11:55
  • $\begingroup$ Every variable is real and >0. I just edited my original post accordingly. $\endgroup$
    – max
    Mar 21, 2012 at 13:08

1 Answer 1


Removing the imaginary portion of an expression is done by doing


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.

  • $\begingroup$ 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. $\endgroup$
    – max
    Mar 26, 2012 at 8:43
  • $\begingroup$ 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. $\endgroup$ Mar 26, 2012 at 18:56
  • 1
    $\begingroup$ 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. $\endgroup$ Mar 26, 2012 at 19:07
  • 1
    $\begingroup$ 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. $\endgroup$
    – nixeagle
    Mar 26, 2012 at 20:11
  • $\begingroup$ Can we use the same command if we have a matrix instead of an expression? $\endgroup$
    – user31694
    Feb 17, 2023 at 9:57

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.