コード例 #1
0
ファイル: qsym.py プロジェクト: sajedel/testsage
        def _from_Monomial_on_basis(self, J):
            r"""
            Given a quasi-symmetric monomial function, this method returns the expansion into the dual immaculate basis.

            INPUT:

            - ``J`` -- a composition

            OUTPUT:

            - A quasi-symmetric function in the dual immaculate basis.

            EXAMPLES:

                sage: dI = QuasiSymmetricFunctions(QQ).dI()
                sage: dI._from_Monomial_on_basis(Composition([]))
                dI[]
                sage: dI._from_Monomial_on_basis(Composition([2,1]))
                -dI[1, 1, 1] - dI[1, 2] + dI[2, 1]
                sage: dI._from_Monomial_on_basis(Composition([3,1,2]))
                -dI[1, 1, 1, 1, 1, 1] + dI[1, 1, 1, 1, 2] + dI[1, 1, 1, 3] - dI[1, 1, 4] - dI[1, 2, 1, 1, 1] + dI[1, 2, 3] + dI[2, 1, 1, 1, 1] - dI[2, 1, 1, 2] + dI[2, 2, 1, 1] - dI[2, 2, 2] - dI[3, 1, 1, 1] + dI[3, 1, 2]
            """
            n = J.size()
            C = Compositions()
            C_n = Compositions(n)
            mat = self._matrix_monomial_to_dual_immaculate(n)
            column = C_n.list().index(J)
            return self.sum_of_terms( (C(I), mat[C_n.list().index(I)][column])
                                            for I in C_n)
コード例 #2
0
ファイル: qsym.py プロジェクト: sajedel/testsage
        def _to_Monomial_on_basis(self, J):
            r"""
            Given a dual immaculate function, this method returns the expansion of the function in the quasi-symmetric monomial basis.

            INPUT:

            - ``J`` -- a composition

            OUTPUT:

            - A quasi-symmetric function in the monomial basis.

            EXAMPLES::

            sage: dI = QuasiSymmetricFunctions(QQ).dI()
            sage: dI._to_Monomial_on_basis(Composition([1,3]))
            M[1, 1, 1, 1] + M[1, 1, 2] + M[1, 2, 1] + M[1, 3]
            sage: dI._to_Monomial_on_basis(Composition([]))
            M[]
            sage: dI._to_Monomial_on_basis(Composition([2,1,2]))
            4*M[1, 1, 1, 1, 1] + 3*M[1, 1, 1, 2] + 2*M[1, 1, 2, 1] + M[1, 1, 3] + M[1, 2, 1, 1] + M[1, 2, 2] + M[2, 1, 1, 1] + M[2, 1, 2]
            """
            M = self.realization_of().Monomial()
            if J == []:
                return M([])
            C = Compositions()
            C_size = Compositions(J.size())
            return M.sum_of_terms((C(I), number_of_fCT(C(I), J)) for I in C_size)
コード例 #3
0
ファイル: qsym.py プロジェクト: sajedel/testsage
        def _matrix_monomial_to_dual_immaculate(self, n):
            r"""
            This function caches the change of basis matrix from the quasisymmetric monomial basis to the dual immaculate basis.

            INPUT:

            - ``J`` -- a composition

            OUTPUT:

            - A list. Each entry in the list is a row in the change of basis matrix.

            EXAMPLES::

                sage: dI = QuasiSymmetricFunctions(QQ).dI()
                sage: dI._matrix_monomial_to_dual_immaculate(3)
                [[1, -1, -1, 1], [0, 1, -1, 0], [0, 0, 1, -1], [0, 0, 0, 1]]
                sage: dI._matrix_monomial_to_dual_immaculate(0)
                [[1]]
            """
            N = NonCommutativeSymmetricFunctions(self.base_ring())
            I = N.I()
            S = N.S()
            mat = []
            C = Compositions()
            for alp in Compositions(n):
                row = []
                expansion = S(I(C(alp)))
                for bet in Compositions(n):
                    row.append(expansion.coefficient(C(bet)))
                mat.append(row)
            return mat
