Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Lossless data compression

Lossless data compression

Overview
Lossless data compression is a class of data compression
Data compression
In computer science and information theory, data compression or source coding is the process of encoding information using fewer bits than an unencoded representation would use, through use of specific encoding schemes.As with any communication, compressed data communication only works when both...

 algorithm
Algorithm
In mathematics, computing, linguistics, and related subjects, an algorithm is an effective method for solving a problem using a finite sequence of instructions. Algorithms are used for calculation, data processing, and many other fields....

s that allows the exact original data to be reconstructed from the compressed data. The term lossless is in contrast to lossy data compression
Lossy data compression
A lossy compression method is one where compressing data and then decompressing it retrieves data that is different from the original, but is close enough to be useful in some way. Lossy compression is most commonly used to compress multimedia data , especially in applications such as streaming...

, which only allows an approximation of the original data to be reconstructed, in exchange for better compression rates.

Lossless data compression is used in many applications. For example, it is used in the popular ZIP
ZIP (file format)
The ZIP file format is a data compression and archive format. A ZIP file contains one or more files that have been compressed to reduce file size, or stored as-is...

 file format and in the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 tool gzip
Gzip
gzip is a software application used for file compression. gzip is short for GNU zip; the program is a free software replacement for the compress program used in early Unix systems, intended for use by the GNU Project....

.
It is also often used as a component within lossy data compression technologies.

Lossless compression is used when it is important that the original and the decompressed data be identical, or when no assumption can be made on whether certain deviation is uncritical.
Discussion
Ask a question about 'Lossless data compression'
Start a new discussion about 'Lossless data compression'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
Lossless data compression is a class of data compression
Data compression
In computer science and information theory, data compression or source coding is the process of encoding information using fewer bits than an unencoded representation would use, through use of specific encoding schemes.As with any communication, compressed data communication only works when both...

 algorithm
Algorithm
In mathematics, computing, linguistics, and related subjects, an algorithm is an effective method for solving a problem using a finite sequence of instructions. Algorithms are used for calculation, data processing, and many other fields....

s that allows the exact original data to be reconstructed from the compressed data. The term lossless is in contrast to lossy data compression
Lossy data compression
A lossy compression method is one where compressing data and then decompressing it retrieves data that is different from the original, but is close enough to be useful in some way. Lossy compression is most commonly used to compress multimedia data , especially in applications such as streaming...

, which only allows an approximation of the original data to be reconstructed, in exchange for better compression rates.

Lossless data compression is used in many applications. For example, it is used in the popular ZIP
ZIP (file format)
The ZIP file format is a data compression and archive format. A ZIP file contains one or more files that have been compressed to reduce file size, or stored as-is...

 file format and in the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 tool gzip
Gzip
gzip is a software application used for file compression. gzip is short for GNU zip; the program is a free software replacement for the compress program used in early Unix systems, intended for use by the GNU Project....

.
It is also often used as a component within lossy data compression technologies.

Lossless compression is used when it is important that the original and the decompressed data be identical, or when no assumption can be made on whether certain deviation is uncritical. Typical examples are executable programs and source code. Some image file formats, like PNG or GIF, use only lossless compression, while others like TIFF and MNG may use either lossless or lossy methods.

Lossless compression techniques


Most lossless compression programs do two things in sequence: the first step generates a statistical model for the input data, and the second step uses this model to map input data to bit sequences in such a way that "probable" (e.g. frequently encountered) data will produce shorter output than "improbable" data.

The primary encoding algorithms used to produce bit sequences are Huffman coding
Huffman coding
In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. The term refers to the use of a variable-length code table for encoding a source symbol where the variable-length code table has been derived in a particular way based on...

 (also used by DEFLATE) and arithmetic coding
Arithmetic coding
Arithmetic coding is a method for lossless data compression. Normally, a string of characters such as the words "hello there" is represented using a fixed number of bits per character, as in the ASCII code...

. Arithmetic coding achieves compression rates close to the best possible for a particular statistical model, which is given by the information entropy
Information entropy
In information theory, entropy is a measure of the uncertainty associated with a random variable. The term by itself in this context usually refers to the Shannon entropy, which quantifies, in the sense of an expected value, the information contained in a message, usually in units such as bits...

