11
$\begingroup$

On a computer I can have integers on arbitrary size thanks to GMP, so it's represented in base 2 in memory.

I'm wondering if it's possible in theory to use less memory if I store only prime factors and their exponent, I think it's worthless for most numbers, but I wonder if it works for a very small minority of numbers with large prime factors.

How can I prove me wrong ?

  • 0
    @Joel, for some certainly, but not at all on average.2012-11-17

3 Answers 3

20

No, it is not possible. In general, there is no algorithm that compresses every $n$ bit string, or reduces the length of a random string of bits (in expectation).

Your algorithm may compress some numbers but then it will use more memory to store others. If your data is random, there is no benefit in using your compression scheme.

Actually the fact that no such compression scheme exists can be used to prove that there are infinitely many prime numbers — otherwise, if there were only finitely many prime numbers your compression scheme would be very efficient!

There are excellent lecture notes on Kolmogorov Complexity by Alexander Shen that discuss “incompressability”; in particular, Shen writes about your compression algorithm in Section 18.

  • 0
    This answer is okay but I think there is a more subtle and interesting aspect to the question when we consider the error bound.2012-11-17
1

https://www.google.com/patents/US6373986

I've done this too. It is not that hard. The reason it works is because the primes become the character set for a language. Instead of base10 or base2 possible characters describing the result, you end up with prime**prime possible characters and the decompressor/program/language becomes the context in which it is interpreted. You end up with unique values WITHIN THAT SET of prime^prime possible values. While the character may be referenced by other sets or other 'languages', fundamentally as long as the value is not outside the maximum possible value for that set, every single value will uniquely represent some other final value. WITHIN that set. Not extending beyond a value of prime^prime.

-2

Something which sort of implies that the answer might be yes in some circumstances (I specialize in precision!) is that solving linear equations with large integer coefficients can be done by solving the system modulo a number of primes (or relatively prime values such as $2^n-1$ for appropriate $n$) and combining the results using the Chinese remainder theorem. You have to have enough moduli so the their product is larger than any of the results.

  • 0
    Surely in _some_ circumstances but else what?2012-11-17