# Math Help - [SOLVED] need help: uniquely encode two vectors from R^n into one vector in R^n

1. ## [SOLVED] need help: uniquely encode two vectors from R^n into one vector in R^n

Hello,

first of all, I´m not very experienced with mathematics, so please forgive me if I make statements which are unclear or not totally mathematical solid

my problem:
uniquely encode two vectors from R^n into one vector in R^n

After spending a lot of time in searching for possible solutions, I came up with the following:

let x,y be two vectors in R^n with x=(x1, x2, ..., xn) and y=(y1, y2, ..., yn)

the function f: R^n x R^n -> R^n , takes two vectors as parameters like this: f(x,y) and returns a new vector in R^n like this: f(x,y) = z

where z = (z1, z2, ..., zn)
every element of z is calculated using the following approach:

let zi be an element of z (with 1 <= i <= n), zi is created as a number in the open interval (0 ,1) by interleaving xi and yi
---> 0.xiyi

an example in R^2 would be:

x = (1 , 2)
y = (3 , 4)

z = (z1, z2)
z1 = 0.13 (created from x1 and y1)
z2 = 0.24 (created from x2 and y2)

so the question is: does this solution make sense ? is there a problem I don´t see ?

thank you,
Andreas

2. ## Problems

I can see several problems:
First, what if $x_i$ and $y_i$ are multidigit integers?
What if $y_i$ is zero, or has trailing zeros:
$x_i=1,~y_i=2$,
$x_i=1,~y_i=20$,
$x_i=1,~y_i=200$

All become the same number $z_i=0.12$.

Both $x_i=1,~y_i=2$ and $x_i=12,~y_i=0$ become 0.12

Third, what if $x_i$ and/or $y_i$ are negative?
Lastly, what if $x_i$ and $y_i$ are not integers?

--Kevin C.

3. Hi Kevin,

thank you for your feedback.

The points you mentioned are totally correct.
A possible solution to the problems would be to modify f like this:

xi and yi must be transformed into the open interval (0,1), before they are interleaved.

so basically the vectors x and y from R^n must be transformed into (0,1)^n and the function f looks now as followed:

f: (0,1)^n x (0,1)^n -> (0,1)^n

how about this modification? Any issues here ?

kind regards,
Andreas

4. Hi,

what about the following extension:

f: (0,1)^n, ...., (0,1)^n -> (0,1)^n
so f does no longer take two parameters, but any number of parameters

an example with three parameters:

having let x,y,k be three vectors in R^n with x=(x1, x2, ..., xn) , y=(y1, y2, ..., yn) and k=(k1, k2, ...., kn)

z = 0.x1y1k1x2y2k2....

does this work as well ?

5. Originally Posted by sirandreus
what about the following extension:

f: (0,1)^n, ...., (0,1)^n -> (0,1)^n
so f does no longer take two parameters, but any number of parameters

an example with three parameters:

having let x,y,k be three vectors in R^n with x=(x1, x2, ..., xn) , y=(y1, y2, ..., yn) and k=(k1, k2, ...., kn)

z = 0.x1y1k1x2y2k2....

does this work as well ?
Yes, I can't see any problem with that. Of course, to decode it, you'll need to know p (the number of parameters), and also the value of n. If these are not known to the person doing the decoding, you could encode them by an integer (for example $2^p3^n$) and put that before the decimal point.

Then a number such as z = 72.a_1a_2a_3a_4... would be decoded as $72 = 2^3\times3^2$, so there are three vectors in R^2, namely $x = (0.a_1a_7a_{13}\ldots,\,0.a_4a_{10}a_{16}\ldots)$, $y = (0.a_2a_8a_{14}\ldots,\,0.a_5a_{11}a_{17}\ldots)$, $k = (0.a_3a_9a_{15}\ldots,\,0.a_6a_{12}a_{18}\ldots)$.

6. Originally Posted by Opalg
If these are not known to the person doing the decoding, you could encode them by an integer (for example $2^p3^n$) and put that before the decimal point.
.
I really have no idea what you are talking about over here. But when you wrote 2^p*3^n did you mean as a sum of those numbers? Because there is a simple Erdos theorem that says such a representation is always possible. Maybe that helps? Or did you mean to say that?

7. ## efficient implementation

Hi all,

thanks again for your helpful feedback.

Things are getting more interesting right now

In practice, the function f can be implemented easily, by using an high precision arithmetical library (such as GMP for C, or apfloat for Java). The values of the vectors, which are the arguments of the function f could be "usual" doubles / floats and the output values (the interleavings) would be BigDoubles (an arbitrary precision floating point implementation from the using library)

However, the real problem is how to work efficiently with numbers which are generated by f (reminder: as we know, f can take many vectors (not just 2))
Because if we have numbers with several thousands or even millions of digits, every basic operation such as add, mult or div, (not to mention exp, sqrt, ...) will run very slow.

So the question is, how to modify the function f, so that the numbers of the result vector are in an efficient practical format. The results must not be exact, but the smaller the errors the better.

any ideas ?

kind regards,
Andreas