U
    L?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   sp   ddl m} m} t " t|ttgttgks4tW 5 Q R X t " tttg| dttgksbtW 5 Q R X d S )Nr   default_sort_keyr   key)	sympy.utilities.iterablesrL   r   rJ   listyxAssertionErrorsortedrK    rU   V/var/www/html/venv/lib/python3.8/site-packages/sympy/utilities/tests/test_iterables.pytest_deprecated_iterables!   s
    &rW   c                   C   s   t dstt dstt ds$tt ds0tt dr<tt drHtt ddsVtt dd	rdtt dd	d
sttt dd	dstt ddstt dd	rtt dd	dstd S )N rR   ZxxZxyxZxyZxyzxZxxyzzyx         Zxxyzyx   )r?   rS   rU   rU   rU   rV   test_is_palindromic)   s    r^   c                     s<  t dddgkstt ttffttgks.tddgdgg t  dd ksPtt  dddddgksjtt  ddd	d
ddddgkstt  ddd	d
ddddgksttt fdd G dd dt} t | tttg| tttgkstt | tttg| dtttgkstt dddhtdddhks8td S )N)rY   rY   rY   )r[   rY   rZ   r   r   r   ZlevelsrZ   r`   r[      c                      s   t  ddS )Nr[   rc   )r   rU   ZlsrU   rV   <lambda>D       ztest_flatten.<locals>.<lambda>c                   @   s   e Zd ZdS )ztest_flatten.<locals>.MyOpN__name__
__module____qualname__rU   rU   rU   rV   MyOpF   s   rl   cls   )	r   rS   rR   rI   
ValueErrorr   rQ   zrP   )rl   rU   re   rV   test_flatten9   s      $&rr   c               	   C   s  t t dgkstt tg g ks(tt tdddgdddgksHtttddgddd	gd
dddddgksttttddgddgddgddddddddgksttttjdksttttjtjdkstdttjkstdttjtjkstdttjtjtjkstttttjtjtjd} | D ]<\}}}t	|t
sXtt	|t
shtt	|t
s>tq>tttddgd  D ]"}|ttjtjtjkstqd S )NrU   rY   rZ   rd   r_   rZ   rd      r]   rY   rd   rY   ru   rY   r]   rZ   rd   rZ   ru   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   T)ru   r]   rY   rZ   rd   i  r`   )rP   r$   rS   rT   r@   rH   ZIntegerssetr   
isinstancer   r   range)ZtriplesZn1Zn2Zn3trU   rU   rV   test_iproductO   sB          
       
r   c                	   C   sp  t g g kstt g ddg ks$tt dgdggks:tt dgdddgksRtt ddgddggksltt ddgdddgkstt dddgdddggkstt dddgdddgkstt dddgdgdgdggkstt dddgdddddgkstt ddddddd	d	gddgdddgdgd	d	ggks>tt ddddddd	d	gdddd
ddgksltd S )NF)ZmultiplerY   rY   rY   ra   rv   rZ   rZ   rY   rd   ry   rd   rZ   )r!   rS   rU   rU   rU   rV   
test_groupe   s     "":  r   c                  C   sR  t tdddgddgkstt tdddgddddgks@tt tdddgdd	d
dgksbtt tdddgddgkstt td} t t| ddddgkstt t| dddddddgkstt t| ddddddddd	d
dddg
kstt t| dddddddddddd d!d"d#d$d%dd&d'd(d)d*gks<ttt t| dddd+ks\tt t| d d dd,dg kstt t| d d ddddddd"gkstt tddgddddddd	dgkstt tddgd,ddddd	gkstt tdddgdd	d
dgks tt tdddgddddd	d
dddgksNtd S )-NrY   rZ   rd   r   rU   r_   rs   rt   ra   rv   ry   r   ru   TZ
repetitionr   rb   r   rY   r   rZ   r   rd   r   rZ   rZ   rd   rd   r|   r}   )r   r   rZ   )r   r   rd   r   r   rY   rZ   r   rY   rd   )r   rZ   rZ   r   rZ   rd   )r   rd   rd   r   )rY   rY   rZ   )rY   rY   rd   )rY   rZ   rZ   )rY   rd   rd   )rZ   rZ   rZ   )rZ   rZ   rd   )rZ   rd   rd   )rd   rd   rd   #   F)rP   r7   rS   r   lenlrU   rU   rV   test_subsetsz   sn    """    
         
 $



r   c                  C   s  t td} t t| ddddgks(tt t| dddddd	d
gksJtt t| dddddddddddddddgks|tt t| ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0gkstt t| dd1ddgkstt t| dd1dddd	d
gkstt t| dd1dd2ddddd3ddddd4ddddd5gksBttt t| dd1dd6ksbttt t| dd1dd7kstt t| d d dddg kstt t| d d dd1dd8d9d:d;d<d=d>d?gkstd S )@Nru   r   Fr   rU   rY   r   r_   rs   rt   rZ   r   r   r   rY   r   ra   rv   )rZ   r   r   ry   )rd   r   rd   rY   r   rd   r   r   r   rZ   rY   r   )r   rd   rY   )r   rd   rZ   rY   r   rZ   )rY   r   rd   rY   rZ   r   r   )rY   rd   r   )rY   rd   rZ   rZ   r   rY   )rZ   r   rd   rZ   rY   r   )rZ   rY   rd   )rZ   rd   r   )rZ   rd   rY   )rd   r   rY   )rd   r   rZ   )rd   rY   r   )rd   rY   rZ   )rd   rZ   r   )rd   rZ   rY   Trb   r   r   r   @      r|   r}   r~   r   r   r   r   r   )rP   r   r<   rS   r   r   rU   rU   rV   test_variations   sF    "2J$          $      r   c                   C   s   t tddgdddgdddd	d
dgks,tt t dgks@tt tddgksVtt tddddgksptt tt tdddgkstd S )NrY   rZ   rd   ru   r]   rv   rw   rx   ry   rz   r{   rU   a)r   )repeat)r   r   r   r_   )rP   r   rS   r   rU   rU   rU   rV   test_cartes   s    r   c                  C   s2   t  } t| td}t|dttdks.td S )Nzx0 x2 x3rd   zx1 x4 x5)r,   r   r
   r8   rP   rS   )sfilteredrU   rU   rV   test_filter_symbols   s    r   c                  C   sD   t td} tt| tsttt ddtdgdtdks@td S )Nrm   CrY   ZC1)startexcludeZC2)r,   r	   r   nextrS   r
   )r   rU   rU   rV   test_numbered_symbols   s
    
r   c                   C   s   t ttddd ddgdddgd	ks.tt ttgd
d tgtgdksRtt tjgdd ddgiksrtt ddddgdd ddddgddgfkstt ddddgdd dddgdddgfksttt	dd  d S )Nr]   c                 S   s   | d S NrZ   rU   _rU   rU   rV   rf      rg   ztest_sift.<locals>.<lambda>rY   rd   r   rZ   ru   r   c                 S   s
   |  tS NhasrR   r   rU   rU   rV   rf      rg   )FTc                 S   s
   |  tS r   r   r   rU   rU   rV   rf      rg   Fc                 S   s   | d S r   rU   rR   rU   rU   rV   rf      rg   Tbinaryc                 S   s   | d dkS )Nrd   rY   rU   r   rU   rU   rV   rf      rg   c                   S   s   t ddddgdd ddS )	Nr   rY   rZ   rd   c                 S   s   | d S )Nrd   rU   r   rU   rU   rV   rf      rg   z-test_sift.<locals>.<lambda>.<locals>.<lambda>Tr   )r5   rU   rU   rU   rV   rf      s    )
r5   rP   r   rS   rR   rQ   rH   ZOnerI   rp   rU   rU   rU   rV   	test_sift   s    .$  
 