, whereas Huffman compression is simpler and faster but produces poor results for models that deal with symbol probabilities close to 1.

There are two primary ways of constructing statistical models: in a static model, the data is analyzed and a model is constructed, then this model is stored with the compressed data. This approach is simple and modular, but has the disadvantage that the model itself can be expensive to store, and also that it forces a single model to be used for all data being compressed, and so performs poorly on files containing heterogeneous data. Adaptive models dynamically update the model as the data is compressed. Both the encoder and decoder begin with a trivial model, yielding poor compression of initial data, but as they learn more about the data performance improves. Most popular types of compression used in practice now use adaptive coders.

Lossless compression methods may be categorized according to the type of data they are designed to compress. While, in principle, any general-purpose lossless compression algorithm (general-purpose meaning that they can compress any bitstring) can be used on any type of data, many are unable to achieve significant compression on data that is not of the form for which they were designed to compress. Many of the lossless compression techniques used for text also work reasonably well for indexed image
Indexed color
In computing, indexed color is a technique to manage digital images' colors in a limited fashion, in order to save computer's memory and file storage, while speeding up display refresh and telecom transfers...

s.

Text


Statistical modeling algorithms for text (or text-like binary data such as executables) include:
  • Context Tree Weighting method (CTW)
  • Burrows-Wheeler transform
    Burrows-Wheeler transform
    The Burrows–Wheeler transform , is an algorithm used in data compression techniques such as bzip2. It was invented by Michael Burrows and David Wheeler in 1994 while working at DEC Systems Research Center in Palo Alto, California...

     (block sorting preprocessing that makes compression more efficient)
  • LZ77 (used by DEFLATE)
  • LZW
    LZW
    Lempel–Ziv–Welch is a universal lossless data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. It was published by Welch in 1984 as an improved implementation of the LZ78 algorithm published by Lempel and Ziv in 1978...


Multimedia


Techniques that take advantage of the specific characteristics of images such as the common phenomenon of contiguous 2-D areas of similar tones.
Every pixel but the first is replaced by the difference to its left neighbor. This leads to small values having a much higher probability than large values.
This is often also applied to sound files and can compress files which contain mostly low frequencies and low volumes.
For images this step can be repeated by taking the difference to the top pixel, and then in videos the difference to the pixel in the next frame can be taken.

A hierarchical version of this technique takes neighboring pairs of data points, stores their difference and sum, and on a higher level with lower resolution continues with the sums. This is called discrete wavelet transform
Discrete wavelet transform
In numerical analysis and functional analysis, a discrete wavelet transform is any wavelet transform for which the wavelets are discretely sampled...

. JPEG2000 additionally uses data points from other pairs and multiplication factors to mix then into the difference. These factors have to be integers so that the result is an integer under all circumstances. So the values are increased, increasing file size, but hopefully the distribution of values is more peaked.

The adaptive encoding uses the probabilities from the previous sample in sound encoding, from the left and upper pixel in image encoding, and additionally from the previous frame in video encoding. In the wavelet transformation the probabilities are also passed through the hierarchy.

Historical legal issues


Many of these methods are implemented in open-source and proprietary tools, particularly LZW and its variants. Some algorithms are patented in the USA
United States
The United States of America is a federal constitutional republic comprising fifty states and a federal district...

 and other countries and their legal usage requires licensing by the patent holder. Because of patents on certain kinds of LZW compression, and in particular licensing practices by patent holder Unisys that many developers considered abusive, some open source proponents encouraged people to avoid using the Graphics Interchange Format (GIF) for compressing image files in favor of Portable Network Graphics PNG, which combines the LZ77-based deflate algorithm with a selection of domain-specific prediction filters. However, the patents on LZW have now expired.

Many of the lossless compression techniques used for text also work reasonably well for indexed images, but there are other techniques that do not work for typical text that are useful for some images (particularly simple bitmaps), and other techniques that take advantage of the specific characteristics of images (such as the common phenomenon of contiguous 2-D areas of similar tones, and the fact that color images usually have a preponderance to a limited range of colors out of those representable in the color space).

