a
    kh@                    @   sh  d dl Z d dlmZ d dl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 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 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)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z7 e/Z8e2Z9G dd deZ:ee:dd Z;dd Z<e<Z=dd Z>dS )    N)S)Add)Tuple)FunctionMul)NumberRational)Pow)default_sort_keySymbol)SympifyError)requires_partial)
PRECEDENCE
precedenceprecedence_traditional)Printerprint_function)sstr)has_variety)sympy_deprecation_warning)
prettyForm
stringPict)hobjvobjxobjxsympretty_symbolpretty_atompretty_use_unicodegreek_unicodeUpretty_try_use_unicode	annotatedis_subscriptable_in_unicode
center_padrootc                   @   s	  e Zd ZdZdZddddddddddd
Zdd	d
Zdd Zedd Z	dd Z
dd Zdd Zdd ZdddZeZdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ ZeZeZeZeZeZeZeZeZ eZ!d,d- Z"d.d/ Z#d0d1 Z$d2d3 Z%d4d5 Z&d6d7 Z'd8d9 Z(dd:d;Z)d<d= Z*d>d? Z+d@dA Z,dBdC Z-dDdE Z.ddFdGZ/ddHdIZ0dJdK Z1dLdM Z2dNdO Z3dPdQ Z4dRdS Z5dTdU Z6dVdW Z7dXdY Z8dZd[ Z9d\d] Z:d^d_ Z;d`da Z<dbdc Z=ddfdgZ>dhdi Z?djdk Z@dldm ZAdndo ZBdpdq ZCdrds ZDdtdu ZEdvdw ZFdxdy ZGdzd{ ZHd|d} ZId~d ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]i fddZ^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd ZgdddZhdd Zidd Zjdd ZkddĄ ZldddȄZmddʄ Zndd̄ Zodd΄ ZpddЄ ZqdddӄZrddՄ Zseddׄ Ztddل Zuddۄ Zvdd݄ Zwdd߄ Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d Zdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zdd"d#Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZeZeZeZdddѐdTdU dfdVdWZdXdY ZdZd[ Zd\d] Zd^d_ Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq ZÐdrds ZĐdtdu ZŐdvdw ZƐdxdy Zǐdzd{ ZȐd|d} Zɐd~d Zʐdd Zːdd Z̐dd Z͐dd Zΐdd Zϐdd ZАdd Zѐdd ZҐdd ZӐdd ZԐdd ZeZ֐dd Zאdd Zؐdd Zِdd Zڐdd Zېdd Zܐdd Zݐdd Zސdd Zߐdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZddÄ ZdĐdń ZdƐdǄ ZdȐdɄ Zdʐd˄ Zd̐d̈́ Zdΐdτ ZdАdф ZdҐdӄ ZdԐdՄ Zd֐dׄ Zdؐdل Zdڐdۄ Zdܐd݄ Zdސd߄ ZdS (  PrettyPrinterz?Printer, which converts an expression into 2D ASCII-art figure.Z_prettyNautoTplaini)
order	full_precuse_unicodeZ	wrap_linenum_columnsuse_unicode_sqrt_charroot_notationmat_symbol_styleimaginary_unitperm_cyclicc                 C   sX   t | | t| jd ts2td| jd n"| jd dvrTtd| jd d S )Nr3   z&'imaginary_unit' must a string, not {})r+   jz4'imaginary_unit' must be either 'i' or 'j', not '{}')r   __init__
isinstance	_settingsstr	TypeErrorformat
ValueError)selfsettings r?   J/var/www/auris/lib/python3.9/site-packages/sympy/printing/pretty/pretty.pyr6   /   s
    zPrettyPrinter.__init__c                 C   s   t t|S Nr   r9   r=   exprr?   r?   r@   emptyPrinter7   s    zPrettyPrinter.emptyPrinterc                 C   s   | j d rdS t S d S )Nr.   T)r8   r    r=   r?   r?   r@   _use_unicode:   s    
zPrettyPrinter._use_unicodec                 C   s   |  |jf i | jS rA   )_printrenderr8   rC   r?   r?   r@   doprintA   s    zPrettyPrinter.doprintc                 C   s   |S rA   r?   r=   er?   r?   r@   _print_stringPictE   s    zPrettyPrinter._print_stringPictc                 C   s   t |S rA   )r   rK   r?   r?   r@   _print_basestringH   s    zPrettyPrinter._print_basestringc                 C   s&   t | |j  }t |d }|S )Natan2)r   
_print_seqargsparensleftr=   rL   pformr?   r?   r@   _print_atan2K   s    zPrettyPrinter._print_atan2Fc                 C   s   t |j|}t|S rA   )r   namer   )r=   rL   Z	bold_nameZsymbr?   r?   r@   _print_SymbolP   s    zPrettyPrinter._print_Symbolc                 C   s   |  || jd dkS )Nr2   Zbold)rX   r8   rK   r?   r?   r@   _print_MatrixSymbolT   s    z!PrettyPrinter._print_MatrixSymbolc                 C   s,   | j d }|dkr| jdk}tt||dS )Nr-   r)      )r-   )r8   Z_print_levelr   r   )r=   rL   r-   r?   r?   r@   _print_FloatW   s    

zPrettyPrinter._print_Floatc                 C   s~   |j }|j}| |}t|d }t|d }t|| td }t|d }t|| | }t|d }|S )N()MULTIPLICATION SIGNZ_expr1Z_expr2rH   r   rS   rightr"   r=   rL   Zvec1Zvec2rU   r?   r?   r@   _print_Cross_   s    
zPrettyPrinter._print_Crossc                 C   s`   |j }| |}t|d }t|d }t|| td }t|| td }|S )Nr\   r]   r^   NABLAZ_exprrH   r   rS   r`   r"   r=   rL   ZvecrU   r?   r?   r@   _print_Curlk   s    
zPrettyPrinter._print_Curlc                 C   s`   |j }| |}t|d }t|d }t|| td }t|| td }|S )Nr\   r]   DOT OPERATORrc   rd   re   r?   r?   r@   _print_Divergencet   s    
zPrettyPrinter._print_Divergencec                 C   s~   |j }|j}| |}t|d }t|d }t|| td }t|d }t|| | }t|d }|S )Nr\   r]   rg   r_   ra   r?   r?   r@   
_print_Dot}   s    
zPrettyPrinter._print_Dotc                 C   sH   |j }| |}t|d }t|d }t|| td }|S )Nr\   r]   rc   rd   r=   rL   funcrU   r?   r?   r@   _print_Gradient   s    
zPrettyPrinter._print_Gradientc                 C   sH   |j }| |}t|d }t|d }t|| td }|S )Nr\   r]   Z	INCREMENTrd   rj   r?   r?   r@   _print_Laplacian   s    
zPrettyPrinter._print_Laplacianc                 C   s8   zt t|jj| dW S  ty2   | | Y S 0 d S )N)printer)r   r   	__class____name__KeyErrorrE   rK   r?   r?   r@   _print_Atom   s    zPrettyPrinter._print_Atomc                 C   s*   | j r| |S ddg}| |ddS d S )Nz-ooZoor\   r]   )rG   rr   rP   )r=   rL   Zinf_listr?   r?   r@   _print_Reals   s    
zPrettyPrinter._print_Realsc                 C   sD   |j d }| |}|jr |js2|js2t|  }t|d }|S Nr   !)rQ   rH   
is_Integeris_nonnegative	is_Symbolr   rR   rS   r=   rL   xrU   r?   r?   r@   _print_subfactorial   s    

z!PrettyPrinter._print_subfactorialc                 C   sD   |j d }| |}|jr |js2|js2t|  }t|d }|S rt   rQ   rH   rv   rw   rx   r   rR   r`   ry   r?   r?   r@   _print_factorial   s    

zPrettyPrinter._print_factorialc                 C   sD   |j d }| |}|jr |js2|js2t|  }t|d }|S )Nr   z!!r|   ry   r?   r?   r@   _print_factorial2   s    

zPrettyPrinter._print_factorial2c                 C   st   |j \}}| |}| |}dt| |  }t|| }t|| }t|dd }|jd d |_|S )N r\   r]   rZ      )rQ   rH   maxwidthr   aboverR   baseline)r=   rL   nkZn_pformZk_pformbarrU   r?   r?   r@   _print_binomial   s    


zPrettyPrinter._print_binomialc                 C   sL   t dt|j d }| |j}| |j}t t|||dt ji}|S )Nr   binding)	r   r   Zrel_oprH   lhsrhsr   nextOPENr=   rL   oplrrU   r?   r?   r@   _print_Relational   s
    zPrettyPrinter._print_Relationalc                 C   s   ddl m}m} | jr|jd }| |}t||rF| j|tddS t||rb| j	|tddS |j
rz|jszt|  }t|td S | |S d S )Nr   )
EquivalentImpliesZNotEquiv)altcharZNotArrowNot)Zsympy.logic.boolalgr   r   rG   rQ   rH   r7   _print_Equivalentr   _print_Implies
is_Booleanis_Notr   rR   rS   _print_Function)r=   rL   r   r   argrU   r?   r?   r@   
_print_Not   s    



zPrettyPrinter._print_Notc                 C   s   |j }|rt|j td}|d }| |}|jrB|jsBt|  }|dd  D ]F}| |}|jrt|jstt|  }t|d|  }t|| }qN|S )Nkeyr   rZ    %s )	rQ   sortedr   rH   r   r   r   rR   r`   )r=   rL   charsortrQ   r   rU   	pform_argr?   r?   r@   Z__print_Boolean   s    

zPrettyPrinter.__print_Booleanc                 C   s(   | j r| |tdS | j|ddS d S )NAndTr   rG   _PrettyPrinter__print_Booleanr   r   rK   r?   r?   r@   
_print_And  s    zPrettyPrinter._print_Andc                 C   s(   | j r| |tdS | j|ddS d S )NOrTr   r   rK   r?   r?   r@   	_print_Or  s    zPrettyPrinter._print_Orc                 C   s(   | j r| |tdS | j|ddS d S )NZXorTr   r   rK   r?   r?   r@   
_print_Xor  s    zPrettyPrinter._print_Xorc                 C   s(   | j r| |tdS | j|ddS d S )NZNandTr   r   rK   r?   r?   r@   _print_Nand  s    zPrettyPrinter._print_Nandc                 C   s(   | j r| |tdS | j|ddS d S )NZNorTr   r   rK   r?   r?   r@   
_print_Nor$  s    zPrettyPrinter._print_Norc                 C   s,   | j r| j||ptdddS | |S d S )NArrowFr   r   r=   rL   r   r?   r?   r@   r   *  s    zPrettyPrinter._print_Impliesc                 C   s,   | j r| ||ptdS | j|ddS d S )NZEquivTr   r   r   r?   r?   r@   r   0  s    zPrettyPrinter._print_Equivalentc                 C   s(   |  |jd }t|td|  S )Nr   _)rH   rQ   r   r   r   r   rT   r?   r?   r@   _print_conjugate6  s    zPrettyPrinter._print_conjugatec                 C   s$   |  |jd }t|dd }|S )Nr   |)rH   rQ   r   rR   rT   r?   r?   r@   
_print_Abs:  s    zPrettyPrinter._print_Absc                 C   s8   | j r*| |jd }t|dd }|S | |S d S )Nr   lfloorrfloorrG   rH   rQ   r   rR   r   rT   r?   r?   r@   _print_floor?  s
    zPrettyPrinter._print_floorc                 C   s8   | j r*| |jd }t|dd }|S | |S d S )Nr   lceilrceilr   rT   r?   r?   r@   _print_ceilingG  s
    zPrettyPrinter._print_ceilingc                 C   s  t |jr| jrtd}nd}d }d}t|jD ]p\}}| |}t|| }||7 }|j	rf|dkrv|tt
| }|d u r|}q0t|d }t|| }q0t| |j dtji}	t|}
|dkdkr|
tt
| }
t|
tj| }
|
jd |
_tt|
|	 }
tj|
_|
S )NPARTIAL DIFFERENTIALdr   rZ   r   r   F)r   rD   rG   r"   reversedZvariable_countrH   r   rS   rv   r9   r`   rR   FUNCbelowr   LINEr   r   MULr   )r=   derivderiv_symbolrz   Zcount_total_derivsymnumsdsfrU   r?   r?   r@   _print_DerivativeO  s8    

zPrettyPrinter._print_Derivativec                 C   s   ddl m}m} || kr.td}t|  S || j}|g kr`| |j	d }t|  S td}|D ],}| t
t|dd}t|| }ql|S )Nr   PermutationCycle rZ   ,) sympy.combinatorics.permutationsr   r   r   r   rR   listZcyclic_formrH   sizer9   tuplereplacer`   )r=   dcr   r   ZcycZdc_listr+   r   r?   r?   r@   _print_Cyclet  s    
zPrettyPrinter._print_Cyclec                 C   s   ddl m}m} |j}|d ur8td| ddddd n| jd	d
}|rX| ||S |j}t	t
t|}td}d
}t||D ]P\}	}
| |	}| |
}t|| }|rd}nt|d }t|| }qt|  S )Nr   r   zw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclic   )Zdeprecated_since_versionZactive_deprecations_target
stacklevelr4   Tr   Fr   )r   r   r   Zprint_cyclicr   r8   getr   Z
array_formr   rangelenr   ziprH   r   r   rS   r`   rR   )r=   rD   r   r   r4   lowerupperresultfirstur   s1s2colr?   r?   r@   _print_Permutation  s6    


z PrettyPrinter._print_Permutationc                 C   s  |j }| |}|jr"t|  }|}|jD ]:}| |d }| dkrVt|  }t|d| }q,d}d }|jD ]D}	| }
|
d }| j	 }|r|d7 }t
d|}t|}|j||
 d  |_t|	dkrt|	dkrtd}| |	d }t|	dkr | |	d }| |	d }|rntdd|  }t|d	|  }tdd
|  }t|d	|  }t|| }t|| }|st|d	 }|r|}d}qvt|| }qvt|| }tj|_|S )Nr   rZ   z dTr   intr      r      F)functionrH   is_Addr   rR   limitsr   r`   heightrG   r   r   r   r   rS   r   r   r   r   )r=   Zintegralr   prettyFr   rz   Z	prettyArgZ	firsttermr   limhH
ascii_modeZvintrU   ZprettyAZprettyBZspcr?   r?   r@   _print_Integral  s\    


zPrettyPrinter._print_Integralc                 C   s  |j }| |}tdd}tdd}tdd}| jrHtdd}tdd}| }d}d}	d}
|jD ]}| |\}}|d d	 d
 d }|| ||d   | | g}t|d D ]&}|d| d|d   | d  qt	d}t
|j|  }t|	| }	|r| }
t
|| }t
|| }|r:d|_d}| }t	d}t
|jdg|d    }t
|| }t
|| }qb|	|
d  |_t
j|_|S )Nr   rZ   r   -ZUpTackTr   r      r   r   r   F)termrH   r   rG   r   r   '_PrettyPrinter__print_SumProduct_Limitsr   appendr   r   stackr   r   r   r   r`   r   r   )r=   rD   rk   Zpretty_funcZhorizontal_chrZ
corner_chrZvertical_chrZfunc_heightr   	max_uppersign_heightr   Zpretty_lowerZpretty_upperr   Z
sign_linesr   Zpretty_signr   paddingr?   r?   r@   _print_Product  sH    





$zPrettyPrinter._print_Productc                    s4    fdd}  |d }||d |d }||fS )Nc                    s>   t dtd d } | } |}t t||| }|S )Nr   ==)r   r   rH   r   r   )r   r   r   r   r   rU   rF   r?   r@   print_start.  s
    

z<PrettyPrinter.__print_SumProduct_Limits.<locals>.print_startr   r   rZ   rH   )r=   r   r   prettyUpperprettyLowerr?   rF   r@   Z__print_SumProduct_Limits-  s    z'PrettyPrinter.__print_SumProduct_Limitsc                 C   sZ  | j  }dd }|j}| |}|jr2t|  }| d }d}d}d}	|jD ]}
| |
\}}t	|| }|||
 |
 |\}}}}td}t|j|  }|r| }	t|| }t|| }|r| j|| d |j  8  _d}td}t|jdg|   }t|| }t|| }qP|s8|nd}||	d  | |_tj|_|S )	Nc              	   S   s  ddd}t | d}|d }|d }| d }g }	|r
|	d| d  |	dd|d    td|D ]"}
|	d	d|
 d||
  f  qh|r|	d
d| d||  f  ttd|D ]"}
|	dd|
 d||
  f  q|	dd|d   d  ||| |	|fS || }|| }tdd}|	d|  td|D ].}
|	dd|
 |d d||
 d  f  q<ttd|D ].}
|	dd|
 |d d||
 d  f  qz|	|d |  ||d|  |	|fS d S )N<^>c                 S   s|   |rt | |kr| S |t |  }|dv s4|tdvr@| d|  S |d }d| }|dkrdd| |  S ||  d|t |   S )N)r  <r  r   r   >)r   r   )r   ZwidhowZneedZhalfZleadr?   r?   r@   adjust=  s    z6PrettyPrinter._print_Sum.<locals>.asum.<locals>.adjustr   rZ   r   r   z\%s`z%s\%sz%s)%sz%s/%s/r   sumr   r   z%s%s%s   )Nr  )r   r   r   r   r   )Z	hrequiredr   r   Z	use_asciir  r   r   wZmorelinesr+   Zvsumr?   r?   r@   asum<  s6    

  
,,z&PrettyPrinter._print_Sum.<locals>.asumr   Tr   r   Fr   )rG   r   rH   r   r   rR   r   r   r   r   r   r   r   r   r   r   r`   r   r   )r=   rD   r   r  r   r   r   r   r   r   r   r  r   r   r   ZslinesZ
adjustmentZ
prettySignpadZascii_adjustmentr?   r?   r@   
_print_Sum9  sF    *


zPrettyPrinter._print_Sumc           	      C   s  |j \}}}}| |}t|td kr8t|dd }td}| |}| jrrt|tdd t	d  }nt|d }t|| | }t
|d	ks|tjtjfv rd
}n"| jrt
|dkrt	dnt	d}t|| | }t|| }t||dtji}|S )Nr   r\   r]   r   r   rZ   r   z->z+-r   +ZSuperscriptPlusZSuperscriptMinusr   )rQ   rH   r   r   r   rR   rG   r`   r   r   r9   r   InfinityNegativeInfinityr   r   )	r=   r   rL   zZz0dirEZLimZLimArgr?   r?   r@   _print_Limit  s$    

"zPrettyPrinter._print_Limitc                    s  |}i  t |jD ].}t |jD ]| ||f  |f< q qd}d}dg|j }t |jD ],t fddt |jD pdg|< q`d}t |jD ]}d}t |jD ] |f }	|	 | ksJ t|	 | \}
}t|	| }	t|		|
 }	|du r|	}qt|d|  }t||	 }q|du rF|}qt |D ]}t|
d }qNt|
| }q|du rtd	}|S )
zL
        This method factors out what is essentially grid printing.
        r   rZ   c                    s   g | ]} |f   qS r?   r   .0r+   ZMsr5   r?   r@   
<listcomp>      z8PrettyPrinter._print_matrix_contents.<locals>.<listcomp>r   Nr   r   )r   rowscolsrH   r   r   r&   r   r`   rS   r   )r=   rL   Mr+   hsepvsepmaxwDD_rowr   rS   r`   r   r?   r  r@   _print_matrix_contents  sB    *


z$PrettyPrinter._print_matrix_contents[]c                 C   s,   |  |}| d |_t||| }|S )Nr   )r%  r   r   r   rR   )r=   rL   lparensrparensr#  r?   r?   r@   _print_MatrixBase  s    
zPrettyPrinter._print_MatrixBasec                 C   sp   |j }|jr\ddlm} t||r4| j|jdddS | |}| d |_	t
|dd S | j|dddS d S )Nr   BlockMatrixr   )r(  r)  r   )r   is_MatrixExpr&sympy.matrices.expressions.blockmatrixr,  r7   r*  blocksrH   r   r   r   rR   )r=   rL   matr,  r#  r?   r?   r@   _print_Determinant  s    

z PrettyPrinter._print_Determinantc                 C   s*   | j rd}nd}| j|jd d |dd dS )Nu   ⊗.*c                 S   s   t | td kS Nr   r   r   rz   r?   r?   r@   <lambda>  r  z4PrettyPrinter._print_TensorProduct.<locals>.<lambda>parenthesizerG   rP   rQ   )r=   rD   Zcircled_timesr?   r?   r@   _print_TensorProduct  s    z"PrettyPrinter._print_TensorProductc                 C   s*   | j rd}nd}| j|jd d |dd dS )Nu   ∧z/\c                 S   s   t | td kS r3  r4  r5  r?   r?   r@   r6    r  z3PrettyPrinter._print_WedgeProduct.<locals>.<lambda>r7  r9  )r=   rD   Zwedge_symbolr?   r?   r@   _print_WedgeProduct  s    z!PrettyPrinter._print_WedgeProductc                 C   s<   |  |j}t|dd }| d |_t|d }|S )Nr\   r]   r   tr)rH   r   r   rR   r   r   rS   )r=   rL   r#  r?   r?   r@   _print_Trace  s
    zPrettyPrinter._print_Tracec                 C   s   ddl m} t|j|rJ|jjrJ|jjrJ| t|jj	d|j|jf  S | |j}t
|  }| j|j|jfddjdddd }t
t||d	t
ji}||_||_|S d S )
Nr   MatrixSymbolz_%d%d, 	delimiterr&  r'  rS   r`   r   )sympy.matricesr?  r7   parentr+   Z	is_numberr5   rH   r   rW   r   rR   rP   r   r   r   
prettyFunc
prettyArgs)r=   rD   r?  rF  ZprettyIndicesrU   r?   r?   r@   _print_MatrixElement%  s,    
z"PrettyPrinter._print_MatrixElementc                    s   ddl m}  |j}t|j|s0t|  } fdd} j||j|jj	||j
|jjfddjddd	d }tt||d
tji}||_||_|S )Nr   r>  c                    sT   t | } | d dkr| d= | d dkr.d| d< | d |krBd| d< t j| dd S )Nr   rZ   r   r   :rA  )r   r   rP   )rz   ZdimrF   r?   r@   ppslice@  s    z1PrettyPrinter._print_MatrixSlice.<locals>.ppslicer@  rA  r&  r'  rC  r   )rD  r?  rH   rE  r7   r   rR   rP   Zrowslicer  Zcolslicer  r   r   r   rF  rG  )r=   mr?  rF  rJ  rG  rU   r?   rF   r@   _print_MatrixSlice:  s,    	
z PrettyPrinter._print_MatrixSlicec                 C   sV   |j }| |}ddlm}m} t||sFt||sF|jrFt|  }|td }|S )Nr   r?  r,  T)	r   rH   rD  r?  r,  r7   r-  r   rR   )r=   rD   r0  rU   r?  r,  r?   r?   r@   _print_TransposeU  s    

zPrettyPrinter._print_Transposec                 C   sn   |j }| |}| jr$ttd}ntd}ddlm}m} t||sbt||sb|j	rbt|
  }|| }|S )NDaggerr  r   rM  )r   rH   rG   r   r   rD  r?  r,  r7   r-  rR   )r=   rD   r0  rU   Zdagr?  r,  r?   r?   r@   _print_Adjoint_  s    

zPrettyPrinter._print_Adjointc                 C   s(   |j jdkr| |j d S | |j S )NrZ   rZ   r   r   )r/  shaperH   )r=   Br?   r?   r@   _print_BlockMatrixm  s    z PrettyPrinter._print_BlockMatrixc                 C   s   d }|j D ]p}| |}|d u r&|}q
| d }t| rZtt|d }| |}ntt|d }tt|| }q
|S )Nr   r    + )rQ   rH   Zas_coeff_mmulr   could_extract_minus_signr   r   r   )r=   rD   r   itemrU   coeffr?   r?   r@   _print_MatAddr  s    

zPrettyPrinter._print_MatAddc                 C   s   t |j}ddlm} ddlm} ddlm} t|D ]N\}}t	|t
|||frvt|jdkrvt| |  ||< q6| |||< q6tj| S )Nr   HadamardProduct)KroneckerProductMatAddrZ   )r   rQ   #sympy.matrices.expressions.hadamardr]  Z$sympy.matrices.expressions.kroneckerr^  !sympy.matrices.expressions.mataddr`  	enumerater7   r   r   r   rH   rR   __mul__)r=   rD   rQ   r]  r^  r`  r+   ar?   r?   r@   _print_MatMul  s    
zPrettyPrinter._print_MatMulc                 C   s   | j rttdS tdS d S )NZIdentityMatrixIrG   r   r   rC   r?   r?   r@   _print_Identity  s    zPrettyPrinter._print_Identityc                 C   s   | j rttdS tdS d S )NZ
ZeroMatrix0rh  rC   r?   r?   r@   _print_ZeroMatrix  s    zPrettyPrinter._print_ZeroMatrixc                 C   s   | j rttdS tdS d S )NZ	OneMatrix1rh  rC   r?   r?   r@   _print_OneMatrix  s    zPrettyPrinter._print_OneMatrixc                 C   s4   t |j}t|D ]\}}| |||< qtj| S rA   )r   rQ   rc  rH   r   rd  r=   rD   rQ   r+   re  r?   r?   r@   _print_DotProduct  s    
zPrettyPrinter._print_DotProductc                 C   sL   |  |j}ddlm} t|j|s8|jjr8t|  }||  |j }|S )Nr   r>  )	rH   baserD  r?  r7   r-  r   rR   exp)r=   rD   rU   r?  r?   r?   r@   _print_MatPow  s    zPrettyPrinter._print_MatPowc                    sZ   ddl m  ddlm ddlm | jr4td}nd}| j|j	d d | fddd	S )
Nr   r\  r_  MatMulRingr2  c                    s   t |  fS rA   r7   r5  r]  r`  rt  r?   r@   r6    r  z6PrettyPrinter._print_HadamardProduct.<locals>.<lambda>r7  )
ra  r]  rb  r`  !sympy.matrices.expressions.matmulrt  rG   r   rP   rQ   r=   rD   delimr?   rw  r@   _print_HadamardProduct  s    
z$PrettyPrinter._print_HadamardProductc                 C   sp   | j rtd}n
| d}| |j}| |j}t|jtd k rPt|  }tt	
||dtji}|| S )Nru  .r   r   )rG   r   rH   rp  rq  r   r   r   rR   r   r   r   )r=   rD   circZpretty_baseZ
pretty_expZpretty_circ_expr?   r?   r@   _print_HadamardPower  s    


z"PrettyPrinter._print_HadamardPowerc                    sT   ddl m  ddlm | jr0dtd d}nd}| j|jd d | fddd	S )
Nr   r_  rs  r   ZTensorProductz x c                    s   t |  fS rA   rv  r5  r`  rt  r?   r@   r6    r  z7PrettyPrinter._print_KroneckerProduct.<locals>.<lambda>r7  )rb  r`  rx  rt  rG   r   rP   rQ   ry  r?   r  r@   _print_KroneckerProduct  s    z%PrettyPrinter._print_KroneckerProductc                 C   s"   |  |jj}t|dd }|S Nr&  r'  )rH   lamdarD   r   rR   )r=   Xr#  r?   r?   r@   _print_FunctionMatrix  s    z#PrettyPrinter._print_FunctionMatrixc                 C   sT   |j dks:|j |j }}t|t|ddddd}| |S | d| |j S d S )NrZ   r  Fevaluate)r   denr   r
   
_print_MulrH   )r=   rD   r   r  resr?   r?   r@   _print_TransferFunction  s
    

z%PrettyPrinter._print_TransferFunctionc                 C   s>   t |j}t|jD ]\}}t| |  ||< qtj| S rA   )r   rQ   rc  r   rH   rR   rd  rn  r?   r?   r@   _print_Series  s    
zPrettyPrinter._print_Seriesc                 C   s   ddl m} t|j}g }t|D ]j}t||rjt|jdkrj| |}| d |_	|
t|   q"| |}| d |_	|
| q"tj| S )Nr   )MIMOParallelrZ   r   )sympy.physics.control.ltir  r   rQ   r   r7   r   rH   r   r   r   r   rR   rd  )r=   rD   r  rQ   Zpretty_argsre  Z
expressionr?   r?   r@   _print_MIMOSeries  s    


zPrettyPrinter._print_MIMOSeriesc                 C   sh   d }|j D ]X}| |}|d u r&|}q
tt| }| d |_tt|d }tt|| }q
|S )Nr   rW  )rQ   rH   r   r   r   r   r   )r=   rD   r   rY  rU   r?   r?   r@   _print_Parallel  s    

zPrettyPrinter._print_Parallelc                 C   s   ddl m} d }|jD ]p}| |}|d u r2|}qtt| }| d |_tt|d }t	||rv| d |_tt|| }q|S )Nr   )TransferFunctionMatrixr   rW  rZ   )
r  r  rQ   rH   r   r   r   r   r   r7   )r=   rD   r  r   rY  rU   r?   r?   r@   _print_MIMOParallel  s    


z!PrettyPrinter._print_MIMOParallelc           
      C   s  ddl m}m} |j|dd|j }}t||r:t|jn|g}t|j|rXt|jjn|jg}t||rt|j|r|g ||R  }nt||rt|j|r|j|kr|| }n|g ||jR  }nzt||rt|j|r||kr|| }n||g|R  }n<||kr|| }n(|j|kr2|| }n|g ||R  }t	t
| | }	|	 d |	_|jdkrt	t
|	d nt	t
|	d }	t	t
|	| | }	| ||	 S )Nr   )TransferFunctionSeriesrZ   r   r  rW   - )sympy.physics.controlr  r  sys1varr7   r   rQ   sys2r   r   r   rH   r   r   sign)
r=   rD   r  r  r   tfZnum_arg_listZden_arg_listr  Zdenomr?   r?   r@   _print_Feedback  s:    






zPrettyPrinter._print_Feedbackc                 C   s   ddl m}m} | ||j|j}| |j}tt| }|j	dkrXtt
d| ntt
d| }tt| }d|_tt
|d }| d |_t|td}t|j|r| d	 |_tt|| }|S )
Nr   )
MIMOSeriesr  r  zI + zI - z-1 r   r   rZ   )r  r  r  rH   r  r  r   r   r   r  r`   rR   r   r   rd  r7   )r=   rD   r  r  Zinv_matZplantZ	_feedbackr?   r?   r@   _print_MIMOFeedback;  s     z!PrettyPrinter._print_MIMOFeedbackc                 C   s>   |  |j}| d |_| jr(td nd}t|| }|S )NrZ   tauz{t})rH   Z	_expr_matr   r   rG   r!   r   r`   )r=   rD   r0  	subscriptr?   r?   r@   _print_TransferFunctionMatrixM  s
    z+PrettyPrinter._print_TransferFunctionMatrixc                 C   sD   ddl m} |j}|j}|j}|j}|||g||gg}| |jS )Nr   r+  )r.  r,  Z_AZ_BZ_CZ_DrH   r/  )r=   rD   r,  ArU  Cr#  r0  r?   r?   r@   _print_StateSpaceT  s    zPrettyPrinter._print_StateSpacec                 C   sJ  ddl m} | jstd||jkr0t|jjS g }g }t||rP| 	 }n
d|fg}|D ]\}}t
|j	 }|jdd d |D ]n\}	}
|
dkr|d|	j  n@|
d	kr|d
|	j  n&| |
 d }||d |	j  ||	j qq^|d dr |d dd  |d< n$|d drD|d dd  |d< g }dg}g }t|D ]*\}}|d d|v rZ|}||| d}tdd|v rtt|D ]l}d||< || tddkr||d  dkr|d | tdd d ||  ||d d   } q|qndtdd|v r||tdd}|d	kr|d||< |d | tdd d ||  ||d d   }|||< qZdd |D }tdd |D }d|v rt|D ]8\}}t|dkr|ddt|d   d||< qt|D ]2\}}|t|||   t|D ]}|d t|kr|t|krt|dt|d d	 dt|d     ||| kr|||   |||  d 7  < n0||  || d|d	 t||  d   7  < nT|t|kr|dt|d d	 dt|d     ||  d|d	 d  7  < q$qtddd |D S )Nr   )Vectorz:ASCII pretty printing of BasisDependent is not implementedc                 S   s   | d   S Nr   )__str__r5  r?   r?   r@   r6  m  r  z5PrettyPrinter._print_BasisDependent.<locals>.<lambda>r   rZ   r   r  z(-1) r   rW  r   
