Mathematica Mathematica Globally Define Variable as Real

AI Thread Summary
To ensure that specific variables in Mathematica are treated as real, users can utilize the "Assuming" function or set global assumptions with "$Assumptions." However, challenges arise when expressions still return results wrapped in the Re[] function, indicating confusion over potential imaginary components. A suggested solution involves using "ComplexExpand" in conjunction with "Simplify" and "Assuming" to properly handle the expressions. For example, applying "Assuming" with the conditions that x, y, and θ are real, followed by "ComplexExpand" and "Simplify," can yield the desired results without imaginary parts. This approach clarifies the treatment of the variables and resolves the confusion in the output.
teroenza
Messages
190
Reaction score
5
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?
 
Physics news on Phys.org
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
 
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]]]]
 

Similar threads

Replies
2
Views
2K
Replies
8
Views
2K
Replies
6
Views
4K
Replies
1
Views
3K
Replies
4
Views
17K
Replies
6
Views
3K
Replies
22
Views
3K
Replies
1
Views
5K
Back
Top