Constructing Binary Huffman Tree

Summary Huffman coding is one of a most famous entropy encoding methods for lossless data compression [16]. JPEG and ZIP formats employ variants of Huffman encoding as lossless compression algorithms. Huffman coding is a bijective map from source letters into leaves of the Huffman tree constructed by the algorithm. In this article we formalize an algorithm constructing a binary code tree, Huffman tree.

Note that R N is non empty. Let D be a non empty set. The binary finite trees of D yielding a set of trees decorated with elements of D is defined by (Def. 2) Let us consider a tree T decorated with elements of D. Then dom T is finite and T is binary if and only if T ∈ it. The Boolean binary finite trees of D yielding a non empty subset of 2 the binary finite trees of D is defined by the term (Def. 3) {x, where x is an element of 2 α : x is finite and x = ∅}, where α is the binary finite trees of D. In this paper S denotes a non empty finite set, p denotes a probability on the trivial σ-field of S, T 1 denotes a finite sequence of elements of the Boolean binary finite trees of R N , and q denotes a finite sequence of elements of N.
Let us consider S and p. The functor InitTrees p yielding a non empty finite subset of the binary finite trees of R N is defined by the term (Def. 4) {T , where T is an element of FinTrees(R N ) : T is a finite binary tree decorated with elements of R N and there exists an element x of S such that T = the root tree of (CFS(S)) −1 (x), p({x}) }. Let p be a tree decorated with elements of R N . The value of root from right of p yielding a real number is defined by the term (Def. 5) p(∅) 2 .
The value of root from left of p yielding a natural number is defined by the term (Def. 6) p(∅) 1 .
Let T be a finite binary tree decorated with elements of R N and p be an element of dom T . The value of tree of p yielding a real number is defined by the term (Def. 7) T (p) 2 .
Let p, q be finite binary trees decorated with elements of R N and k be a natural number. The functor MakeTree(p, q, k) yielding a finite binary tree decorated with elements of R N is defined by the term (Def. 8) k, (the value of root from right of p) + (the value of root from right of q) -tree(p, q). Let X be a non empty finite subset of the binary finite trees of R N . The maximal value of X yielding a natural number is defined by (Def. 9) There exists a non empty finite subset L of N such that (1) Let us consider a non empty finite subset X of the binary finite trees of R N and a finite binary tree w decorated with elements of R N . Suppose X = {w}. Then the maximal value of X = the value of root from left of w. Proof: Consider L being a non empty finite subset of N such that L = {the value of root from left of p, where p is an element of the binary finite trees of R N : p ∈ X} and the maximal value of X = max L. For every element n such that n ∈ L holds n = the value of root from left of w. For every element n such that n = the value of root from left of w holds n ∈ L.
(2) Let us consider non empty finite subsets X, Y , Z of the binary finite trees of R N . Suppose Z = X ∪ Y . Then the maximal value of Z = max(the maximal value of X, the maximal value of Y ).
(3) Let us consider non empty finite subsets X, Z of the binary finite trees of R N and a set Y . Suppose Z = X \ Y . Then the maximal value of Z the maximal value of X. The theorem is a consequence of (2).
(4) Let us consider a non empty finite subset X of the binary finite trees of R N and an element p of the binary finite trees of R N . Suppose p ∈ X.
Then the value of root from left of p the maximal value of X.
Let X be a non empty finite subset of the binary finite trees of R N . A minimal value tree of X is a finite binary tree decorated with elements of R N and is defined by (Def. 10) (i) it ∈ X, and (ii) for every finite binary tree q decorated with elements of R N such that q ∈ X holds the value of root from right of it the value of root from right of q. Now we state the propositions: (5) InitTrees p = S. Proof: Reconsider f 1 = (CFS(S)) −1 as a function from S into Seg S. Define P[element, element] ≡ $ 2 = the root tree of f 1 ($ 1 ), p({$ 1 }) . For every element x such that x ∈ S there exists an element y such that y ∈ InitTrees p and P[x, y] by [12, (5)], [13, (87)], [7, (3)]. Consider f being a function from S into InitTrees p such that for every element x such that x ∈ S holds P[x, f (x)] from [12, Sch. 1].
(6) Let us consider a non empty finite subset X of the binary finite trees of R N and finite binary trees s, t decorated with elements of R N . Then MakeTree(t, s, ((the maximal value of X) + 1)) / ∈ X.
Let X be a set. The set of leaves of X yielding a subset of 2 R N is defined by the term (Def. 11) {Leaves(p), where p is an element of the binary finite trees of R N : p ∈ X}. Now we state the propositions: where p is an element of s : p ∈ Leaves(s)}. The theorem is a consequence of (9). Proof: [9, (6)].
Let us consider decorated trees s, t, an element x, and a finite sequence q of elements of N. Now we state the propositions: Now we state the propositions: (13) Let us consider decorated trees s, t and an element x.

