# Mathematica Globally Define Variable as Real

• Mathematica
I want to write a line of code at the top of my .nb and have Mathematica treat the specified variables as real only. I've tried using "Assumptions" and "Assuming", but it just won't work. I still get back answers where the entire expression is returned inside the Re[ ] command, like it is confused over which variables might have imaginary parts.

Can it just be defined somehow globally that {x,y,z} are real only?

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
DrClaude
Mentor
Using \$Assumptions should work. You will need to give a specific example if you want more help.

Code:
Assuming[x \[Element] Reals && y \[Element] Reals && \[Theta] \[Element] Reals,Re[(x + I y)^2 Sin[\[Theta]/2]^2]]

Simplify[Re[(x + I y)^2 Sin[\[Theta]/2]^2],Assumptions ->  x \[Element] Reals &&   y \[Element] Reals && \[Theta] \[Element] Reals]
returns
Code:
Re[(x + I y)^2 Sin[\[Theta]/2]^2]

Re[(x + I y)^2] Sin[\[Theta]/2]^2

DrClaude
Mentor
I see. You need to do also a ComplexExpand:
Code:
Assuming[x \[Element] Reals && y \[Element] Reals && \[Theta] \[Element] Reals,
Simplify[ComplexExpand[Re[(x + I y)^2 Sin[\[Theta]/2]^2]]]]