a
    lh؉                     @   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   R/var/www/auris/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   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   rn   cls>   rY   rZ      )r   rR   rI   
ValueErrorr   rQ   zrP   )rn   rT   rg   rU   test_flatten9   s    $&rt   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   rf   r_   rZ   rf   rY   rZ   rf      r]   rY   rf   )rY   rz   )rY   r]   rZ   rf   rZ   rz   )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   Trx   )rz   r]   i  ra   rf   )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)multiplerY   rY   rY   rb   r   r|   rY   rZ   rY   rZ   )r   rZ   rY   r   )rY   rY   rZ   rZ   rZ   rY   rf   rf   rZ   rZ   rZ   rf   )rb   r}   r   rf   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 )Nru   r   rT   rY   rv   rZ   )rb   r|   r}   rf   rz   TZ
repetitionr   r_   rw   rx   )
rc   r   rY   r   rZ   r   rf   r   rb   r|   rZ   rZ   r}   rf   rf   )r   r   )r   r   rZ   )r   r   rf   r   r   rY   rZ   r   rY   rf   )r   rZ   rZ   r   rZ   rf   )r   rf   rf   r   rY   rY   rZ   rY   rY   rf   rY   rZ   rZ   ru   )rY   rf   rf   r   )rZ   rZ   rf   )rZ   rf   rf   )rf   rf   rf   #   F)r   r   r   r   )rT   r_   rw   r   rb   r   )rT   r_   rw   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 )Nrz   r   Fr   rT   rY   r   rZ   )r   r   r   rY   r   rb   r|   rZ   r   r   r}   rf   r   rf   rY   r   rf   )r   r   r   rZ   rY   r   r   rf   rY   )r   rf   rZ   rY   r   rZ   )rY   r   rf   rY   rZ   r   ru   )rY   rf   r   )rY   rf   rZ   rZ   r   rY   )rZ   r   rf   rZ   rY   r   )rZ   rY   rf   )rZ   rf   r   )rZ   rf   rY   )rf   r   rY   )rf   r   rZ   )rf   rY   r   )rf   rY   rZ   )rf   rZ   r   rf   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   ry   r{   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 x3rf   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 )Nro   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   rh      ri   ztest_sift.<locals>.<lambda>rY   rf   )r   rZ   rz   r   c                 S   s
   |  tS NZhasrR   r   rT   rT   rU   rh      ri   )FTc                 S   s
   |  tS r   r   r   rT   rT   rU   rh      ri   Fr   rY   rZ   rf   c                 S   s   | d S r   rT   rR   rT   rT   rU   rh      ri   Tbinaryr   rZ   c                 S   s   | d dkS )Nrf   rY   rT   r   rT   rT   rU   rh      ri   r   c                   S   s   t g ddd ddS )Nr   c                 S   s   | d S )Nrf   rT   r   rT   rT   rU   rh      ri   z-test_sift.<locals>.<lambda>.<locals>.<lambda>Tr   )r5   rT   rT   rT   rU   rh      s    )	r5   rP   r   rR   rQ   rH   ZOnerI   rr   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   rf   rz   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   rs   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   ru   rY   rZ   rf   rz   )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]   rz   ry   )rZ   rf   rz   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   rf   r]         	   
   rq   )	)r   rq   r   r   )r]   rq   )rf   r   )rf   r   )rq   rZ   )rq   r   )rq   r   )r   r   )rf   r]   r   r   rq   rZ   r   r   c                 S   s   |  S r   rT   )vrT   rT   rU   rh   	  ri   z'test_topological_sort.<locals>.<lambda>rM   )r   r]   rq   rf   r   r   r   rZ   c                      s   t  dg fS )N)r   r   )r9   rT   EVrT   rU   rh     ri   )r9   rI   rr   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 )
