Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 06, 2014, 07:02:08 PM Last edit: April 17, 2016, 09:08:02 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
JBrace1990
Member
Offline
Activity: 68
Merit: 10
|
|
February 06, 2014, 08:01:40 PM |
|
This may be too simple, but a first start at what I hope to hit...
[3, 6, 9, 12]
can be stored as : 3060912, 2
where the second number is how many spaces the first ones take up. If less than 2 are there, there is a leading 0.
(too simple, I know).
What is the max size of each of the original integers in bits?
|
|
|
|
FiatKiller
|
|
February 06, 2014, 08:07:11 PM |
|
Are you just looking to reduce storage space? Why not apply the same algorithm to all 4 values?
|
|
|
|
Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 06, 2014, 08:20:20 PM Last edit: April 17, 2016, 09:07:56 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
|
Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 06, 2014, 08:43:38 PM Last edit: April 17, 2016, 09:07:50 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
gzaloprgm
Newbie
Offline
Activity: 1
Merit: 0
|
|
February 06, 2014, 09:14:05 PM |
|
The problem is going back from 2 integers to 4... Unless you want a "lossy compression", it is impossible.
Unless the input numbers have a mathematical property, it's imposible to generalize to every integer... Pigeonhole principle means that there would be inputs that map onto the same output.
If some were able to do it, then you would be able to compress any data into half its size, and by repeating the process you would end up with just one integer. Good luck...
|
|
|
|
Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 06, 2014, 09:22:16 PM Last edit: April 17, 2016, 09:07:43 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
Ins
|
|
February 06, 2014, 09:24:25 PM |
|
def p a a[1].times{|f|puts a[0]*f+3} end p [3,4] ruby, just kidding
|
|
|
|
Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 06, 2014, 09:26:35 PM Last edit: April 17, 2016, 09:07:37 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
FiatKiller
|
|
February 06, 2014, 11:38:42 PM |
|
Hey, if these are X and Y = Key... can't you derive X and Y from the key and just store the keys? Or do you actually need one of either X or Y? (just thinking out loud here...)
|
|
|
|
tim-tams
|
|
February 07, 2014, 12:57:01 AM |
|
BTW: One Int = 32 bits.
In the OP you said, The storage space of 2 integers (64bit) may not be exceeded
Does this mean you want to store 4 32-bit integers as 2 64-bit integers? Or are all the integers 32-bit and you just mentioned 64-bit as something that we can use along the way.
|
|
|
|
nick32768
Newbie
Offline
Activity: 42
Merit: 0
|
|
February 07, 2014, 01:24:46 AM |
|
Hi, I think you should clarify a bit the problem: 1. Do you need to keep the same order of the numbers ? e.g. f(1,2,3,4) and f(4,3,2,1) should be considered different ? 2. Are there limitations of integers ? i.e. any integer from -2^31-1 to 2^31 ? Or only natural numbers ?
Without some sort of limitations the solution is impossible, as all the compression algorithm knows...
Nick
|
|
|
|
rxd2
Newbie
Offline
Activity: 1
Merit: 0
|
|
February 07, 2014, 01:59:08 AM Last edit: February 07, 2014, 02:10:59 AM by rxd2 |
|
Along the lines of gzaloprgm, here is a detailed mathematical proof of why this is impossible. Note: this proof is valid even if you allow any extra temporary storage, any amount of constants, any extra function and any amount of CPU cycles. In fact, let's take it a step further and prove that not only such a program is impossible, but also no supercomputer/quantum computer/AWESOM-O can do it either.
I am assuming that the problem is: provide a machine (let's call it AWESOMO) that takes as input two 64-bits integers and outputs four 64-bits integers, such that for any array y consisting of four 64-bits integers, there exists an input x of two 64-bits integers such that AWESOMO outputs y when the input is x, i.e. AWESOMO(x) = y.
First let's count how many 4-integers arrays are possible. Each element of the array can be any of the 64-bit integers. So, there are 2^64 = 18446744073709551616 possibilities for each element. Taken together, the number of ways to choose four 64-bits integers is n = (2^64)^4, which is between 10^77 and 10^78. Now, how many ways do we have to choose 2 integers? A similar reasoning gives m = (2^64)^2, which is between 10^38 and 10^39.
Now let's prove that AWESOMO cannot exist. By contradiction. So, assume that AWESOMO exists. Recall (from Wikipedia) that the pigeonhole principle states that "if n items are put into m pigeonholes with n > m, then at least one pigeonhole must contain more than one item". This is not difficult to see why this is true.
Restating our problem, for each possible output y of AWESOMO, there must exist some input x such that AWESOMO(x)=y. Thus, let's try to associate each possible output (item) to an input (the pigeonhole). Well then, since there are more items (arrays of four 64-bits integers) than pigeonholes (arrays of two 64-bits integers), by the pigeonhole principle, there must exists one pigeonhole, i.e. an array of two 64-bits integers that we will call x1, that is associated to at least two items, i.e. two arrays of four 64-bits integers y1 and y2. In other words, these two outputs y1 and y2 are associated to the input x1. Then what should be the value of AWESOMO(x1)? Either AWESOMO can only return a single value and then AWESOMO(x1) is either y1 or y2, or AWESOMO is allowed to be ambiguous and returns both y1 and y2 when the input is x1. The latter is not possible given our definition of the problem (AWESOMO must output a single 4-integers array). The former contradicts that all possible outputs are covered. This is our contradiction.
--
1rxd2Ts2hRXv6WWpxWyYEmNE9fhVczV1F
|
|
|
|
Dare
|
|
February 07, 2014, 06:06:35 PM |
|
Let us say we have an array of 4 unsigned integers: [3,6,9,12] I am looking for a way to express it by 2 integers only.
You can't fit 256 bits of data into a 128 bit space without losing some precision or assuming something about the data. For instance, if every other bit of the data was static, the integers could be interleaved with a constant or two to maintain the static data. Or, if you don't mind using 32-bit integers as data, you can fit 4 of them into the same space as 64-bit integers, since 32*4 = 64*2 = 128. In C++ (though you might need a static cast or two to make the compiler happy): To create the 64-bit array from the 32-bit one: uint32_t values32[4] = {1, 2, 3, 4}; uint64_t values64[2]; values64[0] = (values32[0] << 32) | values32[1]; values64[1] = (values32[2] << 32) | values32[3];
To restore the array to 4 32-bit integers, use: values32[0] = values64[0] >> 32; values32[1] = values64[0] & 0x00000000ffffffff; values32[2] = values64[1] >> 32; values32[3] = values64[1] & 0x00000000ffffffff;
|
|
|
|
tim-tams
|
|
February 07, 2014, 09:50:33 PM |
|
...Do you need to keep the same order of the numbers ? e.g. f(1,2,3,4) and f(4,3,2,1) should be considered different?
I think I might have a solution but this matters. Where's the OP? We need this question answered (and several others maybe).
|
|
|
|
12648430
|
|
February 07, 2014, 10:45:24 PM |
|
...Do you need to keep the same order of the numbers ? e.g. f(1,2,3,4) and f(4,3,2,1) should be considered different?
I think I might have a solution but this matters. Where's the OP? We need this question answered (and several others maybe). No you don't, lol. You have 64 bits of storage space. If order doesn't matter, the data to store is an unordered set with repetitions and thus has n-choose-k possibilities, with k=4 and n=2^32+4-1 (multiset coefficient for choosing 4 out of 2^32 possibilities) -- that's more than 2^123. It would take 124 bits to store that many possibilities.
|
|
|
|
Evil-Knievel (OP)
Legendary
Offline
Activity: 1260
Merit: 1168
|
|
February 07, 2014, 10:59:17 PM Last edit: April 17, 2016, 09:07:24 PM by Evil-Knievel |
|
This message was too old and has been purged
|
|
|
|
12648430
|
|
February 08, 2014, 09:48:11 AM Last edit: February 08, 2014, 09:58:46 AM by 12648430 |
|
Since apparently GZA and RJD2's explanations of why this is impossible were a bit obtuse for you, here's an additional way to look at it: If you have a way to store any 4 integers into 2 integers, why not do it again? Take 8 integers, put them into 4, put those 4 into 2. Take 16 integers, put them into 8, into 4, into 2... etc. If you can store 4 integers in 2, you can store any even number of integers in 2 integers. You could compress the entire internet into a number less than 18446744073709551616.
|
|
|
|
FiatKiller
|
|
February 08, 2014, 10:11:48 AM |
|
Since apparently GZA and RJD2's explanations of why this is impossible were a bit obtuse for you, here's an additional way to look at it: If you have a way to store any 4 integers into 2 integers, why not do it again? Take 8 integers, put them into 4, put those 4 into 2. Take 16 integers, put them into 8, into 4, into 2... etc. If you can store 4 integers in 2, you can store any even number of integers in 2 integers. You could compress the entire internet into a number less than 18446744073709551616.
Good point! lol Seems like the only way would be if the dataset follows certain patterns and not literally ANY possible integer.
|
|
|
|
|