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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityLet’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.
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.
Simplify
states "Quantities that appear algebraically in inequalities are always assumed to be real."
$\endgroup$
TrueQ[x > 0]
immediately evaluates to False
, since x > 0
does not evaluate to True
at once.
$\endgroup$
Jul 5, 2012 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.
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]
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$
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]
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$
The most direct hint that x>0
implies Element[x,Reals]
is the following:
Reduce[Element[x, Reals] && x > 0]
(*
==> x > 0
*)
x
inside your function is greater than zero (i.e., $x \in \mathbb{N}$)? $\endgroup$