perm_sign

  • full name: tenpy.tools.math.perm_sign

  • parent module: tenpy.tools.math

  • type: function

tenpy.tools.math.perm_sign(p)[source]

Given a permutation p of numbers, returns its sign. (+1 or -1)

Assumes that all the elements are distinct, if not, you get crap.

Examples

>>> import itertools
>>> for p in itertools.permutations(range(3)):
...      print('{p!s}: {sign!s}'.format(p=p, sign=tenpy.tools.math.perm_sign(p)))
(0, 1, 2): 1
(0, 2, 1): -1
(1, 0, 2): -1
(1, 2, 0): 1
(2, 0, 1): 1
(2, 1, 0): -1