home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / compress / 3047 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  6.9 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uknet!acorn!armltd!dseal
  2. From: dseal@armltd.co.uk (David Seal)
  3. Newsgroups: comp.compression
  4. Subject: Re: Compression technique mentioned in PCW
  5. Message-ID: <5504@armltd.uucp>
  6. Date: 19 Aug 92 13:19:20 GMT
  7. References: <1992Aug18.155518@sees.bangor.ac.uk>
  8. Sender: news@armltd.uucp
  9. Distribution: comp
  10. Organization: A.R.M. Ltd, Swaffham Bulbeck, Cambs, UK
  11. Lines: 122
  12.  
  13. In article <1992Aug18.155518@sees.bangor.ac.uk> mather@sees.bangor.ac.uk
  14. (Paul Mather) writes:
  15.  
  16. >A friend showed me a letter in a recent issue (Sep 1992) of Personal
  17. >Computer World magazine.  ...
  18. >
  19. >Anyway, the thrust of the letter was not about those but was to
  20. >outline a method which seemed to illustrate that it was possible
  21. >to compress data outside the laws of information theory ...
  22. >
  23. >Well, the method the person outlined was the familiar one of representing
  24. >the bytes of a data stream as a decimal fraction N, where N is between 0
  25. >and 1.  ...
  26.  
  27. This is effectively what arithmetic compression does. You may be glad to
  28. hear that it doesn't contravene the laws of information theory...
  29.  
  30. The reason why people tend to think it would is that they see it as
  31. compressing a large amount of data down to just one item of information -
  32. i.e. a number. The fallacy in this is that a number is *not* a unit of
  33. information: you need to reduce everything to bits or some equivalent
  34. measure. The number sent needs to be known *very* accurately in order to
  35. reproduce the original text correctly, and representing a number accurately
  36. requires a lot of bits.
  37.  
  38. In fact, you will find that the number of bits required to represent an
  39. arithmetically compressed message is approximately equal to the theoretical
  40. limit for the source model being used - i.e. in technical terms, to the
  41. entropy of that message with respect to the source model used in the
  42. arithmetic compression. (In theory, it would be almost exactly equal to the
  43. entropy; in practice, it's very slightly higher, due to compromises used in
  44. arithmetic compression programs to avoid the necessity for infinite
  45. precision arithmetic.)
  46.  
  47. >However, in the compression scheme mentioned in the letter, instead of
  48. >using a stout piece of oak :-), the decimal fraction was compressed by
  49. >determining two numbers, a and b, such that a/b = N.  To transmit the
  50. >original file, one need only transmit a and b.  Decompression would
  51. >involve calculating a/b and enumerating the result.
  52. >
  53. >A further modification was suggested to the algorithm whereby the
  54. >file is partitioned into arbitrary sized chunks and each chunk treated
  55. >as a decimal number between 0 and 1 as before.  ...
  56. >
  57. >When my friend asked me what I thought of the proposed method, my gut
  58. >reaction was to say that finding the values of a and b sounded pretty
  59. >intractable to me.  It also occurred to me that it was likely that for
  60. >some N the enumeration of the integers a and b could be longer than N
  61. >itself but my number theory is very rusty so I didn't speculate on that
  62. >to my friend. :-)
  63.  
  64. Finding a and b is not especially intractable, using continued fraction
  65. techniques. This is assuming you keep the size of the chunks down to the
  66. point where multi-precision arithmetic is reasonably feasible - this allows
  67. quite long chunks, but not enormously long ones. Thousands of bits are OK,
  68. millions are not.
  69.  
  70. But the real problem is the second one you've raised: the integers a and b
  71. are going to require at least as many bits to represent as the original
  72. fraction. To see an example of this, look at what numbers you can represent
  73. with a and b both containing 3 bits. We're only interested in fractions
  74. between 0 and 1 inclusive. We're obviously not interested in b=0, so we can
  75. represent values of a from 0 to 7, of b from 1 to 8. This allows us to
  76. represent the following fractions, in ascending order:
  77.  
  78.  0  1  1  1  1  1  2  1  3  2  3  1  4  3  5  2  5  3  4  5  6  7  1
  79.  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  80.  1  8  7  6  5  4  7  3  8  5  7  2  7  5  8  3  7  4  5  6  7  8  1
  81.  
  82. The smallest gap between two of these numbers is 1/56 (between 1/8 and 1/7,
  83. and between 6/7 and 7/8); the largest gap is 1/8 (between 0/1 and 1/8, and
  84. between 7/8 and 1/1). So by rounding to the nearest of these fractions, we
  85. are using 6 bits to represent a fraction between 0 and 1 with an error that
  86. can be as bad as 1/16, and even in the most densely covered area can be as
  87. bad as 1/112. But if we simply use the bits to represent the binary number
  88. 0.xxxxxx1 and round the desired fraction to the nearest such number, we
  89. never get an error of more than 1/128.
  90.  
  91. These results generalise: if you use 2N bits as a straightforward binary
  92. expansion, you can represent any fraction with a maximum error of
  93. 1/(2^(2N+1)); if you instead use them as an N-bit a divided by an N-bit b,
  94. the worst case error is 1/(2^(N+1)) and even in the best-covered areas, the
  95. worst case error is 1/(2^(N+1) * (2^N - 1)). So even when it's at its best,
  96. the a/b method represents fractions a bit less accurately than a
  97. straightforward binary expansion; at its worst, it represents them much less
  98. accurately. The conclusion is that the a/b form is *not* an efficient use of
  99. bits to represent a number.
  100.  
  101. The reason why it is inefficient is that it is redundant in two ways: first,
  102. pairs with a>b don't occur because they don't represent fractions between 0
  103. and 1, and secondly, pairs in which a and b have a common factor don't occur
  104. because the fractions are generally used in lowest terms. Thus the 6 bits
  105. used for a and b above can only represent 23 distinct useful values, whereas
  106. 6 bits used for a binary expansion represent 64 distinct useful values.
  107.  
  108. By being a bit more clever about it, you can increase the bounds on a and b
  109. a bit further and represent a few more numbers. E.g. let the three bits for
  110. b represent a number in the range 2 to 9, and the three bits for a represent
  111. a number in the range 1 to 8 if b=9, 0 to 7 otherwise. Then you can
  112. represent the following 29 fractions:
  113.  
  114.  0 1 1 1 1 1 2 1 2 1 3 2 3 4 1 5 4 3 5 2 5 3 7 4 5 6 7 8 2
  115.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  116.  2 9 8 7 6 5 9 4 7 3 8 5 7 9 2 9 7 5 8 3 7 4 9 5 6 7 8 9 2
  117.  
  118. This represents the fractions better, and occasionally achieves better
  119. accuracy than the binary expansion technique (the minimum gap is now 1/72
  120. compared with 1/64). But the odds are still that it will represent a number
  121. less accurately than the binary expansion. It's still inefficient - i.e.
  122. we're still not using all of the available combinations of 6 bits (in fact,
  123. we're using less than half of them).
  124.  
  125. Further improvements are possible, but it should be fairly clear that the
  126. a/b approach is doomed: even if we get it to represent 64 distinct
  127. fractions, spread uniformly over the [0,1] interval in order to minimise the
  128. worst-case error, all we've done is equalled what the binary expansion
  129. technique can do!
  130.  
  131. David Seal
  132. dseal@armltd.co.uk
  133.  
  134. All opinions are mine only...
  135.