Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Efficiency question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34714] Re: Efficiency question
  • From: ryan.shannon at bemail.org (Ryan Shannon)
  • Date: Sun, 2 Jun 2002 01:14:51 -0400 (EDT)
  • References: <ada1u7$kds$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thank you.  I stumbled upon Fold the same day I posted that question. 
That's a great function!

Interestingly, Mathematica doesn't take advantage of the gains to be had if n
is prime.

f[n_]:=If[PrimeQ[n], Sum[z^(k-1),{k,n}], Cyclotomic[n,z]]

This is quite a bit faster

********************************************************************
In[22]:=
\!\(f[n_] := If[PrimeQ[n], Sum[z\^\(k - 1\), {k, n}], Cyclotomic[n,
z]]\)

In[23]:=
Table[f[n]-Cyclotomic[n,z],{n,2,20}]

Out[23]=
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

In[24]:=
Timing[Table[Cyclotomic[n,z],{n,2,2000}];]

Out[24]=
{8.242 Second,Null}

In[25]:=
Timing[Table[f[n],{n,2,2000}];]

Out[25]=
{6.099 Second,Null}
*********************************************************************


  • Prev by Date: repeated entries in File>Palettes menu (again)
  • Next by Date: Package problem
  • Previous by thread: Re: Efficiency question
  • Next by thread: puzzling difference in speed