z)_extz)_lower_hookc                 S   s   g | ]}| d qS )r  )splitr  rz   r?   r?   r@   r    r  z7PrettyPrinter._print_BasisDependent.<locals>.<listcomp>c                 s   s   | ]}t |V  qd S rA   )r   r  r?   r?   r@   	<genexpr>  r  z6PrettyPrinter._print_BasisDependent.<locals>.<genexpr>c                 S   s   g | ]}|d d qS )Nr?   )r  r   r?   r?   r@   r    r  )Zsympy.vectorr  rG   NotImplementedErrorZzeror   Z_pretty_formr7   Zseparateitemsr   
componentsr   r   rH   rR   
startswithrc  r   r   r   r   rfindr   insertr  join)r=   rD   r  Zo1Zvectstrsr  systemZvectZ
inneritemsr   vZarg_strlengthsstrsflagr+   ZpartstrZtempstrZparenindexZ
n_newlinespartsr5   r?   r?   r@   _print_BasisDependent]  s    




&

"
$z#PrettyPrinter._print_BasisDependentc           	         sh  ddl m  | dkr&| |d S g gdd t| D  }dd |jD } fdd}tj| D ]}|d	 ||  d
}t| d d	d	D ]}t	||d  |j| k r qh|r|| ||d   nL|| |||d   t	||d  dkr ||| d	 gg|| d	< | }g ||d < qqh|d d }| d dkr^||g}| |S )Nr   ImmutableMatrixr?   c                 S   s   g | ]}g qS r?   r?   r  r?   r?   r@   r    r  z2PrettyPrinter._print_NDimArray.<locals>.<listcomp>c                 S   s   g | ]}t t|qS r?   )r   r   r  r?   r?   r@   r    r  c                    s    | ddS )NFr  r?   r5  r  r?   r@   r6    r  z0PrettyPrinter._print_NDimArray.<locals>.<lambda>r  TrZ   r   )
Zsympy.matrices.immutabler  rankrH   r   rT  	itertoolsproductr   r   )	r=   rD   Z	level_strZshape_rangesr0  Zouter_iZevenZback_outer_iZout_exprr?   r  r@   _print_NDimArray  s6    


zPrettyPrinter._print_NDimArrayc              	   C   sj  t |}t d|  }t d|  }d }d }|D ]}	| |	jd }
|	|v sV|r||	jkr|	jrxtt |d }ntt |d }|	|v rtt |
d }
tt |
| ||	  }
d}nd}|	jrt ||
 }t |d|
   }t |d|
   }n:t ||
 }t |d|
   }t |d|
   }|	j}q4t|| }t|	| }|S )Nr   r   r   =TF)
r   r   rH   rQ   is_upr   r   r`   r   r   )r=   rW   indices	index_mapcentertopbotZlast_valenceZprev_mapr  ZindpicZpictr?   r?   r@   _printer_tensor_indices  s6    
z%PrettyPrinter._printer_tensor_indicesc                 C   s    |j d j}| }| ||S r  )rQ   rW   get_indicesr  )r=   rD   rW   r  r?   r?   r@   _print_Tensor  s    zPrettyPrinter._print_Tensorc                 C   s,   |j jd j}|j  }|j}| |||S r  )rD   rQ   rW   r  r  r  )r=   rD   rW   r  r  r?   r?   r@   _print_TensorElement  s    
z"PrettyPrinter._print_TensorElementc                    sB   |  \}} fdd|D }tj| }|r:t|| S |S d S )Nc                    s8   g | ]0}t |td  k r*t |  n |qS r   r   r   r   rH   rR   r  rF   r?   r@   r    s   z0PrettyPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr   rd  rS   )r=   rD   r  rQ   rU   r?   rF   r@   _print_TensMul  s    

zPrettyPrinter._print_TensMulc                    s    fdd|j D }tj| S )Nc                    s8   g | ]0}t |td  k r*t |  n |qS r   r  r  rF   r?   r@   r     s   z0PrettyPrinter._print_TensAdd.<locals>.<listcomp>)rQ   r   __add__)r=   rD   rQ   r?   rF   r@   _print_TensAdd  s    
zPrettyPrinter._print_TensAddc                 C   s    |j d }|js| }| |S r  )rQ   r  rH   )r=   rD   r   r?   r?   r@   _print_TensorIndex'  s    
z PrettyPrinter._print_TensorIndexc           	      C   s   | j rtd}nd}d }t|jD ]F}| |}t|| }|d u rL|}q"t|d }t|| }q"t| |j	 dtj
i}t|}t|jdkr|| t|j }t|tj| }|jd |_tt|| }tj|_|S )Nr   r   r   r   rZ   )rG   r"   r   	variablesrH   r   rS   r`   rD   rR   r   r   r   r   r   r   r   r   r   )	r=   r   r   rz   variabler   r   r   rU   r?   r?   r@   _print_PartialDerivative-  s0    

z&PrettyPrinter._print_PartialDerivativec                    s  i  t |jD ]Z\}}| |j |df< |jdkrFtd |df< qttd| |j  |df< qd}d}t|j fddtdD }d }tD ]}d }	tdD ]}
 ||
f }|	 ||
 ksJ ||
 |	  }|d }|| }t|d	|  }t|
d	|  }|	d u r(|}	qt|	d	|  }	t|	| }	q|d u rZ|	}qt|D ]}t|d	 }qbt||	 }qt|d
d }| d |_tj|_|S )Nr   TZ	otherwiserZ   zfor r   c                    s(   g | ]  t  fd dtD qS )c                 3   s   | ]} |f   V  qd S rA   r  r  )Pr5   r?   r@   r  \  r  z<PrettyPrinter._print_Piecewise.<locals>.<listcomp>.<genexpr>)r   r   r  r  Zlen_args)r5   r@   r  \  s   z2PrettyPrinter._print_Piecewise.<locals>.<listcomp>r   {r   )rc  rQ   rH   rD   condr   r`   r   r   r   rS   r   rR   r   r   r   r   )r=   Zpexprr   Zecr   r!  r"  r#  r+   r$  r5   pZwdeltaZwleftZwrightr   r?   r  r@   _print_PiecewiseM  sP    



zPrettyPrinter._print_Piecewisec                 C   s   ddl m} | ||S )Nr   )	Piecewise)Z$sympy.functions.elementary.piecewiser  rH   Zrewrite)r=   Ziter  r?   r?   r@   
_print_ITE  s    zPrettyPrinter._print_ITEc                 C   sP   d }|D ]2}|}|d u r|}qt |d }t || }q|d u rLtd}|S )Nr@  r   )r   r`   r   )r=   r  r#  re  r  r?   r?   r@   _hprint_vec  s    zPrettyPrinter._hprint_vecr   c           	      C   sj   |r$| j s$| j|d|f|||ddS | j||f|||d}ttd| |jd}| j|||f|||dS )Nr   T)rS   r`   rB  ifascii_nougly)rS   r`   rB  r   )rG   rP   r   r   r   r   )	r=   p1p2rS   r`   rB  r  tmpsepr?   r?   r@   _hprint_vseparator  s    
z PrettyPrinter._hprint_vseparatorc                    s   fdd|j D } fdd|jD } |j}| d |_d }||fD ]8} |}|d u rj|}qNt|d }t|| }qN| d |_t|	d }t|
d } ||}t|dd }| d d }| | d }	td	\}
}}}}td
||  | d
|	|   ||
 d}|
d d }t|	 t|j  }t|
 t|j }|| |_t|
d| }|S )Nc                    s   g | ]}  |qS r?   r   r  re  rF   r?   r@   r    r  z.PrettyPrinter._print_hyper.<locals>.<listcomp>c                    s   g | ]}  |qS r?   r   r  brF   r?   r@   r    r  r   r   r\   r]   rZ   Fr  r  )apbqrH   argumentr   r   r  r   r   rS   r`   r  rR   r$   r   )r=   rL   r  r  r  r#  r  r$  r   r   sztr  addimgr  r?   rF   r@   _print_hyper  s8    

zPrettyPrinter._print_hyperc                     s  i } fdd|j D |d<  fdd|jD |d<  fdd|jD |d<  fdd|jD |d	<  |j}| d
 |_i }|D ]} || ||< qt	d
D ]}t
|d|f  |d|f  }t	d
D ]`}|||f }	||	  d
 }
||
 |	  }t|	d|
  }	t|	d|  }	|	|||f< qqt|d d|d  }t|d }t|d d|d	  }t|| }| d
 |_t|d }t|d } ||}t|dd }| d
 d }| | d }td\}}}}}td||  | d||   || d} t|j} t|j} t|j} t|j }dd }|||\}}|||\}}t|d| }t|d| }|j| d
 }|dkrt|d|  }t|| }||_t|| }|| |_t|d| }|S )Nc                    s   g | ]}  |qS r?   r   r  rF   r?   r@   r    r  z0PrettyPrinter._print_meijerg.<locals>.<listcomp>rS  c                    s   g | ]}  |qS r?   r   r  rF   r?   r@   r    r  )r   rZ   c                    s   g | ]}  |qS r?   r   r  rF   r?   r@   r    r  )rZ   r   c                    s   g | ]}  |qS r?   r   r  rF   r?   r@   r    r  rR  r   r   rZ   r   z  r\   r]   Gr  r  c                 S   sZ   |   |   }|dkr | |fS |dkr>| t|d|  fS t| d|   |fS d S )Nr   r   )r   r   rS   )r  r  diffr?   r?   r@   r  
  s    z,PrettyPrinter._print_meijerg.<locals>.adjustr@  )anZaotherZbmZbotherrH   r  r   r   r  r   r   r   r   rS   r`   r   r  rR   r$   r   r  r  ) r=   rL   r  r  Zvpidxr+   r"  r5   r   rS   r`   ZD1ZD2r#  r   r   r  r  r  r  r  r  ppZpqZpmZpnr  ZpuplZhtr  r?   rF   r@   _print_meijerg  sh    "

