Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why can't Mathematica tell when something is algebraically zero?

290 views
Skip to first unread message

mmdanziger

unread,
Mar 8, 2010, 6:09:39 AM3/8/10
to
This isn't the first time that I've encountered something like this in
Mathematica but in my calculations I got a term like this:

r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]

Which is obviously identically zero. For some reason Simplify or even
FullSimplify can't figure this out. Once you get dependent on
Mathematica these things are pretty disturbing...you forget about your
own knowledge because the program tells you that things are
different. Then you sit there like an idiot checking an algebraic
identity that any beginning precalc student should be able to solve no
problem.

Is there any way to get Mathematica to "wake up" to these things? It
has such a powerful algebraic engine for most things, why can't it see
something simple like the above? Do you really have to manually
override and tell the program when things should be zero?

For the time being I'll just sift through and test things by hand but
I can't believe that there isn't a better way.

Best,
md

dh

unread,
Mar 9, 2010, 6:17:08 AM3/9/10
to
Hi,
Sqrt is a multivalued function. Therefore, your expression is not
necessarily zero. If you are sure that all your variables are real and
that you only want the main branch of Power, then you can use PowerExpand:
r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
Daniel


--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:d...@metrohm.com>
Internet:<http://www.metrohm.com>


Nasser M. Abbasi

unread,
Mar 9, 2010, 6:21:05 AM3/9/10
to

"mmdanziger" <mmdan...@gmail.com> wrote in message
news:hn2ltj$3kt$1...@smc.vnet.net...

> This isn't the first time that I've encountered something like this in
> Mathematica but in my calculations I got a term like this:
>
> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>
> Which is obviously identically zero. For some reason Simplify or even
> FullSimplify can't figure this out.

hi;

try this:

In[5]:= f=r^2 Sqrt[(r^3+r+2)/r]-Sqrt[r^3 (r^3+r+2)];

Assuming[r>0,Simplify[f]]

Out[6]= 0


--Nasser

Sjoerd C. de Vries

unread,
Mar 9, 2010, 6:22:05 AM3/9/10
to
Your expression does not generally equal zero:

In[12]:= r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] /. r -> I

Out[12]= -2 + 2 I

PowerExpand does the job:

In[18]:= PowerExpand[
r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]

Out[18]= 0

Cheers -- Sjoerd

mmdanziger

unread,
Mar 9, 2010, 6:22:37 AM3/9/10
to
Thanks for all the helpful responses. This should clean up my
calculations substantially.

md

On Mar 8, 1:09 pm, mmdanziger <mmdanzi...@gmail.com> wrote:

Richard Fateman

unread,
Mar 9, 2010, 6:22:48 AM3/9/10
to
mmdanziger wrote:
> This isn't the first time that I've encountered something like this in
> Mathematica but in my calculations I got a term like this:
>
> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>
> Which is obviously identically zero.

let f[r_]:= r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]

try
Plot[Re[f[x I]], {x, -1, 1}]

from which one can conclude that f[r] is not identically zero when r is
not real.

> For some reason Simplify or even
> FullSimplify can't figure this out.

I'm not sure what to suggest regarding the rest of your message. :)


Bill Rowe

unread,
Mar 9, 2010, 6:23:20 AM3/9/10
to
On 3/8/10 at 6:09 AM, mmdan...@gmail.com (mmdanziger) wrote:

>This isn't the first time that I've encountered something like this
>in Mathematica but in my calculations I got a term like this:

>r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]

>Which is obviously identically zero. For some reason Simplify or


>even FullSimplify can't figure this out.

The problem is the expression is not zero for all possible
values of r. Specifically

In[3]:= r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] /. r
-> I

Out[3]= -2 + 2 I

You can get Mathematica to do what you want by using PowerExpand
which implicitly assumes reals. That is:

In[4]:= r^2 Sqrt[(r^3 + r + 2)/r] -
Sqrt[r^3 (r^3 + r + 2)] // PowerExpand

Out[4]= 0


Simon

unread,
Mar 9, 2010, 6:24:57 AM3/9/10
to
Hi md,

I think that you're being a little harsh on Mathematica.
Your expression is zero when r>=0. You can't expect mathematica to
assume that r is a radius.

In[1]:= FullSimplify[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r +
2)], r >= 0]
Out[1]= 0

In fact it can do better than that, and tell you exactly when it is
zero:

