a
    sh؉                     @   s  d dl mZ d dlmZ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 d dlmZ d d	lmZmZmZ d d
lmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d dlLmMZMmNZN d dlOmPZP d dlQmRZRmSZS ed\ZTZUZVZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd  Z`d!d" Zad#d$ Zbd%d& Zcd'd( Zdd)d* Zed+d, Zfd-d. Zgd/d0 Zhd1d2 Zid3d4 Zjd5d6 Zkd7d8 Zld9d: Zmd;d< Znd=d> Zod?d@ ZpdAdB ZqdCdD ZrdEdF ZsdGdH ZtdIdJ ZudKdL ZvdMdN ZwdOdP ZxdQdR ZydSdT ZzdUdV Z{dWdX Z|dYdZ Z}d[d\ Z~d]d^ Zd_d` Zdadb Zdcdd Zdedf Zdgdh Zdidj Zdkdl ZdmS )n    )dedent)isliceproduct)Basic)Integerordered)Dummysymbols	factorial)Matrix)RGS_enum
RGS_unrankPermutation)5
_partition_set_partitionsbinary_partitions	braceletscapturecartescommon_prefixcommon_suffixconnected_components
dict_mergefilter_symbolsflattengenerate_bellgenerate_derangementsgenerate_involutionsgenerate_oriented_forestgrouphas_dupsibiniproductkbinsminlexmultisetmultiset_combinationsmultiset_partitionsmultiset_permutations	necklacesnumbered_symbols
partitionspermutations	postfixesprefixesreshaperotate_leftrotate_rightrunssiftstrongly_connected_componentssubsetstaketopological_sort	unflattenuniq
variationsordered_partitions	rotationsis_palindromiciterableNotIterablemultiset_derangementssigned_permutationssequence_partitionssequence_partitions_empty)factoring_visitormultiset_partitions_taocp)S)raiseswarns_deprecated_sympyzw,x,y,zc                  C   s   ddl m} m} t , t|ttgttgks4J W d    n1 sH0    Y  t , tttg| dttgksvJ W d    n1 s0    Y  d S )Nr   default_sort_keyr   key)sympy.utilities.iterablesrL   r   rJ   listyxsortedrK    rT   `/var/www/html/assistant/venv/lib/python3.9/site-packages/sympy/utilities/tests/test_iterables.pytest_deprecated_iterables!   s
    :rV   c                   C   s   t dsJ t dsJ t ds$J t ds0J t dr<J t drHJ t ddsVJ t dd	rdJ t dd	d
stJ t dd	dsJ t ddsJ t dd	rJ t dd	dsJ d S )N rR   xxZxyxZxyZxyzxZxxyzzyx         Zxxyzyx   )r?   rT   rT   rT   rU   test_is_palindromic)   s    r^   c                     s&  t dddgksJ t ttffttgks.J ddgdgg t  dd ksPJ t  ddg dkshJ t  d	dg d
ksJ t  ddg d
ksJ tt fdd G dd dt} t | tttg| tttgksJ t | tttg| dtttgksJ t h dth dks"J d S )N)rY   rY   rY   r[   rY   rZ   r   r   r   Zlevels)r`   rb   rc   rZ   )ra   r[   rY   rZ   r   r      c                      s   t  ddS )Nr[   rd   )r   rT   ZlsrT   rU   <lambda>D       ztest_flatten.<locals>.<lambda>c                   @   s   e Zd ZdS )ztest_flatten.<locals>.MyOpN__name__
__module____qualname__rT   rT   rT   rU   MyOpF   s   rm   cls>   rY   rZ      )r   rR   rI   
ValueErrorr   rQ   zrP   )rm   rT   rf   rU   test_flatten9   s    $&rs   c                  C   s  t t dgksJ t tg g ks(J t tg dg dksDJ ttddgg dg dksfJ ttddgddgddgg d	ksJ tttjd
u sJ tttjtjd
u sJ dttjv sJ dttjtjv sJ dttjtjtjv sJ ttttjtjtjd} | D ]<\}}}t|t	s<J t|t	sLJ t|t	s"J q"tt
tddgd  D ]"}|ttjtjtjv sxJ qxd S )NrT   rY   rZ   re   r_   rZ   re   rY   rZ   re      r]   rY   re   )rY   ry   )rY   r]   rZ   re   rZ   ry   )rZ   r]   r   r   r   r   r   r   rY   )r   rY   r   r   rY   rY   )rY   r   r   rY   r   rY   rY   rY   r   rY   rY   rY   Trw   )ry   r]   i  ra   re   )rP   r$   rS   r@   rH   ZIntegerssetr   
isinstancer   r   range)ZtriplesZn1Zn2Zn3trT   rT   rU   test_iproductO   s"    "(r   c                   C   sD  t g g ksJ t g ddg ks$J t dgdggks:J t dgdddgksRJ t ddgddggkslJ t ddgdddgksJ t g dg dgksJ t g ddddgksJ t g ddgd	gdggksJ t g dddg d
ksJ t g dddgg ddgddggks"J t g dddg dks@J d S )NF)ZmultiplerY   rY   rY   rb   r   r{   rY   rZ   rY   rZ   )r   rZ   rY   r   )rY   rY   rZ   rZ   rZ   rY   re   re   rZ   rZ   rZ   re   )rb   r|   r   re   rZ   )r!   rT   rT   rT   rU   
test_groupe   s     ,r   c                  C   s  t tg dddgksJ t tg ddg dks:J t tg ddg dksXJ t tg dddgkstJ t td	} t t| dd
ddgksJ t t| dd
dg dksJ t t| dd
dg dksJ t t| dd
dg dksJ tt t| d	d
ddksJ t t| d d dddg ks:J t t| d d dd
dg dksbJ t tddgd
dg dksJ t tddgddg dksJ t tg ddg dksJ t tg ddd
dg dksJ d S )Nrt   r   rT   rY   ru   rZ   )rb   r{   r|   re   ry   TZ
repetitionr   r_   rv   rw   )
rc   r   rY   r   rZ   r   re   r   rb   r{   rZ   rZ   r|   re   re   )r   r   )r   r   rZ   )r   r   re   r   r   rY   rZ   r   rY   re   )r   rZ   rZ   r   rZ   re   )r   re   re   r   rY   rY   rZ   rY   rY   re   rY   rZ   rZ   rt   )rY   re   re   r   )rZ   rZ   re   )rZ   re   re   )re   re   re   #   F)r   r   r   r   )rT   r_   rv   r   rb   r   )rT   r_   rv   rb   )r   rb   r{   r   r|   r   )rP   r7   r   lenlrT   rT   rU   test_subsetsz   s0    
 $(


r   c                  C   sh  t td} t t| ddddgks(J t t| dddg dksFJ t t| dddg d	ksdJ t t| d
ddg dksJ t t| ddddgksJ t t| dddg dksJ t t| dddg dksJ tt t| d
dddksJ tt t| ddddksJ t t| d d d
ddg ks<J t t| d d d
ddg dksdJ d S )Nry   r   Fr   rT   rY   r   rZ   )r   r   r   rY   r   rb   r{   rZ   r   r   r|   re   r   re   rY   r   re   )r   r   r   rZ   rY   r   r   re   rY   )r   re   rZ   rY   r   rZ   )rY   r   re   rY   rZ   r   rt   )rY   re   r   )rY   re   rZ   rZ   r   rY   )rZ   r   re   rZ   rY   r   )rZ   rY   re   )rZ   re   r   )rZ   re   rY   )re   r   rY   )re   r   rZ   )re   rY   r   )re   rY   rZ   )re   rZ   r   re   rZ   rY   T)rc   r   r   r   r   r   rb   r{   r   r   r   r|   r   r   r   r   @      r~   )rP   r   r<   r   r   rT   rT   rU   test_variations   s     $r   c                   C   s   t tddgg dg dks"J t t dgks6J t tddgksLJ t tdddd	gksfJ t tt tdd
dgksJ d S )NrY   rZ   rx   rz   rT   a)r   )repeat)r   r   r   r_   )rP   r   r   rT   rT   rT   rU   test_cartes   s    r   c                  C   s2   t  } t| td}t|dttdks.J d S )Nzx0 x2 x3re   zx1 x4 x5)r,   r   r
   r8   rP   )sfilteredrT   rT   rU   test_filter_symbols   s    r   c                  C   sD   t td} tt| tsJ tt ddtdgdtdks@J d S )Nrn   CrY   ZC1)startexcludeZC2)r,   r	   r   nextr
   )r   rT   rT   rU   test_numbered_symbols   s
    
r   c                   C   s   t ttddd ddgg ddks,J t ttgdd tgtgd	ksPJ t tjgd
d ddgikspJ t g ddd ddddgddgfksJ t g ddd dddgg dfksJ ttdd  d S )Nr]   c                 S   s   | d S NrZ   rT   _rT   rT   rU   rg      rh   ztest_sift.<locals>.<lambda>rY   re   )r   rZ   ry   r   c                 S   s
   |  tS NhasrR   r   rT   rT   rU   rg      rh   )FTc                 S   s
   |  tS r   r   r   rT   rT   rU   rg      rh   Fr   rY   rZ   re   c                 S   s   | d S r   rT   rR   rT   rT   rU   rg      rh   Tbinaryr   rZ   c                 S   s   | d dkS )Nre   rY   rT   r   rT   rT   rU   rg      rh   r   c                   S   s   t g ddd ddS )Nr   c                 S   s   | d S )Nre   rT   r   rT   rT   rU   rg      rh   z-test_sift.<locals>.<lambda>.<locals>.<lambda>Tr   )r5   rT   rT   rT   rU   rg      s    )	r5   rP   r   rR   rQ   rH   ZOnerI   rq   rT   rT   rT   rU   	test_sift   s    ,$ 


r   c                  C   sX   t  } t| dttdks J t| dttdks:J tg ddg dksTJ d S )Nr]   zx0:5zx5:10rY   rZ   re   ry   r]   )r,   r8   rP   r
   )XrT   rT   rU   	test_take   s    r   c                   C   s   t i dtttidtttiks"J t dtttii dtttiksDJ t dtidtttidtdtttiksnJ t dtttidtidtdtttiksJ t ttddtttidtdtttiksJ t dtttittddtdtttiksJ d S )NrY   rZ   rb   )r   rR   rQ   rr   rT   rT   rT   rU   test_dict_merge   s    ""**,r   c                   C   s   t tg g ksJ t tdgdggks.J t tddgdgddggksPJ t tg ddgddgg dg dg dgksJ d S )NrY   rZ   r   rt   rY   rZ   re   ry   )rP   r0   rT   rT   rT   rU   test_prefixes   s    "r   c                   C   s   t tg g ksJ t tdgdggks.J t tddgdgddggksPJ t tg ddgddgg dg dg dgksJ d S )NrY   rZ   r   r]   ry   rx   )rZ   re   ry   r]   )rP   r/   rT   rT   rT   rU   test_postfixes   s    "r   c                      s`   g dg d t  fg dks(J t  fdd dg dksHJ tt fdd d S )	N)rZ   re   r]         	   
   rp   )	)r   rp   r   r   )r]   rp   )re   r   )re   r   )rp   rZ   )rp   r   )rp   r   )r   r   )re   r]   r   r   rp   rZ   r   r   c                 S   s   |  S r   rT   )vrT   rT   rU   rg   	  rh   z'test_topological_sort.<locals>.<lambda>rM   )r   r]   rp   re   r   r   r   rZ   c                      s   t  dg fS )N)r   r   )r9   rT   EVrT   rU   rg     rh   )r9   rI   rq   rT   rT   r   rU   test_topological_sort  s    r   c                  C   s   t g g fg ksJ t g dg fdgdgdggks8J g d} g d}t | |fg dgksbJ g d} g d}t | |fdgddgdggksJ g d} g d	}t | |fddgddggksJ d S )
