SymPy 1.13 中文文档(十一)
多面体
原文:
docs.sympy.org/latest/modules/combinatorics/polyhedron.html
class sympy.combinatorics.polyhedron.Polyhedron(corners, faces=(), pgroup=())
表示多面体对称群(PSG)。
解释
PSG 是五正立体的对称群之一。有三个多面体群:12 阶四面体群,24 阶八面体群和 60 阶二十面体群。
所有的 doctest 都在对象构造函数的 docstring 中给出。
参考文献
[R92]
mathworld.wolfram.com/PolyhedralGroup.html
property array_form
返回角落的索引。
索引是相对于角落的原始位置给出的。
示例
>>> from sympy.combinatorics.polyhedron import tetrahedron
>>> tetrahedron = tetrahedron.copy()
>>> tetrahedron.array_form
[0, 1, 2, 3]
>>> tetrahedron.rotate(0)
>>> tetrahedron.array_form
[0, 2, 3, 1]
>>> tetrahedron.pgroup[0].array_form
[0, 2, 3, 1]
请参见
corners,cyclic_form
property corners
获取多面体的角落。
方法vertices是corners的别名。
示例
>>> from sympy.combinatorics import Polyhedron
>>> from sympy.abc import a, b, c, d
>>> p = Polyhedron(list('abcd'))
>>> p.corners == p.vertices == (a, b, c, d)
True
请参见
array_form,cyclic_form
property cyclic_form
返回循环表示法中角落的索引。
索引是相对于角落的原始位置给出的。
请参见
corners,array_form
property edges
给定多面体的面,我们可以获得边。
示例
>>> from sympy.combinatorics import Polyhedron
>>> from sympy.abc import a, b, c
>>> corners = (a, b, c)
>>> faces = [(0, 1, 2)]
>>> Polyhedron(corners, faces).edges
{(0, 1), (0, 2), (1, 2)}
property faces
获取多面体的面。
property pgroup
获取多面体的排列。
reset()
将角落返回到它们的原始位置。
示例
>>> from sympy.combinatorics.polyhedron import tetrahedron as T
>>> T = T.copy()
>>> T.corners
(0, 1, 2, 3)
>>> T.rotate(0)
>>> T.corners
(0, 2, 3, 1)
>>> T.reset()
>>> T.corners
(0, 1, 2, 3)
rotate(perm)
将置换就地应用于多面体。置换可以作为置换实例或表示应用于多面体的pgroup中的哪个置换的整数来给出。
这是一种类似于围绕轴的固定增量旋转的操作。
注意事项
当应用置换时,不检查它是否对多面体有效。例如,可以给立方体应用一个只交换两个顶点的置换。如果只使用多面体的pgroup中的置换,则会获得有效的置换(将对象以物理方式旋转)。另一方面,允许任意旋转(应用置换)可以通过名称元素的方式进行跟踪,因为多面体允许对顶点进行命名,而置换仅使用索引。
示例
>>> from sympy.combinatorics import Polyhedron, Permutation
>>> from sympy.combinatorics.polyhedron import cube
>>> cube = cube.copy()
>>> cube.corners
(0, 1, 2, 3, 4, 5, 6, 7)
>>> cube.rotate(0)
>>> cube.corners
(1, 2, 3, 0, 5, 6, 7, 4)
非物理“旋转”,不受此方法禁止。
>>> cube.reset()
>>> cube.rotate(Permutation([[1, 2]], size=8))
>>> cube.corners
(0, 2, 1, 3, 4, 5, 6, 7)
多面体可以用于跟踪用字母标识而不是整数的集合元素:
>>> shadow = h5 = Polyhedron(list('abcde'))
>>> p = Permutation([3, 0, 1, 2, 4])
>>> h5.rotate(p)
>>> h5.corners
(d, a, b, c, e)
>>> _ == shadow.corners
True
>>> copy = h5.copy()
>>> h5.rotate(p)
>>> h5.corners == copy.corners
False
property size
获取多面体的角落数。
property vertices
获取多面体的角点。
方法vertices是corners的别名。
示例
>>> from sympy.combinatorics import Polyhedron
>>> from sympy.abc import a, b, c, d
>>> p = Polyhedron(list('abcd'))
>>> p.corners == p.vertices == (a, b, c, d)
True
另请参见
array_form, cyclic_form
Prufer 序列
class sympy.combinatorics.prufer.Prufer(*args, **kw_args)
Prufer 对应是一种描述标记树和 Prufer 代码之间双射的算法。标记树的 Prufer 代码在同构下是唯一的,并且长度为 n - 2。
Prufer 序列最初由 Heinz Prufer 使用,用于证明 Cayley 公式。
参考文献
[R93]
mathworld.wolfram.com/LabeledTree.html
static edges(*runs)
返回给定运行连接整数标记的树中节点的边列表和节点数量。
所有节点编号将被转移,以使最小节点为 0. 如果在运行中重复边,不会产生问题;仅返回唯一边。对节点标签的范围没有假设,但必须包含从最小到最大的所有节点。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer.edges([1, 2, 3], [2, 4, 5]) # a T
([[0, 1], [1, 2], [1, 3], [3, 4]], 5)
删除重复的边:
>>> Prufer.edges([0, 1, 2, 3], [1, 4, 5], [1, 4, 6]) # a K
([[0, 1], [1, 2], [1, 4], [2, 3], [4, 5], [4, 6]], 7)
next(delta=1)
生成当前序列之后的 delta Prufer 序列。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> a = Prufer([[0, 1], [0, 2], [0, 3]])
>>> b = a.next(1) # == a.next()
>>> b.tree_repr
[[0, 2], [0, 1], [1, 3]]
>>> b.rank
1
参见
prufer_rank, rank, prev, size
property nodes
返回树中节点的数量。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer([[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]]).nodes
6
>>> Prufer([1, 0, 0]).nodes
5
prev(delta=1)
生成当前序列之前的 -delta Prufer 序列。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> a = Prufer([[0, 1], [1, 2], [2, 3], [1, 4]])
>>> a.rank
36
>>> b = a.prev()
>>> b
Prufer([1, 2, 0])
>>> b.rank
35
参见
prufer_rank, rank, next, size
prufer_rank()
计算 Prufer 序列的秩。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> a = Prufer([[0, 1], [0, 2], [0, 3]])
>>> a.prufer_rank()
0
参见
rank, next, prev, size
property prufer_repr
返回 Prufer 对象的 Prufer 序列。
此序列是通过移除编号最高的顶点、记录其连接到的节点,并继续此过程直到仅剩两个顶点为止找到的。Prufer 序列即为记录的节点列表。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer([[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]]).prufer_repr
[3, 3, 3, 4]
>>> Prufer([1, 0, 0]).prufer_repr
[1, 0, 0]
参见
to_prufer
property rank
返回 Prufer 序列的秩。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> p = Prufer([[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]])
>>> p.rank
778
>>> p.next(1).rank
779
>>> p.prev().rank
777
参见
prufer_rank, next, prev, size
property size
返回此 Prufer 对象可能的树的数量。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer([0]*4).size == Prufer([6]*4).size == 1296
True
参见
prufer_rank, rank, next, prev
static to_prufer(tree, n)
返回作为边列表的树的 Prufer 序列,其中n是树中的节点数。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> a = Prufer([[0, 1], [0, 2], [0, 3]])
>>> a.prufer_repr
[0, 0]
>>> Prufer.to_prufer([[0, 1], [0, 2], [0, 3]], 4)
[0, 0]
参见
prufer_repr
返回 Prufer 对象的 Prufer 序列。
static to_tree(prufer)
返回给定 Prufer 序列的树(作为边列表)。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> a = Prufer([0, 2], 4)
>>> a.tree_repr
[[0, 1], [0, 2], [2, 3]]
>>> Prufer.to_tree([0, 2])
[[0, 1], [0, 2], [2, 3]]
参见
tree_repr
返回 Prufer 对象的树表示。
参考文献
[R94]
hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html
property tree_repr
返回 Prufer 对象的树表示。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer([[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]]).tree_repr
[[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]]
>>> Prufer([1, 0, 0]).tree_repr
[[1, 2], [0, 1], [0, 3], [0, 4]]
参见
to_tree
classmethod unrank(rank, n)
找到未排序的 Prufer 序列。
示例
>>> from sympy.combinatorics.prufer import Prufer
>>> Prufer.unrank(0, 4)
Prufer([0, 0])
子集
class sympy.combinatorics.subsets.Subset(subset, superset)
表示基本子集对象。
解释
我们基本上使用两种技术生成子集,即二进制枚举和词典排序枚举。Subset 类接受两个参数,第一个描述要考虑的初始子集,第二个描述超集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.next_binary().subset
['b']
>>> a.prev_binary().subset
['c']
classmethod bitlist_from_subset(subset, superset)
获取与子集对应的位列表。
示例
>>> from sympy.combinatorics import Subset
>>> Subset.bitlist_from_subset(['c', 'd'], ['a', 'b', 'c', 'd'])
'0011'
另请参阅
subset_from_bitlist
property cardinality
返回所有可能子集的数量。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.cardinality
16
另请参阅
subset, superset, size, superset_size
iterate_binary(k)
这是一个辅助函数。它通过k步迭代二进制子集。该变量可以是正数或负数。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.iterate_binary(-2).subset
['d']
>>> a = Subset(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])
>>> a.iterate_binary(2).subset
[]
另请参阅
next_binary, prev_binary
iterate_graycode(k)
用于 prev_gray 和 next_gray 的辅助函数。它执行k步跨越以获取相应的 Gray 码。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([1, 2, 3], [1, 2, 3, 4])
>>> a.iterate_graycode(3).subset
[1, 4]
>>> a.iterate_graycode(-2).subset
[1, 2, 4]
另请参阅
next_gray, prev_gray
next_binary()
生成下一个二进制有序子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.next_binary().subset
['b']
>>> a = Subset(['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.next_binary().subset
[]
另请参阅
prev_binary, iterate_binary
next_gray()
生成下一个 Gray 码排序子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([1, 2, 3], [1, 2, 3, 4])
>>> a.next_gray().subset
[1, 3]
另请参阅
iterate_graycode, prev_gray
next_lexicographic()
生成下一个词典顺序有序子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.next_lexicographic().subset
['d']
>>> a = Subset(['d'], ['a', 'b', 'c', 'd'])
>>> a.next_lexicographic().subset
[]
另请参阅
prev_lexicographic
prev_binary()
生成前一个二进制有序子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([], ['a', 'b', 'c', 'd'])
>>> a.prev_binary().subset
['a', 'b', 'c', 'd']
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.prev_binary().subset
['c']
另请参阅
next_binary, iterate_binary
prev_gray()
生成前一个 Gray 码排序子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([2, 3, 4], [1, 2, 3, 4, 5])
>>> a.prev_gray().subset
[2, 3, 4, 5]
另请参阅
迭代格雷码, 下一个格雷码
prev_lexicographic()
生成前一个词典顺序的子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([], ['a', 'b', 'c', 'd'])
>>> a.prev_lexicographic().subset
['d']
>>> a = Subset(['c','d'], ['a', 'b', 'c', 'd'])
>>> a.prev_lexicographic().subset
['c']
另请参阅
下一个词典顺序
property rank_binary
计算二进制有序排名。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset([], ['a','b','c','d'])
>>> a.rank_binary
0
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.rank_binary
3
另请参阅
迭代二进制, 二进制反向排序
property rank_gray
计算子集的格雷码排名。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c','d'], ['a','b','c','d'])
>>> a.rank_gray
2
>>> a = Subset([2, 4, 5], [1, 2, 3, 4, 5, 6])
>>> a.rank_gray
27
另请参阅
迭代格雷码, 格雷码反向排序
property rank_lexicographic
计算子集的词典排名。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.rank_lexicographic
14
>>> a = Subset([2, 4, 5], [1, 2, 3, 4, 5, 6])
>>> a.rank_lexicographic
43
property size
获取子集的大小。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.size
2
另请参阅
子集, 超集, 超集大小, 基数
property subset
获取当前实例所表示的子集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.subset
['c', 'd']
另请参阅
超集, 大小, 超集大小, 基数
classmethod subset_from_bitlist(super_set, bitlist)
获取由位列表定义的子集。
示例
>>> from sympy.combinatorics import Subset
>>> Subset.subset_from_bitlist(['a', 'b', 'c', 'd'], '0011').subset
['c', 'd']
另请参阅
从子集生成位列表
classmethod subset_indices(subset, superset)
返回列表中子集在超集中的索引;如果subset的所有元素都不在superset中,则列表为空。
示例
>>> from sympy.combinatorics import Subset
>>> superset = [1, 3, 2, 5, 4]
>>> Subset.subset_indices([3, 2, 1], superset)
[1, 2, 0]
>>> Subset.subset_indices([1, 6], superset)
[]
>>> Subset.subset_indices([], superset)
[]
property superset
获取子集的超集。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.superset
['a', 'b', 'c', 'd']
另请参阅
子集, 大小, 超集大小, 基数
property superset_size
返回超集的大小。
示例
>>> from sympy.combinatorics import Subset
>>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
>>> a.superset_size
4
另请参阅
subset, superset, size, cardinality
classmethod unrank_binary(rank, superset)
获取指定等级的二进制排序子集。
示例
>>> from sympy.combinatorics import Subset
>>> Subset.unrank_binary(4, ['a', 'b', 'c', 'd']).subset
['b']
另请参阅
iterate_binary, rank_binary
classmethod unrank_gray(rank, superset)
获取指定等级的格雷码排序子集。
示例
>>> from sympy.combinatorics import Subset
>>> Subset.unrank_gray(4, ['a', 'b', 'c']).subset
['a', 'b']
>>> Subset.unrank_gray(0, ['a', 'b', 'c']).subset
[]
另请参阅
iterate_graycode, rank_gray
subsets.ksubsets(k)
按字典顺序找到大小为k的子集。
这使用了 itertools 生成器。
示例
>>> from sympy.combinatorics.subsets import ksubsets
>>> list(ksubsets([1, 2, 3], 2))
[(1, 2), (1, 3), (2, 3)]
>>> list(ksubsets([1, 2, 3, 4, 5], 2))
[(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]
另请参阅
Subset
Gray 码
原文:
docs.sympy.org/latest/modules/combinatorics/graycode.html
class sympy.combinatorics.graycode.GrayCode(n, *args, **kw_args)
Gray 码本质上是 n 维立方体上的哈密顿路径,边长为 1。立方体的顶点由其值为二进制的向量表示。哈密顿路径访问每个顶点恰好一次。3D 立方体的 Gray 码是['000','100','110','010','011','111','101','001']。
Gray 码解决了顺序生成 n 个对象所有可能子集的问题,每个子集从前一个子集仅通过删除或添加一个对象获得。在上述示例中,1 表示对象存在,0 表示对象不存在。
Gray 码在统计学中也有应用,特别是当我们希望以高效的方式计算与子集相关的各种统计量时。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3)
>>> list(a.generate_gray())
['000', '001', '011', '010', '110', '111', '101', '100']
>>> a = GrayCode(4)
>>> list(a.generate_gray())
['0000', '0001', '0011', '0010', '0110', '0111', '0101', '0100', '1100', '1101', '1111', '1110', '1010', '1011', '1001', '1000']
参考文献
[R44]
Nijenhuis,A. 和 Wilf,H.S.(1978). 组合算法. Academic Press.
[R45]
Knuth, D. (2011). 计算机程序设计艺术,第 4 卷 Addison Wesley
property current
返回当前引用的 Gray 码作为比特字符串。
示例
>>> from sympy.combinatorics import GrayCode
>>> GrayCode(3, start='100').current
'100'
generate_gray(**hints)
生成 Gray 码的比特向量序列。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3)
>>> list(a.generate_gray())
['000', '001', '011', '010', '110', '111', '101', '100']
>>> list(a.generate_gray(start='011'))
['011', '010', '110', '111', '101', '100']
>>> list(a.generate_gray(rank=4))
['110', '111', '101', '100']
参见
skip
参考文献
[R46]
Knuth, D. (2011). 计算机程序设计艺术,第 4 卷, Addison Wesley
property n
返回 Gray 码的维度。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(5)
>>> a.n
5
next(delta=1)
返回 Gray 码从当前值开始的距离delta(默认= 1)的 Gray 码。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3, start='110')
>>> a.next().current
'111'
>>> a.next(-1).current
'010'
property rank
对 Gray 码进行排序。
排名算法确定在给定顺序下,组合对象在所有对象中的位置(或排名)。例如,4 位二进制反射 Gray 码(BRGC)'0101'的排名为 6,因为它在 4 位 Gray 码家族的规范顺序中出现在第 6 个位置。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3)
>>> list(a.generate_gray())
['000', '001', '011', '010', '110', '111', '101', '100']
>>> GrayCode(3, start='100').rank
7
>>> GrayCode(3, rank=7).current
'100'
参见
unrank
参考文献
[R47]
web.archive.org/web/20200224064753/http://statweb.stanford.edu/~susan/courses/s208/node12.html
property selections
返回 Gray 码中的比特向量数。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3)
>>> a.selections
8
skip()
跳过比特生成。
示例
>>> from sympy.combinatorics import GrayCode
>>> a = GrayCode(3)
>>> for i in a.generate_gray():
... if i == '010':
... a.skip()
... print(i)
...
000
001
011
010
111
101
100
参见
generate_gray
classmethod unrank(n, rank)
反排 n 位大小的 Gray 码的排名 k。此方法存在,以便派生 GrayCode 类可以定义其给定排名的自己的代码。
这里生成的字符串是为了允许尾递归优化。
示例
>>> from sympy.combinatorics import GrayCode
>>> GrayCode(5, rank=3).current
'00010'
>>> GrayCode.unrank(5, 3)
'00010'
参见
rank
graycode.random_bitstring()
生成长度为 n 的随机比特列表。
示例
>>> from sympy.combinatorics.graycode import random_bitstring
>>> random_bitstring(3)
100
graycode.gray_to_bin()
从 Gray 编码转换为二进制编码。
我们假设使用大端编码。
示例
>>> from sympy.combinatorics.graycode import gray_to_bin
>>> gray_to_bin('100')
'111'
参见
bin_to_gray
graycode.bin_to_gray()
将二进制编码转换为格雷编码。
我们假设使用大端编码。
示例
>>> from sympy.combinatorics.graycode import bin_to_gray
>>> bin_to_gray('111')
'100'
另请参见
gray_to_bin
graycode.get_subset_from_bitstring(bitstring)
获取由比特字符串定义的子集。
示例
>>> from sympy.combinatorics.graycode import get_subset_from_bitstring
>>> get_subset_from_bitstring(['a', 'b', 'c', 'd'], '0011')
['c', 'd']
>>> get_subset_from_bitstring(['c', 'a', 'c', 'c'], '1100')
['c', 'a']
另请参见
graycode_subsets
graycode.graycode_subsets()
生成由格雷码枚举的子集。
示例
>>> from sympy.combinatorics.graycode import graycode_subsets
>>> list(graycode_subsets(['a', 'b', 'c']))
[[], ['c'], ['b', 'c'], ['b'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'c'], ['a']]
>>> list(graycode_subsets(['a', 'b', 'c', 'c']))
[[], ['c'], ['c', 'c'], ['c'], ['b', 'c'], ['b', 'c', 'c'], ['b', 'c'], ['b'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'b', 'c', 'c'], ['a', 'b', 'c'], ['a', 'c'], ['a', 'c', 'c'], ['a', 'c'], ['a']]
另请参见
get_subset_from_bitstring
命名的群
原文:
docs.sympy.org/latest/modules/combinatorics/named_groups.html
sympy.combinatorics.named_groups.SymmetricGroup(n)
生成 n 元素的对称群作为一个置换群。
解释
采取的生成器是 n-循环 (0 1 2 ... n-1) 和换位 (0 1)(在循环表示中)。 (见 [1])。生成群之后,设置了一些其基本属性。
例子
>>> from sympy.combinatorics.named_groups import SymmetricGroup
>>> G = SymmetricGroup(4)
>>> G.is_group
True
>>> G.order()
24
>>> list(G.generate_schreier_sims(af=True))
[[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1], [3, 1, 2, 0], [0, 2, 3, 1],
[1, 3, 0, 2], [2, 0, 1, 3], [3, 2, 0, 1], [0, 3, 1, 2], [1, 0, 2, 3],
[2, 1, 3, 0], [3, 0, 1, 2], [0, 1, 3, 2], [1, 2, 0, 3], [2, 3, 1, 0],
[3, 1, 0, 2], [0, 2, 1, 3], [1, 3, 2, 0], [2, 0, 3, 1], [3, 2, 1, 0],
[0, 3, 2, 1], [1, 0, 3, 2], [2, 1, 0, 3], [3, 0, 2, 1]]
参见
CyclicGroup, DihedralGroup, AlternatingGroup
参考文献
[R57]
en.wikipedia.org/wiki/Symmetric_group#Generators_and_relations
sympy.combinatorics.named_groups.CyclicGroup(n)
生成 n 阶循环群作为一个置换群。
解释
采取的生成器是 n-循环 (0 1 2 ... n-1)(在循环表示中)。生成群之后,设置了一些其基本属性。
例子
>>> from sympy.combinatorics.named_groups import CyclicGroup
>>> G = CyclicGroup(6)
>>> G.is_group
True
>>> G.order()
6
>>> list(G.generate_schreier_sims(af=True))
[[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 0], [2, 3, 4, 5, 0, 1],
[3, 4, 5, 0, 1, 2], [4, 5, 0, 1, 2, 3], [5, 0, 1, 2, 3, 4]]
参见
SymmetricGroup, DihedralGroup, AlternatingGroup
sympy.combinatorics.named_groups.DihedralGroup(n)
生成二面角群 (D_n) 作为一个置换群。
解释
二面角群 (D_n) 是正规 n-边形的对称群。采取的生成器是 n-循环 a = (0 1 2 ... n-1)(n-边形的旋转)和 b = (0 n-1)(1 n-2)...(n-边形的反射)在循环旋转中。很容易看出它们满足 a**n = b**2 = 1 和 bab = ~a,因此它们确实生成了 (D_n)(见 [1])。生成群之后,设置了一些其基本属性。
例子
>>> from sympy.combinatorics.named_groups import DihedralGroup
>>> G = DihedralGroup(5)
>>> G.is_group
True
>>> a = list(G.generate_dimino())
>>> [perm.cyclic_form for perm in a]
[[], [[0, 1, 2, 3, 4]], [[0, 2, 4, 1, 3]],
[[0, 3, 1, 4, 2]], [[0, 4, 3, 2, 1]], [[0, 4], [1, 3]],
[[1, 4], [2, 3]], [[0, 1], [2, 4]], [[0, 2], [3, 4]],
[[0, 3], [1, 2]]]
参见
SymmetricGroup, CyclicGroup, AlternatingGroup
参考文献
[R58]
en.wikipedia.org/wiki/Dihedral_group
sympy.combinatorics.named_groups.AlternatingGroup(n)
生成 n 元素的交错群作为一个置换群。
解释
对于 n > 2,采取的生成器是 (0 1 2), (0 1 2 ... n-1) 对于奇数 n 和 (0 1 2), (1 2 ... n-1) 对于偶数 n(见 [1], p.31, ex.6.9.)。生成群之后,设置了一些其基本属性。处理了 n = 1, 2 的情况。
例子
>>> from sympy.combinatorics.named_groups import AlternatingGroup
>>> G = AlternatingGroup(4)
>>> G.is_group
True
>>> a = list(G.generate_dimino())
>>> len(a)
12
>>> all(perm.is_even for perm in a)
True
参见
SymmetricGroup, CyclicGroup, DihedralGroup
参考文献
[R59]
Armstrong, M. “Groups and Symmetry”
sympy.combinatorics.named_groups.AbelianGroup(*cyclic_orders)
返回具有给定阶数的循环群的直积。
解释
根据有限阿贝尔群的结构定理([1]),每个有限阿贝尔群都可以写成有限多个循环群的直积。
例子
>>> from sympy.combinatorics.named_groups import AbelianGroup
>>> AbelianGroup(3, 4)
PermutationGroup([
(6)(0 1 2),
(3 4 5 6)])
>>> _.is_group
True
另见
DirectProduct
参考文献
[R60]
groupprops.subwiki.org/wiki/Structure_theorem_for_finitely_generated_abelian_groups
Galois 群
构造对称群的可迁子群,在 Galois 理论中很有用。
除了构造PermutationGroup类的实例以表示小(n)的(S_n)的可迁子群外,此模块还为这些群提供名称。
在某些应用中,知道群的名称可能比接收PermutationGroup类的实例并额外工作来确定群更可取。
名称是此模块中定义的Enum类的实例。有了名称,可以使用名称的get_perm_group方法检索PermutationGroup。
此模块中用于群的名称取自[1]。
参考文献
[R41]
Cohen, H. 计算代数数论课程.
class sympy.combinatorics.galois.S6TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S6 的可迁子群的名称。
class sympy.combinatorics.galois.S5TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S5 的可迁子群的名称。
class sympy.combinatorics.galois.S4TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S4 的可迁子群的名称。
class sympy.combinatorics.galois.S3TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S3 的可迁子群的名称。
class sympy.combinatorics.galois.S2TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S2 的可迁子群的名称。
class sympy.combinatorics.galois.S1TransitiveSubgroups(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
S1 的可迁子群的名称。
sympy.combinatorics.galois.four_group()
返回 Klein 四群作为 S4 的可迁子群的表示。
sympy.combinatorics.galois.M20()
返回 M20 的元循环群的表示,这是 S5 的可迁子群,也是 5 次多项式的可能 Galois 群之一。
笔记
见[1],第 323 页。
sympy.combinatorics.galois.S3_in_S6()
返回 S3 作为 S6 的可迁子群的表示。
笔记
通过将群视为三角柱的对称性来找到表示。
sympy.combinatorics.galois.A4_in_S6()
返回 A4 作为 S6 的可迁子群的表示。
笔记
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.S4m()
返回 S4-作为 S6 的可迁子群的表示。
笔记
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.S4p()
返回 S4+作为 S6 的可迁子群的表示。
笔记
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.A4xC2()
返回(A4 x C2)作为 S6 的可迁子群的表示。
笔记
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.S4xC2()
返回(\boldsymbol{(S4 \times C2)})的表示,作为 S6 的一个传递子群。
注释
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.G18()
返回 G18 群的表示,这是 S6 的一个传递子群,同构于 C3² 与 C2 的半直积。
注释
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.G36m()
返回 G36-群的表示,这是 S6 的一个传递子群,同构于 C3² 与 C2² 的半直积。
注释
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.G36p()
返回 G36+群的表示,这是 S6 的一个传递子群,同构于 C3² 与 C4 的半直积。
注释
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.G72()
返回 G72 群的表示,这是 S6 的一个传递子群,同构于 C3² 与 D4 的半直积。
注释
见[1],第 325 页。
sympy.combinatorics.galois.PSL2F5()
返回(\boldsymbol{PSL_2(\mathbb{F}_5)})群的表示,作为 S6 的一个传递子群,同构于(\boldsymbol{A_5})。
注释
这是使用find_transitive_subgroups_of_S6()计算得出的。
sympy.combinatorics.galois.PGL2F5()
返回(\boldsymbol{PGL_2(\mathbb{F}_5)})群的表示,作为 S6 的一个传递子群,同构于(\boldsymbol{S_5})。
注释
见[1],第 325 页。
sympy.combinatorics.galois.find_transitive_subgroups_of_S6(*targets, print_report=False)
搜索(\boldsymbol{S_6})的某些传递子群。
对称群(\boldsymbol{S_6})有 16 个不同的传递子群,直到共轭。有些比其他的更容易构造。例如,二面角群(\boldsymbol{D_6})可以立即找到,但如何在(\boldsymbol{S_6})内实现(\boldsymbol{S_4})或(\boldsymbol{S_5})的传递性则一点也不明显。
在某些情况下,有可以使用的众所周知的构造。例如,(\boldsymbol{S_5})同构于(\boldsymbol{PGL_2(\mathbb{F}_5)}),它在射影线(\boldsymbol{P¹(\mathbb{F}_5)})上的自然作用,一个包含 6 个元素的集合。
在缺少这样的特殊构造的情况下,我们可以简单地搜索生成元。例如,可以通过这种方式在(\boldsymbol{S_6})内找到(\boldsymbol{A_4})和(\boldsymbol{S_4})的传递实例。
一旦我们进行这样的搜索,然后通过简单的搜索,甚至可以更容易(虽然不太优雅地)找到像(\boldsymbol{S_5})这样的群,这些群确实具有特殊的构造。
此函数定位 S6 中以下传递子群的生成元:
-
(\boldsymbol{A_4})
-
(\boldsymbol{S_4^-})((\boldsymbol{S_4})不包含在(\boldsymbol{A_6})中)
-
(\boldsymbol{S_4^+})((\boldsymbol{S_4})包含在(\boldsymbol{A_6})中)
-
(\boldsymbol{A_4 \times C_2})
-
(\boldsymbol{S_4 \times C_2})
-
(\boldsymbol{G_{18} = C_3² \rtimes C_2})
-
(G_{36}^- = C_3² \rtimes C_2²)
-
(G_{36}^+ = C_3² \rtimes C_4)
-
(G_{72} = C_3² \rtimes D_4)
-
(A_5)
-
(S_5)
注意:这些组的每一个在该模块中还有一个专用函数,可以立即返回使用此搜索过程找到的生成器的组。
搜索过程记录了这些生成器是如何找到的。此外,由于置换群元素生成的随机性,可以再次调用它,以便(可能)获得同一组的不同生成器。
参数:
targets : S6TransitiveSubgroups 值的列表
您想要查找的组。
print_report : 布尔值(默认为 False)
如果为 True,则打印每个组找到的生成器到标准输出。
返回:
字典
将targets中的每个名称映射到找到的
PermutationGroup。
参考文献
[R43]
zh.wikipedia.org/wiki/射影线性群#特殊同构
[R44]
zh.wikipedia.org/wiki/对称群和交错群的自同构#PGL%282,5%29
群组数量
原文:
docs.sympy.org/latest/modules/combinatorics/group_numbers.html
sympy.combinatorics.group_numbers.is_nilpotent_number(n) → bool
检查 (n) 是否为幂零数。如果一个数 (n) 的任意有限阶群都是幂零群,则称其为幂零数。详细信息参见[R48]。
示例
>>> from sympy.combinatorics.group_numbers import is_nilpotent_number
>>> from sympy import randprime
>>> is_nilpotent_number(21)
False
>>> is_nilpotent_number(randprime(1, 30)**12)
True
参考文献
[R48] (1,2)
Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634.
[R49]
sympy.combinatorics.group_numbers.is_abelian_number(n) → bool
检查 (n) 是否为阿贝尔数。如果一个数 (n) 的任意有限阶群都是阿贝尔群,则称其为阿贝尔数。详细信息参见[R50]。
示例
>>> from sympy.combinatorics.group_numbers import is_abelian_number
>>> from sympy import randprime
>>> is_abelian_number(4)
True
>>> is_abelian_number(randprime(1, 2000)**2)
True
>>> is_abelian_number(60)
False
参考文献
[R50] (1,2)
Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634.
[R51]
sympy.combinatorics.group_numbers.is_cyclic_number(n) → bool
检查 (n) 是否为循环数。如果一个数 (n) 的任意有限阶群都是循环群,则称其为循环数。详细信息参见[R52]。
示例
>>> from sympy.combinatorics.group_numbers import is_cyclic_number
>>> from sympy import randprime
>>> is_cyclic_number(15)
True
>>> is_cyclic_number(randprime(1, 2000)**2)
False
>>> is_cyclic_number(4)
False
参考文献
[R52] (1,2)
Pakianathan, J., Shankar, K., Nilpotent Numbers, The American Mathematical Monthly, 107(7), 631-634.
[R53]
sympy.combinatorics.group_numbers.groups_count(n)
数量为 (n) 的群组。在[R54]中,给出了 gnu(n),因此我们在这里也采用这种符号。
参数:
n : 整数
n是正整数
返回:
整数 : gnu(n)
引发:
数值错误
数量为
n的群组尚不明确或未实现。例如,gnu((2^{11})) 尚不为人知。另一方面,gnu(12) 已知为 5,但在此函数中尚未实现。
示例
>>> from sympy.combinatorics.group_numbers import groups_count
>>> groups_count(3) # There is only one cyclic group of order 3
1
>>> # There are two groups of order 10: the cyclic group and the dihedral group
>>> groups_count(10)
2
另请参阅
is_cyclic_number
(n) 是循环数当且仅当 gnu(n) = 1
参考文献
[R54] (1,2)
John H. Conway, Heiko Dietrich 和 E.A. O’Brien, Counting groups: gnus, moas and other exotica The Mathematical Intelligencer 30, 6-15 (2008) doi.org/10.1007/BF02985731
[R55]
Utilities
sympy.combinatorics.util._base_ordering(base, degree)
Order ({0, 1, \dots, n-1}) so that base points come first and in order.
Parameters:
base : the base
degree : the degree of the associated permutation group
Returns:
A list base_ordering such that base_ordering[point] is the
number of point in the ordering.
Examples
>>> from sympy.combinatorics import SymmetricGroup
>>> from sympy.combinatorics.util import _base_ordering
>>> S = SymmetricGroup(4)
>>> S.schreier_sims()
>>> _base_ordering(S.base, S.degree)
[0, 1, 2, 3]
Notes
This is used in backtrack searches, when we define a relation (\ll) on the underlying set for a permutation group of degree (n), ({0, 1, \dots, n-1}), so that if ((b_1, b_2, \dots, b_k)) is a base we have (b_i \ll b_j) whenever (i<j) and (b_i \ll a) for all (i\in{1,2, \dots, k}) and (a) is not in the base. The idea is developed and applied to backtracking algorithms in [1], pp.108-132. The points that are not in the base are taken in increasing order.
References
[R95]
Holt, D., Eick, B., O’Brien, E. “Handbook of computational group theory”
sympy.combinatorics.util._check_cycles_alt_sym(perm)
Checks for cycles of prime length p with n/2 < p < n-2.
Explanation
Here (n) is the degree of the permutation. This is a helper function for the function is_alt_sym from sympy.combinatorics.perm_groups.
Examples
>>> from sympy.combinatorics.util import _check_cycles_alt_sym
>>> from sympy.combinatorics import Permutation
>>> a = Permutation([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12]])
>>> _check_cycles_alt_sym(a)
False
>>> b = Permutation([[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10]])
>>> _check_cycles_alt_sym(b)
True
See also
sympy.combinatorics.perm_groups.PermutationGroup.is_alt_sym
sympy.combinatorics.util._distribute_gens_by_base(base, gens)
Distribute the group elements gens by membership in basic stabilizers.
Parameters:
base : a sequence of points in ({0, 1, \dots, n-1})
gens : a list of elements of a permutation group of degree (n).
Returns:
list
List of length (k), where (k) is the length of base. The (i)-th entry contains those elements in gens which fix the first (i) elements of base (so that the (0)-th entry is equal to gens itself). If no element fixes the first (i) elements of base, the (i)-th element is set to a list containing the identity element.
Explanation
Notice that for a base ((b_1, b_2, \dots, b_k)), the basic stabilizers are defined as (G^{(i)} = G_{b_1, \dots, b_{i-1}}) for (i \in{1, 2, \dots, k}).
Examples
>>> from sympy.combinatorics.named_groups import DihedralGroup
>>> from sympy.combinatorics.util import _distribute_gens_by_base
>>> D = DihedralGroup(3)
>>> D.schreier_sims()
>>> D.strong_gens
[(0 1 2), (0 2), (1 2)]
>>> D.base
[0, 1]
>>> _distribute_gens_by_base(D.base, D.strong_gens)
[[(0 1 2), (0 2), (1 2)],
[(1 2)]]
See also
_strong_gens_from_distr, _orbits_transversals_from_bsgs, _handle_precomputed_bsgs
sympy.combinatorics.util._handle_precomputed_bsgs(base, strong_gens, transversals=None, basic_orbits=None, strong_gens_distr=None)
Calculate BSGS-related structures from those present.
Parameters:
base : the base
strong_gens : the strong generators
transversals : basic transversals
basic_orbits : basic orbits
strong_gens_distr : strong generators distributed by membership in basic stabilizers
Returns:
(transversals, basic_orbits, strong_gens_distr)
其中横截面是基本横截面,基本轨道是基本轨道,strong_gens_distr是按基本稳定器成员分布的强生成器。
说明
必须提供基础和强生成集;如果未提供任何横截面、基本轨道或分布的强生成器,则会从基础和强生成集计算它们。
示例
>>> from sympy.combinatorics.named_groups import DihedralGroup
>>> from sympy.combinatorics.util import _handle_precomputed_bsgs
>>> D = DihedralGroup(3)
>>> D.schreier_sims()
>>> _handle_precomputed_bsgs(D.base, D.strong_gens,
... basic_orbits=D.basic_orbits)
([{0: (2), 1: (0 1 2), 2: (0 2)}, {1: (2), 2: (1 2)}], [[0, 1, 2], [1, 2]], [[(0 1 2), (0 2), (1 2)], [(1 2)]])
另见
_orbits_transversals_from_bsgs,_distribute_gens_by_base
sympy.combinatorics.util._orbits_transversals_from_bsgs(base, strong_gens_distr, transversals_only=False, slp=False)
从基础和强生成集计算基本轨道和横截面。
参数:
基础 : 基础。
strong_gens_distr : 按基本稳定器成员分布的强生成器。
transversals_only : 布尔值,默认值:False
一个标志,在仅返回横截面和返回轨道与横截面两者之间切换。
slp : 布尔值,默认值:False
如果
True,返回包含生成器展示的元素的字典列表,即横截面元素的生成器索引列表,从strong_gens_distr[i]中获取这些生成器的乘积即为相关横截面元素。
说明
生成器按基本稳定器的成员分布提供。如果将可选参数transversals_only设置为 True,则仅返回横截面。
示例
>>> from sympy.combinatorics import SymmetricGroup
>>> from sympy.combinatorics.util import _distribute_gens_by_base
>>> S = SymmetricGroup(3)
>>> S.schreier_sims()
>>> strong_gens_distr = _distribute_gens_by_base(S.base, S.strong_gens)
>>> (S.base, strong_gens_distr)
([0, 1], [[(0 1 2), (2)(0 1), (1 2)], [(1 2)]])
另见
_distribute_gens_by_base,_handle_precomputed_bsgs
sympy.combinatorics.util._remove_gens(base, strong_gens, basic_orbits=None, strong_gens_distr=None)
从强生成集中删除冗余生成器。
参数:
base : 基础
strong_gens : 相对于base的强生成集
basic_orbits : 基本轨道
strong_gens_distr : 按基本稳定器成员分布的强生成器
返回:
关于基础base的强生成集,这是一个子集。
strong_gens。
示例
>>> from sympy.combinatorics import SymmetricGroup
>>> from sympy.combinatorics.util import _remove_gens
>>> from sympy.combinatorics.testutil import _verify_bsgs
>>> S = SymmetricGroup(15)
>>> base, strong_gens = S.schreier_sims_incremental()
>>> new_gens = _remove_gens(base, strong_gens)
>>> len(new_gens)
14
>>> _verify_bsgs(S, base, new_gens)
True
注意
此过程详见[1],p.95。
参考文献
[R96]
Holt, D., Eick, B., O’Brien, E. “计算群论手册”
sympy.combinatorics.util._strip(g, base, orbits, transversals)
尝试使用(可能是部分的)BSGS 结构分解置换。
参数:
g : 要分解的置换
base : 点序列
orbits : 列表
列表中的第
i个条目是在\(base[0], base[1], ..., base[i - 1])的点稳定器的某个子群下base[i]`的轨道。由于我们只需要轨道和横截面的信息,这些群本身在此函数中是隐含的。
横截面 : 列表
与轨道orbits相关的轨道横截面列表。
说明
这是通过将序列 base 视为实际的基础,将轨道 orbits 和横穿 transversals 视为相对其的基本轨道和横穿来完成的。
这个过程被称为“筛选”。当某个轨道元素未找到或者在筛选后分解结果不以单位元结束时,筛选失败。
参数 transversals 是一个字典列表,提供了轨道 orbits 的横穿元素。
示例
>>> from sympy.combinatorics import Permutation, SymmetricGroup
>>> from sympy.combinatorics.util import _strip
>>> S = SymmetricGroup(5)
>>> S.schreier_sims()
>>> g = Permutation([0, 2, 3, 1, 4])
>>> _strip(g, S.base, S.basic_orbits, S.basic_transversals)
((4), 5)
注意
该算法在 [1],pp.89-90 中描述。为什么返回正在分解的元素的当前状态以及筛选结束的级别是因为它们为随机版本的 Schreier-Sims 算法提供了重要信息。
参见
sympy.combinatorics.perm_groups.PermutationGroup.schreier_sims, sympy.combinatorics.perm_groups.PermutationGroup.schreier_sims_random
参考文献
[R97]
Holt, D., Eick, B., O’Brien, E.《计算群论手册》
sympy.combinatorics.util._strong_gens_from_distr(strong_gens_distr)
从基本稳定子的生成器中检索强生成集。
这只是第一个和第二基本稳定子生成器的并集。
参数:
strong_gens_distr:按基本稳定子成员分布的强生成器
示例
>>> from sympy.combinatorics import SymmetricGroup
>>> from sympy.combinatorics.util import (_strong_gens_from_distr,
... _distribute_gens_by_base)
>>> S = SymmetricGroup(3)
>>> S.schreier_sims()
>>> S.strong_gens
[(0 1 2), (2)(0 1), (1 2)]
>>> strong_gens_distr = _distribute_gens_by_base(S.base, S.strong_gens)
>>> _strong_gens_from_distr(strong_gens_distr)
[(0 1 2), (2)(0 1), (1 2)]
参见
_distribute_gens_by_base