How to prevent evaluation.



On Mon, Dec 28, 2009 at 4:33 PM, Richard Hennessy <rich.hennessy at verizon.net
> wrote:

>  ...
>
> The last way is the fastest.  What I think I need to do is dynamically
> generate an if then else statement as the output from piecewise().  I am not
> at all clear on how to do that.
>

Just like any other expression:

(%i12) cond: if a>0 then 1 else 0;
(%o12)                                                        if a > 0 then
1 else 0
(%i13) makelist(inpart(cond,i),i,0,length(cond));
(%o13)                                                        [if, a > 0, 1,
true, 0]

Note that the 'else xxx' is coded as "elseif true then xxx".

(%i14) cond: if a>0 then 1 elseif b>0 then 3;
(%o14)                                                  if a > 0 then 1
elseif b > 0 then 3
(%i15) makelist(inpart(cond,i),i,0,length(cond));
(%o15)                                                 [if, a > 0, 1, b > 0,
3, true, false]
(%i16) funmake("if",[a>0,2,true,3]);
(%o16)                                                        if a > 0 then
2 else 3

               -s