Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Negafibonacci coding

In mathematics, negafibonacci coding is a universal code which encodes nonzero integers into binary code words. It is similar to Fibonacci coding, except that it allows both positive and negative integers to be represented. All codes end with "11" and have no "11" before the end.

We don't have any images related to Negafibonacci coding yet.
We don't have any YouTube videos related to Negafibonacci coding yet.
We don't have any PDF documents related to Negafibonacci coding yet.
We don't have any Books related to Negafibonacci coding yet.
We don't have any archived web articles related to Negafibonacci coding yet.

Encoding method

The following steps describe how to encode a nonzero integer x {\displaystyle x} . Note that f {\displaystyle f} denotes the Negafibonacci sequence.

  1. If x {\displaystyle x} is positive, compute the greatest odd negative integer n {\displaystyle n} such that the sum of the odd negative terms of the Negafibonacci sequence from -1 to n {\displaystyle n} with a step of -2, is greater than or equal to x {\displaystyle x} : n ∈ { − ( 2 k + 1 ) , k ∈ [ 0 , ∞ [ } , ∑ i = − 1 , i o d d n − 2 f ( i ) < x ≤ ∑ i = − 1 , i o d d n f ( i ) . {\displaystyle n\in \{-\left(2k+1\right),k\in [0,\infty [\},\quad \sum _{i=-1,\;i\;odd}^{n-2}f(i)<x\leq \sum _{i=-1,\;i\;odd}^{n}f(i).} If x {\displaystyle x} is negative, compute the greatest even negative integer n {\displaystyle n} such that the sum of the even negative terms of the Negafibonacci sequence from 0 to n {\displaystyle n} with a step of -2, is less than or equal to x {\displaystyle x} : n ∈ { − 2 k , k ∈ [ 2 , ∞ [ } , ∑ i = − 2 , i e v e n n − 2 f ( i ) > x ≥ ∑ i = − 2 , i e v e n n f ( i ) {\displaystyle n\in \{-2k,k\in [2,\infty [\},\quad \sum _{i=-2,\;i\;even}^{n-2}f(i)>x\geq \sum _{i=-2,\;i\;even}^{n}f(i)}
  2. Add a 1 at the | n | th {\displaystyle |n|^{\text{th}}} bit of the binary word. Subtract f ( n ) {\displaystyle f(n)} from x {\displaystyle x} .
  3. Repeat the process from step 1 with the new value of x, until it reaches 0.
  4. Add a 1 on the left of the resulting binary word to finish the encoding.

To decode an encoded binary word, remove the leftmost 1 from the binary word, since it is used only to denote the end of the encoded number. Then assign the remaining bits the values of the Negafibonacci sequence from -1 (1, −1, 2, −3, 5, −8, 13...), and sum the all the values associated with a 1.

Negafibonacci representation

Negafibonacci coding is closely related to negafibonacci representation, a positional numeral system sometimes used by mathematicians. The negafibonacci code for a particular nonzero integer is exactly that of the integer's negafibonacci representation, except with the order of its digits reversed and an additional "1" appended to the end. The negafibonacci code for all negative numbers has an odd number of digits, while those of all positive numbers have an even number of digits.

Table

The code for the integers from −11 to 11 is given below.

NumberNegafibonacci representationNegafibonacci code
−111010000001011
−101010011001011
−91000100100011
−81000000000011
−71000011000011
−61001000010011
−51001011010011
−4101001011
−3100000011
−2100110011
−110011
00(cannot be encoded)
1111
21000011
31011011
410010010011
510000000011
610001100011
710100001011
810101101011
9100101001010011
10100100000010011
11100100110010011

See also

Works cited

  • Knuth, Donald (2008). Negafibonacci Numbers and the Hyperbolic Plane. Annual meeting of the Mathematical Association of America. San Jose, California.
  • Knuth, Donald (2009). The Art of Computer Programming, Volume 4, Fascicle 1: Bitwise Tricks & Techniques; Binary Decision Diagrams. Addison-Wesley. ISBN 978-0-321-58050-4. In the pre-publication draft of section 7.1.3 see in particular pp. 36–39.
  • Margenstern, Maurice (2008). Cellular Automata in Hyperbolic Spaces. Advances in unconventional computing and cellular automata. Vol. 2. Archives contemporaines. p. 79. ISBN 9782914610834.