コード例 #4
0
    def __classcall_private__(cls, s=None, c=None):
        """
        Choose the correct parent based upon input.

        EXAMPLES::

            sage: OrderedSetPartitions(4)
            Ordered set partitions of {1, 2, 3, 4}
            sage: OrderedSetPartitions(4, [1, 2, 1])
            Ordered set partitions of {1, 2, 3, 4} into parts of size [1, 2, 1]
        """
        if s is None:
            if c is not None:
                raise NotImplementedError(
                    "cannot specify 'c' without specifying 's'")
            return OrderedSetPartitions_all()
        if isinstance(s, (int, Integer)):
            if s < 0:
                raise ValueError("s must be non-negative")
            s = frozenset(range(1, s + 1))
        else:
            s = frozenset(s)

        if c is None:
            return OrderedSetPartitions_s(s)

        if isinstance(c, (int, Integer)):
            return OrderedSetPartitions_sn(s, c)
        if c not in Compositions(len(s)):
            raise ValueError("c must be a composition of %s" % len(s))
        return OrderedSetPartitions_scomp(s, Composition(c))
コード例 #5
0
ファイル: ordered_tree.py プロジェクト: sagemathinc/smc-sage
    def __iter__(self):
        """
        A basic generator

        .. TODO:: could be optimized.

        TESTS::

            sage: OrderedTrees(0).list()
            []
            sage: OrderedTrees(1).list()
            [[]]
            sage: OrderedTrees(2).list()
            [[[]]]
            sage: OrderedTrees(3).list()
            [[[], []], [[[]]]]
            sage: OrderedTrees(4).list()
            [[[], [], []], [[], [[]]], [[[]], []], [[[], []]], [[[[]]]]]
        """
        if self._size == 0:
            return
        else:
            for c in Compositions(self._size - 1):
                for lst in CartesianProduct(*(map(self.__class__, c))):
                    yield self._element_constructor_(lst)
コード例 #6
0
def compositions(g, n):
    r"""
    Return compositions of sum at most 3g-3+n and length n
    """
    for k in range(3 * g - 3 + n + 1):
        for c in Compositions(k + n, length=n, min_part=1):
            yield [i - 1 for i in c]
コード例 #7
0
    def strongly_finer(self):
        """
        Return the set of ordered set partitions which are strongly
        finer than ``self``.

        See :meth:`is_strongly_finer` for the definition of "strongly
        finer".

        EXAMPLES::

            sage: C = OrderedSetPartition([[1, 3], [2]]).strongly_finer()
            sage: C.cardinality()
            2
            sage: C.list()
            [[{1}, {3}, {2}], [{1, 3}, {2}]]

            sage: OrderedSetPartition([]).strongly_finer()
            {[]}

            sage: W = OrderedSetPartition([[4, 9], [-1, 2]])
            sage: W.strongly_finer().list()
            [[{4}, {9}, {-1}, {2}],
             [{4}, {9}, {-1, 2}],
             [{4, 9}, {-1}, {2}],
             [{4, 9}, {-1, 2}]]
        """
        par = parent(self)
        if not self:
            return FiniteEnumeratedSet([self])
        else:
            buo = OrderedSetPartition.bottom_up_osp
            return FiniteEnumeratedSet([par(sum((list(P) for P in C), []))
                    for C in cartesian_product([[buo(X, comp) for comp in Compositions(len(X))] for X in self])])
コード例 #8
0
def compositions_order(n):
    r"""
    Return the compositions of `n` ordered as defined in [QSCHUR]_.

    Let `S(\gamma)` return the composition `\gamma` after sorting. For
    compositions `\alpha` and `\beta`, we order `\alpha \rhd \beta` if

    1) `S(\alpha) > S(\beta)` lexicographically, or
    2) `S(\alpha) = S(\beta)` and `\alpha > \beta` lexicographically.

    INPUT:

    - ``n`` -- a positive integer

    OUTPUT:

    - A list of the compositions of ``n`` sorted into decreasing order
      by `\rhd`

    EXAMPLES::

        sage: from sage.combinat.ncsf_qsym.combinatorics import compositions_order
        sage: compositions_order(3)
        [[3], [2, 1], [1, 2], [1, 1, 1]]
        sage: compositions_order(4)
        [[4], [3, 1], [1, 3], [2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]]
    """
    def _myorder(I,J):
        pI = sorted(I, reverse=True)
        pJ = sorted(J, reverse=True)
        if pI == pJ:
            return cmp(list(J), list(I))
        else:
            return cmp(pJ , pI)
    return sorted(Compositions(n), cmp=_myorder)
