Last class

Representations cont.

Example 3: A way to represent rational numbers

$$ E:\mathbb{Q} \rightarrow \{0,1\}^* $$

Suggestion 1: $E(p,q) = \mathrm{unary}_0(p) \cdot \mathrm{unary}_1(q)$

Suggestion 2: Pad with zeros to make both num and dem same length; append

Suggestion 3: Use regular binary encoding, but duplicate each bit. Append with $01$ to denote end.

Define as $E_{\Z_p}$

$$ E(p,q) = E_{\Z_p}(p) \cdot E_{\Z_p}(q) $$

Prefix-Free Encodings

$E:\Theta \rightarrow \{0,1\}^*$ is a prefix-free encoding $\forall x\neq y \in \Theta \,\mathrm{s.t.}\, E(x)$ is not a prefix of $E(y)$.

Example: $E_\Z$ is not prefix-free: $E_\Z(4) = 10$ and $E_\Z(5) = 101$

Example 2: $E_\mathbb{Q}$ is prefix-free

Intuition: we add a unique suffix.

Why prefix-free?

Theorem: Suppose we have a prefix-free encoding $pE:\Theta \rightarrow \{0,1\}^*$.

Then, $\bar{pE} : \Theta^* \rightarrow \{0,1\}^*$

$$ \bar{pE} ([x_0,x_1,...,x_k])=pE(x_0)\cdot pE(x_1) \cdot ...\cdot pE(x_k) $$