MathGroup Archive 2001

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

Search the Archive

Re: Pattern matching "on the fly" + Developer`ClearCache[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30119] Re: Pattern matching "on the fly" + Developer`ClearCache[]
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 29 Jul 2001 21:26:13 -0400 (EDT)
  • References: <9jvr9h$dof$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

(1+x)^(10^6)  (the original example). Andrzej's method is quicker as a
one-off calcuation. But the Series method that Bob and I suggested does some
cacheing and is quicker for repeats.

In fact it seems that it Series is not just cacheing but is loading code at
*any* first use.

Developer`ClearCache` does not seem to clear this code.
So ClearCache does not *always* give the worstcase timing.


Please  note that Quit[] must be evaluated as a separate input on each
occasion.

ORIGINAL: (1+x)^(10^6)

Quit[]

(x^n_^:=0/;n>2;          (*Andrzej*)
myexpand[f_,n_]:=
      Fold[Expand[#1^2*If[#2\[Equal]1,f,1]]&,f,
        Rest[IntegerDigits[n,2]]])//Timing

{0. Second,Null}

myexpand[(1+x),10^6];//Timing

{0.11 Second,Null}

No cacheing:

myexpand[(1+x),10^6];//Timing

{0.11 Second,Null}

Quit[]

(1+x)^(10^6)+O[x]^3//Normal;//Timing

{0.28 Second,Null}

(1+x)^(10^6)+O[x]^3//Normal;//Timing

{0.06 Second,Null}

Quit[]

*Any* use of Series seems to be sufficient.

Series[a,{b,c,0}];//Timing

{0.22 Second,Null}

(1+x)^(10^6)+O[x]^3//Normal;//Timing

{0. Second,Null}

Developer`ClearCache[] has little effect.

Developer`ClearCache[]

(1+x+O[x]^5)^(10^6)//Normal;//Timing

{0. Second,Null}



HIGHER POWER: (1+x)^(10^100)

Quit[]

(x^n_^:=0/;n>2;
myexpand[f_,n_]:=
      Fold[Expand[#1^2*If[#2\[Equal]1,f,1]]&,f,
        Rest[IntegerDigits[n,2]]])//Timing

{0. Second,Null}

myexpand[(1+x),10^100];//Timing

{1.92 Second,Null}

myexpand[(1+x),10^100];//Timing

{1.92 Second,Null}

Quit[]

(1+x)^(10^100)+O[x]^3//Normal;//Timing

{0.28 Second,Null}

(1+x)^(10^100)+O[x]^3//Normal;//Timing

{0. Second,Null}

Quit[]

*Any* use of Series seems to be sufficient.

Series[a,{b,c,0}];//Timing

{0.22 Second,Null}

(1+x)^(10^100)+O[x]^3//Normal;//Timing

{0. Second,Null}

Developer`ClearCache[] has little effect.

Developer`ClearCache[]

(1+x+O[x]^5)^(10^100)//Normal;//Timing

{0.05 Second,Null}

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Re: Pattern matching "on the fly"
  • Next by Date: Lost Line Directives in 3D Graphics
  • Previous by thread: Integrate[Sqrt[Tan[x]], {x, 0, 1}]
  • Next by thread: Lost Line Directives in 3D Graphics