% $Id: partitions.tex,v 1.1.1.7 2005/01/26 13:42:24 nthiery Exp $
\begin{Mhelppage}{partitions}{F.~Hivert and N.~Thiéry}
  [ImplState=stable,TestState=stable,DocState=stable]
\Mproofread{teresa}{10/2003}{proofread}

\begin{MInfo}
  \eng{partitions of an integer}
\end{MInfo}

\MDeclareOption{\MinLength}{MinLength}
\MDeclareOption{\MaxLength}{MaxLength}
\MDeclareOption{\Length}{Length}
\MDeclareOption{\MinPart}{MinPart}
\MDeclareOption{\MaxPart}{MaxPart}
\MDeclareOption{\Inner}{Inner}
\MDeclareOption{\Outer}{Outer}
\MDeclareOption{\MinSlope}{MinSlope}
\MDeclareOption{\MaxSlope}{MaxSlope}

\begin{MIntro}
  \eng{The library \Mthis{} provides functions for counting,
    generating, and manipulating partitions.}
\end{MIntro}

\MKeywords{combinatorics,partition}

\begin{MDetails}
  \eng{A \emph{partition} \Mex{p} of a nonnegative integer \Mpar{n} is
    a non-increasing list of positive integers (the \emph{parts} of the
    partition) with total sum \Mpar{n}.}
  
  \eng{All functions for counting and generating accept the following
    optional constraints on the partitions: \MinLength, \MaxLength,
    \Length, \MinPart, \MaxPart, \Inner, \Outer, \MinSlope, and
    \MaxSlope.  Cf.\ examples~\ref{ex-constraints-length},
    \ref{ex-constraints-parts}, \ref{ex-constraints-inclusion},
    \ref{ex-constraints-slope}, \ref{ex-constraints-advanced}, and
    \ref{ex-constraints-regular}.}
  
  \eng{A partition can be depicted by a diagram made of rows of boxes,
    where the number of boxes in the $i$-th row starting from the
    bottom is the $i$-th part of the partition. For example, this is
    the diagram of the partition \Mex{[5,3,1]}:
    \Mdmath{%
+---+
|   |
+---+---+---+
|   |   |   |
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+---+---+---+
        }
      {\begin{array}{l}
        \fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\fbox{\phantom{1}}\fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\fbox{\phantom{1}}\fbox{\phantom{1}}
        \fbox{\phantom{1}}\fbox{\phantom{1}}\\[-1pt]
      \end{array}}
    
    Applying a reflection w.r.t. the main diagonal to this diagram
    yields the diagram of the \emph{conjugate partition}, here
    \Mex{[3,2,2,1,1]}:
    \Mdmath{%
+---+
|   |
+---+
|   |
+---+---+
|   |   |
+---+---+
|   |   |
+---+---+---+
|   |   |   |
+---+---+---+
        }
      {\begin{array}{l}
        \fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\fbox{\phantom{1}}\\[-1pt]
        \fbox{\phantom{1}}\fbox{\phantom{1}}\fbox{\phantom{1}}\\[-1pt]
      \end{array}}
    See \Mup{combinat::partitions::conjugate}.}
  
\end{MDetails}

\begin{MCategories}
\Mup{Cat::IntegerListsLexClass}
\end{MCategories}

\MRelatedDomains{combinat::compositions, combinat::tableaux}

\begin{MDomEntries}
  \MDomEntry{domtype}
  \eng{The \mupad\ domain used to represent partitions: \Mup{DOM_LIST}}
\end{MDomEntries}

\begin{MMethodDetails}{isA}
  \infoEng{test if an object is a partition}
  \call{\Mtype{any type} part\Mopt{, \Mtype{nonnegative integer} n\Mopt{, constraints}}}
  \eng{Returns whether \Mpar{part} is a partition.}
  \eng{If the optional argument \Mpar{n} is present, returns whether \Mpar{part} is a
   partition of \Mpar{n}.}
  \eng{If constraints are given, returns whether \Mpar{part} is a partition
       satisfying \Mpar{constraints}.}
\end{MMethodDetails}

\begin{MMethodDetails}{count}
  \infoEng{number of partitions}
  \call{\Mtype{nonnegative integer} n \Mopt{, constraints}}
  \eng{Returns the number of partitions of \Mpar{n} satisfying
    \Mpar{constraints}.}
\end{MMethodDetails}