Nrt   rY   rZ   re   rb   r{   r   r|   r   r   rb   r|   r   re   ry   ry   )rb   r   r   )ry   re   )r6   r   r   rT   rT   rU   "test_strongly_connected_components  s    $"r   c                  C   s   t g g fg ksJ t g dg fdgdgdggks8J g d} g d}t | |fg dgksbJ g d} g d}t | |fg dgksJ g d} dd	g}t | |fddgdd
ggksJ d S )Nrt   rY   rZ   re   r   r   r   rb   r   ry   )r   r   rT   rT   rU   test_connected_components   s    $r   c                  C   s   g d} t | dg dksJ t| dg dks4J g } t| d}|g ksNJ |d | g ksdJ t | d}|g kszJ |d | g ksJ d S )Nr   rY   rZ   re   ry   rZ   )rZ   re   ry   r   rY   rY   )ry   r   rY   rZ   re   )r2   r3   append)ABrT   rT   rU   test_rotate1  s    



r   c               
   C   s  g d} t t| ddgdgdgdgdgggks4J tt t| ddksNJ tt t| dd	kshJ t tg d
dg ddggg dddggg ddggg dddggddgg dggksJ t tg ddg ddggddgddggg ddggddgddgggksJ t tg ddg ddggg ddggddgddggg ddggddgddggddgddggdgg dggksJ t tg ddddgdggdgddgggksJ t tdg dgddgdggddgdggdgddggdgdgdgggksJ t tddddgdggddgdggdgddgggksJJ t tdgd ddgddgggkstJ t tdgd g dgdgddggdgdgdgggksJ g d}t t|t tt|ksJ t t|dg ksJ t t|dg dggksJ t t|dg dg ks2J t t|dg dg dggksXJ t tddg kspJ t tddddgggksJ t tddgggksJ t tddg ksJ t tdddggdgdgggksJ t tddddgggksJ t tdddggks(J t tddgdddgggksLJ g d}dd tdD |kspJ dgd dgd!dgdd"gg d#g d$g d%g}d&d tddgD |ksJ d S )'Nr   r]   r   rY   rZ   re   ry   r      )rY   rY   rY   rZ   rZ   )rY   rY   rY   rZ   r   )rY   rY   rZ   rZ   r   r   r   rt   )rY   rZ   ry   rY   re   ry   rZ   re   ry   r   r   r   abbaaa)$)Zmpsyy)ZmpsyrQ   )mpsyy)r   rQ   rQ   )Zmpyyr   )mpysy)r   r   rQ   )mpsyy)r   r   rQ   )r   r   r   )r   r   rQ   rQ   )Zmsyyp)msypy)r   r   rQ   )mspyy)r   r   rQ   )r   r   r   )r   r   rQ   rQ   )myyps)r   r   r   )mypsy)r   r   rQ   )r   r   r   )r   r   r   )r   r   r   rQ   )mZpsyy)r   r   rQ   )r   r   r   )r   r   rQ   rQ   )r   r   r   )r   r   r   )r   r   r   rQ   )r   r   r   )r   r   r   rQ   )r   r   r   r   )r   r   r   rQ   rQ   c                 S   s   g | ]}t d d |D qS )c                 s   s   | ]}d  |V  qdS rW   Njoin).0partrT   rT   rU   	<genexpr>{  rh   z6test_multiset_partitions.<locals>.<listcomp>.<genexpr>)tupler   r   rT   rT   rU   
<listcomp>{  s   z,test_multiset_partitions.<locals>.<listcomp>Zsympy   r      r\   )ry   rZ   re   )r\   rZ   rZ   )rZ   rZ   rZ   re   c                 S   s   g | ]}t |d dgqS r|   )rF   r   rT   rT   rU   r    s   )rP   r)   r   rS   rG   )r   r   ansZ
factoringsrT   rT   rU   test_multiset_partitionsA  sz    ,&
&&(
,$*"

 & ( $

r  c                  C   s   g d} dd t tddD | ks(J td}dd t t|dD | ksPJ dd t|dD g kslJ t td	gd
dggd
d	gd
dgggksJ tt tdddksJ tt tddd	ksJ t tdd	dgdgdggksJ ttdd  d S )N)ZiiiZiimZiipZiisimpZimsZippipsZissZmppr   ZmssZppsZpssZsssc                 S   s   g | ]}d  |qS rW   r   r   irT   rT   rU   r    rh   z.test_multiset_combinations.<locals>.<listcomp>Zmississippire   c                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r    rh   c                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r    rh      rY   rZ   r   r   abcr   cc                   S   s   t tddddS )Nre   r[   r   rZ   )rP   r(   rT   rT   rT   rU   rg     rh   z,test_multiset_combinations.<locals>.<lambda>)rP   r(   r'   r   rI   rq   )r  MrT   rT   rU   test_multiset_combinations  s$    ,"r  c                     sz  g d} dd t dD | ks"J dd t tdD | ks@J tt g ddddggks`J tt g d	ddd
gddgd
dgd
dgddgdd
ggksJ ttt ddd
ksJ ttt dddksJ g i dfD ]}tt |g gksJ qtt |dg gksJ tt |d
g ks*J tt |dg ksBJ dd  t fddtdkshJ ttdd  d S )N)ZabbyZabybZaybbbabyZbaybZbbayZbbyaZbyabZbybaZyabbZybabZybbac                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r    rh   z.test_multiset_permutations.<locals>.<listcomp>r  c                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r    rh   r   rZ   r   r   rY   r   re   rW   r[   c                  S   s8   t ddD ](} t|  tg d| D ]}t| q$q
d S )NrY   r   )r   r   rY   r   rY   )r   printr*   )r
  r   rT   rT   rU   test  s    z(test_multiset_permutations.<locals>.testc                      s     S r   rT   rT   r  rT   rU   rg     rh   z,test_multiset_permutations.<locals>.<lambda>a          1
        [0]
        [1]
        2
        [0, 0]
        [0, 1]
        [1, 0]
        [1, 1]
        3
        [0, 0, 0]
        [0, 0, 1]
        [0, 1, 0]
        [0, 1, 1]
        [1, 0, 0]
        [1, 0, 1]
        [1, 1, 0]
        4
        [0, 0, 0, 1]
        [0, 0, 1, 0]
        [0, 0, 1, 1]
        [0, 1, 0, 0]
        [0, 1, 0, 1]
        [0, 1, 1, 0]
        [1, 0, 0, 0]
        [1, 0, 0, 1]
        [1, 0, 1, 0]
        [1, 1, 0, 0]
        5
        [0, 0, 0, 1, 1]
        [0, 0, 1, 0, 1]
        [0, 0, 1, 1, 0]
        [0, 1, 0, 0, 1]
        [0, 1, 0, 1, 0]
        [0, 1, 1, 0, 0]
        [1, 0, 0, 0, 1]
        [1, 0, 0, 1, 0]
        [1, 0, 1, 0, 0]
        [1, 1, 0, 0, 0]
        6
c                   S   s   t tdddS )Nre   r[   r   )rP   r*   rT   rT   rT   rU   rg     rh   )r*   r'   rP   r   r   r   rI   rq   )r  nulrT   r  rU   test_multiset_permutations  s"     $
(r  c               	   C   s  i gdi fgg} t dD ]}ttd|d| | ks8J ttdd|d| | ksVJ ttddd|d| | ksvJ ttddd |d| | ksJ ttdd d|d| | ksJ ttddd|d| | ksJ qttdddddidddd	ddddigksJ ttdddddidddd
dddddidddd	ddddigks\J ttdd	ddd	diddddddddddg  krdd tdd	ddD ksn J tttdddddidddgksJ ttd	dddddddiddddd	ig  kr6dd td	D ks<n J t ddD ]L}d}t|D ]&\}}|t||ksrJ |d7 }qV|t|ksFJ qFd S )Nr   rZ   )sizerY   r\   )kre   rb   ry   rt   r{   r   )r  r   r   r}   r|   c                 S   s2   g | ]*}t d d |D rt| dkr|qS )c                 s   s   | ]}|d kV  qdS )ry   NrT   r   r  rT   rT   rU   r     rh   -test_partitions.<locals>.<listcomp>.<genexpr>re   )allsumvaluesr	  rT   rT   rU   r    s   z#test_partitions.<locals>.<listcomp>)r   c                 S   s"   g | ]}t d d |D r|qS )c                 s   s   | ]}|d kV  qdS )re   NrT   r  rT   rT   rU   r     rh   r  )r  r	  rT   rT   rU   r    s   )r   rP   r-   rH   r   r   r   )r  r
  nr   qrT   rT   rU   test_partitions  sL       "& 
