• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python element.MonoidElement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sage.structure.element.MonoidElement的典型用法代码示例。如果您正苦于以下问题:Python MonoidElement类的具体用法?Python MonoidElement怎么用?Python MonoidElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: __init__

    def __init__(self, F, x, check=True):
        """
        Create the element `x` of the FreeMonoid `F`.

        This should typically be called by a FreeMonoid.
        """
        MonoidElement.__init__(self, F)
        if isinstance(x, (int, long, Integer)):
            if x == 1:
                self._element_list = []
            else:
                raise TypeError("Argument x (= %s) is of the wrong type."%x)
        elif isinstance(x, list):
            if check:
                x2 = []
                for v in x:
                    if not isinstance(v, tuple) and len(v) == 2:
                        raise TypeError("x (= %s) must be a list of 2-tuples or 1."%x)
                    if not (isinstance(v[0], (int,long,Integer)) and \
                            isinstance(v[1], (int,long,Integer))):
                        raise TypeError("x (= %s) must be a list of 2-tuples of integers or 1."%x)
                    if len(x2) > 0 and v[0] == x2[len(x2)-1][0]:
                        x2[len(x2)-1] = (v[0], v[1]+x2[len(x2)-1][1])
                    else:
                        x2.append(v)
                self._element_list = x2
            else:
                self._element_list = list(x)  # make copy, so user can't accidentally change monoid.

        else:
            # TODO: should have some other checks here...
            raise TypeError("Argument x (= %s) is of the wrong type."%x)
开发者ID:Findstat,项目名称:sage,代码行数:32,代码来源:free_monoid_element.py


示例2: __init__

    def __init__(self, F, x):
        """
        Create the element x of the FreeAbelianMonoid F.

        EXAMPLES::

            sage: F = FreeAbelianMonoid(5, 'abcde')
            sage: F
            Free abelian monoid on 5 generators (a, b, c, d, e)
            sage: F(1)
            1
            sage: a, b, c, d, e = F.gens()
            sage: a^2 * b^3 * a^2 * b^4
            a^4*b^7
            sage: F = FreeAbelianMonoid(5, 'abcde')
            sage: a, b, c, d, e = F.gens()
            sage: a in F
            True
            sage: a*b in F
            True
        """
        MonoidElement.__init__(self, F)
        n = F.ngens()
        if isinstance(x, integer_types + (Integer,)) and x == 1:
            self._element_vector = tuple([0]*n)
        elif isinstance(x, (list, tuple)):
            if len(x) != n:
                raise IndexError("argument length (= %s) must be %s"%(len(x), n))
            self._element_vector = tuple(x)
        else:
            raise TypeError("argument x (= %s) is of wrong type"%x)
开发者ID:mcognetta,项目名称:sage,代码行数:31,代码来源:free_abelian_monoid_element.py


示例3: __init__

    def __init__(self, F, x):
        """
        Create the element x of the FreeAbelianMonoid F.

        EXAMPLES::

            sage: F = FreeAbelianMonoid(5, 'abcde')
            sage: F
            Free abelian monoid on 5 generators (a, b, c, d, e)
            sage: F(1)
            1
            sage: a, b, c, d, e = F.gens()
            sage: a^2 * b^3 * a^2 * b^4
            a^4*b^7
            sage: F = FreeAbelianMonoid(5, 'abcde')
            sage: a, b, c, d, e = F.gens()
            sage: a in F
            True
            sage: a*b in F
            True
        """
        MonoidElement.__init__(self, F)
        self.__repr = None
        n = F.ngens()
        if isinstance(x, (int, long, Integer)) and x == 1:
            self.__element_vector = [ 0 for i in range(n) ]
        elif isinstance(x, list):
            if len(x) != n:
                raise IndexError("Argument length (= %s) must be %s."%(len(x), n))
            self.__element_vector = x
        else:
            raise TypeError("Argument x (= %s) is of wrong type."%x)
开发者ID:BlairArchibald,项目名称:sage,代码行数:32,代码来源:free_abelian_monoid_element.py


示例4: __init__

    def __init__(self, ring, gens, coerce=True):
        """
        Initialize this ideal.

        INPUT:

        - ``ring`` -- A ring

        - ``gens`` -- The generators for this ideal

        - ``coerce`` -- (default: ``True``) If ``gens`` needs to be coerced
          into ``ring``.

        EXAMPLES::

            sage: R.<x> = ZZ[]
            sage: R.ideal([4 + 3*x + x^2, 1 + x^2])
            Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring
        """
        self.__ring = ring
        if not isinstance(gens, (list, tuple)):
            gens = [gens]
        if coerce:
            gens = [ring(x) for x in gens]

        gens = tuple(gens)
        if len(gens)==0: gens=(ring.zero(),)
        self.__gens = gens
        MonoidElement.__init__(self, ring.ideal_monoid())
开发者ID:saraedum,项目名称:sage-renamed,代码行数:29,代码来源:ideal.py


示例5: __init__

    def __init__(self, F, X):
        """
        Create an element X of the DualAbelianGroup of F.

        EXAMPLES:
            sage: F = AbelianGroup(3,[7,8,9])
            sage: Fd = DualAbelianGroup(F,names="ABC")
            sage: A,B,C = Fd.gens()
            sage: A*B^-1 in Fd
            True

        """
        MonoidElement.__init__(self, F)
        self.__repr = None
        G = F.group()
        n = G.ngens()
        if isinstance(X, (int, Integer)) and X == 1:
            self.__element_vector = [ 0 for i in range(n) ]
        elif isinstance(X, list):
            if len(X) != n: 
                raise IndexError, \
                      "Argument length (= %s) must be %s."%(len(X), n)
            self.__element_vector = X
        else:
            raise TypeError, "Argument X (= %s) is of wrong type."%X
开发者ID:bgxcpku,项目名称:sagelib,代码行数:25,代码来源:dual_abelian_group_element.py


示例6: __init__

    def __init__(self, parent, mat):
        r"""
        EXAMPLES::

            sage: from sage.modular.pollack_stevens.sigma0 import Sigma0
            sage: s = Sigma0(3)([1,4,3,3]) # indirect doctest
            sage: TestSuite(s).run()
        """
        self._mat = mat
        MonoidElement.__init__(self, parent)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:10,代码来源:sigma0.py


示例7: __init__

 def __init__(self, ring, gens, coerce=True):
     self.__ring = ring
     if not isinstance(gens, (list, tuple)):
         gens = [gens]
     if coerce:
         gens = [ring(x) for x in gens]
         
     gens = tuple(gens)
     if len(gens)==0: gens=(ring.zero_element(),)
     self.__gens = gens
     MonoidElement.__init__(self, ring.ideal_monoid())
开发者ID:dagss,项目名称:sage,代码行数:11,代码来源:ideal.py


示例8: __init__

    def __init__(self, parent, data, check=False):
        r"""
        INPUT:

        - ``parent`` - a free group

        - ``data`` - the data to be used

        - ``check`` - wether to check the consistency of the input is checked
          (default is ``True`` but it is much faster if ``check`` is set to
          ``False``)
        """
        MonoidElement.__init__(self, parent)
        if check:
            self._data = list(data)
            self._check_alphabet()
            self._reduce()
        else:
            assert isinstance(data, list)
            self._data = data
开发者ID:videlec,项目名称:sage-train-track,代码行数:20,代码来源:free_group_word.py


示例9: __init__

    def __init__(self, F, x):
        """
        Create the element ``x`` of an indexed free abelian monoid ``F``.

        EXAMPLES::

            sage: F = FreeAbelianMonoid(index_set=ZZ)
            sage: F.gen(1)
            F[1]
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: x = a^2 * b^3 * a^2 * b^4; x
            F[0]^4*F[1]^7
            sage: TestSuite(x).run()

            sage: F = FreeMonoid(index_set=tuple('abcde'))
            sage: a,b,c,d,e = F.gens()
            sage: a in F
            True
            sage: a*b in F
            True
            sage: TestSuite(a*d^2*e*c*a).run()
        """
        MonoidElement.__init__(self, F)
        self._monomial = x
开发者ID:JoseGuzman,项目名称:sage,代码行数:24,代码来源:indexed_free_monoid.py


示例10: __pow__

    def __pow__(self, n):
        r"""
        Raise this element to the power n.

        EXAMPLE::

            sage: K.<a> = NumberField(x^3 - 3*x + 8)
            sage: C=K.class_group()
            sage: c = C(2, a)
            sage: c^2
            Fractional ideal class (2, a^2 + 2*a - 1)
            sage: c^3
            Trivial principal fractional ideal class
            sage: c^1000
            Fractional ideal class (2, a)
            sage: (c^2)^2
            Fractional ideal class (2, a)
        """
        # We use MonoidElement's __pow__ routine, since that does
        # repeated squaring, and hence the ideal gets reduced as
        # we go along; actually computing self._value ** n would
        # be disastrous.
        n = n % self.order()
        return MonoidElement.__pow__(self, n)
开发者ID:BlairArchibald,项目名称:sage,代码行数:24,代码来源:class_group.py


示例11: __init__

    def __init__(self, parent, path, check=True):
        """
        Creates a path object.  Type ``QuiverPath?`` for more information.

        TESTS::

            sage: from sage.quivers.paths import QuiverPath
            sage: Q = DiGraph({1:{2:['a']}, 2:{3:['b']}}).path_semigroup()
            sage: p = Q([(1, 1), (1, 1)])
            sage: Q([(1,3,'x')])
            Traceback (most recent call last):
            ...
            ValueError: Cannot interpret [(1, 3, 'x')] as element of
            Partial semigroup formed by the directed paths of Multi-digraph on 3 vertices

        Note that QuiverPath should not be called directly, because
        the elements of the path semigroup associated with a quiver
        use a sub-class of QuiverPath. Nonetheless, just for test, we
        show that it *is* possible to create a path in a deprecated way::

            sage: p == QuiverPath(Q, (1, 1))
            True
            sage: Q([(1, 1), (1, 2, 'a'), (2, 2), (2, 3, 'b'), (3, 3)])._path
            ((1, 2, 'a'), (2, 3, 'b'))
        """
        MonoidElement.__init__(self, parent=parent)

        # Normalise the given path, unless it is asserted that the input is
        # fine
        if not check:
            self._path = tuple(path)
            return
        if path == 1:
            # We do not guarantee that there is only one vertex.
            # However, this element certainly exists.
            v = parent.quiver().vertices()[0]
            self._path = ((v,v),)
            return
        E = parent.quiver().edges()
        if isinstance(path, QuiverPath):
            if path.parent() is parent:
                self._path = path._path
                return
            new_path = list(path._path)
        # A tuple is assumed to be an edge, anything else is assumed to be a
        # list of edges
        elif isinstance(path, tuple):
            new_path = [path]
        else:
            new_path = list(path)

        # Check that each edge in the path is valid
        good = True
        for x in new_path:
            if (len(x) < 2 or x[0] not in ZZ or x[1] not in ZZ
                           or len(x) == 2 and x[0] != x[1]
                           or len(x) == 3 and x not in E
                           or len(x) > 3):
                good = False
                break
        if not good:
            raise ValueError("Cannot interpret %s as element of %s"%(path,parent))
        # Delete trivial edges, and clear the path if not valid
        i = 0
        while i + 1 < len(new_path):
            if new_path[i][1] != new_path[i + 1][0]:
                raise ValueError("Cannot interpret %s as element of %s"%(path,parent))
            elif len(new_path[i])!=3:
                del new_path[i]
            else:
                i += 1
        if len(new_path) > 1 and len(new_path[-1])!=3:
            del new_path[-1]
        self._path = tuple(new_path)
开发者ID:BlairArchibald,项目名称:sage,代码行数:74,代码来源:paths.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python element.RingElement类代码示例发布时间:2022-05-27
下一篇:
Python element.ModuleElement类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap