Ë
    7^(hiQ  ã                   óÜ   — d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZ  G d„ de«      Z G d„ de«      Zdd„Zd„ Zd„ Zd„ Zd„ Zy)é    )ÚBasicÚDictÚsympifyÚTuple)ÚInteger©Údefault_sort_key)Ú_sympify©Úbell)Úzeros)Ú	FiniteSetÚUnion)ÚflattenÚgroup)Úas_int)Údefaultdictc                   ó~   — e Zd ZdZdZdZd„ Zdd„Zed„ «       Z	d„ Z
d„ Zd„ Zd	„ Zed
„ «       Zed„ «       Zed„ «       Zy)Ú	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                 óÌ  — g }d}|D ]T  }t        |t        «      r(t        |«      }t        |«      t        |«      k  rd} n|}|j	                  t        |«      «       ŒV t        d„ |D «       «      st        d«      ‚t        |Ž }|st        |«      t        d„ |D «       «      k  rt        d«      ‚t        j                  | g|¢­Ž }t        |«      |_        t        |«      |_        |S )aW  
        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   ó<   K  — | ]  }t        |t        «      –— Œ y ­w©N)Ú
isinstancer   )Ú.0Úparts     ú\/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/combinatorics/partitions.pyú	<genexpr>z$Partition.__new__.<locals>.<genexpr>N   s   è ø€ Ò@°4”:˜d¤I×.Ñ@ùs   ‚z@Each argument to Partition should be a list, set, or a FiniteSetc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr   )Úlen)r   Úargs     r   r   z$Partition.__new__.<locals>.<genexpr>U   s   è ø€ Ò9¨S¤ C§Ñ9ù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'   z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                 óÈ   ‡— ‰€| j                   }n#t        t        | j                   ˆfd„¬«      «      }t        t        t        | j
                  || j                  f«      «      S )a±  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                 ó   •— t        | ‰«      S r   r   )ÚwÚorders    €r   ú<lambda>z$Partition.sort_key.<locals>.<lambda>u   s   ø€ Ô+;¸A¸uÓ+E€ r2   ©Úkey)r)   r(   ÚsortedÚmapr	   r*   Úrank)Úselfr6   r)   s    ` r   Úsort_keyzPartition.sort_key]   sQ   ø€ ð( ˆ=Ø—l‘l‰GäœF 4§<¡<Û!EôGó HˆGä”SÔ)¨D¯I©I°wÀÇ	Á	Ð+JÓKÓLÐLr2   c           	      óª   — | j                   €7t        | j                  D �cg c]  }t        |t        ¬«      ‘Œ c}«      | _         | j                   S c c}w )zÑReturn partition as a sorted list of lists.

        Examples
        ========

        >>> from sympy.combinatorics import Partition
        >>> Partition([1], [2, 3]).partition
        [[1], [2, 3]]
        r8   )Ú
_partitionr:   r-   r	   )r=   Úps     r   r,   zPartition.partitionx   sK   € ð �?‰?Ð"Ü$Ø/3¯y©yö&:Ø*+ô '-¨QÔ4DÖ&Eò &:ó ;ˆDŒOà�‰Ðùò&:s    Ac                 óÎ   — t        |«      }| j                  |z   }t        |t        | j                  «      z  | j                  «      }t
        j                  || j                  «      S )ai  
        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__zPartition.__add__ˆ   sX   € ô" �u“ˆØ—‘˜UÑ"ˆÜ˜VÜ$ T§Y¡YÓ/ñ0à ŸI™Ió'ˆô ×!Ñ! &¨$¯,©,Ó7Ð7r2   c                 ó&   — | j                  | «      S )af  
        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
        )rI   ©r=   rF   s     r   Ú__sub__zPartition.__sub__    s   € ð" �|‰|˜U˜FÓ#Ð#r2   c                 óV   — | j                  «       t        |«      j                  «       k  S )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
        ©r>   r   rK   s     r   Ú__le__zPartition.__le__³   s"   € ð$ �}‰}‹¤'¨%£.×"9Ñ"9Ó";Ñ;Ð;r2   c                 óV   — | j                  «       t        |«      j                  «       k  S )aA  
        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
        rN   rK   s     r   Ú__lt__zPartition.__lt__Ç   s"   € ð �}‰}‹¤¨£×!8Ñ!8Ó!:Ñ:Ð:r2   c                 ó~   — | j                   �| j                   S t        | j                  «      | _         | j                   S )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<   zPartition.rankØ   s2   € ð �:‰:Ð!Ø—:‘:ÐÜ˜dŸh™hÓ'ˆŒ
Ø�z‰zÐr2   c           
      óö   — i }| j                   }t        |«      D ]  \  }}|D ]  }|||<   Œ	 Œ t        t        |D ��cg c]  }|D ]  }|‘Œ Œ c}}t        ¬«      D �cg c]  }||   ‘Œ	 c}«      S c c}}w c c}w )aä  
        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)
        r8   )r,   Ú	enumerater(   r:   r	   )r=   Úrgsr,   Úir   ÚjrA   s          r   rU   zPartition.RGSê   s–   € ð6 ˆØ—N‘Nˆ	Ü  Ó+ò 	‰GˆAˆtØò �Ø��A’ñð	ô ¤fØ!×-�1¨1Ò- aŠQÐ-ˆQÓ-Ô3Cô'Eö F �c˜!“fò Fó Gð 	GùÛ-ùòFs   ½A0ÁA6c                 ó0  — t        |«      t        |«      k7  rt        d«      ‚t        |«      dz   }t        |«      D �cg c]  }g ‘Œ }}d}|D ]  }||   j	                  ||   «       |dz  }Œ  t        d„ |D «       «      st        d«      ‚t        |Ž S c c}w )aB  
        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   ó    K  — | ]  }|–— Œ y ­wr   © )r   rA   s     r   r   z%Partition.from_rgs.<locals>.<genexpr>/  s   è ø€ Ò(˜”1Ñ(ùs   ‚z(some blocks of the partition were empty.)r   r%   ÚmaxÚranger#   r$   r   )r=   rY   ÚelementsÚmax_elemrZ   r,   r[   s          r   rE   zPartition.from_rgs  s£   € ô4 ˆs‹8”s˜8“}Ò$ÜÐBÓCÐCÜ�s“8˜a‘<ˆÜ!& x£Ö1˜A’RÐ1ˆ	Ð1ØˆØò 	ˆAØ�a‰L×Ñ ¨¡Ô,Ø�‰F‰Að	ô Ñ(˜iÔ(Ô(ÜÐGÓHÐHÜ˜)Ð$Ð$ùò 2s   ¾	Br   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rS   r@   r'   r>   Úpropertyr,   rI   rL   rO   rQ   r<   rU   ÚclassmethodrE   r_   r2   r   r   r      s†   „ ñ
ð €EØ€Jò<ó|Mð6 ñó ðò8ò0$ò&<ò(;ð" ñó ðð" ñ Gó ð GðD ñ#%ó ñ#%r2   r   c                   ó\   — e Zd ZdZdZdZdd„Zd„ Zd„ Zd„ Z	e
d„ «       Zd„ Zd	„ Zdd
„Zd„ Zy)ÚIntegerPartitionaZ  
    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                 ón  — |�||}}t        |t        t        f«      r_g }t        |j	                  «       d¬«      D ]3  \  }}|sŒ	t        |«      t        |«      }}|j                  |g|z  «       Œ5 t        |«      }n$t        t        t        t
        |«      d¬«      «      }d}|€t        |«      }d}nt        |«      }|st        |«      |k7  rt        d|z  «      ‚t        d„ |D «       «      rt        d«      ‚t        j                  | t        |«      t        |Ž «      }t!        |«      |_        ||_        |S )a  
        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   ó&   K  — | ]	  }|d k  –— Œ y­w)r]   Nr_   )r   rZ   s     r   r   z+IntegerPartition.__new__.<locals>.<genexpr>‰  s   è ø€ Ò(˜ˆq�1�uÑ(ù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,   rt   Ú_ÚkÚvÚsum_okr1   s           r   r'   zIntegerPartition.__new__S  s   € ðB ÐØ!*¨G�YˆGÜ�i¤$¬ Ô.ØˆAÜ˜yŸ™Ó0¸$Ô?ò  ‘��1ÙØÜ˜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›ˆŒØˆŒØˆ
r2   c                 óî  — t        t        «      }|j                  | j                  «       «       | j                  }|dgk(  rt        | j                  di«      S |d   dk7  r/||d   xx   dz  cc<   |d   dk(  rd|d<   ncdx||d   dz
  <   |d<   nR||d   xx   dz  cc<   |d   |d   z   }|d   }d|d<   |r+|dz  }||z
  dk\  r||xx   ||z  z  cc<   |||   |z  z  }|rŒ+t        | j                  |«      S )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]   éÿÿÿÿé   éþÿÿÿr   )r   ÚintÚupdateÚas_dictÚ_keysrk   rt   )r=   ÚdÚkeysÚleftÚnews        r   Úprev_lexzIntegerPartition.prev_lex‘  s  € ô œÓˆØ	�‰�—‘“Ô Ø�z‰zˆØ�A�3Š;Ü# T§\¡\°1Ð$5Ó6Ð6Ø�‰8�qŠ=Øˆd�2‰h‹K˜1Ñ‹KØ�B‰x˜1Š}Ø��!’à)*Ð*��$�r‘(˜Q‘,‘ ! A¢$àˆd�2‰h‹K˜1Ñ‹KØ�Q‘4˜$˜r™(‘?ˆDØ�r‘(ˆCØˆAˆa‰DÙØ�q‘�Ø˜#‘: ’?Ø�c“F˜d C™iÑ'“FØ˜A˜c™F 3™JÑ&�Dò	 ô
   §¡¨aÓ0Ð0r2   c                 óú  — t        t        «      }|j                  | j                  «       «       | j                  }|d   }|| j
                  k(  r |j                  «        | j
                  |d<   nø|dk(  rO||   dkD  r||dz   xx   dz  cc<   ||xx   dz  cc<   nÍ|d   }||dz   xx   dz  cc<   ||   dz
  |z  |d<   d||<   n¤||   dkD  rbt        |«      dk(  r.|j                  «        d||dz   <   | j
                  |z
  dz
  |d<   n`|dz   }||xx   dz  cc<   ||   |z  |z
  |d<   d||<   n:|d   }|dz   }||xx   dz  cc<   ||   |z  ||   |z  z   |z
  }dx||<   ||<   ||d<   t        | j
                  |«      S )a†  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
        rz   r]   r{   r|   r   )	r   r}   r~   r   r€   rt   Úclearr   rk   )r=   r�   r9   ÚaÚbÚa1Úb1Úneeds           r   Únext_lexzIntegerPartition.next_lex¶  s›  € ô œÓˆØ	�‰�—‘“Ô Ø�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�a˜!‘e‘HØŸ<™<¨!Ñ+¨aÑ/�A�a’Dà˜Q™�BØ�b“E˜Q‘J“EØ˜Q™4 ™6 B™;�A�a‘DØ�A�a’Dà˜‘G�Ø˜‘U�Ø�"“˜‘
“Ø˜‘t˜A‘v  !¡ Q¡‘¨Ñ+�Ø���!‘�q˜‘tØ��!‘Ü §¡¨aÓ0Ð0r2   c                 óº   — | j                   €?t        | j                  d¬«      }|D �cg c]  }|d   ‘Œ	 c}| _        t	        |«      | _         | j                   S c c}w )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€   rp   )r=   ÚgroupsÚgs      r   r   zIntegerPartition.as_dictè  sN   € ð �:‰:ÐÜ˜4Ÿ>™>°EÔ:ˆFØ(.Ö/ 1˜!˜A›$Ò/ˆDŒJÜ˜f›ˆDŒJØ�z‰zÐùò 0s   ¨Ac                 ó®   — d}t        | j                  «      dgz   }|d   }dg|z  }|dkD  r)|||   kD  r|||dz
  <   |dz  }|||   kD  rŒ|dz  }|dkD  rŒ)|S )a  
        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!   r,   )r=   r[   Útemp_arrrv   r‰   s        r   Ú	conjugatezIntegerPartition.conjugateú  s‚   € ð ˆÜ˜Ÿ™Ó'¨1¨#Ñ-ˆØ�Q‰KˆØˆC�‰EˆØ�!ŠeØ�h˜q‘k’/Ø��!�a‘%‘Ø�Q‘�ð �h˜q‘k“/ð �‰FˆAð	 �!‹eð
 ˆr2   c                 ó|   — t        t        | j                  «      «      t        t        |j                  «      «      k  S )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,   rK   s     r   rQ   zIntegerPartition.__lt__  s+   € ô" ”H˜TŸ^™^Ó,Ó-´´X¸e¿o¹oÓ5NÓ0OÑOÐOr2   c                 ó|   — t        t        | j                  «      «      t        t        |j                  «      «      k  S )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([4])
        >>> a <= a
        True
        r—   rK   s     r   rO   zIntegerPartition.__le__%  s+   € ô ”H˜TŸ^™^Ó,Ó-´´h¸u¿¹Ó6OÓ1PÑPÐPr2   c                 ód   — dj                  | j                  D �cg c]  }||z  ‘Œ	 c}«      S c c}w )a  
        Prints the ferrer diagram of a partition.

        Examples
        ========

        >>> from sympy.combinatorics.partitions import IntegerPartition
        >>> print(IntegerPartition([1, 1, 5]).as_ferrers())
        #####
        #
        #
        ú
)Újoinr,   )r=   ÚcharrZ   s      r   Ú
as_ferrerszIntegerPartition.as_ferrers3  s)   € ð �y‰y¨$¯.©.Ö9 Q˜$˜q›&Ò9Ó:Ð:ùÒ9s   š-c                 ó>   — t        t        | j                  «      «      S r   )Ústrr!   r,   rV   s    r   Ú__str__zIntegerPartition.__str__B  s   € Ü”4˜Ÿ™Ó'Ó(Ð(r2   r   )ú#)rd   re   rf   rg   r�   r€   r'   r…   r�   r   rh   r•   rQ   rO   rž   r¡   r_   r2   r   rk   rk   4  sT   „ ñð6 €EØ€Eó<ò|#1òJ01òdð$ ñó ðò.Pò&Qó;ó)r2   rk   Nc                 óF  — ddl m} t        | «      } | dk  rt        d«      ‚ ||«      }g }| dkD  r6 |d| «      } |d| |z  «      }|j	                  ||f«       | ||z  z  } | dkD  rŒ6|j                  d¬«       t        |D ��cg c]  \  }}|g|z  ‘Œ c}}«      }|S c c}}w )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   )Ú_randintr]   zn must be a positive integerTrm   )Úsympy.core.randomr¤   r   r%   r#   Úsortr   )ÚnÚseedr¤   Úrandintr,   rv   Ú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˜!˜Q™$ÓˆØ×Ñ˜!˜T˜Ô#Ø	ˆQˆt‰V‰ˆð	 ˆq‹5ð
 ‡N�N˜4€NÔ Ü¨9×5¡4 1 a˜!˜˜Q›Ó5Ó6€IØÐùó 6s   ÂB
