Template:Seal integer representations/python
Appearance
Python program to calculate the integer sequence | ||
---|---|---|
This code uses the Python library discrete helpers. from discretehelpers.a import make_linear_binv
arity = 4
depth_to_seals = {depth: None for depth in range(arity)}
depth_to_seals[0] = [make_linear_binv(walsh=0, parity=1, arity=arity)] # tautology
depth_to_seals[1] = [make_linear_binv(walsh=i, parity=1, arity=arity) for i in range(1, 2 ** arity)] # negated Walsh functions
for new_depth in range(2, arity+1):
new_weight = 2 ** (arity - new_depth)
old_depth = new_depth - 1
old_seals = depth_to_seals[old_depth]
new_seals = set()
for key_a, seal_a in enumerate(old_seals):
for key_b in range(key_a + 1, len(old_seals)):
seal_b = old_seals[key_b]
candidate = seal_a & seal_b
if candidate.weight == new_weight:
new_seals.add(candidate)
depth_to_seals[new_depth] = sorted(new_seals)
lengths = []
sequence = []
for depth, seals in depth_to_seals.items():
rank = arity - depth
seal_integers = sorted([seal.intval for seal in seals])
print(f'{rank}: {seal_integers},')
lengths.append(len(seal_integers))
sequence += seal_integers
print('\n', lengths)
print('\n', sorted(sequence))
|