zPrettyPrinter._print_meijergc                 C   s"   t tdd}|| |jd  S )NExp1rL   r   )r   r   rH   rQ   )r=   rL   rp  r?   r?   r@   _print_ExpBase%  s    zPrettyPrinter._print_ExpBasec                 C   s   t tddS )Nr  rL   )r   r   rK   r?   r?   r@   _print_Exp1+  s    zPrettyPrinter._print_Exp1r\   r]   c                 C   s   | j |j|j||||dS )N)r   	func_namerS   r`   )_helper_print_functionrk   rQ   )r=   rL   r   r  rS   r`   r?   r?   r@   r   .  s    zPrettyPrinter._print_Functionc                 C   s   | j |ddS Nr  r  r   rK   r?   r?   r@   _print_mathieuc4  s    zPrettyPrinter._print_mathieucc                 C   s   | j |ddS Nr   r  r  rK   r?   r?   r@   _print_mathieus7  s    zPrettyPrinter._print_mathieusc                 C   s   | j |ddS )NzC'r  r  rK   r?   r?   r@   _print_mathieucprime:  s    z"PrettyPrinter._print_mathieucprimec                 C   s   | j |ddS )NzS'r  r  rK   r?   r?   r@   _print_mathieusprime=  s    z"PrettyPrinter._print_mathieusprimer@  c	                 C   s   |rt |td}|s$t|dr$|j}|r8| t|}	nt| |  }	|r| jr^t	d}
nd}
| |
}
tt
|	|
dtji}	t| j||dj||d }tt
|	|dtji}|	|_||_|S )Nr   rp   zModifier Letter Low Ringr|  r   rA  rC  )r   r   hasattrrp   rH   r   r   rR   rG   r   r   r   r   rP   r   rF  rG  )r=   rk   rQ   r   r  rB  elementwiserS   r`   rF  r}  rG  rU   r?   r?   r@   r  @  s8    



z$PrettyPrinter._helper_print_functionc                 C   s$   |j }|j}|g}| j||dddS )Nr   T)rB  r  )r   rD   r  )r=   rL   rk   r   rQ   r?   r?   r@   _print_ElementwiseApplyFunctione  s    z-PrettyPrinter._print_ElementwiseApplyFunctionc                 C   s   ddl m} ddlm}m} ddlm} ddlm} ddl	m
} ddlm} |td dg|td	 d	g|td
 dg|td dg|td dg|td dg|ddgiS )Nr   )KroneckerDelta)gamma
lowergamma)lerchphi)beta)
DiracDelta)ChideltaGammaPhir  r	  BetarU  r  )Z(sympy.functions.special.tensor_functionsr  Z'sympy.functions.special.gamma_functionsr	  r
  Z&sympy.functions.special.zeta_functionsr  Z&sympy.functions.special.beta_functionsr  Z'sympy.functions.special.delta_functionsr  Z'sympy.functions.special.error_functionsr  r!   )r=   r  r	  r
  r  r  r  r  r?   r?   r@   _special_function_classesk  s    z'PrettyPrinter._special_function_classesc                 C   sf   | j D ]L}t||r|j|jkr| jr<t| j | d   S t| j | d   S q|j}tt|S )Nr   rZ   )r  
issubclassrp   rG   r   r   )r=   rD   clsr  r?   r?   r@   _print_FunctionClass{  s    
z"PrettyPrinter._print_FunctionClassc                 C   s
   |  |S rA   )rE   rC   r?   r?   r@   _print_GeometryEntity  s    z#PrettyPrinter._print_GeometryEntityc                 C   sD   |  |jd }| jr:t|r:| td| |jd S | |S )Nr   zLi_%srZ   rH   rQ   rG   r%   r   r   r=   rL   r  r?   r?   r@   _print_polylog  s    zPrettyPrinter._print_polylogc                 C   s    | j rtd nd}| j||dS )Nr  r  r  rG   r!   r   r=   rL   r  r?   r?   r@   _print_lerchphi  s    zPrettyPrinter._print_lerchphic                 C   s    | j rtd nd}| j||dS )NetaZdirichlet_etar  r  r  r?   r?   r@   _print_dirichlet_eta  s    z"PrettyPrinter._print_dirichlet_etac                 C   s^   | j rtd nd}|jd tju rLt| |jd   }t|| }|S | j	||dS d S )NthetaZ	HeavisiderZ   r   r  )
rG   r!   rQ   r   ZHalfr   rH   rR   rS   r   )r=   rL   r  rU   r?   r?   r@   _print_Heaviside  s    zPrettyPrinter._print_Heavisidec                 C   s   | j |ddS r  r  rK   r?   r?   r@   _print_fresnels  s    zPrettyPrinter._print_fresnelsc                 C   s   | j |ddS r  r  rK   r?   r?   r@   _print_fresnelc  s    zPrettyPrinter._print_fresnelcc                 C   s   | j |ddS )NZAir  r  rK   r?   r?   r@   _print_airyai  s    zPrettyPrinter._print_airyaic                 C   s   | j |ddS )NZBir  r  rK   r?   r?   r@   _print_airybi  s    zPrettyPrinter._print_airybic                 C   s   | j |ddS )NzAi'r  r  rK   r?   r?   r@   _print_airyaiprime  s    z PrettyPrinter._print_airyaiprimec                 C   s   | j |ddS )NzBi'r  r  rK   r?   r?   r@   _print_airybiprime  s    z PrettyPrinter._print_airybiprimec                 C   s   | j |ddS )NWr  r  rK   r?   r?   r@   _print_LambertW  s    zPrettyPrinter._print_LambertWc                 C   s   | j |ddS )NZCovr  r  rK   r?   r?   r@   _print_Covariance  s    zPrettyPrinter._print_Covariancec                 C   s   | j |ddS )NZVarr  r  rK   r?   r?   r@   _print_Variance  s    zPrettyPrinter._print_Variancec                 C   s   | j |ddS )Nr  r  r  rK   r?   r?   r@   _print_Probability  s    z PrettyPrinter._print_Probabilityc                 C   s   | j |ddddS )Nr  r&  r'  )r  rS   r`   r  rK   r?   r?   r@   _print_Expectation  s    z PrettyPrinter._print_Expectationc                 C   sn   |j }|j}| jr$dtd d}nd}t|dkrF|d jrF|d }| |}tt	||| |ddiS )Nr   ZArrowFromBar -> rZ   r   r   r	  )
rD   	signaturerG   r   r   Z	is_symbolrH   r   r   r   )r=   rL   rD   sigarrowZvar_formr?   r?   r@   _print_Lambda  s    
zPrettyPrinter._print_Lambdac                 C   s  |  |j}|jr&tdd |jD s4t|jdkrt|d }t|jdkrht||  |j }n$t|jrt||  |jd  }| jrt|dt	d d }nt|d }t|jdkrt||  |j }nt||  |jd  }t|
  }t|d	 }|S )
Nc                 s   s   | ]}|t jkV  qd S rA   )r   Zero)r  r  r?   r?   r@   r    r  z-PrettyPrinter._print_Order.<locals>.<genexpr>rZ   ; r   r   r   r.  O)rH   rD   pointanyr   r  r   r`   rG   r   rR   rS   r=   rD   rU   r?   r?   r@   _print_Order  s$    
zPrettyPrinter._print_Orderc                 C   s   | j r`| |jd |jd  }| |jd }td}t|| }t|d }|| }|S | |jd }| |jd |jd  }| |ddd}|| S d S )Nr   rZ   r   r  r  r   )rG   rH   rQ   r   r`   rP   )r=   rL   shiftr   rp  rU   r?   r?   r@   _print_SingularityFunction  s    z(PrettyPrinter._print_SingularityFunctionc                 C   s    | j rtd nd}| j||dS )Nr  rU  r  r  r  r?   r?   r@   _print_beta  s    zPrettyPrinter._print_betac                 C   s   d}| j ||dS )NzB'r  r  r  r?   r?   r@   _print_betainc  s    zPrettyPrinter._print_betaincc                 C   s   d}| j ||dS )Nrg  r  r  r  r?   r?   r@   _print_betainc_regularized  s    z(PrettyPrinter._print_betainc_regularizedc                 C   s    | j rtd nd}| j||dS Nr  r  r  r  r?   r?   r@   _print_gamma  s    zPrettyPrinter._print_gammac                 C   s    | j rtd nd}| j||dS r?  r  r  r?   r?   r@   _print_uppergamma  s    zPrettyPrinter._print_uppergammac                 C   s    | j rtd nd}| j||dS )Nr	  r
  r  r  r  r?   r?   r@   _print_lowergamma  s    zPrettyPrinter._print_lowergammac                 C   s   | j rt|jdkrttd }| |jd }t|  }| |jd }t|  }|| }t|d }t|| }|S | |jd }t|  }t|td  }|S | 	|S d S )Nr   r  rZ   r   r   )
rG   r   rQ   r   r!   rH   rR   r`   rS   r   )r=   rL   re  r  crU   r?   r?   r@   _print_DiracDelta
  s     zPrettyPrinter._print_DiracDeltac                 C   sD   |  |jd }| jr:t|r:| td| |jd S | |S )Nr   zE_%srZ   r  r  r?   r?   r@   _print_expint  s    zPrettyPrinter._print_expintc                 C   sD   t d}t | |j  }t t||dt ji}||_||_|S )Nr  r   )	r   rP   rQ   rR   r   r   r   rF  rG  )r=   rL   rF  rG  rU   r?   r?   r@   
_print_Chi#  s    
zPrettyPrinter._print_Chic                 C   s^   |  |jd }t|jdkr$|}n|  |jd }| ||}t|  }t|d }|S )Nr   rZ   r  )rH   rQ   r   r  r   rR   rS   )r=   rL   pforma0rU   pforma1r?   r?   r@   _print_elliptic_e2  s    zPrettyPrinter._print_elliptic_ec                 C   s.   |  |jd }t|  }t|d }|S )Nr   K)rH   rQ   r   rR   rS   rT   r?   r?   r@   _print_elliptic_k=  s    zPrettyPrinter._print_elliptic_kc                 C   sJ   |  |jd }|  |jd }| ||}t|  }t|d }|S )Nr   rZ   r  )rH   rQ   r  r   rR   rS   )r=   rL   rG  rH  rU   r?   r?   r@   _print_elliptic_fC  s    zPrettyPrinter._print_elliptic_fc                 C   s   | j rtd nd}| |jd }| |jd }t|jdkrN| ||}n<| |jd }| j||dd}t|d }t|| }t|  }t|| }|S )NPir   rZ   r   Fr  r4  )	rG   r!   rH   rQ   r   r  r   rS   rR   )r=   rL   rW   rG  rH  rU   Zpforma2Zpformar?   r?   r@   _print_elliptic_piK  s    z PrettyPrinter._print_elliptic_pic                 C   s    | j rttdS | tdS )NphiZGoldenRatiorG   r   r   rH   r   rC   r?   r?   r@   _print_GoldenRatioZ  s    z PrettyPrinter._print_GoldenRatioc                 C   s    | j rttdS | tdS )Nr	  Z
EulerGammarQ  rC   r?   r?   r@   _print_EulerGamma_  s    zPrettyPrinter._print_EulerGammac                 C   s   |  tdS )Nr  )rH   r   rC   r?   r?   r@   _print_Cataland  s    zPrettyPrinter._print_Catalanc                 C   s\   |  |jd }|jtjkr(t|  }t|d }t||  |jd  }tj|_|S )Nr   z mod rZ   )rH   rQ   r   r   r   rR   r`   r   r8  r?   r?   r@   
_print_Modg  s    zPrettyPrinter._print_Modc                 C   s  | j ||d}g g  }}dd }t|D ]\}}|jr| r|jdd\}	}
|	dkrft|
ddi}nt|	 g|
R ddi}| |}|||| q(|jr|j	dkr|d  || q(|j
r|d	k r| | }|||| q(|jr|t| |   q(|| | q(|rd
}|D ]$}|d ur.| dkr. qXq.d}|D ]p}|| d }}|d	k r| d
 }}|rtt|jtt|j	 }n
| |}|r|||}|||< q\tj| S )Nr,   c                 S   sj   |dkr |   dkrd}q$d}nd}| jtjks<| jtjkrJt|   }n| }t||}t|dtjiS )z'Prepend a minus sign to a pretty form. r   rZ   z- r   r  r   )r   r   r   NEGZADDr   rR   r   )rU   r  Z	pform_negr  r?   r?   r@   pretty_negativet  s    
z1PrettyPrinter._print_Add.<locals>.pretty_negativeF)Zrationalr  r  rZ   r   T)Z_as_ordered_termsrc  Zis_MulrX  Zas_coeff_mulr   rH   r   is_RationalqZ	is_Numberis_Relationalr   rR   r   r9   r  r  )r=   rD   r,   Ztermspformsr  rX  r+   r   rZ  otherZnegtermrU   Zlargenegativer?   r?   r@   
_print_Addp  sJ    






zPrettyPrinter._print_Addc           	         s  ddl m  |j}|d tju s:tdd |dd  D rttj|}|d dk}|rjt	ddd|d< t	j
| }|rt	d|j |j|j}|S g }g }jd	vr| }n
t|j}t| fd
dd}|D ]}|jr8|jr8|jjr8|jjr8|jdkr |t|j|j dd n|t|j|j  q|jr|tjur|jdkrh|t|j |jdkr|t|j q|| qЇfdd|D }fdd|D }t|dkrt	j
| S t|dkr|tj t	j
| t	j
|  S d S )Nr   Quantityc                 s   s   | ]}t |tV  qd S rA   )r7   r   r  r   r?   r?   r@   r    r  z+PrettyPrinter._print_Mul.<locals>.<genexpr>rZ   z-1rl  r   )oldnonec                    s    t |  pt | tot | j S rA   )r7   r
   rp  r5  r`  r?   r@   r6    s   
