U
    @f؉                     @   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   H/tmp/pip-unpacked-wheel-6uje5nh9/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   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   rm   cls   )	r   rS   rR   rI   
ValueErrorr   rQ   zrP   )rm   rU   rf   rV   test_flatten9   s      $&rs   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   re   r_   rZ   re      r]   rY   re   rY   rv   rY   r]   rZ   re   rZ   rv   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)rv   r]   rY   rZ   re   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)multiplerY   rY   rY   ra   rw   rZ   rZ   rY   re   rz   re   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   re   r   rU   r_   rt   ru   ra   rw   rz   r   rv   TZ
repetitionr   rb   r   rY   r   rZ   r   re   r   rZ   rZ   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   )rY   re   re   )rZ   rZ   rZ   )rZ   rZ   re   )rZ   re   re   )re   re   re   #   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 )@Nrv   r   Fr   rU   rY   r   r_   rt   ru   rZ   r   r   r   rY   r   ra   rw   )rZ   r   r   rz   )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   r   )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   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   re   rv   r]   rw   rx   ry   rz   r{   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 x3re   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 )Nrn   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   rg      rh   ztest_sift.<locals>.<lambda>rY   re   r   rZ   rv   r   c                 S   s
   |  tS NZhasrR   r   rU   rU   rV   rg      rh   )FTc                 S   s
   |  tS r   r   r   rU   rU   rV   rg      rh   Fc                 S   s   | d S r   rU   rR   rU   rU   rV   rg      rh   Tbinaryc                 S   s   | d dkS )Nre   rY   rU   r   rU   rU   rV   rg      rh   c                   S   s   t ddddgdd ddS )	Nr   rY   rZ   re   c                 S   s   | d S )Nre   rU   r   rU   rU   rV   rg      rh   z-test_sift.<locals>.<lambda>.<locals>.<lambda>Tr   )r5   rU   rU   rU   rV   rg      s    )
r5   rP   r   rS   rR   rQ   rH   ZOnerI   rq   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   re   rv   )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   rr   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   re   rv   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   re   r]         	   
   rp   )r   rp   r   r   )r]   rp   )re   r   )re   r   )rp   rZ   )rp   r   )rp   r   )r   r   c                 S   s   |  S r   rU   )vrU   rU   rV   rg   	  rh   z'test_topological_sort.<locals>.<lambda>rM   c                      s   t  dg fS )N)r   r   )r9   rU   EVrU   rV   rg     rh   )r9   rS   rI   rq   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   re   ra   rw   r   rz   r   rv   r   re   rv   )rv   re   )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   re   ra   rw   r   rz   r   rv   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   re   rv   )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   re   rv   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 rz   )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mississippire   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 )Nre   r[   r   rZ   )rP   r(   rU   rU   rU   rV   rg     rh   z,test_multiset_combinations.<locals>.<lambda>)rP   r(   rS   r'   r   rI   rq   )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aybbZ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   re   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   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*   rU   rU   rU   rV   rg     rh   )	r*   rS   r'   rP   r   r   r   rI   rq   )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\   )kre   ra   rv   r   rw   r   )r  r   )rY   re   rv   r{   rz   c                 S   s2   g | ]*}t d d |D rt| dkr|qS )c                 s   s   | ]}|d kV  qdS )rv   NrU   r   r  rU   rU   rV   r     s     -test_partitions.<locals>.<listcomp>.<genexpr>re   )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 )re   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   rv   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    re   r   r   r   r   r   r   r]   c                   S   s   t tdS )Nr   )rP   r   rU   rU   rU   rV   rg     rh   z test_bell_perm.<locals>.<lambda>)