As mentioned previously, lossless sound compression is a somewhat specialised area. Lossless sound compression algorithms can take advantage of the repeating patterns shown by the wave-like nature of the data – essentially using models to predict the "next" value and encoding the (hopefully small) difference between the expected value and the actual data. If the difference between the predicted and the actual data (called the "error") tends to be small, then certain difference values (like 0, +1, -1 etc. on sample values) become very frequent, which can be exploited by encoding them in few output bits.

It is sometimes beneficial to compress only the differences between two versions of a file (or, in video compression
Video compression
Video compression refers to reducing the quantity of data used to represent digital video images, and is a combination of spatial image compression and temporal motion compensation. Video compression is an example of the concept of source coding in Information theory...

, of an image). This is called delta compression
Delta encoding
Delta encoding is a way of storing or transmitting data in the form of differences between sequential data rather than complete files.Delta encoding is sometimes called delta compression, particularly where archival histories of changes are required .The differences are recorded in discrete files...

 (from the Greek letter Δ
Delta (letter)
Delta is the fourth letter of the Greek alphabet. In the system of Greek numerals it has a value of 4. It was derived from the Phoenician letter Dalet...

 which is commonly used in mathematics to denote a difference), but the term is typically only used if both versions are meaningful outside compression and decompression. For example, while the process of compressing the error in the above-mentioned lossless audio compression scheme could be described as delta compression
Delta encoding
Delta encoding is a way of storing or transmitting data in the form of differences between sequential data rather than complete files.Delta encoding is sometimes called delta compression, particularly where archival histories of changes are required .The differences are recorded in discrete files...

 from the approximated sound wave to the original sound wave, the approximated version of the sound wave is not meaningful in any other context.

Lossless compression methods


By operation of the pigeonhole principle
Pigeonhole principle
In mathematics and computer science, the pigeonhole principle, also known as Dirichlet's box principle, is exemplified by such things as the fact that in a family of three children there must be at least two of the same gender...

, no lossless compression algorithm can efficiently compress all possible data, and completely random data streams cannot be compressed. For this reason, many different algorithms exist that are designed either with a specific type of input data in mind or with specific assumptions about what kinds of redundancy the uncompressed data are likely to contain.

Some of the most common lossless compression algorithms are listed below.

General purpose

  • Run-length encoding
    Run-length encoding
    Run-length encoding is a very simple form of data compression in which runs of data are stored as a single data value and count, rather than as the original run...

     – a simple scheme that provides good compression of data containing lots of runs of the same value.
  • LZW
    LZW
    Lempel–Ziv–Welch is a universal lossless data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. It was published by Welch in 1984 as an improved implementation of the LZ78 algorithm published by Lempel and Ziv in 1978...

     – used by gif and compress among others
  • Deflate
    DEFLATE
    Deflate is a lossless data compression algorithm that uses a combination of the LZ77 algorithm and Huffman coding. It was originally defined by Phil Katz for version 2 of his PKZIP archiving tool, and was later specified in RFC 1951....

     – used by gzip, modern versions of zip and as part of the compression process of PNG, PPP, HTTP, SSH

Audio

  • Apple Lossless
    Apple Lossless
    Apple Lossless is an audio codec developed by Apple Inc. for lossless data compression of digital music....

     – ALAC (Apple Lossless Audio Codec)
  • apt-X
    Apt-X
    The digital audio data reduction technology now known as apt-X is a family of proprietary audio codec compression algorithms developed by APT Licensing. From March 14, 2009, APT Licensing changed the company's trading identity to APTX. The original algorithm was developed in the 1980s by Dr...

     Lossless
  • ATRAC
    ATRAC
    Adaptive Transform Acoustic Coding is a family of proprietary audio compression algorithms developed by Sony. MiniDisc was the first commercial product to incorporate ATRAC in 1992. ATRAC allowed a relatively small disc like MiniDisc to have the same running time as CD while storing audio...

     Advanced Lossless
  • Audio Lossless Coding
    Audio Lossless Coding
    MPEG-4 Audio Lossless Coding, also known as MPEG-4 ALS, is an extension to the MPEG-4 Part 3 audio standard to allow lossless audio compression. The extension was finalized in December 2005 and published as ISO/IEC 14496-3:2005/Amd 2:2006 in 2006...

     – also known as MPEG-4 ALS
  • MPEG-4 SLS
    MPEG-4 SLS
    MPEG-4 SLS, or MPEG-4 Scalable to Lossless as per ISO/IEC 14496-3:2005/Amd 3:2006 , is an extension to the MPEG-4 Part 3 standard to allow lossless audio compression scalable to lossy MPEG-4 General Audio coding methods...

     – also known as HD-AAC
  • Direct Stream Transfer – DST
  • Dolby TrueHD
    Dolby TrueHD
    Dolby TrueHD is an advanced lossless multi-channel audio codec developed by Dolby Laboratories which is intended primarily for high-definition home-entertainment equipment such as Blu-ray Disc and HD DVD. It is the successor to the AC-3 Dolby Digital surround sound codec which was used as the...

  • DTS-HD Master Audio
    DTS-HD Master Audio
    DTS-HD Master Audio is a lossless audio codec created by Digital Theater System. It was previously known as DTS++. It is an extension of DTS which, when played back on devices which do not support the Master Audio or High Resolution extension, degrades to a "core" track which is lossy...

  • Free Lossless Audio Codec – FLAC
  • Meridian Lossless Packing
    Meridian Lossless Packing
    Meridian Lossless Packing, also known as Packed PCM , is a proprietary lossless compression technique for compressing PCM audio data developed by Meridian Audio, Ltd. MLP is the standard lossless compression method for DVD-Audio content and typically provides about 2:1 compression on most music...

     – MLP
  • Monkey's Audio
    Monkey's Audio
    Monkey’s Audio is a file format for audio data compression. Being a lossless format, Monkey’s Audio does not discard data during the process of encoding, unlike lossy compression methods such as AAC, MP3, Vorbis and Musepack....

     – Monkey's Audio APE
  • OptimFROG
    OptimFROG
    OptimFROG is a proprietary lossless audio data compression codec developed by Florin Ghido. OptimFROG is optimized for very high compression ratios, even for the price of slower encoding and decoding.-OptimFROG DualStream:...

  • RealPlayer
    RealPlayer
    RealPlayer is a closed source cross-platform media player by RealNetworks that plays a number of multimedia formats including MP3, MPEG-4, QuickTime, Windows Media, and multiple versions of proprietary RealAudio and RealVideo formats....

     – RealAudio Lossless
  • Shorten
    Shorten
    Shorten is a file format optimized for compressing audio data. It is a form of data compression of files and is used to losslessly compress CD-quality audio files . Shorten is no longer developed and more mature lossless audio codecs such as FLAC, MPEG-4 ALS, Monkey's Audio , TTA, and WavPack ...

     – SHN
  • TTA
    TTA (codec)
    True Audio is a free, real-time lossless audio codec, based on adaptive prognostic filters.Also, .tta is the generic extension to filenames of audio files created by True Audio codec.-Codec overview:...

     – True Audio Lossless
  • WavPack
    WavPack
    WavPack is a free, open source lossless audio compression format developed by David Bryant.-Features:WavPack compression can compress 8-, 16-, 24-, and 32-bit floating point audio files in the .WAV file format. It also supports surround sound streams and high frequency sampling rates...

     – WavPack lossless
  • WMA Lossless – Windows Media Lossless

Graphics

  • ABO
    Adaptive Binary Optimization
    Adaptive Binary Optimization, , is a supposed lossless image compression algorithm by MatrixView Ltd. It uses a patented method to compress the high correlation found in digital content signals and additional compression with standard entropy encoding algorithms such as Huffman coding.- External...

     – Adaptive Binary Optimization
  • GIF – (lossless, but contains a very limited number color range)
  • JBIG2
    JBIG2
    JBIG2 is an image compression standard for bi-level images, developed by the Joint Bi-level Image Experts Group. It is suitable for both lossless and lossy compression...

     – (lossless or lossy compression of B&W images)
  • JPEG-LS
    JPEG-LS
    The Joint Photographic Experts Group, in addition to their well-known lossy image compression techniques, JPEG and JPEG 2000, also have three standards for lossless compression .-Lossless JPEG:...

     – (lossless/near-lossless compression standard)
  • JPEG 2000
    JPEG 2000
    JPEG 2000 is a wavelet-based image compression standard. It was created by the Joint Photographic Experts Group committee in the year 2000 with the intention of superseding their original discrete cosine transform-based JPEG standard...

     – (includes lossless compression method, as proven by Sunil Kumar, Prof San Diego State University)
  • JPEG XR - formerly WMPhoto and HD Photo, includes a lossless compression method
  • PGF
    Progressive Graphics File
    PGF is a wavelet-based bitmapped image format that employs lossless and lossy data compression. PGF was created to improve upon and replace the JPEG format...

     – Progressive Graphics File (lossless or lossy compression)
  • PNG – Portable Network Graphics
  • TIFF - Tagged Image File Format

Video

  • Animation codec
    Animation codec
    The Animation codec is a fast lossless Quicktime video codec created by Apple Computer to enable playback of RGB video in real time without expensive hardware. It is one of the few video codecs that support an alpha channel. It also supports color depths from 1 to 32 bit...

  • CorePNG
  • Dirac
    Dirac (codec)
    Dirac is an open and royalty-free video compression format, specification and system developed by BBC Research at the BBC. Schrödinger and dirac-research are an open and royalty-free software implementations of Dirac...

     - Has a lossless mode.
  • FFV1
    FFV1
    FFV1, which stands for "FF video codec 1", is a lossless intra-frame video format. It can use either variable length coding or arithmetic coding for entropy coding. The encoder and decoder are part of the free, open-source library libavcodec in the project FFmpeg...

  • JPEG 2000
    JPEG 2000
    JPEG 2000 is a wavelet-based image compression standard. It was created by the Joint Photographic Experts Group committee in the year 2000 with the intention of superseding their original discrete cosine transform-based JPEG standard...

  • Huffyuv
    Huffyuv
    Huffyuv is a lossless video codec created by Ben Rudiak-Gould which is meant to replace uncompressed YCbCr as a video capture format. Despite the "YUV" in the name, it does not compress the YUV color space, but YCbCr...

  • Lagarith
    Lagarith
    Lagarith is an open source lossless video codec written by Ben Greenwood. It was designed and written with a few aims in mind:*Speed; while not as fast as Huffyuv, encoding speed is comparable to many other lossless video codecs, although decoding speed may be slower...

  • MSU Lossless Video Codec
    MSU Lossless Video Codec
    The MSU Lossless Video Codec is a video codec developed by the Graphics & Media Lab Video Group of Moscow State University. The aim of development was producing lossless video at very high rate of compression...

  • SheerVideo
    SheerVideo
    SheerVideo is a family of proprietary lossless video codecs developed by BitJazz Inc. to enable capture, editing, playback, and archival of professional-quality lossless video formats in real time on low-power inexpensive hardware such as laptop computers and video cameras...


Cryptography


Cryptosystem
Cryptosystem
There are two different meanings of the word cryptosystem. One is used by the cryptographic community, while the other is the meaning understood by the public.- General meaning :...

s often compress data before encryption for added security; compression prior to encryption helps remove redundancies and patterns that might facilitate cryptanalysis. However, many ordinary lossless compression algorithms introduce predictable patterns (such as headers, wrappers, and tables) into the compressed data that may actually make cryptanalysis easier. Therefore, cryptosystems often incorporate specialized compression algorithms specific to the cryptosystem—or at least demonstrated or widely held to be cryptographically secure—rather than standard compression algorithms that are efficient but provide potential opportunities for cryptanalysis.

Limitations


