Ticket #14136: trac_14136-p_partition_enumerator_folded.patch

File trac_14136-p_partition_enumerator_folded.patch, 3.6 KB (added by darij, 8 years ago)

folded with Travis's review

  • sage/combinat/posets/posets.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1367338060 -7200
    # Node ID 74cbe35c5fe24c42e9ff96a8bac05f420f69744e
    # Parent  e140221d62f056a39f43136970b31e5bba512c62
    trac #14136 implement P-partition enumerator of a poset
    * * *
    #14136: review patch.
    
    diff --git a/sage/combinat/posets/posets.py b/sage/combinat/posets/posets.py
    a b This module implements finite partialy o 
    7575    :meth:`~FinitePoset.order_filter` | Returns the order filter generated by a list of elements.
    7676    :meth:`~FinitePoset.order_ideal` | Returns the order ideal generated by a list of elements.
    7777    :meth:`~FinitePoset.order_polytope` | Returns the order polytope of the poset.
     78    :meth:`~FinitePoset.p_partition_enumerator` | Returns a `P`-partition enumerator of the poset.
    7879    :meth:`~FinitePoset.plot` | Returns a Graphic object corresponding the Hasse diagram of the poset.
    7980    :meth:`~FinitePoset.product` | Returns the cartesian product of ``self`` and ``other``.
    8081    :meth:`~FinitePoset.promotion` | Computes the (extended) promotion on the linear extension of the poset ``self``
    class FinitePoset(UniqueRepresentation,  
    33583359        ps.reverse()
    33593360        return Partition(ps)
    33603361
     3362    def p_partition_enumerator(self, tup, R, check=False):
     3363        r"""
     3364        Return a `P`-partition enumerator of ``self``.
     3365
     3366        Given a total order `\prec` on the vertices of a poset `P`, a
     3367        `P`-partition enumerator is the quasisymmetric function
     3368        `\sum_f \prod_{p \in P} x_{f(p)}`, where the first sum is taken over
     3369        all `P`-partitions `f`.
     3370
     3371        A `P`-partition is a function `f : P \to \{1,2,3,...\}` satisfying
     3372        the following properties for any two elements `i` and `j` of `P`:
     3373
     3374        - if `i \prec j` then `f(i) \leq f(j)`,
     3375
     3376        - if `j \prec i` then `f(j) < f(i)`.
     3377
     3378        INPUT:
     3379
     3380        - ``tup`` -- A tuple of elements of `P` representing a total order
     3381          (this does not have to be a linear extension)
     3382
     3383        - ``R`` -- A commutative ring
     3384
     3385        OUTPUT:
     3386
     3387        The `P`-partition enumerator of ``self`` according to ``tup`` in the
     3388        algebra `QSym` over the base ring `R`.
     3389
     3390        EXAMPLES::
     3391
     3392            sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]])
     3393            sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, check=True); FP
     3394            2*M[1, 1, 1, 1] + 2*M[1, 2, 1] + M[2, 1, 1] + M[3, 1]
     3395
     3396            sage: expansion = FP.expand(5)
     3397            sage: xs = expansion.parent().gens()
     3398            sage: expansion == sum([xs[a]*xs[b]*xs[c]*xs[d] for a in range(5) for b in range(5) for c in range(5) for d in range(5) if a <= b and c <= b and b < d])
     3399            True
     3400
     3401            sage: P = Poset([[],[]])
     3402            sage: FP = P.p_partition_enumerator((), QQ, check=True); FP
     3403            M[]
     3404        """
     3405        if check:
     3406            if sorted(self.list()) != sorted(tup):
     3407                raise ValueError("the elements of tup are not those of P")
     3408        from sage.combinat.composition import Composition
     3409        from sage.combinat.ncsf_qsym.qsym import QuasiSymmetricFunctions
     3410        QR = QuasiSymmetricFunctions(R)
     3411        n = len(tup)
     3412        res = QR.zero()
     3413        tupdict = dict(zip(tup, range(n)))
     3414        for lin in self.linear_extensions(facade=True):
     3415            descents = [i + 1 for i in xrange(n-1) if tupdict[lin[i]] > tupdict[lin[i+1]]]
     3416            res += QR.Fundamental()(Composition(from_subset=(descents, n)))
     3417        return res
     3418
    33613419FinitePoset._dual_class = FinitePoset
    33623420
    33633421##### Posets #####