+
    ‹°³jiQ  ã                   óà   € ^ RI HtHtHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHtHt ^ RIHtHt ^ R	IHt ^ R
IHt  ! R R]4      t ! R R]4      tRR ltR tR tR tR tR# )é    )ÚBasicÚDictÚsympifyÚTuple)ÚInteger©Údefault_sort_key)Ú_sympify©Úbell)Úzeros)Ú	FiniteSetÚUnion)ÚflattenÚgroup)Úas_int)Údefaultdictc                   ó”   a € ] tR t^t o RtRtRtR tRR lt]	R 4       t
R tR tR tR	 t]	R
 4       t]	R 4       t]R 4       tRtV tR# )Ú	PartitionzÝ
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                óF  € . pRpV F]  p\        V\        4      '       d+   \        V4      p\        V4      \        V4      8  d   Rp M TpVP	                  \        V4      4       K_  	  \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R4      h\        V!  pV'       g!   \        V4      \        R V 4       4      8  d   \        R4      h\        P                  ! V .VO5!  p\        V4      Vn        \        V4      Vn        V# )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   "  € T F  p\        V\        4      x € K  	  R # 5i©N)Ú
isinstancer   )Ú.0Úparts   & Ú_/home/luca/screen-checking/.venv/lib/python3.14/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   "  € T F  p\        V4      x € K  	  R # 5i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œ ›Ö&ñ ÷ ‹sÑ@¹4Ó@�s�sŠsÑ@¹4Ó@×@Ò@Üð.ó/ð /ô
 �4‰Lˆß”3�q“6œCÑ9±DÓ9Ó9Ô9ÜÐFÓGÐGä×Ò Ð+ dÓ+ˆÜ˜A“hˆŒÜ�q“6ˆŒØˆ