r   rS   rP   r   r   r   Z
array_formZnext_trotterjohnsonrI   rq   )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   rv   r      L   c                 S   s   h | ]}t |d  qS rt   )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   re   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     Z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   re   r\   rv   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   rv   r   rY   re   )rP   r   r   rS   )Z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   re   rv   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   re   r:   rP   r   rU   rU   rU   rV   rg   {  rh   z test_unflatten.<locals>.<lambda>c                   S   s   t ttddS )Nr   r`   r-  rU   rU   rU   rV   rg   |  rh   )rP   r   r:   ziprS   r   rI   rq   )rrU   rU   rV   test_unflattenw  s
    ..r0  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   re   r   rZ   rv   r]   r   r   )r   rS   rP   r   r   rU   rU   rU   rV   test_common_prefix_suffix  s    (" ($$r1  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   r2  r   )r&   rS   r   rU   rU   rU   rV   test_minlex  s    r3  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   re   c                 S   s   t | S r   )r   r   rU   rU   rV   rg     rh   ztest_ordered.<locals>.<lambda>c                 S   s   t | S r   )r
  r   rU   rU   rV   rg     rh   r4  warnc                      s   t t dddS )NFTr5  )rP   r   rU   keysseqrU   rV   rg     s    )rP   r   rR   rQ   hashrS   rI   rq   rU   rU   r7  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      "r?  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   rv   rZ   re   r]   r\   r   r   )rv   )rY   rZ   re   rv   )r]   r\   r   r   r   rt   ra   )r]   r\   r   r   r   )rY   ru   rY   r   )r   )r   r   r   rp   c                   S   s   t ddgdgS )Nr   rY   r[   r1   rU   rU   rU   rV   rg     rh   ztest_reshape.<locals>.<lambda>c                   S   s   t ddgdgS )Nr   rY   re   r@  rU   rU   rU   rV   rg     rh   )rP   r   r1   rS   r   rI   rq   )r9  rU   rU   rV   test_reshape  s<    



rA  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>rv   rY   rw   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     re   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   rD  rU   rV   rg     rh   ztest_uniq.<locals>.<lambda>c                      s    fddt  D S )Nc                    s   g | ]}  |qS rU   rB  r   rD  rU   rV   r     s     rE  rF  rU   rD  rU   rV   rg     rh   )rP   r;   r-   rS   r   r.   rI   RuntimeErrorrU   rU   rD  rV   	test_uniq  s"    $&,  
&
rH  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   rp   r  r   r   r]   re   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   rp   	ordered =r   rY   rZ   r      )r   r%   Z
orderedvalr   rU   rU   rV   test1  s    
ztest_kbins.<locals>.test1c                      s     S r   rU   rU   )rM  rU   rV   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 )NrI  rJ  re   rZ   r   rK  )r   r%   rP   r   rL  rU   rU   rV   test2  s    
ztest_kbins.<locals>.test2c                      s     S r   rU   rU   )rN  rU   rV   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%   rS   r   r   rU   rU   )rM  rN  rV   
test_kbins  s    rO  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 )NFre   rY   rZ   T)r"   r   rS   rP   r   rU   rU   rU   rV   test_has_dups'  s
    rP  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   dre   )r  )r   rS   )outputrU   rU   rV   test__partition/  s      
  
rT  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 rV  rU   r   rU   rU   rV   r   A  s     )Z%sympy.functions.combinatorial.numbersrU  r=   rP   rS   r   r
  )rU  r   r   r  rU   rU   rV   test_ordered_partitions8  s    rW  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   re   r   rY   rZ   r[   )dir)rP   r>   rS   r   rU   rU   rU   rV   test_rotationsE  s     0rY  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 )Nre   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   rg   R  rh   ztest_ibin.<locals>.<lambda>c                   S   s
   t ddS )NrZ   rY   r\  rU   rU   rU   rV   rg   S  rh   )r#   rS   rP   rI   rq   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>.Test1Nri   rU   rU   rU   rV   Test1[  s   r^  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test2TNrj   rk   rl   Z	_iterablerU   rU   rU   rV   Test2`  s   r`  Tc                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test3Nri   rU   rU   rU   rV   Test3e  s   ra  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test4TNr_  rU   rU   rU   rV   Test4j  s   rb  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)rj   rk   rl   rd  rU   rU   rU   rV   Test5o  s   re  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test6FNr_  rU   rU   rU   rV   Test6u  s   rf  )r@   rS   rA   )r^  r`  ra  rb  re  rf  rU   rU   rV   test_iterableV  s    rg  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   re   r   )rP   rD   rS   rU   rU   rU   rV   test_sequence_partitions{  s    "$&*ri  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 rh  )rP   rE   rS   rD   rU   rU   rU   rV   test_sequence_partitions_empty  sN    ( " 
    (2
     	rj  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          rk  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   rW   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  r  r*  r+  r,  r0  r1  r3  r;  r?  rA  rH  rO  rP  rT  rW  rY  r]  rg  ri  rj  rk  rU   rU   rU   rV   <module>   sx   (				BA+
!
	N	% 