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



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.  Note that op(a-b)  is +.

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="*"

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.

RJF



> -----Original Message-----
> From: maxima-bounces at math.utexas.edu [mailto:maxima-
> bounces at math.utexas.edu] On Behalf Of Andrej Vodopivec
> Sent: Saturday, January 06, 2007 1:35 PM
> To: Michel Van den Bergh
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] Bugfix for GosperSum? (was: cannot load Zeilberger)
> 
> On 1/6/07, Michel Van den Bergh <michel.vandenbergh at uhasselt.be> wrote:
> >
> > > >/ Blindly changing
> > > />/
> > > />/ if op(expr) = "+"  then
> > > />/
> > > />/ into
> > > />/
> > > />/ if op(expr) = "+"  or op(expr)="-" then
> > > /
> > > This alone is not enough. It still fails for -n*n!.
> > Hmm true
> >
> > > A better fix is
> > > probably to add another if statment:
> > >
> > > if op(expr)="-" then
> > >   return(shiftQuoAuxHypCheck(-expr, k, hyp_flag))
> > >
> > You mean another else if? I still get
> >
> > AntiDifference(-k*k!,k);
> > - k k!  is not hypergeometric in  k
> 
> Yes, another else if. The correct result is -k!.
> 
> Andrej
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima