§
    OŠtjiQ  ã                   óê   — 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dS )é    )Ú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dS )Ú	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 ]n}t          |t          ¦  «        r5t          |¦  «        }t          |¦  «        t          |¦  «        k     rd} n%|}|                     t          |¦  «        ¦  «         Œot          d„ |D ¦   «         ¦  «        st          d¦  «        ‚t          |Ž }|s*t          |¦  «        t          d„ |D ¦   «         ¦  «        k     rt          d¦  «        ‚t          j        | g|¢R Ž }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          ¦  «        V — Œd S ©N)Ú
isinstancer   )Ú.0Úparts     ú\/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/combinatorics/partitions.pyú	<genexpr>z$Partition.__new__.<locals>.<genexpr>N   s,   è è € Ð@Ð@°4•:˜d¥IÑ.Ô.Ð@Ð@Ð@Ð@Ð@Ð@ó    z@Each argument to Partition should be a list, set, or a FiniteSetc              3   ó4   K  — | ]}t          |¦  «        V — Œd S r   )Úlen)r   Úargs     r   r   z$Partition.__new__.<locals>.<genexpr>U   s(   è è € Ð9Ð9¨S¥ C¡¤Ð9Ð9Ð9Ð9Ð9Ð9r   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__   s3  € ðH ˆØˆØð 	'ð 	'ˆCÝ˜#�tÑ$Ô$ð Ý˜S™œ�Ý�v‘;”;¥ S¡¤Ò)Ð)Ø�DØ�EØ�Ø�KŠK� ™œÑ&Ô&Ð&Ð&åÐ@Ð@¸4Ð@Ñ@Ô@Ñ@Ô@ð 	/Ýð.ñ/ô /ð /õ
 �4ˆLˆØð 	H•3�q‘6”6�CÐ9Ð9°DÐ9Ñ9Ô9Ñ9Ô9Ò9Ð9ÝÐFÑGÔGÐGåÔ Ð+ dÐ+Ð+Ð+ˆÝ˜A‘h”hˆŒÝ�q‘6”6ˆŒØˆ
r   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})]
        Nc                 ó$   •— t          | ‰¦  «        S r   r   )ÚwÚorders    €r   ú<lambda>z$Partition.sort_key.<locals>.<lambda>u   s   ø€ Õ+;¸A¸uÑ+EÔ+E€ r   ©Úkey)r*   r)   ÚsortedÚmapr	   r+   Úrank)Úselfr6   r*   s    ` r   Úsort_keyzPartition.sort_key]   sl   ø€ ð( ˆ=Ø”lˆGˆGå�F 4¤<Ø!EÐ!EÐ!EÐ!EðGñ Gô Gñ Hô HˆGå•SÕ)¨D¬I°wÀÄ	Ð+JÑKÔKÑLÔLÐLr   c                 ód   — | j         €#t          d„ | j        D ¦   «         ¦  «        | _         | j         S )zÑReturn partition as a sorted list of lists.

        Examples
        ========

        >>> from sympy.combinatorics import Partition
        >>> Partition([1], [2, 3]).partition
        [[1], [2, 3]]
        Nc                 ó:   — g | ]}t          |t          ¬ ¦  «        ‘ŒS )r8   )r:   r	   ©r   Úps     r   ú
<listcomp>z'Partition.partition.<locals>.<listcomp>„   s6   € ð &:ð &:ð &:Ø*+õ '-¨QÕ4DÐ&EÑ&EÔ&Eð &:ð &:ð &:r   )Ú
_partitionr:   r.   ©r=   s    r   r-   zPartition.partitionx   sC   € ð Œ?Ð"Ý$ð &:ð &:Ø/3¬yð&:ñ &:ô &:ñ ;ô ;ˆDŒOàŒÐr   c                 óÈ   — t          |¦  «        }| j        |z   }t          |t          | j        ¦  «        z  | j        ¦  «        }t
                               || 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__ˆ   s]   € õ" �u‘”ˆØ”˜UÑ"ˆÝ˜VÝ$ T¤YÑ/Ô/ñ0à œIñ'ô 'ˆõ ×!Ò! &¨$¬,Ñ7Ô7Ð7r   c                 ó.   — |                       | ¦  «        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
        )rM   ©r=   rJ   s     r   Ú__sub__zPartition.__sub__    s   € ð" �|Š|˜U˜FÑ#Ô#Ð#r   c                 óp   — |                       ¦   «         t          |¦  «                              ¦   «         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   rO   s     r   Ú__le__zPartition.__le__³   s)   € ð$ �}Š}‰Œ¥'¨%¡.¤.×"9Ò"9Ñ";Ô";Ò;Ð;r   c                 óp   — |                       ¦   «         t          |¦  «                              ¦   «         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
        rR   rO   s     r   Ú__lt__zPartition.__lt__Ç   s)   € ð �}Š}‰Œ¥¨¡¤×!8Ò!8Ñ!:Ô!:Ò:Ð:r   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ÚRGSrE   s    r   r<   zPartition.rankØ   s-   € ð Œ:Ð!Ø”:ÐÝ˜dœhÑ'Ô'ˆŒ
ØŒzÐr   c                 óÆ   ‡— i Š| j         }t          |¦  «        D ]\  }}|D ]}|‰|<   ŒŒt          ˆfd„t          d„ |D ¦   «         t          ¬¦  «        D ¦   «         ¦  «        S )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)
        c                 ó    •— g | ]
}‰|         ‘ŒS © r\   )r   ÚiÚrgss     €r   rC   z!Partition.RGS.<locals>.<listcomp>
  s/   ø€ ð Fð Fð F �c˜!”fð Fð Fð Fr   c                 ó   — g | ]	}|D ]}|‘ŒŒ
S r\   r\   )r   rB   r]   s      r   rC   z!Partition.RGS.<locals>.<listcomp>  s%   € Ð-Ð-Ð-�1¨1Ð-Ð- aˆQÐ-Ð-Ð-Ð-r   r8   )r-   Ú	enumerater)   r:   r	   )r=   r-   r]   r   Újr^   s        @r   rY   zPartition.RGSê   s²   ø€ ð6 ˆØ”Nˆ	Ý  Ñ+Ô+ð 	ð 	‰GˆAˆtØð ð �Ø��A‘�ðåð Fð Fð Fð F¥fØ-Ð-˜	Ð-Ñ-Ô-Õ3Cð'Eñ 'Eô 'Eð Fñ Fô Fñ Gô Gð 	Gr   c                 ór  — t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚t          |¦  «        dz   }d„ t          |¦  «        D ¦   «         }d}|D ](}||                              ||         ¦  «         |dz  }Œ)t          d„ |D ¦   «         ¦  «        st          d¦  «        ‚t          |Ž S )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é   c                 ó   — g | ]}g ‘ŒS r\   r\   ©r   r]   s     r   rC   z&Partition.from_rgs.<locals>.<listcomp>*  s   € Ð1Ð1Ð1˜A�RÐ1Ð1Ð1r   r   c              3   ó   K  — | ]}|V — Œd S r   r\   rA   s     r   r   z%Partition.from_rgs.<locals>.<genexpr>/  s"   è è € Ð(Ð(˜�1Ð(Ð(Ð(Ð(Ð(Ð(r   z(some blocks of the partition were empty.)r    r&   ÚmaxÚranger$   r%   r   )r=   r^   ÚelementsÚmax_elemr-   ra   r]   s          r   rI   zPartition.from_rgs  sÇ   € õ4 ˆs‰8Œ8•s˜8‘}”}Ò$Ð$ÝÐBÑCÔCÐCÝ�s‘8”8˜a‘<ˆØ1Ð1¥ x¡¤Ð1Ñ1Ô1ˆ	ØˆØð 	ð 	ˆAØ�aŒL×Ò ¨¤Ñ,Ô,Ð,Ø�‰FˆAˆAÝÐ(Ð(˜iÐ(Ñ(Ô(Ñ(Ô(ð 	IÝÐGÑHÔHÐHÝ˜)Ð$Ð$r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rW   rD   r(   r>   Úpropertyr-   rM   rP   rS   rU   r<   rY   ÚclassmethodrI   r\   r   r   r   r      sþ   € € € € € ð
ð 
ð €EØ€Jð<ð <ð <ð|Mð Mð Mð Mð6 ðð ñ „Xðð8ð 8ð 8ð0$ð $ð $ð&<ð <ð <ð(;ð ;ð ;ð" ðð ñ „Xðð" ð Gð  Gñ „Xð GðD ð#%ð #%ñ „[ð#%ð #%ð #%r   r   c                   ód   — 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dS )Ú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                 ó  — |�||}}t          |t          t          f¦  «        rug }t          |                     ¦   «         d¬¦  «        D ]?\  }}|sŒt          |¦  «        t          |¦  «        }}|                     |g|z  ¦  «         Œ@t          |¦  «        }n1t          t          t          t
          |¦  «        d¬¦  «        ¦  «        }d}|€t          |¦  «        }d}nt          |¦  «        }|s%t          |¦  «        |k    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

        NT©ÚreverseFzPartition did not add to %sc              3   ó"   K  — | ]
}|d k     V — ŒdS )rc   Nr\   re   s     r   r   z+IntegerPartition.__new__.<locals>.<genexpr>‰  s&   è è € Ð(Ð(˜ˆq�1ŠuÐ(Ð(Ð(Ð(Ð(Ð(r   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(   zIntegerPartition.__new__S  s~  € ðB ÐØ!*¨G�YˆGÝ�i¥$­ Ñ.Ô.ð 		LØˆAÝ˜yŸšÑ0Ô0¸$Ð?Ñ?Ô?ð  ð  ‘��1Øð ØÝ˜a‘y”y¥&¨¡)¤)�1�Ø—’˜!˜˜Q™‘”��Ý˜a™œˆIˆIå�f¥S­°Ñ%;Ô%;ÀTÐJÑJÔJÑKÔKˆIØˆØˆ?Ý˜)‘n”nˆGØˆFˆFå˜W‘o”oˆGàð 	F�#˜i™.œ.¨GÒ3Ð3ÝÐ:¸WÑDÑEÔEÐEÝÐ(Ð(˜iÐ(Ñ(Ô(Ñ(Ô(ð 	NÝÐLÑMÔMÐMåŒm˜C¥¨Ñ!1Ô!1µ5¸)Ð3DÑEÔEˆÝ˜Y™œˆŒØˆŒØˆ
r   c                 óH  — t          t          ¦  «        }|                     |                      ¦   «         ¦  «         | j        }|dgk    rt          | j        di¦  «        S |d         dk    r<||d         xx         dz  cc<   |d         dk    rd|d<   n{dx||d         dz
  <   |d<   ng||d         xx         dz  cc<   |d         |d         z   }|d         }d|d<   |r1|dz  }||z
  dk    r!||xx         ||z  z  cc<   |||         |z  z  }|°1t          | 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
        rc   éÿÿÿÿé   éþÿÿÿr   )r   ÚintÚupdateÚas_dictÚ_keysrr   r{   )r=   ÚdÚkeysÚleftÚnews        r   Úprev_lexzIntegerPartition.prev_lex‘  sR  € õ �ÑÔˆØ	�Š�—’‘”Ñ Ô Ð ØŒzˆØ�A�3Š;ˆ;Ý# T¤\°1Ð$5Ñ6Ô6Ð6Ø�Œ8�qŠ=ˆ=Øˆd�2ŒhˆKˆKŒK˜1ÑˆKˆK‰KØ�BŒx˜1Š}ˆ}Ø��!‘�à)*Ð*��$�r”(˜Q‘,‘ ! A¡$ $àˆd�2ŒhˆKˆKŒK˜1ÑˆKˆK‰KØ�Q”4˜$˜rœ(‘?ˆDØ�r”(ˆCØˆAˆa‰DØð 'Ø�q‘�Ø˜#‘: ’?�?Ø�c�F�F”F˜d C™iÑ'�F�F‘FØ˜A˜cœF 3™JÑ&�Dð	 ð 'õ
   ¤¨aÑ0Ô0Ð0r   c                 ób  — t          t          ¦  «        }|                     |                      ¦   «         ¦  «         | j        }|d         }|| j        k    r |                     ¦   «          | j        |d<   �n&|dk    rb||         dk    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k    rlt          |¦  «        dk    r-|                     ¦   «          d||dz   <   | j        |z
  dz
  |d<   nr|dz   }||xx         dz  cc<   ||         |z  |z
  |d<   d||<   nF|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
        r�   rc   r‚   rƒ   r   )	r   r„   r…   r†   r‡   r{   Úclearr    rr   )r=   rˆ   r9   ÚaÚbÚa1Úb1Úneeds           r   Únext_lexzIntegerPartition.next_lex¶  sæ  € õ �ÑÔˆØ	�Š�—’‘”Ñ Ô Ð ØŒjˆØ�ŒGˆØ�”ÒÐØ�GŠG‰IŒIˆIØ”<ˆAˆa‰D‰DØ�!ŠVˆVØ�Œt�aŠxˆxØ�!�a‘%��”˜A‘��‘Ø�!��”˜‘	��‘�à˜”G�Ø�!�a‘%��”˜A‘��‘Ø˜!œ˜q™ !‘|��!‘Ø��!‘�à�Œt�aŠxˆxÝ�s‘8”8˜q’=�=Ø—G’G‘I”I�IØ �A�a˜!‘e‘HØœ<¨!Ñ+¨aÑ/�A�a‘D�Dà˜Q™�BØ�b�E�E”E˜Q‘J�E�E‘EØ˜Qœ4 ™6 B™;�A�a‘DØ�A�a‘D�Dà˜”G�Ø˜‘U�Ø�"��”˜‘
��‘Ø˜”t˜A‘v  !¤ Q¡‘¨Ñ+�Ø���!‘�q˜‘tØ��!‘Ý ¤¨aÑ0Ô0Ð0r   c                 ó”   — | j         €;t          | j        d¬¦  «        }d„ |D ¦   «         | _        t	          |¦  «        | _         | j         S )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}
        NF)Úmultiplec                 ó   — g | ]
}|d          ‘ŒS )r   r\   )r   Úgs     r   rC   z,IntegerPartition.as_dict.<locals>.<listcomp>ö  s   € Ð/Ð/Ð/ 1˜!˜Aœ$Ð/Ð/Ð/r   )Ú_dictr   r-   r‡   rw   )r=   Úgroupss     r   r†   zIntegerPartition.as_dictè  sJ   € ð Œ:ÐÝ˜4œ>°EÐ:Ñ:Ô:ˆFØ/Ð/¨Ð/Ñ/Ô/ˆDŒJÝ˜f™œˆDŒJØŒzÐr   c                 óÂ   — d}t          | j        ¦  «        dgz   }|d         }dg|z  }|dk    r0|||         k    r|||dz
  <   |dz  }|||         k    °|dz  }|dk    °0|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]
        rc   r   )r"   r-   )r=   ra   Útemp_arrr}   r�   s        r   Ú	conjugatezIntegerPartition.conjugateú  s‹   € ð ˆÝ˜œÑ'Ô'¨1¨#Ñ-ˆØ�QŒKˆØˆC�‰EˆØ�!ŠeˆeØ�h˜q”k’/�/Ø��!�a‘%‘Ø�Q‘�ð �h˜q”k’/�/ð �‰FˆAð	 �!Šeˆeð
 ˆr   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-   rO   s     r   rU   zIntegerPartition.__lt__  s3   € õ" •H˜Tœ^Ñ,Ô,Ñ-Ô-µµX¸e¼oÑ5NÔ5NÑ0OÔ0OÒOÐOr   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Ÿ   rO   s     r   rS   zIntegerPartition.__le__%  s3   € õ •H˜Tœ^Ñ,Ô,Ñ-Ô-µµh¸u¼Ñ6OÔ6OÑ1PÔ1PÒPÐPr   ú#c                 óP   ‡— d                      ˆfd„| j        D ¦   «         ¦  «        S )a  
        Prints the ferrer diagram of a partition.

        Examples
        ========

        >>> from sympy.combinatorics.partitions import IntegerPartition
        >>> print(IntegerPartition([1, 1, 5]).as_ferrers())
        #####
        #
        #
        ú
c                 ó   •— g | ]}‰|z  ‘ŒS r\   r\   )r   r]   Úchars     €r   rC   z/IntegerPartition.as_ferrers.<locals>.<listcomp>@  s   ø€ Ð9Ð9Ð9 Q˜$˜q™&Ð9Ð9Ð9r   )Újoinr-   )r=   r¦   s    `r   Ú
as_ferrerszIntegerPartition.as_ferrers3  s.   ø€ ð �yŠyÐ9Ð9Ð9Ð9¨$¬.Ð9Ñ9Ô9Ñ:Ô:Ð:r   c                 óD   — t          t          | j        ¦  «        ¦  «        S r   )Ústrr"   r-   rE   s    r   Ú__str__zIntegerPartition.__str__B  s   € Ý•4˜œÑ'Ô'Ñ(Ô(Ð(r   r   )r¢   )rk   rl   rm   rn   r™   r‡   r(   rŒ   r”   r†   ro   r�   rU   rS   r¨   r«   r\   r   r   rr   rr   4  sÐ   € € € € € ðð ð6 €EØ€Eð<ð <ð <ð <ð|#1ð #1ð #1ðJ01ð 01ð 01ðdð ð ð$ ðð ñ „Xðð.Pð Pð Pð&Qð Qð Qð;ð ;ð ;ð ;ð)ð )ð )ð )ð )r   rr   Nc                 ó^  — ddl m} t          | ¦  «        } | dk     rt          d¦  «        ‚ ||¦  «        }g }| dk    r@ |d| ¦  «        } |d| |z  ¦  «        }|                     ||f¦  «         | ||z  z  } | dk    °@|                     d¬¦  «         t          d„ |D ¦   «         ¦  «        }|S )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   )Ú_randintrc   zn must be a positive integerTrt   c                 ó    — g | ]\  }}|g|z  ‘ŒS r\   r\   )r   r}   Úms      r   rC   z,random_integer_partition.<locals>.<listcomp>i  s"   € Ð5Ð5Ð5¡4 1 a˜!˜˜Q™Ð5Ð5Ð5r   )Úsympy.core.randomr­   r   r&   r$   Úsortr   )ÚnÚseedr­   Úrandintr-   r}   Úmults          r   Úrandom_integer_partitionr¶   F  sà   € ð( +Ð*Ð*Ð*Ð*Ð*åˆq‰	Œ	€AØˆ1‚u€uÝÐ7Ñ8Ô8Ð8àˆh�t‰nŒn€Gà€IØˆqŠ5ˆ5ØˆG�A�q‰MŒMˆØˆw�q˜!˜Q™$ÑÔˆØ×Ò˜!˜T˜Ñ#Ô#Ð#Ø	ˆQˆt‰V‰ˆð	 ˆqŠ5ˆ5ð
 ‡N‚N˜4€NÑ Ô Ð ÝÐ5Ð5¨9Ð5Ñ5Ô5Ñ6Ô6€IØÐr   c                 ó   — t          | dz   ¦  «        }t          | dz   ¦  «        D ]	}d|d|f<   Œ