コード例 #9
0
    def __iter__(self):
        r"""
        EXAMPLES::

            sage: [t for t in CompositionTableaux(3)]
            [[[1], [2], [3]],
             [[1], [2, 2]],
             [[1], [3, 2]],
             [[1], [3, 3]],
             [[2], [3, 3]],
             [[1, 1], [2]],
             [[1, 1], [3]],
             [[2, 1], [3]],
             [[2, 2], [3]],
             [[1, 1, 1]],
             [[2, 1, 1]],
             [[2, 2, 1]],
             [[2, 2, 2]],
             [[3, 1, 1]],
             [[3, 2, 1]],
             [[3, 2, 2]],
             [[3, 3, 1]],
             [[3, 3, 2]],
             [[3, 3, 3]]]

            sage: CompositionTableaux(3)[0].parent() is CompositionTableaux(3)
            True
        """
        for comp in Compositions(self.size):
            for T in CompositionTableaux_shape(comp, self.max_entry):
                yield self.element_class(self, T)
コード例 #10
0
ファイル: qsym.py プロジェクト: sajedel/testsage
        def __init__(self, QSym):
            r"""
            The dual immaculate basis of the non-commutative symmetric functions. This basis first
            appears in Berg, Bergeron, Saliola, Serrano and Zabrocki's " A lift of the Schur and Hall-Littlewood
            bases to non-commutative symmetric functions".

            EXAMPLES ::

                sage: QSym = QuasiSymmetricFunctions(QQ)
                sage: dI = QSym.dI()
                sage: dI([1,3,2])*dI([1])  # long time (6s on sage.math, 2013)
                dI[1, 1, 3, 2] + dI[2, 3, 2]
                sage: dI([1,3])*dI([1,1])
                dI[1, 1, 1, 3] + dI[1, 1, 4] + dI[1, 2, 3] - dI[1, 3, 2] - dI[1, 4, 1] - dI[1, 5] + dI[2, 3, 1] + dI[2, 4]
                sage: dI([3,1])*dI([2,1])  # long time (7s on sage.math, 2013)
                dI[1, 1, 5] - dI[1, 4, 1, 1] - dI[1, 4, 2] - 2*dI[1, 5, 1] - dI[1, 6] - dI[2, 4, 1] - dI[2, 5] - dI[3, 1, 3] + dI[3, 2, 1, 1] + dI[3, 2, 2] + dI[3, 3, 1] + dI[4, 1, 1, 1] + 2*dI[4, 2, 1] + dI[4, 3] + dI[5, 1, 1] + dI[5, 2]
                sage: F = QSym.F()
                sage: dI(F[1,3,1])
                -dI[1, 1, 1, 2] + dI[1, 1, 2, 1] - dI[1, 2, 2] + dI[1, 3, 1]
                sage: F(dI(F([2,1,3])))
                F[2, 1, 3]
            """
            CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(),
                                             prefix='dI', bracket=False,
                                             category=QSym.Bases())
コード例 #11
0
    def discrepancy_statistics(self, length):
        r"""
        Return the discrepancy of words of given length.

        INPUT:

        - ``length`` -- integer

        OUTPUT:

            dict

        EXAMPLES::

            sage: from slabbe.mult_cont_frac import Brun
            sage: Brun().discrepancy_statistics(5)
            {[1, 1, 3]: 6/5,
             [1, 2, 2]: 4/5,
             [1, 3, 1]: 4/5,
             [2, 1, 2]: 4/5,
             [2, 2, 1]: 4/5,
             [3, 1, 1]: 4/5}
        """
        from finite_word import discrepancy
        from sage.combinat.composition import Compositions
        D = {}
        for c in Compositions(length, length=3, min_part=1):
            w = self.s_adic_word(c)
            if c != w.abelian_vector():
                raise ValueError("c={} but vector is"
                                 " {}".format(c, w.abelian_vector()))
            D[c] = discrepancy(w)
        return D