ó    c                óÌ   a€ Sf   V P                   pM$\        \        V P                   V3R lR7      4      p\        \        \        V P
                  W P                  34      4      # )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                 ó   <€ \        V S4      # r   r   )ÚwÚorders   &€r   Ú<lambda>Ú$Partition.sort_key.<locals>.<lambda>u   s   ø€ Ô+;¸A¸uÔ+Er4   ©Úkey)r*   r)   ÚsortedÚmapr	   r+   Úrank)Úselfr8   r*   s   &f r   Úsort_keyÚPartition.sort_key]   sO   ø€ ð( Š=Ø—l‘l‰GäœF 4§<¡<Ü!EôGó HˆGä”SÔ)¨D¯I©I°wÇ	Á	Ð+JÓKÓLÐLr4   c           
     ó²   € V P                   f:   \        V P                   Uu. uF  p\        V\        R7      NK  	  up4      V n         V P                   # u upi )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	   )r@   Úps   & r   r-   ÚPartition.partitionx   sP   € ð �?‰?Ò"Ü$Ø/3¯yªyó&:Ù/8¨!ô '-¨QÔ4D×&EÙ/8ñ&:ó ;ˆDŒOà�‰Ðùò&:s   ¢Ac                óÜ   € \        V4      pV P                  V,           p\        V\        V P                  4      ,          V P                  4      p\
        P                  W0P                  4      # )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*   )r@   ÚotherÚoffsetÚresults   &&  r   Ú__add__ÚPartition.__add__ˆ   sV   € ô" �u“ˆØ—‘˜UÕ"ˆÜ˜VÜ$ T§Y¡YÓ/õ0à ŸI™Ió'ˆô ×!Ñ! &¯,©,Ó7Ð7r4   c                ó&   € V P                  V) 4      # )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
)rN   ©r@   rK   s   &&r   Ú__sub__ÚPartition.__sub__    s   € ð" �|‰|˜U˜FÓ#Ð#r4   c                óV   € V P                  4       \        V4      P                  4       8*  # )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
©rA   r   rQ   s   &&r   Ú__le__ÚPartition.__le__³   s"   € ð$ �}‰}‹¤'¨%£.×"9Ñ"9Ó";Ñ;Ð;r4   c                óV   € V P                  4       \        V4      P                  4       8  # )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
rU   rQ   s   &&r   Ú__lt__ÚPartition.__lt__Ç   s"   € ð �}‰}‹¤¨£×!8Ñ!8Ó!:Ñ:Ð:r4   c                ó‚   € V P                   e   V P                   # \        V P                  4      V n         V P                   # )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©r@   s   &r   r?   ÚPartition.rankØ   s2   € ð �:‰:Ò!Ø—:‘:ÐÜ˜dŸh™hÓ'ˆŒ
Ø�z‰zÐr4   c           
     ó  € / pV P                   p\        V4       F  w  r4V F  pW1V&   K	  	  K  	  \        \        V UUu. uF  qf F  q3NK  	  K  	  upp\        R7       Uu. uF  q1V,          NK  	  up4      # u uppi u upi )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	   )r@   Úrgsr-   Úir   ÚjrE   s   &      r   r^   ÚPartition.RGSê   s”   € ð6 ˆØ—N‘Nˆ	Ü  Ö+‰GˆAÛ�Ø�A“ó ñ ,ô ¤fÙ!Ô-™	�1ª1 aŠQ©1‰Q™	Ò-Ô3Cõ'Eó Fñ 'E ˜!—f�fñ 'Eñ Fó Gð 	GùÛ-ùòFs   ¿A9Á!A?c                óª  € \        V4      \        V4      8w  d   \        R4      h\        V4      ^,           p\        V4       Uu. uF  p. NK  	  pp^ pV F)  pWT,          P	                  W&,          4       V^,          pK+  	  \
        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R4      h\        V!  # u upi )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 lengthsc              3   ó$   "  € T F  qx € K  	  R # 5ir   © )r   rE   s   & r   r   Ú%Partition.from_rgs.<locals>.<genexpr>/  s   é € Ð(™i˜”1›iùs   ‚FTz(some blocks of the partition were empty.)r    r&   ÚmaxÚranger$   r%   r   )r@   rc   ÚelementsÚmax_elemrd   r-   re   s   &&&    r   rJ   ÚPartition.from_rgs  s®   € ô4 ˆs‹8”s˜8“}Ô$ÜÐBÓCÐCÜ�s“8˜a•<ˆÜ!& x¤Ó1¡˜A“R¡ˆ	Ð1ØˆÛˆAØ�L×Ñ ¥Ô,Ø��FŠAñ ÷ ‹sÑ(™iÓ(�s�sŠsÑ(™iÓ(×(Ò(ÜÐGÓHÐHÜ˜)Ñ$Ð$ùò 2s   ÁC)rD   r\   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r\   rD   r(   rA   Úpropertyr-   rN   rR   rV   rY   r?   r^   ÚclassmethodrJ   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r      s‰   ø‡ € ñ
ð €EØ€Jò<ô|Mð6 ñó ðò8ò0$ò&<ò(;ð" ñó ðð" ñ Gó ð GðD ñ#%ó ö#%r4   r   c                   ót   a € ] tR tRt o RtRtRtRR ltR tR t	R t
]R 4       tR	 tR
 tRR ltR tRtV tR# )Ú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                óþ  € Ve   Yr\        V\        \        34      '       dk   . p\        VP	                  4       RR7       F=  w  rEV'       g   K  \        V4      \        V4      rTVP                  V.V,          4       K?  	  \        V4      pM$\        \        \        \
        V4      RR7      4      pRpVf   \        V4      pRpM\        V4      pV'       g#   \        V4      V8w  d   \        RV,          4      h\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        R4      h\        P                  ! V \        V4      \        V!  4      p\!        V4      Vn        W'n        V# )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   ó*   "  € T F	  q^8  x € K  	  R# 5i)é   Nri   )r   rd   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_okr2   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ß‹3Ñ(™iÓ(�3�3Š3Ñ(™iÓ(×(Ò(ÜÐLÓMÐMä�mŠm˜C¤¨Ó!1´5¸)Ñ3DÓEˆÜ˜Y›ˆŒØŒØˆ
r4   c                ó®  € \        \        4      pVP                  V P                  4       4       V P                  pV^.8X  d   \        V P                  ^/4      # VR,          ^8w  dH   WR,          ;;,          ^,          uu&   VR,          ^8X  d   ^V^&   Mª^;WR,          ^,
          &   V^&   M’WR,          ;;,          ^,          uu&   V^,          VR,          ,           pVR,          p^ V^&   V'       dK   V^,          pW4,
          ^ 8¼  g   K   W;;,          W4,          ,          uu&   W1V,          V,          ,          pKR  \        V P                  V4      # )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
éÿÿÿÿéþÿÿÿ)r   ÚintÚupdateÚas_dictÚ_keysr|   r‡   )r@   Ú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Ð0r4   c                óþ  € \        \        4      pVP                  V P                  4       4       V P                  pVR,          pW0P
                  8X  d"   VP                  4        V P
                  V^&   EMtV^8X  d�   W,          ^8”  d2   W^,           ;;,          ^,          uu&   W;;,          ^,          uu&   EM/VR,          pW^,           ;;,          ^,          uu&   W,          ^,
          V,          V^&   ^ W&   MíW,          ^8”  d…   \        V4      ^8X  d:   VP                  4        ^W^,           &   V P
                  V,
          ^,
          V^&   M—V^,           pW;;,          ^,          uu&   W,          V,          V,
          V^&   ^ W&   M\VR,          pV^,           pW;;,          ^,          uu&   W,          V,          W,          V,          ,           V,
          p^ ;W&   W&   Wq^&   \        V P
                  V4      # )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Ž   r�   )	r   r�   r‘   r’   r“   r‡   Úclearr    r|   )r@   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Ð0r4   c                óÈ   € V P                   fE   \        V P                  RR7      pV Uu. uF  q"^ ,          NK  	  upV n        \	        V4      V n         V P                   # u upi )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)Úmultiple)Ú_dictr   r-   r“   rƒ   )r@   ÚgroupsÚgs   &  r   r’   ÚIntegerPartition.as_dictè  sR   € ð �:‰:ÒÜ˜4Ÿ>™>°EÔ:ˆFÙ(.Ó/© 1˜AŸ$˜$©Ñ/ˆDŒJÜ˜f›ˆDŒJØ�z‰zÐùò 0s   ªAc                óÔ   € ^p\        V P                  4      ^ .,           pV^ ,          p^ .V,          pV^ 8”  d/   W2V,          8”  d   WV^,
          &   V^,          pK#  V^,          pK5  V# )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]
)r"   r-   )r@   re   Útemp_arrr‰   r�   s   &    r   Ú	conjugateÚIntegerPartition.conjugateú  sd   € ð ˆÜ˜Ÿ™Ó'¨1¨#Õ-ˆØ�Q�KˆØˆC��EˆØ�!ŒeØ˜q•k”/Ø�!�a•%‘Ø�Q•’Ø��FŠAØˆr4   c                ó|   € \        \        V P                  4      4      \        \        VP                  4      4      8  # )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-   rQ   s   &&r   rY   ÚIntegerPartition.__lt__  s+   € ô" ”H˜TŸ^™^Ó,Ó-´´X¸e¿o¹oÓ5NÓ0OÑOÐOr4   c                ó|   € \        \        V P                  4      4      \        \        VP                  4      4      8*  # )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®   rQ   s   &&r   rV   ÚIntegerPartition.__le__%  s+   € ô ”H˜TŸ^™^Ó,Ó-´´h¸u¿¹Ó6OÓ1PÑPÐPr4   c                ón   € RP                  V P                   Uu. uF  q!V,          NK  	  up4      # u upi )z½
Prints the ferrer diagram of a partition.

Examples
========