z*PrettyPrinter._print_Mul.<locals>.<lambda>r   r  Fr  c                    s   g | ]}  |qS r?   r   )r  ZairF   r?   r@   r    r  z,PrettyPrinter._print_Mul.<locals>.<listcomp>c                    s   g | ]}  |qS r?   r   )r  ZbirF   r?   r@   r    r  )Zsympy.physics.unitsra  rQ   r   Oner7  r   maprH   r   rd  r   r   r   r,   Zas_ordered_factorsr   is_commutativeZis_Powrq  rY  Zis_negativer   r
   rp  r  r  r	   rZ  r   )	r=   r  rQ   ZstrargsZnegoneobjre  r  rY  r?   )ra  r=   r@   r    sF    (



$
zPrettyPrinter._print_Mulc           	         sx  |  |}| jd rX| jrX|dkrX| dkrX| dksF|jrX|jrXt|t	d  S t
dd t
dd  }|  |}| dkr|  ||  d|  S |dkrdnt|d}t|dkrdt|d  | }t|d | }d	|_| d td fd
dtD }d |_t|| }td|j|_ttdd|  }t|| }t|| }|S )Nr0   r   rZ   r  \r   r   r  r   c                 3   s*   | ]"}d | d    d |  V  qdS )r   rZ   Nr?   r  Z_zZZ
linelengthr?   r@   r    s   z0PrettyPrinter._print_nth_root.<locals>.<genexpr>r   )rH   r8   rG   r   r   rv   rw   r   rS   nth_rootr   r9   ljustr   r   r   r  r   r`   r   r   r   )	r=   rp  r'   ZbprettyZrootsignZrprettyrq  Zdiagonalr   r?   rj  r@   _print_nth_root  sD    






zPrettyPrinter._print_nth_rootc                 C   s   ddl m} | \}}|jr|tju r:td| | S ||\}}|tju r~|j	r~|j
s~|jsh|jr~| jd r~| ||S |jr|dk rtd| t|| dd S |jrt| |  | |S | || | S )Nr   )fractionrl  r1   Fr  )Zsympy.simplify.simplifyrn  Zas_base_exprg  r   ZNegativeOner   rH   re  Zis_Atomrv   rY  rx   r8   rm  r
   r[  rR   __pow__)r=   powerrn  r  rL   r   r   r?   r?   r@   
_print_Pow!  s    
"zPrettyPrinter._print_Powc                 C   s   |  |jd S r  )rH   rQ   rC   r?   r?   r@   _print_UnevaluatedExpr3  s    z$PrettyPrinter._print_UnevaluatedExprc                 C   s   |dkr0|dk r"t t|t jdS t t|S n\t|dkrt|dkr|dk rnt t|t jdt t| S t t|t t| S nd S d S )NrZ   r   )r   
   )r   r9   rW  abs)r=   r  rZ  r?   r?   r@   Z__print_numer_denom6  s    z!PrettyPrinter.__print_numer_denomc                 C   s*   |  |j|j}|d ur|S | |S d S rA   )!_PrettyPrinter__print_numer_denomr  rZ  rE   r=   rD   r   r?   r?   r@   _print_RationalH  s    zPrettyPrinter._print_Rationalc                 C   s*   |  |j|j}|d ur|S | |S d S rA   )ru  	numeratordenominatorrE   rv  r?   r?   r@   _print_FractionP  s    zPrettyPrinter._print_Fractionc                 C   sl   t |jdkr8t|js8| |jd | t |j S | jrFtdnd}| j|jd d d| dd dS d S )	NrZ   r   ZMultiplicationrz   r   c                 S   s   | j p| jp| jS rA   )is_Unionis_Intersectionis_ProductSetsetr?   r?   r@   r6  ^  s   z1PrettyPrinter._print_ProductSet.<locals>.<lambda>r7  )r   setsr   rH   rG   r   rP   )r=   r  Z	prod_charr?   r?   r@   _print_ProductSetX  s     zPrettyPrinter._print_ProductSetc                 C   s   t |jtd}| |dddS )Nr   r  }r@  )r   rQ   r   rP   )r=   r   r  r?   r?   r@   _print_FiniteSeta  s    zPrettyPrinter._print_FiniteSetc                 C   s   | j rtd}nd}|jjrL|jjrL|jjr<|ddd|f}q|ddd|f}n||jjrn||d |j |d f}nZ|jjrt|}t|t||f}n6t	|dkrt|}t|t|||d f}nt
|}| |ddd	S )
NDots...r  r   rZ   r   r  r  r@  )rG   r   startis_infinitestopstepZis_positiveiterr   r   r   rP   )r=   r   dotsprintsetitr?   r?   r@   _print_Rangee  s"    
zPrettyPrinter._print_Rangec                 C   s`   |j |jkr$| |jd d ddS |jr0d}nd}|jr@d}nd}| |jd d ||S d S )	NrZ   r  r  r\   r&  r]   r'  r   )r  endrP   rQ   Z	left_openZ
right_openr=   r+   rS   r`   r?   r?   r@   _print_Interval~  s    zPrettyPrinter._print_Intervalc                 C   s    d}d}|  |jd d ||S )Nr  r  r   rP   rQ   r  r?   r?   r@   _print_AccumulationBounds  s    z'PrettyPrinter._print_AccumulationBoundsc                 C   s(   dt dd }| j|jd d |dd dS )Nr   ZIntersectionr   c                 S   s   | j p| jp| jS rA   )r}  r{  is_Complementr~  r?   r?   r@   r6    s   z3PrettyPrinter._print_Intersection.<locals>.<lambda>r7  r   rP   rQ   r=   r   rB  r?   r?   r@   _print_Intersection  s    z!PrettyPrinter._print_Intersectionc                 C   s(   dt dd }| j|jd d |dd dS )Nr   Unionr"   c                 S   s   | j p| jp| jS rA   )r}  r|  r  r~  r?   r?   r@   r6    s   z,PrettyPrinter._print_Union.<locals>.<lambda>r7  r  )r=   r   Zunion_delimiterr?   r?   r@   _print_Union  s    zPrettyPrinter._print_Unionc                 C   s,   | j stddtd }| |jd d |S )Nz?ASCII pretty printing of SymmetricDifference is not implementedr   ZSymmetricDifference)rG   r  r   rP   rQ   )r=   r   Zsym_delimeterr?   r?   r@   _print_SymmetricDifference  s    z(PrettyPrinter._print_SymmetricDifferencec                 C   s   d}| j |jd d |dd dS )Nz \ c                 S   s   | j p| jp| jS rA   )r}  r|  r{  r~  r?   r?   r@   r6    s   z1PrettyPrinter._print_Complement.<locals>.<lambda>r7  r  r  r?   r?   r@   _print_Complement  s    zPrettyPrinter._print_Complementc                    s   | j rtd nd |j}|j}|j}| |j}t|dkrp| j|d  |d fdd}| j	||ddd	dd
S t
 fddt||D }| j|d d dd}| j	||ddd	dd
S d S )NSmallElementOfinrZ   r   r   rA  r  r  TrS   r`   r  rB  c                 3   s,   | ]$\}}|d  d |dfD ]
}|V  qqdS )r   r@  Nr?   )r  r  Zsetvr5   innr?   r@   r    s   
z0PrettyPrinter._print_ImageSet.<locals>.<genexpr>r  r   )rG   r   r  Z	base_setsr/  rH   rD   r   rP   r  r   r   )r=   tsfunr  r/  rD   r   Zpargsr?   r  r@   _print_ImageSet  s*    
zPrettyPrinter._print_ImageSetc           	      C   s   | j rtd}td}nd}d}| t|j}t|jdd }|d urX| |j }n(| |j}| j r| |}t	|
  }|jtju r| j||dddd	d
S | |j}| j|||||fd	d}| j||dddd	d
S )Nr  r   r  andas_exprr  r  Tr   r  rA  )rG   r   rP   r   r   getattr	conditionrH   r  r   rR   Zbase_setr   UniversalSetr  )	r=   r  r  Z_andr  r  r  rp  r  r?   r?   r@   _print_ConditionSet  s2    


z!PrettyPrinter._print_ConditionSetc                 C   sb   | j rtd}nd}| |j}| |j}| |j}| j|||fdd}| j||dddddS )	Nr  r  r   rA  r  r  Tr  )rG   r   rP   r  rH   rD   r  r  )r=   r  r  r  rD   Zprodsetsr  r?   r?   r@   _print_ComplexRegion  s    
z"PrettyPrinter._print_ComplexRegionc                 C   sT   |j \}}| jrDdtd d}tt| ||| |ddiS tt|S d S )Nr   Z	ElementOfr   r	  )rQ   rG   r   r   r   r   rH   r   )r=   rL   r  r  elr?   r?   r@   _print_Contains  s    

zPrettyPrinter._print_Containsc                 C   sT   |j jtju r(|jjtju r(| |jS | jr8td}nd}| 	|
 | | S )Nr  r  )r  Zformular   r3  ZbnrH   Za0rG   r   r_  truncate)r=   r   r  r?   r?   r@   _print_FourierSeries	  s    
z"PrettyPrinter._print_FourierSeriesc                 C   s   |  |jS rA   )r_  Zinfiniter=   r   r?   r?   r@   _print_FormalPowerSeries	  s    z&PrettyPrinter._print_FormalPowerSeriesc                 C   s0   t | |j  }| td}t || S )NZSetExpr)r   rH   r  rR   r   r`   )r=   seZ
pretty_setpretty_namer?   r?   r@   _print_SetExpr	  s    zPrettyPrinter._print_SetExprc                 C   s   | j rtd}nd}t|jjdks4t|jjdkr<td|jtju r|j}||	|d |	|d |	|d |	|f}n>|jtj
u s|jdkr|d d }|| t|}nt|}| |S )	Nr  r  r   z@Pretty printing of sequences with symbolic bound not implementedr   r   rZ   r   )rG   r   r   r  Zfree_symbolsr  r  r   r  rZ  r  lengthr   r   _print_list)r=   r   r  r  r  r?   r?   r@   _print_SeqFormula	  s     
 

