3
$\begingroup$

What I'm doing:

I was attempting to evaluate this

$Assumptions =  
  a \[Element] Reals && b \[Element] Reals &&  c \[Element] Reals && 
   d \[Element] Reals && h \[Element] Reals && k \[Element] Reals && 
   t \[Element] Reals && r \[Element] Reals  && r >= 0 && t >= 0 && 
   t <= 2*Pi;

 Re[ComplexExpand[(a*((h + r*Cos[t]) + I*(k + r*Sin[t])) + 
      b)/(c*((h + r*Cos[t]) + I*(k + r*Sin[t])) + d)] ]

Which is basically asking for the real part of $$ \text{Re}\left[ \frac{a(h+r\cos(t))+ i (k+r\sin(t))+b}{c(h+r\cos(t))+ i(k+r\sin(t)) + d} \right] $$

Which is the Möbius transform $\frac{az+b}{cz+d}$ applied to the circle given by parametric equation of a generic circle $(h + r\cos(t), k + r\sin(t))$.

What Happened:

I was a bit shocked at the output. In particular certain expressions that were clearly not complex were assumed to have a nontrivial imaginary part. See below:

enter image description here

What I was expecting:

I was expecting instead to see something like

$$ \frac{bd+bch+adh+ach^2+ack^2+(bcr+adr+2achr+acr^2 \cos(t))\cos(t)+2ackr\sin(t)+acr^2 \sin(t)^2 }{(d + c(h+r \cos(t)))^2 + c^2(k+r\sin(t))^2}$$

Or at least a fractional decomposition of that. Certainly I did NOT expect to see stray "Re" and "Im" operators in the output. That entire "Im" section should be just 0 in the Mathematica output.

What I tried to Troubleshoot:

I thought perhaps Mathematica couldn't reason about the $\sin(t)$ and $\cos(t)$ since they were functions. So I thought to add those to the assumptions as well. Namely that they are real. Unfortunately that did not seem to change this behavior.

What I'm asking for:

I'm looking either for an operator to apply to this expression that gets Mathematica to drop those "Im" terms that are clearly 0.

Or alternatively some other configuration/command that will cause Mathematica to consider my assumptions more carefully and see for itself that the "Im" term should be 0.

$\endgroup$
5
  • 2
    $\begingroup$ In[298]:= Together@ ComplexExpand[ Re[(a*((h + r*Cos[t]) + I*(k + r*Sin[t])) + b)/(c*((h + r*Cos[t]) + I*(k + r*Sin[t])) + d)]] Out[298]= (b d + b c h + a d h + a c h^2 + a c k^2 + b c r Cos[t] + a d r Cos[t] + 2 a c h r Cos[t] + a c r^2 Cos[t]^2 + 2 a c k r Sin[t] + a c r^2 Sin[t]^2)/(d^2 + 2 c d h + c^2 h^2 + c^2 k^2 + 2 c d r Cos[t] + 2 c^2 h r Cos[t] + c^2 r^2 Cos[t]^2 + 2 c^2 k r Sin[t] + c^2 r^2 Sin[t]^2) maybe? $\endgroup$ Commented Nov 20 at 22:36
  • 1
    $\begingroup$ Alternative: e=(a*((h+r*Cos[t])+I*(k+r*Sin[t]))+b)/(c*((h+r*Cos[t])+I*(k+r*Sin[t]))+d); o=ComplexExpand[e]; Select[o,FreeQ[#,I]&]//FullSimplify gives same output as above by Daniel's. I do not know now why what you did, did not work. $\endgroup$
    – Nasser
    Commented Nov 20 at 22:42
  • $\begingroup$ btw, the first line you wrote does nothing really. DId you mean to write $Assumptions =... ? $\endgroup$
    – Nasser
    Commented Nov 20 at 22:44
  • $\begingroup$ @Nasser oops the ` command hid it. Will try your and Daniel's solution. Do ya'll want to post those as answers so I can give upvotes if they work and potentially accept? $\endgroup$ Commented Nov 20 at 22:50
  • $\begingroup$ @Daniel and Nasser both work for me! I'm still not sure why my thing doesn't work. But that unblocks me here. $\endgroup$ Commented Nov 20 at 22:58

2 Answers 2

5
$\begingroup$

I think the problem is that you wrote Re[ComplexExpand[expression]] instead of ComplexExpand[Re[expression]]

ComplexExpand assumes all variables are real. So when Re is inside the call to ComplexExpand, then ComplexExpand takes care of sorting things out based on this and you get the expected result.

But when you call Re after the call to ComplexExpand is made, then now Re do not have the same tools that ComplexExpand have and does not have the smarts of assuming all variables are real.

See the difference:

e = (a*((h + r*Cos[t]) + I*(k + r*Sin[t])) + 
     b)/(c*((h + r*Cos[t]) + I*(k + r*Sin[t])) + d);
ComplexExpand[Re[e]]

enter image description here

Compare to

Re[ComplexExpand[e]]

enter image description here

There is no need to write $Assumptions = a \[Element] Reals && b \[Element] Reals ...., as ComplexExpand handles all of this internally and you can make mistake or overlook one of the variables this way. Just let Mathematica figure it out.

You just have to make sure to use ComplexExpand after the call to Re and not before

$\endgroup$
4
$\begingroup$

I think it will work better to have Re[] inside the ComplexExpand. I also use Together at the end to make the result more concise since ComplexExpand gives a bunch of terms with a common denominator.

Together@ComplexExpand[
  Re[(a*((h + r*Cos[t]) + I*(k + r*Sin[t])) + 
      b)/(c*((h + r*Cos[t]) + I*(k + r*Sin[t])) + d)]]

(* Out[298]= (b d + b c h + a d h + a c h^2 + a c k^2 + b c r Cos[t] + 
   a d r Cos[t] + 2 a c h r Cos[t] + a c r^2 Cos[t]^2 + 
   2 a c k r Sin[t] + a c r^2 Sin[t]^2)/(d^2 + 2 c d h + c^2 h^2 + 
   c^2 k^2 + 2 c d r Cos[t] + 2 c^2 h r Cos[t] + c^2 r^2 Cos[t]^2 + 
   2 c^2 k r Sin[t] + c^2 r^2 Sin[t]^2) *)
$\endgroup$

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.