>>> from sympy.combinatorics.partitions import IntegerPartition
>>> print(IntegerPartition([1, 1, 5]).as_ferrers())
#####
#
#
Ú
)Újoinr-   )r@   Úcharrd   s   && r   Ú
as_ferrersÚIntegerPartition.as_ferrers3  s-   € ð �y‰y¨$¯.ª.Ó9©. Q˜qŸ&˜&©.Ñ9Ó:Ð:ùÒ9s   š2c                ó>   € \        \        V P                  4      4      # r   )Ústrr"   r-   r_   s   &r   Ú__str__ÚIntegerPartition.__str__B  s   € Ü”4˜Ÿ™Ó'Ó(Ð(r4   )r¥   r“   r   )Ú#)rp   rq   rr   rs   rt   r¥   r“   r(   r˜   r¡   r’   ru   r«   rY   rV   r·   r»   rw   rx   ry   s   @r   r|   r|   4  s\   ø‡ € ñð6 €EØ€Eô<ò|#1òJ01òdð$ ñó ðò.Pò&Qô;÷)ð )r4   r|   Nc                ób  € ^ RI Hp \        V 4      p V ^8  d   \        R4      hV! V4      p. pV ^ 8”  d<   V! ^V 4      pV! ^W,          4      pVP	                  WV34       WV,          ,          p KB  VP                  RR7       \        V UUu. uF  w  rWV.V,          NK  	  upp4      pV# u uppi )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]
)Ú_randintz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�ŠØ‡N�N˜4€NÔ Ü©9Ô5©9¡4 1˜!˜˜QŸ˜©9Ò5Ó6€IØÐùó 6s   ÂB+
c                ó^  € \        V ^,           4      p\        V ^,           4       F
  p^V^ V3&   K  	  \        ^V ^,           4       Fc  p\        V 4       FQ  pW0V,
          8:  d<   W1V^,
          V3,          ,          W^,
          V^,           3,          ,           WV3&   KK  ^ WV3&   KS  	  Ke  	  V# )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]])
)r   rl   )rÆ   r”   rd   re   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�$“ó	 ñ ð €Hr4   c                ó<   € V ^8  d   ^ # V ^8X  d   ^# \        V 4      # )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

r   )rÆ   s   &r   rI   rI   �  s!   € ð: 	
ˆAŒÙØ
ˆqŒ&Ùä�A‹wˆr4   c                óà  € V^8  d   \        R4      hV ^ 8  g   \        V4      V 8:  d   \        R4      h^.V^,           ,          p^p\        V4      p\        ^V^,           4       Fb  pWAV,
          V3,          pW6,          pWp8:  d   V^,           W%&   W,          p V^,          pK@  \	        W,          ^,           4      W%&   W,          p Kd  	  VR,           Uu. uF  qˆ^,
          NK  	  up# u upi )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]
zThe superset size must be >= 1zInvalid arguments:r�   NN)r&   rI   rÉ   rl   r�   )	r?   rÆ   ÚLre   ÚDrd   rŠ   ÚcrÚxs	   &&       r   rH   rH   ²  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ñ ð ˜Rž5Ó!™5�a��EˆE™5Ñ!Ð!ùÒ!s   ÃC+c                óè   € \        V 4      p^ p\        V4      p\        ^V4       FI  p\        W^,           R 4      p\        V ^ V 4      pW#WV^,           3,          W,          ,          ,          pKK  	  V# )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
N)r    rÉ   rl   rk   )rc   Úrgs_sizer?   rÍ   rd   rÂ   rÆ   s   &      r   r]   r]   Õ  sn   € ô �3‹x€HØ€DÜ˜Ó!€AÜ�1�hÖˆÜ�˜•U�H�ÓˆÜ��A�a�‹MˆØ�!˜•U�(•˜c�fÕ$Õ$Šñ  ð €Kr4   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É   rI   rH   r]   ri   r4   r   Ú<module>rÜ      sc   ðß 2Ó 2Ý &Ý /Ý 'Ý 6Ý  ß ,ß 4Ý 'õ $ôb%�	ô b%ôJ	O)�uô O)ôd$òNò@"òJ "ôFr4   