15

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.

István Zachar
  • 47,032
  • 20
  • 143
  • 291
max
  • 1,585
  • 1
  • 14
  • 18
  • Are you trying to declare that your x inside your function is greater than zero (i.e., $x \in \mathbb{N}$)? – night owl Mar 26 '12 at 08:57
  • That's a general question. If you do not say anything more than $x>0$ to Mathematica, what does it understand? – max Mar 26 '12 at 09:03

5 Answers5

21

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.

rm -rf
  • 88,781
  • 21
  • 293
  • 472
sebhofer
  • 2,741
  • 18
  • 25
17

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.

halirutan
  • 112,764
  • 7
  • 263
  • 474
8

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}]
0
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]
Artes
  • 57,212
  • 12
  • 157
  • 245
  • 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. – Andrzej Kozlowski Mar 26 '12 at 10:24
  • 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. – Artes Mar 26 '12 at 10:48
  • 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}]. – Andrzej Kozlowski Mar 26 '12 at 11:08
  • 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. – Andrzej Kozlowski Mar 26 '12 at 11:20
  • @AndrzejKozlowski I find the third example gives a correct result and yes, the assumption Element[y, Reals] is indeed superfluous. I think you really did not understand what I meant. In my third example I have more general assumption but I get more strict result than that in the second one. – Artes Mar 26 '12 at 12:01
  • Yes,I meant the third example. This one, I think, is a bug, not intentional behaviour. – Andrzej Kozlowski Mar 26 '12 at 12:05
  • 1
    @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. – Artes Mar 26 '12 at 12:12
4

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]
Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
Andrzej Kozlowski
  • 2,839
  • 19
  • 20
  • 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. – Artes Mar 26 '12 at 10:53
3

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

Reduce[Element[x, Reals] && x > 0]
(*
==> x > 0
*)
celtschk
  • 19,133
  • 1
  • 51
  • 106
  • 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). – Andrzej Kozlowski Mar 26 '12 at 16:45