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

1k Views Asked by At

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):

  • suppose that the sequence S has n elements e1, ... en

  • generate first n prime numbers p1 ... pn

  • write K = p1^e1 + p2 ^ e2 + ... + pn ^ en

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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.