r   c                  C   sd   t  } t| dttdks tt| dttdks:ttdddddgddddddgks`td S )Nr]   zx0:5zx5:10rY   rZ   rd   ru   )r,   r8   rP   r
   rS   )XrU   rU   rV   	test_take   s    r   c                   C   s   t i dtttidtttiks"tt dtttii dtttiksDtt dtidtttidtdtttiksntt dtttidtidtdtttikstt ttddtttidtdtttikstt dtttittddtdtttikstd S )NrY   rZ   ra   )r   rR   rQ   rq   rS   rU   rU   rU   rV   test_dict_merge   s    ""**,r   c                
   C   s   t tg g kstt tdgdggks.tt tddgdgddggksPtt tdddddgdgddgdddgddddgdddddggkstd S NrY   rZ   rd   ru   r]   )rP   r0   rS   rU   rU   rU   rV   test_prefixes   s    "*r   c                
   C   s   t tg g kstt tdgdggks.tt tddgdgddggksPtt tdddddgdgddgdddgddddgdddddggkstd S r   )rP   r/   rS   rU   rU   rU   rV   test_postfixes   s    "*r   c                	      s   ddddddddgd	d
dddddddg	 t  fddddddddgksNtt  fdd dddddddddgkszttt fdd d S )NrZ   rd   r]         	   
   ro   )r   ro   r   r   )r]   ro   )rd   r   )rd   r   )ro   rZ   )ro   r   )ro   r   )r   r   c                 S   s   |  S r   rU   )vrU   rU   rV   rf   	  rg   z'test_topological_sort.<locals>.<lambda>rM   c                      s   t  dg fS )N)r   r   )r9   rU   EVrU   rV   rf     rg   )r9   rS   rI   rp   rU   rU   r   rV   test_topological_sort  s        $r   c                  C   s   t g g fg kstt dddgg fdgdgdggks:tdddg} dddddg}t | |fdddggksntdddd	g} ddd
dg}t | |fd	gddgdggkstdddd	g} ddddg}t | |fddgdd	ggkstd S )NrY   rZ   rd   ra   rv   r   ry   r   ru   r   rd   ru   )ru   rd   )r6   rS   r   r   rU   rU   rV   "test_strongly_connected_components  s    &
"r   c                  C   s   t g g fg kstt dddgg fdgdgdggks:tdddg} dddddg}t | |fdddggksntdddd	g} ddd
dg}t | |fdddd	ggkstdddd	g} ddg}t | |fddgdd	ggkstd S )NrY   rZ   rd   ra   rv   r   ry   r   ru   r   r   )r   rS   r   rU   rU   rV   test_connected_components   s    &
r   c                  C   s   dddddg} t | ddddddgks*tt| ddddddgksFtg } t| d}|g ks`t|d | g ksvtt | d}|g kst|d | g kstd S )Nr   rY   rZ   rd   ru   )r2   rS   r3   append)ABrU   rU   rV   test_rotate1  s    



r   c               $   C   sH  dddddg} t t| ddgdgdgdgdgggks:ttt t| ddksTttt t| ddksntt tdddddgdddddgdggdddgddggddddgdggdddgddggddgdddgggkstt tddddgddddgdggddgddggdddgdggddgddgggks6tt tddddgddddgdggdddgdggddgddggdddgdggddgddggddgddggdgdddgggkstt tdddgdddgdggdgddgggkstt tddddg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@tt tddddgdggddgdggdgddgggks|tt tdgd ddgddgggkstt tdgd dddggdgddggdgdgdgggkstdddg}t t|t tt|kstt t|dg ks*tt t|ddddgggksLtt t|dg dg ksjtt t|dg dddddgggkstt tddg kstt tddddgggkstt td	d	gggkstt td	dg ks tt td
d	dggd	gdgggks(tt td
dd	dgggksHtt tdddggksdtt tddgdddgggkstdddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0g$}d1d2 td3D |kstd4gd5dgd6dgdd7gdddgd7ddgddddgg}d8d2 tddgD |ksDtd S )9Nr   rY   rZ   rd   ru   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 rX   Njoin).0partrU   rU   rV   	<genexpr>{  s     z6test_multiset_partitions.<locals>.<listcomp>.<genexpr>)tupler   r   rU   rU   rV   
<listcomp>{  s   z,test_multiset_partitions.<locals>.<listcomp>Zsympy   r      r\   c                 S   s   g | ]}t |d dgqS ry   )rF   r   rU   rU   rV   r     s   )rP   r)   rS   r   rT   rG   )r   r   ansZ
factoringsrU   rU   rV   test_multiset_partitionsA  s    ,   
       

     *
  


"* ( $                     
 

r   c                  C   s  ddddddddd	d
dddddg} dd t tddD | ksBttd}dd t t|dD | ksjtdd t|dD g kstt tdgddggddgddgggksttt tdddksttt tdddkstt tdddgdgdggks
tttdd  d S ) NZiiiZiimZiipZiisimpZimsZippipsZissZmppr   ZmssZppsZpssZsssc                 S   s   g | ]}d  |qS rX   r   r   irU   rU   rV   r     s     z.test_multiset_combinations.<locals>.<listcomp>Zmississippird   c                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r     s     c                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r     s        rY   rZ   r   r   abcr   cc                   S   s   t tddddS )Nrd   r[   r   rZ   )rP   r(   rU   rU   rU   rV   rf     rg   z,test_multiset_combinations.<locals>.<lambda>)rP   r(   rS   r'   r   rI   rp   )r   MrU   rU   rV   test_multiset_combinations  s4          ,$r   c                     s  ddddddddd	d
ddg} dd t dD | ks6tdd t tdD | ksTttt dddgdddggksvttt dddgdddgddgddgddgddgddggkstttt dddkstttt dddkstg i dfD ]}tt |g gkstqtt |dg gks*ttt |dg ksBttt |dg ksZtdd  t fddtdkstttdd  d S )NZabbyZabybZaybbbabyZbaybZbbayZbbyaZbyabZbybaZyabbZybabZybbac                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r     s     z.test_multiset_permutations.<locals>.<listcomp>c                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r     s     r   rZ   rY   r   rd   rX   r[   c                  S   s>   t ddD ].} t|  tdddddg| D ]}t| q*q
d S )NrY   r   r   )r   printr*   )r   r   rU   rU   rV   test  s    z(test_multiset_permutations.<locals>.testc                      s     S r   rU   rU   r  rU   rV   rf     rg   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 )Nrd   r[   r   )rP   r*   rU   rU   rU   rV   rf     rg   )	r*   rS   r'   rP   r   r   r   rI   rp   )r   nulrU   r  rV   test_multiset_permutations  s6       "     
(r  c               	   C   s  i gdi fgg} t dD ]}ttd|d| | ks8tttdd|d| | ksVtttddd|d| | ksvtttddd |d| | kstttdd d|d| | kstttddd|d| | kstqttdddddidddd	ddddigkst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\t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 ttttdddddidddgkst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 tt ddD ]L}d}t|D ]&\}}|t||ksrt|d7 }qV|t|ksFtqFd S )Nr   rZ   )sizerY   r\   )krd   ra   ru   r   rv   r   )r  r   )rY   rd   ru   rz   ry   c                 S   s2   g | ]*}t d d |D rt| dkr|qS )c                 s   s   | ]}|d kV  qdS )ru   NrU   r   r  rU   rU   rV   r     s     -test_partitions.<locals>.<listcomp>.<genexpr>rd   )allsumvaluesr   rU   rU   rV   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 )rd   NrU   r  rU   rU   rV   r     s     r  )r	  r   rU   rU   rV   r     s     )r   rP   r-   rS   rH   r   r   r   )r   r   nr   qrU   rU   rV   test_partitions  sj       "    
     
      
r  c                   C   s   dd t dD ddgdddgdddgddddgddddgdddddgddddddgdddddddgdddddgddddddgdddddddgddddddddgdddddddddg	ddddddddddg
gksttdd t d	D d
kstd S )Nc                 S   s   g | ]}|d d  qS r   rU   r   rU   rU   rV   r      s     z*test_binary_partitions.<locals>.<listcomp>r   r   rZ   rY   ru   c                 S   s   g | ]}|d d  qS r   rU   r   jrU   rU   rV   r     s        $   )r   rS   r   rU   rU   rU   rV   test_binary_partitions  s     
 
      
r  c                  C   s   dd t ddD dd t ddD ks,tttdddd	d
ddgksLtt ddD ]<} tt | }t| }|D ]}|t|jkst| }qrqVtt	dd  d S )Nc                 S   s   g | ]}t tt|qS rU   )r   r   r   r   rU   rU   rV   r   
  s     z"test_bell_perm.<locals>.<listcomp>rY   r   c                 S   s   g | ]}t |qS rU   r   r   rU   rU   rV   r   
  s    rd   r   r   r   r   r   r   r]   c                   S   s   t tdS )Nr   )rP   r   rU   rU   rU   rV   rf     rg   z test_bell_perm.<locals>.<lambda>)
r   rS   rP   r   r   r   Z
array_formZnext_trotterjohnsonrI   rp   )r  r   r   ZbirU   rU   rV   test_bell_perm	  s$    
     
r  c                  C   s`   ddddddg} t | D ]B\}}tt|d }t||ks@ttdd |D dkstqd S )	NrY   rZ   ru   r      L   c                 S   s   h | ]}t |d  qS rs   )r   r  rU   rU   rV   	<setcomp>  s     z#test_involutions.<locals>.<setcomp>)	enumeraterP   r   r   rS   )lengthsr  Nr   rU   rU   rV   test_involutions  s
    r  c                  C   sV  t ttttddks tddd tdD dks@tttdd	d
dgd	ddd
gd	d
ddgd	ddd
gd
ddd	gd
ddd	gd
dd	dgddd	d
gdd
dd	gdd
d	dgg	kstttdd	d
d
gd
d
dd	gd
d
d	dggkstttdtdgkstt} t| dg kstdd | dD dgks:tdd | dD ddgksZtdd | dD dgksxtdd | dD ddddddgkstd d | d!D d"d#d$d%d&d'd(d)d*d+d,d-gkstd.d | d/D d0d1d2d3d4d5d6d7d8d9d:d;gkst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sRtd S )<Nr\   i	  rX   c                 s   s   | ]}d  |V  qdS r   r   r   rU   rU   rV   r   $  s     z$test_derangements.<locals>.<genexpr>abcdeZbadecbaecdbcaedbcdeabceadbdaecbdeacbdecabeacdbedacbedcacabedcadebcaebdcdaebcdbeacdeabcdebaceabdcebadcedabcedbadabecdaebcdaecbdcaebdcbeadceabdcebadeabcdeacbdebacdebcaeabcdeadbceadcbecabdecbadecdabecdbaedabcedacbedbacedbcar   rY   rZ   rd   bar   Zabbc                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   2  s     z%test_derangements.<locals>.<listcomp>c                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   3  s     r   ZbcaZcabc                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   4  s     ZaabbZbbaac                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   5  s     ZaabbccccZccccaabbZccccababZccccabbaZccccbaabZccccbabaZccccbbaac                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   8  s     ZaabbcccZcccabbaZcccababZcccaabbZccacbbaZccacbabZccacabbZcbccbaaZcbccabaZcbccaabZbcccbaaZbcccabaZbcccaabc                 S   s   g | ]}d  |qS r   r   r   rU   rU   rV   r   <  s     booksZkbsooZksbooZsbkooZskbooZoksboZoskboZokbsoZobksoZoskobZoksobZosbokZobsok)r   rP   r   r   rS   r   rB   )DrU   rU   rV   test_derangements"  s~     
 
 
 

 
 
 
 


 

                       r   c                  C   s   dd } g }t ddD ].}||| |dd| |dd| |ddf qt|tddddgddddgdd	d	d
gd	dddgddddgddddgddddggkstd S )Nc                 S   s   t tt| ||S r   )r   rP   r+   )r  r  frU   rU   rV   countD  s    ztest_necklaces.<locals>.countrY   r   rZ   r   rd   r\   ru   r      r]   '         \   r            )r   r   r   rS   )r"  r   r   rU   rU   rV   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^tt tdd} t| tddddgddddgddddgddddgddddgddddggkstd S )NrZ   ru   r   rY   rd   )rP   r   r   rS   )bcrU   rU   rV   test_braceletsT  s,    





r-  c                   C   s$  t tddddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddgdddddggksttt tddks td S )	Nr]   r   rY   rZ   rd   ru   r   i2  )rP   r    rS   r   rU   rU   rU   rV   test_generate_oriented_forestm  s,                  r.  c                  C   s   t td} t| t t| d d d | dd d ks:tt| dt| d d t| dd  gkshtttdd  ttdd  d S )Nr   rZ   rY   r]   c                   S   s   t ttddS )Nr   rd   r:   rP   r   rU   rU   rU   rV   rf   {  rg   z test_unflatten.<locals>.<lambda>c                   S   s   t ttddS )Nr   r`   r/  rU   rU   rU   rV   rf   |  rg   )rP   r   r:   ziprS   r   rI   rp   )rrU   rU   rV   test_unflattenw  s
    ..r2  c                   C   sd  t g dgg kstt ttddddgks2tt ttdttddddgksZtt dddgdddgddgks|tt dddgdddgdgksttg dgg ksttttddddgksttttdttddddgksttttdttdg ksttdddgdddgddgks>ttdddgdddgdgks`td S )	NrY   rd   r   rZ   ru   r]   r   r   )r   rS   rP   r   r   rU   rU   rU   rV   test_common_prefix_suffix  s    (" ($$r3  c                   C   sr   t dddgdkstt ddks&tt ddks6tt ddd	dksJtt d
dksZtt dtddksntd S )NrY   rZ   r   r   r   r   r   F)ZdirectedZabaZaab)bbr   r   r   rM   )r   r   r4  r   )r&   rS   r   rU   rU   rU   rV   test_minlex  s    r5  c                      s  t tttftddttgttgfks*tt tttftddt tttftddksZtt tttfttgksvtdddgdddgdddgdgdggdd d	d fg\ t t ddd
dgdgdddgdddgdddggksttt fdd d S )NF)defaultrY   rZ   r   rd   c                 S   s   t | S r   )r   r   rU   rU   rV   rf     rg   ztest_ordered.<locals>.<lambda>c                 S   s   t | S r   )r
  r   rU   rU   rV   rf     rg   r6  warnc                      s   t t dddS )NFTr7  )rP   r   rU   keysseqrU   rV   rf     s    )rP   r   rR   rQ   hashrS   rI   rp   rU   rU   r9  rV   test_ordered  s    *""r=  c                  C   s   t g g kstt dgdggks&tt ddgdgdggksBtt dddgdgddggksbtt dddgddgdggkstt dddgdgdgdggkstddlm}  t dddg| ddgdggkstd S )NrY   rZ   r   lt)r4   rS   operatorr?  r>  rU   rU   rV   	test_runs  s      "rA  c                  C   s  t tdd} t| dgddddgdddd	ggks6tt| d
ddgksLtt| dddgksbtt| ddgfddddgfdddd	gfgkstt| ddgfdddgfddd	gfgkstt| ddgdfdddgdfdddgd	fgksttt| dgddgfdgddgfdgddgffks*ttt| dgddfdgddfdgddffks^ttt tdddgdhdgdddddgddhdggkstttdd  ttdd  d S )NrY   r   ru   rZ   rd   r]   r\   r   r   )ru   )rY   rZ   rd   ru   )r]   r\   r   r   r   rs   ra   )r]   r\   r   r   r   )rY   rt   rY   r   )r   )r   r   r   ro   c                   S   s   t ddgdgS )Nr   rY   r[   r1   rU   rU   rU   rV   rf     rg   ztest_reshape.<locals>.<lambda>c                   S   s   t ddgdgS )Nr   rY   rd   rB  rU   rU   rU   rV   rf     rg   )rP   r   r1   rS   r   rI   rp   )r;  rU   rU   rV   test_reshape  s<    



rC  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sDtt tdd td	D d
dgksjtt tddgkstt tdt dkstt tdgddgdggdgddggkst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t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sRt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   rU   r   rU   rU   rV   r     s     ztest_uniq.<locals>.<genexpr>ru   rY   rv   rZ   ra   c                 s   s   | ]}|d  V  qdS )rZ   NrU   )r   rR   rU   rU   rV   r     s     r]   r   r   Zababcr   c                 s   s   | ]
}|V  qd S r   rU   r   rU   rU   rV   r     s     rd   c                      s    fddt  D S )Nc                    s   g | ]}  |qS rU   remover   r!  rU   rV   r     s     /test_uniq.<locals>.<lambda>.<locals>.<listcomp>r;   rU   rF  rU   rV   rf     rg   ztest_uniq.<locals>.<lambda>c                      s    fddt  D S )Nc                    s   g | ]}  |qS rU   rD  r   rF  rU   rV   r     s     rG  rH  rU   rF  rU   rV   rf     rg   )rP   r;   r-   rS   r   r.   rI   RuntimeErrorrU   rU   rF  rV   	test_uniq  s"    $&,  
&
rJ  c                      s   t ttdddddkstt ttdddddks<tt ttdddddksZtt ttddd	dd
ksxtt ttddd ddkstdd  t fddtdkstdd tfddtdkstd S )NZ1123rZ   rY   r   r   ro   r  r   r   r]   rd   c                  S   s<   dD ]2} t d|  tdddgd| dD ]}t d| q&qd S )NNr   rY   r   ro   	ordered =r   rY   rZ   r      )r   r%   Z
orderedvalr   rU   rU   rV   test1  s    
ztest_kbins.<locals>.test1c                      s     S r   rU   rU   )rO  rU   rV   rf     rg   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 )NrK  rL  rd   rZ   r   rM  )r   r%   rP   r   rN  rU   rU   rV   test2  s    
ztest_kbins.<locals>.test2c                      s     S r   rU   rU   )rP  rU   rV   rf     rg   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%   rS   r   r   rU   rU   )rO  rP  rV   
test_kbins  s    rQ  c                   C   st   t t dkstt ttddks*tt dddgdks@tt dgdggdksXtt dgdggdksptd S )NFrd   rY   rZ   T)r"   r   rS   rP   r   rU   rU   rU   rV   test_has_dups'  s
    rR  c                  C   s   t ddddddgddgddgd	ggks,tt ddddddgd
ddgddgd	ggksZtd
dddddgf} t d|  ddgddgd	ggkstd S )Nr  rY   r   rZ   r   er   r   drd   )r  )r   rS   )outputrU   rU   rV   test__partition/  s      
  
rV  c               	   C   s   ddl m}  t}t|ddg gks(tt|ddg gks@t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 tqbqJd S )Nr   )nTrY   r   c                 s   s   | ]
}d V  qdS rY   NrU   r   rU   rU   rV   r   @  s     z*test_ordered_partitions.<locals>.<genexpr>c                 s   s   | ]
}d V  qdS rX  rU   r   rU   rU   rV   r   A  s     )Z%sympy.functions.combinatorial.numbersrW  r=   rP   rS   r   r
  )rW  r!  r   r  rU   rU   rV   test_ordered_partitions8  s    rY  c                   C   s   t tdddgddggks tt ttddddgdddgdddggksPtt ttddd	dddgdddgdddggkstd S )
Nr   r   r   rd   r   rY   rZ   r[   )dir)rP   r>   rS   r   rU   rU   rU   rV   test_rotationsE  s     0r[  c                   C   s   t dddgkstt dddddgks,tt ddddks@tt dddddksVttt dd	d
dddgkstttt ddddddddgkstttdd  ttdd  d S )Nrd   rY   r   T)strZ11Z011rZ   r	  rb   r   r   r   rX   Z00Z0110c                   S   s   t dS )Ng      ࿩r#   rU   rU   rU   rV   rf   R  rg   ztest_ibin.<locals>.<lambda>c                   S   s
   t ddS )NrZ   rY   r^  rU   rU   rU   rV   rf   S  rg   )r#   rS   rP   rI   rp   rU   rU   rU   rV   	test_ibinK  s    "r_  c                  C   s   t ddkstt ddks tt d dks0tG dd dt} t |  dksRtG dd dt}t | dksttG d	d
 d
}t | dkstG dd d}t | dkstG dd d}t | dkstG dd d|}t | dkstd S )Nr   FrY   c                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test1Nrh   rU   rU   rU   rV   Test1[  s   r`  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test2TNri   rj   rk   	_iterablerU   rU   rU   rV   Test2`  s   rc  Tc                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test3Nrh   rU   rU   rU   rV   Test3e  s   rd  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test4TNra  rU   rU   rU   rV   Test4j  s   re  c                   @   s   e Zd Zdd ZdS )ztest_iterable.<locals>.Test5c                 s   s
   dV  d S )NrY   rU   )selfrU   rU   rV   __iter__p  s    z%test_iterable.<locals>.Test5.__iter__N)ri   rj   rk   rg  rU   rU   rU   rV   Test5o  s   rh  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test6FNra  rU   rU   rU   rV   Test6u  s   ri  )r@   rS   rA   )r`  rc  rd  re  rh  ri  rU   rU   rV   test_iterableV  s    rj  c                   C   sR  t tdgddgggkstt tddgdddgggks@tt tddgddgdgggksdtt tdddgddddgggkstt tdddgddgddggddgdgggkstt tdddgddgdgdgggkstt tg dg kstt tg dg kstt tddgdg ks2tt tddgdg ksNtd S NrY   rZ   rd   r   )rP   rD   rS   rU   rU   rU   rV   test_sequence_partitions{  s    "$&*rl  c                   C   s  t tg dg ggkstt tg dg g ggks6tt tg dg g g ggksTtt tdgddgggksrtt tdgdg dggdgg ggkstt tdgdg g dggg dgg gdgg g ggkstt tddgdddgggkstt tddgdg ddggdgdggddgg ggks,t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stt tdddgddddgggkstt tdddgdg dddggdgddggddgdggdddgg ggkstt tdddgdg g dddggg dgddggg ddgdggg dddg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dddgg g gg
kstt tg dg kstt tdgdg kstt tddgdg kstd S rk  )rP   rE   rS   rD   rU   rU   rU   rV   test_sequence_partitions_empty  sN    ( " 
    (2
     	rm  c                  C   s\   ddddddddd	d
ddg} t td| ks0tt td| ksDtt td	| ksXtd S )Nr   )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   )rP   rC   rS   )r   rU   rU   rV   test_signed_permutations  s          rn  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   rq   rW   r^   rr   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.  r2  r3  r5  r=  rA  rC  rJ  rQ  rR  rV  rY  r[  r_  rj  rl  rm  rn  rU   rU   rU   rV   <module>   sx   (				BA+
!
	N	% 