Binary Huffman Tree
Let us consider S, p, T 1 , and q. We say that T 1 , q, and p are constructing T 1 ($ 1 ) = X and $ 2 = X and $ 2 = 0. For every natural number k such that k ∈ Seg S there exists an element x of N such that B[k, x] by [11, (3)]. Consider q being a finite sequence of elements of N such that dom q = Seg S and for every natural number k such that k ∈ Seg S holds B[k, q(k)] from [8,Sch. 5]. For every natural number k such that k ∈ Seg S holds q(k) = T 1 (k) and q(k) = 0. For every natural number k such that 1 k < S holds if 2 q(k), then q(k + 1) = q(k) − 1 by [8, (1)], [2, (11), (13)]. Define C[natural number] ≡ if $ 1 < S, then q($ 1 + 1) = q(1) − $ 1 . For every natural number n such that C[n] holds C[n + 1] by [2, (11)], [8, (1)], [2, (14), (13)]. For every natural number n, C[n] from [2, Sch. 2]. For every natural number n such that 1 n < S holds 2 q(n) by [2, (21), (13)]. For every natural number k such that 1 k < len T 1 there exist non empty finite subsets X, Y of the binary finite trees of R N and there exists a minimal value tree s of X and there exists a minimal value tree t of Y and there exists a finite binary tree w decorated with elements of R N such that T 1 (k) = X and Y = X \ {s} and w ∈ {MakeTree(t, s, ((the maximal value of X) + 1)), MakeTree(s, t, ((the maximal value of X) + 1))} and T 1 (k + 1) = (X \ {t, s}) ∪ {w} by [8, (1)]. Consider T 2 being a finite set such that T 1 (S) = T 2 and q(S) = T 2 and q(S) = 0. Consider u being an element such that T 2 = {u}.
Let us consider S and p. A binary Huffman tree of p is a finite binary tree decorated with elements of R N and is defined by (Def. 13) There exists a finite sequence T 1 of elements of the Boolean binary finite trees of R N and there exists a finite sequence q of elements of N such that T 1 , q, and p are constructing binary Huffman tree and {it} = T 1 (len T 1 ).
In this paper T denotes a binary Huffman tree of p. Now we state the propositions:     Let us consider an element p of dom w and an element r of N. Suppose r = w(p) 1 . Then r (the maximal value of X) + 1. The theorem is a consequence of (11) and (12). Proof: For every element a such that a ∈ dom d holds a = ∅ or there exists an element f of dom t such that a = 0 f or there exists an element f of dom s such that a = 1 f by [2, (23)].
(24) Suppose T 1 , q, and p are constructing binary Huffman tree. Let us consider a natural number i. Suppose 1 i < len T 1 . Let us consider non empty finite subsets X, Y of the binary finite trees of R N . Suppose Then the maximal value of Y = (the maximal value of X) + 1. Proof: Consider X, Y being non empty finite subsets of the binary finite trees of R N , s being a minimal value tree of X, t being a minimal value tree of Y , v being a finite binary tree decorated with elements of R N such that T 1 (i) = X and Y = X \ {s} and v ∈ {MakeTree(t, s, ((the maximal value of X) + 1)), MakeTree(s, t, ((the maximal value of X) + 1))} and Let us consider a finite binary tree z decorated with elements of R N . Suppose z ∈ X. Then (the maximal value of X) + 1, (the value of root from right of t) + (the value of root from right of s) / ∈ rng z. The theorem is a consequence of (26). Let x be an element. Note that the root tree of x is one-to-one. Now we state the propositions: (28) Let us consider a non empty finite subset X of the binary finite trees of R N and finite binary trees s, t, w decorated with elements of R N . Suppose (i) for every finite binary tree T decorated with elements of R N such that T ∈ X for every element p of dom T for every element r of N such that r = T (p) 1 holds r the maximal value of X, and (ii) for every finite binary trees p, q decorated with elements of R N such that p, q ∈ X and p = q holds rng p ∩ rng q = ∅, and (iii) s, t ∈ X, and (iv) s = t, and Then rng MakeTree(t, s, ((the maximal value of X) + 1)) ∩ rng w = ∅. The theorem is a consequence of (11) and (12). Proof: Set d = MakeTree(t, s, ((the maximal value of X) + 1)). For every element a such that a ∈ dom d holds a = ∅ or there exists an element f of dom t such that a = 0 f or there exists an element f of dom s such that a = 1 f by [2, (23)]. Consider n 2 being an element such that n 2 ∈ rng d ∩ rng w. Consider a 1 being an element such that a 1 ∈ dom d and n 2 = d(a 1 ). Consider b 1 being an element such that b 1 ∈ dom w and n 2 = w(b 1 ). w ∈ X and w = s and w = t. (29) Suppose T 1 , q, and p are constructing binary Huffman tree. Let us consider a natural number i and finite binary trees T , S decorated with elements of R N . Suppose Then rng T ∩ rng S = ∅. The theorem is a consequence of (26)  (v) for every finite binary tree z decorated with elements of R N such that z ∈ X holds (the maximal value of X) + 1, (the value of root from right of t) + (the value of root from right of s) / ∈ rng z.
Then MakeTree(t, s, ((the maximal value of X) + 1)) is one-to-one. The theorem is a consequence of (11) and (12). Proof: Set d = MakeTree(t, s, ((the maximal value of X) + 1)). For every element a such that a ∈ dom d holds a = ∅ or there exists an element f of dom t such that a = 0 f or there exists an element f of dom s such that a = 1 f by [2, (23)]. For every element x such that x ∈ dom d and x = ∅ holds d(x) = d(∅) by [11, (3)]. For every elements x 1 , x 2 such that x 1 , x 2 ∈ dom d and d(x 1 ) = d(x 2 ) holds it is not true that there exists an element f of dom s such that x 1 = 1 f and there exists an element f of dom t such that x 2 = 0 f by [11, (3)]. For every elements x 1 , x 2 such that x 1 , x 2 ∈ dom d and d(x 1 ) = d(x 2 ) holds x 1 = x 2 . (31) Suppose T 1 , q, and p are constructing binary Huffman tree. Let us consider a natural number i and a finite binary tree T decorated with elements of R N . If T ∈ T 1 (i), then T is one-to-one. The theorem is a consequence of (27), (29), and (30). Proof: Define P[natural number] ≡ if 1 $ 1 len T 1 , then for every finite binary tree T decorated with elements of R N such that T ∈ T 1 ($ 1 ) holds T is one-to-one. For every natural number i such that P[i] holds P[i + 1] by [2, (16), (14)]. For every natural number i, P[i] from [2, Sch. 2]. Let us consider p. Now we are at the position where we can present the Main Theorem of the paper: Every binary Huffman tree of p is one-to-one.