# Define Fibonacci numbers > F:=proc(n) option remember; > if n=0 then 0 > elif n=1 then 1 > elif n>1 then F(n-1)+F(n-2) > else (-1)^(n-1)*F(-n) > fi > end: # Define Lucas numbers > L:=proc(i) F(i-1)+F(i+1) end: # Compute Zeckendorf representation of an integer > Zeck:=proc(nn) local n,Z,i; > n:=nn; > Z:=NULL; > while n>0 do > i:=2; > while F(i) <= n do i:=i+1 od; > Z:=Z,i-1; > n:=n-F(i-1) > od; > [Z] > end: # Find a reduced Zeckendorf representation # > rz:=proc(n) local Z,i; > Z:=Zeck(n); > if nops(Z)=0 then [] else > [seq(Z[i] - Z[i+1]-2, i=1..nops(Z) -1), Z[nops(Z)] -2] > fi > end: # Print a list of numbers compactly > compact:=proc(L) local s,x; s:=``; > for x in L do s:=``.s.` `.(x) od; > s > end: # Find the period of the Fibonacci numbers mod m > period:=proc(m) local i; > if m=1 then RETURN(1) fi; > for i from 1 do > if (F(i-1) mod m ) = 1 and (F(i) mod m) = 0 then RETURN(i) fi > od > end: # Find the Zeckendorf representation for (F(n+p)-F(n))/m, where p= # period(m) > Zp:=proc(n,m) Zeck((F(n+period(m))-F(n))/m) end: # Find the "alpha" representation" for n > Zecka:=proc(n) > local x, L,k,a; > a:=(1+sqrt(5))/2; > L:=NULL; > x:=n; > while x <> 0 do > k :=floor(evalf(log(x)/log(a))+.00001); > L:=L,k; x:=simplify(x-a^k); > od; > [L] > end: > # Find the Lucas representation for n > ZeckL:=proc(nn) local n,Z,i; > n:=nn; > Z:=NULL; > while n>2 do > i:=2; > while L(i) <= n do i:=i+1 od; > Z:=Z,i-1; > n:=n-L(i-1) > od; > if n=2 then Z:=Z,0 elif n=1 then Z:=Z,1 fi; > [Z] > end: