Let’s assume I input

Assuming[x > 0, expression]

Is it assumed by Mathematica that $x$ is a real number? Or that the real part of $x$ is positive? Something else?

A simple Mathematica illustration would be welcome.

  • $\begingroup$ Are you trying to declare that your x inside your function is greater than zero (i.e., $x \in \mathbb{N}$)? $\endgroup$ – night owl Mar 26 '12 at 8:57
  • $\begingroup$ That's a general question. If you do not say anything more than $x>0$ to Mathematica, what does it understand? $\endgroup$ – max Mar 26 '12 at 9:03

The most direct way to test this is probably the following:

$Assumptions = x > 0;
Element[x, Reals] // Simplify
(* Out[1]= True *)

$Assumptions = True;
Element[x, Reals] // Simplify
(* Out[4]= x ∈ Reals *)

So $x>0$ seems to imply that $x$ is real.

|improve this answer|||||
  • 10
    $\begingroup$ The documentation for Simplify states "Quantities that appear algebraically in inequalities are always assumed to be real." $\endgroup$ – Andrew Mar 26 '12 at 12:21
  • $\begingroup$ Ok, so it is obviously true for Simplify. The question is, is it true for everything else? I still think the answer is generally yes, but there might be some exceptions (and bugs) of course... $\endgroup$ – sebhofer Mar 26 '12 at 12:37
  • 1
    $\begingroup$ Assuming[x>0,TrueQ[x>0]] does reply False ... I don't understand that. $\endgroup$ – max Mar 26 '12 at 22:37
  • 3
    $\begingroup$ @max, that's because TrueQ[x > 0] immediately evaluates to False, since x > 0 does not evaluate to True at once. $\endgroup$ – J. M.'s technical difficulties Jul 5 '12 at 8:33

It is assumed that $x$ is a real number. Everything else would mathematically not make sense because on complex numbers there does not exist an ordering relation.

An example would be to take the expression $\sqrt{x^2}$ and to imagine that this is not equal $x$ for $x=-\mathbb{i}$. Therefore the expression is in a general form not simplified

In[37]:= Sqrt[x^2]

(* Out[37]= Sqrt[x^2] *)

If you now say that $x \geq 0$ should hold you get

In[33]:= Assuming[x >= 0, Refine[Sqrt[x^2]]]

(* Out[33]= x *)

Note that if $x \geq 0$ would mean the real part is non-negative, the value $x=-\mathbb{i}$ would still be possible. Therefore, it can be assumed, that using an ordering does automatically force the variable to be real.

|improve this answer|||||

In general the situation is much more subtle than the other answers suggest. For example this issue is present in version 8 while not in version 7 :

Integrate[ Exp[-a^2] Sin[2 t] (a^2 + b^2 + b*Cos[t] + a*Sin[t]), {t, 0, 2 Pi}]
$Assumptions = {x > 0};
Integrate[ Exp[-a^2] Sin[2 t] (a^2 + b^2 + b*Cos[t] + a*Sin[t]), {t, 0, 2 Pi}]
8/3 Sqrt[a^2 + b^2] E^-a^2

The identical integrand (not depending on x) yields different results if we assume x > 0. This bug may appear in different cases when we deal with complex variables.

One may encounter certain inconsequences working with these examples :

Assuming[ y > 0 && x > 0, 
         Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]                 (* I *)

Assuming[ y > 0 && Element[x, Complexes] && Re[x] > 0, 
          Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]                (* II *)

Assuming[ y > 0 && Element[x, Complexes], 
          Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]                (* III *)

Assuming[ Element[y, Reals] && Element[x, Complexes], 
          Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]                 (* IV *)
2 Log[(x + Sqrt[x^2 + y^2])/y]
2 Log[(x + Sqrt[x^2 + y^2])/y]
ConditionalExpression[2 Log[(x + Sqrt[x^2 + y^2])/y], x > 0]
ConditionalExpression[2 ArcSinh[x/Abs[y]], y != 0 && x >= 0]

For example assuming in (III) weaker conditions we get ConditionalExpression[..., x > 0] while in (II) under a more restrictive condition we get a more general expression.

FunctionExpand[2 ArcSinh[x/Abs[y]], x > 0 && y > 0] // TrigToExp
2 Log[Sqrt[1 + x^2/y^2] + x/y]
|improve this answer|||||
  • $\begingroup$ In all your examples when have assumed x>0 it is not necessary to assume Element[x,Reals]. In other words, if x>0&&Element[x,Reals] is equivalent to just x>0. This was, I think, the point of the question. $\endgroup$ – Andrzej Kozlowski Mar 26 '12 at 10:24
  • $\begingroup$ This should be like you said, but it seems that Mathematica sometimes cannot distinguish differences. I mean it could be nice if Mathematica had returned in the second example that x was implicitly assumed to be real. In that case the difference between the second and the third examples would not be inconvenient. I think it is important to point out when some assumptions are important, becaue that would be really helpful. $\endgroup$ – Artes Mar 26 '12 at 10:48
  • $\begingroup$ Your second example is exactly the same as Assuming[y > 0 && Re[x] > 0, Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]. In other words, most of your assumptions are not needed. Your third example is exactly equivalent to Assuming[y > 0, Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]. Again, you have unneeded assumptions. You also seem to be misunderstanding the meaning of Conditional. It means that Mathematica returns an answer which is valid only when the condition is satisfied and may be invalid otherwise. To see the point try Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]. $\endgroup$ – Andrzej Kozlowski Mar 26 '12 at 11:08
  • $\begingroup$ I think I missed your point. Sorry. I now think there is actually a bug involved in your second example: Mathematica does assume that x is real even though this assumption is not specified. One can see this by evaluating Assuming[y > 0 && Im[x] != 0, Integrate[1/Sqrt[z^2 + y^2], {z, -x, x}]]. I don't think that in this example Mathematica's behaviour is intentionally misleading. $\endgroup$ – Andrzej Kozlowski Mar 26 '12 at 11:20
  • 1
    $\begingroup$ @AndrzejKozlowski I could give a more complete explaining of what I meant, but I haven't time right now. I think these examples are good to describe a general statement that M sometimes implicitly assumes variables to be real although we assumed them to be complex. I disagree with that I don't understant ConditionalExpression. $\endgroup$ – Artes Mar 26 '12 at 12:12

Mathematica will always assume that all the arguments of an inequality relation are real but there are situations the presence of an inequality will lead to a stronger assumption. This is the case with Reduce. If you evaluate:

Reduce[x^2 + y^2 <= 1, {x, y}]

Mathematica will assume that both x and y are real. If you do not want this assumption you need to tell Reduce explicitly:

Reduce[x^2 + y^2 <= 1, {x, y},Complexes]
|improve this answer|||||
  • $\begingroup$ As you can see in my second example Mathematica implicitly assumes x is real although I assumed x to be complex. I mean it should be ConditionalExpression[2 Log[(x + Sqrt[x^2 + y^2])/y], x > 0] as in the third example. $\endgroup$ – Artes Mar 26 '12 at 10:53

The most direct hint that x>0 implies Element[x,Reals] is the following:

Reduce[Element[x, Reals] && x > 0]
==> x > 0
|improve this answer|||||
  • $\begingroup$ Really, there is no need for "hints". This is indeed so, full stop. It is to ask people who have programmed these functions and they have already answered such questions in great detail, more then once (on MathGroup). $\endgroup$ – Andrzej Kozlowski Mar 26 '12 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.