Return index of for loop



How about something like this?:

GivePeriodOfAngle(n0,d):=
  block([ni:n0],
   for i thru 200 do if (ni:doubling_map(ni,d))=n0 then return(i));

This returns 'done' if it doesn't terminate successfully.

            -s

block(
> [ni:doubling_map(n0,d)],
> for i:1 step 1 thru 200 unless (n0=ni) do ni:doubling_map(ni,d),
> i
> );
>



On Wed, Nov 26, 2008 at 4:24 PM, Adam Majewski <adammaj1 at o2.pl> wrote:

> Hi,
>
> I want to make function which computes period.
> Period is an integer number which shows how many iterates of
> rational number ( = n/d ) under doubling_map is needed to get the same
> value.
> I made 2 functions :
> - first looks nice but not works ( it seems that maxima does not see
> index of for loop out of loop.
> - second function uses go-loop. It works, but ...
>
> Can it be done better ?
>
> Adam Majewski
>
>
> ======== code ==================
>
>
>
> doubling_map(n,d):=mod(2*n,d);
>
>
> /* first function does not work,
> gives i as an output */
> /* Give Period Of rational external Angle
> under doubling map */
> GivePeriodOfAngle(n0,d):=block(
> [ni:doubling_map(n0,d)],
> for i:1 step 1 thru 200 unless (n0=ni) do ni:doubling_map(ni,d),
> i
> );
>
>
> /* this second function works */
> GiveP(n0,d):=block(
> [ni:n0,i:0],
> block(
>   loop,
>   ni:doubling_map(ni,d),
>   i:i+1,
>   if i<100 and not (n0=ni) then go(loop)
> ),
> if (n0=ni)
>        then i
>        else 0
> );
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>