r  c                   C   s   dd t dD ddgg dg dg dg d	g d
g dg dg dg dg dg dg dg dgksnJ tdd t dD dksJ d S )Nc                 S   s   g | ]}|d d  qS r   rT   r	  rT   rT   rU   r     rh   z*test_binary_partitions.<locals>.<listcomp>r   r   rZ   )r   rY   rY   )ry   ry   rZ   )ry   ry   rY   rY   )ry   rZ   rZ   rZ   )ry   rZ   rZ   rY   rY   )ry   rZ   rY   rY   rY   rY   )ry   rY   rY   rY   rY   rY   rY   )rZ   rZ   rZ   rZ   rZ   )rZ   rZ   rZ   rZ   rY   rY   )rZ   rZ   rZ   rY   rY   rY   rY   )rZ   rZ   rY   rY   rY   rY   rY   rY   )	rZ   rY   rY   rY   rY   rY   rY   rY   rY   )
rY   rY   rY   rY   rY   rY   rY   rY   rY   rY   c                 S   s   g | ]}|d d  qS r   rT   r   jrT   rT   rU   r    rh      $   )r   r   rT   rT   rT   rU   test_binary_partitions  s    
r$  c                  C   s   dd t ddD dd t ddD ks,J ttdg dksDJ t ddD ]<} tt | }t| }|D ]}|t|jksJ | }qjqNttd	d
  d S )Nc                 S   s   g | ]}t tt|qS rT   )r   r   r   r	  rT   rT   rU   r  
  rh   z"test_bell_perm.<locals>.<listcomp>rY   r   c                 S   s   g | ]}t |qS rT   r   r	  rT   rT   rU   r  
  s   re   )r   r   r   r   r   r   r]   c                   S   s   t tdS )Nr   )rP   r   rT   rT   rT   rU   rg     rh   z test_bell_perm.<locals>.<lambda>)	r   rP   r   r   r   Z