コード例 #12
0
ファイル: descent_algebra.py プロジェクト: yunboliu27/sage
        def __init__(self, alg, prefix="I"):
            r"""
            Initialize ``self``.

            EXAMPLES::

                sage: TestSuite(DescentAlgebra(QQ, 4).B()).run()
            """
            self._prefix = prefix
            self._basis_name = "idempotent"
            CombinatorialFreeModule.__init__(self,
                                             alg.base_ring(),
                                             Compositions(alg._n),
                                             category=DescentAlgebraBases(alg),
                                             bracket="",
                                             prefix=prefix)

            ## Change of basis:
            B = alg.B()
            self.module_morphism(
                self.to_B_basis, codomain=B,
                category=self.category()).register_as_coercion()

            B.module_morphism(B.to_I_basis,
                              codomain=self,
                              category=self.category()).register_as_coercion()
コード例 #13
0
ファイル: descent_algebra.py プロジェクト: yunboliu27/sage
        def __getitem__(self, p):
            """
            Return the basis element indexed by ``p``.

            INPUT:

            - ``p`` -- a composition

            EXAMPLES::

                sage: B = DescentAlgebra(QQ, 4).B()
                sage: B[Composition([4])]
                B[4]
                sage: B[1,2,1]
                B[1, 2, 1]
                sage: B[4]
                B[4]
                sage: B[[3,1]]
                B[3, 1]
            """
            C = Compositions(self.realization_of()._n)
            if p in C:
                return self.monomial(C(p))  # Make sure it's a composition
            if not p:
                return self.one()

            if not isinstance(p, tuple):
                p = [p]
            return self.monomial(C(p))
コード例 #14
0
ファイル: descent_algebra.py プロジェクト: yunboliu27/sage
        def to_B_basis(self, S):
            r"""
            Return `D_S` as a linear combination of `B_p`-basis elements.

            EXAMPLES::

                sage: DA = DescentAlgebra(QQ, 4)
                sage: D = DA.D()
                sage: B = DA.B()
                sage: map(B, D.basis()) # indirect doctest
                [B[4],
                 B[1, 3] - B[4],
                 B[2, 2] - B[4],
                 B[3, 1] - B[4],
                 B[1, 1, 2] - B[1, 3] - B[2, 2] + B[4],
                 B[1, 2, 1] - B[1, 3] - B[3, 1] + B[4],
                 B[2, 1, 1] - B[2, 2] - B[3, 1] + B[4],
                 B[1, 1, 1, 1] - B[1, 1, 2] - B[1, 2, 1] + B[1, 3]
                  - B[2, 1, 1] + B[2, 2] + B[3, 1] - B[4]]
            """
            B = self.realization_of().B()

            if not S:
                return B.one()

            n = self.realization_of()._n
            C = Compositions(n)
            return B.sum_of_terms([(C.from_subset(T,
                                                  n), (-1)**(len(S) - len(T)))
                                   for T in SubsetsSorted(S)])
コード例 #15
0
ファイル: combinatorics.py プロジェクト: bopopescu/sage-5
def number_of_fCT(content_comp, shape_comp):
    r"""
    Returns the number of Immaculate tableau of shape ``shape_comp`` and content ``content_comp``.

    INPUT:

    - ``content_comp``, ``shape_comp`` -- compositions

    OUTPUT:

    - An integer

    EXAMPLES::

        sage: from sage.combinat.ncsf_qsym.combinatorics import number_of_fCT
        sage: number_of_fCT(Composition([3,1]), Composition([1,3]))
        0
        sage: number_of_fCT(Composition([1,2,1]), Composition([1,3]))
        1
        sage: number_of_fCT(Composition([1,1,3,1]), Composition([2,1,3]))
        2

    """
    if content_comp.to_partition().length() == 1:
        if shape_comp.to_partition().length() == 1:
            return 1
        else:
            return 0
    C = Compositions(content_comp.size() - content_comp[-1],
                     outer=list(shape_comp))
    s = 0
    for x in C:
        if len(x) >= len(shape_comp) - 1:
            s += number_of_fCT(Composition(content_comp[:-1]), x)
    return s
コード例 #16
0
ファイル: combinatorics.py プロジェクト: bopopescu/sage-5
def m_to_s_stat(R, I, K):
    r"""
    Returns the statistic for the expansion of the Monomial basis element indexed by two
    compositions, as in formula (36) of Tevlin's "Noncommutative Analogs of Monomial Symmetric
    Functions, Cauchy Identity, and Hall Scalar Product".

    INPUT:

    - ``R`` -- A ring
    - ``I``, ``K`` -- compositions

    OUTPUT:

    - An integer

    EXAMPLES::

        sage: from sage.combinat.ncsf_qsym.combinatorics import m_to_s_stat
        sage: m_to_s_stat(QQ,Composition([2,1]), Composition([1,1,1]))
        -1
        sage: m_to_s_stat(QQ,Composition([3]), Composition([1,2]))
        -2
    """
    stat = 0
    for J in Compositions(I.size()):
        if (I.is_finer(J) and K.is_finer(J)):
            pvec = [
                0
            ] + Composition(I).refinement_splitting_lengths(J).partial_sums()
            pp = prod(R(len(I) - pvec[i]) for i in range(len(pvec) - 1))
            stat += R((-1)**(len(I) - len(K)) / pp * coeff_lp(K, J))
    return stat
コード例 #17
0
    def __init__(self, parent, t):
        r"""
        Initialize a composition tableau.

        TESTS::

            sage: t = CompositionTableaux()([[1],[2,2]])
            sage: s = CompositionTableaux(3)([[1],[2,2]])
            sage: s==t
            True
            sage: t.parent()
            Composition Tableaux
            sage: s.parent()
            Composition Tableaux of size 3 and maximum entry 3
            sage: r = CompositionTableaux()(s)
            sage: r.parent()
            Composition Tableaux
        """
        if isinstance(t, CompositionTableau):
            Element.__init__(self, parent)
            CombinatorialObject.__init__(self, t._list)
            return

        # CombinatorialObject verifies that t is a list
        # We must verify t is a list of lists
        if not all(isinstance(row, list) for row in t):
            raise ValueError("A composition tableau must be a list of lists.")

        if not map(len, t) in Compositions():
            raise ValueError(
                "A composition tableau must be a list of non-empty lists.")

        # Verify rows weakly decrease from left to right
        for row in t:
            if any(row[i] < row[i + 1] for i in range(len(row) - 1)):
                raise ValueError(
                    "Rows must weakly decrease from left to right.")

        # Verify leftmost column strictly increases from top to bottom
        first_col = [row[0] for row in t if t != [[]]]
        if any(first_col[i] >= first_col[i + 1] for i in range(len(t) - 1)):
            raise ValueError(
                "Leftmost column must strictly increase from top to bottom.")

        # Verify triple condition
        l = len(t)
        m = max(map(len, t) + [0])
        TT = [row + [0] * (m - len(row)) for row in t]
        for i in range(l):
            for j in range(i + 1, l):
                for k in range(1, m):
                    if TT[j][k] != 0 and TT[j][k] >= TT[i][k] and TT[j][
                            k] <= TT[i][k - 1]:
                        raise ValueError("Triple condition must be satisfied.")

        Element.__init__(self, parent)
        CombinatorialObject.__init__(self, t)
