Ticket #14111: trac_14111-qsym_tutorial-sb.patch

File trac_14111-qsym_tutorial-sb.patch, 15.1 KB (added by billey, 8 years ago)
  • doc/en/reference/combinat/ncsf_qsym.rst

    # HG changeset patch
    # User Sara Billey <billey@math.washington.edu>
    # Date 1362103878 28800
    # Node ID e08dcba42369938033c098524510eb3687006b98
    # Parent  ec1fb07db6e23f9fbd4c34f0d48198d08ec76473
    #14111: Tutorial for quasisymmetric functions (QSYM)
    
    diff --git a/doc/en/reference/combinat/ncsf_qsym.rst b/doc/en/reference/combinat/ncsf_qsym.rst
    a b  
    44.. toctree::
    55   :maxdepth: 2
    66
     7   ../sage/combinat/ncsf_qsym/tutorial
    78   ../sage/combinat/ncsf_qsym/combinatorics
    89   ../sage/combinat/ncsf_qsym/generic_basis_code
    910   ../sage/combinat/ncsf_qsym/ncsf
  • sage/combinat/ncsf_qsym/__init__.py

    diff --git a/sage/combinat/ncsf_qsym/__init__.py b/sage/combinat/ncsf_qsym/__init__.py
    a b  
    1 
     1import tutorial
  • new file sage/combinat/ncsf_qsym/tutorial.py

    diff --git a/sage/combinat/ncsf_qsym/tutorial.py b/sage/combinat/ncsf_qsym/tutorial.py
    new file mode 100755
    - +  
     11# -*- coding: utf-8 -*-
     2r"""
     3=====================================
     4Tutorial for Quasisymmetric Functions
     5=====================================
     6
     7In this document we briefly explain the quasisymmetric function bases and related functionality in Sage.   We assume the reader is familar with the package
     8:class:`SymmetricFunctions`
     9
     10Quasisymmetric functions, denoted QSym, form a subring of the power
     11series ring in countably many variables.  QSym contains the symmetric
     12functions.  These functions first arose in the theory of
     13$P$-partitions.  The initial ideas in this field are attributed to
     14MacMahon, Knuth, Kreweras, Glâffrwd Thomas, Stanley.  In 1984, Gessel
     15formalized the study of quasisymmetric functions and introduced the
     16basis of fundamental quasisymmetric functions.  In 1995, Gelfand,
     17Krob, Lascoux, Leclerc, Retakh, and Thibon showed that the ring of
     18quasisymmetric functions is Hopf dual to the noncommutative symmetric
     19functions.  Many results have built on these.   
     20
     21
     22
     23One advantage of working in QSym is that many
     24interesting families of symmetric functions have explicit expansions
     25in fundamental quasisymmetric functions such as Schur functions
     26[Ges]_, Macdonald polynomials [Haiman-Haglund-Loehr], and plethysm of
     27Schur functions [Loehr-Warrington].
     28
     29For more background see :wikipedia:`Quasisymmetric_function`.
     30
     31To begin, initialize the ring.  Below we chose to use the rational
     32numbers `\QQ`.  Other options include the integers `\ZZ` and `\CC`::
     33
     34    sage: QSym = QuasiSymmetricFunctions(QQ)
     35    sage: QSym
     36    Quasisymmetric functions over the Rational Field
     37
     38    sage: QSym = QuasiSymmetricFunctions(CC); QSym
     39    Quasisymmetric functions over the Complex Field with 53 bits of precision
     40
     41    sage: QSym = QuasiSymmetricFunctions(ZZ); QSym
     42    Quasisymmetric functions over the Integer Ring
     43
     44All bases of QSym are indexed by compositions e.g. `[3,1,1,4]`.  The
     45convention is to use capitol letters for bases of QSym and lowercase
     46letters for bases of Sym.  Next set up names for the  known bases by running
     47:meth:`QuasiSymmetricFunctions.inject_shorthands`. 
     48As with symmetric functions, you do not need to run this commmand and
     49you could assign these bases other names.  ::
     50
     51    sage: QSym = QuasiSymmetricFunctions(QQ)
     52    sage: QSym.inject_shorthands()
     53    Injecting M as shorthand for Quasisymmetric functions over the Rational Field in the Monomial basis
     54    Injecting F as shorthand for Quasisymmetric functions over the Rational Field in the Fundamental basis
     55    Injecting dI as shorthand for Quasisymmetric functions over the Rational Field in the dualImmaculate basis
     56
     57
     58Now one can start constructing quasisymmetric functions.  Note, it is best to use variables other than M,F.  ::
     59
     60    sage: x = M[2,1]+M[1,2]
     61    sage: x
     62    M[1, 2] + M[2, 1]
     63
     64    sage: y=3*M[1,2]+M[3]^2; y
     65    3*M[1, 2] + 2*M[3, 3] + M[6]
     66
     67    sage: F[3,1,3]+7*F[2,1]
     68    7*F[2, 1] + F[3, 1, 3]
     69
     70    sage: 3*F[2,1,2]+F[3]^2
     71    F[1, 2, 2, 1] + F[1, 2, 3] + 2*F[1, 3, 2] + F[1, 4, 1] + F[1, 5] + 3*F[2, 1, 2] + 2*F[2, 2, 2] + 2*F[2, 3, 1] + 2*F[2, 4] + F[3, 2, 1] + 3*F[3, 3] + 2*F[4, 2] + F[5, 1] + F[6]
     72
     73To convert from one basis to another is easy::
     74
     75
     76    sage: z=M[1,2,1]
     77    sage: z
     78    M[1, 2, 1]
     79
     80    sage: F(z)
     81    -F[1, 1, 1, 1] + F[1, 2, 1]
     82
     83    sage: M(F(z))
     84    M[1, 2, 1]
     85
     86To expand in variables, one can specify a finite size alphabet $x_1,x_2,\ldots, x_m$. ::
     87
     88    sage: y=M[1,2,1]
     89    sage: y.expand(4)
     90    x0*x1^2*x2 + x0*x1^2*x3 + x0*x2^2*x3 + x1*x2^2*x3
     91
     92The usual methods on free modules are available such as coefficients, degrees, and the support. ::
     93
     94    sage: z=3*M[1,2]+M[3]^2; z
     95    3*M[1, 2] + 2*M[3, 3] + M[6]
     96
     97    sage: z.coefficient([1,2])
     98    3
     99
     100    sage: z.degree()
     101    6
     102
     103    sage: z.coefficients()
     104    [3, 2, 1]
     105
     106    sage: z.monomials()
     107    [M[1, 2], M[3, 3], M[6]]
     108
     109    sage: z.monomial_coefficients()
     110    {[3, 3]: 2, [1, 2]: 3, [6]: 1}
     111
     112As with the symmetric functions package, the quasisymmetric function 1
     113has several instantiations.  However, the most obvious way to write 1
     114leads to an error::
     115
     116    sage: M[[]]
     117    M[]
     118    sage: M.one()
     119    M[]
     120    sage: M(1)
     121    M[]
     122    sage: M[[]] == 1
     123    True
     124    sage: M[]
     125    Traceback (most recent call last):
     126    ...
     127    SyntaxError: invalid syntax
     128
     129
     130Working with symmetric functions
     131--------------------------------
     132
     133The quasisymmetric functions are a ring which contains the symmetric
     134functions as a subring.  The Monomial quasisymmetric functions are
     135related to the monomial symmetric functions by `m_\lambda =
     136\sum_{sort(c) = \lambda} M_c~`::
     137
     138    sage: SymmetricFunctions(QQ).inject_shorthands()
     139    doctest:1075: RuntimeWarning: redefining global value `e`
     140    doctest:1075: RuntimeWarning: redefining global value `m`
     141    sage: m[2,1]
     142    m[2, 1]
     143    sage: M(m[2,1])
     144    M[1, 2] + M[2, 1]
     145    sage: M(s[2,1])
     146    2*M[1, 1, 1] + M[1, 2] + M[2, 1]
     147
     148There are methods to test if an expression in the quasisymmetric functions is a symmetric
     149function and, if it is, send it to an expression in the symmetric functions.
     150::
     151
     152    sage: f = M[1,1,2] + M[1,2,1]
     153    sage: f.is_symmetric()
     154    False
     155    sage: g = M[3,1] + M[1,3]
     156    sage: g.is_symmetric()
     157    True
     158    sage: g.to_symmetric_function()
     159    m[3, 1]
     160
     161The expansion of the Schur function in terms of the Fundamental quasisymmetric
     162functions is due to [Ges]_.  There is one term in the expansion for each standard
     163tableau of shape equal to the partition indexing the Schur function.
     164::
     165
     166    sage: f = F[3,2] + F[2,2,1] + F[2,3] + F[1,3,1] + F[1,2,2]
     167    sage: f.is_symmetric()
     168    True
     169    sage: f.to_symmetric_function()
     170    5*m[1, 1, 1, 1, 1] + 3*m[2, 1, 1, 1] + 2*m[2, 2, 1] + m[3, 1, 1] + m[3, 2]
     171    sage: s(f.to_symmetric_function())
     172    s[3, 2]
     173
     174It is also possible to convert any symmetric function to the quasisymmetric function expansion in any known basis.  The converse is not true
     175::
     176
     177    sage: M( m[3,1,1] )
     178    M[1, 1, 3] + M[1, 3, 1] + M[3, 1, 1]
     179    sage: F( s[2,2,1] )
     180    F[1, 1, 2, 1] + F[1, 2, 1, 1] + F[1, 2, 2] + F[2, 1, 2] + F[2, 2, 1]
     181
     182    sage: s(M[2,1])
     183    Traceback (most recent call last):
     184    ...
     185    TypeError: do not know how to make x (= M[2, 1]) an element of self
     186
     187It is possible to experiment with the quasisymmetric function expansion of other
     188bases, but it is important that the base ring be the same for both algebras.
     189::
     190
     191    sage: R = QQ['t']
     192    sage: Qp = SymmetricFunctions(R).hall_littlewood().Qp()
     193    sage: QSymt = QuasiSymmetricFunctions(R)
     194    sage: Ft = QSymt.F()
     195    sage: Ft( Qp[2,2] )
     196    F[1, 2, 1] + t*F[1, 3] + (t+1)*F[2, 2] + t*F[3, 1] + t^2*F[4]
     197
     198::
     199
     200    sage: K = QQ['q','t'].fraction_field()
     201    sage: Ht = SymmetricFunctions(K).macdonald().Ht()
     202    sage: Fqt = QuasiSymmetricFunctions(Ht.base_ring()).F()
     203    sage: Fqt(Ht[2,1])
     204    q*t*F[1, 1, 1] + (q+t)*F[1, 2] + (q+t)*F[2, 1] + F[3]
     205
     206The following will raise an error because the base ring of ``F`` is not
     207equal to the base ring of ``Ht``
     208::
     209
     210    sage: F(Ht[2,1])
     211    Traceback (most recent call last):
     212    ...
     213    TypeError: do not know how to make x (= McdHt[2, 1]) an element of self (=Quasisymmetric functions over the Rational Field in the Fundamental basis)
     214
     215QSym is a Hopf algebra
     216----------------------
     217
     218The product on this space is commutative and is inherited from the
     219product by the realization within the polynomial ring::
     220
     221    sage: M[3]*M[1,1] == M[1,1]*M[3]
     222    True
     223    sage: M[3]*M[1,1]
     224    M[1, 1, 3] + M[1, 3, 1] + M[1, 4] + M[3, 1, 1] + M[4, 1]
     225    sage: F[3]*F[1,1]
     226    F[1, 1, 3] + F[1, 2, 2] + F[1, 3, 1] + F[1, 4] + F[2, 1, 2] + F[2, 2, 1] + F[2, 3] + F[3, 1, 1] + F[3, 2] + F[4, 1]
     227    sage: M[3]*F[2]
     228    M[1, 1, 3] + M[1, 3, 1] + M[1, 4] + M[2, 3] + M[3, 1, 1] + M[3, 2] + M[4, 1] + M[5]
     229    sage: F[2]*M[3]
     230    F[1, 1, 1, 2] - F[1, 2, 2] + F[2, 1, 1, 1] - F[2, 1, 2] - F[2, 2, 1] + F[5]
     231
     232There is a coproduct on this ring as well, which in the Monomial basis acts by
     233cutting the composition into a left half and a right half.  The
     234co-product is non-co-commutative
     235::
     236
     237    sage: M[1,3,1].coproduct()
     238    M[] # M[1, 3, 1] + M[1] # M[3, 1] + M[1, 3] # M[1] + M[1, 3, 1] # M[]
     239    sage: F[1,3,1].coproduct()
     240    F[] # F[1, 3, 1] + F[1] # F[3, 1] + F[1, 1] # F[2, 1] + F[1, 2] # F[1, 1] + F[1, 3] # F[1] + F[1, 3, 1] # F[]
     241
     242.. rubric:: The duality pairing with non-commutative symmetric functions
     243
     244These two operations endow the quasisymmetric functions `QSym` with the
     245structure of a Hopf algebra. It is the dual Hopf algebra of the
     246non-commutative symmetric functions `NCSF`. Under this duality, the
     247Monomial basis of `QSym` is dual to the Complete basis of `NCSF`, and the
     248Fundamental basis of `QSym` is dual to the Ribbon basis of `NCSF` (see
     249[MR]_)
     250::
     251
     252    sage: S = M.dual(); S
     253    Non-Commutative Symmetric Functions over the Rational Field in the Complete basis
     254    sage: M[1,3,1].duality_pairing( S[1,3,1] )
     255    1
     256    sage: M.duality_pairing_matrix( S, degree=4 )
     257    [1 0 0 0 0 0 0 0]
     258    [0 1 0 0 0 0 0 0]
     259    [0 0 1 0 0 0 0 0]
     260    [0 0 0 1 0 0 0 0]
     261    [0 0 0 0 1 0 0 0]
     262    [0 0 0 0 0 1 0 0]
     263    [0 0 0 0 0 0 1 0]
     264    [0 0 0 0 0 0 0 1]
     265    sage: F.duality_pairing_matrix( S, degree=4 )
     266    [1 0 0 0 0 0 0 0]
     267    [1 1 0 0 0 0 0 0]
     268    [1 0 1 0 0 0 0 0]
     269    [1 1 1 1 0 0 0 0]
     270    [1 0 0 0 1 0 0 0]
     271    [1 1 0 0 1 1 0 0]
     272    [1 0 1 0 1 0 1 0]
     273    [1 1 1 1 1 1 1 1]
     274    sage: NCSF = M.realization_of().dual()
     275    sage: R = NCSF.Ribbon()
     276    sage: F.duality_pairing_matrix( R, degree=4 )
     277    [1 0 0 0 0 0 0 0]
     278    [0 1 0 0 0 0 0 0]
     279    [0 0 1 0 0 0 0 0]
     280    [0 0 0 1 0 0 0 0]
     281    [0 0 0 0 1 0 0 0]
     282    [0 0 0 0 0 1 0 0]
     283    [0 0 0 0 0 0 1 0]
     284    [0 0 0 0 0 0 0 1]
     285    sage: M.duality_pairing_matrix( R, degree=4 )
     286    [ 1  0  0  0  0  0  0  0]
     287    [-1  1  0  0  0  0  0  0]
     288    [-1  0  1  0  0  0  0  0]
     289    [ 1 -1 -1  1  0  0  0  0]
     290    [-1  0  0  0  1  0  0  0]
     291    [ 1 -1  0  0 -1  1  0  0]
     292    [ 1  0 -1  0 -1  0  1  0]
     293    [-1  1  1 -1  1 -1 -1  1]
     294
     295Let `H` and `G` be elements of `QSym` and `h` an element of `NCSF`. Then if
     296we represent the duality pairing with the mathematical notation `[ \cdot,
     297\cdot ]`,
     298
     299`[H G, h] = [H \otimes G, \Delta(h)]~.`
     300
     301For example, the coefficient of ``M[2,1,4,1]`` in ``M[1,3]*M[2,1,1]`` may be
     302computed with the duality pairing::
     303
     304    sage: I, J = Composition([1,3]), Composition([2,1,1])
     305    sage: (M[I]*M[J]).duality_pairing(S[2,1,4,1])
     306    1
     307
     308And the coefficient of ``S[1,3] # S[2,1,1]`` in ``S[2,1,4,1].coproduct()`` is
     309equal to this result
     310::
     311
     312    sage: S[2,1,4,1].coproduct()
     313    S[] # S[2, 1, 4, 1] + ... + S[1, 3] # S[2, 1, 1] + ... + S[4, 1] # S[2, 1]
     314
     315The duality pairing on the tensor space is another way of getting this
     316coefficient, but currently the method ``duality_pairing`` is not defined on
     317the tensor squared space. However, we can extend this functionality by
     318applying a linear morphism to the terms in the coproduct, as follows
     319::
     320
     321    sage: X = S[2,1,4,1].coproduct()
     322    sage: def linear_morphism(x, y):
     323    ...     return x.duality_pairing(M[1,3]) * y.duality_pairing(M[2,1,1])
     324    sage: X.apply_multilinear_morphism(linear_morphism, codomain=ZZ)
     325    1
     326
     327Similarly, if `H` is an element of `QSym` and `g` and `h` are elements of `NCSF`,
     328then
     329
     330`[ H, g h ] = [ \Delta(H), g \otimes h ]~.`
     331
     332For example, the coefficient of ``R[2,3,1]`` in ``R[2,1]*R[2,1]`` is computed with
     333the duality pairing by the following command
     334::
     335
     336    sage: (R[2,1]*R[2,1]).duality_pairing(F[2,3,1])
     337    1
     338    sage: R[2,1]*R[2,1]
     339    R[2, 1, 2, 1] + R[2, 3, 1]
     340
     341This coefficient should then be equal to the coefficient of ``F[2,1] # F[2,1]``
     342in ``F[2,3,1].coproduct()``
     343::
     344
     345    sage: F[2,3,1].coproduct()
     346    F[] # F[2, 3, 1] + ... + F[2, 1] # F[2, 1]  + ... + F[2, 3, 1] # F[]
     347
     348This can also be computed by the duality pairing on the tensor space,
     349as above
     350::
     351
     352    sage: X = F[2,3,1].coproduct()
     353    sage: def linear_morphism(x, y):
     354    ...     return x.duality_pairing(R[2,1]) * y.duality_pairing(R[2,1])
     355    sage: X.apply_multilinear_morphism(linear_morphism, codomain=ZZ)
     356    1
     357
     358.. rubric:: The operation adjoint to multiplication by a non-commutative symmetric function
     359
     360Let `g \in NCSF` and consider the linear endomorphism of `NCSF` defined by
     361left (respectively, right) multiplication by `g`. Since there is a duality
     362between `QSym` and `NCSF`, this linear transformation induces an operator
     363`g^\perp` on `QSym` satisfying
     364
     365`[ g^\perp(H), h ] = [ H, gh ]~.`
     366
     367for any non-commutative symmetric function `h`.
     368
     369This is implemented by the method :meth:`~sage.combinat.ncsf_qsym.generic_basis_code.BasesOfQSymOrNCSF.ElementMethods.skew_by`.
     370Explicitly, if ``H`` is a quasisymmetric function and ``g``
     371a non-commutative symmetric function, then ``H.skew_by(g)`` and
     372``H.skew_by(g, side='right')`` are expressions that satisfy
     373for any non-commutative symmetric function ``h``
     374
     375::
     376
     377    H.skew_by(g).duality_pairing(h) == H.duality_pairing(g*h)
     378    H.skew_by(g, side='right').duality_pairing(h) == H.duality_pairing(h*g)
     379
     380For example, ``M[J].skew_by(S[I])`` is `0` unless the composition ``J``
     381begins with ``I`` and ``M(J).skew_by(S(I), side='right')`` is `0` unless
     382the composition ``J`` ends with ``I``
     383
     384::
     385
     386    sage: M[3,2,2].skew_by(S[3])
     387    M[2, 2]
     388    sage: M[3,2,2].skew_by(S[2])
     389    0
     390    sage: M[3,2,2].coproduct().apply_multilinear_morphism( lambda x,y: x.duality_pairing(S[3])*y )
     391    M[2, 2]
     392    sage: M[3,2,2].skew_by(S[3], side='right')
     393    0
     394    sage: M[3,2,2].skew_by(S[2], side='right')
     395    M[3, 2]
     396
     397.. rubric:: The antipode
     398
     399The antipode sends the Fundamental basis element indexed by the
     400composition `I` to `-1` to the size of `I` times the Fundamental
     401basis element indexed by the conjugate composition to `I`
     402::
     403
     404    sage: F[3,2,2].antipode()
     405    -F[1, 2, 2, 1, 1]
     406    sage: Composition([3,2,2]).conjugate()
     407    [1, 2, 2, 1, 1]
     408    sage: M[3,2,2].antipode()
     409    -M[2, 2, 3] - M[2, 5] - M[4, 3] - M[7]
     410
     411We demonstrate here the defining relation of the antipode::
     412
     413    sage: X = F[3,2,2].coproduct()
     414    sage: X.apply_multilinear_morphism(lambda x,y: x*y.antipode())
     415    0
     416    sage: X.apply_multilinear_morphism(lambda x,y: x.antipode()*y)
     417    0
     418
     419"""