Re: FullSimplify with Pi
- To: mathgroup at smc.vnet.net
- Subject: [mg84141] Re: [mg84129] FullSimplify with Pi
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 11 Dec 2007 06:11:30 -0500 (EST)
- References: <200712110320.WAA26066@smc.vnet.net>
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 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
- References:
- FullSimplify with Pi
- From: Uberkermit <chris.r.sims@gmail.com>
- FullSimplify with Pi