Lossless data compression algorithms cannot guarantee compression for all input data sets. In other words, for any (lossless) data compression algorithm, there will be an input data set that does not get smaller when processed by the algorithm. This is easily proven with elementary mathematics using a counting argument, as follows:
  • Assume that each file is represented as a string of bits of some arbitrary length.
  • Suppose that there is a compression algorithm that transforms every file into a distinct file which is no longer than the original file, and that at least one file will be compressed into something that is shorter than itself.
  • Let be the least number such that there is a file with length bits that compresses to something shorter. Let be the length (in bits) of the compressed version of .
  • Because , every file of length keeps its size during compression. There are such files. Together with , this makes files which all compress into one of the files of length .
  • But is smaller than , so by the pigeonhole principle
    Pigeonhole principle
    In mathematics and computer science, the pigeonhole principle, also known as Dirichlet's box principle, is exemplified by such things as the fact that in a family of three children there must be at least two of the same gender...

     there must be some file of length which is simultaneously the output of the compression function on two different inputs. That file cannot be decompressed reliably (which of the two originals should that yield?), which contradicts the assumption that the algorithm was lossless.
  • We must therefore conclude that our original hypothesis (that the compression function makes no file longer) is necessarily untrue.


Any lossless compression algorithm that makes some files shorter must
necessarily make some files longer, but it is not necessary that those files become very much longer. Most practical compression algorithms provide an "escape" facility that can turn off the normal coding for files that would become longer by being encoded. Then the only increase in size is a few bits to tell the decoder that the normal coding has been turned off for the entire input. For example, DEFLATE
DEFLATE
Deflate is a lossless data compression algorithm that uses a combination of the LZ77 algorithm and Huffman coding. It was originally defined by Phil Katz for version 2 of his PKZIP archiving tool, and was later specified in RFC 1951....

 compressed files never need to grow by more than 5 bytes per 65,535 bytes of input.

In fact, if we consider files of length N, if all files were equally probable, then for any lossless compression that reduces the size of some file, the expected length of a compressed file (averaged over all possible files of length N) must necessarily be greater than N. So if we know nothing about the properties of the data we are compressing, we might as well not compress it at all. A lossless compression algorithm is useful only when we are more likely to compress certain types of files than others; then the algorithm could be designed to compress those types of data better.

Thus, the main lesson from the argument is not that one risks big losses, but merely that one cannot always win. To choose an algorithm always means implicitly to select a subset of all files that will become usefully shorter. This is the theoretical reason why we need to have different compression algorithms for different kinds of files: there cannot be any algorithm that is good for all kinds of data.

The "trick" that allows lossless compression algorithms, used on the type of data they were designed for, to consistently compress such files to a shorter form is that the files the algorithm are designed to act on all have some form of easily-modeled redundancy
Redundancy (information theory)
Redundancy in information theory is the number of bits used to transmit a message minus the number of bits of actual information in the message. Informally, it is the amount of wasted "space" used to transmit certain data...

 that the algorithm is designed to remove, and thus belong to the subset of files that that algorithm can make shorter, whereas other files would not get compressed or even get bigger. Algorithms are generally quite specifically tuned to a particular type of file: for example, lossless audio compression programs do not work well on text files, and vice versa.

In particular, files of random data cannot be consistently compressed by any conceivable lossless data compression algorithm: indeed, this result is used to define the concept of randomness in algorithmic complexity theory.

There have been many claims through the years of companies achieving 'perfect-compression' where an arbitrary number of random bits can always be compressed to N-1 bits. This is, of course, impossible: if such an algorithm existed, it could be applied repeatedly to losslessly reduce any file to length 0. These kinds of claims can be safely discarded without even looking at any further details regarding the purported compression scheme.

An algorithm
Algorithm
In mathematics, computing, linguistics, and related subjects, an algorithm is an effective method for solving a problem using a finite sequence of instructions. Algorithms are used for calculation, data processing, and many other fields....

 that is asserted to be able to losslessly compress any data stream is provably impossible. In a more general sense, any compression algorithm whose proposed properties contradict fundamental laws of mathematics
Mathematics
Mathematics is the science and study of quantity, structure, space, and change. Mathematicians seek out patterns, formulate new conjectures, and establish truth by rigorous deduction from appropriately chosen axioms and definitions....

 may be called magic.

