Documentation

CslibFrontier.Algorithms.Lean.BurrowsWheeler.Decode

Table-driven inversion of the Burrows–Wheeler transform #

[BW94], Section 4.2, inverts the transform with two tables computed from the last column L: C[c], the number of symbols of L smaller than c, and the rank array P, where P[i] counts the occurrences of L[i] in L[0..i-1]. The LF-mapping is then the lookup T i = P[i] + C[L[i]], and the word is decoded by |L| such lookups.

For bounded integer alphabets < σ, CslibFrontier.Algorithms.WordRAM.BurrowsWheeler builds C and P in O(|L| + σ) Word-RAM instructions and runs the |L| LF-step lookups in O(|L|) instructions.

Main definitions #

Main results #

References #

The rank table #

rankTableFrom cnt L lists, for each position i, cnt L[i] plus the number of earlier occurrences of L[i]. It is one left-to-right pass with a running count per symbol.

The rank array P of [BW94], Section 4.2: P[i] is the number of occurrences of L[i] before position i (Batteries' L.countBefore L[i] i).

@[simp]
theorem Cslib.Algorithms.Lean.BurrowsWheeler.getElem?_rankTableFrom {α : Type u_1} [DecidableEq α] (cnt : α → ℕ) (L : List α) (i : ℕ) :
(rankTableFrom cnt L)[i]? = Option.map (fun (a : α) => cnt a + List.count a (List.take i L)) L[i]?

Table-driven LF decoding #

def Cslib.Algorithms.Lean.BurrowsWheeler.lfDecodeTable {α : Type u_1} (L : List α) (C : α → ℕ) (P : List ℕ) :
ℕ → ℕ → List α → List α

k LF steps from row r with the tables C and P, prepending the symbols read to acc. Each step reads L[r] and P[r] and moves to P[r] + C[L[r]] ([BW94], Section 4.2). It stops early out of range.

def Cslib.Algorithms.Lean.BurrowsWheeler.inverseBwtTable {α : Type u_1} (L : List α) (I : ℕ) (C : α → ℕ) (P : List ℕ) :
List α

Table-driven inverse Burrows–Wheeler transform: |L| LF steps from row I using C and P.

theorem Cslib.Algorithms.Lean.BurrowsWheeler.lfDecodeTable_eq_lfDecode {α : Type u_1} [LinearOrder α] (L : List α) {C : α → ℕ} (hC : ∀ c ∈ L, C c = List.countP (fun (x : α) => decide (x < c)) L) (k r : ℕ) (acc : List α) :
lfDecodeTable L C (rankTable L) k r acc = lfDecode L k r acc

With P = rankTable L and C matching L.countP (· < c) on every symbol in L, lfDecodeTable computes lfDecode.

theorem Cslib.Algorithms.Lean.BurrowsWheeler.inverseBwtTable_eq_inverseBwt {α : Type u_1} [LinearOrder α] (L : List α) (I : ℕ) {C : α → ℕ} (hC : ∀ c ∈ L, C c = List.countP (fun (x : α) => decide (x < c)) L) :
theorem Cslib.Algorithms.Lean.BurrowsWheeler.inverseBwtTable_bwt {α : Type u_1} [LinearOrder α] (w : List α) {C : α → ℕ} (hC : ∀ c ∈ bwtLast w, C c = List.countP (fun (x : α) => decide (x < c)) (bwtLast w)) :

Table-driven decoding of bwt w recovers w.