Why not replace q with zero?



On 12/11/08, Dotan Cohen <dotancohen at gmail.com> wrote:

>  I suppose that I could run the query three times, once for each value,
>  if I don't know the value of q.

I made an attempt to put together some functions which would
catch asksign queries and automatically construct a conditional
expression to represent the alternatives. This stuff is in the
noninteractive package.

load (noninteractive);
sum (i, i, q, n), simpsum;
 => if q < 0 then (n^2+n)/2-(q^2+q)/2 elseif equal(q,0)
    then (n^2+n)/2-(q+(q-1)^2-1)/2
    else (n^2+n)/2-(q+(q-1)^2-1)/2

Some rules can be defined to collapse identical branches.

In a simple problem like this it works well enough but it 's easy to
find problems for which it gets seriously messed up.

Having tried this, I think the basic approach cannot work,
but I haven't come up with anything better.

Robert Dodier