コード例 #1
0
        def __init__(self, parent, iterable):
            """
            EXAMPLES::

                sage: F = CommutativeAdditiveSemigroups().example()
                sage: x = F.element_class(F, (('a',4), ('b', 0), ('a', 2), ('c', 1), ('d', 5)))
                sage: x
                2*a + c + 5*d
                sage: x.value
                {'a': 2, 'b': 0, 'c': 1, 'd': 5}
                sage: x.parent()
                An example of a commutative monoid: the free commutative monoid generated by ('a', 'b', 'c', 'd')

            Internally, elements are represented as dense dictionaries which
            associate to each generator of the monoid its multiplicity. In
            order to get an element, we wrap the dictionary into an element
            via :class:`ElementWrapper`::

                sage: x.value
                {'a': 2, 'b': 0, 'c': 1, 'd': 5}
            """
            d = dict((a, 0) for a in parent.alphabet)
            for (a, c) in iterable:
                d[a] = c
            ElementWrapper.__init__(self, parent, d)
コード例 #2
0
        def __init__(self, parent, iterable):
            """
            EXAMPLES::

                sage: F = CommutativeAdditiveSemigroups().example()
                sage: x = F.element_class(F, (('a',4), ('b', 0), ('a', 2), ('c', 1), ('d', 5)))
                sage: x
                2*a + c + 5*d
                sage: x.value
                {'a': 2, 'b': 0, 'c': 1, 'd': 5}
                sage: x.parent()
                An example of a commutative monoid: the free commutative monoid generated by ('a', 'b', 'c', 'd')

            Internally, elements are represented as dense dictionaries which
            associate to each generator of the monoid its multiplicity. In
            order to get an element, we wrap the dictionary into an element
            via :class:`ElementWrapper`::

                sage: x.value
                {'a': 2, 'b': 0, 'c': 1, 'd': 5}
            """
            d = dict( (a,0) for a in parent.alphabet )
            for (a, c) in iterable:
                d[a] = c
            ElementWrapper.__init__(self, parent, d)
コード例 #3
0
ファイル: cluster_algebra.py プロジェクト: Etn40ff/level_zero
    def __init__(self, parent, value):
        ElementWrapper.__init__(self, parent=parent, value=value)

        # setup methods defined only in special cases
        if parent._is_principal:
            self.g_vector = MethodType(g_vector, self, self.__class__)
            self.is_homogeneous = MethodType(is_homogeneous, self, self.__class__)
            self.homogeneous_components = MethodType(homogeneous_components, self, self.__class__)
コード例 #4
0
ファイル: cluster_algebra.py プロジェクト: Etn40ff/level_zero
    def __init__(self, parent, value):
        ElementWrapper.__init__(self, parent=parent, value=value)

        # setup methods defined only in special cases
        if parent._is_principal:
            self.g_vector = MethodType(g_vector, self, self.__class__)
            self.is_homogeneous = MethodType(is_homogeneous, self,
                                             self.__class__)
            self.homogeneous_components = MethodType(homogeneous_components,
                                                     self, self.__class__)
コード例 #5
0
        def __init__(self, parent, x):
            """
            TESTS::

                sage: W = CoxeterGroup(['A', 3], implementation='coxeter3')    # optional - coxeter3
                sage: W([2,1,2])                                               # optional - coxeter3
                [1, 2, 1]
            """
            if not isinstance(x, CoxGroupElement):
                x = CoxGroupElement(parent._coxgroup, x).reduced()
            ElementWrapper.__init__(self, parent, x)
コード例 #6
0
        def __init__(self, ambient_element, parent):
            """
            TESTS::

                sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
                sage: R = IntegerModRing(21)
                sage: M = AutomaticSemigroup(Family([2]))
                sage: m = M(2); m
                2
                sage: type(m)
                <class 'sage.monoids.automatic_semigroup.AutomaticSemigroup_with_category.element_class'>
            """
            ElementWrapper.__init__(self, ambient_element, parent)
            self._reduced_word = None
コード例 #7
0
ファイル: automatic_semigroup.py プロジェクト: novoselt/sage
        def __init__(self, ambient_element, parent):
            """
            TESTS::

                sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
                sage: R = IntegerModRing(21)
                sage: M = AutomaticSemigroup(Family([2]))
                sage: m = M(2); m
                2
                sage: type(m)
                <class 'sage.monoids.automatic_semigroup.AutomaticSemigroup_with_category.element_class'>
            """
            ElementWrapper.__init__(self, ambient_element, parent)
            self._reduced_word = None
コード例 #8
0
ファイル: multisegments.py プロジェクト: sagemath/sage
        def __init__(self, parent, value):
            """
            Initialize ``self``.

            EXAMPLES::

                sage: B = crystals.infinity.Multisegments(2)
                sage: mg = B.highest_weight_vector()
                sage: TestSuite(mg).run()
            """
            def sort_key(x):
                return (-x[0], ZZ(x[1]))
            ZM = parent._Zn
            value = [(k, ZM(i)) for k,i in value]
            ElementWrapper.__init__(self, parent, tuple(sorted(value, key=sort_key)))
