block



On Fri, Apr 18, 2008 at 3:59 AM, Adam Majewski <adammaj1 at o2.pl> wrote:
>  LastIteration(x,y):=
>  block
>  (
>  z:x+y*%i,
>  i:0,
>  if (abs(z)>ER) then return(i),
> loop,
>  z:z*z,
>  i:i+1,
>  if ((abs(z)<ER) and (i<iMax)) then go(loop),
>  return(i)
>  );

This definition can be improved in several ways.  First of all, Maxima
syntax requires block-local variables to be in a *list* e.g.
block([x:3],...).  Otherwise they are not block-local at all.
Secondly, the first if-condition is redundant. And third, Maxima
offers the "while" construct to make the loop somewhat clearer:

LastIteration(x,y):=
  block([z:x+y*%i,i:0],
    while abs(z)<ER and i<iMax
       do (z:z*z,i:i+1),
    i)$

or even

LastIteration(x,y):=
  block([z:x+y*%i,i:0],
    while (i:i+1)<iMax  and abs(z:z*z)<ER do 1,
    i)$

Even more like pseudo-code, I daresay.

        -s