Return index of for loop



Hi,

Thx for help.

> 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));

Yes it really works, but what ( and why ) makes that your program works 
and my do not ?

/* my gives i */
G1(n0,d):=block(
[ni:doubling_map(n0,d)],
for i:1 step 1 thru 200 unless (n0=ni) do ni:doubling_map(ni,d),
return(i)
);



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

If the function will be used inside another function it can be a problem 
  because done is not a numerical value ( if I'm not wrong ). But it can 
be changed to

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

(:-|
  Still gives done for :
G(1,31000000);


Adam
> 
>             -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 <mailto:Maxima at math.utexas.edu>
>     http://www.math.utexas.edu/mailman/listinfo/maxima
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima