# US 6,801,141 B2 · Method for lossless data compression using greedy sequential context-dependent grammar transform

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 6,801,141 B2
- Document ID: US6801141B2
- Status: Granted
- Kind: B2
- Application number: 10/438,357
- Filed: 2003-05-14
- Published: 2004-01-15
- Granted: 2004-10-05
- Earliest claimed: 2002-07-12
- Assignees: Slipstream Data Inc.
- Inventors: En-Hui Yang; Da-ke He
- Web page: https://patentgrep.com/patent/US6801141B2

## CPC

- H03M 7/4006: {Conversion to or from arithmetic code}
- H03M 7/3084: {using adaptive string matching, e.g. the Lempel-Ziv method}
- H03M: CODING; DECODING; CODE CONVERSION IN GENERAL (using fluidic means F15C4/00; optical analogue/digital converters G02F7/00; coding, decoding or code conversion, specially adapted for particular applications, see the relevant subclasses, e.g. G01D, G01R, G06F, G06T, G09G, G10L, G11B, G11C, H04B, H04L, H04M, H04N; ciphering or deciphering for cryptography or other purposes involving the need for secrecy G09C)

## Abstract

A method of lossless data compression is provided which uses a grammar transform to sequentially construct a sequence of greedy context-dependent grammars from which an original data sequence can be recovered incrementally. The data sequence is encoded using any one of a sequential context-dependent method, an improved sequential context-dependent method, and a hierarchical context-dependent method.

## Claims

### Claim 1

A method of sequentially transforming an original data sequence comprising a plurality of symbols and associated with a known context model into an irreducible context-dependant grammar from which the original data can be fully recovered, wherein the irreducible context-dependent grammar is represented by a set of production rules which are formed using a set of pairs of variables and contexts representing non-overlapping repeated patterns and contexts in the data sequence, the method applicable to any countable context model and comprising the steps of:
(a) parsing a substring from the sequence, wherein the substring is the longest prefix of a string of previously unparsed symbols of the sequence that can be represented, under the context of the current time instant, by a variable within the set of variables of a previous irreducible context-dependent grammar other than the initial variable in the initial pair of the set of pairs of variables and contexts if such a prefix exists, and otherwise a first symbol of the string of the previously unparsed symbols in the sequence;
(b) generating an admissible context-dependent grammar based on the substring, the current context, and the previous irreducible context-dependent grammar;
(c) applying at least one set of reduction rules to the admissible context-dependent grammar to generate a new irreducible context-dependent grammar;
(d) repeating steps (a) through (c) until all of the symbols of the sequence are represented by the final irreducible context-dependent grammar.

### Claim 2 (depends on 1)

The method according to claim 1, wherein said applying step further comprises the step of implementing a reduction rule comprising the steps of:
(a) defining s as a variable of an admissible context-dependent grammar G that appears once under some context C in the range of G;
(b) defining a production rule s′|Ĉ→αsβ in which s appears under the context C on the right of a group of symbols;
(c) defining a production rule s|C→γ which corresponds to the pair (C,s); and
(d) reducing G to an admissible context-dependent grammar G′ by removing said production rule s|C→γ from G and replacing said production rule s′|Ĉ→αsβ with the production rule s′|Ĉ→αγβ, the resulting admissible context-dependent grammar G′ and G representing an equivalent data sequence.

### Claim 3 (depends on 1)

The method according to claim 1, wherein said applying step further comprises the step of implementing a reduction rule comprising the steps of:
(a) defining G as an admissible context-dependent grammar possessing a production rule of form s|C→α1βα2βα3, where the length of β is at least 2, and the underlying contexts of β at these two locations are equal to the same context C′;
(b) defining a new production rule s′|C′→β, where (C′,s′) is a new pair of context and variable which is not in the domain of G; and
(c) reducing G to a new context-dependent grammar G′ by replacing the production rule s|C→α1βα2βα3 of G with s|C→α1s′α2s′α3, and appending the production rule s′|C′→β, the resulting grammar G′ having a new pair of context and variable (C′,s′) and representing an equivalent data sequence x as does G.

### Claim 4 (depends on 3)

The method according to claim 3, wherein said reducing step is performed in lieu of other ones of said set of production rules when G′ has a non-overlapping repeated pattern of said symbols and contexts in the range of G′.

### Claim 5 (depends on 1)

The method according to claim 1, wherein said applying step further comprises the step of implementing a reduction rule comprising the steps of:
(a) defining G as an admissible context-dependent grammar possessing two production rules of form s|C→α1βα2 and s′|C′→α3βα4, where the length of β is at least 2, the underlying contexts of β at these two locations are equal to the same context C″, either of α1 and α2 is not empty, and either α3 and α4 is not empty;
(b) defining a new production rule s″|C″→β, where (C″,s″) is a new pair of context and variable which is not in the domain of G; and
(c) reducing G to a new context-dependent grammar G′ by replacing the production rule s|C→α1βα2 by s|C→α1s″α2, and by replacing the production rule s′|C′→α3βα4 by s′|C′→α3s″α4, and by appending the new rule s″|C″→β.

### Claim 6 (depends on 1)

The method according to claim 1, wherein said applying step further comprises the step of implementing a reduction rule comprising the steps of:
(a) defining G as an admissible context-dependent grammar possessing two production rules of the form s|C→α1βα2 and s′|C′→β, where the length of β is at least 2, the underlying context of β in s|C→α1βα2 is also equal to C′, and either of α1 and α2 is not empty;
(b) reducing G to the context-dependent grammar G′ obtained by replacing said production rule s|C→α1βα2 with a new production rule s|C→α1s′α2.

### Claim 7 (depends on 1)

The method according to claim 1, wherein said applying step further comprises the step of implementing a reduction rule comprising the steps of:
(a) defining G as an admissible context-dependent grammar in which two variables s and s′ under a given context C represent the same substring of an A-sequence represented by G; and
(b) reducing G to a new context-dependent grammar G′ by replacing each appearance of s′ whenever the underlying context of s′ is equal to C in the range of G by s and deleting the production rule corresponding to (C,s′).

### Claim 8 (depends on 7)

The method according to claim 7, wherein said reducing step further comprises the step of further reducing G′ to the admissible context-dependent grammar G″ obtained by deleting each said production rules corresponding to pairs of context and variable of G′ that are not involved in the serial replacement process of G′ if said grammar G′ is not admissible.

### Claim 9

A method of sequentially transforming an original data sequence x=x1x2 . . . xn comprising a plurality of symbols and associated with a known context model given by a countable context set C and a next context function ƒ into a sequence of irreducible context-dependant grammars {Gi}′i=1 from which the original data sequence x can be fully recovered incrementally, wherein each context-dependent grammar Gi is represented by a set of production rules si|C1→Gt(si|C1) formed from a variable set S(ji)={s0,s1, . . . sji−1} and a set ΩG(Ki,ji) of pairs of contexts and variables with j1=1, K1=1, and ΩG(K1,j1)={(C1,s0)}, the method comprising the steps of:
(a) parsing the sequence x=x1x2 . . . xn into t non-overlapping substrings {x1,x2 . . . xn2, . . . , xni−1+1 . . . xni}, wherein n1=1, nt=n, and for each 1<i≦t, the substring xni−1+1 . . . xnt (denoted by βi) is the longest prefix of the remaining sequence of previously unparsed symbols xni−1+1 . . . xn that can be represented under the context Cni−1+1 by a variable si within a variable subset given by {s:s≠s0&(Cni−1+1,s)∈ΩG(Ki−1,ji−1)} if such a prefix exists, and otherwise the first symbol xni−1+1 of the remaining sequence of previously unparsed symbols, wherein ΩG(Ki−1,ji−1) is the set of pairs of contexts and variables of the previous irreducible context-dependent grammar Gi−1, and (b) generating an irreducible context-dependent grammar Gi for each xi . . . xni based on the current parsed substring βi=xni−1+1 . . . xni, the current context Cni−1+1 determined from the context model, and the previous irreducible context-dependent grammar Gi−1, where G1 consists of only one production rule {s0|C1→x1} and (C1,s0) is the initial context and variable pair.

### Claim 10 (depends on 9)

The method according to claim 9, wherein the step of parsing the sequence x=x1x2 . . . xn into a plurality of non-overlapping substrings {x1,x2 . . . xn2, . . . , xni−1+1 . . . xni} further comprises the steps of:
(a) determining, for each 1<i≦t, the context Cni−1+1 at the time instant ni−1+1;
(b) determining if a prefix of the remaining unparsed sequence xni−1+1 . . . xn can be represented under the current context Cni−1+1 by a variable sj within a variable subset given by {s:s≠s0&(Cni−1+1,s)∈ΩG(Ki−1,ji−1)}, where ΩG(Ki−1,ji−1) is the set of pairs of contexts and variables of the previous irreducible context-dependent grammar Gi−1;
(c) setting the current parsed substring βi to be equal to the longest prefix xni−1+1 . . . xni if xni−1+1 . . . xni is represented by the variable sj under the context Cni−1+1; and
(d) settteing the current parsed substring βi to be equal to xni−1+1 with nt=ni−1+1 if no prefix of xni−1+1 . . . xn can be represented under the current context Cni−1+1 by a variable sj within a variable subset given by {s:s≠s0&(Cni−1+1,s)∈ΩG(Ki−1,ji−1)}.

### Claim 11 (depends on 9)

The method according to claim 9, wherein the step of generating an irreducible context-dependent grammar Gi for each x1 . . . xni based on the current parsed substring βi=xni−1+1 . . . xni, the current context Cni−1+1, and the previous irreducible context-dependent grammar Gi−1 further comprises the steps of:
(a) appending the variable sj to the right end of Gi−1(s0|C1) to generate an admissible context-dependent grammar G′i−1 if ni−ni−1>1 and βi=xni−1+1 . . . xni is represented by sj under the context Cni−1+1;
(b) appending the symbol xni−1+1 to the right end of Gi−1(s0|C1) to generate an admissible context-dependent grammar G′i−1 if ni−ni−1=1; and
(c) applying a set of reduction rules to G′i−1 to generate the irreducible context-dependent grammar Gi for each x1 . . . xni.

### Claim 12 (depends on 11)

The method according to claim 11, wherein said applying a set of reduction rules to G′i−1 farther comprises the steps of:
(a) setting a grammar reduction bit I(i−1) associated with the (i−1)th parsed substring to be equal to 1 if the admissible context-dependent grammar G′i−2 is reducible, and 0 if G′i−2 is irreducible;
(b) defining α to be the last symbol of Gi−1(s0|C1);
(c) defining C to be the context of α in Gi−1(s0|C1);
(d) defining β to be the last symbol of G′i−1(s0|C1);
(e) determining if αβ appears under the context C in two non-overlapping positions in the range of G′i−1;
(f) setting Gi to be equal to G′i−1 if αβ does not appears under the context C in two non-overlapping positions in the range of G′i−1;
(g) applying a first reduction rule to G′i−1 to generate Gi if I(i−1)=0 and αβ repeats itself under the same context C in two non-overlapping positions in G′i−1(s0|C1), wherein said first reduction rule comprises the steps of:
(1) defining G as an admissible context-dependent grammar possessing a production rule of form s|Ĉ→α1γα2γα3, where the length of γ is at least 2, and the underlying contexts of γ at these two locations are equal to the same context C′;
(2) defining a new production rule s′|C′→γ, where (C′,s′) is a new pair of context and variable which is not in the domain of G; and
(3) reducing G to a new context-dependent grammar Ĝ by replacing the production rule s|Ĉ→α1γα2γα3 of G with s|Ĉ→α1s′α2s′α3, and appending the production rule s′|C′→γ, the resulting grammar Ĝ having a new pair of context and variable (C′,s′) and representing an equivalent data sequence x as does G;
(h) applying a second reduction rule to G′i−1 to generate Gi if I(i−1)=0 and αβ repeats itself under the same context C in two non-overlapping positions in the range of G′i−1 but not in G′i−1(s0|C1), wherein said second reduction rule comprises the steps of:
(1) defining G as an admissible context-dependent grammar possessing two production rules of form s|Ĉ→α1γα2 and s′|C′→α3γα4, where the length of γ is at least 2, the underlying contexts of γ at these two locations are equal to the same context C″, either of α1 and α2 is not empty, and either α3 and α4 is not empty;
(2) defining a new production rule s″|C″→γ, where (C″,s″) is a new pair of context and variable which is not in the domain of G; and
(3) reducing G to a new context-dependent grammar Ĝ by replacing the production rule s|Ĉ→α1γα2 by s|Ĉ→α1s″α2, and by replacing the production rule s′|C′→α3γα4 by s′|C′→α3s″α4, and by appending the new rule s″|C″→γ;
(i) applying said one of a first reduction rule and a second reduction rule followed by a third reduction rule if I(i−1)=1 and αβ repeats itself under the same context C in two non-overlapping positions in the range of G′i−1, wherein said third reduction rule comprises the steps of:
(1) defining s as a variable of an admissible context-dependent grammar G that appears once under some context Ĉ in the range of G;
(2) defining a production rule s′|C′→α1sβ1 in which s appears under the context Ĉ on the right of a group of symbols;
(3) defining a production rule s|Ĉ→γ which corresponds to the pair (Ĉ,s); and reducing G to an admissible context-dependent grammar Ĝ by removing said production rule s|Ĉ→γ from G and replacing said production rule s′|C′→α1sβ1 with the production rule s′|C′→α1γβ1, the resulting admissible context-dependent grammar Ĝ and G representing an equivalent data sequence.

### Claim 13 (depends on 12)

The method according to claim 12, wherein said determining step (e) further comprises the steps of:
(a) defining, for each pair (Ĉ,γ)∈ΩG(Ki−1,ji−1) other than the initial pair (C1,s0), two lists L1(γ|Ĉ) and L2(γ|Ĉ), where said list L1(γ|Ĉ) comprises all symbols η∈AS(ji−1) having the following properties:
(1) the pattern γη appears under the context Ĉ in the range of Gi−1;
(2) the pattern γη is not the last two symbols of Gi−1(s0|C1); and
(3) there is no variable si of Gi−1 such that Gi−1(si|Ĉ) is equal to γη; and where said list L2(γ|Ĉ) comprises all symbols η∈AS(ji−1) having properties (1) and (2);
(b) declaring that αβ appears under the context C in two non-overlapping positions in the range of G′i−1 if β appears in the list L1(α|C).

### Claim 14

A method of encoding an original data sequence comprising a plurality of symbols and associated with a known context model given by a countable context set C and a next context function ƒ by using an adaptive context-dependent arithmetic code to encode an irreducible context-dependent grammar from which the original data sequence can be fully recovered, wherein the irreducible context-dependent grammar is represented by a set of production rules which are formed using a set of pairs of variables and contexts representing non-overlapping repeated patterns and contexts in the data sequence, the method comprising the steps of:
(a) transforming the data sequence into the irreducible context-dependent grammar from which the original data sequence can be fully recovered;
(b) converting the irreducible context-dependent grammar into its sorted form, yielding a sorted irreducible context-dependent grammar;
(c) constructing a generated sequence from the sorted irreducible context-dependent grammar; and
(d) encoding the generated sequence using an adaptive context-dependent arithmetic code with dynamic alphabets.

### Claim 15 (depends on 14)

