# arithmetic encoding

*Arithmetic coding* is a technique for achieving near-optimal entropy encoding.

An arithmetic encoder takes a string of symbols as input and produces a rational number in the interval $[0,1)$ as output. As each symbol is processed, the encoder will restrict the output to a smaller interval.

Let $N$ be the number of distinct symbols in the input; let ${x}_{1},{x}_{2}\mathrm{\dots}{x}_{N}$ represent the symbols, and let ${P}_{1},{P}_{2}\mathrm{\dots}{P}_{N}$ represent the probability of each symbol appearing. At each step in the process, the output is restricted to the current interval $[y,y+R)$. Partition^{} this interval into $N$ disjoint subintervals:

$${I}_{1}=[y,y+{P}_{1}R)$$ |

$${I}_{2}=[y+{P}_{1}R,y+{P}_{1}R+{P}_{2}R)$$ |

$$\mathrm{\vdots}$$ |

$${I}_{N}=[y+\sum _{i=1}^{N-1}{P}_{i}R,y+R)$$ |

Therefore the of ${I}_{i}$ is ${P}_{i}R$. If the next symbol is ${x}_{i}$, then restrict the output to the new interval ${I}_{i}$.

Note that at each stage, all the possible intervals are pairwise disjoint. Therefore a specific sequence^{} of symbols produces exactly one unique output range, and the process can be reversed.

Since arithmetic encoders are typically implemented on binary computers, the actual output of the encoder is generally the shortest sequence of bits representing the fractional part of a rational number in the final interval.

Suppose our entire input string contains $M$ symbols: then ${x}_{i}$ appears exactly ${P}_{i}M$ times in the input. Therefore, the size of the final interval will be

$${R}_{f}=\prod _{i=1}^{N}{P}_{i}^{{P}_{i}M}$$ |

The number of bits necessary to write a binary fraction in this range is

$-{\mathrm{log}}_{2}{R}_{f}$ | $=$ | $-{\mathrm{log}}_{2}{\displaystyle \prod _{i=1}^{N}}{P}_{i}^{{P}_{i}M}$ | ||

$=$ | $\sum _{i=1}^{N}}-{\mathrm{log}}_{2}{P}_{i}^{{P}_{i}M$ | |||

$=$ | $\sum _{i=1}^{N}}-{P}_{i}M{\mathrm{log}}_{2}{P}_{i$ |

By Shannon’s theorem^{}, this is the total entropy^{} of the original message. Therefore arithmetic encoding is near-optimal entropy encoding.

Title | arithmetic encoding |
---|---|

Canonical name | ArithmeticEncoding |

Date of creation | 2013-03-22 12:32:20 |

Last modified on | 2013-03-22 12:32:20 |

Owner | vampyr (22) |

Last modified by | vampyr (22) |

Numerical id | 4 |

Author | vampyr (22) |

Entry type | Definition |

Classification | msc 68P30 |

Classification | msc 94A24 |

Synonym | arithmetic coding |

Synonym | arithmetic encoder |

Synonym | arithmetic coder |

Related topic | HuffmanCoding |