1 Many approaches have been developed to solve the problem of building
2 a Gray code in a $\mathsf{N}$-cube~\cite{Robinson:1981:CS,DBLP:journals/combinatorics/BhatS96,ZanSup04,Bykov2016}, according to properties
3 the produced code has to verify.
4 For instance,~\cite{DBLP:journals/combinatorics/BhatS96,ZanSup04} focus on
5 balanced Gray codes. In the transition sequence of these codes,
6 the number of transitions of each element must differ
8 This uniformity is a global property on the cycle, \textit{i.e.}
9 a property that is established while traversing the whole cycle.
10 On the opposite side, when the objective is to follow a subpart
11 of the Gray code and to switch each element approximately the
13 local properties are wished.
14 For instance, the locally balanced property is studied in~\cite{Bykov2016}
15 and an algorithm that establishes locally balanced Gray codes is given.
17 The current context is to provide a function
18 $f:\Bool^{\mathsf{N}} \rightarrow \Bool^{\mathsf{N}}$ by removing a Hamiltonian
19 cycle in the $\mathsf{N}$-cube. Such a function is going to be iterated
20 $b$ times to produce a pseudo random number,
21 \textit{i.e.} a vertex in the
23 Obviously, the number of iterations $b$ has to be sufficiently large
24 to provide a uniform output distribution.
25 To reduce the number of iterations, the provided Gray code
26 should ideally possess both balanced and locally balanced properties.
27 However, none of the two algorithms is compatible with the second one:
28 balanced Gray codes that are generated by state of the art works~\cite{ZanSup04,DBLP:journals/combinatorics/BhatS96} are not locally balanced. Conversely,
29 locally balanced Gray codes yielded by Igor Bykov approach~\cite{Bykov2016}
30 are not globally balanced.
31 This section thus shows how the non deterministic approach
32 presented in~\cite{ZanSup04} has been automatized to provide balanced
33 Hamiltonian paths such that, for each subpart,
34 the number of switches of each element is as uniform as possible.
36 \subsection{Analysis of the Robinson-Cohn extension algorithm}
37 As far as we know three works,
38 namely~\cite{Robinson:1981:CS},~\cite{DBLP:journals/combinatorics/BhatS96},
39 and~\cite{ZanSup04} have addressed the problem of providing an approach
40 to produce balanced gray code.
41 The authors of~\cite{Robinson:1981:CS} introduced an inductive approach
42 aiming at producing balanced Gray codes, provided the user gives
43 a special subsequence of the transition sequence at each induction step.
44 This work have been strengthened in~\cite{DBLP:journals/combinatorics/BhatS96}
45 where the authors have explicitly shown how to construct such a subsequence.
46 Finally the authors of~\cite{ZanSup04} have presented
47 the \emph{Robinson-Cohn extension}
48 algorithm. There rigorous presentation of this one
49 have mainly allowed them to prove two properties.
50 The former states that if
51 $\mathsf{N}$ is a 2-power, a balanced Gray code is always totally balanced.
52 The latter states that for every $\mathsf{N}$ there
53 exists a Gray code such that all transition count numbers
54 are 2-powers whose exponents are either equal
55 or differ from each other by 1.
56 However, the authors do not prove that the approach allows to build
57 (totally balanced) Gray code.
58 What follows shows that this fact is established and first recalls the approach.
61 Let be given a $\mathsf{N}-2$-bit Gray code whose transition sequence is
62 $S_{\mathsf{N}-2}$. What follows is the
63 \emph{Robinson-Cohn extension} method~\cite{ZanSup04}
64 which produces a $n$-bits Gray code.
67 \item \label{item:nondet}Let $l$ be an even positive integer. Find
68 $u_1, u_2, \dots , u_{l-2}, v$ (maybe empty) subsequences of $S_{\mathsf{N}-2}$
69 such that $S_{\mathsf{N}-2}$ is the concatenation of
71 s_{i_1}, u_0, s_{i_2}, u_1, s_{i_3}, u_2, \dots , s_{i_l-1}, u_{l-2}, s_{i_l}, v
73 where $i_1 = 1$, $i_2 = 2$, and $u_0 = \emptyset$ (the empty sequence).
74 \item\label{item:u'}Replace in $S_{\mathsf{N}-2}$ the sequences $u_0, u_1, u_2, \ldots, u_{l-2}$
76 $\mathsf{N} - 1, u'(u_1,\mathsf{N} - 1, \mathsf{N}) , u'(u_2,\mathsf{N}, \mathsf{N} - 1), u'(u_3,\mathsf{N} - 1,\mathsf{N}), \dots, u'(u_{l-2},\mathsf{N}, \mathsf{N} - 1)$
77 respectively, where $u'(u,x,y)$ is the sequence $u,x,u^R,y,u$ such that
78 $u^R$ is $u$ in reversed order.
79 The obtained sequence is further denoted as $U$.
80 \item\label{item:VW} Construct the sequences $V=v^R,\mathsf{N},v$, $W=\mathsf{N}-1,S_{\mathsf{N}-2},\mathsf{N}$, and let $W'$ be $W$ where the first
81 two elements have been exchanged.
82 \item The transition sequence $S_{\mathsf{N}}$ is thus the concatenation $U^R, V, W'$.
85 It has been proven in~\cite{ZanSup04} that
86 $S_{\mathsf{N}}$ is the transition sequence of a cyclic $\mathsf{N}$-bits Gray code
87 if $S_{\mathsf{N}-2}$ is.
88 However, the step~(\ref{item:nondet}) is not a constructive
89 step that precises how to select the subsequences which ensures that
90 yielded Gray code is balanced.
91 Next section shows how to choose the sequence $l$ to have the balance property.
93 \subsection{Balanced Codes}
94 Let us first recall how to formalize the balance property of a Gray code.
95 Let $L = w_1, w_2, \dots, w_{2^\mathsf{N}}$ be the sequence
96 of a $\mathsf{N}$-bits cyclic Gray code.
97 The transition sequence
98 $S = s_1, s_2, \dots, s_{2^n}$, $s_i$, $1 \le i \le 2^\mathsf{N}$,
99 indicates which bit position changes between
100 codewords at index $i$ and $i+1$ modulo $2^\mathsf{N}$.
101 The \emph{transition count} function
102 $\textit{TC}_{\mathsf{N}} : \{1,\dots, \mathsf{N}\} \rightarrow \{0, \ldots, 2^{\mathsf{N}}\}$
103 gives the number of times $i$ occurs in $S$,
104 \textit{i.e.}, the number of times
105 the bit $i$ has been switched in $L$.
107 The Gray code is \emph{totally balanced} if $\textit{TC}_{\mathsf{N}}$
108 is constant (and equal to $\frac{2^{\mathsf{N}}}{\mathsf{N}}$).
109 It is \emph{balanced} if for any two bit indices $i$ and $j$,
110 $|\textit{TC}_{\mathsf{N}}(i) - \textit{TC}_{\mathsf{N}}(j)| \le 2$.
115 Let $L^*=000,100,101,001,011,111,110,010$ be the Gray code that corresponds to
116 the Hamiltonian cycle that has been removed in $f^*$.
117 Its transition sequence is $S=3,1,3,2,3,1,3,2$ and its transition count function is
118 $\textit{TC}_3(1)= \textit{TC}_3(2)=2$ and $\textit{TC}_3(3)=4$. Such a Gray code is balanced.
121 $L^4=0000, 0010, 0110, 1110, 1111, 0111, 0011, 0001, 0101,$
122 $0100, 1100, 1101, 1001, 1011, 1010, 1000$
123 be a cyclic Gray code. Since $S=2,3,4,1,4,3,2,3,1,4,1,3,2,1,2,4$, $\textit{TC}_4$ is equal to 4 everywhere, this code
124 is thus totally balanced.
126 On the contrary, for the standard $4$-bits Gray code
127 $L^{\textit{st}}=0000,0001,0011,0010,0110,0111,0101,0100,1100,$
128 $1101,1111,1110,1010,1011,1001,1000$,
129 we have $\textit{TC}_4(1)=8$ $\textit{TC}_4(2)=4$ $\textit{TC}_4(3)=\textit{TC}_4(4)=2$ and
130 the code is neither balanced nor totally balanced.
134 \begin{thrm}\label{prop:balanced}
135 Let $\mathsf{N}$ in $\Nats^*$, and $a_{\mathsf{N}}$ be defined by
136 $a_{\mathsf{N}}= 2 \left\lfloor \dfrac{2^{\mathsf{N}}}{2\mathsf{N}} \right\rfloor$.
137 There exists then a sequence $l$ in
138 step~(\ref{item:nondet}) of the \emph{Robinson-Cohn extension} algorithm
139 such that all the transition counts $\textit{TC}_{\mathsf{N}}(i)$
140 are $a_{\mathsf{N}}$ or $a_{\mathsf{N}}+2$
141 for any $i$, $1 \le i \le \mathsf{N}$.
148 The proof is done by induction on $\mathsf{N}$. Let us immediately verify
149 that it is established for both odd and even smallest values, \textit{i.e.}
151 For the initial case where $\mathsf{N}=3$, \textit{i.e.} $\mathsf{N-2}=1$ we successively have: $S_1=1,1$, $l=2$, $u_0 = \emptyset$, and $v=\emptyset$.
152 Thus again the algorithm successively produces
153 $U= 1,2,1$, $V = 3$, $W= 2, 1, 1,3$, and $W' = 1,2,1,3$.
154 Finally, $S_3$ is $1,2,1,3,1,2,1,3$ which obviously verifies the theorem.
155 For the initial case where $\mathsf{N}=4$, \textit{i.e.} $\mathsf{N-2}=2$
156 we successively have: $S_1=1,2,1,2$, $l=4$,
157 $u_0,u_1,u_2 = \emptyset,\emptyset,\emptyset$, and $v=\emptyset$.
158 Thus again the algorithm successively produces
159 $U= 1,3,2,3,4,1,4,3,2$, $V = 4$, $W= 3, 1, 2, 1,2, 4$, and $W' = 1, 3, 2, 1,2, 4 $.
162 2,3,4,1,4,3,2,3,1,4,1,3,2,1,2,4
164 such that $\textit{TC}_4(i) = 4$ and the theorem is established for
165 odd and even initial values.
168 For the inductive case, let us first define some variables.
169 Let $c_{\mathsf{N}}$ (resp. $d_{\mathsf{N}}$) be the number of elements
170 whose transition count is exactly $a_{\mathsf{N}}$ (resp $a_{\mathsf{N}} +2$).
171 These two variables are defined by the system
176 c_{\mathsf{N}} + d_{\mathsf{N}} & = & \mathsf{N} \\
177 c_{\mathsf{N}}a_{\mathsf{N}} + d_{\mathsf{N}}(a_{\mathsf{N}}+2) & = & 2^{\mathsf{N}}
185 d_{\mathsf{N}} & = & \dfrac{2^{\mathsf{N}} -\mathsf{N}.a_{\mathsf{N}}}{2} \\
186 c_{\mathsf{N}} &= &\mathsf{N} - d_{\mathsf{N}}
191 Since $a_{\mathsf{N}}$ is even, $d_{\mathsf{N}}$ is an integer.
192 Let us first proove that both $c_{\mathsf{N}}$ and $d_{\mathsf{N}}$ are positive
194 Let $q_{\mathsf{N}}$ and $r_{\mathsf{N}}$, respectively, be
195 the quotient and the remainder in the Euclidean disvision
196 of $2^{\mathsf{N}}$ by $2\mathsf{N}$, \textit{i.e.}
197 $2^{\mathsf{N}} = q_{\mathsf{N}}.2\mathsf{N} + r_{\mathsf{N}}$, with $0 \le r_{\mathsf{N}} <2\mathsf{N}$.
198 First of all, the integer $r$ is even since $r_{\mathsf{N}} = 2^{\mathsf{N}} - q_{\mathsf{N}}.2\mathsf{N}= 2(2^{\mathsf{N}-1} - q_{\mathsf{N}}.\mathsf{N})$.
199 Next, $a_{\mathsf{N}}$ is $\frac{2^{\mathsf{N}}-r_{\mathsf{N}}}{\mathsf{N}}$. Consequently
200 $d_{\mathsf{N}}$ is $r_{\mathsf{N}}/2$ and is thus a positive integer s.t.
201 $0 \le d_{\mathsf{N}} <\mathsf{N}$.
202 The proof for $c_{\mathsf{N}}$ is obvious.
205 For any $i$, $1 \le i \le \mathsf{N}$, let $zi_{\mathsf{N}}$ (resp. $ti_{\mathsf{N}}$ and $bi_{\mathsf{N}}$)
206 be the occurence number of element $i$ in the sequence $u_0, \dots, u_{l-2}$
207 (resp. in the sequences $s_{i_1}, \dots , s_{i_l}$ and $v$)
208 in step (\ref{item:nondet}) of the algorithm.
210 Due to the definition of $u'$ in step~(\ref{item:u'}),
211 $3.zi_{\mathsf{N}} + ti_{\mathsf{N}}$ is the
212 number of element $i$ in the sequence $U$.
213 It is clear that the number of element $i$ in the sequence $V$ is
214 $2bi_{\mathsf{N}}$ due to step (\ref{item:VW}).
215 We thus have the following system:
219 3.zi_{\mathsf{N}} + ti_{\mathsf{N}} + 2.bi_{\mathsf{N}} + \textit{TC}_{\mathsf{N}-2}(i) &= &\textit{TC}_{\mathsf{N}}(i) \\
220 zi_{\mathsf{N}} + ti_{\mathsf{N}} + bi_{\mathsf{N}} & =& \textit{TC}_{\mathsf{N}-2}(i)
231 \dfrac{\textit{TC}_{\mathsf{N}}(i) - 2.\textit{TC}_{\mathsf{N}-2}(i) - bi_{\mathsf{N}}}{2}\\
232 ti_{\mathsf{N}} &= & \textit{TC}_{\mathsf{N}-2}(i)-zi_{\mathsf{N}}-bi_{\mathsf{N}}
238 In this set of 2 equations with 3 unknown variables, let $b_i$ be set with 0.
239 In this case, since $\textit{TC}_{\mathsf{N}}$ is even (equal to $a_{\mathsf{N}}$
240 or to $a_{\mathsf{N}}+2$), the variable $zi_{\mathsf{N}}$ is thus an integer.
241 Let us now prove that the resulting system has always positive integer
242 solutions $z_i$, $t_i$, $0 \le z_i, t_i \le \textit{TC}_{\mathsf{N}-2}(i)$
243 and s.t. their sum is equal to $\textit{TC}_{\mathsf{N}-2}(i)$.
244 This latter consraint is obviously established if the system has a solution.
245 We thus have the following system.
253 \dfrac{\textit{TC}_{\mathsf{N}}(i) - 2.\textit{TC}_{\mathsf{N}-2}(i) }{2}\\
254 ti_{\mathsf{N}} &= & \textit{TC}_{\mathsf{N}-2}(i)-zi_{\mathsf{N}}
260 The definition of $\textit{TC}_{\mathsf{N}}(i)$ depends on the value of $\mathsf{N}$.
261 When $3 \le N \le 7$, values are defined as follows:
263 \textit{TC}_{3} & = & [2,2,4] \\
264 \textit{TC}_{5} & = & [6,6,8,6,6] \\
265 \textit{TC}_{7} & = & [18,18,20,18,18,18,18] \\
267 \textit{TC}_{4} & = & [4,4,4,4] \\
268 \textit{TC}_{6} & = & [10,10,10,10,12,12] \\
270 It is not hard to verify that all these instanciations verify the aformentioned contraints.
272 When $N \ge 8$, $\textit{TC}_{\mathsf{N}}(i)$ is defined as follows:
274 \textit{TC}_{\mathsf{N}}(i) = \left\{
276 a_{\mathsf{N}} \textrm{ if } 1 \le i \le c_{\mathsf{N}} \\
277 a_{\mathsf{N}}+2 \textrm{ if } c_{\mathsf{N}} +1 \le i \le c_{\mathsf{N}} + d_{\mathsf{N}}
287 \textit{TC}_{\mathsf{N}}(i) - 2.\textit{TC}_{\mathsf{N}-2}(i)
289 a_{\mathsf{N}} - 2(a_{\mathsf{N}-2}+2) \\
291 \frac{2^{\mathsf{N}}-r_{\mathsf{N}}}{\mathsf{N}}
292 -2 \left( \frac{2^{\mathsf{N-2}}-r_{\mathsf{N-2}}}{\mathsf{N-2}}+2\right)\\
294 \frac{2^{\mathsf{N}}-2N}{\mathsf{N}}
295 -2 \left( \frac{2^{\mathsf{N-2}}}{\mathsf{N-2}}+2\right)\\
297 \dfrac{(\mathsf{N} -2).2^{\mathsf{N}}-2N.2^{\mathsf{N-2}}-6N(N-2)}{\mathsf{N.(N-2)}}\\
301 A simple variation study of the function $t:\R \rightarrow \R$ such that
302 $x \mapsto t(x) = (x -2).2^{x}-2x.2^{x-2}-6x(x-2)$ shows that
303 its derivative is strictly postive if $x \ge 6$ and $t(8)=224$.
304 The integer $\textit{TC}_{\mathsf{N}}(i) - 2.\textit{TC}_{\mathsf{N}-2}(i)$ is thus positive
305 for any $\mathsf{N} \ge 8$ and the proof is established.
310 % \begin{array}{|l|l|l|l|l|l|}
312 % \mathsf{N} & 3 & 4 & 5 & 6 & 7\\
314 % a_{\mathsf{N}} & 2 & 4 & 6 & 10 & 18\\
319 % \caption{First values of $a_{\mathsf{N}}$}
322 For each element $i$, we are then left to choose $zi_{\mathsf{N}}$ positions
323 among $\textit{TC}_{\mathsf{N}}(i)$, which leads to
324 ${\textit{TC}_{\mathsf{N}}(i) \choose zi_{\mathsf{N}} }$ possibilities.
325 Notice that all such choices lead to a hamiltonian path.
333 %%% TeX-master: "main"
334 %%% ispell-dictionary: "american"