Discrete helpers/sig perm
sig_perm |
This is an extension of the class Perm with added negators.
Signed permutations of length are the elements of the hyperoctahedral group of dimension . (See e.g. the full octahedral group for the 48 permutations of the cube.)
This class has been created to model transformations between Boolean functions in the same clan. (See Studies of Euler diagrams/transformations.)
import numpy as np
from discretehelpers.sig_perm import SigPerm
from discretehelpers.perm import Perm
from discretehelpers.binv import Binv
sp = SigPerm(sequence=[3, ~1, ~0, 2])
matrix = [
[ 0, 0, -1, 0],
[ 0, -1, 0, 0],
[ 0, 0, 0, 1],
[ 1, 0, 0, 0]
]
assert sp == SigPerm(matrix=matrix)
assert sp == SigPerm(pair=[3, 11])
assert sp == SigPerm(valneg_index=3, perm_index=11)
assert sp == SigPerm(valneg=[1, 1, 0, 0], perm=[3, 1, 0, 2])
assert sp == SigPerm(valneg={0, 1}, perm=[3, 1, 0, 2, 4, 5, 6])
assert sp == SigPerm(keyneg_index=6, perm_index=11)
assert sp == SigPerm(keyneg=[0, 1, 1, 0], perm=[3, 1, 0, 2])
assert sp == SigPerm(keyneg={1, 2}, perm=[3, 1, 0, 2, 4, 5, 6])
assert sp.pair == (3, 11)
assert (sp.keyneg_index, sp.valneg_index, sp.perm_index) == (6, 3, 11)
assert sp.length == 4
assert sp.sequence() == sp.sequence(4) == [3, ~1, ~0, 2] == [3, -2, -1, 2]
assert sp.sequence_string() == sp.sequence_string(4) == '[3, ~1, ~0, 2]'
assert sp.binv == Binv('1100')
assert sp.perm == Perm([3, 1, 0, 2])
assert np.array_equal(sp.matrix(), matrix)
keyneg and valneg | ||
---|---|---|
The pattern of negations can be described in two different ways:
When a signed permutation is denoted by a pair (m, n), it is usually the valneg index m and the permutation index n. |
inverse |
---|
assert sp.inverse == SigPerm(sequence=[~2, ~1, 3, 0])
assert sp.inverse.pair == (6, 19)
inverse_matrix = [
[ 0, 0, 0, 1],
[ 0, -1, 0, 0],
[-1, 0, 0, 0],
[ 0, 0, 1, 0]
]
assert sp * sp.inverse == sp.inverse * sp == SigPerm(sequence=[]) == Perm()
assert np.array_equal(
np.dot(matrix, inverse_matrix),
np.eye(4)
)
|
This is a subclass of Perm
, making the instances comparable.
from discretehelpers.sig_perm import SigPerm
from discretehelpers.perm import Perm
assert SigPerm(sequence=[3, 2, 0, 1]) == Perm([3, 2, 0, 1])
assert SigPerm(sequence=[3, ~2, 0, 1]) != Perm([3, 2, 0, 1])
Schoute permutation
editThe property schoute_perm
is inherited from Perm
. (See there.)
These are signed Schoute permutations.
name | a | b |
---|---|---|
pair | (6, 3) | (5, 4) |
sequence | [~2, 0, ~1] | [1, ~2, ~0] |
cube permutation |
from discretehelpers.sig_perm import SigPerm
from discretehelpers.perm import Perm
a = SigPerm(pair=[6, 3])
b = SigPerm(pair=[5, 4])
assert a.inverse == b
a.sequence_string() == '[~2, 0, ~1]'
b.sequence_string() == '[1, ~2, ~0]'
a.schoute_perm == Perm([6, 2, 7, 3, 4, 0, 5, 1], perilen=8)
b.schoute_perm == Perm([5, 7, 1, 3, 4, 6, 0, 2], perilen=8)
Like for normal permutations, the parity corresponds to the determinant of the matrix. (But the metribute inherited from Perm is wrong.)