Ratios and the Chinese Remainder Theorem

The following visualization shows a diagonal line travelling on a torus with sides a and b.  By a torus I mean that the x values are considered modulo a and the y values are considered modulo b.  I’m actually showing four copies of it, to help you see the “wrapping around” effect happening.

Use “ijkl” as arrow keys to resize the torus (you may need to click first).  Play with it before viewing the explanation below.

This demonstrates the Chinese Remainder Theorem, as explained in this nice post (and some related posts) from The Math Less Travelled. Here’s the idea:  think of position (x,y) meaning x mod a and y mod b.  Then the diagonal line is the positive integers 1,2,3,… in order. Like this (again, ‘ijkl’ as arrow keys will resize):

In some cases, the diagonal line eventually covers everything, meaning there’s some integer T so that T = x mod a and T = y mod b for every pair (x,y).  But sometimes, you can’t solve this system of equations.  Can you see how to tell when you can and cannot?