The method according to claim 14, wherein said transforming step (a) further comprises the steps of:
(1) parsing a substring from the sequence, wherein the substring is the longest prefix of a string of previously unparsed symbols of the sequence that can be represented, under the context of the current time instant, by a variable within the set of variables of a previous irreducible context-dependent grammar other than the initial variable in the initial pair of the set of pairs of variables and contexts if such a prefix exists, and otherwise a first symbol of the string of the previously unparsed symbols in the sequence;
(2) generating an admissible context-dependent grammar based on the substring, the current context, and the previous irreducible context-dependent grammar;
(3) applying at least one set of reduction rules to the admissible context-dependent grammar to generate a new irreducible context-dependent grammar; and
(4) repeating steps (1) through (3) until all of the symbols of the sequence are processed and the desired final irreducible context-dependent grammar is obtained.

### Claim 16 (depends on 14)

The method according to claim 14, wherein an irreducible context-dependent grammar G with a variable set S(j)={s0,s1, . . . sj−1} and a set ΩG(K,j) of pairs of contexts and variables is said to be of sorted form if for each legitimate context C, the replacement of (C,si) always takes place before that of (C,si+1) for any meaningful i>0 in the following recursive replacement procedure:
(1) Let ΩG denote a dynamically changing subset of ΩG(K,j); initially, ΩG is empty;
(2) Set u(0)=G(s0|C1) and i=0;
(3) For i≧0, read u(i) from left to right; replace the first pair (C,s) which is not in ΩG by G(s|C), where C is the context for s determined by the context model;
(4) Update ΩG by inserting the pair (C,s) into ΩG;
(5) Repeat steps (3) and (4) for i=0,1, . . . |ΩG(K,j)|−1 so that each pair (C,s)∈ΩG(K,j) other than (C1,s0) is replaced by G(s|C) exactly once; and
Said converting step (b) further comprises the step of renaming, under each legitimate context C, variables si so that for renamed variables, the replacement of (C,si) always takes place before that of (C, si+1) for any meaningful i>0 in said recursive replacement procedure.

### Claim 17 (depends on 14)

The method according to claim 14, wherein said constructing step (c) further comprises the steps of:
(1) defining a sorted irreducible context-dependent grammar G with a variable set S(j)={s0,s1, . . . sj−1} and a set ΩG(K,j) of pairs of contexts and variables;
(2) initializing ΩG to be an empty set;
(3) setting u(0)=G(s0|C1) and i=0;
(4) reading u(i), for i≧0, from left to right, and replacing the first pair (C,s) which is not in ΩG by [G(s|C)], where C is the context for s determined by the context model;
(5) updating ΩG by inserting the pair (C,s) into ΩG;
(6) repeating steps (4) and (5) for i=0,1, . . . |ΩG(K,j)|−1 so that each pair (C,s)∈ΩG(K,j) other than (C1,s0) is replaced by [G(s|C)] exactly once, the final sequence u(|ΩG(K,j)|−1) being the generated sequence from G.

### Claim 18 (depends on 14)

