I've encountered a math problem in programming-language compilation, and I was wondering if there was a known, easy solution to it.
Suppose a chunk of memory is addressed in the usual fashion, using offsets relative to the start of the allocated memory. Also suppose that a program uses two different interpretations of that chunk of memory.
In one interpretation, the memory has this repeating layout: $a0, a1, a2, a0, a1, a2, ...$
In the other interpretation, the memory has this repeating layout: $b0, b1, b2, b3, b0, b1, b2, b3, ...$
So it looks like this: $$\begin{array}{|c|c|c|c|c|c|c|c|c|c|} \hline \text{memory offset} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & \cdots \\ \hline \text{sequence A} & a0 & a1 & a2 & a0 & a1 & a2 & a0 & a1 & a2 & a0 & \cdots \\ \hline \text{sequence B} & b0 & b1 & b2 & b3 & b0 & b1 & b2 & b3 & b0 & b1 & \cdots \\ \hline \end{array}$$
So in the general case, the symbol $a_k$ is associated with all memory offsets $\{i*3 + k\ |\ i \ge 0\}$ and $b_k$ is associated with all memory offsets $\{i*4 + k\ |\ i \ge 0\}$.
Now here's my question. Suppose that for both sequences, I'm interested in a contiguous range of symbol names. For example, $A_{interest} = \{ a_x | q \le x \le r \}$ and $B_{interest} = \{ b_x | s \le x \le t \}$. I'd simply like to know whether or not any of the memory offsets will be associated with both an element of $A_{interest}$ and an element of $B_{interest}$.
I think a solution goes something like this:
If neither $|\text{sequence A}|$ nor $|\text{sequence B}|$ evenly divides into the other, the answer is simply yes, there's overlap. Regardless of what symbols comprise $A_{interest}$ and $B_{interest}$, every pairing of symbols from those two sets will end up sharing some of the memory locations.
Otherwise, I analyze the offsets generated by repeating the smaller of those two sequences, $|\text{sequence A}|$ or $|\text{sequence B}|$, inside the larger sequence. I could do brute-force here, but I'm sure there's a more elegant solution.