Ë
    7^(h¯>  ã                   ó6   — d dl mZ d dlmZ  G d„ d«      Zd„ Zy)é    ©Úcombinations)ÚGrayCodec                   ó0  — e Zd ZdZdZdZdZdZdZd„ Z	d„ Z
d„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z ed„ «       Z!y)ÚSubseta  
    Represents a basic subset object.

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

    We generate subsets using essentially two techniques,
    binary enumeration and lexicographic enumeration.
    The Subset class takes two arguments, the first one
    describes the initial subset to consider and the second
    describes the superset.

    Examples
    ========

    >>> from sympy.combinatorics import Subset
    >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
    >>> a.next_binary().subset
    ['b']
    >>> a.prev_binary().subset
    ['c']
    Nc                 óÚ   — t        |«      t        |«      kD  rt        d«      ‚|D ]   }||vsŒt        dj                  |«      «      ‚ t        j	                  | «      }||_        ||_        |S )ax  
        Default constructor.

        It takes the ``subset`` and its ``superset`` as its parameters.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.subset
        ['c', 'd']
        >>> a.superset
        ['a', 'b', 'c', 'd']
        >>> a.size
        2
        zRInvalid arguments have been provided. The superset must be larger than the subset.zFThe superset provided is invalid as it does not contain the element {})ÚlenÚ
ValueErrorÚformatÚobjectÚ__new__Ú_subsetÚ	_superset)ÚclsÚsubsetÚsupersetÚelemÚobjs        úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/combinatorics/subsets.pyr   zSubset.__new__$   s‚   € ô$ ˆv‹;œ˜X›Ò&Üð Hó Ið Iàò 	LˆDØ˜8Ò#Ü ð ">ß>D¹fÀT»lóLð Lð	Lô �n‰n˜SÓ!ˆØˆŒØ ˆŒØˆ
ó    c                 ó–   — t        |t        «      st        S | j                  |j                  k(  xr | j                  |j                  k(  S )zÆReturn a boolean indicating whether a == b on the basis of
        whether both objects are of the class Subset and if the values
        of the subset and superset attributes are the same.
        )Ú
isinstancer   ÚNotImplementedr   r   )ÚselfÚothers     r   Ú__eq__zSubset.__eq__B   s9   € ô
 ˜%¤Ô(Ü!Ð!Ø�{‰{˜eŸl™lÑ*ÒN¨t¯}©}ÀÇÁÑ/NÐNr   c                 óB  — t         j                  | j                  | j                  «      }t	        dj                  |«      d«      |z   d| j                  z  z  }t        |«      dd j                  | j                  d«      }t         j                  | j                  |«      S )a  
        This is a helper function. It iterates over the
        binary subsets by ``k`` steps. This variable can be
        both positive or negative.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.iterate_binary(-2).subset
        ['d']
        >>> a = Subset(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])
        >>> a.iterate_binary(2).subset
        []

        See Also
        ========

        next_binary, prev_binary
        Ú é   NÚ0)
r   Úbitlist_from_subsetr   r   ÚintÚjoinÚsuperset_sizeÚbinÚrjustÚsubset_from_bitlist)r   ÚkÚbin_listÚnÚbitss        r   Úiterate_binaryzSubset.iterate_binaryK   s�   € ô, ×-Ñ-¨d¯k©k¸4¿=¹=ÓIˆÜ�—‘˜Ó" AÓ&¨Ñ*¨a°×1CÑ1CÑ.CÑCˆÜ�1‹v�a�bˆz×Ñ × 2Ñ 2°CÓ8ˆÜ×)Ñ)¨$¯-©-¸Ó>Ð>r   c                 ó$   — | j                  d«      S )aµ  
        Generates the next binary ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.next_binary().subset
        ['b']
        >>> a = Subset(['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.next_binary().subset
        []

        See Also
        ========

        prev_binary, iterate_binary
        é   ©r,   ©r   s    r   Únext_binaryzSubset.next_binaryf   s   € ð( ×"Ñ" 1Ó%Ð%r   c                 ó$   — | j                  d«      S )a¹  
        Generates the previous binary ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([], ['a', 'b', 'c', 'd'])
        >>> a.prev_binary().subset
        ['a', 'b', 'c', 'd']
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.prev_binary().subset
        ['c']

        See Also
        ========

        next_binary, iterate_binary
        éÿÿÿÿr/   r0   s    r   Úprev_binaryzSubset.prev_binary|   s   € ð( ×"Ñ" 2Ó&Ð&r   c                 ó(  — | j                   dz
  }t        j                  | j                  | j                  «      }||v ru|dz
  |v r|j                  |dz
  «       n…|j                  |«       |dz
  }|dk\  r||vr|dz
  }|dk\  r||vrŒ|dk\  rR|j                  |«       |j                  |dz   «       n,||vr|dk\  r|dz
  }||vr|dk\  rŒ|j                  |dz   «       g }| j                  }|D ]  }|j                  ||   «       Œ t        ||«      S )a¶  
        Generates the next lexicographically ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.next_lexicographic().subset
        ['d']
        >>> a = Subset(['d'], ['a', 'b', 'c', 'd'])
        >>> a.next_lexicographic().subset
        []

        See Also
        ========

        prev_lexicographic
        r.   r   ©r$   r   Úsubset_indicesr   r   ÚremoveÚappend©r   ÚiÚindicesÚret_setÚ	super_sets        r   Únext_lexicographiczSubset.next_lexicographic’   s!  € ð( ×Ñ Ñ"ˆÜ×'Ñ'¨¯©°T·]±]ÓCˆà�‰<Ø�1‰u˜ÑØ—‘˜q 1™uÕ%à—‘˜qÔ!Ø˜‘E�Ø˜1’f ¨'Ñ!1Ø˜A™�Að ˜1’f ¨'Ò!1à˜’6Ø—N‘N 1Ô%Ø—N‘N 1 Q¡3Õ'à˜7Ñ" q¨A¢vØ˜‘E�ð ˜7Ñ" q¨A£và�N‰N˜1˜q™5Ô!àˆØ—M‘Mˆ	Øò 	)ˆAØ�N‰N˜9 Q™<Õ(ð	)ä�g˜yÓ)Ð)r   c                 óÚ  — | j                   dz
  }t        j                  | j                  | j                  «      }|dk\  r||vr|dz
  }|dk\  r||vrŒ|dk(  s|dz
  |v r|j                  |«       nH|dk\  r%|j                  |«       |j                  |dz
  «       |j                  | j                   dz
  «       g }| j                  }|D ]  }|j                  ||   «       Œ t        ||«      S )a¹  
        Generates the previous lexicographically ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([], ['a', 'b', 'c', 'd'])
        >>> a.prev_lexicographic().subset
        ['d']
        >>> a = Subset(['c','d'], ['a', 'b', 'c', 'd'])
        >>> a.prev_lexicographic().subset
        ['c']

        See Also
        ========

        next_lexicographic
        r.   r   r6   r:   s        r   Úprev_lexicographiczSubset.prev_lexicographic¿   sé   € ð( ×Ñ Ñ"ˆÜ×'Ñ'¨¯©°T·]±]ÓCˆà�1Šf˜ 'Ñ)Ø�A‘ˆAð �1Šf˜ 'Ò)ð �Š6�Q˜‘U˜gÑ%Ø�N‰N˜1Õà�AŠvØ—‘˜qÔ!Ø—‘˜q 1™uÔ%Ø�N‰N˜4×-Ñ-°Ñ1Ô2àˆØ—M‘Mˆ	Øò 	)ˆAØ�N‰N˜9 Q™<Õ(ð	)ä�g˜yÓ)Ð)r   c                 ó¶   — t        j                  | j                  | j                  |z   | j                  z  «      }t
        j                  | j                  |«      S )aÆ  
        Helper function used for prev_gray and next_gray.
        It performs ``k`` step overs to get the respective Gray codes.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([1, 2, 3], [1, 2, 3, 4])
        >>> a.iterate_graycode(3).subset
        [1, 4]
        >>> a.iterate_graycode(-2).subset
        [1, 2, 4]

        See Also
        ========

        next_gray, prev_gray
        )r   Úunrankr$   Ú	rank_grayÚcardinalityr   r'   r   )r   r(   Úunranked_codes      r   Úiterate_graycodezSubset.iterate_graycodeç   sN   € ô( !Ÿ™¨×(:Ñ(:Ø(,¯©¸Ñ(:¸d×>NÑ>NÑ'NóPˆä×)Ñ)¨$¯-©-Ø*7ó9ð 	9r   c                 ó$   — | j                  d«      S )a=  
        Generates the next Gray code ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([1, 2, 3], [1, 2, 3, 4])
        >>> a.next_gray().subset
        [1, 3]

        See Also
        ========

        iterate_graycode, prev_gray
        r.   ©rG   r0   s    r   Ú	next_grayzSubset.next_gray   s   € ð" ×$Ñ$ QÓ'Ð'r   c                 ó$   — | j                  d«      S )aJ  
        Generates the previous Gray code ordered subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([2, 3, 4], [1, 2, 3, 4, 5])
        >>> a.prev_gray().subset
        [2, 3, 4, 5]

        See Also
        ========

        iterate_graycode, next_gray
        r3   rI   r0   s    r   Ú	prev_grayzSubset.prev_gray  s   € ð" ×$Ñ$ RÓ(Ð(r   c                 óÂ   — | j                   €Ht        dj                  t        j	                  | j
                  | j                  «      «      d«      | _         | j                   S )aƒ  
        Computes the binary ordered rank.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset([], ['a','b','c','d'])
        >>> a.rank_binary
        0
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.rank_binary
        3

        See Also
        ========

        iterate_binary, unrank_binary
        r   r   )Ú_rank_binaryr"   r#   r   r!   r   r   r0   s    r   Úrank_binaryzSubset.rank_binary&  sT   € ð* ×ÑÐ$Ü # B§G¡GÜ×*Ñ*¨4¯;©;Ø+/¯=©=ó:ó%;à<=ó!?ˆDÔð × Ñ Ð r   c                 óÆ   ‡— | j                   €Iˆfd„Št        j                  | j                  | j                  «      } ‰| |d| j
                  «      | _         | j                   S )aa  
        Computes the lexicographic ranking of the subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.rank_lexicographic
        14
        >>> a = Subset([2, 4, 5], [1, 2, 3, 4, 5, 6])
        >>> a.rank_lexicographic
        43
        c                 óš   •— |g k(  s||kD  ry||v r"|j                  |«       d ‰| ||dz   |«      z   S d||z
  dz
  z   ‰| ||dz   |«      z   S )Nr   r.   r   )r8   )r   Úsubset_indexr;   r*   Ú_ranklexs       €r   rS   z+Subset.rank_lexicographic.<locals>._ranklexR  sj   ø€ Ø 2Ò%¨¨QªØØ˜Ñ$Ø ×'Ñ'¨Ô*Ø™x¨¨l¸AÀ¹EÀ1ÓEÑEÐEØ˜1˜q™5 1™9‘~©°°|ÀQÈÁUÈAÓ(NÑNÐNr   r   )Ú	_rank_lexr   r7   r   r   r$   )r   r<   rS   s     @r   Úrank_lexicographiczSubset.rank_lexicographicA  sS   ø€ ð  �>‰>Ð!ôOô ×+Ñ+¨D¯K©K¸¿¹ÓGˆGÙ% d¨G°Q¸×8JÑ8JÓKˆDŒNØ�~‰~Ðr   c                 óÐ   — | j                   €Ot        j                  | j                  | j                  «      }t        t        |«      |¬«      j                  | _         | j                   S )a�  
        Computes the Gray code ranking of the subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c','d'], ['a','b','c','d'])
        >>> a.rank_gray
        2
        >>> a = Subset([2, 4, 5], [1, 2, 3, 4, 5, 6])
        >>> a.rank_gray
        27

        See Also
        ========

        iterate_graycode, unrank_gray
        )Ústart)Ú_rank_graycoder   r!   r   r   r   r	   Úrank)r   r+   s     r   rD   zSubset.rank_gray]  sO   € ð* ×ÑÐ&Ü×-Ñ-¨d¯k©k¸4¿=¹=ÓIˆDÜ"*¬3¨t«9¸DÔ"A×"FÑ"FˆDÔØ×"Ñ"Ð"r   c                 ó   — | j                   S )aU  
        Gets the subset represented by the current instance.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.subset
        ['c', 'd']

        See Also
        ========

        superset, size, superset_size, cardinality
        )r   r0   s    r   r   zSubset.subsetw  s   € ð$ �|‰|Ðr   c                 ó,   — t        | j                  «      S )a4  
        Gets the size of the subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.size
        2

        See Also
        ========

        subset, superset, superset_size, cardinality
        )r	   r   r0   s    r   ÚsizezSubset.size‹  s   € ô$ �4—;‘;ÓÐr   c                 ó   — | j                   S )aK  
        Gets the superset of the subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.superset
        ['a', 'b', 'c', 'd']

        See Also
        ========

        subset, size, superset_size, cardinality
        )r   r0   s    r   r   zSubset.supersetŸ  s   € ð$ �~‰~Ðr   c                 ó,   — t        | j                  «      S )a9  
        Returns the size of the superset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.superset_size
        4

        See Also
        ========

        subset, superset, size, cardinality
        )r	   r   r0   s    r   r$   zSubset.superset_size³  s   € ô$ �4—=‘=Ó!Ð!r   c                 ó    — d| j                   z  S )aD  
        Returns the number of all possible subsets.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> a = Subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        >>> a.cardinality
        16

        See Also
        ========

        subset, superset, size, superset_size
        r   )r$   r0   s    r   rE   zSubset.cardinalityÇ  s   € ð$ �4×%Ñ%Ñ&Ð&r   c                 óÎ   — t        |«      t        |«      k7  rt        d«      ‚g }t        t        |«      «      D ]  }||   dk(  sŒ|j                  ||   «       Œ! t	        ||«      S )a/  
        Gets the subset defined by the bitlist.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> Subset.subset_from_bitlist(['a', 'b', 'c', 'd'], '0011').subset
        ['c', 'd']

        See Also
        ========

        bitlist_from_subset
        z$The sizes of the lists are not equalÚ1)r	   r
   Úranger9   r   )r   r>   Úbitlistr=   r;   s        r   r'   zSubset.subset_from_bitlistÛ  sh   € ô" ˆy‹>œS ›\Ò)ÜÐCÓDÐDØˆÜ”s˜7“|Ó$ò 	-ˆAØ�q‰z˜SÓ Ø—‘˜y¨™|Õ,ð	-ô �g˜yÓ)Ð)r   c                 óº   — dgt        |«      z  }t        |t        «      r|j                  }t        j	                  ||«      D ]  }d||<   Œ	 dj                  |«      S )a,  
        Gets the bitlist corresponding to a subset.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> Subset.bitlist_from_subset(['c', 'd'], ['a', 'b', 'c', 'd'])
        '0011'

        See Also
        ========

        subset_from_bitlist
        r    ra   r   )r	   r   r   r   r7   r#   )r   r   r   rc   r;   s        r   r!   zSubset.bitlist_from_subsetô  s[   € ð" �%œ#˜h›-Ñ'ˆÜ�fœfÔ%Ø—]‘]ˆFÜ×&Ñ& v¨xÓ8ò 	ˆAØˆG�AŠJð	à�w‰w�wÓÐr   c                 ó|   — t        |«      dd j                  t        |«      d«      }t        j	                  ||«      S )a5  
        Gets the binary ordered subset of the specified rank.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> Subset.unrank_binary(4, ['a', 'b', 'c', 'd']).subset
        ['b']

        See Also
        ========

        iterate_binary, rank_binary
        r   Nr    )r%   r&   r	   r   r'   )r   rY   r   r+   s       r   Úunrank_binaryzSubset.unrank_binary  s7   € ô" �4‹y˜˜ˆ}×"Ñ"¤3 x£=°#Ó6ˆÜ×)Ñ)¨(°DÓ9Ð9r   c                 ól   — t        j                  t        |«      |«      }t        j	                  ||«      S )a{  
        Gets the Gray code ordered subset of the specified rank.

        Examples
        ========

        >>> from sympy.combinatorics import Subset
        >>> Subset.unrank_gray(4, ['a', 'b', 'c']).subset
        ['a', 'b']
        >>> Subset.unrank_gray(0, ['a', 'b', 'c']).subset
        []

        See Also
        ========

        iterate_graycode, rank_gray
        )r   rC   r	   r   r'   )r   rY   r   Úgraycode_bitlists       r   Úunrank_grayzSubset.unrank_gray   s-   € ô& $Ÿ?™?¬3¨x«=¸$Ó?ÐÜ×)Ñ)¨(Ð4DÓEÐEr   c                 ó¼   — ||}}t        |«      }i }t        |«      D ]$  \  }}||v sŒ|||<   |j                  |«       |rŒ$ n g S |D �	cg c]  }	||	   ‘Œ	 c}	S c c}	w )aë  Return indices of subset in superset in a list; the list is empty
        if all elements of ``subset`` are not in ``superset``.

        Examples
        ========

            >>> from sympy.combinatorics import Subset
            >>> superset = [1, 3, 2, 5, 4]
            >>> Subset.subset_indices([3, 2, 1], superset)
            [1, 2, 0]
            >>> Subset.subset_indices([1, 6], superset)
            []
            >>> Subset.subset_indices([], superset)
            []

        )ÚsetÚ	enumerater8   )
