Re: explanation need!

• To: mathgroup at smc.vnet.net
• Subject: [mg73471] Re: [mg73467] explanation need!
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Mon, 19 Feb 2007 01:24:22 -0500 (EST)
• References: <200702181113.GAA13442@smc.vnet.net>

```On 18 Feb 2007, at 12:13, dimitris wrote:

> Hello.
>
> Can somebody expalin the following code (which is used in order to
> "block" the use of the RootReduce function by FullSimplify; this
> example is adopted by Peter Pein's post here:
>
> lnk=gst&q=&rnum=9&hl=el#5155017508beef3b
> )
>
> In[7]:=
> << "Developer`"
> ClearCache[]
> s3 = Block[{RootReduce}, FullSimplify[Solve[1 + x^2 + x^3 == 0]]]
>
> More specifically why is needed to change context first?
> What does the function ClearCache here in particular?
> Should the following command give a different output?
>
> In[10]:=
> \$Context
>
> Out[10]=
> "Global`"
>
> Thanks a lot!
>
> Dimitris
>
>

<<Developer` does not change the context to Developer`, it only adds
the Developer` context to \$ContextPath. That you means you can use
ClearCache instead of Developer`ClearCache, that's all.
You only need to use CLearCache if you use Solve on your equation
more than once; since it will used Cashed  values instead of
recomputing them again. Just evaluate these two commands:

In[1]:=
FullSimplify[Solve[1 + x^2 + x^3 == 0]]

Out[1]=
{{x -> Root[#1^3 + #1^2 + 1 & , 1]}, {x -> Root[#1^3 + #1^2 + 1 & , 2]},
{x -> Root[#1^3 + #1^2 + 1 & , 3]}}

In[2]:=
Block[{RootReduce}, FullSimplify[Solve[1 + x^2 + x^3 == 0]]]

Out[2]=
{{x -> Root[#1^3 + #1^2 + 1 & , 1]}, {x -> Root[#1^3 + #1^2 + 1 & , 2]},
{x -> Root[#1^3 + #1^2 + 1 & , 3]}}

You see you get exactly the same answer and the second computation
takes no time at all. That makes it look as if using Block did not
help, while no computation was done in the second line but the cached
value of the answer from the first computation was used. However:

Developer`ClearCache[]

Block[{RootReduce}, FullSimplify[Solve[1 + x^2 + x^3 == 0]]]

{{x -> (1/3)*(-1 - (2/(29 - 3*Sqrt[93]))^(1/3) - ((1/2)*(29 - 3*Sqrt
[93]))^(1/3))},
{x -> (1/12)*(-4 + (2 - 2*I*Sqrt[3])*(2/(29 - 3*Sqrt[93]))^(1/3) +
2^(2/3)*(1 + I*Sqrt[3])*(29 - 3*Sqrt[93])^(1/3))},
{x -> (1/12)*(-4 + (2 + 2*I*Sqrt[3])*(2/(29 - 3*Sqrt[93]))^(1/3) +
2^(2/3)*(1 - I*Sqrt[3])*(29 - 3*Sqrt[93])^(1/3))}}

Finally, note that the idea of using FullSimplify without RootReduce
is not as brilliant as it might seem. If instead you use

Simplify[Solve[1 + x^2 + x^3 == 0]]

{{x -> (1/3)*(-1 - (2/(29 - 3*Sqrt[93]))^(1/3) - ((1/2)*(29 - 3*Sqrt
[93]))^(1/3))},
{x -> (1/12)*(-4 + (2 - 2*I*Sqrt[3])*(2/(29 - 3*Sqrt[93]))^(1/3) +
2^(2/3)*(1 + I*Sqrt[3])*(29 - 3*Sqrt[93])^(1/3))},
{x -> (1/12)*(-4 + (2 + 2*I*Sqrt[3])*(2/(29 - 3*Sqrt[93]))^(1/3) +
2^(2/3)*(1 - I*Sqrt[3])*(29 - 3*Sqrt[93])^(1/3))}}

you will get the same answer considerably quicker.

Andrzej Kozlowski

```

• Prev by Date: Re: grouping similar list elements with gaps
• Next by Date: Re: Re: Showing that a hypergeometric expression is 0?
• Previous by thread: explanation need!
• Next by thread: Re: explanation need!