The method according to claim 14, wherein said encoding step (d) further comprises the steps of:
(1) extending the next context function ƒ to include C=ƒ(C,[) and C=ƒ(C,]) for any context C;
(2) associating each pair (C,α) with a counter c(C,α), where C is a context and α is a symbol, variable, or bracket ([ or ]);
(3) initializing c(C,α) to be 1 if α is a symbol in the original data sequence or bracket ([ or]), and 0 otherwise;
(4) encoding each symbol β of the generated sequence conditioned on its context C and based on the counter c(C,β) divided by the sum of all counters c(C,α) over all α satisfying c(C,α)≠0;
(5) increasing c(C,β) by 1;
(6) increasing c(C′,s1) from 0 to 1 whenever β is equal to the bracket ] and the legitimate bracket pair corresponding to β is the ith bracket pair under the context C′ counted from the left of the generated sequence, where C′ is the context for the left bracket [ of this bracket pair;
(7) determining the context for the next symbol in the generated sequence; and
(8) repeating steps (4) through (7) until all symbols in the generated sequence are encoded.

### Claim 19

A method of sequentially transforming an original data sequence x=x1x2 . . . xn into a sequence of irreducible context-dependant grammars {Gi}′i=1 and encoding the data sequence by using an adaptive context-dependent arithmetic code to encode the final irreducible context-dependent grammar Gi, wherein the data sequence x=x1x2 . . . xn comprises a plurality of symbols and is associated with a known context model given by a countable context set C and a next context function ƒ, and each context-dependent grammar Gi is represented by a set of production rules si|C1→Gi(si|C1) formed from a variable set S(ji)={s0,s1, . . . sji−1} and a set ΩG(Ki,ji) of pairs of contexts and variables with j1=1, K1=1, and ΩG(K1,j1)={(C1,s0)}, the method comprising the steps of:
(a) parsing the sequence x=x1x2 . . . xn into t non-overlapping substrings {x1,x2 . . . xn1, . . . , xni−1+1 . . . xnt}, wherein n1=1, nt=n, and for each 1<i≦t, the substring xni−1+1 . . . xni (denoted by βi) is the longest prefix of the remaining sequence of previously unparsed symbols xni−1+1 . . . xn that can be represented under the context Cni−1+1 by a variable sj within a variable subset given by {s:s≠s0&(Cni−1+1,s)∈ΩG(Ki−1,ji−1)} if such a prefix exists, and otherwise the first symbol xni−1+1 of the remaining sequence of previously unparsed symbols, wherein ΩG(Ki−1,ji−1) is the set of pairs of contexts and variables of the previous irreducible context-dependent grammar Gi−1, and
(b) generating an irreducible context-dependent grammar Gi for each x1 . . . xni based on the current parsed substring βi=xni−1+1 . . . xni, the current context Cni−1+1 determined from the context model, and the previous irreducible context-dependent grammar Gi−1, where G1 consists of only one production rule {s0|C1→x1} and (C1,s0) is the initial context and variable pair;
(c) converting the final irreducible context-dependent grammar Gi into its sorted form Gts;
(d) constructing a generated sequence from the sorted irreducible context-dependent grammar Gts; and
(e) encoding the generated sequence using an adaptive context-dependent arithmetic code with dynamic alphabets.

### Claim 20

A method of sequentially transforming a data sequence into a sequence of irreducible context-dependent grammars and encoding the data sequence based on each of the irreducible context-dependent grammars by using adaptive context-dependent arithmetic coding, wherein the data sequence comprises a plurality of symbols and is associated with a known context model given by a countable context set C and a next context function ƒ, and each irreducible context-dependent grammar is represented by a set of production rules which are formed using a set of pairs of variables and contexts representing non-overlapping repeated patterns and contexts in the data sequence, the method comprising the steps of:
(a) parsing a substring from the sequence, wherein the substring is the longest prefix of a string of previously unparsed symbols of the sequence that can be represented, under the context of the current time instant, by a variable within the set of variables of a previous irreducible context-dependent grammar other than the initial variable in the initial pair of the set of pairs of variables and contexts if such a prefix exists, and otherwise a first symbol of the string of the previously unparsed symbols in the sequence;
(b) encoding the substring by utilizing the structure of the previous irreducible context-dependent grammar and by using adaptive context-dependent arithmetic coding;
(c) generating an admissible context-dependent grammar based on the substring, the current context, and the previous irreducible context-dependent grammar;
(d) applying at least one set of reduction rules to the admissible context-dependent grammar to generate a new irreducible context-dependent grammar; and
(e) repeating steps (a) through (d) until all of the symbols of the sequence are parsed and encoded.

### Claim 21

A method of sequentially transforming an original data sequence x=x1x2 . . . xn into a sequence of irreducible context-dependant grammars {Gi}′i=1 and encoding the data sequence based on each of the irreducible context-dependent grammars {Gi}′i=1 by using adaptive context-dependent arithmetic coding, wherein the data sequence x=x1x2 . . . xn comprises a plurality of symbols and is associated with a known context model given by a countable context set C and a next context function ƒ, and each context-dependent grammar G1 is represented by a set of production rules si|C1→Gi(si|C1) formed from a variable set S(ji)={s0,s1, . . . sji−1} and a set ΩG(Ki,ji) of pairs of contexts and variables with j1=1, K1=1, and ΩG(K1,j1)={(C1,s0)}, the method comprising the steps of:
(a) associating each pair (C,α) with two counters c(C,α) and ĉ(C,α), where C is a context and α is a symbol or variable;
(b) initializing c(C,α) and ĉ(C,α) to be 1 if α is a symbol in the original data sequence, and 0 otherwise;
(c) parsing, for each 1<i≦t, a substring xni−1+1 . . . xnt from the sequence, wherein n1=1, nt=n, and for each 1<i≦t, the substring xni−1+1 . . . xnt (denoted by βi) is the longest prefix of the remaining sequence of previously unparsed symbols xni−1+1 . . . xn that can be represented under the context Cni−1+1 by a variable sj within a variable subset given by {s:s≠s0&(Cni−1+1,s)∈ΩG(Ki−1,ji−1)} if such a prefix exists, and otherwise the first symbol xni−1+1 of the remaining sequence of previously unparsed symbols, wherein ΩG(Ki−1,ji−1) is the set of pairs of contexts and variables of the previous irreducible context-dependent grammar Gi−1, and wherein G1 consists of only one production rule {s0|C1→x1} with (C1,s0) being the initial context and variable pair;
(d) generating an admissible context-dependent grammar G′i−1 based on the previous irreducible context-dependent grammar Gi−1, the current substring βi, and the current context Cni−1+1;
(e) setting the current grammar reduction bit I(i) to be 1 if the admissible context-dependent grammar G′i−1 is reducible, and 0 if G′i−1 is irreducible;
(f) encoding the current grammar reduction bit I(i) using an adaptive order one or higher order arithmetic code;
(g) encoding the current substring βi based on the previous irreducible context-dependent grammar Gi−1, grammar reduction bits I(i) and I(i−1), and the current context Cni−1+1 using adaptive context-dependent arithmetic coding;
(h) applying at least one set of reduction rules to the admissible context-dependent grammar G′i−1 to generate a new irreducible context-dependent grammar Gi; and
(i) repeating steps (c) through (h) until all of the symbols of the sequence x are parsed and encoded.

### Claim 22 (depends on 21)

The method according to claim 21, wherein said encoding step (g) further comprises the steps of:
(1) defining α to be the last symbol of Gi−1(s0|C1);
(2) defining Ĉ to be the context of α in Gi−1(s0|C1);
(3) defining β to be the variable sj if ni−ni−1>1 and βi=xni−1+1 . . . xni is represented by sj under the context Cni−1+1, or simply the symbol xni−1+1 if ni−ni−1=1;
(4) defining {tilde over (C)} as the context Cni−1+1;
(5) defining, for each pair (C,γ)∈ΩG(Ki−1,ji−1) other than the initial pair (C1,s0), two lists L1(γ|C) and L2(γ|C), where said list L1(γ|C) comprises all symbols η∈AS(ji−1) having the following properties:
a) the pattern γη appears under the context C in the range of Gi−1;
b) the pattern γη under the context C is not the last two symbols of Gi−1(s0|C1); and
c) there is no variable sj of Gi−1 such that Gi−1(si|C) is equal to γη; and
where said list L2(γ|C) comprises all symbols η∈AS(ji−1) having properties a) and b);
(6) encoding β conditioned on its context {tilde over (C)} and based on the count c({tilde over (C)},β) divided by the sum of all counters c({tilde over (C)},γ) over all γ∈AS(ji−1)\L2(α|Ĉ) satisfying c({tilde over (C)},γ)≠0 and then increasing c({tilde over (C)},β) by one if I(i)=0;
(7) encoding β conditioned on its context {tilde over (C)} and based on the count ĉ({tilde over (C)},β) divided by the sum of all counters ĉ({tilde over (C)},γ) over all γ∈L1(α|Ĉ) and then increasing ĉ({tilde over (C)},β) by one if I(i−1)=0 and I(i)=1.

### Claim 23 (depends on 21)

The method according to claim 21, wherein said step (h) further includes the step of updating lists L1(γ|C) and L2(γ|C) accordingly.