r   r   r   ÚaÚbÚsbÚdr;   ÚaiÚbis
             r   r7   zSubset.subset_indices6  sr   € ð$ ˜ˆ1ˆÜ�‹VˆØˆÜ˜q“\ò 	‰EˆAˆrØ�RŠxØ��"‘Ø—	‘	˜"”ÚÙð	ð ˆIØ !Ö"˜"��"“Ò"Ð"ùÒ"s   Á
A)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__rN   rT   rX   r   r   r   r   r,   r1   r4   r?   rA   rG   rJ   rL   ÚpropertyrO   rU   rD   r   r\   r   r$   rE   Úclassmethodr'   r!   rf   ri   r7   © r   r   r   r      s]  „ ñð. €LØ€IØ€NØ€GØ€Iòò<Oò?ò6&ò,'ò,+*òZ&*òP9ò2(ò&)ð& ñ!ó ð!ð4 ñó ðð6 ñ#ó ð#ð2 ñó ðð& ñ ó ð ð& ñó ðð& ñ"ó ð"ð& ñ'ó ð'ð& ñ*ó ð*ð0 ñ ó ð ð. ñ:ó ð:ð& ñFó ðFð* ñ#ó ñ#r   r   c                 ó   — t        | |«      S )a«  
    Finds the subsets of size ``k`` in lexicographic order.

    This uses the itertools generator.

    Examples
    ========

    >>> from sympy.combinatorics.subsets import ksubsets
    >>> list(ksubsets([1, 2, 3], 2))
    [(1, 2), (1, 3), (2, 3)]
    >>> list(ksubsets([1, 2, 3, 4, 5], 2))
    [(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4),     (2, 5), (3, 4), (3, 5), (4, 5)]

    See Also
    ========

    Subset
    r   )r   r(   s     r   Úksubsetsr{   V  s   € ô* ˜ !Ó$Ð$r   N)Ú	itertoolsr   Úsympy.combinatorics.graycoder   r   r{   ry   r   r   ú<module>r~      s   ðÝ "å 1÷M	#ñ M	#ó`%r   