On the other hand, it has also been proven that there is no algorithm to determine whether a file is incompressible in the sense of Kolmogorov complexity
Kolmogorov complexity
In algorithmic information theory , the Kolmogorov complexity of an object such as a piece of text is a measure of the computational resources needed to specify the object...

; hence, given any particular file, even if it appears random, it's possible that it may be significantly compressed, even including the size of the decompressor. An example is the digits of the mathematical constant pi
Pi
Pi or π is a mathematical constant whose value is the ratio of any circle's circumference to its diameter in Euclidean space; this is the same value as the ratio of a circle's area to the square of its radius. The symbol π was first proposed by the Welsh mathematician William Jones in 1706...

, which appear random but can be generated by a very small program. However, even though it cannot be determined whether a particular file is incompressible, a simple theorem about incompressible strings shows that over 99% of files of any given length cannot be compressed by more than one byte (including the size of the decompressor).

Mathematical background


Any compression algorithm can be viewed as a function
Function (mathematics)
In mathematics, a function is a relation between a given set of elements and another set of elements , which associates each element in the domain with exactly one element in the codomain...

 that maps sequences of units (normally octet
Octet
An octet is a group consisting of eight elements. It has several specific meanings:* Octet , a musical ensemble consisting of eight instruments....

s) into other sequences of the same units. Compression is successful if the resulting sequence is shorter than the original sequence. In order for a compression algorithm to be considered lossless, there needs to exist a reverse mapping from compressed bit sequences to original bit sequences; that is to say, the compression method would need to encapsulate a bijection
Bijection
In mathematics, a bijection, or a bijective function is a function f from a set X to a set Y with the property that, for every y in Y, there is exactly one x in X such that f = y and no unmapped element remains in both X and Y.Alternatively, f is bijective if it is a one-to-one correspondence...

 between "plain" and "compressed" bit sequences.

The sequences of length N or less are clearly a strict superset of the sequences of length N-1 or less. It follows that there are more sequences of length N or less than there are sequences of length N-1 or less. It therefore follows from the pigeonhole principle
Pigeonhole principle
In mathematics and computer science, the pigeonhole principle, also known as Dirichlet's box principle, is exemplified by such things as the fact that in a family of three children there must be at least two of the same gender...

 that it is not possible to map every sequence of length N or less to a unique sequence of length N-1 or less. Therefore it is not possible to produce an algorithm that reduces the size of every possible input sequence.

Psychological background


Most everyday files are relatively 'sparse' in an information entropy
Information entropy
In information theory, entropy is a measure of the uncertainty associated with a random variable. The term by itself in this context usually refers to the Shannon entropy, which quantifies, in the sense of an expected value, the information contained in a message, usually in units such as bits...

 sense, and thus, most lossless algorithms a layperson is likely to apply on regular files compress them relatively well. This may, through misapplication of intuition
Intuition (knowledge)
Intuition is the apparent ability to acquire knowledge without inference or the use of reason. “The word ‘intuition’ comes from the Latin word 'intueri', which is often roughly translated as meaning ‘to look inside’ or ‘to contemplate’." Intuition provides us with beliefs that we cannot necessarily...

, lead some individuals to conclude that a well-designed compression algorithm can compress any input, thus, constituting a magic compression algorithm.

Points of application in real compression theory


Real compression algorithm designers accept that streams of high information entropy cannot be compressed, and accordingly, include facilities for detecting and handling this condition. An obvious way of detection is applying a raw compression algorithm and testing if its output is smaller than its input. Sometimes, detection is made by heuristics; for example, a compression application may consider files whose names end in ".zip", ".arj" or ".lha" uncompressible without any more sophisticated detection. A common way of handling this situation is quoting input, or uncompressible parts of the input in the output, minimising the compression overhead. For example, the zip
ZIP (file format)
The ZIP file format is a data compression and archive format. A ZIP file contains one or more files that have been compressed to reduce file size, or stored as-is...

 data format specifies the 'compression method' of 'Stored' for input files that have been copied into the archive verbatim.