zPrettyPrinter._print_SeqFormulac                 C   s   dS )NFr?   r5  r?   r?   r@   r6  3	  r  zPrettyPrinter.<lambda>c                 C   sx   g }|D ]:}|  |}	||r*t|	  }	|r8|| ||	 q|sRtd}
nttj|  }
t|
j|||d }
|
S )Nr   rN  )rH   r   rR   r   r   r   )r=   seqrS   r`   rB  r8  r  r\  rY  rU   r   r?   r?   r@   rP   2	  s    


zPrettyPrinter._print_seqc                 C   sP   d }|D ].}|d u r|}qt || }t || }q|d u rHt dS |S d S )Nr   )r   r`   )r=   rB  rQ   rU   r   r?   r?   r@   r  F	  s    zPrettyPrinter.joinc                 C   s   |  |ddS r  rP   )r=   r   r?   r?   r@   r  U	  s    zPrettyPrinter._print_listc                 C   sL   t |dkr:tt| |d d }t|jdddd S | |ddS d S )NrZ   r   r   r\   r]   TrN  )r   r   r   r   rH   rR   rP   )r=   r  Zptupler?   r?   r@   _print_tupleX	  s    zPrettyPrinter._print_tuplec                 C   s
   |  |S rA   )r  rC   r?   r?   r@   _print_Tuple_	  s    zPrettyPrinter._print_Tuplec                 C   s`   t | td}g }|D ]8}| |}| || }tt|d| }|| q| |ddS )Nr   z: r  r  )	r   keysr   rH   r   r   r   r   rP   )r=   r   r  r  r   rJ  Vr   r?   r?   r@   _print_dictb	  s    
zPrettyPrinter._print_dictc                 C   s
   |  |S rA   )r  )r=   r   r?   r?   r@   _print_Dicto	  s    zPrettyPrinter._print_Dictc                 C   s:   |st dS t|td}| |}t |jdddd }|S )Nzset()r   r  r  TrN  )r   r   r   rP   rR   r=   r   r  prettyr?   r?   r@   
_print_setr	  s    
zPrettyPrinter._print_setc                 C   sd   |st dS t|td}| |}t |jdddd }t |jdddd }t tt|j| }|S )	Nzfrozenset()r   r  r  TrN  r\   r]   )	r   r   r   rP   rR   r   r   typerp   r  r?   r?   r@   _print_frozensetz	  s    
zPrettyPrinter._print_frozensetc                 C   s   | j rttdS tdS d S )NZUniverser  rh  r  r?   r?   r@   _print_UniversalSet	  s    z!PrettyPrinter._print_UniversalSetc                 C   s   t t|S rA   r   r   )r=   ringr?   r?   r@   _print_PolyRing	  s    zPrettyPrinter._print_PolyRingc                 C   s   t t|S rA   r  )r=   fieldr?   r?   r@   _print_FracField	  s    zPrettyPrinter._print_FracFieldc                 C   s   t t|S rA   rB   )r=   elmr?   r?   r@   _print_FreeGroupElement	  s    z%PrettyPrinter._print_FreeGroupElementc                 C   s   t t|S rA   r  )r=   Zpolyr?   r?   r@   _print_PolyElement	  s    z PrettyPrinter._print_PolyElementc                 C   s   t t|S rA   r  )r=   fracr?   r?   r@   _print_FracElement	  s    z PrettyPrinter._print_FracElementc                 C   s*   |j r| |  S | | S d S rA   )Z
is_aliasedrH   Zas_polyr  rC   r?   r?   r@   _print_AlgebraicNumber	  s    z$PrettyPrinter._print_AlgebraicNumberc                 C   s:   | j |jdd|jg}t| |  }t|d }|S )NlexrV  ZCRootOf)r_  rD   r  r   rP   rR   rS   r=   rD   rQ   rU   r?   r?   r@   _print_ComplexRootOf	  s    z"PrettyPrinter._print_ComplexRootOfc                 C   sT   | j |jddg}|jtjur0|| |j t| |	  }t|
d }|S )Nr  rV  ZRootSum)r_  rD   r  r   ZIdentityFunctionr   rH   r   rP   rR   rS   r  r?   r?   r@   _print_RootSum	  s    zPrettyPrinter._print_RootSumc                 C   s,   | j rtd d}nd}tt||j S )NIntegersz_%dzGF(%d))rG   r   r   r   mod)r=   rD   formr?   r?   r@   _print_FiniteField	  s    z PrettyPrinter._print_FiniteFieldc                 C   s   | j rttdS tdS d S )Nr  ZZZrh  rC   r?   r?   r@   _print_IntegerRing	  s    z PrettyPrinter._print_IntegerRingc                 C   s   | j rttdS tdS d S )NZ	RationalsZQQrh  rC   r?   r?   r@   _print_RationalField	  s    z"PrettyPrinter._print_RationalFieldc                 C   sB   | j rtd}nd}|jr"t|S | t|d t|j S d S )NZRealsZRRr   rG   r   Zhas_default_precisionr   rH   r   r9   Z	precisionr=   domainprefixr?   r?   r@   _print_RealField	  s    
zPrettyPrinter._print_RealFieldc                 C   sB   | j rtd}nd}|jr"t|S | t|d t|j S d S )NZ	ComplexesCCr   r  r  r?   r?   r@   _print_ComplexField	  s    
z!PrettyPrinter._print_ComplexFieldc                 C   s^   t |j}|jjs6ttd| |j }|| | |dd}t|	| |j
 }|S Norder=r&  r'  r   symbolsr,   Z
is_defaultr   r`   rH   r   rP   rS   r  r=   rD   rQ   r,   rU   r?   r?   r@   _print_PolynomialRing	  s    

z#PrettyPrinter._print_PolynomialRingc                 C   s^   t |j}|jjs6ttd| |j }|| | |dd}t|	| |j
 }|S )Nr  r\   r]   r  r  r?   r?   r@   _print_FractionField	  s    

z"PrettyPrinter._print_FractionFieldc                 C   sV   |j }t|jt|jkr.|dt|j f }| |dd}t|| |j }|S r  )	r  r9   r,   Zdefault_orderrP   r   rS   rH   r  )r=   rD   grU   r?   r?   r@   _print_PolynomialRingBase	  s    z'PrettyPrinter._print_PolynomialRingBasec                    s    fdd j D }td|jddd }fdd jD }ttd j }ttd	 j }d|g| ||g }t|  }t|	 j
j }|S )
Nc                    s   g | ]}j | jd qS )rV  )r_  r,   rb  basisr=   r?   r@   r  	  s   z6PrettyPrinter._print_GroebnerBasis.<locals>.<listcomp>r@  r&  r'  rC  c                    s   g | ]}  |qS r?   r   r  genrF   r?   r@   r   
  r  zdomain=r  )exprsr   r  rR   gensr`   rH   r  r,   rS   ro   rp   )r=   r  r  r  r  r,   rU   r?   r  r@   _print_GroebnerBasis	  s    z"PrettyPrinter._print_GroebnerBasisc              	      s     |j}t|  }| dkr,| nd}ttd||jd}t|| }|j}| d |_t| 	 fddt
|j|jD  }||_|S )NrZ   r   r   r  c              	      s8   g | ]0} j  |d  td |d fddqS )r   r   rZ   r   rA  )rP   rH   r   )r  r  rF   r?   r@   r  
  s   $z-PrettyPrinter._print_Subs.<locals>.<listcomp>)rH   rD   r   rR   r   r   r   r   r`   rP   r   r  r6  )r=   rL   rU   r   Zrvertr  r?   rF   r@   _print_Subs
  s    zPrettyPrinter._print_Subsc           
      C   s   t |}| |jd }t d|  }t || }t || }t|jdkrV|S |j\}}|}t | |g  }	t t	
||	dt ji}||_|	|_|S )Nr   r   rZ   r   )r   rH   rQ   r   r   r`   r   rP   rR   r   r   r   rF  rG  )
r=   rL   rW   rU   r   r   rK  rz   rF  rG  r?   r?   r@   _print_number_function
  s$    

z$PrettyPrinter._print_number_functionc                 C   s   |  |dS )Nr  r  rK   r?   r?   r@   _print_euler3
  s    zPrettyPrinter._print_eulerc                 C   s   |  |dS )Nr  r  rK   r?   r?   r@   _print_catalan6
  s    zPrettyPrinter._print_catalanc                 C   s   |  |dS )NrU  r  rK   r?   r?   r@   _print_bernoulli9
  s    zPrettyPrinter._print_bernoullic                 C   s   |  |dS )NLr  rK   r?   r?   r@   _print_lucas>
  s    zPrettyPrinter._print_lucasc                 C   s   |  |dS )Nr  r  rK   r?   r?   r@   _print_fibonacciA
  s    zPrettyPrinter._print_fibonaccic                 C   s   |  |dS )NrN  r  rK   r?   r?   r@   _print_tribonacciD
  s    zPrettyPrinter._print_tribonaccic                 C   s&   | j r| |td S | |dS d S )Nr	  Z	stieltjes)rG   r  r!   rK   r?   r?   r@   _print_stieltjesG
  s    zPrettyPrinter._print_stieltjesc                 C   s   |  |jd }t|td }t||  |jd  }| jrPttd}ntd}|}t|d|   }t|d|   }t|	|dtj
iS )Nr   r   rZ   r  r   r   r   )rH   rQ   r   r`   rG   r   r   rS   r   r   ZPOW)r=   rL   rU   re  r  r  r  r?   r?   r@   _print_KroneckerDeltaM
  s    z#PrettyPrinter._print_KroneckerDeltac                 C   s   t |dr0| d}t|| |  }|S t |dr| d}t|| |j }t|| d }t|| |j }|S t |dr| d}t|| |j }|S | d S d S )N
as_booleanzDomain: r  z in r  z
Domain on )r  rH   r   r`   r  r  r  )r=   r   rU   r?   r?   r@   _print_RandomDomainZ
  s    





z!PrettyPrinter._print_RandomDomainc                 C   sD   z"|j d ur | |j |W S W n ty4   Y n0 | t|S rA   )r  rH   to_sympyr   reprr=   r  r?   r?   r@   
_print_DMPl
  s    
zPrettyPrinter._print_DMPc                 C   s
   |  |S rA   )r  r  r?   r?   r@   
_print_DMFu
  s    zPrettyPrinter._print_DMFc                 C   s   |  t|jS rA   rH   r   rW   )r=   objectr?   r?   r@   _print_Objectx
  s    zPrettyPrinter._print_Objectc                 C   s8   t d}| |j}| |j}|||d }t|S )Nz-->r   )r   rH   r  codomainr`   r   )r=   morphismr1  r  r  tailr?   r?   r@   _print_Morphism{
  s
    zPrettyPrinter._print_Morphismc                 C   s.   |  t|j}| |}t|d|d S )NrI  r   )rH   r   rW   r
  r   r`   )r=   r  r  pretty_morphismr?   r?   r@   _print_NamedMorphism
  s    
z"PrettyPrinter._print_NamedMorphismc                 C   s"   ddl m} | ||j|jdS )Nr   )NamedMorphismid)Zsympy.categoriesr  r  r  r  )r=   r  r  r?   r?   r@   _print_IdentityMorphism
  s    z%PrettyPrinter._print_IdentityMorphismc                 C   sT   t d}dd |jD }|  ||d }| |}| |}t||d S )Nr|  c                 S   s   g | ]}t |jqS r?   )r   rW   )r  	componentr?   r?   r@   r  
  s   z:PrettyPrinter._print_CompositeMorphism.<locals>.<listcomp>rI  r   )r   r  reverser  rH   r
  r   r`   )r=   r  ZcircleZcomponent_names_listZcomponent_namesr  r  r?   r?   r@   _print_CompositeMorphism
  s    

