-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5-dammMethod.tex
311 lines (286 loc) · 8.73 KB
/
5-dammMethod.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
\chapter{Damm's method}
Damm's method is check digit algorithm based on
\emph{quasigroup}.
It can detect all single-digit errors and all adjacent transposition errors.
\section{Quasigroup}
\emph{Quasigroup} $(Q,*)$ is a set $Q$ with a binary operation ``$*$''
such that \emph{ Latin square property} holds:
for every $a,b \in Q$, there exists unique $x$ and $y$ satisfy the following.
\begin{align*}
a*x = b\\
y*a = b
\end{align*}
Let us consider a \emph{Cayley table} of the operation ``$*$''.
Latin square property can be characterize by whether
the table is \emph{Latin square}:
each element occurs exactly once in each row and exactly once in each column.
For example, the operation expressed by the following table
satisfies Latin square property.
\begin{center}
\begin{tabular}{| l || l | l | l |}
\hline
$*$& 0 & 1 & 2\\
\hline\hline
0 & 0 & 1 & 2\\
\hline
1 & 1 & 2 & 0 \\
\hline
1 & 2 & 0 & 1 \\
\hline
\end{tabular}
\end{center}
The following lemma is derived immediately,
which is significant for error detection of
damm's method.
\begin{lemma}
Suppose $(Q,*)$ is quasigroup.
For arbitrary $x,x'$ and $a$ in $Q$, the following hold.
\begin{align}
x \neq x'\; \Rightarrow a*x \neq a*x' \label{eq:lem1}\\
x \neq x'\; \Rightarrow x*a \neq x'*a \label{eq:lem2}
\end{align}
\end{lemma}
\section{Damm's method}
This algorithm is based on quasigroup $(Q,*)$
of 10-order with a special property:
for all $c,x,y \in Q$ the followings hold.
\begin{align}
&(c*x)*y = (c*y)*x \;\Rightarrow x = y \label{eq:antiSym1}\\
&x*x = 0 \label{eq:res}
\end{align}
The example of such a quasigroup is shown below.
\begin{figure}[htb]
\begin{center}
\begin{tabular}{| l || l | l | l | l | l | l | l | l | l | l |}
\hline
* & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline\hline
0 & 0 & 3 & 1 & 7 & 5 & 9 & 8 & 6 & 4 & 2\\
\hline
1 & 7 & 0 & 9 & 2 & 1 & 5 & 4 & 8 & 6 & 3\\
\hline
2 & 4 & 2 & 0 & 6 & 8 & 7 & 1 & 3 & 5 & 9\\
\hline
3 & 1 & 7 & 5 & 0 & 9 & 8 & 3 & 4 & 2 & 6\\
\hline
4 & 6 & 1 & 2 & 3 & 0 & 4 & 5 & 9 & 7 & 8\\
\hline
5 & 3 & 6 & 7 & 4 & 2 & 0 & 9 & 5 & 8 & 1\\
\hline
6 & 5 & 8 & 6 & 9 & 7 & 2 & 0 & 1 & 3 & 4\\
\hline
7 & 8 & 9 & 4 & 5 & 3 & 6 & 2 & 0 & 1 & 7\\
\hline
8 & 9 & 4 & 3 & 8 & 6 & 1 & 7 & 2 & 0 & 5\\
\hline
9 & 2 & 5 & 8 & 1 & 4 & 3 & 6 & 7 & 9 & 0\\
\hline
\end{tabular}
\end{center}
\caption{Example:Quasigroup for damm's method}
\label{fig:10digitsQuasi}
\end{figure}
{\bf The validity of a digit sequence $m_1 m_2 ... m_n$ is judged by whether
$(...((0*m_1)*m_2)*...*m_n) = 0 $ holds.}
Given a digit sequence $m_1 m_2...m_{n-1}$,
a valid sequence can be generated by
adding $m_n = (...((0*m_1)*m_2)*...*m_{n-1})$ to the tail:
$(...((0*m_1)*m_2)*...*m_n) = 0 $ holds from the equation~\ref{eq:res}.
This method can detect all single-digit
errors and all adjacent transposition errors.
The proof is as follow.
We denote $k_i^{m}$ as $(...(0*m_1)*...*m_i)$.
\begin{itemize}
\item \underline{single-digit errors }
Suppose digit sequences $m$ and $m'$ are same except for i'th element:
$m_i \neq m'_i$.
\begin{align*}
k_i^{m} &= k_{i-1}^{m} * m_i \\
k_i^{m'} &= k_{i-1}^{m} * m'_i
\end{align*}
From the implication~\ref{eq:lem1},
$$k_i^{m} \neq k_i^{m'}$$
is derived.
\begin{align*}
k_{i+1}^{m} &= k_i^{m} * m_i \\
k_{i+1}^{m'} &= k_i^{m} * m'_i
\end{align*}
From the implication~\ref{eq:lem2},
$$k_{i+1}^{m} \neq k_{i+1}^{m'}$$
Therefore, inductively,
$$k_{n}^{m'} \neq k_{n}^{m} = 0$$
\item \underline{ adjacent transposition errors}
Suppose a digit sequence $m'$ is a result of
swapping $m_i$ and $m_{i+1}$ in a sequence $m$.
Here, we assume $m_i \neq m_{i+1}$.
\begin{align*}
k_{i+1}^{m} &= (k_{i-1}^{m}* m_i) * m_{i+1} \\
k_{i+1}^{m'} &= (k_{i-1}^{m}* m_{i+1}) * m_i
\end{align*}
From (\ref{eq:antiSym1}),
$$k_{i+1}^{m} \neq k_{i+1}^{m'}$$
is derived.
Hence, same as the case \underline{single-digit errors },
$$k_{n}^{m'} \neq k_{n}^{m} = 0$$
\end{itemize}
\section{Sufficient condition}
We modified the original validation method such that the additional property is as weak as possible.
Given a digit sequence $m_1 m_2 \ldots m_{n-1}$, since \emph{ Latin square property} of Quasigroup, there exists unique $m_n$ such that $(((0*m_1)*m_2)*\ldots *m_{n-1}) * m_n = 0$. Valid sequence can be generated by adding this $m_n$ value to the tail.
\underline{single-digit errors } proof requires implication~\ref{eq:lem1} and~\ref{eq:lem2}, that can be implied from \emph{ Latin square property} of Quasigroup. And, \underline{ adjacent transposition errors} proof requires only~\ref{eq:antiSym1}. We wrote a program to find all such Quasigroups that they satisify~\ref{eq:antiSym1} but not~\ref{eq:res}. The result is shown in Figure~\ref{fig:10digitsQuasiNotdamm1},~\ref{fig:10digitsQuasiNotdamm2},~\ref{fig:10digitsQuasiNotdamm3}.
C++ code is as following
\begin{minted}{cpp}
#include <iostream>
using namespace std;
#define SIZE 10
//number of tables to find
#define NFIND 3
int cnt = NFIND;
void tprint(int a[][SIZE]){
cout << "Result " << (NFIND - cnt + 1) << endl;
for(int row = 0; row < SIZE; row++){
for(int col = 0; col < SIZE; col ++)
cout << a[row][col] << " ";
cout << endl;
//print for latex
//cout << row;
//for(int col = 0; col < SIZE; col ++)
//cout << " & " << a[row][col];
//cout << "\\\\\n\\hline\n";
}
cout << endl;
}
bool f(int a[][SIZE], int row, int col, int val){
if (!cnt) return false;
a[row][col] = val;
int nrow, ncol;
if (col < SIZE - 1){
ncol = col + 1;
nrow = row;
} else if (row < SIZE - 1){
ncol = 0;
nrow = row + 1;
} else {
bool found = false;
for(int i = 0; i < SIZE; i++)
if (a[i][i] != i){
found = true;
break;
}
if (!found) return false;
tprint(a);
cnt--;
return !cnt;
}
bool checked[SIZE];
fill(checked, checked + SIZE * sizeof(bool), false);
for(int i = 0; i < ncol; i++)
checked[a[nrow][i]] = true;
for(int i = 0; i < nrow; i++)
checked[a[i][ncol]] = true;
for(int v = 0; v < SIZE; v++)
if (!checked[v] && f(a, nrow, ncol, v))
return true;
return false;
}
int main(){
int a[SIZE][SIZE];
for(int i = 0; i < SIZE; i++)
f(a, 0, 0, i);
if (cnt == NFIND)
cout << "not found" << endl;
return 0;
}
\end{minted}
\begin{figure}[htb]
\begin{center}
\begin{tabular}{| l || l | l | l | l | l | l | l | l | l | l |}
\hline
* & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline\hline
0 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline
1 & 1 & 0 & 3 & 2 & 5 & 4 & 7 & 6 & 9 & 8\\
\hline
2 & 2 & 3 & 0 & 1 & 6 & 7 & 8 & 9 & 4 & 5\\
\hline
3 & 3 & 2 & 1 & 0 & 7 & 6 & 9 & 8 & 5 & 4\\
\hline
4 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3\\
\hline
5 & 5 & 4 & 7 & 6 & 9 & 8 & 1 & 0 & 3 & 2\\
\hline
6 & 6 & 7 & 8 & 9 & 2 & 3 & 4 & 5 & 0 & 1\\
\hline
7 & 7 & 6 & 9 & 8 & 3 & 2 & 5 & 4 & 1 & 0\\
\hline
8 & 8 & 9 & 4 & 5 & 0 & 1 & 2 & 3 & 6 & 7\\
\hline
9 & 9 & 8 & 5 & 4 & 1 & 0 & 3 & 2 & 7 & 6\\
\hline
\end{tabular}
\end{center}
\caption{Example1: Non anti-symmetric Quasigroup for damm's method}
\label{fig:10digitsQuasiNotdamm1}
\end{figure}
\begin{figure}[htb]
\begin{center}
\begin{tabular}{| l || l | l | l | l | l | l | l | l | l | l |}
\hline
* & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline\hline
0 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline
1 & 1 & 0 & 3 & 2 & 5 & 4 & 7 & 6 & 9 & 8\\
\hline
2 & 2 & 3 & 0 & 1 & 6 & 7 & 8 & 9 & 4 & 5\\
\hline
3 & 3 & 2 & 1 & 0 & 7 & 6 & 9 & 8 & 5 & 4\\
\hline
4 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3\\
\hline
5 & 5 & 4 & 7 & 6 & 9 & 8 & 1 & 0 & 3 & 2\\
\hline
6 & 6 & 7 & 8 & 9 & 2 & 3 & 4 & 5 & 0 & 1\\
\hline
7 & 7 & 6 & 9 & 8 & 3 & 2 & 5 & 4 & 1 & 0\\
\hline
8 & 8 & 9 & 4 & 5 & 0 & 1 & 2 & 3 & 7 & 6\\
\hline
9 & 9 & 8 & 5 & 4 & 1 & 0 & 3 & 2 & 6 & 7\\
\hline
\end{tabular}
\end{center}
\caption{Example2: Non anti-symmetric Quasigroup for damm's method}
\label{fig:10digitsQuasiNotdamm2}
\end{figure}
\begin{figure}[htb]
\begin{center}
\begin{tabular}{| l || l | l | l | l | l | l | l | l | l | l |}
\hline
* & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline\hline
0 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline
1 & 1 & 0 & 3 & 2 & 5 & 4 & 7 & 6 & 9 & 8\\
\hline
2 & 2 & 3 & 0 & 1 & 6 & 7 & 8 & 9 & 4 & 5\\
\hline
3 & 3 & 2 & 1 & 0 & 7 & 6 & 9 & 8 & 5 & 4\\
\hline
4 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3\\
\hline
5 & 5 & 4 & 7 & 6 & 9 & 8 & 1 & 0 & 3 & 2\\
\hline
6 & 6 & 7 & 8 & 9 & 2 & 3 & 4 & 5 & 0 & 1\\
\hline
7 & 7 & 6 & 9 & 8 & 3 & 2 & 5 & 4 & 1 & 0\\
\hline
8 & 8 & 9 & 4 & 5 & 0 & 1 & 3 & 2 & 6 & 7\\
\hline
9 & 9 & 8 & 5 & 4 & 1 & 0 & 2 & 3 & 7 & 6\\
\hline
\end{tabular}
\end{center}
\caption{Example3: Non anti-symmetric Quasigroup for damm's method}
\label{fig:10digitsQuasiNotdamm3}
\end{figure}