c                 óþ   — t        | dz   «      }t        | dz   «      D ]	  }d|d|f<   Œ t        d| dz   «      D ]B  }t        | «      D ]2  }|| |z
  k  r!|||dz
  |f   z  ||dz
  |dz   f   z   |||f<   Œ,d|||f<   Œ4 ŒD |S )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]   r   )r   ra   )r«   r�   rZ   r[   s       r   ÚRGS_generalizedr®   m  s´   € ô& 	ˆa�!‰e‹€AÜ�1�q‘5‹\ò ˆØˆˆ!ˆQˆ$Šðô �1�a˜!‘e‹_ò ˆÜ�q“ò 	ˆAØ�A˜‘EŠzØ˜a  A¡ q ™k™/¨A¨a°!©e°Q¸±U¨l©OÑ;��!�Q�$’à��!�Q�$’ñ		ðð €Hr2   c                 ó0   — | dk  ry| dk(  ryt        | «      S )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   r   )r«   s    r   rD   rD   �  s!   € ð: 	
ˆAŠØØ
ˆqŠ&Øä�A‹wˆr2   c                 óh  — |dk  rt        d«      ‚| dk  st        |«      | k  rt        d«      ‚dg|dz   z  }d}t        |«      }t        d|dz   «      D ]B  }|||z
  |f   }||z  }|| k  r|dz   ||<   | |z  } |dz  }Œ*t	        | |z  dz   «      ||<   | |z  } ŒD |dd D �cg c]  }|dz
  ‘Œ	 c}S c c}w )a  
    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]
    r]   zThe superset size must be >= 1r   zInvalid argumentsr{   N)r%   rD   r®   ra   r}   )	r<   r«   ÚLr[   ÚDrZ   rw   ÚcrÚxs	            r   rC   rC   ²  së   € ð 	ˆ1‚uÜÐ9Ó:Ð:Øˆa‚x”8˜A“; $Ò&ÜÐ,Ó-Ð-à	
ˆˆq�1‰u‰€AØ	€AÜ˜Ó€AÜ�1�a˜!‘e‹_ò 	ˆØˆa�!‰e�Qˆh‰KˆØˆq‰SˆØ�Š:Ø�q‘5ˆAˆa‰DØ�B‰JˆDØ�‰F‰Aä�t˜a‘x !‘|Ó$ˆAˆa‰DØ�A‰I‰Dð	ð ˜Q˜R˜5Ö!�aˆA�‹EÒ!Ð!ùÒ!s   Â B/c                 ó¼   — t        | «      }d}t        |«      }t        d|«      D ]4  }t        | |dz   d «      }t        | d| «      }||||dz   f   | |   z  z  }Œ6 |S )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   r]   N)r   r®   ra   r`   )rY   Úrgs_sizer<   r²   rZ   r§   r«   s          r   rT   rT   Õ  s{   € ô �3‹x€HØ€DÜ˜Ó!€AÜ�1�hÓò %ˆÜ��Q˜‘U�H�ÓˆÜ��A�a�‹MˆØ��!�Q˜‘U�(‘˜c !™fÑ$Ñ$‰ð%ð €Kr2   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   rk   r¬   r®   rD   rC   rT   r_   r2   r   ú<module>rÁ      sc   ðß 2Ó 2Ý &Ý /Ý 'Ý 6Ý  ß ,ß 4Ý 'õ $ôb%�	ô b%ôJ	O)�uô O)ód$òNò@"òJ "óFr2   