MathGroup Archive 2008

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

Search the Archive

Re: Re: Re: Nested If

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92907] Re: [mg92857] Re: [mg92823] Re: [mg92779] Nested If
  • From: Syd Geraghty <sydgeraghty at me.com>
  • Date: Sat, 18 Oct 2008 06:24:18 -0400 (EDT)
  • References: <gcn4ge$7ad$1@smc.vnet.net> <200810120833.EAA08815@smc.vnet.net>

Thanks to Daniel Lichtblau for his reply to my question below.

His suggestion of using Table[-1, {ndivs}] instead of 
ConstantArray[-1, ndivs] for Mathematica V6 works fine as seen below.


countFirstDivisors =
  Compile[{{max, _Integer}, {ndivs, _Integer}},
   Module[{mlist = Table[-1, {ndivs}], primes = =
Prime[Range[ndivs]]},
    Do[Do[If[Mod[n, primes[[k]]] == 0, mlist[[k]]++; Break[]], {k, =

ndivs}], {n,
       max}];
    mlist]]

Timing[countFirstDivisors[10!, 9]]

{2.23923, {1814399, 604799, 241919, 138239, 75402, 58003, 40941, 34478,
   26982}}

Cheers ... Syd



Syd Geraghty B.Sc, M.Sc.

sydgeraghty at mac.com

Mathematica 6.0.3 for Mac OS X x86 (64 - bit) (21st May, 2008)
MacOS X V 10.5.4
MacBook Pro 2.33 Ghz Intel Core 2 Duo  2GB RAM








On Oct 17, 2008, at 8:33 AM, Daniel Lichtblau wrote:

> Syd Geraghty wrote:
>> Hi Daniel,
>> I have tried to use and understand your input below but I cannot 
>> see where the bug is to generate the Error message below.
>> Attached is a Mathematica file that I used to experiment with.
>> Appreciate your help.
>> Cheers Syd
>> In[7]:= countFirstDivisors =
>> Compile[{{max, _Integer}, {ndivs, _Integer}},
>>  Module[{mlist = ConstantArray[-1, ndivs], primes = 
>> Prime[Range[ndivs]]},
>>   Do[Do[If[Mod[n, primes[[k]]] == 0, mlist[[k]]++; Break[]], {k, =

>> ndivs}], {n,
>>      max}];
>>   mlist]]
>> During evaluation of In[7]:= Compile::"part" :  "Part specification =

>> mlist=CE k=CE=A4 cannot be compiled since the \
>> argument is not a tensor of sufficient rank. Evaluation will use 
>> the \
>> uncompiled function.    ButtonBox["",
>> BaseStyle->"Link",
>> ButtonData:>"paclet:ref/Compile",
>> ButtonFrame->None,
>> .....SNIP
>> Syd Geraghty B.Sc, M.Sc.
>> sydgeraghty at mac.com <mailto:sydgeraghty at mac.com>
>> Mathematica 6.0.3 for Mac OS X x86 (64 - bit) (21st May, 2008)
>> MacOS X V 10.5.4
>> MacBook Pro 2.33 Ghz Intel Core 2 Duo  2GB RAM
>
> I use a development kernel. Apparently ConstantArray is unfamiliar 
> to Compile in version 6. Try it instead with
>
>  mlist = Table[-1,{ndivs}]
>
> and see if that works better.
>
> Daniel
>



  • Follow-Ups:
  • Prev by Date: Dynamic tangential plane - how?
  • Next by Date: Re: FindFit, Weibull
  • Previous by thread: Re: Re: Nested If
  • Next by thread: Pi Formula