Nru   rY   rZ   rf   rb   r|   r   r}   r   r   rb   r}   r   rf   rz   rz   )rb   r   r   )rz   rf   )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 )Nru   rY   rZ   rf   r   r   r   rb   r   rz   )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   rf   rz   rZ   )rZ   rf   rz   r   rY   rY   )rz   r   rY   rZ   rf   )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   rf   rz   r      )rY   rY   rY   rZ   rZ   )rY   rY   rY   rZ   r   )rY   rY   rZ   rZ   r   r   r   ru   )rY   rZ   rz   rY   rf   rz   rZ   rf   rz   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>{  ri   z6test_multiset_partitions.<locals>.<listcomp>.<genexpr>)tupler   r   rT   rT   rU   
<listcomp>{  s   z,test_multiset_partitions.<locals>.<listcomp>Zsympy   r      r\   )rz   rZ   rf   )r\   rZ   rZ   )rZ   rZ   rZ   rf   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    ri   z.test_multiset_combinations.<locals>.<listcomp>Zmississippirf   c                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r    ri   c                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r    ri      rY   rZ   r   r   abcr   cc                   S   s   t tddddS )Nrf   r[   r   rZ   )rP   r(   rT   rT   rT   rU   rh     ri   z,test_multiset_combinations.<locals>.<lambda>)rP   r(   r'   r   rI   rr   )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    ri   z.test_multiset_permutations.<locals>.<listcomp>r  c                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r    ri   r   rZ   r   r   rY   r   rf   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   rh     ri   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 )Nrf   r[   r   )rP   r*   rT   rT   rT   rU   rh     ri   )r*   r'   rP   r   r   r   rI   rr   )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\   )krf   rb   rz   ru   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 )rz   NrT   r   r  rT   rT   rU   r     ri   -test_partitions.<locals>.<listcomp>.<genexpr>rf   )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 )rf   NrT   r  rT   rT   rU   r     ri   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     ri   z*test_binary_partitions.<locals>.<listcomp>r   r   rZ   )r   rY   rY   )rz   rz   rZ   )rz   rz   rY   rY   )rz   rZ   rZ   rZ   )rz   rZ   rZ   rY   rY   )rz   rZ   rY   rY   rY   rY   )rz   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    ri      $   )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  
  ri   z"test_bell_perm.<locals>.<listcomp>rY   r   c                 S   s   g | ]}t |qS rT   r   r
  rT   rT   rU   r  
  s   rf   )r   r   r   r   r   r   r]   c                   S   s   t tdS )Nr   )rP   r   rT   rT   rT   rU   rh     ri   z test_bell_perm.<locals>.<lambda>)	r   rP   r   r   r   Z
array_formZnext_trotterjohnsonrI   rr   )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   rz   r      L   rY   c                 S   s   h | ]}t |d  qS rw   )r   r!  rT   rT   rU   	<setcomp>  ri   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   $  ri   z$test_derangements.<locals>.<genexpr>abcdeZbadecbaecdbcaedbcdeabceadbdaecbdeacbdecabeacdbedacbedcacabedcadebcaebdcdaebcdbeacdeabcdebaceabdcebadcedabcedbadabecdaebcdaecbdcaebdcbeadceabdcebadeabcdeacbdebacdebcaeabcdeadbceadcbecabdecbadecdabecdbaedabcedacbedbacedbcar   )rY   r   rf   rZ   )rY   rZ   rf   r   )rY   rf   r   rZ   )rZ   r   rf   rY   )rZ   rf   r   rY   )rZ   rf   rY   r   )rf   r   rY   rZ   )rf   rZ   r   rY   )rf   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  ri   z%test_derangements.<locals>.<listcomp>c                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r  3  ri   r  ZbcaZcabc                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r  4  ri   ZaabbZbbaac                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r  5  ri   Zaabbcccc)ZccccaabbZccccababZccccabbaZccccbaabZccccbabaZccccbbaac                 S   s   g | ]}d  |qS r	  r   r
  rT   rT   rU   r  8  ri   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  <  ri   Zbooks)ZkbsooZksbooZsbkooZskbooZoksboZoskboZokbsoZobksoZoskobZoksobZosbokZobsokrf   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   rf   )rY   rZ   rZ   rf   )rZ   rf   rf   r\   )rf   rz   rz   r   )rz   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   rz   r   rY   rf   )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   )Z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   rf   rf   )r   rY   rZ   rf   rZ   )r   rY   rZ   rf   rY   )r   rY   rZ   rf   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   rf   r:   rP   r   rT   rT   rT   rU   rh   {  ri   z test_unflatten.<locals>.<lambda>c                   S   s   t ttddS )Nr   ra   r?  rT   rT   rT   rU   rh   |  ri   )rP   r   r:   zipr   rI   rr   )rrT   rT   rU   test_unflattenw  s
    ..rB  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   rf   r   rz   ru   )rY   rZ   r]   rZ   )rY   rf   r]   )r   rZ   rf   )r   r   rf   )r   rP   r   r   rT   rT   rT   rU   test_common_prefix_suffix  s    &&$ rC  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   rD  r   )r&   r   rT   rT   rT   rU   test_minlex  s    rE  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   rh     ri   ztest_ordered.<locals>.<lambda>c                 S   s   t | S r   )r  r   rT   rT   rU   rh     ri   rF  warnc                      s   t t dddS )NFTrG  )rP   r   rT   keysseqrT   rU   rh     s    )rP   r   rR   rQ   hashrI   rr   rT   rT   rI  rU   test_ordered  s    *rM  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   operatorrO  rN  rT   rT   rU   	test_runs  s     rQ  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   rz   r   )r]   r\   r   r   )rz   r   rZ   rf   r]   r\   r   r   rw   rb   )r]   r\   r   r   r  )rY   rx   rY   r   r   )r   )r   r   r   rq   c                   S   s   t ddgdgS )Nr   rY   r[   r1   rT   rT   rT   rU   rh     ri   ztest_reshape.<locals>.<lambda>c                   S   s   t ddgdgS )Nr   rY   rf   rR  rT   rT   rT   rU   rh     ri   )rP   r   r1   r   rI   rr   )rK  rT   rT   rU   test_reshape  s<    



