当前位置: 首页>>代码示例>>Python>>正文


Python Graph.is_forest方法代码示例

本文整理汇总了Python中sage.graphs.graph.Graph.is_forest方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.is_forest方法的具体用法?Python Graph.is_forest怎么用?Python Graph.is_forest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.graphs.graph.Graph的用法示例。


在下文中一共展示了Graph.is_forest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _finite_recognition

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import is_forest [as 别名]
    def _finite_recognition(self):
        """
        Return ``True`` if and only if the type is finite.

        This is an auxiliary function used during the initialisation.

        EXAMPLES:

        Some infinite ones::

            sage: F = CoxeterGroups().Finite()
            sage: W = CoxeterGroup([[1,3,2],[3,1,-1],[2,-1,1]])
            sage: W in F  # indirect doctest
            False
            sage: W = CoxeterGroup([[1,-1,-1],[-1,1,-1],[-1,-1,1]])
            sage: W in F  # indirect doctest
            False

        Some finite ones::

            sage: CoxeterGroup(['D',4], base_ring=QQ) in F  # indirect doctest
            True
            sage: CoxeterGroup(['H',4]) in F  # indirect doctest
            True
        """
        # First, we build the Coxeter graph of the group, without the
        # edge labels.
        coxeter_matrix = self._matrix
        n = ZZ(coxeter_matrix.nrows())
        G = Graph([(i, j) for i in range(n) for j in range(i)
                   if coxeter_matrix[i, j] not in [1, 2]])
        # Coxeter graphs of finite Coxeter groups are forests
        if not(G.is_forest()):
            return False
        comps = G.connected_components()
        finite = True
        # The group is finite if and only if for every connected
        # component ``comp`` of its Coxeter graph, the submatrix of
        # the Coxeter matrix corresponding to ``comp`` is one of the
        # type-A,B,D,E,F,H,I matrices (up to permutation). So we
        # shall check this condition on every ``comp``.
        for comp in comps:
            l = len(comp)
            if l == 1:
                # Any `1 \times 1` Coxeter matrix gives a finite group.
                continue  # A1
            elif l == 2:
                # A dihedral group is finite iff there is no `\infty`
                # in its Coxeter matrix.
                c0, c1 = comp
                if coxeter_matrix[c0, c1] > 0:
                    continue  # I2
                return False
            elif l == 3:
                # The `3`-node case. The finite groups to check for
                # here are `A_3`, `B_3` and `H_3`.
                c0, c1, c2 = comp
                s = sorted([coxeter_matrix[c0, c1],
                            coxeter_matrix[c0, c2],
                            coxeter_matrix[c1, c2]])
                if s[1] == 3 and s[2] in [3, 4, 5]:
                    continue  # A3, B3, H3
                return False
            elif l == 4:
                # The `4`-node case. The finite groups to check for
                # here are `A_4`, `B_4`, `D_4`, `F_4` and `H_4`.
                c0, c1, c2, c3 = comp
                u = [coxeter_matrix[c0, c1],
                     coxeter_matrix[c0, c2],
                     coxeter_matrix[c0, c3],
                     coxeter_matrix[c1, c2],
                     coxeter_matrix[c1, c3],
                     coxeter_matrix[c2, c3]]
                s = sorted(u)
                # ``s`` is the list of all off-diagonal entries of
                # the ``comp``-submatrix of the Coxeter matrix,
                # sorted in increasing order.
                if s[3:5] == [3, 3]:
                    if s[5] == 3:
                        continue  # A4, D4
                    if s[5] in [4, 5]:
                        u0 = u[0] + u[1] + u[2]
                        u1 = u[0] + u[3] + u[4]
                        u2 = u[1] + u[3] + u[5]
                        u3 = u[2] + u[4] + u[5]
                        ss = sorted([u0, u1, u2, u3])
                        if ss in [[7, 7, 9, 9], [7, 8, 8, 9],
                                  [7, 8, 9, 10]]:
                            continue  # F4, B4, H4
                return False
            else:
                # The case of `l \geq 5` nodes. The finite
                # groups to check for here are `A_l`, `B_l`, `D_l`,
                # and `E_l` (for `l = 6, 7, 8`).

                # Checking that the Coxeter matrix of the subgroup
                # corresponding to the vertices ``comp`` has all its
                # off-diagonal entries equal to 2, 3 or at most once 4
                found_a_4 = False
                for j in range(l):
#.........这里部分代码省略.........
开发者ID:sensen1,项目名称:sage,代码行数:103,代码来源:coxeter_group.py


注:本文中的sage.graphs.graph.Graph.is_forest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。