t t f f f f t t
t t f f f f t t
f f t t t t f f
f f t t t t f f
t t f f f f t t
t t f f f f t t
f f t t t t f f
f f t t t t f f
Is it possible to determine the symmetry of the above 8x8 using 8-input truth tables e.g. OR, AND, XOR, etc?
Assuming you mean symmetry the same way I do and that you have the input in something like a bool[][]
or an std::vector<std::vector<bool> >
(or char
instead of bool
, it doesn't really matter as long as ==
works), you'd simply iterate over one half of the matrix and compare with the other half, something like this:
bool symmetric = true;
for (unsigned int i = 1; symmetric && i <= n; ++i) {
for (unsigned int j = i+1; symmetric && j <= n; ++j) {
symmetric = (M[i][j] == M[j][i]);
}
}
Note that you don't need to check the diagonal, which is why i
starts at 1 and j
at i+1
in the code above.
(I tend to write more parentheses and braces than some people like. I just happen to prefer code written that way.)
EDIT:
You can have a 64-input table that tells you which inputs are symmetric, sure. With a bit of compression, you could store that table in 2097152 TB of memory. I guess the looping code can run pretty often before you are finished loading this table for lookup. Instead, you could of course enter the six non-trivial lines parallel to the antidiagonal into corresponding truth tables, since if they are symmetric, the whole matrix is. Those tables (for 2, 3, 4, 5, 6, 7, and 8 inputs) would easily fit into a few hundred bytes.
But it seems your interpretation of symmetry is different from mine, anyway. If you are interested in whether each row and/or each column is symmetric, then, obviously, you can use truth tables for that. Stroing them takes 256 bits, so if you are really short on space, you could squeeze them into 8 bits, but lookup is probably faster when you spend 256 bytes on it.