algorithmchinese-remainder-theorem

Encode a sequence of numbers as a single number -- use chinese remainder theorem


I need to encode a sequence S of an arbitrary number of elements (but finite) with an whole number K, and be able to decode K in order to obtain back the initial sequence.

I need to do it such that a computer be able to cope good with the number K.

I did it so (in lisp):

I tried this method. However, I get huge numbers.

I know that it is possible to use the chinese remainder theorem to solve the problem, and the K obtained so is not that large.

Somebody can help me to use this theorem such that I encode a sequence ?

EDIT:

I wish to see the algorithm of encoding using ch r th using a concrete simple example. I cannot understand the theoretical ideas from wikipedia and other web resources.


Solution

  • You are looking for Gödel numbering of sequences. This is a way of encoding a (finite) sequence of numbers as a single number. The Chinese Remainder Theorem gives a recursive method of construction.