Prefix-Free Encoding

Pyro·2021년 10월 2일

계산이론

목록 보기
3/5

출처

숫자가 아닌 임의의 객체를 인코딩하려면 2가지 조건이 필요하다.
하나는 인코딩 함수가 one-to-one 이어야 한다는 것과,
두번째는 Prefix-Free 이어야 한다는 것이다.

One-To-One 이 필요한 이유는 매우 직관적이다.
One-To-One 이 아니라면 Decoding 이 불가능하기 때문이다.

Prefix-Free 가 필요한 이유는 여러개의 객체를 tuple 로 묶어서 인코딩을 하기 위해서이다.
만약 Prefix-Free 하지 않는다면, 여러개의 객체를 하나의 bit string 으로 표현하는 인코딩 함수가
one-to-one 이 아니게 되어서, Decoding 이 불가능할수도 있다.

Definition 2.17 (Prefix free encoding)

y,y′y,y': string
yy is a prefix of y′y' if
∣y∣≤∣y′∣|y| \leq |y'| and ∀i<∣y∣\forall i<|y|, yi′=yiy'_i = y_i

O\mathcal{O} : non-empty set
E:O→{0,1}∗E:\mathcal{O} \rightarrow \{0,1\}^* : function
E is prefix free if
E(o)≠∅,∀o∈OE(o) \neq \emptyset, \forall o \in \mathcal{O} and
∄\nexists distinct objects o,o′∈Oo,o' \in \mathcal{O} s.t E(o)E(o) is a prefix of E(o′)E(o')

Theorem 2.18 (Prefix-free implies tuple encoding)

E:O→{0,1}∗E:\mathcal{O} \rightarrow \{0,1\}^* is prefix-free
Define E‾:O∗→{0,1}∗\overline{E}:\mathcal{O}^* \rightarrow \{0,1\}^* as follows:
∀o0,…,ok−1∈O∗\forall o_0,\ldots,o_{k-1} \in \mathcal{O}^*

E‾(o0,…,ok−1)=E(o0)E(o1)⋯E(ok−1)  \overline{E}(o_0,\ldots,o_{k-1}) = E(o_0)E(o_1) \cdots E(o_{k-1}) \;

Then, E‾\overline{E} is one to one.

Proof

Suppose E‾\overline{E} is not one to one.
⇒∃\Rightarrow \exists distinct tuples (o0,…,ok−1)(o_0,\ldots,o_{k-1}), (o0′,…,ok′−1′)(o'_0,\ldots,o'_{k'-1}) s.t

E‾(o0,…,ok−1)=E‾(o0′,…,ok′−1′)=x‾∈{0,1}∗\overline{E}(o_0,\ldots,o_{k-1}) = \overline{E}(o'_0,\ldots,o'_{k'-1}) = \overline{x} \in \{0,1\}^*

Let ii be the first index s.t oi≠oi′o_i \neq o'_i
Then, xj=E(oj)=E(oj′)x_j = E(o_j) = E(o'_j) for ∀j∈{0,1,2,…i−1}\forall j \in \{0, 1, 2, \dots i-1\}.

x‾=E‾(o0,…,ok−1)=x0⋯xi−1E(oi)E(oi+1)⋯E(ok−1)\overline{x} = \overline{E}(o_0,\ldots,o_{k-1}) = x_0\cdots x_{i-1} E(o_i) E(o_{i+1}) \cdots E(o_{k-1})
=E‾(o0′,…,ok′−1′)=x0⋯xi−1E(oi′)E(oi+1′)⋯E(ok′−1′)= \overline{E}(o'_0,\ldots,o'_{k'-1}) = x_0\cdots x_{i-1} E(o'_i) E(o'_{i+1}) \cdots E(o'_{k'-1})

∴E(oi)⋯E(ok−1)=E(oi′)⋯E(ok′−1′)\therefore E(o_i) \cdots E(o_{k-1}) = E(o'_i) \cdots E(o'_{k'-1})
This means that one of E(oi)E(o_i) and E(oi′)E(o'_i) must be a prefix of the other.
This contradicts to "E is prefix-free".
Proved by contradiction.
QED

Lemma 2.20

E:O→{0,1}∗E:\mathcal{O} \rightarrow \{0,1\}^* is one-to-one. Then,
∃\exists one-to-one prefix-free encoding E‾\overline{E} s.t ∣E‾(o)∣≤2∣E(o)∣+2|\overline{E}(o)| \leq 2|E(o)|+2 for ∀o∈O\forall o\in \mathcal{O}.

Proof

Double every bit in the string xx (0↦000 \mapsto 00, 1↦111 \mapsto 11)
and mark the end of the string by concatenating to it the pair 0101.
Then, E(x)≠E(x′)E(x) \neq E(x') for ∀x≠x′\forall x \neq x'

Define a function PF:{0,1}∗→{0,1}∗PF:\{0,1\}^* \rightarrow \{0,1\}^* for x∈{0,1}∗x\in \{0,1\}^* as follows:

PF(x)=x0x0x1x1…xn−1xn−101PF(x)=x_0 x_0 x_1 x_1 \ldots x_{n-1}x_{n-1}01

We want to show E‾(o)=PF(E(o))\overline{E}(o)=PF(E(o)) is an prefix-free encoding.

(1) E‾\overline{E} is encoding

EE is one-to-one and PFPF is one-to-one.
Then, E‾=PF∘E\overline{E}=PF \circ E is also one-to-one
∴\therefore E‾\overline{E} is encoding.

(2) E‾\overline{E} is prefix-free

E‾\overline{E} is prefix-free
⇔\Leftrightarrow E‾(o)\overline{E}(o) is not a prefix of E‾(o′)\overline{E}(o') for
∀\forall distinct object o,o′∈Oo, o' \in \mathcal{O}

Suppose E‾(o)\overline{E}(o) is a prefix of E‾(o′)\overline{E}(o') for some distinct o,o′∈Oo, o' \in \mathcal{O}
E‾(o)=PF(E(o))\overline{E}(o)=PF(E(o))
E‾(o′)=PF(E(o′))\overline{E}(o')=PF(E(o'))
Let x=E(o)x = E(o), x′=E(o′)x'=E(o').
Since EE is one-to-one, x≠x′x \neq x'.

(i) ∣x∣<∣x′∣|x|<|x'|
the two bits in positions 2∣x∣2|x| in PF(x)PF(x) will be 0101
but two bits in positions 2∣x∣2|x| in PF(x′)PF(x') will be 0000 or 1111
⇒\Rightarrow PF(x)PF(x) and PF(x′)PF(x') differ in the coordinates 2∣x∣,2∣x∣+12|x|, 2|x|+1
∴PF(x)\therefore PF(x) cannot be a prefix of PF(x′)PF(x').

(ii) ∣x∣=∣x′∣|x|=|x'|
Since x≠x′x \neq x', ∃\exists coordinate ii in which they differ.
⇒\Rightarrow PF(x)PF(x) and PF(x′)PF(x') differ in the coordinates 2i,2i+12i,2i+1
∴\therefore PF(x)PF(x) cannot be a prefix of PF(x′)PF(x').

(iii) ∣x∣>∣x′∣|x|>|x'|
then ∣PF(x)∣=2∣x∣+2>∣PF(x′)∣=2∣x′∣+2|PF(x)|=2|x|+2>|PF(x')|=2|x'|+2.
⇒\Rightarrow PF(x)PF(x) is longer than PF(x′)PF(x').
∴PF(x)\therefore PF(x) cannot be a prefix of PF(x′)PF(x').

Therefore, PF(x)=E‾(o)PF(x)=\overline{E}(o) is not a prefix of PF(x′)=E‾(o′)PF(x')=\overline{E}(o') for ∀o,o′∈O\forall o, o' \in \mathcal{O}.
Hence, completing the proof.
QED

profile
dreams of chronic and sustained passion

0개의 댓글