In[2]:= Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] ==
0, Reals]
Out[2]= r <= -1 || r > 0

More generally, I remember having read that the question of when a
complex algebraic object consisting of elementary functions and
absolute values as zero is undecidable. That's why Mathematica (and other
systems) have (and internally use) things like PossibleZeroQ. The
documentation says
-----
The general problem of determining whether an expression has value
zero is undecidable; PossibleZeroQ provides a quick but not always
accurate test.
With the setting Method->"ExactAlgebraics", PossibleZeroQ will use
exact guaranteed methods in the case of explicit algebraic numbers.
-----
Can anyone supply a reference or argument proving the undecidability??

Simon

sashap

unread,
Mar 9, 2010, 6:25:29 AM3/9/10
to
On Mar 8, 5:09 am, mmdanziger <mmdanzi...@gmail.com> wrote:
> This isn't the first time that I've encountered something like this in
> Mathematica but in my calculations I got a term like this:
>
> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>
> Which is obviously identically zero.

In[73]:= FindInstance[
r^2 Sqrt[(r^3 + r + 2)/r] != Sqrt[r^3 (r^3 + r + 2)], r, 2]

Out[73]= {{r -> -37 + (108 I)/5}, {r -> 51/5 - (228 I)/5}}


David Park

unread,
Mar 9, 2010, 6:26:13 AM3/9/10
to
expr = r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)];

The expression is undefined for r == 0, and definitely not zero for complex
values of r. Mathematica usually assumes a complex domain.

The following work:

Simplify[expr, r > 0]
0

Simplify[expr /. r -> -r, r > 0]
0

But I don't know why the following doesn't work.

FullSimplify[expr, r != 0 \[And] r \[Element] Reals]
r^2 Sqrt[(2 + r + r^3)/r] - Sqrt[r^3 (2 + r + r^3)]

However, the following does work:

Simplify[expr // ComplexExpand, r != 0 \[And] r \[Element] Reals]
0

I don't think it would be very obvious to try that.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


From: mmdanziger [mailto:mmdan...@gmail.com]

This isn't the first time that I've encountered something like this in
Mathematica but in my calculations I got a term like this:

r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]

Which is obviously identically zero. For some reason Simplify or even

psycho_dad

unread,
Mar 9, 2010, 6:27:07 AM3/9/10
to
Hi,
Applying PowerExpand seems to work (in v.7):

r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] //PowerExpand
0

Cheers,
psycho_dad

Andrzej Kozlowski

unread,
Mar 10, 2010, 1:42:30 AM3/10/10
to
In fact, I was wrong, and I forgot of something I once new (or assumed
that it had been "fixed"). Assuming has no effect on PowerExpand and the
answer returned is completely misleading. For example:

Assuming[Im[r] != 0,
PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
0

which is of course wrong.

PowerExpand only works with Assumptions passed view the Assumptions ->
... method and then the answer is very complicated:

PowerExpand[
r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],
Assumptions -> Element[r, Reals]]

r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
(2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
Arg[r^3 + r + 2]/(2*Pi) + 1/2])

But, what is rather strange, this works:

PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)],
Assumptions -> r <= 0]

even though it does not work with Simplify and Reduce

Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
r < 0, r]
Reduce::cpow: Reduce was unable to prove that a radical of an expression
containing only real variables and parameters is real valued. If you are
interested only in solutions for which all radicals contained in the
input are real valued, use Reduce with domain argument Reals. >>

The question is then, does PowerExpand really do that correctly? It
would be reassuring if someone from WRI would confirm it. (Getting the
right answer with PowerExpand itself is not very reassuring...).

I remember a while ago there was already a discussion here concerning
the fact that PowerExpand is probably the only function that admits
Assumptions only in the form Assumptions -> and not via Assuming. I
though that was going to be changed but it remains as it used to be. If
changing this behaviour is really impossible I think there ought to be
some sort of warning message that appears when one attempts to use
Assuming[something,PowerExpand[expr]], for obvious reasons.

Andrzej Kozlowski


On 9 Mar 2010, at 14:22, Andrzej Kozlowski wrote:

