MathGroup Archive 2009

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

Search the Archive

Re: Simplify

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98684] Re: [mg98659] Simplify
  • From: dh <dh at metrohm.com>
  • Date: Thu, 16 Apr 2009 04:14:40 -0400 (EDT)
  • References: <200904150902.FAA08151@smc.vnet.net> <ACCF1343-E098-469B-A599-4CA4F9E1A5E0@mimuw.edu.pl> <49E5CA92.7030005@metrohm.com> <7379A405-70A4-404B-8ACB-B4367F9A5A2A@mimuw.edu.pl>

Hi Andrzej,
which version of Mathematica do you have? In version 7.0.1 Simplify seems to 
have changed.
Your example:

 > FullSimplify[2*6^z - 6^z]
 > 2^(z + 1)*3^z - 6^z

in my version:
Simplify[2*6^z - 6^z]
6^z

Daniel

Andrzej Kozlowski wrote:
> Yes, you are right but I still think it is beside the point. Consider 
> this rather more striking (in my opinion) example.
> 
> let
> 
> expr = 2^(z + 1)*3^z
> 
> You can easily see that this can be re-written as 2*6^z and that:
> 
> LeafCount[Hold[2*6^z]]
>  6
> 
> while
> 
> LeafCount[expr]
> 9
> 
> so  2*6^z has a much smaller LeafCount than expr, but you can never 
> Simplify expr to 2*6^z because the Evaluator will always rewrite it 
> again as expr. This has a rather unpleasant consequence:
> 
> FullSimplify[2*6^z - 6^z]
> 2^(z + 1)*3^z - 6^z
> 
> Simplify cannot see that the simplest answer if 6^z (no matter what 
> ComplexityFunction you use) because immediately on evaluation 2*6^z is 
> converted to expr above and then it is too late; Simplify can't see that 
> the first term is simply twice the second term. Yet Simplify has no 
> problem noticing that:
> 
> Simplify[2*6^z - 6^z == 6^z]
> True
> 
> The reason for the problem is the following "canonical form":  
> expressions like  (a^k1*b^k2*c^k3...)^z *(a*l1*b^l2*...) where a, b, c 
> are positive are re-written as a^(k1+l1)*b^(k2+l2)*....
> 
> For example
> 
> (2^u*5^v)*(2*3^w*5^z)
> 2^(u + 1) 3^w 5^(v + z)
> 
> (actually the rule used is note general, but I just want to give an 
> example of a "canonical form" that causes trouble).
> 
> Since these reductions are made by the Evaluator, Simplify has no effect 
> on them. But because of them we get the following inconsistent behaviour:
> 
> 2*5^z - 5^z
> 5^z
> 
> but
> 
> 2*6^z - 6^z
> 2^(z + 1)*3^z - 6^z
> 
> 
> This, of course, cannot be changed by applying Simplify with any 
> ComplexityFunction because canonical forms can't be changed by Simplify 
> (unless you apply Hold).
> 
> Andrzej
> 
> 
> 
> 
> 
> 
> 
> 
> On 15 Apr 2009, at 20:52, dh wrote:
> 
>> Hi Andrzej,
>> thanks for your helpfull explanations.
>> Let me just mention that there is an additional reason, internally the 
>> expression x^2/y^2 is rewritten and has the the same leaf count as 
>> (x/y)^2. Consider:
>> FullForm[Hold[x^2/y^2]]
>> FullForm[x^2/y^2]
>> Daniel
>>
>>
>> Andrzej Kozlowski wrote:
>>> Actually, this point has been explained many times (by me ;-))
>>> (I like to think of Mathematica's evaluation process in terms of 
>>> something called "The Evaluator", which I think I first found in 
>>> David Wagner's book "Power Programming with Mathematica". I think it 
>>> is only an abstraction, along with "the Parser", "the Typesetter" 
>>> etc, but a convenient one when one is thinking about the evaluation 
>>> process. )
>>> The "Evaluator" always evaluates
>>> (x/y)^2
>>> to
>>> x^2/y^2
>>> This happens before Simplify takes any effect. Even if Simplify 
>>> converted x^2/y^2 to (x/y)^2  the Evaluator would kick in and again 
>>> convert  it back to x^2/y^2. Since the Evaluator always overrides 
>>> Simplify there is no way to get (x/y)^2 as the output without using 
>>> Hold.
>>> Perhaps you are asking why Mathematica (or the "Evaluator") 
>>> automatically converts (x/y)^2 to  x^2/y^2. It's because of something 
>>> called "canonical forms" or "standard forms". Basically, in order to 
>>> optimize performance in computer algebra systems one want to reduce 
>>> to 0 as quickly as possible as many expressions that are actually 
>>> equal. The earlier you do this the better the performance. If you 
>>> allow expressions to contain a large number of subexpressions that 
>>> are actually 0 until you apply Simplify, it may very seriously impair 
>>> performance. "Canonical forms" (or "normal forms", there is a slight 
>>> difference between them but I shall ignore it) are certain unique 
>>> forms to which various expressions are reduced automatically by the 
>>> Evaluator (before applying Simplify). This has the effect causing 
>>> cancellations to occur early. Also, these "canonical forms" have to 
>>> be independent of any particular ComplexityFunction used, hence the 
>>> reduction has to be performed outside Simplify. The advantage of 
>>> using canonical forms independent of ComplexityFunction is that they 
>>> often enable Mathematica to identify two expressions as equal even if 
>>> Simplify can't fine a sequence of Complexity reducing transformations 
>>> that will convert one expression into the other.
>>> Not surprisingly, using "canonical forms" can sometimes produce 
>>> undesirable side-effects and this is one of them (a rather minor one, 
>>> worse ones do occur).
>>> Andrzej Kozlowski
>>> Andrzej Kozlowski
>>> On 15 Apr 2009, at 18:02, dh wrote:
>>>>
>>>>
>>>> Hi,
>>>>
>>>> can somebody explain, why
>>>>
>>>> Simplify[x^2/y^2,ComplexityFunction->LeafCount]
>>>>
>>>> does not simplify to (x/y)^2, although the LeafCount is:
>>>>
>>>> LeafCount[Hold[x^2/y^2]] gives 10
>>>>
>>>> and
>>>>
>>>> LeafCount[Hold[(x/y)^2]] gives 8
>>>>
>>>>
>>>>
>>>> Daniel
>>>>
>>>>
>>>>
>>
>>
>> -- 
>>
>> Daniel Huber
>> Metrohm Ltd.
>> Oberdorfstr. 68
>> CH-9100 Herisau
>> Tel. +41 71 353 8585, Fax +41 71 353 8907
>> E-Mail:<mailto:dh at metrohm.com>
>> Internet:<http://www.metrohm.com>
>>
> 
> 
> 
> 


-- 

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



  • References:
  • Prev by Date: Re: Simplify
  • Next by Date: Re: Simplify
  • Previous by thread: Re: Simplify
  • Next by thread: Re: Simplify