# gmp Gauss_Map_Period # Input a floating point number # Output : n the smallest integer such that x[2*n]=x[n]. # where x[n] is the n'th iterate of the gauss map. # This n is the smallest n such that gauss map starts to cycle. # Ref: Knuth. Vol. 2 Semi-Numerical Algorithms. exercise 6 page 7. # Algorithm due to Floyd. gmp := proc(a) local t,ti,tf,x,y,n; t := evalf(a); ti := trunc(t); tf := t-ti; if t<0 then t := t+1; fi; x := t; if x=0 then y:=0; else y := 1/t; ti := trunc(y); y := y-ti; fi; for n while x<>y do if x<>0 then x := 1/x; ti := trunc(x); x := x-ti; fi; if y<>0 then y := 1/y; ti := trunc(y); y := y-ti; fi; if y<>0 then y := 1/y; ti := trunc(y); y := y-ti; fi; od; n; end: Digits := 6; gmp(.3); Digits := 10; gmp(.3); Digits := 19; gmp(.3); Digits := 6; gmp(.787121); evalhf(gmp(.3));