コード例 #18
0
ファイル: shuffle_product.py プロジェクト: shrutig/sage
    def _proc(self, vect):
        """
        Return the shuffle of ``w1`` with ``w2`` with 01-vector
        ``vect``.

        The 01-vector of a shuffle is a list of 0s and 1s whose
        length is the sum of the lengths of ``w1`` and ``w2``,
        and whose `k`-th entry is `1` if the `k`-th letter of
        the shuffle is taken from ``w1`` and `0` if it is taken
        from ``w2``.

        EXAMPLES::

            sage: from sage.combinat.words.shuffle_product import ShuffleProduct_w1w2
            sage: w, u = map(Words("abcd"), ["ab", "cd"])
            sage: S = ShuffleProduct_w1w2(w,u)
            sage: S._proc([0,1,0,1])
            word: cadb
            sage: S._proc([1,1,0,0])
            word: abcd

            sage: I = Composition([1, 1])
            sage: J = Composition([2])
            sage: S = ShuffleProduct_w1w2(I, J)
            sage: S._proc([1,0,1])
            [1, 2, 1]

        TESTS:

        Sage is no longer confused by a too-restrictive parent
        of `I` when shuffling two compositions `I` and `J`
        (cf. :trac:`15131`)::

            sage: I = Composition([1, 1])
            sage: J = Composition([2])
            sage: S = ShuffleProduct_w1w2(I, J)
            sage: S._proc([1,0,1])
            [1, 2, 1]
        """
        i1 = -1
        i2 = -1
        res = []
        for v in vect:
            if v == 1:
                i1 += 1
                res.append(self._w1[i1])
            else:
                i2 += 1
                res.append(self._w2[i2])
        try:
            return self._w1.parent()(res)
        except ValueError:
            # Special situation: the parent of w1 is too
            # restrictive to be cast on res.
            if isinstance(self._w1.parent(), Compositions_n):
                return Compositions(res)
コード例 #19
0
ファイル: qsym.py プロジェクト: sajedel/testsage
        def __init__(self, QSym):
            """
            EXAMPLES::

                sage: M = QuasiSymmetricFunctions(QQ).Monomial(); M
                Quasisymmetric functions over the Rational Field in the Monomial basis
                sage: TestSuite(M).run()
            """
            CombinatorialFreeModule.__init__(self, QSym.base_ring(), Compositions(),
                                             prefix='M', bracket=False,
                                             category=QSym.Bases())
コード例 #20
0
        def one_basis(self):
            r"""
            Return the empty composition.

            OUTPUT

            - The empty composition.

            EXAMPLES::

                sage: L=NonCommutativeSymmetricFunctions(QQ).L()
                sage: parent(L)
                <class 'sage.combinat.ncsf_qsym.ncsf.NonCommutativeSymmetricFunctions.Elementary_with_category'>
                sage: parent(L).one_basis()
                []
            """
            return Compositions()([])
コード例 #21
0
ファイル: descent_algebra.py プロジェクト: yunboliu27/sage
        def product_on_basis(self, p, q):
            r"""
            Return `B_p B_q`, where `p` and `q` are compositions of `n`.

            EXAMPLES::

                sage: DA = DescentAlgebra(QQ, 4)
                sage: B = DA.B()
                sage: p = Composition([1,2,1])
                sage: q = Composition([3,1])
                sage: B.product_on_basis(p, q)
                B[1, 1, 1, 1] + 2*B[1, 2, 1]
            """
            IM = IntegerMatrices(list(p), list(q))
            P = Compositions(self.realization_of()._n)
            to_composition = lambda m: P([x for x in m.list() if x != 0])
            return self.sum_of_monomials([to_composition(_) for _ in IM])
コード例 #22
0
ファイル: shuffle_product.py プロジェクト: shrutig/sage
    def __init__(self, w1, w2, r):
        """
        EXAMPLES::

            sage: from sage.combinat.words.shuffle_product import ShuffleProduct_overlapping_r
            sage: w, u = map(Words("abcdef"), ["ab", "cd"])
            sage: S = ShuffleProduct_overlapping_r(w,u,1)
            sage: S == loads(dumps(S))
            True
        """
        self._w1 = w1
        self._w2 = w2
        self.r = r
        self.W = self._w1.parent()
        # Special situation: the parent of w1 is too
        # restrictive to be cast on the shuffles.
        if isinstance(self.W, Compositions_n):
            self.W = Compositions()
コード例 #23
0
        def __init__(self, alg, prefix="B"):
            r"""
            Initialize ``self``.

            EXAMPLES::

                sage: TestSuite(DescentAlgebra(QQ, 4).B()).run()
            """
            self._prefix = prefix
            self._basis_name = "subset"
            CombinatorialFreeModule.__init__(self, alg.base_ring(),
                                             Compositions(alg._n),
                                             category=DescentAlgebraBases(alg),
                                             bracket="", prefix=prefix)

            S = NonCommutativeSymmetricFunctions(alg.base_ring()).Complete()
            self.module_morphism(self.to_nsym,
                                 codomain=S, category=Algebras(alg.base_ring())
                                 ).register_as_coercion()
コード例 #24
0
    def IntegerCompositions(n):
        """
        Returns the poset of integer compositions of the integer ``n``.

        A composition of a positive integer `n` is a list of positive
        integers that sum to `n`. The order is reverse refinement:
        `[p_1,p_2,...,p_l] < [q_1,q_2,...,q_m]` if `q` consists
        of an integer composition of `p_1`, followed by an integer
        composition of `p_2`, and so on.

        EXAMPLES::

            sage: P = Posets.IntegerCompositions(7); P
            Finite poset containing 64 elements
            sage: len(P.cover_relations())
            192
        """
        from sage.combinat.composition import Compositions
        C = Compositions(n)
        return Poset((C, [[c,d] for c in C for d in C if d.is_finer(c)]), cover_relations=False)
コード例 #25
0
ファイル: descent_algebra.py プロジェクト: yunboliu27/sage
        def one_basis(self):
            r"""
            Return the identity element which is the composition `[n]`, as per
            ``AlgebrasWithBasis.ParentMethods.one_basis``.

            EXAMPLES::

                sage: DescentAlgebra(QQ, 4).B().one_basis()
                [4]
                sage: DescentAlgebra(QQ, 0).B().one_basis()
                []

                sage: all( U * DescentAlgebra(QQ, 3).B().one() == U
                ....:      for U in DescentAlgebra(QQ, 3).B().basis() )
                True
            """
            n = self.realization_of()._n
            P = Compositions(n)
            if not n:  # n == 0
                return P([])
            return P([n])
コード例 #26
0
    def __iter__(self):
        """
        EXAMPLES::

            sage: [ p for p in OrderedSetPartitions([1,2,3]) ]
            [[{1}, {2}, {3}],
             [{1}, {3}, {2}],
             [{2}, {1}, {3}],
             [{3}, {1}, {2}],
             [{2}, {3}, {1}],
             [{3}, {2}, {1}],
             [{1}, {2, 3}],
             [{2}, {1, 3}],
             [{3}, {1, 2}],
             [{1, 2}, {3}],
             [{1, 3}, {2}],
             [{2, 3}, {1}],
             [{1, 2, 3}]]
        """
        for x in Compositions(len(self._set)):
            for z in OrderedSetPartitions(self._set, x):
                yield self.element_class(self, z)
コード例 #27
0
ファイル: combinatorics.py プロジェクト: BrentBaccala/sage
def m_to_s_stat(R, I, K):
    r"""
    Return the coefficient of the complete non-commutative symmetric
    function `S^K` in the expansion of the monomial non-commutative
    symmetric function `M^I` with respect to the complete basis
    over the ring `R`. This is the coefficient in formula (36) of
    Tevlin's paper [Tev2007]_.

    INPUT:

    - ``R`` -- A ring, supposed to be a `\QQ`-algebra
    - ``I``, ``K`` -- compositions

    OUTPUT:

    - The coefficient of `S^K` in the expansion of `M^I` in the
      complete basis of the non-commutative symmetric functions
      over ``R``.

    EXAMPLES::

        sage: from sage.combinat.ncsf_qsym.combinatorics import m_to_s_stat
        sage: m_to_s_stat(QQ, Composition([2,1]), Composition([1,1,1]))
        -1
        sage: m_to_s_stat(QQ, Composition([3]), Composition([1,2]))
        -2
        sage: m_to_s_stat(QQ, Composition([2,1,2]), Composition([2,1,2]))
        8/3
    """
    stat = 0
    for J in Compositions(I.size()):
        if (I.is_finer(J) and K.is_finer(J)):
            pvec = [
                0
            ] + Composition(I).refinement_splitting_lengths(J).partial_sums()
            pp = prod(R(len(I) - pvec[i]) for i in range(len(pvec) - 1))
            stat += R((-1)**(len(I) - len(K)) / pp * coeff_lp(K, J))
    return stat
