programming, using op(), was ..RE: Bugfix for GosperSum? (was: cannot load Zeilberger)



On 1/6/07, Richard Fateman <fateman at cs.berkeley.edu> wrote:
> I don't know what you are really trying to test for, but op(expr)="-"  means
> either the expression is a negative number like -3, or perhaps -x, or
> perhaps something like -a*b*c.  So what you are really determining is if
> expr is a negative number or a product with a negative constant e.g. -1 out
> front.

The code tries to computes the shift quotient (that is f(k+1)/f(k) ).
It failed when expr was a product with a negative constant in front.
It does not happen that often, thats probably why the author of the
code missed this case.

> Also, be aware that op()  takes a fair amount of time and space, since it
> formats its argument.  For op(a/b) to return //, it must first convert
> ((MTIMES SIMP) $A ((MEXPT SIMP) $B -1))
>
> To
> ((MQUOTIENT) $A $B)
>
> Which is done by the lisp program nformat.
>
>
> A much faster programming technique, which does not require reformatting the
> expression argument, is to use inpart.
>
> Thus a program might look like this:
>
>   If atom(expr) then xxxx
>   else block([op=inpart(expr,0)],
>             if  op="+" then yyy
>                        else if op="*"

I agree that Zeilberger could be more efficient when computing the
shift quotient. But this is not the most time consuming part of the
algorithm.

> A neater way of doing this would be with a case statement, e.g.
>
> Else  case(inpart(expr,0),
>            ["+", yyy],
>            ["*", zzz],
>            [otherwise, ...])
>
>
> Macsyma has a case statement. Maxima could have one too. It takes about 5
> lines of code using buildq, I think.

I agree that a case statement would be very useful to have in maxima.
It would simplify a lot of my code.

Andrej