array_formZnext_trotterjohnsonrI   rq   )r  r   r   ZbirT   rT   rU   test_bell_perm	  s    r%  c                  C   sX   g d} t | D ]B\}}tt|d }t||ks8J tdd |D dksJ qd S )N)rY   rZ   ry   r      L   rY   c                 S   s   h | ]}t |d  qS rv   )r   r   rT   rT   rU   	<setcomp>  rh   z#test_involutions.<locals>.<setcomp>)	enumeraterP   r   r   )lengthsr  Nr
  rT   rT   rU   test_involutions  s
    r,  c                  C   s  t ttttddks J ddd tdD dks@J ttg dg d	g d
g dg dg dg dg dg dg dg	ksJ ttg dg dg dgksJ ttdtdgksJ t} t| dg ksJ dd | dD dgksJ dd | dD ddgks"J dd | dD d gks@J d!d | d"D g d#ks`J d$d | d%D g d&ksJ d'd | d(D g d)ksJ ttd*gd+gd+gd,ggd+gd,gd*gd+ggd+gd*gd,gd+gggksJ d S )-Nr\   i	  rW   c                 s   s   | ]}d  |V  qdS r   r   r	  rT   rT   rU   r   $  rh   z$test_derangements.<locals>.<genexpr>abcdeZbadecbaecdbcaedbcdeabceadbdaecbdeacbdecabeacdbedacbedcacabedcadebcaebdcdaebcdbeacdeabcdebaceabdcebadcedabcedbadabecdaebcdaecbdcaebdcbeadceabdcebadeabcdeacbdebacdebcaeabcdeadbceadcbecabdecbadecdabecdbaedabcedacbedbacedbcar   )rY   r   re   rZ   )rY   rZ   re   r   )rY   re   r   rZ   )rZ   r   re   rY   )rZ   re   r   rY   )rZ   re   rY   r   )re   r   rY   rZ   )re   rZ   r   rY   )re   rZ   rY   r   )r   rY   rZ   rZ   )rZ   rZ   r   rY   )rZ   rZ   rY   r   bar   Zabbc                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  2  rh   z%test_derangements.<locals>.<listcomp>c                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  3  rh   r  ZbcaZcabc                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  4  rh   ZaabbZbbaac                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  5  rh   Zaabbcccc)ZccccaabbZccccababZccccabbaZccccbaabZccccbabaZccccbbaac                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  8  rh   Zaabbccc)ZcccabbaZcccababZcccaabbZccacbbaZccacbabZccacabbZcbccbaaZcbccabaZcbccaabZbcccbaaZbcccabaZbcccaabc                 S   s   g | ]}d  |qS r  r   r	  rT   rT   rU   r  <  rh   books)ZkbsooZksbooZsbkooZskbooZoksboZoskboZokbsoZobksoZoskobZoksobZosbokZobsokre   rZ   rY   )r   rP   r   r   r   rB   )DrT   rT   rU   test_derangements"  s.     

    $r1  c               
   C   s   dd } g }t ddD ].}||| |dd| |dd| |ddf qt|tg dg d	g d
g dg dg dg dgksJ d S )Nc                 S   s   t tt| ||S r   )r   rP   r+   )r  r  frT   rT   rU   countD  s    ztest_necklaces.<locals>.countrY   r   rZ   r   re   )rY   rZ   rZ   re   )rZ   re   re   r\   )re   ry   ry   r   )ry   r\   r\      )r]   r   r   '   )r\         \   )r            )r   r   r   )r3  r   r
  rT   rT   rU   test_necklacesC  s     r<  c                  C   s   t tdd} t| tddgddgddgddgddgddgddgddgddgddgg
ks^J t tdd} t| tg dg dg dg d	g d
g dgksJ d S )NrZ   ry   r   rY   re   )r   r   r   r   )r   r   r   rY   )r   r   rY   rY   )r   rY   r   rY   )r   rY   rY   rY   )rY   rY   rY   rY   )rP   r   r   )bcrT   rT   rU   test_braceletsT  s,    r>  c                   C   s   t tdg dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg dg dgksJ tt tddksJ d S )Nr]   r   )r   rY   rZ   re   re   )r   rY   rZ   re   rZ   )r   rY   rZ   re   rY   )r   rY   rZ   re   r   )r   rY   rZ   rZ   rZ   )r   rY   rZ   rZ   rY   )r   rY   rZ   rZ   r   )r   rY   rZ   rY   rZ   )r   rY   rZ   rY   rY   )r   rY   rZ   rY   r   )r   rY   rZ   r   rY   )r   rY   rZ   r   r   )r   rY   rY   rY   rY   )r   rY   rY   rY   r   )r   rY   rY   r   rY   )r   rY   rY   r   r   )r   rY   r   rY   r   )r   rY   r   r   r   )r   r   r   r   r   r   i2  )rP   r    r   rT   rT   rT   rU   test_generate_oriented_forestm  s    
r?  c                  C   s   t td} t| t t| d d d | dd d ks:J t| dt| d d t| dd  gkshJ ttdd  ttdd  d S )Nr   rZ   rY   r]   c                   S   s   t ttddS )Nr   re   r:   rP   r   rT   rT   rT   rU   rg   {  rh   z test_unflatten.<locals>.<lambda>c                   S   s   t ttddS )Nr   ra   r@  rT   rT   rT   rU   rg   |  rh   )rP   r   r:   zipr   rI   rq   )rrT   rT   rU   test_unflattenw  s
    ..rC  c                   C   sL  t g dgg ksJ t ttdg dks0J t ttdttdg dksVJ t g dg dddgkstJ t g dg ddgksJ tg dgg ksJ tttdg dksJ tttdttdg dksJ tttdttdg ks
J tg dg d	ddgks*J tg dg d
dgksHJ d S )NrY   re   r   ry   rt   )rY   rZ   r]   rZ   )rY   re   r]   )r   rZ   re   )r   r   re   )r   rP   r   r   rT   rT   rT   rU   test_common_prefix_suffix  s    &&$ rD  c                   C   sp   t g ddksJ t ddks$J t ddks4J t ddddksHJ t ddksXJ t d	td
dkslJ d S )Nr   r   r   r   F)ZdirectedZabaZaab)bbr   r  r   rM   )r  r   rE  r   )r&   r   rT   rT   rT   rU   test_minlex  s    rF  c                      s   t tttftddttgttgfv s*J t tttftddt tttftddksZJ t tttfttgksvJ g dg dg ddgdggdd	 d
d	 fg\ t t ddddgdgg dg dg dgksJ tt fdd	 d S )NF)defaultr   r   r   rZ   rY   c                 S   s   t | S r   )r   r   rT   rT   rU   rg     rh   ztest_ordered.<locals>.<lambda>c                 S   s   t | S r   )r  r   rT   rT   rU   rg     rh   rG  warnc                      s   t t dddS )NFTrH  )rP   r   rT   keysseqrT   rU   rg     s    )rP   r   rR   rQ   hashrI   rq   rT   rT   rJ  rU   test_ordered  s    *rN  c                  C   s   t g g ksJ t dgdggks&J t ddgdgdggksBJ t g ddgddggks`J t g dddgdggks~J t g ddgdgdggksJ ddlm}  t g d| ddgdggksJ d S )NrY   r   rZ   r   )rZ   rY   rY   r   lt)r4   operatorrP  rO  rT   rT   rU   	test_runs  s     rR  c                  C   s  t tdd} t| dgg dg dgks.J t| dddgksDJ t| dddgksZJ t| ddgfddd	dgfd
dddgfgksJ t| ddgfdd	dgfdddgfgksJ t| ddgdfddd	gdfd
ddgdfgksJ tt| dgddgfdgddgfd
gddgffks"J tt| dgddfdgddfd
gddffksVJ tt tddd	gdhdgddg dd
dhdggksJ ttdd  ttdd  d S )NrY   r   ry   r   )r]   r\   r   r   )ry   r   rZ   re   r]   r\   r   r   rv   rb   )r]   r\   r   r   r  )rY   rw   rY   r   r   )r   )r   r   r   rp   c                   S   s   t ddgdgS )Nr   rY   r[   r1   rT   rT   rT   rU   rg     rh   ztest_reshape.<locals>.<lambda>c                   S   s   t ddgdgS )Nr   rY   re   rS  rT   rT   rT   rU   rg     rh   )rP   r   r1   r   rI   rq   )rL  rT   rT   rU   test_reshape  s<    



rT  c                      s  t tdd tdD ddidddddidddddigksDJ t tdd td	D d
dgksjJ t tddgksJ t tdt dksJ t tdgddgdggdgddggksJ t ttdd dgddfD dgddfddgdfdddgfgksJ t tdddddgdgdgdgdgg	ddddgdgdggksRJ dg tt fdd dgg tt fdd d S )Nc                 s   s   | ]
}|V  qd S r   rT   r   rT   rT   rU   r     rh   ztest_uniq.<locals>.<genexpr>ry   rY   r{   rZ   rb   c                 s   s   | ]}|d  V  qdS )rZ   NrT   )r   rR   rT   rT   rU   r     rh   r]   r   r   Zababcr  c                 s   s   | ]
}|V  qd S r   rT   r	  rT   rT   rU   r     rh   re   c                      s    fddt  D S )Nc                    s   g | ]}  |qS rT   remover	  r2  rT   rU   r    rh   /test_uniq.<locals>.<lambda>.<locals>.<listcomp>r;   rT   rW  rT   rU   rg     rh   ztest_uniq.<locals>.<lambda>c                      s    fddt  D S )Nc                    s   g | ]}  |qS rT   rU  r	  rW  rT   rU   r    rh   rX  rY  rT   rW  rT   rU   rg     rh   )rP   r;   r-   r   r.   rI   RuntimeErrorrT   rT   rW  rU   	test_uniq  s"    $&,  
&
r[  c                      s   t ttdddddksJ t ttdddddks<J t ttdddddksZJ t ttddd	dd
ksxJ t ttddd ddksJ dd  t fddtdksJ dd tfddtdksJ d S )NZ1123rZ   rY   r   r  rp   r#  r   r   r]   re   c                  S   s:   dD ]0} t d|  tg dd| dD ]}t d| q$qd S )NNr   rY   r   rp   	ordered =r   rZ   r      )r  r%   Z
orderedvalr   rT   rT   rU   test1  s    
ztest_kbins.<locals>.test1c                      s     S r   rT   rT   )r`  rT   rU   rg     rh   ztest_kbins.<locals>.<lambda>a#          ordered = None
            [[0], [0, 1]]
            [[0, 0], [1]]
        ordered = 0
            [[0, 0], [1]]
            [[0, 1], [0]]
        ordered = 1
            [[0], [0, 1]]
            [[0], [1, 0]]
            [[1], [0, 0]]
        ordered = 10
            [[0, 0], [1]]
            [[1], [0, 0]]
            [[0, 1], [0]]
            [[0], [0, 1]]
        ordered = 11
            [[0], [0, 1]]
            [[0, 0], [1]]
            [[0], [1, 0]]
            [[0, 1], [0]]
            [[1], [0, 0]]
            [[1, 0], [0]]
c                  S   s>   dD ]4} t d|  tttdd| dD ]}t d| q(qd S )Nr\  r]  re   rZ   r   r^  )r  r%   rP   r   r_  rT   rT   rU   test2  s    
ztest_kbins.<locals>.test2c                      s     S r   rT   rT   )ra  rT   rU   rg     rh   a[          ordered = None
            [[0], [1, 2]]
            [[0, 1], [2]]
        ordered = 0
            [[0, 1], [2]]
            [[0, 2], [1]]
            [[0], [1, 2]]
        ordered = 1
            [[0], [1, 2]]
            [[0], [2, 1]]
            [[1], [0, 2]]
            [[1], [2, 0]]
            [[2], [0, 1]]
            [[2], [1, 0]]
        ordered = 10
            [[0, 1], [2]]
            [[2], [0, 1]]
            [[0, 2], [1]]
            [[1], [0, 2]]
            [[0], [1, 2]]
            [[1, 2], [0]]
        ordered = 11
            [[0], [1, 2]]
            [[0, 1], [2]]
            [[0], [2, 1]]
            [[0, 2], [1]]
            [[1], [0, 2]]
            [[1, 0], [2]]
            [[1], [2, 0]]
            [[1, 2], [0]]
            [[2], [0, 1]]
            [[2, 0], [1]]
            [[2], [1, 0]]
            [[2, 1], [0]]
)r   rP   r%   r   r   rT   rT   )r`  ra  rU   
test_kbins  s    rb  c                   C   sr   t t du sJ t ttddu s*J t g ddu s>J t dgdggdu sVJ t dgdggdu snJ d S )NFre   r   TrY   rZ   )r"   r   rP   r   rT   rT   rT   rU   test_has_dups'  s
    rc  c                  C   s   t dg dddgddgdggks&J t dg ddddgddgdggksNJ dg df} t dg| R  ddgddgdggksJ d S )	Nr-  )rY   r   rY   rZ   r   r   er   r  dre   )r   )outputrT   rT   rU   test__partition/  s    

rg  c               	   C   s   ddl m}  t}t|ddg gks(J t|ddg gks@J tddD ]j}d gttd| D ]P}tdd |||dD tdd |||dD   kr| ||ksbn J qbqJd S )Nr   )nTrY   r   c                 s   s   | ]
}d V  qdS rY   NrT   r   rT   rT   rU   r   @  rh   z*test_ordered_partitions.<locals>.<genexpr>c                 s   s   | ]
}d V  qdS ri  rT   r   rT   rT   rU   r   A  rh   )Z%sympy.functions.combinatorial.numbersrh  r=   rP   r   r  )rh  r2  r
  r!  rT   rT   rU   test_ordered_partitions8  s    rj  c                   C   s|   t tdddgddggks J t ttdg dg dg dgksJJ t ttddd	g dg dg dgksxJ d S )
Nr   r   r   re   r   r   r   r[   )dir)rP   r>   r   rT   rT   rT   rU   test_rotationsE  s     *rl  c                   C   s   t dddgksJ t ddg dks*J t ddddks>J t dddddksTJ tt dd	g d
ksnJ tt ddddg dksJ ttdd  ttdd  d S )Nre   rY   r   T)str11Z011rZ   r  )rc   r   r   r   rW   )Z00Z0110rn  c                   S   s   t dS )Ng      ࿩r#   rT   rT   rT   rU   rg   R  rh   ztest_ibin.<locals>.<lambda>c                   S   s
   t ddS )NrZ   rY   rp  rT   rT   rT   rU   rg   S  rh   )r#   rP   rI   rq   rT   rT   rT   rU   	test_ibinK  s    rq  c                  C   s   t ddu sJ t ddu s J t d du s0J G dd dt} t |  du sRJ G dd dt}t | du stJ G d	d
 d
}t | du sJ G dd d}t | du sJ G dd d}t | du sJ G dd d|}t | du sJ d S )Nr   FrY   c                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test1Nri   rT   rT   rT   rU   Test1[  s   rr  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test2TNrj   rk   rl   	_iterablerT   rT   rT   rU   Test2`  s   ru  Tc                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test3Nri   rT   rT   rT   rU   Test3e  s   rv  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test4TNrs  rT   rT   rT   rU   Test4j  s   rw  c                   @   s   e Zd Zdd ZdS )ztest_iterable.<locals>.Test5c                 s   s
   dV  d S )NrY   rT   )selfrT   rT   rU   __iter__p  s    z%test_iterable.<locals>.Test5.__iter__N)rj   rk   rl   ry  rT   rT   rT   rU   Test5o  s   rz  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test6FNrs  rT   rT   rT   rU   Test6u  s   r{  )r@   rA   )rr  ru  rv  rw  rz  r{  rT   rT   rU   test_iterableV  s    r|  c                   C   sJ  t tdgddgggksJ t tddgdddgggks@J t tddgddgdgggksdJ t tg ddg dggksJ t tg dddgddggddgdgggksJ t tg dddgdgdgggksJ t tg dg ksJ t tg dg ksJ t tddgdg ks*J t tddgdg ksFJ d S )NrY   rZ   rt   re   r   )rP   rD   rT   rT   rT   rU   test_sequence_partitions{  s    "$"(r}  c                   C   s  t tg dg ggksJ t tg dg g ggks6J t tg dg g g ggksTJ t tdgddgggksrJ t tdgdg dggdgg ggksJ t tdgdg g dggg dgg gdgg g ggksJ t tddgdddgggksJ t tddgdg ddggdgdggddgg ggks,J t tddgdg g ddggg dgdggg ddgg gdgg dggdgdgg gddgg g ggksJ t tg ddg dggksJ t tg ddg g dgdgddggddgdggg dg ggksJ t tg ddg g g dgg dgddggg ddgdggg g dg gdgg ddggdgdgdggdgddgg gddgg dggddgdgg gg dg g gg
ksJ t tg dg ksJ t tdgdg ksJ t tddgdg ksJ d S )NrY   rZ   re   rt   r   )rP   rE   rD   rT   rT   rT   rU   test_sequence_partitions_empty  s<    ( " 
$$$.
	r~  c                  C   sH   g d} t td| ksJ t td| ks0J t td| ksDJ d S )N)r   )r   r[   rY   )r   rY   r[   )r   r[   r[   r   )r[   r   rY   )rY   r   r[   )r[   r   r[   r   )r[   rY   r   )rY   r[   r   )r[   r[   r   r   r   r   )rP   rC   )r  rT   rT   rU   test_signed_permutations  s    r  N)textwrapr   	itertoolsr   r   Zsympy.core.basicr   Zsympy.core.numbersr   Zsympy.core.sortingr   Zsympy.core.symbolr	   r
   Z(sympy.functions.combinatorial.factorialsr   Zsympy.matrices.denser   Zsympy.combinatoricsr   r   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   Zsympy.utilities.enumerativerF   rG   Zsympy.core.singletonrH   Zsympy.testing.pytestrI   rJ   wrR   rQ   rr   rV   r^   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r$  r%  r,  r1  r<  r>  r?  rC  rD  rF  rN  rR  rT  r[  rb  rc  rg  rj  rl  rq  r|  r}  r~  r  rT   rT   rT   rU   <module>   sx   (				BA+
!
	N	% 