Re: Another question about Compile[]:
- To: mathgroup at smc.vnet.net
- Subject: [mg50056] Re: Another question about Compile[]:
- From: "Mariusz Jankowski" <mjankowski at usm.maine.edu>
- Date: Fri, 13 Aug 2004 05:56:05 -0400 (EDT)
- Organization: University of Southern Maine
- References: <cf22mp$7si$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Gilmar, the first argument of Compile is the input list, so variables p and q should be removed. Try mgppp = Compile[{ {n, _Integer, 1}}, etc...] However, I suspect your compiled code will be slower. Most of the work is done inside kernel functions, which I suspect cannot be made faster by wrapping with compile. Regards, Mariusz >>> Gilmar Rodr?guez Pierluissi<gilmar.rodriguez at nwfwmd.state.fl.us> 8/7/2004 4:08:57 AM >>> 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!