コード例 #9
0
ファイル: group_exp.py プロジェクト: BrentBaccala/sage
    def __init__(self, parent, x):
        r"""
        EXAMPLES::

            sage: G = QQ^2
            sage: EG = GroupExp()(G)
            sage: x = EG.an_element(); x
            (1, 0)
            sage: TestSuite(x).run(skip = "_test_category")

        See the documentation of :meth:`sage.structure.element_wrapper.ElementWrapper.__init__`
        for the reason behind skipping the category test.
        """
        if x not in parent._G:
            raise ValueError("%s is not an element of %s" % (x, parent._G))
        ElementWrapper.__init__(self, parent, x)
コード例 #10
0
    def __init__(self, parent, value, check=True):
        """
        TESTS::

            sage: from sage.structure.set_factories_example import XYPairs
            sage: P = XYPairs(); p = P.list()[0]
            sage: TestSuite(p).run()
        """
        if check:
            if not isinstance(value, tuple):
                raise ValueError("Value {} must be a tuple".format(value))
            if len(value) != 2:
                raise ValueError("Value must be of length 2")
            if not all(int(x) in range(MAX) for x in value):
                raise ValueError("numbers must be in range({})".format(MAX))
        ElementWrapper.__init__(self, parent, value)
コード例 #11
0
    def __init__(self, parent, value, check=True):
        """
        TESTS::

            sage: from sage.structure.set_factories_example import XYPairs
            sage: P = XYPairs(); p = P.list()[0]
            sage: TestSuite(p).run()
        """
        if check:
            if not isinstance(value, tuple):
                raise ValueError("Value {} must be a tuple".format(value))
            if len(value) != 2:
                raise ValueError("Value must be of length 2")
            if not all(int(x) in range(MAX) for x in value):
                raise ValueError("numbers must be in range({})".format(MAX))
        ElementWrapper.__init__(self, parent, value)
コード例 #12
0
ファイル: group_exp.py プロジェクト: sagemath/sage
    def __init__(self, parent, x):
        r"""
        EXAMPLES::

            sage: G = QQ^2
            sage: EG = GroupExp()(G)
            sage: x = EG.an_element(); x
            (1, 0)
            sage: TestSuite(x).run(skip = "_test_category")

        See the documentation of :meth:`sage.structure.element_wrapper.ElementWrapper.__init__`
        for the reason behind skipping the category test.
        """
        if x not in parent._G:
            raise ValueError("%s is not an element of %s" % (x, parent._G))
        ElementWrapper.__init__(self, parent, x)
コード例 #13
0
ファイル: multisegments.py プロジェクト: shalec/sage
        def __init__(self, parent, value):
            """
            Initialize ``self``.

            EXAMPLES::

                sage: B = crystals.infinity.Multisegments(2)
                sage: mg = B.highest_weight_vector()
                sage: TestSuite(mg).run()
            """
            def sort_key(x):
                return (-x[0], ZZ(x[1]))

            ZM = parent._Zn
            value = [(k, ZM(i)) for k, i in value]
            ElementWrapper.__init__(self, parent,
                                    tuple(sorted(value, key=sort_key)))
コード例 #14
0
        def __init__(self, parent, x):
            """
            TESTS::

                sage: W = CoxeterGroup(['A', 3], implementation='coxeter3')    # optional - coxeter3
                sage: W([2,1,2])                                               # optional - coxeter3
                [1, 2, 1]

            Check that :trac:`32266` is fixed::

                sage: A3 = CoxeterGroup('A3', implementation='coxeter3')       # optional - coxeter3
                sage: s1,s2,s3 = A3.simple_reflections()                       # optional - coxeter3
                sage: s1*s3                                                    # optional - coxeter3
                [1, 3]
                sage: s3*s1                                                    # optional - coxeter3
                [1, 3]
                sage: s3*s1 == s1*s3                                           # optional - coxeter3
                True
            """
            if not isinstance(x, CoxGroupElement):
                x = CoxGroupElement(parent._coxgroup, x).reduced()
            x = x.normal_form()
            ElementWrapper.__init__(self, parent, x)
コード例 #15
0
ファイル: automatic_semigroup.py プロジェクト: novoselt/sage
        def _repr_(self):
            """
            EXAMPLES::

                sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
                sage: R = IntegerModRing(19)
                sage: M = AutomaticSemigroup(Family({1: R(3), 2: R(5)}), one=R.one())
                sage: a = M.an_element(); a
                3
                sage: b = M.from_reduced_word([1,2,1]); b
                7
                sage: M.repr_element_method("reduced_word")
                sage: a
                [1]
                sage: b
                7
                sage: M.construct(up_to=b)
                sage: b
                [1, 1, 2]
            """
            if self.parent()._repr_element_method == "ambient" or self._reduced_word is None:
                return ElementWrapper._repr_(self)
            return str(self._reduced_word)
コード例 #16
0
ファイル: automatic_semigroup.py プロジェクト: matsen/sage
        def _repr_(self):
            """
            EXAMPLES::

                sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
                sage: R = IntegerModRing(19)
                sage: M = AutomaticSemigroup(Family({1: R(3), 2: R(5)}), one=R.one())
                sage: a = M.an_element(); a
                3
                sage: b = M.from_reduced_word([1,2,1]); b
                7
                sage: M.repr_element_method("reduced_word")
                sage: a
                [1]
                sage: b
                7
                sage: M.construct(up_to=b)
                sage: b
                [1, 1, 2]
            """
            if self.parent()._repr_element_method == "ambient" or self._reduced_word is None:
                return ElementWrapper._repr_(self)
            return str(self._reduced_word)