Re: Re: Compile
- To: mathgroup at smc.vnet.net
- Subject: [mg45248] Re: [mg45228] Re: Compile
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 23 Dec 2003 05:13:39 -0500 (EST)
- References: <brplr9$7tf$1@smc.vnet.net> <200312210842.DAA18989@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 21 Dec 2003, at 17:42, Maxim wrote: > Probably unrelated, but consider > > In[1]:= > Module[{subs = x -> x^2}, > Plot[x /. subs, {x, 0, 1}, Compiled -> True] > ] > Module[{subs = x -> x^2}, > Plot[x /. subs, {x, 0, 1}, Compiled -> False] > ] > > (straight line with the default setting of Compiled->True and parabola > with > Compiled->False). Or > > In[3]:= > Module[{y := If[NumericQ[x], x, 1]}, > Plot[x y, {x, 0, 1}, Compiled -> True] > ] > Module[{y := If[NumericQ[x], x, 1]}, > Plot[x y, {x, 0, 1}, Compiled -> False] > ] > > (same, straight line in the first case and parabola in the second). > The question is > probably what exactly Mathematica tries to wrap in Compile and how it > then deals with > 'external' expressions depending on the iterator variable. > > In any case it seems that we have yet another untransparent internal > transformation that > leaves us guessing about the result. > > Maxim Rytin > m.r at prontomail.com > > > I can't see anything at all surprising here. In both cases this simply amounts to the fact that with the option Compiled ->False the argument of Plot is evaluated, in other words you get the same answers as with Module[{subs = x -> x^2}, Plot[Evaluate[x /. subs], {x, 0, 1}, Compiled -> True]] etc. What's more, this is actually described in the documentation: Since Plot needs to evaluate your function many times, it is important to make each evaluation as quick as possible. As a result, Mathematica usually compiles your function into a low$B!>(Blevel pseudocode that can be executed very efficiently. One potential problem with this, however, is that the pseudocode allows only machine$B!>(Bprecision numerical operations. If the function you are plotting requires higher$B!>(Bprecision operations, you may have to switch off compilation in Plot. You can do this by setting the option Compiled -> False. Note that Mathematica can only compile $B!H(Binline code$B!I(B; it cannot for example compile functions that you have defined. As a result, you should, when possible, use Evaluate as described in Section 1.9.1 to evaluate any such definitions and get a form that the Mathematica compiler can handle. Andrzej Kozlowski
- References:
- Re: Compile
- From: Maxim <dontsendhere@.>
- Re: Compile