> It seems better to use:
>
> Assuming[Element[r, Reals],
> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>
> 0
>
> PowerExpand with Assumptions ought to be as reliable as Simplify
(which does not work in this case), whereas if you use it without
assumptions it can return answers that will be false for some values of
the variables (it makes use of the maximal assumptions that permit the
expansion). The fact that Simplify works here with the assumption r>=0
but not r<0 appears to be a bug.
>
> Andrzej Kozlowski


>
>
>
>
> On 9 Mar 2010, at 12:19, dh wrote:
>
>> Hi,
>> Sqrt is a multivalued function. Therefore, your expression is not
>> necessarily zero. If you are sure that all your variables are real
and
>> that you only want the main branch of Power, then you can use
PowerExpand:
>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
>> Daniel
>>
>> On 08.03.2010 12:09, mmdanziger wrote:

Andrzej Kozlowski

unread,
Mar 10, 2010, 1:42:41 AM3/10/10
to
Actually, I have confirmed myself that PowerExpand with Assuming does
this correctly. The general result is:

PowerExpand[
r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

Assumptions -> True]

r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
(2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
Arg[r^3 + r + 2]/(2*Pi) + 1/2])

and inspecting it, it is not surprising that

In[42]:= PowerExpand[


r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

Assumptions -> Arg[r] == 0]

0

PowerExpand[
r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

Assumptions -> Arg[r] == Pi]

0

This also works:

Simplify[
PowerExpand[r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],
Assumptions -> Element[r, Reals]], Element[r, Reals]]
0

I think I was too hasty to state that the failure of Simplify to get the
right answer with the assumption r<0 is a bug. Clearly Simplify and
FullSimplify to not use PowerExpand (with Assumptions). Judging by the
complicated expression returned by PowerExpand above, this is probably
justified on the grounds of performance. On the other hand, it seems to
me that Reduce ought to be able to do better in the example below.

Andrzej Kozlowski

Andrzej Kozlowski

unread,
Mar 10, 2010, 1:45:27 AM3/10/10
to
It seems better to use:

Assuming[Element[r, Reals],
PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]

0

PowerExpand with Assumptions ought to be as reliable as Simplify (which
does not work in this case), whereas if you use it without assumptions
it can return answers that will be false for some values of the
variables (it makes use of the maximal assumptions that permit the
expansion). The fact that Simplify works here with the assumption r>=0
but not r<0 appears to be a bug.

Andrzej Kozlowski


On 9 Mar 2010, at 12:19, dh wrote:

> Hi,
> Sqrt is a multivalued function. Therefore, your expression is not

> necessarily zero. If you are sure that all your variables are real and=

> that you only want the main branch of Power, then you can use =


PowerExpand:
> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
> Daniel
>
> On 08.03.2010 12:09, mmdanziger wrote:

>> This isn't the first time that I've encountered something like this =


in
>> Mathematica but in my calculations I got a term like this:
>>
>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>>

>> Which is obviously identically zero. For some reason Simplify or =


even
>> FullSimplify can't figure this out. Once you get dependent on

>> Mathematica these things are pretty disturbing...you forget about =


your
>> own knowledge because the program tells you that things are
>> different. Then you sit there like an idiot checking an algebraic

>> identity that any beginning precalc student should be able to solve =


no
>> problem.
>>
>> Is there any way to get Mathematica to "wake up" to these things? It

>> has such a powerful algebraic engine for most things, why can't it =


see
>> something simple like the above? Do you really have to manually
>> override and tell the program when things should be zero?
>>
>> For the time being I'll just sift through and test things by hand but
>> I can't believe that there isn't a better way.
>>
>> Best,
>> md
>>
>
>

Andrzej Kozlowski

unread,
Mar 10, 2010, 1:45:38 AM3/10/10
to

On 9 Mar 2010, at 12:26, Simon wrote:

>
>
> In fact it can do better than that, and tell you exactly when it is
> zero:
>
> In[2]:= Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] ==
> 0, Reals]
> Out[2]= r <= -1 || r > 0
>

Well, actually, this does not mean what you think it means. The way to do it is:

Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
Element[r, Reals], r]

and then you will see that Reduce can't do it. In fact

r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] /.
r -> -1/2

0

Andrzej Kozlowski

schochet123

unread,
Mar 10, 2010, 1:50:23 AM3/10/10
to
On Mar 8, 1:09 pm, mmdanziger <mmdanzi...@gmail.com> wrote:
> This isn't the first time that I've encountered something like this in
> Mathematica but in my calculations I got a term like this:
>
> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>
> Which is obviously identically zero. For some reason Simplify or even
> FullSimplify can't figure this out.

Actually, since Mathematica works over the complex numbers that
expression is NOT identically zero:

