Consider the set of parity vectors of size n such that:
- None is a rotation of any other one (also known as necklace problem)
- None is a power of a smaller one
These parity vectors, which for a like of a better term I call “prime” parity vectors (don’t hesitate if you have a better name!) are interesting because they are a restricted family which is enough to enumerate if you’re looking for a nontrivial cycle.
Here’s their number starting at n=0:
1,2,1,2,3,6,9,18,30,56,99,186,335,630,1161,2182,4080,7710
Here is a Python function to enumerate them:
def divisors(n):
result = set()
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
result.add(i)
result.add(n // i)
return sorted(result)
def is_power(pv):
for d in divisors(len(pv)):
if d == len(pv):
continue
if pv == pv[:d]*(len(pv)//d):
return True
return False
def enumerate_pv_without_rotation_and_without_powers(len_pv):
seen = {}
for pv in itertools.product([0,1], repeat=len_pv):
pv_c = coreli.ParityVector(pv)
rot_seen = False
for i in range(len(pv)):
pv_c_r = pv_c.rotate(i)
if tuple(pv_c_r.parity_vector) in seen:
rot_seen = True
break
if rot_seen:
continue
seen[pv] = True
if is_power(pv):
continue
yield pv
Here are all of them up to size 7:
[()],
[(0,), (1,)],
[(0, 1)],
[(0, 0, 1), (0, 1, 1)],
[(0, 0, 0, 1), (0, 0, 1, 1), (0, 1, 1, 1)],
[(0, 0, 0, 0, 1),
(0, 0, 0, 1, 1),
(0, 0, 1, 0, 1),
(0, 0, 1, 1, 1),
(0, 1, 0, 1, 1),
(0, 1, 1, 1, 1)],
[(0, 0, 0, 0, 0, 1),
(0, 0, 0, 0, 1, 1),
(0, 0, 0, 1, 0, 1),
(0, 0, 0, 1, 1, 1),
(0, 0, 1, 0, 1, 1),
(0, 0, 1, 1, 0, 1),
(0, 0, 1, 1, 1, 1),
(0, 1, 0, 1, 1, 1),
(0, 1, 1, 1, 1, 1)],
[(0, 0, 0, 0, 0, 0, 1),
(0, 0, 0, 0, 0, 1, 1),
(0, 0, 0, 0, 1, 0, 1),
(0, 0, 0, 0, 1, 1, 1),
(0, 0, 0, 1, 0, 0, 1),
(0, 0, 0, 1, 0, 1, 1),
(0, 0, 0, 1, 1, 0, 1),
(0, 0, 0, 1, 1, 1, 1),
(0, 0, 1, 0, 0, 1, 1),
(0, 0, 1, 0, 1, 0, 1),
(0, 0, 1, 0, 1, 1, 1),
(0, 0, 1, 1, 0, 1, 1),
(0, 0, 1, 1, 1, 0, 1),
(0, 0, 1, 1, 1, 1, 1),
(0, 1, 0, 1, 0, 1, 1),
(0, 1, 0, 1, 1, 1, 1),
(0, 1, 1, 0, 1, 1, 1),
(0, 1, 1, 1, 1, 1, 1)]