Mathematica Globally Define Variable as Real

  • Context: Mathematica 
  • Thread starter Thread starter teroenza
  • Start date Start date
  • Tags Tags
    Mathematica Variable
Click For Summary

Discussion Overview

The discussion revolves around how to globally define variables as real in Mathematica, specifically addressing issues with assumptions and simplifications that lead to expressions being returned with complex components. Participants explore various methods to ensure that specified variables are treated as real throughout the code.

Discussion Character

  • Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • One participant seeks a way to globally define variables {x, y, z} as real in Mathematica, expressing frustration with the use of "Assumptions" and "Assuming" which do not yield the desired results.
  • Another participant suggests that using $Assumptions should work, indicating that a specific example would help clarify the issue further.
  • A participant provides an example using "Assuming" with conditions for x, y, and θ being real, but notes that the output still includes the Re[ ] command, suggesting that Mathematica is not recognizing the variables as real.
  • Another participant recommends using "ComplexExpand" in conjunction with "Assuming" to potentially resolve the issue with complex components in the output.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method to globally define variables as real, with multiple approaches discussed and some uncertainty about their effectiveness.

Contextual Notes

Limitations include the lack of clarity on how Mathematica handles assumptions in different contexts, and the specific conditions under which the proposed solutions may or may not work.

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 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
18K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K