t          d| dz   ¦  «        D ]K}t          | ¦  «        D ]9}|| |z
  k    r'|||dz
  |f         z  ||dz
  |dz   f         z   |||f<   Œ2d|||f<   Œ:ŒL|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]])
    rc   r   )r   rh   )r¯   rˆ   r]   ra   s       r   ÚRGS_generalizedr¸   m  sÇ   € õ& 	ˆa�!‰e‰Œ€AÝ�1�q‘5‰\Œ\ð ð ˆØˆˆ!ˆQˆ$‰ˆå�1�a˜!‘e‰_Œ_ð ð ˆÝ�q‘”ð 	ð 	ˆAØ�A˜‘EŠzˆzØ˜a  A¡ q œk™/¨A¨a°!©e°Q¸±U¨l¬OÑ;��!�Q�$‘�à��!�Q�$‘�ð		ð
 €Hr   c                 ó@   — | dk     rdS | dk    rdS 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

    rc   r   r   )r¯   s    r   rH   rH   �  s+   € ð: 	
ˆAŠˆØˆqØ
ˆqŠ&ˆ&Øˆqå�A‰wŒwˆr   c                 ó”  — |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 ]J}|||z
  |f         }||z  }|| k    r|dz   ||<   | |z  } |dz  }Œ-t	          | |z  dz   ¦  «        ||<   | |z  } ŒKd„ |dd…         D ¦   «         S )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]
    rc   zThe superset size must be >= 1r   zInvalid argumentsr‚   c                 ó   — g | ]}|d z
  ‘ŒS )rc   r\   )r   Úxs     r   rC   zRGS_unrank.<locals>.<listcomp>Ò  s   € Ð!Ð!Ð!�aˆA�‰EÐ!Ð!Ð!r   N)r&   rH   r¸   rh   r„   )r<   r¯   ÚLra   ÚDr]   r~   Úcrs           r   rG   rG   ²  s  € ð 	ˆ1‚u€uÝÐ9Ñ:Ô:Ð:Øˆa‚x€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ˆAå�t˜a‘x !‘|Ñ$Ô$ˆAˆa‰DØ�A‰IˆDˆDØ!Ð!˜1˜Q˜R˜Rœ5Ð!Ñ!Ô!Ð!r   c                 ó   — t          | ¦  «        }d}t          |¦  «        }t          d|¦  «        D ]L}t          | |dz   d…         ¦  «        }t          | d|…         ¦  «        }||||dz   f         | |         z  z  }ŒM|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   rc   N)r    r¸   rh   rg   )r^   Úrgs_sizer<   r¾   r]   r²   r¯   s          r   rX   rX   Õ  sŒ   € õ �3‰xŒx€HØ€DÝ˜Ñ!Ô!€AÝ�1�hÑÔð %ð %ˆÝ��Q˜‘U�H�H”ÑÔˆÝ��A�a�C”‰MŒMˆØ��!�Q˜‘U�(”˜c !œfÑ$Ñ$ˆˆØ€Kr   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   rr   r¶   r¸   rH   rG   rX   r\   r   r   ú<module>rÌ      s�  ðØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø &Ð &Ð &Ð &Ð &Ð &Ø /Ð /Ð /Ð /Ð /Ð /Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø  Ð  Ð  Ð  Ð  Ð  Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'ð $Ð #Ð #Ð #Ð #Ð #ðb%ð b%ð b%ð b%ð b%�	ñ b%ô b%ð b%ðJ	O)ð O)ð O)ð O)ð O)�uñ O)ô O)ð O)ðd$ð $ð $ð $ðNð ð ð@"ð "ð "ðJ "ð  "ð  "ðFð ð ð ð r   