rS  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     ri   ztest_uniq.<locals>.<genexpr>rz   rY   r|   rZ   rb   c                 s   s   | ]}|d  V  qdS )rZ   NrT   )r   rR   rT   rT   rU   r     ri   r]   r   r   Zababcr  c                 s   s   | ]
}|V  qd S r   rT   r
  rT   rT   rU   r     ri   rf   c                      s    fddt  D S )Nc                    s   g | ]}  |qS rT   remover
  r2  rT   rU   r    ri   /test_uniq.<locals>.<lambda>.<locals>.<listcomp>r;   rT   rV  rT   rU   rh     ri   ztest_uniq.<locals>.<lambda>c                      s    fddt  D S )Nc                    s   g | ]}  |qS rT   rT  r
  rV  rT   rU   r    ri   rW  rX  rT   rV  rT   rU   rh     ri   )rP   r;   r-   r   r.   rI   RuntimeErrorrT   rT   rV  rU   	test_uniq  s"    $&,  
&
rZ  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  rq   r$  r   r   r]   rf   c                  S   s:   dD ]0} t d|  tg dd| dD ]}t d| q$qd S )NNr   rY   r   rq   	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   rh     ri   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\  rf   rZ   r   r]  )r  r%   rP   r   r^  rT   rT   rU   test2  s    
ztest_kbins.<locals>.test2c                      s     S r   rT   rT   )r`  rT   rU   rh     ri   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_  r`  rU   
test_kbins  s    ra  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 )NFrf   r   TrY   rZ   )r"   r   rP   r   rT   rT   rT   rU   test_has_dups'  s
    rb  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  drf   )r   )outputrT   rT   rU   test__partition/  s    

rf  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   @  ri   z*test_ordered_partitions.<locals>.<genexpr>c                 s   s   | ]
}d V  qdS rh  rT   r  rT   rT   rU   r   A  ri   )Z%sympy.functions.combinatorial.numbersrg  r=   rP   r   r  )rg  r2  r  r"  rT   rT   rU   test_ordered_partitions8  s    ri  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   rf   r   r   r   r[   )dir)rP   r>   r   rT   rT   rT   rU   test_rotationsE  s     *rk  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 )Nrf   rY   r   T)str11Z011rZ   r  )rc   r   r   r   rW   )Z00Z0110rm  c                   S   s   t dS )Ng      ࿩r#   rT   rT   rT   rU   rh   R  ri   ztest_ibin.<locals>.<lambda>c                   S   s
   t ddS )NrZ   rY   ro  rT   rT   rT   rU   rh   S  ri   )r#   rP   rI   rr   rT   rT   rT   rU   	test_ibinK  s    rp  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>.Test1Nrj   rT   rT   rT   rU   Test1[  s   rq  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test2TNrk   rl   rm   Z	_iterablerT   rT   rT   rU   Test2`  s   rs  Tc                   @   s   e Zd ZdS )ztest_iterable.<locals>.Test3Nrj   rT   rT   rT   rU   Test3e  s   rt  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test4TNrr  rT   rT   rT   rU   Test4j  s   ru  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)rk   rl   rm   rw  rT   rT   rT   rU   Test5o  s   rx  c                   @   s   e Zd ZdZdS )ztest_iterable.<locals>.Test6FNrr  rT   rT   rT   rU   Test6u  s   ry  )r@   rA   )rq  rs  rt  ru  rx  ry  rT   rT   rU   test_iterableV  s    rz  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   ru   rf   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   rf   ru   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   rs   rV   r^   rt   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>  rB  rC  rE  rM  rQ  rS  rZ  ra  rb  rf  ri  rk  rp  rz  r{  r|  r}  rT   rT   rT   rU   <module>   sx   (				BA+
!
	N	% 