The Million Random Number Challenge


Mark Nelson, frustrated over many cranks trying to claim having invented a magic compression algorithm appearing in comp.compression, has constructed a 415,241 byte binary file (http://marknelson.us/attachments/million-digit-challenge/AMillionRandomDigits.bin) of highly entropic content, and issued a public challenge of $100 to anyone to write a program that, together with its input, would be smaller than his provided binary data yet be able to reconstitute ("decompress") it without error.

The FAQ
FAQ
Frequently asked questions, or FAQs are listed questions and answers, all supposed to be frequently asked in some context, and pertaining to a particular topic. Since the acronym FAQ originated in textual media, its pronunciation varies; "fack," "fax," "facts," and "F.A.Q." are commonly heard...

 for the comp.compression newsgroup
Newsgroup
A usenet newsgroup is a repository usually within the Usenet system, for messages posted from many users in different locations. The term may be confusing to some, because it is usually a discussion group. Newsgroups are technically distinct from, but functionally similar to, discussion forums on...

 contains a challenge by Mike Goldman offering $5,000 for a program that can compress random data. Patrick Craig took up the challenge, but rather than compressing the data, he split it up into separate files all of which ended in the number '5' which was not stored as part of the file. Omitting this character allowed the resulting files (plus, in accordance with the rules, the size of the program that reassembled them) to be smaller than the original file. However, no actual compression took place, and the information stored in the names of the files was necessary in order to reassemble them in the correct order into the original file, and this information was not taken into account in the file size comparison. The files themselves are thus not sufficient to reconstitute the original file, the file names are also necessary. A full history of the event, including discussion on whether or not the challenge was technically met, is on Patrick Craig's web site.

See also

  • Audio data compression
  • Comparison of file archivers
    Comparison of file archivers
    The following tables compare general and technical information for a number of file archivers. Please see the individual products' articles for further information. This article is not all-inclusive or necessarily up-to-date...

  • David A. Huffman
    David A. Huffman
    David Albert Huffman was a pioneer in the computer science field.Throughout his life, Huffman made significant contributions to the study of finite state machines, switching circuits, synthesis procedures, and signal designs...

  • Information entropy
    Information entropy
    In information theory, entropy is a measure of the uncertainty associated with a random variable. The term by itself in this context usually refers to the Shannon entropy, which quantifies, in the sense of an expected value, the information contained in a message, usually in units such as bits...

  • Kolmogorov complexity
    Kolmogorov complexity
    In algorithmic information theory , the Kolmogorov complexity of an object such as a piece of text is a measure of the computational resources needed to specify the object...

  • Data compression
    Data compression
    In computer science and information theory, data compression or source coding is the process of encoding information using fewer bits than an unencoded representation would use, through use of specific encoding schemes.As with any communication, compressed data communication only works when both...

  • Precompressor
    Precompressor
    A precompressor is a computer program, which alternates file content so that a real lossless compression program will achieve better results than without precompressing. This is possible by creating such patterns that compression programs will recognize....

  • Lossy data compression
    Lossy data compression
    A lossy compression method is one where compressing data and then decompressing it retrieves data that is different from the original, but is close enough to be useful in some way. Lossy compression is most commonly used to compress multimedia data , especially in applications such as streaming...

  • Lossless Transform Audio Compression (LTAC)
  • List of codecs
  • Information theory
    Information theory
    Information theory is a branch of applied mathematics and electrical engineering involving the quantification of information. Historically, information theory was developed by Claude E. Shannon to find fundamental limits on compressing and reliably storing and communicating data...

  • universal code (data compression)
    Universal code (data compression)
    In data compression, a universal code for integers is a prefix code that maps the positive integers onto binary codewords, with the additional property that whatever the true probability distribution on integers, as long as the distribution is monotonic , the expected lengths of the codewords are...

  • Grammar induction
    Grammar Induction
    Grammatical induction, also known as grammatical inference or syntactic pattern recognition, refers to the process in machine learning of learning a formal grammar from a set of observations, thus constructing a model which accounts for the characteristics of the observed objects...


External links