z&PrettyPrinter._print_CompositeMorphismc                 C   s   |  t|jS rA   r  )r=   categoryr?   r?   r@   _print_Category
  s    zPrettyPrinter._print_Categoryc                 C   sX   |j s| tjS | |j }|jrLdtd }| |jd }|||}t|d S )Nr   z==>r   )ZpremisesrH   r   ZEmptySetZconclusionsr   r`   r   )r=   ZdiagramZpretty_resultZresults_arrowZpretty_conclusionsr?   r?   r@   _print_Diagram
  s    zPrettyPrinter._print_Diagramc                    s2   ddl m} | fddt jD }| |S )Nr   )Matrixc                    s&   g | ]  fd dt jD qS )c                    s,   g | ]$} |f r  |f nt d qS )r   r   )r  r5   )gridr+   r?   r@   r  
  s   z?PrettyPrinter._print_DiagramGrid.<locals>.<listcomp>.<listcomp>)r   r   r  r  )r+   r@   r  
  s   z4PrettyPrinter._print_DiagramGrid.<locals>.<listcomp>)rD  r  r   r   r%  )r=   r  r  matrixr?   r  r@   _print_DiagramGrid
  s
    z PrettyPrinter._print_DiagramGridc                 C   s   |  |ddS r  r  r=   rK  r?   r?   r@   _print_FreeModuleElement
  s    z&PrettyPrinter._print_FreeModuleElementc                    s"    fdd j D }| |ddS )Nc                    s   g | ]} fd d|D qS )c                    s   g | ]} j |qS r?   )r  r  )r  r  r  r?   r@   r  
  r  z=PrettyPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>r?   r  r  r?   r@   r  
  r  z2PrettyPrinter._print_SubModule.<locals>.<listcomp>r  r  )r  rP   )r=   r  r  r?   r  r@   _print_SubModule
  s    zPrettyPrinter._print_SubModulec                 C   s   |  |j|  |j S rA   )rH   r  r  r=   r  r?   r?   r@   _print_FreeModule
  s    zPrettyPrinter._print_FreeModulec                    s(   |j j |  fdd|jjD ddS )Nc                    s   g | ]\} |qS r?   r?   r  r   r?   r@   r  
  r  z?PrettyPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>r  r  )r  r  rP   _moduler  r  r?   r!  r@   _print_ModuleImplementedIdeal
  s    z+PrettyPrinter._print_ModuleImplementedIdealc                 C   s   |  |j|  |j S rA   )rH   r  
base_idealr=   Rr?   r?   r@   _print_QuotientRing
  s    z!PrettyPrinter._print_QuotientRingc                 C   s    |  |j||  |jj S rA   )rH   r  r  r$  r%  r?   r?   r@   _print_QuotientRingElement
  s    z(PrettyPrinter._print_QuotientRingElementc                 C   s   |  |j|  |jj S rA   )rH   datamodulekilled_moduler  r?   r?   r@   _print_QuotientModuleElement
  s    z*PrettyPrinter._print_QuotientModuleElementc                 C   s   |  |j|  |j S rA   )rH   rp  r+  r  r?   r?   r@   _print_QuotientModule
  s    z#PrettyPrinter._print_QuotientModulec              	   C   sN   |  | }| d |_t|d|  |jdtdd |  |j }|S )Nr   z : z %s> r   )	rH   Z_sympy_matrixr   r   r   r`   r  r   r  )r=   r   r  rU   r?   r?   r@   _print_MatrixHomomorphism
  s    z'PrettyPrinter._print_MatrixHomomorphismc                 C   s   |  |jS rA   rH   rW   )r=   Zmanifoldr?   r?   r@   _print_Manifold
  s    zPrettyPrinter._print_Manifoldc                 C   s   |  |jS rA   r/  )r=   patchr?   r?   r@   _print_Patch
  s    zPrettyPrinter._print_Patchc                 C   s   |  |jS rA   r/  )r=   Zcoordsr?   r?   r@   _print_CoordSystem
  s    z PrettyPrinter._print_CoordSystemc                 C   s   |j j|j j}| t|S rA   )
_coord_sysr  _indexrW   rH   r   )r=   r  stringr?   r?   r@   _print_BaseScalarField
  s    z$PrettyPrinter._print_BaseScalarFieldc                 C   s*   t dd |jj|j j }| t|S )Nr   r   )r"   r4  r  r5  rW   rH   r   )r=   r  r   r?   r?   r@   _print_BaseVectorField
  s    z$PrettyPrinter._print_BaseVectorFieldc                 C   sr   | j rtd}nd}|j}t|drJ|jj|j j}| |d t	| S | |}t
|  }t
|| S d S )NZDifferentialr   r4  r   )rG   r   Z_form_fieldr  r4  r  r5  rW   rH   r   r   rR   rS   )r=   r  r   r  r6  rU   r?   r?   r@   _print_Differential
  s    


z!PrettyPrinter._print_Differentialc                 C   s8   |  |jd }t|d|jj  }t|d }|S )Nr   z%s(r]   )rH   rQ   r   rS   ro   rp   r`   )r=   r  rU   r?   r?   r@   	_print_Tr
  s    zPrettyPrinter._print_Trc                 C   sH   |  |jd }t|  }| jr6t|td  }nt|d }|S )Nr   nurH   rQ   r   rR   rG   rS   r!   rT   r?   r?   r@   _print_primenu
  s    zPrettyPrinter._print_primenuc                 C   sH   |  |jd }t|  }| jr6t|td  }nt|d }|S )Nr   Omegar<  rT   r?   r?   r@   _print_primeomega  s    zPrettyPrinter._print_primeomegac                 C   sB   |j j dkr4| jr"| td}n| td}|S | |S d S )NZdegreeZDegree   )rW   rG   rH   r   chrrE   rT   r?   r?   r@   _print_Quantity  s    zPrettyPrinter._print_Quantityc                 C   sD   t dt|j d }| |j}| |j}t t||| }|S )Nr   )r   r   r   rH   r   r   r   r   r   r?   r?   r@   _print_AssignmentBase  s
    z#PrettyPrinter._print_AssignmentBasec                 C   s   |  |jS rA   r/  r  r?   r?   r@   
_print_Str#  s    zPrettyPrinter._print_Str)N)F)T)N)N)r&  r'  )NNr   F)FNr\   r]   )FNr@  Fr\   r]   )N)rp   
__module____qualname____doc__ZprintmethodZ_default_settingsr6   rE   propertyrG   rJ   rM   rN   rV   rX   Z_print_RandomSymbolrY   r[   rb   rf   rh   ri   rl   rm   rr   Z_print_InfinityZ_print_NegativeInfinityZ_print_EmptySetZ_print_NaturalsZ_print_Naturals0Z_print_IntegersZ_print_RationalsZ_print_ComplexesZ_print_EmptySequencers   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*  r1  r:  r;  r=  rH  rL  rO  rQ  rV  r[  rf  ri  rk  rm  ro  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  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-  r2  r9  r;  r<  r=  r>  r@  rA  rB  rD  rE  rF  rI  rK  rL  rO  rR  rS  rT  rU  r_  r  rm  rq  rr  ru  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z_print_SeqPerZ_print_SeqAddZ_print_SeqMulrP   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  Z_print_bellr  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  r2  r3  r7  r8  r9  r:  r=  r?  rB  rC  rD  r?   r?   r?   r@   r(      s  
					%%K6aC		

$	f!# 8	0T 
  
%

		H=,			
					
	r(   c                 K   s>   t |}|jd }t|}z|| W t| S t| 0 dS )zReturns a string containing the prettified form of expr.

    For information on keyword arguments see pretty_print function.

    r.   N)r(   r8   r    rJ   )rD   r>   r  r.   Zuflagr?   r?   r@   r  '  s    

r  c                 K   s   t t| fi | dS )a  Prints expr in pretty form.

    pprint is just a shortcut for this function.

    Parameters
    ==========

    expr : expression
        The expression to print.

    wrap_line : bool, optional (default=True)
        Line wrapping enabled/disabled.

    num_columns : int or None, optional (default=None)
        Number of columns before line breaking (default to None which reads
        the terminal width), useful when using SymPy without terminal.

    use_unicode : bool or None, optional (default=None)
        Use unicode characters, such as the Greek letter pi instead of
        the string pi.

    full_prec : bool or string, optional (default="auto")
        Use full precision.

    order : bool or string, optional (default=None)
        Set to 'none' for long expressions if slow; default is None.

    use_unicode_sqrt_char : bool, optional (default=True)
        Use compact single-character square root symbol (when unambiguous).

    root_notation : bool, optional (default=True)
        Set to 'False' for printing exponents of the form 1/n in fractional form.
        By default exponent is printed in root form.

    mat_symbol_style : string, optional (default="plain")
        Set to "bold" for printing MatrixSymbols using a bold mathematical symbol face.
        By default the standard face is used.

    imaginary_unit : string, optional (default="i")
        Letter to use for imaginary unit when use_unicode is True.
        Can be "i" (default) or "j".
    N)printr  )rD   kwargsr?   r?   r@   pretty_print:  s    +rK  c                 K   sH   ddl m} ddlm} d|vr(d|d< |t| fi ||  dS )a  Prints expr using the pager, in pretty form.

    This invokes a pager command using pydoc. Lines are not wrapped
    automatically. This routine is meant to be used with a pager that allows
    sideways scrolling, like ``less -S``.

    Parameters are the same as for ``pretty_print``. If you wish to wrap lines,
    pass ``num_columns=None`` to auto-detect the width of the terminal.

    r   )pager)getpreferredencodingr/   i  N)pydocrL  localerM  r  encode)rD   r>   rL  rM  r?   r?   r@   pager_printj  s
    rQ  )?r  Z
sympy.corer   Zsympy.core.addr   Zsympy.core.containersr   Zsympy.core.functionr   Zsympy.core.mulr   Zsympy.core.numbersr   r	   Zsympy.core.powerr
   Zsympy.core.sortingr   Zsympy.core.symbolr   Zsympy.core.sympifyr   Zsympy.printing.conventionsr   Zsympy.printing.precedencer   r   r   Zsympy.printing.printerr   r   Zsympy.printing.strr   Zsympy.utilities.iterablesr   Zsympy.utilities.exceptionsr   Z sympy.printing.pretty.stringpictr   r   Z&sympy.printing.pretty.pretty_symbologyr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   rk  Zpprint_use_unicodeZpprint_try_use_unicoder(   r  rK  pprintrQ  r?   r?   r?   r@   <module>   s`   @                      
-