       Re: Simplify[Abs[x],x<0]]

• To: mathgroup at smc.vnet.net
• Subject: [mg39355] Re: [mg39303] Simplify[Abs[x],x<0]]
• Date: Wed, 12 Feb 2003 03:53:13 -0500 (EST)
• References: <F49BA3AA-3D49-11D7-BC3F-000393A48D74@platon.c.u-tokyo.ac.jp>
• Sender: owner-wri-mathgroup at wolfram.com

```My experience with changing the defualt complexity function is
that for each complexity function there are cases in which
it does not agree with the intuitive notion of simplicity.
The more complicated the complexity function becomes the stranger
(and harder to understand) such examples get.

simple to understand way, and may be useful for small examples.
Certainly by its very definition it will produce answers that
have the smallest size when printed.

However, another important property that the default complexity
function should have is that computing its value should take
a negligible amount of time compared to the rest of the Simplify
algorithm. A complexity function that involves formatting of
expressions does not have this property.

In:= e=Sum[Random[Integer, {-10, 10}] x^i y^j z^k,
{i, 0, 4}, {j, 0, 4}, {k, 0, 4}];

In:= Simplify[e];//Timing

Out= {0.96 Second, Null}

In:= Simplify[e, ComplexityFunction ->

Out= {4.09 Second, Null}

Here computing the complexity function takes 3 times longer
then the rest of the Simplify algorithm (and a polynomial
is not the hardest expression to format).

One could try to find a function that estimates the size of
the printed expression, without quite formatting it, and the
current default complexity function gives a simply defined
estimate of size. Each such function, given it only estimates
the size of output, is bound to have cases where it is
incorrect, and we come back to my first comment, i.e. the more
complicated the complexity function the stranger its unintended
consequences.

Best Regards,

Wolfram Research

Andrzej Kozlowski wrote:
> In fact the following ComplexityFunction, (which I have used on this
> list before to deal with similar problems), works quite well:
>
> Simplify[Abs[x], x < 0, ComplexityFunction ->
>
>
> -x
>
>
> The only problem is that it penalizes functions with long names, like
> KroneckerDelta. If one could deal with that problem I think it would be
> the ideal choice for the default ComplexityFZunction in Simplify.
>
> Andrzej Kozlowski
>
> On Tuesday, February 11, 2003, at 07:23 AM, Andrzej Kozlowski wrote:
>
>> Yes, but although I have known this for years, I kept getting deceived
>> by this silly point. WOuld it not however be easier if the default
>> ComplexityFunction in Mathematica reflected more closely the "visible"
>> number of characters rather then the Mathematica FullForm? > (LeafCount).
>> It should be possible to create a "VisibleCharacterLength" function
>> that would do that.
>>
>> A.
>>
>> On Tuesday, February 11, 2003, at 12:47 AM, Adam Strzebonski wrote:
>>
>>> This is an issue of deciding what is simpler. With the default
>>> ComplexityFunction -x is not simpler than Abs[x]. Simplify's
>>> built in complexity measure is based on FullForm of expressions,
>>> rather than on the size of printed output.
>>>
>>> In:= LeafCount/@{-x, Abs[x]}
>>> Out= {3, 2}
>>>
>>> In:= -x // FullForm
>>> Out//FullForm= Times[-1, x]
>>>
>>> In:= Abs[x] // FullForm
>>> Out//FullForm= Abs[x]
>>>
>>> With a ComplexityFunction attributing additional weight to Abs
>>> Simplify will transform Abs[x] to -x.
>>>
>>> In:= f=1000 Count[#, _Abs, {0, Infinity}]+LeafCount[#]&;
>>>
>>> In:= Simplify[ Abs[x] , x<0, ComplexityFunction -> f ]
>>> Out= -x
>>>
>>> Best Regards,
>>>
>>> Wolfram Research
>>>
>>> Andrzej Kozlowski wrote:
>>>
>>>> Almost certainly an oversight. However, if you replace Abs by
>>>> something equivalent, things work as they should, e.g:
>>>> Simplify[Sqrt[x*Conjugate[x]], x < 0]
>>>> -x
>>>> or
>>>> Simplify[Sqrt[Im[x]^2 + Re[x]^2], x < 0]
>>>> -x
>>>> etc.
>>>> On Monday, February 10, 2003, at 03:07 PM, Uri Zwick wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Simplify[ Abs[x] , x>0 ] returns x.
>>>>> But, Simplify[ Abs[x] , x<0] returns Abs[x], and not -x.
>>>>>
>>>>> Why is that?
>>>>>
>>>>> Uri
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Andrzej Kozlowski
>>>> Yokohama, Japan
>>>> http://www.mimuw.edu.pl/~akoz/
>>>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>>
>>>
>>>
>>>
>>>
>>>
>> Andrzej Kozlowski
>> Yokohama, Japan
>> http://www.mimuw.edu.pl/~akoz/
>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>
>>
> Andrzej Kozlowski
> Yokohama, Japan
> http://www.mimuw.edu.pl/~akoz/
> http://platon.c.u-tokyo.ac.jp/andrzej/
>

```