Re: Compile

*To*: mathgroup at smc.vnet.net*Subject*: [mg45520] Re: Compile*From*: Maxim <dontsendhere@.>*Date*: Sun, 11 Jan 2004 03:20:23 -0500 (EST)*References*: <bti21a$a8p$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

"Wolf, Hartmut" wrote: > > > Now my guess is -- and I leave it up to you to check this out -- that if you > replace > > Plot[ expression , {x, xmin, xmax}, Compiled -> trueorfalse] > > with > > Plot[ Block[{x = xx}, expression] ,{xx, xmin, xmax}, Complied -> > trueorfalse] > > you'll get something satisfying for all expressions and for all cases of the > Compiled option. > > -- > Hartmut Wolf Okay, just as a sports excercise: local variables of Plot needn't be symbols. I can use Plot[x[1],{x[1],0,1}] but it cannot be rewritten as Block[{x[1]=xx},...]. Either way you look at it, Compiled->True does violate the Block-like semantics of Plot. And of course such trifle isn't mentioned in the documentation. Another interesting issue that comes up is local variables inside Compile. The only thing on this topic that we can find in the documentation is "Compiled code does not handle numerical precision and local variables in the same way as ordinary Mathematica code". This is as good as saying "left as a puzzle for the reader". For example: In[1]:= Compile[{x}, Block[{x = 1}, x]][2] <warning messages> Out[1]= Block[{2 = 1}, 2] In[2]:= Compile[{x}, Table[x, {x, 2}]][2] Out[2]= {1, 2} I don't see any logical explanation for this; ordinary scoping constructs seem to always handle Block and Table in a uniform way. For example, Function would make a substitution for the Block/Table variable in both cases, so in the second case we'd have Table[2,{2,2}]. Moreover, it follows that if executing CompiledFunction fails, we'll have yet another inconsistency: In[3]:= Compile[{x}, Append[{}, {}]; Table[x, {x, 2}]][2] <warning messages> Out[3]= Table[2, {2, 2}] (which is different from Out[2]). Maxim Rytin m.r at prontomail.com