[Date Index]
[Thread Index]
[Author Index]
Re: Re: ComplexityFunction affects set of transformations tried by Simplify
Daniel Huber has written to point out something that probably should
have been obvious (if I still had the time and patience to try to
interpret posts to this group other than literally), namely:
expr1 = Sqrt[c + d/k](c k + d)^2;
In this case you indeed do get:
In[2]:=
Simplify[expr1, k > 0, ComplexityFunction -> LeafCount]
Out[2]=
Sqrt[c + d/k]*(d + c*k)^2
and
In[3]:=
Simplify[expr1, k > 0, ComplexityFunction -> Depth]
Out[3]=
(d + c*k)^(5/2)/Sqrt[k]
It is also true that the last output has a lower LeafCount than the
original input. Does it them mean that "ComplexityFunction affects
set of transformations tried by Simplify"? I don't think so. I think
it is simply a consequence of the fact t, that Simplify accepts the
result of transformation for further transforming if it has a lower
value of ComplexityFunciton. So in order to get from expr1 to expr2,
in needs to find a sequence of intermediate expressions, say inter[1]
=expr1,inter[2],..., inter[n]=expr2 such that ComplexityFunction[inter
[n]] <ComplexityFunction[inter[n-1]].
What happens then (I believe) is that Simplify cannot find such a
sequence of steps wiht COmplexityFunction=LeafCount but can wiht
ComplexityFunction=Depth. Remember that it is not enough that the
final expression has a lower ComplexityFunction: each intermediate
expression must have a lower ComplexityFunction that the previous
one. So the set of TransformationFunctions that are uses is the same,
but the sequence of intermediate expressions is not.
Andrzej Kozlowski
On 21 Nov 2006, at 21:05, Andrzej Kozlowski wrote:
> On 21 Nov 2006, at 08:11, Schochet wrote:
>
>> Oops! I originally sent this as a reply to an unrelated thread.
>> Please reply only to this new version.
>>
>> As part of a large computation, I wanted Mathematica to
>> simplify expressions of the form Sqrt[c + d/k](c k + d)2,
>> where k is positive, to (c k + d)^(5/2)/Sqrt[k]
>>
>> Note that Mathematica knows that the two expressions
>> are equivalent:
>>
>> In[1]:=expr1 = Sqrt[c + d/k](c k + d)2;
>> expr2 = (c k + d)^(5/2)/Sqrt[k];
>> Simplify[expr1 == expr2, k > 0]
>>
>> Out[1]=True
>
> Rather unlikely, I would say. Consider that my Mathematica 5.1 gives:
>
> expr1 = Sqrt[c + d/k]*(d + c*k)*2;
> expr2 = (d + c*k)^(5/2)/Sqrt[k];
>
>
> Simplify[expr1 == expr2, k > 0]
>
>
> (d + c*k - 2)*Sqrt[d + c*k] == 0
>
> furthermore
>
> expr1 /. {d -> 1, c -> 0, k -> 1}
>
>
> 2
>
>
> expr2 /. {d -> 1, c -> 0, k -> 1}
>
>
> 1
>
> It kind of makes the rest of the message less interesting but...
>
>>
>> However Simplify with LeafCount as the ComplexityFunction
>> leaves expr1 unchanged, while Simplify with Depth as the
>> ComplexityFunction changes expr1 to expr2:
>>
>> In[3]:=Simplify[expr1, k > 0,
>> ComplexityFunction -> LeafCount] // InputForm
>>
>> Out[3]//InputForm=Sqrt[c + d/k]*(d + c*k)2
>>
>> In[4]:=Simplify[expr1, k > 0,
>> ComplexityFunction -> Depth] // InputForm
>>
>> Out[4]//InputForm=(d + c*k)^(5/2)/Sqrt[k]
>>
>> What explains this difference in behavior? Changing the order
>> of calculations 3 and 4 has no effect. Since calculation 2
>> shows that the form expr2 would be preferred if it were tried,
>> while calculation 4 shows that the form expr2 is tried when
>> the ComplexityFunction is Depth, it seems that the choice of
>> ComplexityFunction affects the set of transformations tried
>> by Simplify.
>
> Here I get:
>
>
> In[4]:=
> Simplify[expr1, k > 0, ComplexityFunction -> LeafCount]
>
> Out[4]=
> (2*(d + c*k)^(3/2))/Sqrt[k]
>
> In[6]:=
> Simplify[expr1, k > 0, ComplexityFunction -> Depth]
>
> Out[6]=
> (2*(d + c*k)^(3/2))/Sqrt[k]
>
>
> So, the way I see it there are two possibilities. One is, that there
> was something funny with the state of your Mathematica when you got
> those results. If not, then I am pleased that I have not upgraded
> from version 5.1 to 5.2 ;-)
>
> Andrzej Kozlowski
> Tokyo, Japan
>
>
>
>
Prev by Date:
**RE: Bookmarks in Mathematica ????**
Next by Date:
**Re: general form of a n-derivative**
Previous by thread:
**Re: ComplexityFunction affects set of transformations tried by Simplify**
Next by thread:
**Re: ComplexityFunction affects set of transformations tried by Simplify**
| |