# How to define a real positive variable in mathematica

Suppose I have a function $f(x)$. I want Mathematica to treat $x$ as a real positive number, and hence to interpret $\sqrt{x^{2}}$ as $x$, for instance. How to do that?

• Assuming[x>0,f[x]] should solve your problem. You could also use $Assumptions command. – ivbc Jun 2 '17 at 16:44 • Depending on what computation you're doing, the answer might be there isn't a (convenient) way. Mathematica applies $Assumptions sparingly, for instance, whenever Simplify is called and functions that have an Assumptions option. I don't think you can get M to automatically simplify Sqrt[x^2] to x (barring overriding Power). You would have to use something like Simplify to get the assumptions to have the desired effect. Often that is sufficiently acceptable. – Michael E2 Jun 2 '17 at 17:04
• – jkuczm Jun 4 '17 at 19:04

I'll use "code" in this answer to symbolize whatever you are doing, just in case it is more complex than just the function you mentioned.

One way to get Mathematica to do what you ask is by:

Assuming[x>0,
"code"
]


But as "code" gets bigger or starts to encompass more than one cell it becomes easier to use

$$Assumptions = x > 0; "code"$$Assumptions = True;


The last line is not strictly necessary, but it might be very important. It clears your assumptions, so that you may use the symbol x freely again. If you have more than one notebook in use at once I recommend using it.

Checkout the tutorials when in doubt (lots of good stuff there):

https://reference.wolfram.com/language/ref/\$Assumptions.html?q=%24Assumptions