In truth I don't remember what made me think of this. It's just a puzzle that popped into my head.
Suppose you want to go through a binary sequence that repeats using all possible codes, and changes as many bits as possible in each step, like the opposite of gray code. If a minimum of n bits must change in each step, then how can you calculate the maximum n for a given word size?
I think n is one less than the word size, considering that you could always generate the next code in gray code and then complement it so all but one bit would change. Or would that not use every code? (I'm trying to do this in my head.)
I think that one gets the maximum randomness if on average half the bits change on each step. The crypto folk worry about such things a lot. As do the sparse neural code folk.
What I mean is very non-random because it would change more than half if possible.
I couldn't do it in my head, but working it out for the 4 bit case shows that the maximum n is 3, and using the next gray code complemented does cycle through all codes.
Well, if a gray code changes only one bit yet gets through all possible codes, then it's possible to change all-but-one bit and also get through all possible codes. All you have to do is to compute the gray code, and your result is the result of xor-ing each code with its preceding one.
I think you wanna find the path along the edges of a graph like this:
formatting link
That visits all vertices only once and also maximizes the distance traveled. Sort of the inverse traveling-salesman problem. I can't do it in my head even for three bits.
And like Gray codes there's likely more than one equally valid solution for any particular (hyper)cube.
It's clear than n cannot be equal to the word size. So, can one prove that it's possible with n = word size - 1?
For a word size of k bits, assume that there is a sequence of 2^k - 1 steps that starting from all zeros, visits every combination once, with the final combination being all ones. Further assume that each step involves flipping at least k - 1 bits.
Now introduce a new bit that also starts at zero. For each step, flip that bit. Since the previous sequence of 2^k - 1 steps flipped at least k - 1 bits, this means that now each step flips at least k bits.
The odd number of steps means that new new bit is now a one. On the next step, flip all of the other bits, but leave the new one alone. Since all the other bits are flipped, that step also flipped at least k bits, and those bits are returned to zero.
Now repeat the above process of flipping the new bit together with at least k - 1 of the other bits, in the same sequence as before. For each step, where the new bit was previously zero, it is now a one, and vice versa, so each combination of the k + 1 bits is visited for the first time.
The last step changes the original k bits to 1, and leaves the new bit as a one.
So, if it's possible for k bits, it's also possible for k + 1 bits.
Now consider the case for k = 2. We can use the sequence 00 01 10 11. So it is possible for k = 2.
This proves by induction that it is possible for all k.
We use the same sequence for the initial k bits, twice, and ex hypotesi it visits every combination of the k bits on each pass.
Adding a bit that is alternately 0, then 1, for the first pass of the k bits, and then alternately 1, then 0, for the second pass means that each combination of the k bits has been visited with the additional bit being both 0 and 1. Thus all combinations of the k + 1 bits are visited.
I don't think finding a sequence that maximizes the minimum Hamming distance between consecutive pairs of elements, is the same problem as finding a sequence which maximizes the total of the Hamming distance across pairs of consecutive elements, out of any permutation of all the elements, that is to say the maximum overall path length of the sequence.
It's the latter problem that gets you the maximum number of bits that change at each step or an "anti-Gray" code. You can get an anti-Gray code from any Gray code by applying a sorting function based on the Gray code itself:
formatting link
I think in the first problem you must inspect the taxicab distance at each step like a vector, the second you're just maximizing the total path length traveled on the graph you don't have to enforce constraints on each step additionally.
The taxicab distance to all other elements of the set, rather. That's why brute force for that one goes factorial on you when you're working with an n-cube.
This is more complicated than I expected. It got more attention than I expected too.
By traversing a 3D cube it's easy to see why you can't visit every vertex with diagonals that represent 2-bit changes. You need two 3-bit changes also, which is good, but I don't see a way to generalize the sequence.
You're in good company. some very good mathematicians have also tried and failed.
BTW the word for an n-D cube is tesseract.
I recently solved a mathematical problem that has some similar characteristics, which was to determine which numbers N have reciprocals that are maximum-length (length N-1) repeating decimals. It turns out to be linked to prime factors are other funky stuff.
Anyhow no-one knows how to construct a formula for this one. If you solve it, you'll be famous!
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.