Excess simplifications (was tail-recursion)



Am 19 Feb 2006 um 11:48 hat Stavros Macrakis geschrieben:

> On 2/17/06, Richard Fateman <fateman at cs.berkeley.edu> wrote:
> > [Simplifya] returns quickly if the SIMP flag is set in the CAR of the expression.
> 
> Yes, but simplifya still seems to be called in many situations where
> the argument should be known to have been simplified.  It is possible
> (but I am not sure) that the case blocking tail-recursion is one of
> them.  The reason I am not sure is that there is no clear, documented
> convention about what is guaranteed to return a simplified expression.
>  And even if there was one at some point, I suspect that it is not
> obeyed systematically.
> 
>            -s

Hello Stavros,
isn't it possible to use an optional parameter in the translate functions, which supresses 
the use of SIMPLIFY for arithmetic functions ?

We only need simplification, if we are doing symbolic computations. We don't need 
them in arithmetics, right?

nsum(n,s):=
   if n=0 then s
   else nsum(n-1,s+n)$

automatic translation by Maxima:

(PROGN
  (DEFPROP $NSUM T TRANSLATED)
  (ADD2LNC '$NSUM $PROPS)
  (DEFMTRFUN ($NSUM $ANY MDEFINE NIL NIL) ($N $S)
      (DECLARE (SPECIAL $S $N))
      (COND
        ((LIKE $N 0) $S)
        (T (SIMPLIFY (MFUNCTION-CALL $NSUM (ADD* $N -1) (ADD* $S $N)))))))      

I only need this:

(defun $nsum (n s)
   (if (zerop n) s
      ($nsum (1- n)(+ s n)) ))

Volker