expr = r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)];

FindInstance[expr != 0, r] // InputForm

{{r -> 42/5 + (82*I)/5}}

However, Mathematica can't find an example with r real:

FindInstance[expr != 0 && Element[r, Reals], r]

FindInstance::nsmet: The methods available to FindInstance are
insufficient to find the requested instances or prove they do not
exist.

Telling Mathematica that r is positive enables it to simplify the
expression:

Simplify[expr, r > 0]

0

It often helps to try Reduce instead of Simplify, but even that does
not yield the complete answer here:

Reduce[expr == 0 && Element[r, Reals], r, Complexes] // InputForm

During evaluation of In[5]:= Reduce::cpow: Reduce was unable to prove


that a radical of an expression containing only real variables and
parameters is real valued. If you are interested only in solutions for
which all radicals contained in the input are real valued, use Reduce
with domain argument Reals. >>

Reduce[expr == 0, r, Reals] // InputForm

r <= -1 || r > 0

So the best Mathematica can do is to show that the expression is zero
when r is real and does not lie in the interval (-1,0]. When r=0 then
the expression is Indeterminate since the first term has the form zero
times infinity. The interval (-1,0) is precisely where the arguments
of the square roots are negative. For such values whether the
expression equals zero depends on the choice of branch of the square
root. Although the expression does equal zero for the choice of branch
made by Mathematica, Simplify and Reduce apparently do not rely on a
particular branch being used (except that the positive branch is used
for roots of positive numbers).

Steve

Adam Strzebonski

unread,
Mar 10, 2010, 1:51:05 AM3/10/10
to
All that Assuming does is locally changing the value of $Assumptions.

Assuming[assum, expr]

is a shorthand for

Block[{$Assumptions = $Assumptions && assum}, expr]

All functions that take the Assumptions option, with the exception of
PowerExpand, have the default option setting of

Assuptions :> $Assumptions

This means that they will automatically use the value of $Assumptions,
whether it has been set with Assuming, or directly with

$Assumptions = assum

PowerExpand is an exception, its default option setting is

In[1]:= Options[PowerExpand]
Out[1]= {Assumptions -> Automatic}

where Automatic means that PowerExpand is allowed to assume that
all "simple" power and log expansion transformations are valid.
This is the expected default behaviour of PowerExpand.

In[2]:= PowerExpand[(a b)^c]

c c
Out[2]= a b

If Assumptions was set to $Assumptions, which by default evaluates
to True, PowerExpand would add terms that make the expansion valid
without any assumptions and the expected default behaviour would not
be preserved.

In[3]:= PowerExpand[(a b)^c, Assumptions :> $Assumptions]

c c (2 I) c Pi Floor[1/2 - Arg[a]/(2 Pi) - Arg[b]/(2 Pi)]
Out[3]= a b E

Best Regards,

Adam Strzebonski
Wolfram Research

Andrzej Kozlowski wrote:
> In fact, I was wrong, and I forgot of something I once new (or assumed that it had been "fixed"). Assuming has no effect on PowerExpand and the answer returned is completely misleading. For example:
>
> Assuming[Im[r] != 0,
> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
> 0
>
> which is of course wrong.
>
> PowerExpand only works with Assumptions passed view the Assumptions -> ... method and then the answer is very complicated:
>
> PowerExpand[
> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],
> Assumptions -> Element[r, Reals]]
>
> r^(3/2)*Sqrt[r^3 + r + 2]*
> E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
> (2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
> E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
> Arg[r^3 + r + 2]/(2*Pi) + 1/2])
>
> But, what is rather strange, this works:
>
> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)],
> Assumptions -> r <= 0]
>
> even though it does not work with Simplify and Reduce
>
> Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
> r < 0, r]

> Reduce::cpow: Reduce was unable to prove that a radical of an expression containing only real variables and parameters is real valued. If you are interested only in solutions for which all radicals contained in the input are real valued, use Reduce with domain argument Reals. >>
>

> The question is then, does PowerExpand really do that correctly? It would be reassuring if someone from WRI would confirm it. (Getting the right answer with PowerExpand itself is not very reassuring...).
>
> I remember a while ago there was already a discussion here concerning the fact that PowerExpand is probably the only function that admits Assumptions only in the form Assumptions -> and not via Assuming. I though that was going to be changed but it remains as it used to be. If changing this behaviour is really impossible I think there ought to be some sort of warning message that appears when one attempts to use
> Assuming[something,PowerExpand[expr]], for obvious reasons.
>
> Andrzej Kozlowski
>
>
> On 9 Mar 2010, at 14:22, Andrzej Kozlowski wrote:
>

