Re: Another question about Compile[]:
- To: mathgroup at smc.vnet.net
- Subject: [mg49967] Re: [mg49950] Another question about Compile[]:
- From: DrBob <drbob at bigfoot.com>
- Date: Sun, 8 Aug 2004 05:37:53 -0400 (EDT)
- References: <200408070751.DAA07788@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
myMgpp = Compile[ {{n, _Integer}}, Block[{p}, Do[If[PrimeQ[n - (p = Prime[i])], Return[p]], {i, PrimePi[n/2], 1, -1}]], {{i, _Integer}, {Prime[_], _Integer}, {PrimePi[_], _Integer}, {PrimeQ[_], True | False}}]; myMgpp[400] 173 Bobby On Sat, 7 Aug 2004 03:51:48 -0400 (EDT), Gilmar Rodr?guez Pierluissi <gilmar.rodriguez at nwfwmd.state.fl.us> wrote: > Dear Mathematica Web Group: > I'm attempting to build a Compiled version of the following function: > > In[1]: > MGPPP[n_] := Module[{p, q}, > {m = n/2; If[Element[m, > Primes], {p = m, q = m}, {k = > PrimePi[m]; Do[If[Element[n - Prime[i], Primes], hit = i; > Break[]], {i, k, 1, -1}], p = Prime[hit], q = n - p}]}; {p, q}] > > which works as follows: > > In[2]: > MGPPP[400] > > Out[2]: > {173, 227} > > Unfortunately, my attempt fails: > > In[3]: > mgppp = Compile[{{p, _Integer, > 1}, {q, _Integer, 1}, {n, _Integer, 1}}, Module[{p, q}, > {m = n/2; If[Element[m, Primes], {p = m, q = m}, { > k = PrimePi[m]; Do[If[Element[n - Prime[i], > Primes], hit = i; > Break[]], {i, k, 1, -1}], p = Prime[hit], q = n - p}]}; {p, q}]] > > Out[3]: > Compile::initvar: The variable p has not been initialized or has been \ > initialized to Null. > Compile::cptype: List not supported for type Void; evaluation will use the \ > uncompiled function. > > Thank you for your help! > > > -- DrBob at bigfoot.com www.eclecticdreams.net
- References:
- Another question about Compile[]:
- From: gilmar.rodriguez@nwfwmd.state.fl.us (Gilmar Rodr?guez Pierluissi)
- Another question about Compile[]: