Ticket #14136: trac_14136_p_partition_enumerator_v1.patch

File trac_14136_p_partition_enumerator_v1.patch, 3.6 KB (added by chapoton, 8 years ago)
  • sage/combinat/posets/posets.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1367338060 -7200
    # Node ID 6edbb91649bc49f824ea9346e729089eb096a29f
    # Parent  d38af13415d6e01c39449656a183a533f951e553
    trac #14136 implement P-partition enumerator of a poset
    
    diff --git a/sage/combinat/posets/posets.py b/sage/combinat/posets/posets.py
    a b This module implements finite partialy o 
    7373    :meth:`~FinitePoset.order_filter` | Returns the order filter generated by a list of elements.
    7474    :meth:`~FinitePoset.order_ideal` | Returns the order ideal generated by a list of elements.
    7575    :meth:`~FinitePoset.order_polytope` | Returns the order polytope of the poset.
     76    :meth:`~FinitePoset.p_partition_enumerator` | Returns a `P`-partition enumerator of the poset.
    7677    :meth:`~FinitePoset.plot` | Returns a Graphic object corresponding the Hasse diagram of the poset.
    7778    :meth:`~FinitePoset.product` | Returns the cartesian product of ``self`` and ``other``.
    7879    :meth:`~FinitePoset.promotion` | Computes the (extended) promotion on the linear extension of the poset ``self``
    class FinitePoset(UniqueRepresentation,  
    32343235                return False
    32353236        return True
    32363237
     3238    def p_partition_enumerator(self, tup, R, check=False):
     3239        r"""
     3240        return a `P`-partition enumerator of ``self``
     3241
     3242        This is a quasisymmetric function which depends on a total
     3243        order on the vertices of the poset.
     3244
     3245        INPUT:
     3246
     3247        - `tup` -- tuple: the elements of `P` in some total order; this does not have to be a linear extension.
     3248
     3249        - `R` -- commutative ring
     3250
     3251        OUTPUT:
     3252
     3253        the `P`-partition enumerator of ``self`` according to `tup` in the
     3254        algebra `QSym` over the base ring `R`.
     3255
     3256        This is the quasisymmetric function `\sum\limits_{f\text{ a
     3257        }P\text{-partition}} \prod\limits_{p \in P} x_{f(p)}`, where a
     3258        `P`-partition is a function `P \to \{1,2,3,...\}` satisfying
     3259        the following properties:
     3260
     3261        For any two elements `i` and `j` of `P`,
     3262
     3263        - if `i < j` then `f(i) \leq f(j)`,
     3264
     3265        - if `i < j` and `i` appears left of `j` in `tup` then `f(i) < f(j)`.
     3266
     3267        EXAMPLES::
     3268
     3269            sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]])
     3270            sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, check=True);FP
     3271            2*M[1, 1, 1, 1] + 2*M[1, 2, 1] + M[2, 1, 1] + M[3, 1]
     3272
     3273            sage: expansion = FP.expand(5)
     3274            sage: xs = expansion.parent().gens()
     3275            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])
     3276            True
     3277
     3278            sage: P = Poset([[],[]])
     3279            sage: FP = P.p_partition_enumerator((), QQ, check=True) ; FP
     3280            M[]
     3281        """
     3282        if check:
     3283            if sorted(self.list()) != sorted(tup):
     3284                raise ValueError("the elements of tup are not those of P")
     3285        from sage.combinat.ncsf_qsym.qsym import QuasiSymmetricFunctions
     3286        from sage.combinat.composition import Composition
     3287        print('no error yet')
     3288        QR = QuasiSymmetricFunctions(R)
     3289        print('error is before this line')
     3290        n = len(tup)
     3291        res = QR.zero()
     3292        tupdict = dict(zip(tup, range(n)))
     3293        for lin in self.linear_extensions(facade=True):
     3294            descents = [i + 1 for i in xrange(n-1) if tupdict[lin[i]] > tupdict[lin[i+1]]]
     3295            res += QR.Fundamental()(Composition(from_subset=(descents, n)))
     3296        return res
     3297
    32373298FinitePoset._dual_class = FinitePoset
    32383299
    32393300##### Posets #####