Template:3-bit Walsh permutation/inverse nitpick
six edge cases of invertibility | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
To be precise, the group consists of the 168 binary matrices whose inverses are integer matrices, namely with entries 0, 1 and −1.
The following Python script shows that the 512 binary matrices consist of 338 singular matrices, 168 with integer inverses and 6 with non-integer inverses: from itertools import product
def is_integer_matrix(matrix):
for row in matrix:
for entry in row:
if entry % 1 > 0:
return False
return True
number_of_singular_matrices = 0
number_of_matrices_with_integer_inverses = 0
number_of_matrices_with_non_integer_inverses = 0
for m00, m01, m02, m10, m11, m12, m20, m21, m22 in product([0, 1], repeat=9):
mat = np.array([[m00, m01, m02], [m10, m11, m12], [m20, m21, m22]])
try:
mat_inv = np.linalg.inv(mat)
if is_integer_matrix(mat_inv):
number_of_matrices_with_integer_inverses += 1
else:
number_of_matrices_with_non_integer_inverses += 1
except np.linalg.LinAlgError:
number_of_singular_matrices += 1
print('singular matrices:', number_of_singular_matrices)
print('matrices with integer inverses:', number_of_matrices_with_integer_inverses)
print('matrices with non-integer inverses:', number_of_matrices_with_non_integer_inverses)
|