Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: InequalitySolve with algebraic numbers and Simplify

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23004] Re: [mg22987] InequalitySolve with algebraic numbers and Simplify
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Mon, 10 Apr 2000 02:22:31 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

on 00.4.9 2:45 PM, Gianluca Gorni at gorni at dimi.uniud.it wrote:

> 
> Hello!
> 
> I had a system of *linear* inequalities in two variables x,y,
> with simple algebraic numbers as coefficients,
> to solve with InequalitySolve[], and I naively assumed
> that the solution would be a set of likewise *linear*
> inequalities. So I was surprised at results like this:
> 
> Needs["Algebra`InequalitySolve`"]
> 
> InequalitySolve[{y <= x*Sqrt[2], y <= x}, {x, y}]
> 
> x <= 0 && y <= -(Sqrt[2]*Sqrt[x^2]) || x > 0 && y <= x
> 
> Strictly speaking the result is correct, but it does not look
> good, because of that Sqrt[x^2]. I tried with
> Experimental`CylindricalAlgebraicDecomposition,
> but it gives exactly the same answer.
> 
> Trying to reduce the results to a more manageable form, I
> met some somewhat disappointing behaviour of Simplify[]
> with assumptions (of Mathematica version 4):
> 
> In:   Simplify[Sqrt[x^2], x == 1 + Sqrt[2]]
> 
> Out:  Sqrt[x^2]
> 
> It seems that Mathematica doesn't notice that 1+Sqrt[2] is real and
> positive! So let's teach Mathematica that it is real, at least:
> 
> In:  Simplify[Sqrt[x^2], {Element[x, Reals], x == 1 + Sqrt[2]}]
> 
> Out: x
> 
> Somehow I would have expected the answer to be 1+Sqrt[2], what
> about you? Even if x has a smaller LeafCount than 1+Sqrt[2].
> 
> Best regards,
> 
> Gianluca Gorni


It seems to me that you have come across some unpleasant quirks in
Mathematica if not exactly bugs. As for the first one, I don't now exactly
the cause of it but in general it seems that Mathematica generally has
problems with expressions like Sqrt[x^2] in logical expressions. For
example, compare the following behaviour:

In[1]:=
And[x < 3, x < 2] // Simplify
Out[1]=
x < 2

In[2]:=
And[x < 4, x > 5] // Simplify
Out[2]=
False

In[3]:=
And[x > 3, x^2 < 9] // Simplify
Out[3]=
False


In[4]:=
And[x > 3, Sqrt[x^2] < 3] // Simplify
Out[4]=
               2
x > 3 && Sqrt[x ] < 3

That last one should have been false, of course. On the other Simplify with
assumptions behaves correctly in such cases:

In[5]:=
Simplify[x > 3, Sqrt[x^2] < 3]

Out[5]=
False

This makes me feel that it should not be impossible to fix the first problem
you pointed out. For example one might define a function:

mysimplify[expr_] :=
  expr /. And[LessEqual[x_, 0], y_] /; Not[FreeQ[y, x]] :>
      And[LessEqual[x, 0], Simplify[y, LessEqual[x, 0]]]

Now, 

In[7]:=
Experimental`CylindricalAlgebraicDecomposition[{y <= x*Sqrt[2], y <= x},
{x,y}]


Out[7]=
                              2
x <= 0 && y <= -Sqrt[2] Sqrt[x ] || x > 0 && y <= x


We can improve this by applying mysimplify

In[8]:=
mysimplify[%]

Out[8]=
x <= 0 && y <= Sqrt[2] x || x > 0 && y <= x

gives the kind of answer one would expect. Of course one would need
something a lot more sophisticated to deal with all the cases in which this
sort of problem may arise.


The second one has indeed something to do with the ComplexityFunction.
Mathematica does indeed give;

In[9]:=
Simplify[Sqrt[x^2], { x == 1 + Sqrt[2]}]

Out[9]=
      2
Sqrt[x ]

Suppose however, we define a complexity function f by:

cf[expr_] := Count[expr, _?(Not[NumericQ[#]] &), {0, Infinity}]

Now we notice something curious:

In[11]:=
Simplify[Sqrt[x^2], { x == 1 + Sqrt[2]}, ComplexityFunction -> cf]

Out[11]=
Sqrt[3 + 2 Sqrt[2]]

That's a bit weird. If we try FullSimplify (Simplify does not work here!) we
indeed get:

In[12]:=
FullSimplify[%]

Out[12]=
1 + Sqrt[2]

Why did we not get this answer the first time? Both 1+Sqrt[2] and Sqrt[3 + 2
Sqrt[2]] have the same value of cf, namely 0, but of course the firs tone
has much smaller LeafCount. It seems that Simplify never considered the
simpler answer. This happens even if we modify cf so as to make
cf[1+Sqrt[2]]  explicitly smaller than cf[Sqrt[3 + 2 Sqrt[2]]:

In[16]:=
Clear[cf]

In[17]:=
cf[expr_] := 
  10*Count[expr, _?(Not[NumericQ[#]] &), {0, Infinity}] + LeafCount[expr]

In[18]:=
cf[1 + Sqrt[2]]

Out[18]=
7

In[19]:=
cf[Sqrt[3 + 2*Sqrt[2]]]

Out[19]=
13


However:

In[20]:=
Simplify[Sqrt[x^2], { x == 1 + Sqrt[2]}, ComplexityFunction -> cf]

Out[20]=
Sqrt[3 + 2 Sqrt[2]]

Fortunately

In[21]:=
FullSimplify[Sqrt[x^2], { x == 1 + Sqrt[2]}, ComplexityFunction -> cf]

Out[21]=
1 + Sqrt[2]

Note also that with the previous complexity function cf, which is zero on
both 1+Sqrt[2] and Sqrt[3 + 2 Sqrt[2]]) even FullSimplify chooses the latter
answer!. All of it does seem weirs and in need of improvement.


--
Andrzej Kozlowski
Toyama International University
Toyama, Japan




  • Prev by Date: Re: list manipulation, mean value
  • Next by Date: Product of the first 1000th Prime
  • Previous by thread: InequalitySolve with algebraic numbers and Simplify
  • Next by thread: Re: InequalitySolve with algebraic numbers and Simplify