>> It seems better to use:
>>
>> Assuming[Element[r, Reals],
>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>>
>> 0
>>
>> PowerExpand with Assumptions ought to be as reliable as Simplify (which does not work in this case), whereas if you use it without assumptions it can return answers that will be false for some values of the variables (it makes use of the maximal assumptions that permit the expansion). The fact that Simplify works here with the assumption r>=0 but not r<0 appears to be a bug.
>>
>> Andrzej Kozlowski
>>
>>
>>
>>
>> On 9 Mar 2010, at 12:19, dh wrote:
>>
>>> Hi,
>>> Sqrt is a multivalued function. Therefore, your expression is not
>>> necessarily zero. If you are sure that all your variables are real and

>>> that you only want the main branch of Power, then you can use PowerExpand:


>>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
>>> Daniel
>>>
>>> On 08.03.2010 12:09, mmdanziger wrote:

Adam Strzebonski

unread,
Mar 10, 2010, 1:51:16 AM3/10/10
to
Getting a complete description of the solution set of an equation
that contains complex-valued radicals requires taking into account
branch cuts of radicals. We need to introduce a new complex variable
for each radical and add inequalities on real and imaginary parts
of the variables. Hence a univariate equation in one real variable

r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
Element[r, Reals]

gets transformed into a quantifier elimination problem with
five real variables

Exists[{s1, s2},
s1^2 == (r^3 + r + 2)/r &&
s2^2 == r^3 (r^3 + r + 2) &&
(Re[s1]>0 || Re[s1]==0 && Im[s1]>=0) &&
(Re[s2]>0 || Re[s2]==0 && Im[s1]>=0) &&
r^2 s1 - s2 == 0 &&
Element[r, Reals]]

Since the cylindrical algebraic decomposition algorithm used
to solve such problems is doubly exponential in the number of
variables, the system generated this way is likely to take forever
to solve. However, this particular system is solved rather quickly,
so it turns out this method is not as hopeless as I would imagine.
Reduce will use it automatically in the next version of Mathematica.

In[1]:= Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
Element[r, Reals], r]

Out[1]= r < 0 || r > 0

Best Regards,

Adam Strzebonski
Wolfram Research

Andrzej Kozlowski wrote:
> Actually, I have confirmed myself that PowerExpand with Assuming does this correctly. The general result is:
>
> PowerExpand[

> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

> Assumptions -> True]


>
> r^(3/2)*Sqrt[r^3 + r + 2]*
> E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
> (2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
> E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
> Arg[r^3 + r + 2]/(2*Pi) + 1/2])
>

> and inspecting it, it is not surprising that
>
> In[42]:= PowerExpand[

> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

> Assumptions -> Arg[r] == 0]
>
> 0
>
> PowerExpand[

> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

> Assumptions -> Arg[r] == Pi]
>
> 0
>
> This also works:
>
> Simplify[

> PowerExpand[r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],

> Assumptions -> Element[r, Reals]], Element[r, Reals]]
> 0
>
> I think I was too hasty to state that the failure of Simplify to get the right answer with the assumption r<0 is a bug. Clearly Simplify and FullSimplify to not use PowerExpand (with Assumptions). Judging by the complicated expression returned by PowerExpand above, this is probably justified on the grounds of performance. On the other hand, it seems to me that Reduce ought to be able to do better in the example below.
>

Andrzej Kozlowski

unread,
Mar 10, 2010, 6:28:42 AM3/10/10
to
Yes, but why something like this could not just be added to Mathematica
to make life much easier to slightly sclerotic users?

Unprotect[Assuming];
Assuming[cond_, PowerExpand[expr_]] /; flag :=
Block[{flag}, PowerExpand[expr, Assumptions -> cond]]
flag = True;

Assuming[Element[r, Reals],

PowerExpand[r^2*Sqrt[(r^3 + r + 2)/r] -
Sqrt[r^3*(r^3 + r + 2)]]]

r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
(2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
Arg[r^3 + r + 2]/(2*Pi) + 1/2])

?

Andrzej Kozlowski

> Best Regards,
>
> Adam Strzebonski
> Wolfram Research
>
> Andrzej Kozlowski wrote:

>> In fact, I was wrong, and I forgot of something I once new (or =
assumed that it had been "fixed"). Assuming has no effect on PowerExpand =


and the answer returned is completely misleading. For example:
>>
>> Assuming[Im[r] != 0,
>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>> 0
>>
>> which is of course wrong.
>>

>> PowerExpand only works with Assumptions passed view the Assumptions =


-> ... method and then the answer is very complicated:
>>
>> PowerExpand[
>> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],
>> Assumptions -> Element[r, Reals]]
>>
>> r^(3/2)*Sqrt[r^3 + r + 2]*
>> E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
>> (2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
>> E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
>> Arg[r^3 + r + 2]/(2*Pi) + 1/2])
>>
>> But, what is rather strange, this works:
>>
>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)],
>> Assumptions -> r <= 0]
>>
>> even though it does not work with Simplify and Reduce
>>

>> Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 =
&&
>> r < 0, r]
>> Reduce::cpow: Reduce was unable to prove that a radical of an =
expression containing only real variables and parameters is real valued. =
If you are interested only in solutions for which all radicals contained =


in the input are real valued, use Reduce with domain argument Reals. >>
>>

>> The question is then, does PowerExpand really do that correctly? It =
would be reassuring if someone from WRI would confirm it. (Getting the =


right answer with PowerExpand itself is not very reassuring...).
>>

>> I remember a while ago there was already a discussion here concerning =
the fact that PowerExpand is probably the only function that admits =
Assumptions only in the form Assumptions -> and not via Assuming. I =
though that was going to be changed but it remains as it used to be. If =
changing this behaviour is really impossible I think there ought to be =


some sort of warning message that appears when one attempts to use
>> Assuming[something,PowerExpand[expr]], for obvious reasons.
>>
>> Andrzej Kozlowski
>>
>>
>> On 9 Mar 2010, at 14:22, Andrzej Kozlowski wrote:
>>
>>> It seems better to use:
>>>
>>> Assuming[Element[r, Reals],
>>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>>>
>>> 0
>>>

>>> PowerExpand with Assumptions ought to be as reliable as Simplify =
(which does not work in this case), whereas if you use it without =
assumptions it can return answers that will be false for some values of =
the variables (it makes use of the maximal assumptions that permit the =
expansion). The fact that Simplify works here with the assumption r>=0 =


but not r<0 appears to be a bug.
>>>
>>> Andrzej Kozlowski
>>>
>>>
>>>
>>>
>>> On 9 Mar 2010, at 12:19, dh wrote:
>>>
>>>> Hi,

>>>> Sqrt is a multivalued function. Therefore, your expression is not=

>>>> necessarily zero. If you are sure that all your variables are real =
and
>>>> that you only want the main branch of Power, then you can use =


PowerExpand:
>>>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
>>>> Daniel
>>>>
>>>> On 08.03.2010 12:09, mmdanziger wrote:

>>>>> This isn't the first time that I've encountered something like =


this in
>>>>> Mathematica but in my calculations I got a term like this:
>>>>>
>>>>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]
>>>>>

>>>>> Which is obviously identically zero. For some reason Simplify or =


even
>>>>> FullSimplify can't figure this out. Once you get dependent on

>>>>> Mathematica these things are pretty disturbing...you forget about =


your
>>>>> own knowledge because the program tells you that things are
>>>>> different. Then you sit there like an idiot checking an algebraic

>>>>> identity that any beginning precalc student should be able to =
solve no
>>>>> problem.
>>>>>
>>>>> Is there any way to get Mathematica to "wake up" to these things? =
It
>>>>> has such a powerful algebraic engine for most things, why can't it =


see
>>>>> something simple like the above? Do you really have to manually
>>>>> override and tell the program when things should be zero?
>>>>>

>>>>> For the time being I'll just sift through and test things by hand =


but
>>>>> I can't believe that there isn't a better way.
>>>>>
>>>>> Best,
>>>>> md
>>>>>
>>>>

Adam Strzebonski

unread,
Mar 11, 2010, 6:37:51 AM3/11/10
to
It could be added, but then somebody might be even more
surprised when

Assuming[x<0, PowerExpand[Sqrt[x^2]]]

would give -x, but

Assuming[x<0, PowerExpand[Sqrt[x^2]]===-x]

would give False.