コード例 #28
0
    def fatter(self):
        """
        Return the set of ordered set partitions which are fatter
        than ``self``.

        See :meth:`finer` for the definition of "fatter".

        EXAMPLES::

            sage: C = OrderedSetPartition([[2, 5], [1], [3, 4]]).fatter()
            sage: C.cardinality()
            4
            sage: sorted(C)
            [[{1, 2, 3, 4, 5}],
             [{1, 2, 5}, {3, 4}],
             [{2, 5}, {1, 3, 4}],
             [{2, 5}, {1}, {3, 4}]]

            sage: OrderedSetPartition([[4, 9], [-1, 2]]).fatter().list()
            [[{4, 9}, {-1, 2}], [{-1, 2, 4, 9}]]

        Some extreme cases::

            sage: list(OrderedSetPartition([[5]]).fatter())
            [[{5}]]
            sage: list(Composition([]).fatter())
            [[]]
            sage: sorted(OrderedSetPartition([[1], [2], [3], [4]]).fatter())
            [[{1, 2, 3, 4}],
             [{1, 2, 3}, {4}],
             [{1, 2}, {3, 4}],
             [{1, 2}, {3}, {4}],
             [{1}, {2, 3, 4}],
             [{1}, {2, 3}, {4}],
             [{1}, {2}, {3, 4}],
             [{1}, {2}, {3}, {4}]]
        """
        return Compositions(len(self)).map(self.fatten)
コード例 #29
0
ファイル: shuffle_product.py プロジェクト: yunboliu27/sage
    def __init__(self, w1, w2, r):
        """
        The overlapping shuffle product of the two words ``w1`` and ``w2``
        with precisely ``r`` overlaps.

        See :class:`ShuffleProduct_overlapping` for a definition.

        EXAMPLES::

            sage: from sage.combinat.words.shuffle_product import ShuffleProduct_overlapping_r
            sage: w, u = map(Words(range(20)), [[2, 9], [9, 1]])
            sage: S = ShuffleProduct_overlapping_r(w,u,1)
            sage: S == loads(dumps(S))
            True
        """
        self._w1 = w1
        self._w2 = w2
        self.r = r
        self.W = self._w1.parent()
        # Special situation: the parent of w1 is too
        # restrictive to be cast on the shuffles.
        if isinstance(self.W, Compositions_n):
            self.W = Compositions()
コード例 #30
0
    def __iter__(self):
        """
        EXAMPLES::

            sage: [ p for p in OrderedSetPartitions([1,2,3,4], 2) ]
            [[{1, 2, 3}, {4}],
             [{1, 2, 4}, {3}],
             [{1, 3, 4}, {2}],
             [{2, 3, 4}, {1}],
             [{1, 2}, {3, 4}],
             [{1, 3}, {2, 4}],
             [{1, 4}, {2, 3}],
             [{2, 3}, {1, 4}],
             [{2, 4}, {1, 3}],
             [{3, 4}, {1, 2}],
             [{1}, {2, 3, 4}],
             [{2}, {1, 3, 4}],
             [{3}, {1, 2, 4}],
             [{4}, {1, 2, 3}]]
        """
        for x in Compositions(len(self._set), length=self.n):
            for z in OrderedSetPartitions_scomp(self._set, x):
                yield self.element_class(self, z)