How to prevent evaluation.



Again, more thoughts, sorry.

Why is this slower.

Try

(%i29) for i : 1 thru 1000 do for j : 1 thru 2 do apply('block, [expand((y-x)^100-3), expand((y-x)^100), 
expand((y-x)^100-5),expand((y-x)^100-7)]);
Evaluation took 66.4200 seconds (66.4200 elapsed)
(out29)                                                                              done
(%i30) for i : 1 thru 1000 do for j : 1 thru 2 do apply('block, [if i>1 then (if equal(j,1) then expand((y-x)^100-3) 
else expand((y-x)^100)) else (if equal(j,2) then expand((y-x)^100-5) else expand((y-x)^100-7))]);
Evaluation took 16.6700 seconds (16.6700 elapsed)
(out30)                                                                              done
(%i31) for i : 1 thru 2000 do expand((x-y)^100-9)$
Evaluation took 6.6000 seconds (6.6000 elapsed)

I guess it is okay to use block this way. It works in this case but it will not give just 6.6 seconds like the expand in 
%i31.  I am not sure how to get 6.6 second for any of the if's.

Rich

  From: Richard Hennessy
  Sent: Sunday, December 27, 2009 5:41 PM
  To: Maxima List
  Subject: Re: How to prevent evaluation.


  Sorry for the second post but I should say the example is just to illustrate the problem.
    From: Richard Hennessy
    Sent: Sunday, December 27, 2009 5:16 PM
    To: Maxima List
    Subject: How to prevent evaluation.


    I tried this to see the timing information.

    load(pw)$

    (%i3) showtime:true;
    Evaluation took 0.0000 seconds (0.0000 elapsed)
    (out3)
    (%i4) for i : 1 thru 2000 do %if(i>0, expand((x-y)^100), expand((x-y)^100));
    Evaluation took 13.0200 seconds (13.0200 elapsed)
    (out4) done
    %i5) for i : 1 thru 2000 do %if(i>0, expand((x-y)^100), 1);
    Evaluation took 6.7700 seconds (6.7700 elapsed)
    (out5) done
    %i6) for i : 1 thru 2000 do %if(i>0, 1, expand((x-y)^100));
    Evaluation took 7.0400 seconds (7.0400 elapsed)
    (out6) done
    %i7) for i : 1 thru 2000 do %if(i>0, expand((x-y)^100), 1);
    Evaluation took 6.8200 seconds (6.8200 elapsed)
    (out7)  done
    (%i8  for i : 1 thru 2000 do %if(i>0, 1, 1);
    Evaluation took 0.1500 seconds (0.1500 elapsed)
    (out8)  done
    (%i4)

    It seems like in the %if function both the then part and the else part are always expanded even when only one needs 
to be evaluated.  Is there a way to stop evaluation of both parts?  This would make possible major speed improvements 
dealing with large expressions.

    Rich