A Novel Block-based Scheme for Arithmetic Coding

It is well-known that for a given sequence, its optimal codeword length is fixed. Many coding schemes have been proposed to make the codeword length as close to the optimal value as possible. In this paper, a new block-based coding scheme operating on the subsequences of a source sequence is proposed. It is proved that the optimal codeword lengths of the subsequences are not larger than that of the given sequence. Experimental results using arithmetic coding will be presented.


Introduction
For any discrete memoryless source (DMS, an independent identically distributed source-a typical example is a sequence of independent flips of an unbiased coin), Shannon's lossless source coding theorem [1] shows that the optimal lossless compression rate is bounded by the entropy of the given source.Since then, there has been considerable interest in designing source codes and the objective is to make them matched to different applications.As regards the existing source codes, the most widely used algorithms are indubitably Huffman coding [2], arithmetic coding [3,4] and Lempel-Ziv coding [5,6].Of these coding methods, arithmetic coding offers great potential for the combination of compression and encryption.Recently, many novel approaches on joint compression and encryption have been presented [7][8][9][10][11][12][13][14] and interested readers may find their corresponding cryptanalysis in [15][16][17][18].
The first exhibited coding method is the well-known Huffman coding, proved to be optimal by Huffman [2].Due to the optimality of Huffman coding, it has been applied into many international OPEN ACCESS standards, such as JPEG [19].Later, with the appearance of arithmetic coding, Huffman coding has been replaced gradually and many new standards (such as JPEG2000 [20] and H.264 [21]) in multimedia have utilized modified versions of arithmetic coding to serve as their entropy coders.
The predecessor of arithmetic coding is Shannon-Fano-Elias coding.The extension of Shannon-Fano-Elias method to sequences is based on the enumerative methods presented by Cover [22].Nevertheless, both of these codes suffer from precision problem.Fortunately, Rissanen and Langdon [3] successfully solve this problem and characterize the family of arithmetic codes through the notion of the decodability criterion which applies to all such codes.Actually, a practical implementation of arithmetic coding is due to Witten et al. [23] and a revisited version of arithmetic coding should be attributed to Moffat et al. [24].
As is known, the prerequisite for the establishment of Shannon's theorem is that the encoder should be optimal and work according to the distribution of the given source, which indicates the compression ratio is restricted by the entropy rate of the given DMS.The contribution of this paper is to draw freedom lines not bound by entropy rate constraint for a given DMS.The source sequence is first separated into two or more subsequences which are encoded independently.Then we consider a simple case that the length of each subsequence is the same and analyze the proposed coding scheme theoretically.Next, we prove that for general case, the sum of optimal codeword lengths of the subsequences is no longer than that of the original sequence.Moreover, the subsequences are encoded without interference, which facilities parallel computing.In addition, it should be noted that the coding algorithms adopted here are for a class of mean-optimal source codes.As a result, in the sequel, arithmetic coding is the main compression algorithm so as to achieve desired results.
The rest of this paper is arranged as follows: in the next section, the proposed scheme is described in detail.In Section 3, its constraint and feasibility are analyzed.In Section 4 we introduce a simple arithmetic coding scheme and present the experimental results as well.Finally, conclusions are drawn in Section 5.

Block-Based Coding
Let X be a random variable having value A or B: with probability ( ) with probability ( )  be an independent and identically distributed sequence of length n generated according to this distribution and let n A and n B denote the number of times that symbols A and B appeared, respectively.Let x be a realization of X, then the optimal codeword length L of this sequence is given by [25]: where here and throughout the sequel in the first subsequence be n 1A and n 1B , respectively.For the second one, they are n 2A and n 2B .Denote the actual probability mass function of the source sequence as p(X).For the two subsequences, they are q(X) and r(X), respectively.As the symbols of the given binary sequence is independent, we have [25]: where H(X n ) is the entropy of the source sequence.Note that the entropy here refers to the information entropy presented by Shannon [1].There are of course other kinds of entropies, interested readers can find them in [26][27][28][29].Thus, the optimal codeword length of the source sequence can be rewritten as: where L 1 and L 2 denote the respective codeword lengths of the two subsequences after encoding in accordance with the distribution of the source sequence.Actually, it can be easily found that the probability mass functions of the two subsequences and the source sequence are not necessarily the same.Therefore, after partitioning the real optimal codeword length of the first subsequence is: For the second subsequence, the real optimal codeword length is expressed as: From Equations ( 4)- (6), it seems that the source sequence has been encoded according to a wrong distribution after partitioning.In other words, an i.i.d.source sequence can be further compressed if it is divided into two subsequences.In the following subsections, we shall formally analyze this fact.

