Re: Compile
- To: mathgroup at smc.vnet.net
- Subject: [mg45338] Re: Compile
- From: Maxim <dontsendhere@.>
- Date: Thu, 1 Jan 2004 05:54:31 -0500 (EST)
- References: <bsu1ai$8gm$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Bill Rowe wrote: > On 12/30/03 at 4:14 AM, dontsendhere@. (Maxim) wrote: > > > I don't see any problem with Plot[Random[],{x,0,1},Compiled->True] either, it was just an > > illustration (if you don't like Random[], you can insert A Very > > Complicated Expression instead). But you have to read the thread from the beginning, the problem is > > with > > > > Module[{y := If[NumericQ[x], x, 1]}, > > Plot[x y, {x, 0, 1}, Compiled -> True] > > ] > > But this too works as should be expected from the documentation. In order for the expression x y to be Compiled it must be evaluated and this must happen before Plot assigns values to any portion of the expression. Consequently, when it is evaluated x is not numeric so y evaluates to 1 and the product evaluates to x. Hence, with Compiled->True a line with slope = 1 results. > > OTOH, with Compiled->False, Plot supplies a numeric value to x then evaluates the expression. Since x is now numeric, y evalutes to x and the product evaluates to x^2. The resulting plot is a parabola. > > -- > To reply via email subtract one hundred and four My congratulations, now we're starting the second lap. Here you should re-read the previous messages in this thread about inserting Evaluate and comparing the results. If you tried to actually do some testing -- Module[{y := If[Print[x];NumericQ[x], x, 1]}, Plot[x y, {x, 0, 1}, Compiled -> True] ] you would notice that y is evaluated for each step Plot takes and it prints symbol x. And of course, Compile doesn't evaluate its second argument -- do you really think that to execute Compile[{}, Print[x]] Print[x] should be evaluated? Maxim Rytin m.r at prontomail.com