Dyadic Encoding

From HandWiki

Dyadic Encoding is a form of binary encoding defined by Smullyan[1] commonly used in computational complexity theory '1's and '2's that is bijective and has the "technical advantage, not shared by binary, of setting up a one-to-one correspondence between finite strings and numbers."[2]

Dyadic encoding works by using a recursive definition of concatenating strings of '1's and '2's together using the following formula.

  • dya(0) = ξ (empty string)
  • dya(2n + 1) = dya(n)'1' Odd numbers
  • dya(2n + 2) = dya(n)'2' Even numbers

For example:

Natural Number Dyadic Encoding
0 ξ (empty string)
1 1
2 2
3 11
4 12
5 21
6 22
7 111

The numerical value n of a string dkd2d1 with di{1,2} is given by n=dk2k1++d22+d1. As the above recursive construction implies, each positive integer is uniquely represented in this way.

References

Computational complexity theory