I am trying to write code for the Fibonacci shift, a monotonic
function N->N that takes the nth Fibonacci number to the (n+1)th
Fibonacci number.

The idea is to write a positive integer n as a (greedy) sum of
Fibonacci numbers

n=F[i_1]+F[i_2]+...+F[i_m]

Then shift(n) is defined by

shift(n)=F[i_1+1]+F[i_2+1]+...+F[i_m+1]

I am using the following code from

http://www.jsoftware.com/jwiki/Essays/Fibonacci_Index

fib=: 3 : 0 " 0
 mp=. +/ .*
 {.{: mp/ mp~^:(I.|.#:y) 2 2$0 1 1 1x
)
phi=: -:1+%:5
fi =: 3 : 'n - y<fib n=. 0>.(1=y)-~>.(phi^.%:5)+phi^.y'

My code has the verb z where

z(n)=i_1,i_2,...,i_m

its inverse zi, and the shift operator.

z =:|.@:fi@:(2 -~/\ ])@:(-(- [EMAIL PROTECTED])^:*^:a:)
zi=:+/@:fib
k=:z :. zi
shift=:>:&.k

   shift"0 >:i.10
1 3 5 6 8 9 11 13 14 16
   ]f=:fib 4 5 6
3 5 8
   shift"0 f
5 8 13

Any suggestions for improvement would be appreciated.

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to