\begin{MMethodDetails}{generator}
  \infoEng{generator for partitions}
  \call{\Mtype{nonnegative integer} n \Mopt{, constraints}}
  \eng{Returns a generator for the partitions of \Mpar{n} satisfying
    \Mpar{constraints}.}
\end{MMethodDetails}

\begin{MMethodDetails}{list}
  \infoEng{list of the partitions}
  \call{\Mtype{nonnegative integer} n \Mopt{, constraints}}
  \eng{Returns the list of the partitions of \Mpar{n} satisfying
    \Mpar{constraints}.}
\end{MMethodDetails}

\begin{MMethodDetails}{first}
  \infoEng{first partition}
  \call{\Mtype{nonnegative integer} n \Mopt{, constraints}}
  \eng{Returns the first partition of \Mpar{n} satisfying
    \Mpar{constraints} or \Mex{FAIL} if there is none.}
\end{MMethodDetails}
    
\begin{MMethodDetails}{Next}
  \infoEng{next partition}
  \call{\Mtype{partition} p \Mopt{, constraints}}
  \eng{Returns the partition following \Mpar{p} satisfying
    \Mpar{constraints} or \Mex{FAIL} if there is none.}
\end{MMethodDetails}

\begin{MMethodDetails}{printPretty}
  \infoEng{graphic representation of a partition}
  \call{\Mtype{partition} p}%
  \eng{Returns a graphic representation of the partition
       as rows of boxes.}
\end{MMethodDetails}

