# 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 This module implements finite partialy o :meth:~FinitePoset.order_filter | Returns the order filter generated by a list of elements. :meth:~FinitePoset.order_ideal | Returns the order ideal generated by a list of elements. :meth:~FinitePoset.order_polytope | Returns the order polytope of the poset. :meth:~FinitePoset.p_partition_enumerator | Returns a P-partition enumerator of the poset. :meth:~FinitePoset.plot | Returns a Graphic object corresponding the Hasse diagram of the poset. :meth:~FinitePoset.product | Returns the cartesian product of self and other. :meth:~FinitePoset.promotion | Computes the (extended) promotion on the linear extension of the poset self class FinitePoset(UniqueRepresentation, ps.reverse() return Partition(ps) def p_partition_enumerator(self, tup, R, check=False): r""" Return a P-partition enumerator of self. Given a total order \prec on the vertices of a poset P, a P-partition enumerator is the quasisymmetric function \sum_f \prod_{p \in P} x_{f(p)}, where the first sum is taken over all P-partitions f. A P-partition is a function f : P \to \{1,2,3,...\} satisfying the following properties for any two elements i and j of P: - if i \prec j then f(i) \leq f(j), - if j \prec i then f(j) < f(i). INPUT: - tup -- A tuple of elements of P representing a total order (this does not have to be a linear extension) - R -- A commutative ring OUTPUT: The P-partition enumerator of self according to tup in the algebra QSym over the base ring R. EXAMPLES:: sage: P = Poset([[1,2,3,4],[[1,4],[2,4],[4,3]]]) sage: FP = P.p_partition_enumerator((3,1,2,4), QQ, check=True); FP 2*M[1, 1, 1, 1] + 2*M[1, 2, 1] + M[2, 1, 1] + M[3, 1] sage: expansion = FP.expand(5) sage: xs = expansion.parent().gens() 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]) True sage: P = Poset([[],[]]) sage: FP = P.p_partition_enumerator((), QQ, check=True); FP M[] """ if check: if sorted(self.list()) != sorted(tup): raise ValueError("the elements of tup are not those of P") from sage.combinat.composition import Composition from sage.combinat.ncsf_qsym.qsym import QuasiSymmetricFunctions QR = QuasiSymmetricFunctions(R) n = len(tup) res = QR.zero() tupdict = dict(zip(tup, range(n))) for lin in self.linear_extensions(facade=True): descents = [i + 1 for i in xrange(n-1) if tupdict[lin[i]] > tupdict[lin[i+1]]] res += QR.Fundamental()(Composition(from_subset=(descents, n))) return res FinitePoset._dual_class = FinitePoset ##### Posets #####