MathGroup Archive 2004

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

Search the Archive

Re: Compile

"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

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:

Compile[{x}, Block[{x = 1}, x]][2]

<warning messages>

Block[{2 = 1}, 2]

Compile[{x}, Table[x, {x, 2}]][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:

Compile[{x}, Append[{}, {}]; Table[x, {x, 2}]][2]

<warning messages>

Table[2, {2, 2}]

(which is different from Out[2]).

Maxim Rytin
m.r at

  • Prev by Date: Re: Re: Compile
  • Next by Date: Re: Problem with FullSimplify in Version 5: Rationals are converted to Reals
  • Previous by thread: Re: Re: Compile
  • Next by thread: RE: RE: RE: Re: Compile