Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: FullSimplify with Pi

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84152] Re: [mg84129] FullSimplify with Pi
  • From: Adam Strzebonski <adams at wolfram.com>
  • Date: Tue, 11 Dec 2007 15:32:28 -0500 (EST)
  • References: <200712110320.WAA26066@smc.vnet.net> <706CBD72-28F5-459D-A2F9-994E4F124022@mimuw.edu.pl>
  • Reply-to: adams at wolfram.com

Andrzej Kozlowski wrote:
> 
> On 11 Dec 2007, at 12:20, Uberkermit wrote:
> 
>> Greetings,
>>
>> I would like to simplify an expression involving Pi. Actually,
>> simplifying the expression isn't hard, getting Mathematica to
>> recognize the simplification is the hard part. Consider:
>>
>> Assuming[Element[x, Reals],
>>  FullSimplify[Log[1/Sqrt[2 Pi] Exp[x]]]]
>>
>> Mathematica doesn't do anything to simplify this. However, replacing
>> the symbol Pi with any other variable in the above leads to the
>> trivial substitutions.
>>
>> By trivial, I mean:
>> Log[Exp[x]] = x, and Log[a/b] = Log[a] - Log[b].
>>
>> Why does Pi confuse Mathematica so??
>>
>> Thanks,
>> -Chris
>>
> 
> Well, how to put it, everything is the other way round. According to 
> Mathematica's default ComplexityFunction (which is very close to 
> LeafCount) the expression that you get when you use Pi is simpler:
> 
> p = Assuming[Element[x, Reals],
>    FullSimplify[Log[E^x/Sqrt[2*a]]]]
> x - Log[a]/2 - Log[2]/2
> 
> q = Assuming[Element[x, Reals],
>    Simplify[Log[E^x/Sqrt[2*Pi]]]]
> 
> x - (1/2)*Log[2*Pi]
> 
> Now compare the LeafCount :
> 
> LeafCount /@ {p, q}
> {14, 10}
> 
> q is smaller so the second expression is "simpler". So there are two 
> questions that one may wish to ask now.
> 1. Why does FullSimplify return the "simpler" expression in the case of Pi?
> 2. How to make FullSimplify return the expanded form of the expression 
> in the case of Pi.
> 
> Let's start with the easier question, that is the second. Of course one 
> way would be to use a replacement rule, but that is not the point here. 
> What you need to do is to use a ComplexityFunction that will make an 
> expanded expression simpler. One has to find a good choice; for example 
> if we try to maximize the number of Logs we will get:
> 
>  Assuming[Element[x, Reals], FullSimplify[Log[E^x/Sqrt[2*Pi]], 
> ComplexityFunction ->
>      (LeafCount[#1] - 6*Count[#1, Log, Infinity, Heads -> True] & )]]
> 
> Log[E^x] - Log[Pi]/2 - Log[2]/2
> 
> which is not what we wanted.
> 
> One possibility is to minimize the complexity of the expression inside 
> Log. Here is one attempt:
> 
>  Assuming[Element[x, Reals],
>   FullSimplify[Log[E^x/Sqrt[2*Pi]], ComplexityFunction ->
>          (LeafCount[#1] +
>        10*Max[0, Cases[{#1}, Log[x_] :> LeafCount[x], Infinity]] & )]]
> 
> x - Log[Pi]/2 - Log[2]/2
> 
> The ComplexityFunction is pretty complicated, I am sure it is possible 
> to find a simpler one but I don't wish to spend any time on this.
> 
> Now question one. Why does the expansion take place in the first case? 
> Well, I would speculate that this is related to the following strange 
> behaviour:
> 
> FullSimplify[x + Log[a]/2 + Log[2]/2]
> 
> x + (1/2)*Log[2*a]
> 
>  FullSimplify[x + Log[a]/2 + Log[2]/2]
> 
>  x + (1/2)*Log[2*a]
> 
> FullSimplify[x - Log[a]/2 - Log[2]/2]
>  x - Log[a]/2 - Log[2]/2
> 
> Just to confirm:
> 
>  LeafCount[x - Log[a]/2 - Log[2]/2]
>  14
>  LeafCount[x - 1/2 log(2 a)]
> 10
> 

The second simplification is harder to make. (Full)Simplify
tries various transformations and keeps only the simplest form
found so far. In both examples the Together'ed forms are more
useful for further simplification. However, only in the first
example the Together'ed form has a lower LeafCount and is kept.
In the second example the Together'ed form has a higher
LeafCount and is rejected.


In[6]:= {x + Log[a]/2 + Log[2]/2, x - Log[a]/2 - Log[2]/2}

              Log[2]   Log[a]      Log[2]   Log[a]
Out[6]= {x + ------ + ------, x - ------ - ------}
                2        2           2        2

In[7]:= LeafCount/@%

Out[7]= {14, 14}

In[8]:= Together[%%]

          2 x + Log[2] + Log[a]  2 x - Log[2] - Log[a]
Out[8]= {---------------------, ---------------------}
                    2                      2

In[9]:= LeafCount/@%

Out[9]= {12, 16}

In the current development version FullSimplify has more
transformation rules and can make this simplification.

In[1]:= FullSimplify[x - Log[a]/2 - Log[2]/2]

             Log[2 a]
Out[1]= x - --------
                2

Best Regards,

Adam Strzebonski
Wolfram Research


> So it does look like an imperfection in FullSimplify but of a somewhat 
> different kind than the one you had in mind. I believe that the cause of 
> it all lies in the following behaviour:
> 
> Simplify[Sqrt[2*a]]
> Sqrt[2]*Sqrt[a]
> 
> Simplify[Sqrt[2*Pi]]
> Sqrt[2*Pi]
> 
> Andrzej Kolowski
> 
> 
> 
> 
> 



  • Prev by Date: Re: ContourPlotOnSurface
  • Next by Date: Re: Vieta infinite product formula
  • Previous by thread: Re: FullSimplify with Pi
  • Next by thread: Re: FullSimplify with Pi