有限多正整数的置换
permutation的Python项目详细描述
GitHub |PyPI |Documentation |Issues
permutation提供一个Permutation类,用于表示有限多个正的permutations python中的整数。支持的操作和属性包括反转(组 理论上)顺序,奇偶性,合成/乘法,循环分解, 循环符号、单词表示法、lehmer码,当然,还用作 对整数可调用。
示例
>>> from permutation import Permutation >>> p = Permutation(2, 1, 4, 5, 3) >>> p.to_cycles() [(1, 2), (3, 4, 5)] >>> print(p) (1 2)(3 4 5) >>> print(p.inverse()) (1 2)(3 5 4) >>> p.degree 5 >>> p.order 6 >>> p.is_even False >>> p.lehmer(5) 27 >>> q = Permutation.cycle(1,2,3) >>> print(p * q) (2 4 5 3) >>> print(q * p) (1 3 4 5) >>> for p in Permutation.group(3): ... print(p) ... 1 (1 2) (2 3) (1 3 2) (1 2 3) (1 3)