FWIW, here’s my code for changing back to decimal representation.
z2d =: 3 : 0
if. _1 < <./ y do.
+/ #/ y join Fb
else.
+/ */ y join Fb
end.
)
join =: 3 : 0
join/ y
:
l =. - ({:@$x) >. {:@$y
r =. (l{."1 x),: l{."1 y
if. 2<#$r do.
(l{."1 x), l{."1 y
end.
)
eg
d2z 100
1 0 0 0 0 1 0 1 0 0
z2d d2z 100
100
z2d add&d2z /3 4. NB. Addition
7
z2d sub&d2z /3 4 NB. Subtraction
_1
z2d mult&d2z /3 4 NB. Multiplication
12
So far so good, but...
z2d div&d2z /12 3. NB. Division!
|domain error: z2d
| _1< <./y
... and the functions for rational division and square root don’t seem to work,
now! So I won’t bother the forum with them.
I now see that Jon has used a binary representation where the rightmost bits
are
most significant, while, Zeckendorf, at least in the Rosetta code
specification, as in
https://rosettacode.org/wiki/Zeckendorf_arithmetic
has leftmost most significant.
I restricted my stuff to 100+ Fibonacci elements, somewhat arbitrarily, I
think. And they’re in descending order, cf Jon’s increasing 1400.
Thanks,
Mike
Please reply to [email protected].
Sent from my iPad
> On 19 Jul 2019, at 11:23, Mike Day <[email protected]> wrote:
>
> Just time to list d2z, dec to Zeckendorf...
>
> _8{.Fb NB. Reverse list of fibs...
> 34 21 13 8 5 3 2 1
> d2z. NB. Dec to z
> 3 : 0
> f =. Fb, 0
> if. y = 0 do. ,0 return. end.
> if. y e. f do. (#~>./\ ) Fb = y return.end.
> reduce =. | }. +/\ inv f&(( (] - I.{[)^:a:)) n =. y NB. 12 ==> 12 4 1
> }: (#~>./\ ) f e. reduce
> )
>
> More later,
>
> Mike
>
> Sent from my iPad
>
>> On 19 Jul 2019, at 11:07, Mike Day <[email protected]> wrote:
>>
>> I did a quick compare - on the hoof, so briefly- my d2z and z2d, ie
>> decimal-Zeckendorf switches appear faster than decode/encode - no time to
>> say how or why!
>>
>> More later,
>>
>> Mike
>>
>> Sent from my iPad
>>
>>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm