Unique unclosed paths on torus grid

194 Views Asked by At

Consider a grid of points in the shape of torus with in my case $n=16$ points around the toroidal direction and $m=7$ points around the poloidal direction. Now draw a line by starting at any grid point on the torus and walking around the torus in the toroidal direction to toriodially adjacent grid points, making $n-1$ steps and so visiting $n$ points At every step you move you may pick any of the $m$ points in the poloidal direction. your line does not have to but may connect after you have visited $n$ points.

Lines translated or mirrored in either direction are equal and lines with a period $p < n$ are omitted

My question is: how many paths are there? And how could I iterate them efficiently?

Not considering the symmetries there are $m^n$ paths, symmetry around the poloidal direction can be avoided by simply always starting at 0 on the poloidal direction, this makes for $m^{n-1}$ paths. For each path their are $n$ symmetries around the toroidal direction, giving $m^{n-1} / n$, this however only holds when n is prime, in situations where n is not prime there are periodic paths that we have to omit first, The amount of Lyndon words seems to define this. But I'm not sure how to count those.

As for iteration, I'm currently stuck doing pretty bad O(n) checks on Lyndon words.