An Alphabet of Size Two
Consider a given binary sequence of length n.Without loss of generality, suppose that n is an even number and the two subsequences have the same length, i.e., 1 2 n n = .Then similar to the manner above, we have: The optimal codeword length of the binary sequence can be given by: log log log log After partition, it is easy to observe that  .Therefore, we can obtain the following pair of equations: and the sum of the optimal codeword lengths of these two subsequences is: The above discussion leads to Theorem 1.
Theorem 1.For a given binary message X n with length ( 2) n n  , the sum of the optimal codeword length of the two equally-divided subsequences is no greater than that of the given message sequence as: with equality holds if and only if Proof of Theorem 1. From Equations ( 8)-( 10), we have: , we have: , we can rewrite Equation ( 12) as: Equation ( 13) implies that * sum L is a function of n 1A since n and n A are constants for a given binary sequence.In order to make Equation ( 13) clear, here let F(t) and t denote * sum L and n 1A , respectively.
Then differentiating F(t) with respect to t yields: After rearrangement, we have: As 0

A Special Case for an Alphabet of Size 2
In this subsection, we shall demonstrate the case where the two subsequences are of arbitrary lengths while the sum of the two lengths are constant for a given source message sequence.
Theorem 2. For a given binary source sequence n n n + = ), then the sum of the optimal codeword lengths of the two subsequences is no greater than the length of the given binary sequence, i.e., Before the formal proof is presented, the following lemma [25] is required: Lemma 1: Let p(x) and q(x), x X  , be two probability mass functions.Then   || 0 D p q  with equality holds if and only if ( ) ( ) p x q x  for all x.Here, ( ) D  represents the relative entropy.
Proof of Theorem 2. From the previous part, we have: , , , For symbol A, we have: Now, expanding the first part of Equation ( 17) using Equation (18) with respect to the optimal codeword length of symbol A in the given source sequence, we have: Similarly, for symbol B we have: Combining Equations ( 19) and (20), we have: From Lemma 1, we know that: If the equality holds, we have: As a result, the proof of Theorem 2 has been shown.Additionally, we can see that Theorem 1 is a special case of Theorem 2 and Equation ( 21) can be considered as a coding scheme which is designed based on a wrong distribution [25].

An Alphabet of Size D > 2
In the above two subsections, we have discussed the case that the alphabet size is two.In this subsection, we shall deal with the case of alphabet size 2 D  .Consider an i.i.d.random variable Z taking value from the set {1, 2, , } D  and a given discrete sequence 1 2 n Z Z Z  of length n.Suppose that the number of occurrences of symbol i is n i for some {1, 2, , } i D   and the corresponding probability is p(i).Obviously, we have: Following the preceding method, we once more partition the given sequence into two subsequences Z A and Z B with length n A and n B , respectively.We further assume that the probability of symbol i is ( ) A p i and the number of times that symbol i occurred in Z A is n iA .For Z B , they are ( ) B p i and n iB , respectively.Similarly, we have: and: Then the entropies of the source sequence and the two subsequences are given by: Their corresponding optimal codeword lengths: Similar to Theorem 2, we have the following theorem.
Theorem 3.For a discrete sequence from a multiple-symbol source, after partitioning it into two subsequences (Z A and Z B ), its optimal codeword length

equality holds if and only if their probability mass functions satisfy
Proof of Theorem 3. Let the source sequence be represented by : As the source sequence is independent and identically distributed, we have: Similar way to the proof of Theorem 2, we have:

np i n p i n p i p i p i p i p i n p i n p i p i p i p i p i
Thus:

L np i p i p i p i n p i n p i p i p i p i p i n D p p n D p p n H n H
As: we have: with equality holds if and only if: Now, we can see that not only binary sequences but also the non-binary ones can be further compressed by using the proposed method.

Constraint and Feasibility
In Section 2, we have studied the advantages of block-based coding.Particularly, as the source message is sufficiently large, we can repeat the partition operation.Nevertheless, this has the downside of increasing the size of the output file when the number of subsequences or alphabet size grows since more distributions will take up too much space in the output file.In this section, we shall show the constraint and feasibility of our approach.
For a given binary sequence 1 2 n x x x  with length n and probability mass function ( , , , ) x   bits [25].This means that if the source is i.i.d., this code achieves an average codeword length within 2 bits above the entropy.If the prefix-free restriction is removed, a codeword length of x   bits can be achieved.When the given message sequence 1 2 n x x x  is partitioned into two subsequences of length n 1 and n 2 , the practical codeword lengths of the two subsequences can be given by: Now, consider the following two special cases: (a) Suppose that the message sequence is 010101…, i.e., equal number of zeros and ones.Obviously, it is not compressible.However, if we separate it into two subsequences alternatively, one subsequence will have all zeros while another will consist of all ones.Both subsequences have zero entropy and this is the ideal case; (b) Suppose the message sequence is 010101… and the numbers of zeros and ones are both even numbers.After partitioned into three sequences, each one has equal probability of zero and one.
According to the preceding analysis, the final codeword length will be within 2 bits above the codeword length before partitioning.
There is no doubt that the second special case exists.Thus, we suggest applying this work to binary arithmetic coding when the size of target input file is much smaller.On the other hand, since the subsequences after partition are encoded without interference, this fact implies that parallel coding is feasible.Peculiarly, if the file to be compressed is considerably large, then we can partition it into multiple subsequences and encode them in parallel.

Experimental Results
As an extension of Shannon-Fano-Elias coding, arithmetic coding is an efficient coding scheme for lossless compression.Unlike Huffman coding, the process of arithmetic coding does not require much additional memory as the sequence length increases.Therefore arithmetic coding has been adopted in quite a number of international standards.On the other hand, there is no need for a representative sample of sequence and the probability model can be updated with each symbol read, which indicates that adaptive coding can be utilized (but won't perform well).
In order to further illustrate the superiority of the proposed coding scheme, we have performed a simple binary coding experiment.The operating procedures are described in Table 1 and one can refer to Figure 2 as well.

Input Original sequence Output Codeword sequence
Step 1: Read the source sequence to buffer in bits.
Step 2: Find the middle symbol in the original sequence.
Step 3: Divide the original sequence into two subsequences.
Step 4: Encode the two subsequences according to their own probability models and then obtain two codeword sequences.
Step 5: Combine the two codeword sequences.Eighteen test files from the Calgary Corpus [30] are compressed to show the performance of this compression method.The test results are listed in Table 2, where R T and R P represent the compression ratio of the traditional and the proposed schemes, respectively.Note that the proposed method is used to further improve the compression ratio instead of designing a new source coding algorithm.Consequently, we just compare the compression ratio of the proposed scheme with the traditional arithmetic coding algorithm.Similarly, another experiment is performed by employing a fixed model with 256 possible source symbols.The detailed operating procedures are the same as that listed in Table 1 except that the source sequence is read in bytes rather than in bits.The corresponding test results are listed in Table 3.So far, the compression ratios of most present compression algorithms cannot break the restriction of entropy.However, from Tables 2 and 3, it can be found that with extra relative entropy, the compression ratio of the proposed scheme is smaller the entropy of the original sequence, which is highlighted in the two tables.The reason for this phenomenon can boil down to the following three aspects: The first aspect is important since the compression ratio of a given source sequence depends on the probability distribution of the source sequence.As proved in Section 2, our method is able to work better than the traditional one because of the existence of the extra relative entropy.Meanwhile, a good partition method can increase the extra relative entropy.In other words, when there is a greater difference between the source sequence and the subsequence, the extra relative entropy will be larger and further the compression ratio will be higher.This fact exactly reflects the importance of Aspect (b).The importance of Aspect (c) is conspicuous and we no longer repeat it.In addition, as the subsequences are encoded independently, we can perform the coding by parallel processing which can obviously reduce the processing time.

Conclusions
In this paper, we have proved that the overall codeword length after sequence partition is no greater than the original one.The original sequence can be regarded as the case that the code is designed using a wrong distribution.Because of the existence of error in the encoding process, we cannot divide the sequence into multiple sequences infinitely.Nonetheless, if we perform the sequence separation properly according to the length of the original sequence, the expected codeword length can be achieved.This fact indirectly suggests that we can implement our scheme efficiently by parallel coding.Furthermore, since our work depends on the partition method, our future work will focus on how to partition different kinds of files and which kinds of files should be partitioned.

2 log
( ) : log ( )    .Let the given binary message sequence be divided into two subsequences of lengths 1 n and 2 n , respectively.Let the number of symbols A and B

Figure 1 .
Figure 1.A plot of H* when (a) n A < n/2; and (b) n A ≥ n/2.

Figure 2 .
Figure 2. Encoding process of the proposed arithmetic coding scheme....A A A B A B B A B A B (a) The probability distribution of the source sequence; (b) The partition method; (c) The encoding function.