\begin{MMethodDetails}{printCompact}
  \infoEng{graphic representation of a partition}
  \call{\Mtype{partition} p}%
  \eng{Same as above, but in a more compact way, where each box
       is represented by \Mpar{\#}.}
\end{MMethodDetails}

\begin{MMethodDetails}{conjugate}
  \infoEng{conjugate of a partition}
  \call{\Mtype{partition} p}%
  \eng{Returns the conjugate (or transposed) of the partition
    \Mpar{p}. Geometrically, this operation amounts to a reflection of
    the diagram of the partition with respect to the main diagonal.}
\end{MMethodDetails}

\begin{MMethodDetails}{hooklengths}
  \infoEng{hooklengths of a partition}
  \call{\Mtype{partition} p}
  \eng{Returns the list of the hook-lengths of the partition \Mpar{p}.}
   \eng{These lengths allow to enumerate standard Young tableaux
     of shape \Mpar{p}. The formula was first discovered by Frame, Robinson,
     and Thrall in 1954.}
\end{MMethodDetails}

\begin{MMethodDetails}{toExp}
  \infoEng{exponential notation of a partition} %
  \call{\Mtype{partition} p}%
  \eng{Returns the exponential notation of the partition \Mpar{p}.
    This is a vector \Mex{v} of nonnegative integers such that
    \Mex{v[i]} counts the number of occurrences of \Mex{i} as part of
    \Mpar{p}. By default, the length of the vector is the size of the
    maximal part of \Mpar{p}.}%
  \call{\Mtype{partition} p, \Mtype{nonnegative integer} k}
  \eng{Returns the exponential notation of the partition \Mpar{p},
    padded with zeroes to ensure a length at least \Mpar{k}.}%
  \eng{See also \Mup{combinat::partitions::fromExp}.}
\end{MMethodDetails}

\begin{MMethodDetails}{fromExp}
  \infoEng{partition from its exponential notation}
  \call{\Mtype{list} l}%
  \eng{Returns the partition \Mpar{p} from its exponential notation \Mpar{l}.}
  \eng{See also \Mup{combinat::partitions::toExp}.}
\end{MMethodDetails}

% The last two are experimental!

\begin{MMethodDetails}{centralizerSize}
  \infoEng{size of the centralizer of a conjugacy class of the
    symmetric group}
  \call{\Mtype{partition} p}
  \eng{Returns the size of the centralizer of the conjugacy class
    of the symmetric group indexed by the partition \Mpar{p}.}
\end{MMethodDetails}

\begin{MMethodDetails}{conjugacyClassSize}
  \infoEng{size of a conjugacy class of the symmetric group}
  \call{\Mtype{partition} p}
  \eng{Returns the size of the conjugacy class of the symmetric group
    indexed by the partition \Mpar{p}.}%
  \eng{Reference: A.~Kerber, "Algebraic Combinatoric Via Finite Group
    Action", 1.3 p.~24.}
\end{MMethodDetails}

\begin{MMethodDetails}{corners}
  \infoEng{corners of a partition}
  \call{\Mtype{partition} p}%
  \eng{Returns a list of coordinates of the corner boxes of the partition.}
\end{MMethodDetails}

\begin{MMethodDetails}{printPrettyCorners}
  \infoEng{graphic representation of the corners of a partition}
  \call{\Mtype{partition} p}%
  \eng{Returns a graphic representation of the partition
       as rows of boxes where the corners are marked with \Mpar{*}.}
\end{MMethodDetails}

\begin{MMethodDetails}{printCompactCorners}
  \infoEng{graphic representation of the corners of a partition}
  \call{\Mtype{partition} p}%
  \eng{Same as above, but in a more compact way, where each box
       is represented by \Mpar{\#} and corners are marked with \Mpar{*}.}
\end{MMethodDetails}

\begin{MMethodDetails}{rCore}
  \infoEng{the r-core of a partition}
  \call{\Mtype{partition} part, \Mtype{nonnegative integer} r } \eng{Returns the r-core of
  a partition, ie the partition we obtain by retiring all ribbons from
  the partition. The set of all the r-core is a set strictly smaller
  than the set of all the partitions.}
\end{MMethodDetails}

\begin{MMethodDetails}{rQuotient }
  \infoEng{the r-quotient of a partition}
  \call{\Mtype{partition} part, \Mtype{nonnegative integer} r}
  \eng{Returns the r-quotient of a partition, ie a r-uplet of partitions.}
\end{MMethodDetails}

\begin{MMethodDetails}{fromCoreAndQuotient}
  \infoEng{partition from its core and its quotient}
  \call{\Mtype{partition} core, \Mtype{list of partitions }}
  \eng{Rebuilding the partition between its r-core and its r-quotient.}
\end{MMethodDetails}

\begin{MMethodDetails}{addRibbonsAndSpin}
  \infoEng{Adding some ribbons to a partition} \call{\Mtype{partition}
  part, \Mtype{list of nonnegative integers} pos} \eng{This function add a ribbon to
  the partition $part$ for each non-zero entries of the vector
  $pos$. The length of the added ribbon is given by the value of the
  corresponding entry. by convention the first entry correspond to the
  first line of the partition. This function returns the shape of the
  new partition and also the cumulative spin of the added ribbons. }
\end{MMethodDetails} 

\begin{MMethodDetails}{removeRibbonsAndSpin}
  \infoEng{Removing some ribbons to a partition} \call{\Mtype{partition}
  part, \Mtype{list of nonnegative integers} pos} \eng{This function remove a ribbon to
  the partition $part$ for each non-zero entries of the vector
  $pos$. The length of the removed ribbon is given by the value of the
  corresponding entry. by convention the first entry correspond to the
  first line of the partition. This function returns the shape of the
  new partition and also the cumulative spin of the removed ribbons. }
\end{MMethodDetails} 




\begin{MExample}{ex-basic}
  \eng{There are $5$ partitions of $4$:}
  \begin{Mexin}
combinat::partitions::count(4)
  \end{Mexin}
  \begin{Mexout}
                               5
  \end{Mexout}

  \eng{Here is the list:}
  \begin{Mexin}
combinat::partitions::list(4)
  \end{Mexin}
  \begin{Mexout}
        [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}

  \eng{And here is the graphic representation of these partitions:}
  \begin{Mexin}
map(combinat::partitions::list(4), combinat::partitions::printPretty)
  \end{Mexin}
  \begin{Mexout}
--
|
|                                               +---+
|                                               |   |
|                     +---+          +---+---+  +---+
|                     |   |          |   |   |  |   |
|  +---+---+---+---+  +---+---+---+  +---+---+  +---+---+
|  |   |   |   |   |, |   |   |   |, |   |   |, |   |   |,
-- +---+---+---+---+  +---+---+---+  +---+---+  +---+---+

   +---+ --
   |   |  |
   +---+  |
   |   |  |
   +---+  |
   |   |  |
   +---+  |
   |   |  |
   +---+ --
  \end{Mexout}
  \eng{Or in a more compact way:}
  \begin{Mexin}
map(combinat::partitions::list(4), combinat::partitions::printCompact)
  \end{Mexin}
  \begin{Mexout}
                  --                    # --
                  |        #    ##  #   #  |
                  |  ####, ###, ##, # , #  |
                  --                ##  # --
  \end{Mexout}


  \eng{You can use the function \Mex{combinat::partitions::first} to get
    the ``first'' partition of a number:}
  \begin{Mexin}
combinat::partitions::first(4)
  \end{Mexin}
  \begin{Mexout}
                              [4]
  \end{Mexout}
  
  \eng{Using \Mex{combinat::partitions::Next}, you can calculate the
    ``next'' partition.  This function takes as argument the partition
    relative to which you want the next one:}
  \begin{Mexin}
combinat::partitions::Next([4])
  \end{Mexin}
  \begin{Mexout}
                            [3, 1]
  \end{Mexout}
  
  \eng{\Mex{combinat::partitions::Next} returns \Mup{FAIL} when the
    input is the last partition:}
  \begin{Mexin}
combinat::partitions::Next([1, 1, 1, 1])
  \end{Mexin}
  \begin{Mexout}
                             FAIL
  \end{Mexout}
  
  \eng{When you want to run through the partitions of a number, you
    can generate them one by one to save memory:}
  \begin{Mexin}
g := combinat::partitions::generator(4):
g(); g(); g(); g(); g(); g()
  \end{Mexin}
  \begin{Mexout}
                              [4]

                            [3, 1]

                            [2, 2]

                           [2, 1, 1]

                         [1, 1, 1, 1]

                             FAIL
  \end{Mexout}

  \eng{Typically, this would be used as follows:}
  \begin{Mexin}
g := combinat::partitions::generator(4):
while (p := g()) <> FAIL do print(p): end:
  \end{Mexin}
  \begin{Mexout}
                              [4]

                            [3, 1]

                            [2, 2]

                           [2, 1, 1]

                         [1, 1, 1, 1]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-length}
  \eng{The options \Length, \MinLength, and \MaxLength\ can be used to
    set length constraints. This is the list of the partitions of $4$
    of length $2$:}
  \begin{Mexin}
combinat::partitions::list(4, Length=2)
  \end{Mexin}
  \begin{Mexout}
                       [[3, 1], [2, 2]]
  \end{Mexout}

  \eng{This is the list of the partitions of $4$ of length at least
    $2$:}
  \begin{Mexin}
combinat::partitions::list(4, MinLength=2)
  \end{Mexin}
  \begin{Mexout}
           [[3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}
  
  \eng{This is the list of the partitions of $4$ of length at most $2$:}
  \begin{Mexin}
combinat::partitions::list(4, MaxLength=2)
  \end{Mexin}
  \begin{Mexout}
                     [[4], [3, 1], [2, 2]]
  \end{Mexout}
  
  \eng{Setting both \MinLength\ and \MaxLength\ to the same value is
    equivalent to setting \Length\ to this value. This is again the
    list of the partitions of $4$ of length $2$:}
  \begin{Mexin}
combinat::partitions::list(4, MinLength=2, MaxLength=2)
  \end{Mexin}
  \begin{Mexout}
                       [[3, 1], [2, 2]]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-parts}
  \eng{The options \MinPart\ and \MaxPart\ can be used to set
    constraints on the sizes of all parts. Using \MaxPart, you can
    select partitions having only small entries. This is the list of
    the partitions of $4$ with all parts at most $2$:}
  \begin{Mexin}
combinat::partitions::list(4, MaxPart=2)
  \end{Mexin}
  \begin{Mexout}
               [[2, 2], [2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}
  
  \eng{\MinPart\ is complementary to \MaxPart\ and selects partitions
    having only large parts (it takes a non-negative value). This is
    the list of the partitions of $4$ with all parts at least $2$:}
  \begin{Mexin}
combinat::partitions::list(4, MinPart=2)
  \end{Mexin}
  \begin{Mexout}
                         [[4], [2, 2]]
  \end{Mexout}
  
  \eng{By default, the parts of a partition have to be positive. This
    can be changed using the option \MinPart. In the following
    example, the options \Length\ and \MinPart\ are combined together
    to obtain the list of the partitions of $4$ with $3$ nonnegative
    parts:}
  \begin{Mexin}
combinat::partitions::list(4, Length=3, MinPart=0)
  \end{Mexin}
  \begin{Mexout}
         [[4, 0, 0], [3, 1, 0], [2, 2, 0], [2, 1, 1]]
  \end{Mexout}
  
  \eng{\Mwarn{Two partitions are considered equivalent whenever they
      differ only by trailing zeroes. Whenever two equivalent
      partitions satisfy the constraints, only the shortest one is
      considered. Hence, this is the list of partitions of $4$ with
      at least $3$ nonnegative parts:}}
  \begin{Mexin}
combinat::partitions::list(4, MinLength=3, MinPart=0)
  \end{Mexin}
  \begin{Mexout}
  [[4, 0, 0], [3, 1, 0], [2, 2, 0], [2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-inclusion}
%  \eng{Options \Inner\ and \Outer.}%
  \eng{The options \Inner, and \Outer\ can be used to set part-by-part
    inclusion constraints. This is the list of the partitions of $4$
    with \Mex{[3, 1, 1]} as an outer bound:}
  \begin{Mexin}
combinat::partitions::list(4, Outer=[3, 1, 1])
  \end{Mexin}
  \begin{Mexout}
                      [[3, 1], [2, 1, 1]]
  \end{Mexout}
  \eng{\Outer\ sets \MaxLength\ to the length of its argument.
    Moreover, the parts of \Outer\ may be infinite to clear the
    constraint on specific parts. This is the list of the partitions
    of $4$ of length at most $3$ such that that the second and third
    part are $1$ when they exists:}
  \begin{Mexin}
combinat::partitions::list(4, Outer=[infinity, 1, 1])
  \end{Mexin}
  \begin{Mexout}
                   [[4], [3, 1], [2, 1, 1]]
  \end{Mexout}
  
  \eng{This is the list of the partitions of $4$ with \Mex{[1, 1, 1]}
       as an inner bound:}
  \begin{Mexin}
combinat::partitions::list(4, Inner=[1, 1, 1])
  \end{Mexin}
  \begin{Mexout}
                   [[2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-slope}
  \eng{The options \MinSlope\ and \MaxSlope\ can be used to set
    constraints on the slope, that is on the difference
    \Mex{p[i+1]-p[i]} of two consecutive parts. This is the list of
    the strictly decreasing partitions of $4$:}
  \begin{Mexin}
combinat::partitions::list(4, MaxSlope=-1)
  \end{Mexin}
  \begin{Mexout}
                         [[4], [3, 1]]
  \end{Mexout}
  
  \eng{The default value for \MaxSlope\ is zero to force the parts to
    be non-increasing. If \MaxSlope\ is explicitly set to a positive
    number, the resulting lists are not necessarily partitions anymore
    since the parts may increase:}
  \begin{Mexin}
combinat::partitions::list(4, MaxSlope=1)
  \end{Mexin}
  \begin{Mexout}
[[4], [3, 1], [2, 2], [2, 1, 1], [1, 2, 1], [1, 1, 2],

   [1, 1, 1, 1]]
  \end{Mexout}

  \eng{This is the list of the partitions of $4$ such that the
    difference between two consecutive parts is at least $-1$:}
  \begin{Mexin}
combinat::partitions::list(4, MinSlope=-1)
  \end{Mexin}
  \begin{Mexout}
            [[4], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
  \end{Mexout}

  \eng{This is the list of increasing partitions of $4$:}
  \begin{Mexin}
combinat::partitions::list(4, MaxSlope=infinity, MinSlope=0)
  \end{Mexin}
  \begin{Mexout}
        [[4], [2, 2], [1, 3], [1, 1, 2], [1, 1, 1, 1]]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-advanced}
  \eng{The constraints can be combined together in all reasonable
    ways. This is the list of the partitions of $11$ of length between
    $2$ and $4$ such that the difference between two consecutive parts
    is between $-3$ and $-1$:}
  \begin{Mexin}
combinat::partitions::list(11,
                           MaxSlope=-1, MinSlope=-3, 
                           MinLength=2, MaxLength=4)
  \end{Mexin}
  \begin{Mexout}
[[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]]
  \end{Mexout}

  \eng{Idem with an \Outer\ constraint:}
  \begin{Mexin}
combinat::partitions::list(11,
                           MaxSlope=-1, MinSlope=-3, 
                           MinLength=2, MaxLength=4, 
                           Outer=[6,5,2])
  \end{Mexin}
  \begin{Mexout}
           [[6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2]]
  \end{Mexout}
  \eng{However, providing incoherent constraints may yield strange
    results. It is up to the user to ensure that the \Inner\ and
    \Outer\ partitions themselves satisfy the part and slope
    constraints:}
  \begin{Mexin}
combinat::partitions::list(5, Inner=[2, 1], MinPart=2)  
  \end{Mexin}
  \begin{Mexout}
                  [[4, 1], [3, 2], [2, 1, 2]]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-conjugate}
  \eng{This is the conjugate of the partition \Mex{[4, 1]}:}
  \begin{Mexin}
combinat::partitions::conjugate([4, 1])
  \end{Mexin}
  \begin{Mexout}
                         [2, 1, 1, 1]
  \end{Mexout}
  \eng{Geometrically, we just applied a reflection with respect to the
    main diagonal on the diagram of the partition. Of course, this
    operation is an involution:}
  \begin{Mexin}
combinat::partitions::conjugate([2, 1, 1, 1])
  \end{Mexin}
  \begin{Mexout}
                            [4, 1]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-constraints-regular}
  \eng{We describe how to generate $k$-regular partitions. Recall that
    a partition \Mex{p} is $k$-\emph{regular} if no part is repeated
    more than $k-1$ times, or, equivalently, if the difference between
    any two consecutive parts of the conjugate partition \Mex{pc} is
    at most $n-1$. Here is a first (buggy) attempt to get the
    $3$-regular partitions of $7$:
    \begin{Mexin}
map(combinat::partitions::list(7, MinSlope=-2),
    combinat::partitions::conjugate)
  \end{Mexin}
  \begin{Mexout}
[[1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 1], [3, 2, 1, 1], [3, 2, 2],

   [3, 3, 1], [4, 2, 1], [5, 1, 1], [4, 3], [5, 2], [6, 1], [7]

   ]
  \end{Mexout}
  This is not quite correct: in \Mex{[2,2,2,1]}, the first part is repeated
  $3$ times. Here is what happened: this $3$ is the last part of the conjugate
  partition \Mex{[4,3]}, and we did not check the slope condition between this
  last part and the consecutive implicit zeroes. We ensure that the conjugate
  partition is padded with zeroes by setting \Mex{Length=7+1}. Note that
  \Mup{combinat::partitions::conjugate} allows partitions with padded zeroes.
  Now, here is the correct list of $3$ regular partitions of $7$:}
  \begin{Mexin}
map(combinat::partitions::list(7, MinSlope=-2, MinPart=0, 
    Length=7+1), combinat::partitions::conjugate)
  \end{Mexin}
  \begin{Mexout}
[[3, 2, 1, 1], [3, 2, 2], [3, 3, 1], [4, 2, 1], [5, 1, 1],

   [4, 3], [5, 2], [6, 1], [7]]
  \end{Mexout}
  \eng{This trick is efficient, and can be refined further to generate
    regular partitions with length, part, or inclusion
    constraints.}
\end{MExample}

\begin{MExample}{ex-exp}
  \eng{This is the exponential notation of the partition \Mex{[4, 1]}:}
  \begin{Mexin}
combinat::partitions::toExp([6,4,4,2,1])
  \end{Mexin}
  \begin{Mexout}
                      [1, 1, 0, 2, 0, 1]
  \end{Mexout}
  \eng{It can be converted back to the original partition:}
  \begin{Mexin}
combinat::partitions::fromExp([1, 1, 0, 2, 0, 1])
  \end{Mexin}
  \begin{Mexout}
                        [6, 4, 4, 2, 1]
  \end{Mexout}
  \eng{The exponential notation can be padded with extra zeroes:}
  \begin{Mexin}
combinat::partitions::toExp([6,4,4,2,1], 5);
combinat::partitions::toExp([6,4,4,2,1], 7);
combinat::partitions::toExp([6,4,4,2,1], 10);
  \end{Mexin}
  \begin{Mexout}
                      [1, 1, 0, 2, 0, 1]

                     [1, 1, 0, 2, 0, 1, 0]

                [1, 1, 0, 2, 0, 1, 0, 0, 0, 0]
  \end{Mexout}
  \eng{In any cases, converting back yields the original partition:}
  \begin{Mexin}
combinat::partitions::fromExp([1, 1, 0, 2, 0, 1, 0, 0, 0]);
  \end{Mexin}
  \begin{Mexout}
                        [6, 4, 4, 2, 1]
  \end{Mexout}
\end{MExample}

\begin{MExample}{ex-corners}
  \eng{This example shows how to compute the corners of a
       partition.}
  \begin{Mexin}
combinat::partitions::corners([4, 3, 1])
  \end{Mexin}
  \begin{Mexout}
                   [[1, 4], [2, 3], [3, 1]]
  \end{Mexout}
  \eng{The corners can be represented graphically:}
  \begin{Mexin}
combinat::partitions::printPrettyCorners([4, 3, 1])
  \end{Mexin}
  \begin{Mexout}
                       +---+
                       | * |
                       +---+---+---+
                       |   |   | * |
                       +---+---+---+---+
                       |   |   |   | * |
                       +---+---+---+---+
  \end{Mexout}
  \eng{Here is a more compact representation:}
  \begin{Mexin}
combinat::partitions::printCompactCorners([4, 3, 1])
  \end{Mexin}
  \begin{Mexout}
                             *
                             ##*
                             ###*
  \end{Mexout}
\end{MExample}

%

\begin{MExample}{r-core r-quotient}
  
  \eng{Example of computation of a r-core and r-quotient of a partition:}
  \begin{Mexin}
    combinat::partitions::rCore([6,3,2,2],3);
    combinat::partitions::rQuotient([7,7,5,3,3,3,1],3)
  \end{Mexin}
  \begin{Mexout}
                           [2, 1, 1]

                     [[2], [1], [2, 2, 2]]
  \end{Mexout}
 
  \eng{Rebuilding a partition from its r-core and its r-quotient:}
  \begin{Mexin}
   combinat::partitions::fromCoreAndQuotient([2,1],[[2,1],[3],[1,1,1]]);
  \end{Mexin}
  \begin{Mexout}
                    [11, 5, 5, 3, 2, 2, 2]
  \end{Mexout}


\end{MExample}

\begin{MExample}{add/remove ribbon to partition}
\eng{These are two example of adding and removing ribbon to a partition}
\begin{Mexin}
  combinat::partitions::addRibbonsAndSpin([4, 3, 1], [2, 0, 0, 0, 2])
\end{Mexin}
\begin{Mexout}
                     [[6, 3, 1, 1, 1], 1]
\end{Mexout}

\begin{Mexin}
  combinat::partitions::removeRibbonsAndSpin([4, 3, 1], [0, 2, 0])
\end{Mexin}
\begin{Mexout}
                        [[4, 1, 1], 0] 
\end{Mexout}
\end{MExample}



\begin{MBackground}
  \eng{Partitions are naturally ordered lexicographically. The
    functions for counting and generating are directly inherited from
    \Mup{Cat::IntegerListsLexClass} with, by default,
    \Mex{MaxSlope=0}, and \Mex{MinPart=1}. The complexity of the
    generation algorithm is constant time amortized for each partition
    generated.}
  
  \eng{Without optional constraints, counting is done efficiently with
    Euler's pentagonal formula for small values of $n$ and
    Hardy-Ramanujan-Rademacher's formula otherwise.
    
    \Mwarn{In all other cases, counting is done by brute force
      generation.}}
\end{MBackground}

\begin{MChanges}
  \version{2.5}%
  \eng[New library]{\Mthis{} is a new library} %
  \eng[Deprecates combinat::partitions(n)]{Calling
    \Mupc{combinat::partitions}{n} to compute the number of partitions
    of \Mpar{n} is temporarily retained for backward compatibility;
    however, it is strongly deprecated in favor of
    \Mupc{combinat::partitions::count}{n}. The emission of a warning
    can be controlled with \Mupc{combinat::warnDeprecated}{FALSE} or
    \Mupc{combinat::warnDeprecated}{TRUE}.}
  \version{3.0}%
  \eng[combinat::partitions(n) deprecated]{Calling
    \Mupc{combinat::partitions}{n} to compute the number of partitions
    of \Mpar{n} is strongly deprecated, and will not work anymore
    starting from the next minor release of \mupad{}; please use
    \Mupc{combinat::partitions::count}{n} instead. The emission of a
    warning can be controlled with
    \Mupc{combinat::warnDeprecated}{FALSE} or
    \Mupc{combinat::warnDeprecated}{TRUE}.}
  \version{3.1}%
  \eng[combinat::partitions(n) standardized]{
    \Mupc{combinat::partitions}{n} is now an alias for
    \Mupc{combinat::partitions::list}{n}, as in the other
    combinatorial classes.}
\end{MChanges}

\MSuperDomain{Dom::BaseDomain}

\begin{MAxioms}
  \Mup{Ax::systemRep}
\end{MAxioms}


\end{Mhelppage}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: main
%%% End: 
