@@ -194,19 +194,34 @@ \subsection{Arrays}
194
194
decoded list $ l$ (from the remainder $ s^{(k)}$ ) forms the final result.
195
195
196
196
\subsection {Natural numbers }
197
- We encode natural numbers by splitting their binary representations into
198
- sequences of 7-bit blocks, then emitting these as a list with the \textbf {least
199
- significant block first }:
197
+ Every natural number $ n$ of arbirary size can be uniquely written in the following form:
200
198
201
199
$$
202
- \E _{ \N } (s, \sum _{i=0}^{n-1 }k_i2 ^{7i}) = \Elist _ 7 (s, [k_ 0 , \ldots , k_{n-1}])
200
+ n = \sum _{i=0}^{n}k_i2 ^{7i} \text { where for any $ i $ with } 0 \leq i \leq n \text {, } 0 \leq k_i \leq 127 \text { and } k_n \ne 0
203
201
$$
204
- \noindent (where $ k_i \in \Z $ and $ 0 \leq k_i \leq 127 $ ).
202
+
203
+ \noindent Here, each $ k_i$ is 7 bit binary block; $ k_0 $ being the least significant block.
204
+
205
+ $$
206
+ \E _{\N } (s, \sum _{i=0}^{n}k_i2 ^{7i}) =
207
+ \begin {cases}
208
+ \E _7 (\Elist _7 (s, []), k_{0}) & \text {if } n = 0 \\
209
+ \E _7 (\Elist _7 (s, [k_0 , \ldots , k_{n-1}]), k_{n}) & \text {if } n \ne 0
210
+ \end {cases}
211
+ $$
212
+
205
213
\noindent The decoder is
206
214
$$
207
- \D _{\N }(s) = (s', \sum _{i=0}^{n-1}k_i2 ^{7i}) \quad \text {if $ \Dlist _7 (s) = (s', [k_0 , \ldots , k_{n-1}])$ }.
215
+ \D _{\N }(s) =
216
+ \begin {cases}
217
+ \text {let } \Dlist _7 (s) = (s', ks) \\
218
+ D_7 (s') & \text {if } ks = [] \\
219
+ (s'', \sum _{i=0}^{n}k_i2 ^{7i}) & \text {if } ks = [k_0 , \ldots , k_{n-1}] \text { and } \D _7 (s') = (s'', k_{n})
220
+ \end {cases}
208
221
$$
209
222
223
+ \noindent Intuitively, every 7 bit blocks except the last block are prefixed by 1 and the last block is prefixed by 0.
224
+
210
225
\subsection {Integers }
211
226
Signed integers are encoded by converting them to natural numbers using the
212
227
zigzag encoding ($ 0 \mapsto 0 , -1 \mapsto 1 , 1 \mapsto 2 , -2 \mapsto 3 , 2
0 commit comments