ó
    ˆ*£hiQ  ã                   óÞ   • S SK JrJrJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJrJr  S SKJrJr  S S	KJr  S S
KJr   " S S\5      r " S S\5      rSS jrS rS rS rS rg)é    )ÚBasicÚDictÚsympifyÚTuple)ÚInteger©Údefault_sort_key)Ú_sympify©Úbell)Úzeros)Ú	FiniteSetÚUnion)ÚflattenÚgroup)Úas_int)Údefaultdictc                   óˆ   • \ rS rSrSrSrSrS rSS jr\	S 5       r
S rS rS	 rS
 r\	S 5       r\	S 5       r\S 5       rSrg)Ú	Partitioné   zÝ
This class represents an abstract partition.

A partition is a set of disjoint sets whose union equals a given set.

See Also
========

sympy.utilities.iterables.partitions,
sympy.utilities.iterables.multiset_partitions
Nc                 óô  • / nSnU H[  n[        U[        5      (       a)  [        U5      n[        U5      [        U5      :  a  Sn  O UnUR	                  [        U5      5        M]     [        S U 5       5      (       d  [        S5      e[        U6 nU(       d  [        U5      [        S U 5       5      :  a  [        S5      e[        R                  " U /UQ76 n[        U5      Ul        [        U5      Ul        U$ )a‡  
Generates a new partition object.

This method also verifies if the arguments passed are
valid and raises a ValueError if they are not.

Examples
========

Creating Partition from Python lists:

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3])
>>> a
Partition({3}, {1, 2})
>>> a.partition
[[1, 2], [3]]
>>> len(a)
2
>>> a.members
(1, 2, 3)

Creating Partition from Python sets:

>>> Partition({1, 2, 3}, {4, 5})
Partition({4, 5}, {1, 2, 3})

Creating Partition from SymPy finite sets:

>>> from sympy import FiniteSet
>>> a = FiniteSet(1, 2, 3)
>>> b = FiniteSet(4, 5)
>>> Partition(a, b)
Partition({4, 5}, {1, 2, 3})
FTc              3   óB   #   • U  H  n[        U[        5      v •  M     g 7f©N)Ú
isinstancer   )Ú.0Úparts     Ú[/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/combinatorics/partitions.pyÚ	<genexpr>Ú$Partition.__new__.<locals>.<genexpr>N   s   é € Ð@º4°4”:˜d¤I×.Ð.º4ùs   ‚z@Each argument to Partition should be a list, set, or a FiniteSetc              3   ó8   #   • U  H  n[        U5      v •  M     g 7fr   )Úlen)r   Úargs     r   r   r   U   s   é € Ð9²D¨S¤ C§ ²Dùs   ‚z'Partition contained duplicate elements.)r   ÚlistÚsetr!   Úappendr
   ÚallÚ
ValueErrorr   Úsumr   Ú__new__ÚtupleÚmembersÚsize)ÚclsÚ	partitionÚargsÚdupsr"   Úas_setÚUÚobjs           r   r)   ÚPartition.__new__   sá   € ðH ˆØˆÛˆCÜ˜#œt×$Ñ$Ü˜S›�Ü�v“;¤ S£Ó)Ø�DÙØ�Ø�K‰Kœ ›Ö&ñ ô Ñ@¹4Ó@×@Ñ@Üð.ó/ð /ô
 �4ˆLˆÞ”3�q“6œCÑ9±DÓ9Ó9Ó9ÜÐFÓGÐGä×Ò Ð+ dÒ+ˆÜ˜A“hˆŒÜ�q“6ˆŒØˆ
ó    c                 óÄ   ^• Tc  U R                   nO![        [        U R                   U4S jS95      n[        [        [        U R
                  X R                  45      5      $ )a9  Return a canonical key that can be used for sorting.

Ordering is based on the size and sorted elements of the partition
and ties are broken with the rank.

Examples
========

>>> from sympy import default_sort_key
>>> from sympy.combinatorics import Partition
>>> from sympy.abc import x
>>> a = Partition([1, 2])
>>> b = Partition([3, 4])
>>> c = Partition([1, x])
>>> d = Partition(list(range(4)))
>>> l = [d, b, a + 1, a, c]
>>> l.sort(key=default_sort_key); l
[Partition({1, 2}), Partition({1}, {2}), Partition({1, x}), Partition({3, 4}), Partition({0, 1, 2, 3})]
c                 ó   >• [        U T5      $ r   r   )ÚwÚorders    €r   Ú<lambda>Ú$Partition.sort_key.<locals>.<lambda>u   s   ø€ Ô+;¸A¸uÔ+Er5   ©Úkey)r+   r*   ÚsortedÚmapr	   r,   Úrank)Úselfr9   r+   s    ` r   Úsort_keyÚPartition.sort_key]   sO   ø€ ð( ‰=Ø—l‘l‰GäœF 4§<¡<Ü!EñGó HˆGä”SÔ)¨D¯I©I°wÇ	Á	Ð+JÓKÓLÐLr5   c           
      ó¬   • U R                   c7  [        U R                   Vs/ s H  n[        U[        S9PM     sn5      U l         U R                   $ s  snf )z¡Return partition as a sorted list of lists.

Examples
========

>>> from sympy.combinatorics import Partition
>>> Partition([1], [2, 3]).partition
[[1], [2, 3]]
r<   )Ú
_partitionr>   r/   r	   )rA   Úps     r   r.   ÚPartition.partitionx   sP   € ð �?‰?Ñ"Ü$Ø/3¯yªyó&:Ú/8¨!ô '-¨QÔ4DÔ&EÙ/8ñ&:ó ;ˆDŒOà�‰Ðùò&:s   ¡Ac                 óÌ   • [        U5      nU R                  U-   n[        U[        U R                  5      -  U R                  5      n[
        R                  X0R                  5      $ )a  
Return permutation whose rank is ``other`` greater than current rank,
(mod the maximum rank for the set).

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3])
>>> a.rank
1
>>> (a + 1).rank
2
>>> (a + 100).rank
1
)r   r@   Ú
RGS_unrankÚRGS_enumr,   r   Úfrom_rgsr+   )rA   ÚotherÚoffsetÚresults       r   Ú__add__ÚPartition.__add__ˆ   sV   € ô" �u“ˆØ—‘˜UÑ"ˆÜ˜VÜ$ T§Y¡YÓ/ñ0à ŸI™Ió'ˆô ×!Ñ! &¯,©,Ó7Ð7r5   c                 ó&   • U R                  U* 5      $ )zþ
Return permutation whose rank is ``other`` less than current rank,
(mod the maximum rank for the set).

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3])
>>> a.rank
1
>>> (a - 1).rank
0
>>> (a - 100).rank
1
)rO   ©rA   rL   s     r   Ú__sub__ÚPartition.__sub__    s   € ð" �|‰|˜U˜FÓ#Ð#r5   c                 óV   • U R                  5       [        U5      R                  5       :*  $ )a  
Checks if a partition is less than or equal to
the other based on rank.

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3, 4, 5])
>>> b = Partition([1], [2, 3], [4], [5])
>>> a.rank, b.rank
(9, 34)
>>> a <= a
True
>>> a <= b
True
©rB   r   rR   s     r   Ú__le__ÚPartition.__le__³   s"   € ð$ �}‰}‹¤'¨%£.×"9Ñ"9Ó";Ñ;Ð;r5   c                 óV   • U R                  5       [        U5      R                  5       :  $ )zé
Checks if a partition is less than the other.

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3, 4, 5])
>>> b = Partition([1], [2, 3], [4], [5])
>>> a.rank, b.rank
(9, 34)
>>> a < b
True
rV   rR   s     r   Ú__lt__ÚPartition.__lt__Ç   s"   € ð �}‰}‹¤¨£×!8Ñ!8Ó!:Ñ:Ð:r5   c                 ó€   • U R                   b  U R                   $ [        U R                  5      U l         U R                   $ )z–
Gets the rank of a partition.

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3], [4, 5])
>>> a.rank
13
)Ú_rankÚRGS_rankÚRGS©rA   s    r   r@   ÚPartition.rankØ   s2   € ð �:‰:Ñ!Ø—:‘:ÐÜ˜dŸh™hÓ'ˆŒ
Ø�z‰zÐr5   c           
      ó   • 0 nU R                   n[        U5       H  u  p4U H  nX1U'   M	     M     [        [        U VVs/ s H  of  H  o3PM     M     snn[        S9 Vs/ s H  o1U   PM	     sn5      $ s  snnf s  snf )aD  
Returns the "restricted growth string" of the partition.

Explanation
===========

The RGS is returned as a list of indices, L, where L[i] indicates
the block in which element i appears. For example, in a partition
of 3 elements (a, b, c) into 2 blocks ([c], [a, b]) the RGS is
[1, 1, 0]: "a" is in block 1, "b" is in block 1 and "c" is in block 0.

Examples
========

>>> from sympy.combinatorics import Partition
>>> a = Partition([1, 2], [3], [4, 5])
>>> a.members
(1, 2, 3, 4, 5)
>>> a.RGS
(0, 0, 1, 2, 2)
>>> a + 1
Partition({3}, {4}, {5}, {1, 2})
>>> _.RGS
(0, 0, 1, 2, 3)
r<   )r.   Ú	enumerater*   r>   r	   )rA   Úrgsr.   Úir   ÚjrF   s          r   r_   ÚPartition.RGSê   s’   € ð6 ˆØ—N‘Nˆ	Ü  Ö+‰GˆAÛ�Ø�A“ó ñ ,ô ¤fÙ!Ô-š	�1«1 aŠQ©1‰Q™	Ò-Ô3Cò'Eó Fò 'E ˜!”fñ 'Eñ Fó Gð 	GùÛ-ùòFs   ¿A5Á A;c                 óB  • [        U5      [        U5      :w  a  [        S5      e[        U5      S-   n[        U5       Vs/ s H  n/ PM     nnSnU H  nXT   R	                  X&   5        US-  nM     [        S U 5       5      (       d  [        S5      e[        U6 $ s  snf )aª  
Creates a set partition from a restricted growth string.

Explanation
===========

The indices given in rgs are assumed to be the index
of the element as given in elements *as provided* (the
elements are not sorted by this routine). Block numbering
starts from 0. If any block was not referenced in ``rgs``
an error will be raised.

Examples
========

>>> from sympy.combinatorics import Partition
>>> Partition.from_rgs([0, 1, 2, 0, 1], list('abcde'))
Partition({c}, {a, d}, {b, e})
>>> Partition.from_rgs([0, 1, 2, 0, 1], list('cbead'))
Partition({e}, {a, c}, {b, d})
>>> a = Partition([1, 4], [2], [3, 5])
>>> Partition.from_rgs(a.RGS, a.members)
Partition({2}, {1, 4}, {3, 5})
z#mismatch in rgs and element lengthsé   r   c              3   ó$   #   • U  H  ov •  M     g 7fr   © )r   rF   s     r   r   Ú%Partition.from_rgs.<locals>.<genexpr>/  s   é € Ð(ši˜”1šiùs   ‚z(some blocks of the partition were empty.)r!   r'   ÚmaxÚranger%   r&   r   )rA   rd   ÚelementsÚmax_elemre   r.   rf   s          r   rK   ÚPartition.from_rgs  sž   € ô4 ˆs‹8”s˜8“}Ó$ÜÐBÓCÐCÜ�s“8˜a‘<ˆÜ!& x¤Ó1¢˜A“R¡ˆ	Ð1ØˆÛˆAØ‰L×Ñ ¡Ô,Ø�‰FŠAñ ô Ñ(™iÓ(×(Ñ(ÜÐGÓHÐHÜ˜)Ð$Ð$ùò 2s   ¿B)rE   r]   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r]   rE   r)   rB   Úpropertyr.   rO   rS   rW   rZ   r@   r_   ÚclassmethodrK   Ú__static_attributes__rk   r5   r   r   r      s†   † ñ
ð €EØ€Jò<ô|Mð6 ñó ðò8ò0$ò&<ò(;ð" ñó ðð" ñ Gó ð GðD ñ#%ó ó#%r5   r   c                   óh   • \ rS rSrSrSrSrSS jrS rS r	S r
\S 5       rS	 rS
 rSS jrS rSrg)ÚIntegerPartitioni4  a  
This class represents an integer partition.

Explanation
===========

In number theory and combinatorics, a partition of a positive integer,
``n``, also called an integer partition, is a way of writing ``n`` as a
list of positive integers that sum to n. Two partitions that differ only
in the order of summands are considered to be the same partition; if order
matters then the partitions are referred to as compositions. For example,
4 has five partitions: [4], [3, 1], [2, 2], [2, 1, 1], and [1, 1, 1, 1];
the compositions [1, 2, 1] and [1, 1, 2] are the same as partition
[2, 1, 1].

See Also
========

sympy.utilities.iterables.partitions,
sympy.utilities.iterables.multiset_partitions

References
==========

.. [1] https://en.wikipedia.org/wiki/Partition_%28number_theory%29
Nc                 óŽ  • Ub  Xp[        U[        [        45      (       ab  / n[        UR	                  5       SS9 H8  u  pEU(       d  M  [        U5      [        U5      pTUR                  U/U-  5        M:     [        U5      nO![        [        [        [
        U5      SS95      nSnUc  [        U5      nSnO[        U5      nU(       d  [        U5      U:w  a  [        SU-  5      e[        S U 5       5      (       a  [        S5      e[        R                  " U [        U5      [        U6 5      n[!        U5      Ul        X'l        U$ )aP  
Generates a new IntegerPartition object from a list or dictionary.

Explanation
===========

The partition can be given as a list of positive integers or a
dictionary of (integer, multiplicity) items. If the partition is
preceded by an integer an error will be raised if the partition
does not sum to that given integer.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> a = IntegerPartition([5, 4, 3, 1, 1])
>>> a
IntegerPartition(14, (5, 4, 3, 1, 1))
>>> print(a)
[5, 4, 3, 1, 1]
>>> IntegerPartition({1:3, 2:1})
IntegerPartition(5, (2, 1, 1, 1))

If the value that the partition should sum to is given first, a check
will be made to see n error will be raised if there is a discrepancy:

>>> IntegerPartition(10, [5, 4, 3, 1])
Traceback (most recent call last):
...
ValueError: The partition is not valid

T©ÚreverseFzPartition did not add to %sc              3   ó*   #   • U  H	  oS :  v •  M     g7f)ri   Nrk   )r   re   s     r   r   Ú+IntegerPartition.__new__.<locals>.<genexpr>‰  s   é € Ð(ši˜�1Žušiùs   ‚z-All integer summands must be greater than one)r   Údictr   r>   Úitemsr   Úextendr*   r?   r(   r'   Úanyr   r)   r   r   r#   r.   Úinteger)r-   r.   r…   Ú_ÚkÚvÚsum_okr3   s           r   r)   ÚIntegerPartition.__new__S  s  € ðB ÑØ!*�YÜ�i¤$¬ ×.Ñ.ØˆAÜ˜yŸ™Ó0¸$Ô?‘�ÞÙÜ˜a“y¤&¨£)�1Ø—‘˜!˜˜Q™–ñ	 @ô
 ˜a›‰Iäœf¤S¬°Ó%;ÀTÑJÓKˆIØˆØ‰?Ü˜)“nˆGØ‰Fä˜W“oˆGæœ#˜i›.¨GÓ3ÜÐ:¸WÑDÓEÐEÜÑ(™iÓ(×(Ñ(ÜÐLÓMÐMä�mŠm˜C¤¨Ó!1´5¸)Ð3DÓEˆÜ˜Y›ˆŒØŒØˆ
r5   c                 óþ  • [        [        5      nUR                  U R                  5       5        U R                  nUS/:X  a  [        U R                  S05      $ US   S:w  a.  XS   ==   S-  ss'   US   S:X  a  SUS'   OiS=XS   S-
  '   US'   OYXS   ==   S-  ss'   US   US   -   nUS   nSUS'   U(       a.  US-  nX4-
  S:¼  a  X==   X4-  -  ss'   X1U   U-  -  nU(       a  M.  [        U R                  U5      $ )a:  Return the previous partition of the integer, n, in lexical order,
wrapping around to [1, ..., 1] if the partition is [n].

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> p = IntegerPartition([4])
>>> print(p.prev_lex())
[3, 1]
>>> p.partition > p.prev_lex().partition
True
ri   éÿÿÿÿé   éþÿÿÿr   )r   ÚintÚupdateÚas_dictÚ_keysr{   r…   )rA   ÚdÚkeysÚleftÚnews        r   Úprev_lexÚIntegerPartition.prev_lex‘  s  € ô œÓˆØ	�‰�—‘“Ô Ø�z‰zˆØ�A�3‹;Ü# T§\¡\°1Ð$5Ó6Ð6Ø�‰8�q‹=Ø�2‰h‹K˜1Ñ‹KØ�B‰x˜1‹}Ø��!’à)*Ð*��r‘(˜Q‘,‘ ! A¢$à�2‰h‹K˜1Ñ‹KØ�Q‘4˜$˜r™(‘?ˆDØ�r‘(ˆCØˆAˆa‰DÞØ�q‘�Ø‘: “?Ø“F˜d™iÑ'“FØ˜c™F 3™JÑ&�D÷	 �$ô
   §¡¨aÓ0Ð0r5   c                 óà  • [        [        5      nUR                  U R                  5       5        U R                  nUS   nX0R
                  :X  a   UR                  5         U R
                  US'   OëUS:X  aJ  X   S:”  a  XS-   ==   S-  ss'   X==   S-  ss'   OÁUS   nXS-   ==   S-  ss'   X   S-
  U-  US'   SX'   O›X   S:”  a_  [        U5      S:X  a-  UR                  5         SXS-   '   U R
                  U-
  S-
  US'   OWUS-   nX==   S-  ss'   X   U-  U-
  US'   SX'   O4US   nUS-   nX==   S-  ss'   X   U-  X   U-  -   U-
  nS=X'   X'   XqS'   [        U R
                  U5      $ )a6  Return the next partition of the integer, n, in lexical order,
wrapping around to [n] if the partition is [1, ..., 1].

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> p = IntegerPartition([3, 1])
>>> print(p.next_lex())
[4]
>>> p.partition < p.next_lex().partition
True
rŒ   ri   r�   rŽ   r   )	r   r�   r�   r‘   r’   r…   Úclearr!   r{   )rA   r“   r=   ÚaÚbÚa1Úb1Úneeds           r   Únext_lexÚIntegerPartition.next_lex¶  sw  € ô œÓˆØ	�‰�—‘“Ô Ø�j‰jˆØ�‰GˆØ—‘ÓØ�G‰GŒIØ—<‘<ˆAˆaŠDØ�!‹VØ‰t�a‹xØ�a‘%“˜A‘“Ø“˜‘	”à˜‘G�Ø�a‘%“˜A‘“Ø™˜q™ !‘|��!‘Ø�’à‰t�a‹xÜ�s“8˜q“=Ø—G‘G”IØ �A˜!‘e‘HØŸ<™<¨!Ñ+¨aÑ/�A�a’Dà˜Q™�BØ“E˜Q‘J“EØ™4 ™6 B™;�A�a‘DØ�A’Dà˜‘G�Ø˜‘U�Ø“˜‘
“Ø‘t˜A‘v ¡ Q¡‘¨Ñ+�Ø��‘�q‘tØ�!‘Ü §¡¨aÓ0Ð0r5   c                 óº   • U R                   c>  [        U R                  SS9nU Vs/ s H  o"S   PM	     snU l        [	        U5      U l         U R                   $ s  snf )a  Return the partition as a dictionary whose keys are the
partition integers and the values are the multiplicity of that
integer.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> IntegerPartition([1]*3 + [2] + [3]*4).as_dict()
{1: 3, 2: 1, 3: 4}
F)Úmultipler   )Ú_dictr   r.   r’   r�   )rA   ÚgroupsÚgs      r   r‘   ÚIntegerPartition.as_dictè  sP   € ð �:‰:ÑÜ˜4Ÿ>™>°EÑ:ˆFÙ(.Ó/ª 1˜Aœ$©Ñ/ˆDŒJÜ˜f›ˆDŒJØ�z‰zÐùò 0s   ¦Ac                 ó´   • Sn[        U R                  5      S/-   nUS   nS/U-  nUS:”  a+  X2U   :”  a  XUS-
  '   US-  nX2U   :”  a  M  US-  nUS:”  a  M+  U$ )zÎ
Computes the conjugate partition of itself.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> a = IntegerPartition([6, 3, 3, 2, 1])
>>> a.conjugate
[5, 4, 3, 1, 1, 1]
ri   r   )r#   r.   )rA   rf   Útemp_arrr‡   rœ   s        r   Ú	conjugateÚIntegerPartition.conjugateú  s|   € ð ˆÜ˜Ÿ™Ó'¨1¨#Ñ-ˆØ�Q‰KˆØˆC�‰EˆØ�!‹eØ˜q‘k“/Ø�!�a‘%‘Ø�Q‘�ð ˜q‘k•/ð �‰FˆAð	 �!�eð
 ˆr5   c                 ó|   • [        [        U R                  5      5      [        [        UR                  5      5      :  $ )a  Return True if self is less than other when the partition
is listed from smallest to biggest.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> a = IntegerPartition([3, 1])
>>> a < a
False
>>> b = a.next_lex()
>>> a < b
True
>>> a == b
False
©r#   Úreversedr.   rR   s     r   rZ   ÚIntegerPartition.__lt__  s+   € ô" ”H˜TŸ^™^Ó,Ó-´´X¸e¿o¹oÓ5NÓ0OÑOÐOr5   c                 ó|   • [        [        U R                  5      5      [        [        UR                  5      5      :*  $ )zàReturn True if self is less than other when the partition
is listed from smallest to biggest.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> a = IntegerPartition([4])
>>> a <= a
True
r­   rR   s     r   rW   ÚIntegerPartition.__le__%  s+   € ô ”H˜TŸ^™^Ó,Ó-´´h¸u¿¹Ó6OÓ1PÑPÐPr5   c                 óh   • SR                  U R                   Vs/ s H  o!U-  PM	     sn5      $ s  snf )z½
Prints the ferrer diagram of a partition.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> print(IntegerPartition([1, 1, 5]).as_ferrers())
#####
#
#
Ú
)Újoinr.   )rA   Úcharre   s      r   Ú
as_ferrersÚIntegerPartition.as_ferrers3  s+   € ð �y‰y¨$¯.ª.Ó9ª. Q˜qœ&©.Ñ9Ó:Ð:ùÒ9s   š/c                 ó>   • [        [        U R                  5      5      $ r   )Ústrr#   r.   r`   s    r   Ú__str__ÚIntegerPartition.__str__B  s   € Ü”4˜Ÿ™Ó'Ó(Ð(r5   )r¤   r’   r   )Ú#)rr   rs   rt   ru   rv   r¤   r’   r)   r—   r    r‘   rw   rª   rZ   rW   r¶   rº   ry   rk   r5   r   r{   r{   4  sT   † ñð6 €EØ€Eô<ò|#1òJ01òdð$ ñó ðò.Pò&Qô;õ)r5   r{   Nc                 óF  • SSK Jn  [        U 5      n U S:  a  [        S5      eU" U5      n/ nU S:”  a5  U" SU 5      nU" SX-  5      nUR	                  XV45        XU-  -  n U S:”  a  M5  UR                  SS9  [        U VVs/ s H  u  pWU/U-  PM     snn5      nU$ s  snnf )aä  
Generates a random integer partition summing to ``n`` as a list
of reverse-sorted integers.

Examples
========

>>> from sympy.combinatorics.partitions import random_integer_partition

For the following, a seed is given so a known value can be shown; in
practice, the seed would not be given.

>>> random_integer_partition(100, seed=[1, 1, 12, 1, 2, 1, 85, 1])
[85, 12, 2, 1]
>>> random_integer_partition(10, seed=[1, 2, 3, 1, 5, 1])
[5, 3, 1, 1]
>>> random_integer_partition(1)
[1]
r   )Ú_randintri   zn must be a positive integerTr}   )Úsympy.core.randomr¾   r   r'   r%   Úsortr   )ÚnÚseedr¾   Úrandintr.   r‡   ÚmultÚms           r   Úrandom_integer_partitionrÆ   F  s±   € õ( +äˆq‹	€AØˆ1ƒuÜÐ7Ó8Ð8á�t‹n€Gà€IØˆq‹5Ù�A�q‹MˆÙ�q˜!™$ÓˆØ×Ñ˜!˜Ô#Ø	ˆt‰V‰ˆð	 ˆq�5ð
 ‡N�N˜4€NÑ Ü©9Ô5ª9¡4 1˜!˜˜Qœ©9Ò5Ó6€IØÐùó 6s   ÂB
c                 ó  • [        U S-   5      n[        U S-   5       H
  nSUSU4'   M     [        SU S-   5       HB  n[        U 5       H0  nX0U-
  ::  a  X1US-
  U4   -  XS-
  US-   4   -   XU4'   M*  SXU4'   M2     MD     U$ )a­  
Computes the m + 1 generalized unrestricted growth strings
and returns them as rows in matrix.

Examples
========

>>> from sympy.combinatorics.partitions import RGS_generalized
>>> RGS_generalized(6)
Matrix([
[  1,   1,   1,  1,  1, 1, 1],
[  1,   2,   3,  4,  5, 6, 0],
[  2,   5,  10, 17, 26, 0, 0],
[  5,  15,  37, 77,  0, 0, 0],
[ 15,  52, 151,  0,  0, 0, 0],
[ 52, 203,   0,  0,  0, 0, 0],
[203,   0,   0,  0,  0, 0, 0]])
ri   r   )r   rn   )rÅ   r“   re   rf   s       r   ÚRGS_generalizedrÈ   m  s›   € ô& 	ˆa�!‰e‹€AÜ�1�q‘5Ž\ˆØˆˆ!ˆQˆ$‹ñ ô �1�a˜!‘eŽ_ˆÜ�q–ˆAØ˜‘E‹zØ  A¡ q ™k™/¨A°!©e°Q¸±U¨l©OÑ;��Q�$“à��Q�$“ó	 ñ ð €Hr5   c                 ó4   • U S:  a  gU S:X  a  g[        U 5      $ )a%  
RGS_enum computes the total number of restricted growth strings
possible for a superset of size m.

Examples
========

>>> from sympy.combinatorics.partitions import RGS_enum
>>> from sympy.combinatorics import Partition
>>> RGS_enum(4)
15
>>> RGS_enum(5)
52
>>> RGS_enum(6)
203

We can check that the enumeration is correct by actually generating
the partitions. Here, the 15 partitions of 4 items are generated:

>>> a = Partition(list(range(4)))
>>> s = set()
>>> for i in range(20):
...     s.add(a)
...     a += 1
...
>>> assert len(s) == 15

ri   r   r   )rÅ   s    r   rJ   rJ   �  s!   € ð: 	
ˆA‹ØØ
ˆq‹&Øä�A‹wˆr5   c                 ój  • US:  a  [        S5      eU S:  d  [        U5      U ::  a  [        S5      eS/US-   -  nSn[        U5      n[        SUS-   5       H=  nXAU-
  U4   nX6-  nXp::  a  US-   X%'   X-  n US-  nM'  [	        X-  S-   5      X%'   X-  n M?     USS  Vs/ s H  oˆS-
  PM	     sn$ s  snf )zÛ
Gives the unranked restricted growth string for a given
superset size.

Examples
========

>>> from sympy.combinatorics.partitions import RGS_unrank
>>> RGS_unrank(14, 4)
[0, 1, 2, 3]
>>> RGS_unrank(0, 4)
[0, 0, 0, 0]
ri   zThe superset size must be >= 1r   zInvalid argumentsr�   N)r'   rJ   rÈ   rn   r�   )	r@   rÅ   ÚLrf   ÚDre   rˆ   ÚcrÚxs	            r   rI   rI   ²  sØ   € ð 	ˆ1ƒuÜÐ9Ó:Ð:Øˆaƒx”8˜A“; $Ó&ÜÐ,Ó-Ð-à	
ˆˆq�1‰u‰€AØ	€AÜ˜Ó€AÜ�1�a˜!‘eŽ_ˆØ�!‰e�Qˆh‰KˆØ‰SˆØ‹:Ø�q‘5ˆA‰DØ‰JˆDØ�‰FŠAä�t‘x !‘|Ó$ˆA‰DØ‰IŠDñ ð ˜Q˜R™5Ó!š5�a�ŒE™5Ñ!Ð!ùÒ!s   ÂB0c                 ó¸   • [        U 5      nSn[        U5      n[        SU5       H1  n[        XS-   S 5      n[        U SU 5      nX#XVS-   4   X   -  -  nM3     U$ )zÌ
Computes the rank of a restricted growth string.

Examples
========

>>> from sympy.combinatorics.partitions import RGS_rank, RGS_unrank
>>> RGS_rank([0, 1, 2, 1, 3])
42
>>> RGS_rank(RGS_unrank(4, 7))
4
r   ri   N)r!   rÈ   rn   rm   )rd   Úrgs_sizer@   rÌ   re   rÁ   rÅ   s          r   r^   r^   Õ  sn   € ô �3‹x€HØ€DÜ˜Ó!€AÜ�1�hÖˆÜ�˜‘U�H�ÓˆÜ��A�a�‹MˆØ�!˜‘U�(‘˜c™fÑ$Ñ$Šñ  ð €Kr5   r   ) Ú
sympy.corer   r   r   r   Úsympy.core.numbersr   Úsympy.core.sortingr	   Úsympy.core.sympifyr
   Ú%sympy.functions.combinatorial.numbersr   Úsympy.matricesr   Úsympy.sets.setsr   r   Úsympy.utilities.iterablesr   r   Úsympy.utilities.miscr   Úcollectionsr   r   r{   rÆ   rÈ   rJ   rI   r^   rk   r5   r   Ú<module>rÛ      sc   ðß 2Ó 2Ý &Ý /Ý 'Ý 6Ý  ß ,ß 4Ý 'õ $ôb%�	ô b%ôJ	O)�uô O)ôd$òNò@"òJ "óFr5   