def to_symmetric_function(self): r""" Takes a quasi-symmetric function, expressed in the monomial basis, and returns its symmetric realization, when possible, expressed in the monomial basis of symmetric functions. OUTPUT: - If ``self`` is a symmetric function, then the expansion in the monomial basis of the symmetric functions is returned. Otherwise an error is raised. EXAMPLES:: sage: QSym = QuasiSymmetricFunctions(QQ) sage: M = QSym.Monomial() sage: (M[3,2] + M[2,3] + M[4,1]).to_symmetric_function() Traceback (most recent call last): ... ValueError: M[2, 3] + M[3, 2] + M[4, 1] is not a symmetric function sage: (M[3,2] + M[2,3] + 2*M[4,1] + 2*M[1,4]).to_symmetric_function() m[3, 2] + 2*m[4, 1] sage: m = SymmetricFunctions(QQ).m() sage: M(m[3,1,1]).to_symmetric_function() m[3, 1, 1] sage: (M(m[2,1])*M(m[2,1])).to_symmetric_function()-m[2,1]*m[2,1] 0 TESTS:: sage: (M(0)).to_symmetric_function() 0 sage: (M([])).to_symmetric_function() m[] sage: (2*M([])).to_symmetric_function() 2*m[] """ m = SymmetricFunctions(self.parent().base_ring()).monomial() if self.is_symmetric(): return m.sum_of_terms( [(I, coeff) for (I, coeff) in self if list(I) in Partitions()], distinct=True) else: raise ValueError, "%s is not a symmetric function" % self
def to_symmetric_function( self ): r""" Takes a quasi-symmetric function, expressed in the monomial basis, and returns its symmetric realization, when possible, expressed in the monomial basis of symmetric functions. OUTPUT: - If ``self`` is a symmetric function, then the expansion in the monomial basis of the symmetric functions is returned. Otherwise an error is raised. EXAMPLES:: sage: QSym = QuasiSymmetricFunctions(QQ) sage: M = QSym.Monomial() sage: (M[3,2] + M[2,3] + M[4,1]).to_symmetric_function() Traceback (most recent call last): ... ValueError: M[2, 3] + M[3, 2] + M[4, 1] is not a symmetric function sage: (M[3,2] + M[2,3] + 2*M[4,1] + 2*M[1,4]).to_symmetric_function() m[3, 2] + 2*m[4, 1] sage: m = SymmetricFunctions(QQ).m() sage: M(m[3,1,1]).to_symmetric_function() m[3, 1, 1] sage: (M(m[2,1])*M(m[2,1])).to_symmetric_function()-m[2,1]*m[2,1] 0 TESTS:: sage: (M(0)).to_symmetric_function() 0 sage: (M([])).to_symmetric_function() m[] sage: (2*M([])).to_symmetric_function() 2*m[] """ m = SymmetricFunctions(self.parent().base_ring()).monomial() if self.is_symmetric(): return m.sum_of_terms([(I, coeff) for (I, coeff) in self if list(I) in Partitions()], distinct=True) else: raise ValueError, "%s is not a symmetric function"%self
def to_symmetric_function(self): r""" Return the image of ``self`` under the natural projection map to `Sym`. The natural projection map `FSym \to Sym` sends each standard tableau `t` to the Schur function `s_\lambda`, where `\lambda` is the shape of `t`. This map is a surjective Hopf algebra homomorphism. EXAMPLES:: sage: FSym = algebras.FSym(QQ) sage: G = FSym.G() sage: t = StandardTableau([[1,3],[2,4],[5]]) sage: G[t].to_symmetric_function() s[2, 2, 1] """ s = SymmetricFunctions(self.parent().base_ring()).s() return s.sum_of_terms((t.shape(), coeff) for t, coeff in self)
def to_symmetric_function(self): r""" Take a function in the `\mathbf{w}` basis, and return its symmetric realization, when possible, expressed in the homogeneous basis of symmetric functions. OUTPUT: - If ``self`` is a symmetric function, then the expansion in the homogeneous basis of the symmetric functions is returned. Otherwise an error is raised. EXAMPLES:: sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: elt = w[[1],[2,3]] + w[[1,2],[3]] + w[[1,3],[2]] sage: elt.to_symmetric_function() h[2, 1] sage: elt = w.sum_of_partitions([2,1,1]) / 2 sage: elt.to_symmetric_function() 1/2*h[2, 1, 1] TESTS:: sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: w(0).to_symmetric_function() 0 sage: w([]).to_symmetric_function() h[] sage: (2*w([])).to_symmetric_function() 2*h[] """ if not self.is_symmetric(): raise ValueError("not a symmetric function") h = SymmetricFunctions(self.parent().base_ring()).homogeneous() d = {A.shape(): c for A, c in self} return h.sum_of_terms( [(AA, cc / prod(map(factorial, AA.to_exp()))) for AA, cc in d.items()], distinct=True)
def to_symmetric_function(self): r""" Take a function in the `\mathbf{w}` basis, and return its symmetric realization, when possible, expressed in the homogeneous basis of symmetric functions. OUTPUT: - If ``self`` is a symmetric function, then the expansion in the homogeneous basis of the symmetric functions is returned. Otherwise an error is raised. EXAMPLES:: sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: elt = w[[1],[2,3]] + w[[1,2],[3]] + w[[1,3],[2]] sage: elt.to_symmetric_function() h[2, 1] sage: elt = w.sum_of_partitions([2,1,1]) / 2 sage: elt.to_symmetric_function() 1/2*h[2, 1, 1] TESTS:: sage: w = SymmetricFunctionsNonCommutingVariables(QQ).dual().w() sage: w(0).to_symmetric_function() 0 sage: w([]).to_symmetric_function() h[] sage: (2*w([])).to_symmetric_function() 2*h[] """ if not self.is_symmetric(): raise ValueError("not a symmetric function") h = SymmetricFunctions(self.parent().base_ring()).homogeneous() d = {A.shape(): c for A, c in self} return h.sum_of_terms( [(AA, cc / prod(map(factorial, AA.to_exp()))) for AA, cc in d.items()], distinct=True )
def cycle_index(self, parent=None): r""" Return the *cycle index* of ``self``. INPUT: - ``self`` - a permutation group `G` - ``parent`` -- a free module with basis indexed by partitions, or behave as such, with a ``term`` and ``sum`` method (default: the symmetric functions over the rational field in the `p` basis) The *cycle index* of a permutation group `G` (:wikipedia:`Cycle_index`) is a gadget counting the elements of `G` by cycle type, averaged over the group: .. MATH:: P = \frac{1}{|G|} \sum_{g\in G} p_{ \operatorname{cycle\ type}(g) } EXAMPLES: Among the permutations of the symmetric group `S_4`, there is the identity, 6 cycles of length 2, 3 products of two cycles of length 2, 8 cycles of length 3, and 6 cycles of length 4:: sage: S4 = SymmetricGroup(4) sage: P = S4.cycle_index() sage: 24 * P p[1, 1, 1, 1] + 6*p[2, 1, 1] + 3*p[2, 2] + 8*p[3, 1] + 6*p[4] If `l = (l_1,\dots,l_k)` is a partition, ``|G| P[l]`` is the number of elements of `G` with cycles of length `(p_1,\dots,p_k)`:: sage: 24 * P[ Partition([3,1]) ] 8 The cycle index plays an important role in the enumeration of objects modulo the action of a group (Pólya enumeration), via the use of symmetric functions and plethysms. It is therefore encoded as a symmetric function, expressed in the powersum basis:: sage: P.parent() Symmetric Functions over Rational Field in the powersum basis This symmetric function can have some nice properties; for example, for the symmetric group `S_n`, we get the complete symmetric function `h_n`:: sage: S = SymmetricFunctions(QQ); h = S.h() sage: h( P ) h[4] .. TODO:: Add some simple examples of Pólya enumeration, once it will be easy to expand symmetric functions on any alphabet. Here are the cycle indices of some permutation groups:: sage: 6 * CyclicPermutationGroup(6).cycle_index() p[1, 1, 1, 1, 1, 1] + p[2, 2, 2] + 2*p[3, 3] + 2*p[6] sage: 60 * AlternatingGroup(5).cycle_index() p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] sage: for G in TransitiveGroups(5): # long time ....: G.cardinality() * G.cycle_index() p[1, 1, 1, 1, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 10*p[4, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] p[1, 1, 1, 1, 1] + 10*p[2, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 20*p[3, 2] + 30*p[4, 1] + 24*p[5] Permutation groups with arbitrary domains are supported (see :trac:`22765`):: sage: G = PermutationGroup([['b','c','a']], domain=['a','b','c']) sage: G.cycle_index() 1/3*p[1, 1, 1] + 2/3*p[3] One may specify another parent for the result:: sage: F = CombinatorialFreeModule(QQ, Partitions()) sage: P = CyclicPermutationGroup(6).cycle_index(parent = F) sage: 6 * P B[[1, 1, 1, 1, 1, 1]] + B[[2, 2, 2]] + 2*B[[3, 3]] + 2*B[[6]] sage: P.parent() is F True This parent should be a module with basis indexed by partitions:: sage: CyclicPermutationGroup(6).cycle_index(parent = QQ) Traceback (most recent call last): ... ValueError: `parent` should be a module with basis indexed by partitions REFERENCES: - [Ke1991]_ AUTHORS: - Nicolas Borie and Nicolas M. Thiéry TESTS:: sage: P = PermutationGroup([]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] sage: P = PermutationGroup([[(1)]]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] """ from sage.categories.modules import Modules if parent is None: from sage.rings.rational_field import QQ from sage.combinat.sf.sf import SymmetricFunctions parent = SymmetricFunctions(QQ).powersum() elif not parent in Modules.WithBasis: raise ValueError( "`parent` should be a module with basis indexed by partitions" ) base_ring = parent.base_ring() return parent.sum_of_terms( [C.an_element().cycle_type(), base_ring(C.cardinality())] for C in self.conjugacy_classes()) / self.cardinality()
def cycle_index(self, parent = None): r""" Return the *cycle index* of ``self``. INPUT: - ``self`` - a permutation group `G` - ``parent`` -- a free module with basis indexed by partitions, or behave as such, with a ``term`` and ``sum`` method (default: the symmetric functions over the rational field in the `p` basis) The *cycle index* of a permutation group `G` (:wikipedia:`Cycle_index`) is a gadget counting the elements of `G` by cycle type, averaged over the group: .. MATH:: P = \frac{1}{|G|} \sum_{g\in G} p_{ \operatorname{cycle\ type}(g) } EXAMPLES: Among the permutations of the symmetric group `S_4`, there is the identity, 6 cycles of length 2, 3 products of two cycles of length 2, 8 cycles of length 3, and 6 cycles of length 4:: sage: S4 = SymmetricGroup(4) sage: P = S4.cycle_index() sage: 24 * P p[1, 1, 1, 1] + 6*p[2, 1, 1] + 3*p[2, 2] + 8*p[3, 1] + 6*p[4] If `l = (l_1,\dots,l_k)` is a partition, ``|G| P[l]`` is the number of elements of `G` with cycles of length `(p_1,\dots,p_k)`:: sage: 24 * P[ Partition([3,1]) ] 8 The cycle index plays an important role in the enumeration of objects modulo the action of a group (Pólya enumeration), via the use of symmetric functions and plethysms. It is therefore encoded as a symmetric function, expressed in the powersum basis:: sage: P.parent() Symmetric Functions over Rational Field in the powersum basis This symmetric function can have some nice properties; for example, for the symmetric group `S_n`, we get the complete symmetric function `h_n`:: sage: S = SymmetricFunctions(QQ); h = S.h() sage: h( P ) h[4] .. TODO:: Add some simple examples of Pólya enumeration, once it will be easy to expand symmetric functions on any alphabet. Here are the cycle indices of some permutation groups:: sage: 6 * CyclicPermutationGroup(6).cycle_index() p[1, 1, 1, 1, 1, 1] + p[2, 2, 2] + 2*p[3, 3] + 2*p[6] sage: 60 * AlternatingGroup(5).cycle_index() p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] sage: for G in TransitiveGroups(5): # optional - database_gap # long time ....: G.cardinality() * G.cycle_index() p[1, 1, 1, 1, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 10*p[4, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] p[1, 1, 1, 1, 1] + 10*p[2, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 20*p[3, 2] + 30*p[4, 1] + 24*p[5] Permutation groups with arbitrary domains are supported (see :trac:`22765`):: sage: G = PermutationGroup([['b','c','a']], domain=['a','b','c']) sage: G.cycle_index() 1/3*p[1, 1, 1] + 2/3*p[3] One may specify another parent for the result:: sage: F = CombinatorialFreeModule(QQ, Partitions()) sage: P = CyclicPermutationGroup(6).cycle_index(parent = F) sage: 6 * P B[[1, 1, 1, 1, 1, 1]] + B[[2, 2, 2]] + 2*B[[3, 3]] + 2*B[[6]] sage: P.parent() is F True This parent should be a module with basis indexed by partitions:: sage: CyclicPermutationGroup(6).cycle_index(parent = QQ) Traceback (most recent call last): ... ValueError: `parent` should be a module with basis indexed by partitions REFERENCES: - [Ke1991]_ AUTHORS: - Nicolas Borie and Nicolas M. Thiéry TESTS:: sage: P = PermutationGroup([]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] sage: P = PermutationGroup([[(1)]]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] """ from sage.categories.modules import Modules if parent is None: from sage.rings.rational_field import QQ from sage.combinat.sf.sf import SymmetricFunctions parent = SymmetricFunctions(QQ).powersum() elif not parent in Modules.WithBasis: raise ValueError("`parent` should be a module with basis indexed by partitions") base_ring = parent.base_ring() return parent.sum_of_terms([C.an_element().cycle_type(), base_ring(C.cardinality())] for C in self.conjugacy_classes() ) / self.cardinality()