If we made PowerExpand use assumptions when called anywhere inside
Assuming, it would break examples where the user expects PowerExpand
with the default option settings to make syntactic transformations
that do not check the assumed values of symbols. For instance

In[1]:= Assuming[x<0, {PowerExpand[Sqrt[x^2]], Refine[Sqrt[x^2]]}]

Out[1]= {x, -x}

might be meant as a demonstration of the fact that the "obvious"
simplification is not always correct.

Best Regards,

Adam Strzebonski
Wolfram Research

Andrzej Kozlowski wrote:
> Yes, but why something like this could not just be added to Mathematica to make life much easier to slightly sclerotic users?
>
> Unprotect[Assuming];
> Assuming[cond_, PowerExpand[expr_]] /; flag :=
> Block[{flag}, PowerExpand[expr, Assumptions -> cond]]
> flag = True;
>
> Assuming[Element[r, Reals],

> PowerExpand[r^2*Sqrt[(r^3 + r + 2)/r] -

>>> In fact, I was wrong, and I forgot of something I once new (or assumed that it had been "fixed"). Assuming has no effect on PowerExpand and the answer returned is completely misleading. For example:


>>>
>>> Assuming[Im[r] != 0,
>>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>>> 0
>>>
>>> which is of course wrong.
>>>

>>> PowerExpand only works with Assumptions passed view the Assumptions -> ... method and then the answer is very complicated:


>>>
>>> PowerExpand[
>>> r^2*Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3*(r^3 + r + 2)],
>>> Assumptions -> Element[r, Reals]]
>>>
>>> r^(3/2)*Sqrt[r^3 + r + 2]*
>>> E^(I*Pi*Floor[Arg[r]/(2*Pi) - Arg[r^3 + r + 2]/
>>> (2*Pi) + 1/2]) - r^(3/2)*Sqrt[r^3 + r + 2]*
>>> E^(I*Pi*Floor[-((3*Arg[r])/(2*Pi)) -
>>> Arg[r^3 + r + 2]/(2*Pi) + 1/2])
>>>
>>> But, what is rather strange, this works:
>>>
>>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)],
>>> Assumptions -> r <= 0]
>>>
>>> even though it does not work with Simplify and Reduce
>>>

>>> Reduce[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] == 0 &&
>>> r < 0, r]
>>> Reduce::cpow: Reduce was unable to prove that a radical of an expression containing only real variables and parameters is real valued. If you are interested only in solutions for which all radicals contained in the input are real valued, use Reduce with domain argument Reals. >>
>>>
>>> The question is then, does PowerExpand really do that correctly? It would be reassuring if someone from WRI would confirm it. (Getting the right answer with PowerExpand itself is not very reassuring...).
>>>
>>> I remember a while ago there was already a discussion here concerning the fact that PowerExpand is probably the only function that admits Assumptions only in the form Assumptions -> and not via Assuming. I though that was going to be changed but it remains as it used to be. If changing this behaviour is really impossible I think there ought to be some sort of warning message that appears when one attempts to use


>>> Assuming[something,PowerExpand[expr]], for obvious reasons.
>>>
>>> Andrzej Kozlowski
>>>
>>>
>>> On 9 Mar 2010, at 14:22, Andrzej Kozlowski wrote:
>>>
>>>> It seems better to use:
>>>>
>>>> Assuming[Element[r, Reals],
>>>> PowerExpand[r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)]]]
>>>>
>>>> 0
>>>>

>>>> PowerExpand with Assumptions ought to be as reliable as Simplify (which does not work in this case), whereas if you use it without assumptions it can return answers that will be false for some values of the variables (it makes use of the maximal assumptions that permit the expansion). The fact that Simplify works here with the assumption r>=0 but not r<0 appears to be a bug.

>>>>
>>>> Andrzej Kozlowski
>>>>
>>>>
>>>>
>>>>
>>>> On 9 Mar 2010, at 12:19, dh wrote:
>>>>
>>>>> Hi,
>>>>> Sqrt is a multivalued function. Therefore, your expression is not

>>>>> necessarily zero. If you are sure that all your variables are real and
>>>>> that you only want the main branch of Power, then you can use PowerExpand:


>>>>> r^2 Sqrt[(r^3 + r + 2)/r] - Sqrt[r^3 (r^3 + r + 2)] // PowerExpand
>>>>> Daniel
>>>>>
>>>>> On 08.03.2010 12:09, mmdanziger wrote:

0 new messages