o
    GZh@                    @   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   sV   t | | t| jd tstd| jd | jd dvr)t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?   K/var/www/auris/lib/python3.10/site-packages/sympy/printing/pretty/pretty.pyr6   /   s   zPrettyPrinter.__init__c                 C      t t|S Nr   r9   r=   exprr?   r?   r@   emptyPrinter7      zPrettyPrinter.emptyPrinterc                 C   s   | j d rdS t S )Nr.   T)r8   r    r=   r?   r?   r@   _use_unicode:   s   
zPrettyPrinter._use_unicodec                 C   s   |  |jdi | jS )Nr?   )_printrenderr8   rD   r?   r?   r@   doprintA      zPrettyPrinter.doprintc                 C   s   |S rB   r?   r=   er?   r?   r@   _print_stringPictE   s   zPrettyPrinter._print_stringPictc                 C   s   t |S rB   )r   rN   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=   rO   pformr?   r?   r@   _print_atan2K   s   zPrettyPrinter._print_atan2Fc                 C   s   t |j|}t|S rB   )r   namer   )r=   rO   Z	bold_nameZsymbr?   r?   r@   _print_SymbolP   s   zPrettyPrinter._print_Symbolc                 C   s   |  || jd dkS )Nr2   bold)r[   r8   rN   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=   rO   r-   r?   r?   r@   _print_FloatW   s   

zPrettyPrinter._print_Floatc                 C   ~   |j }|j}| |}t|d }t|d }t|| td }t|d }t|| | }t|d }|S )N()MULTIPLICATION SIGNZ_expr1Z_expr2rJ   r   rV   rightr"   r=   rO   Zvec1Zvec2rX   r?   r?   r@   _print_Cross_      
zPrettyPrinter._print_Crossc                 C   `   |j }| |}t|d }t|d }t|| td }t|| td }|S )Nra   rb   rc   NABLAZ_exprrJ   r   rV   re   r"   r=   rO   ZvecrX   r?   r?   r@   _print_Curlk      
zPrettyPrinter._print_Curlc                 C   ri   )Nra   rb   DOT OPERATORrj   rk   rl   r?   r?   r@   _print_Divergencet   rn   zPrettyPrinter._print_Divergencec                 C   r`   )Nra   rb   ro   rd   rf   r?   r?   r@   
_print_Dot}   rh   zPrettyPrinter._print_Dotc                 C   H   |j }| |}t|d }t|d }t|| td }|S )Nra   rb   rj   rk   r=   rO   funcrX   r?   r?   r@   _print_Gradient      
zPrettyPrinter._print_Gradientc                 C   rr   )Nra   rb   Z	INCREMENTrk   rs   r?   r?   r@   _print_Laplacian   rv   zPrettyPrinter._print_Laplacianc                 C   s4   zt t|jj| dW S  ty   | | Y S w )N)printer)r   r   	__class____name__KeyErrorrF   rN   r?   r?   r@   _print_Atom   s
   zPrettyPrinter._print_Atomc                 C   s&   | j r| |S ddg}| |ddS )Nz-ooZoora   rb   )rI   r|   rS   )r=   rO   Zinf_listr?   r?   r@   _print_Reals   s   
zPrettyPrinter._print_Realsc                 C   D   |j d }| |}|jr|js|jst|  }t|d }|S Nr   !)rT   rJ   
is_Integeris_nonnegative	is_Symbolr   rU   rV   r=   rO   xrX   r?   r?   r@   _print_subfactorial      

z!PrettyPrinter._print_subfactorialc                 C   r~   r   rT   rJ   r   r   r   r   rU   re   r   r?   r?   r@   _print_factorial   r   zPrettyPrinter._print_factorialc                 C   r~   )Nr   z!!r   r   r?   r?   r@   _print_factorial2   r   zPrettyPrinter._print_factorial2c                 C   st   |j \}}| |}| |}dt| |  }t|| }t|| }t|dd }|jd d |_|S )N ra   rb   r^      )rT   rJ   maxwidthr   aboverU   baseline)r=   rO   nkZn_pformZk_pformbarrX   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_oprJ   lhsrhsr   nextOPENr=   rO   oplrrX   r?   r?   r@   _print_Relational   s
   zPrettyPrinter._print_Relationalc                 C   s   ddl m}m} | jrF|jd }| |}t||r#| j|tddS t||r1| j	|tddS |j
r=|js=t|  }t|td S | |S )Nr   )
EquivalentImpliesZNotEquiv)altcharZNotArrowNot)Zsympy.logic.boolalgr   r   rI   rT   rJ   r7   _print_Equivalentr   _print_Implies
is_Booleanis_Notr   rU   rV   _print_Function)r=   rO   r   r   argrX   r?   r?   r@   
_print_Not   s   




zPrettyPrinter._print_Notc                 C   s   |j }|rt|j td}|d }| |}|jr!|js!t|  }|dd  D ]#}| |}|jr:|js:t|  }t|d|  }t|| }q'|S )Nkeyr   r^    %s )	rT   sortedr   rJ   r   r   r   rU   re   )r=   rO   charsortrT   r   rX   	pform_argr?   r?   r@   Z__print_Boolean   s   

zPrettyPrinter.__print_Booleanc                 C   $   | j r| |tdS | j|ddS )NAndTr   rI   _PrettyPrinter__print_Booleanr   r   rN   r?   r?   r@   
_print_And     zPrettyPrinter._print_Andc                 C   r   )NOrTr   r   rN   r?   r?   r@   	_print_Or  r   zPrettyPrinter._print_Orc                 C   r   )NZXorTr   r   rN   r?   r?   r@   
_print_Xor  r   zPrettyPrinter._print_Xorc                 C   r   )NZNandTr   r   rN   r?   r?   r@   _print_Nand  r   zPrettyPrinter._print_Nandc                 C   r   )NZNorTr   r   rN   r?   r?   r@   
_print_Nor$  r   zPrettyPrinter._print_Norc                 C   s(   | j r| j||ptdddS | |S )NArrowFr   r   r=   rO   r   r?   r?   r@   r   *  s   
zPrettyPrinter._print_Impliesc                 C   s(   | j r| ||ptdS | j|d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   _)rJ   rT   r   r   r   r   rW   r?   r?   r@   _print_conjugate6  s   zPrettyPrinter._print_conjugatec                 C   s$   |  |jd }t|dd }|S )Nr   |)rJ   rT   r   rU   rW   r?   r?   r@   
_print_Abs:  s   zPrettyPrinter._print_Absc                 C   4   | j r| |jd }t|dd }|S | |S )Nr   lfloorrfloorrI   rJ   rT   r   rU   r   rW   r?   r?   r@   _print_floor?  
   
zPrettyPrinter._print_floorc                 C   r   )Nr   lceilrceilr   rW   r?   r?   r@   _print_ceilingG  r   zPrettyPrinter._print_ceilingc                 C   s  t |jr| jrtd}nd}d }d}t|jD ]8\}}| |}t|| }||7 }|j	r3|dkr;|tt
| }|d u rB|}qt|d }t|| }qt| |j dtji}	t|}
|dkdkrq|
tt
| }
t|
tj| }
|
jd |
_tt|
|	 }
tj|
_|
S )NPARTIAL DIFFERENTIALdr   r^   r   r   F)r   rE   rI   r"   reversedZvariable_countrJ   r   rV   r   r9   re   rU   FUNCbelowr   LINEr   r   MULr   )r=   derivderiv_symbolr   Zcount_total_derivsymnumsdsfrX   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r0| |j	d }t|  S td}|D ]}| t
t|dd}t|| }q6|S )Nr   PermutationCycle r^   ,) sympy.combinatorics.permutationsr   r   r   r   rU   listZcyclic_formrJ   sizer9   tuplereplacere   )r=   Z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rtd| ddddd n| jd	d
}|r,| ||S |j}t	t
t|}td}d
}t||D ](\}	}
| |	}| |
}t|| }|r\d}nt|d }t|| }qBt|  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   ziprJ   r   r   rV   re   rU   )r=   rE   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r+t|  }t|d| }qd}d }|jD ]}	| }
|
d }| j	 }|rO|d7 }t
d|}t|}|j||
 d  |_t|	dkrt|	dkrytd}| |	d }t|	dkr| |	d }| |	d }|rtdd|  }t|d	|  }tdd
|  }t|d	|  }t|| }t|| }|st|d	 }|r|}d}q;t|| }q;t|| }tj|_|S )Nr   r^   z dTr   intr      r      F)functionrJ   is_Addr   rU   limitsr   re   heightrI   r   r   r   r   rV   r   r   r   r   )r=   Zintegralr   prettyFr   r   Z	prettyArgZ	firsttermr   limhH
ascii_modeZvintrX   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r$tdd}tdd}| }d}d}	d}
|jD ]}| |\}}|d d	 d
 d }|| ||d   | | g}t|d D ]}|d| d|d   | d  qYt	d}t
|j|  }t|	| }	|r| }
t
|| }t
|| }|rd|_d}| }t	d}t
|jdg|d    }t
|| }t
|| }q1|	|
d  |_t
j|_|S )Nr   r^   r   -ZUpTackTr   r      r   r   r   F)termrJ   r   rI   r   r   '_PrettyPrinter__print_SumProduct_Limitsr   appendr   r   stackr   r   r   r   re   r   r   )r=   rE   rt   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   rJ   r   r   )r   r   r   r   r   rX   rH   r?   r@   print_start.  s
   

z<PrettyPrinter.__print_SumProduct_Limits.<locals>.print_startr   r   r^   rJ   )r=   r   r  prettyUpperprettyLowerr?   rH   r@   Z__print_SumProduct_Limits-  s   z'PrettyPrinter.__print_SumProduct_Limitsc                 C   sX  | j  }dd }|j}| |}|jrt|  }| d }d}d}d}	|jD ]n}
| |
\}}t	|| }|||
 |
 |\}}}}td}t|j|  }|rX| }	t|| }t|| }|rz| j|| d |j  8  _d}td}t|jdg|   }t|| }t|| }q(|s|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  q3|rV|	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  qttd|D ]}
|	dd|
 |d d||
 d  f  q|	|d |  ||d|  |	|fS )N<^>c                 S   s|   |rt | |kr
| S |t |  }|dv s|tdvr | d|  S |d }d| }|dkr2d| |  S ||  d|t |   S )N)r  <r  r   r   >)r   r   )r   ZwidhowZneedZhalfleadr?   r?   r@   adjust=  s   z6PrettyPrinter._print_Sum.<locals>.asum.<locals>.adjustr   r^   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   wmorelinesr+   Zvsumr?   r?   r@   asum<  s6   

  
**z&PrettyPrinter._print_Sum.<locals>.asumr   Tr   r   Fr   )rI   r   rJ   r   r   rU   r   r   r  r   r   r   r  r   r   r   re   r   r   )r=   rE   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rt|dd }td}| |}| jr9t|tdd t	d  }nt|d }t|| | }t
|d	ksX|tjtjfv r[d
}n| jrlt
|dkrht	dnt	d}t|| | }t|| }t||dtji}|S )Nr   ra   rb   r   r  r^   r   z->z+-r   +ZSuperscriptPlusZSuperscriptMinusr   )rT   rJ   r   r   r   rU   rI   re   r   r   r9   r   InfinityNegativeInfinityr   r   )	r=   r   rO   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 pBdg|< q0d}t |jD ]h}d}t |jD ]B |f }	|	 | ksiJ t|	 | \}
}t|	| }	t|		|
 }	|du r|	}qWt|d|  }t||	 }qW|du r|}qNt |D ]	}t|
d }qt|
| }qN|du rtd	}|S )
zL
        This method factors out what is essentially grid printing.
        r   r^   c                    s   g | ]
} |f   qS r?   r   .0r+   ZMsr5   r?   r@   
<listcomp>  s    z8PrettyPrinter._print_matrix_contents.<locals>.<listcomp>r   Nr   r   )r   rowscolsrJ   r   r   r&   r   re   rV   r   )r=   rO   Mr+   hsepvsepmaxwDD_rowr   rV   re   r   r?   r+  r@   _print_matrix_contents  sD   *z$PrettyPrinter._print_matrix_contents[]c                 C   s,   |  |}| d |_t||| }|S )Nr   )r5  r   r   r   rU   )r=   rO   lparensrparensr3  r?   r?   r@   _print_MatrixBase  s   
zPrettyPrinter._print_MatrixBasec                 C   sl   |j }|jr.ddlm} t||r| j|jdddS | |}| d |_	t
|dd S | j|dddS )Nr   BlockMatrixr   )r8  r9  r   )r   is_MatrixExpr&sympy.matrices.expressions.blockmatrixr<  r7   r:  blocksrJ   r   r   r   rU   )r=   rO   matr<  r3  r?   r?   r@   _print_Determinant  s   

z PrettyPrinter._print_Determinantc                 C   *   | j rd}nd}| j|jd d |dd dS )Nu   ⊗.*c                 S      t | td kS Nr   r   r   r   r?   r?   r@   <lambda>      z4PrettyPrinter._print_TensorProduct.<locals>.<lambda>parenthesizerI   rS   rT   )r=   rE   Zcircled_timesr?   r?   r@   _print_TensorProduct     z"PrettyPrinter._print_TensorProductc                 C   rB  )Nu   ∧z/\c                 S   rD  rE  rF  rG  r?   r?   r@   rH    rI  z3PrettyPrinter._print_WedgeProduct.<locals>.<lambda>rJ  rL  )r=   rE   Zwedge_symbolr?   r?   r@   _print_WedgeProduct  rN  z!PrettyPrinter._print_WedgeProductc                 C   s<   |  |j}t|dd }| d |_t|d }|S )Nra   rb   r   tr)rJ   r   r   rU   r   r   rV   )r=   rO   r3  r?   r?   r@   _print_Trace  s
   zPrettyPrinter._print_Tracec                 C   s   ddl m} t|j|r%|jjr%|jjr%| 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 )
Nr   MatrixSymbolz_%d%d, 	delimiterr6  r7  rV   re   r   )sympy.matricesrS  r7   parentr+   Z	is_numberr5   rJ   r   rZ   r   rU   rS   r   r   r   
prettyFunc
prettyArgs)r=   rE   rS  rZ  ZprettyIndicesrX   r?   r?   r@   _print_MatrixElement%  s,   
z"PrettyPrinter._print_MatrixElementc                    s   ddl m}  |j}t|j|st|  } 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   rR  c                    sT   t | } | d dkr| d= | d dkrd| d< | d |kr!d| d< t j| dd S )Nr   r^   r   r   :rU  )r   r   rS   )r   dimrH   r?   r@   ppslice@  s   z1PrettyPrinter._print_MatrixSlice.<locals>.ppslicerT  rU  r6  r7  rW  r   )rX  rS  rJ   rY  r7   r   rU   rS   Zrowslicer-  Zcolslicer.  r   r   r   rZ  r[  )r=   mrS  rZ  r_  r[  rX   r?   rH   r@   _print_MatrixSlice:  s,   	
z PrettyPrinter._print_MatrixSlicec                 C   sV   |j }| |}ddlm}m} t||s#t||s#|jr#t|  }|td }|S )Nr   rS  r<  T)	r   rJ   rX  rS  r<  r7   r=  r   rU   )r=   rE   r@  rX   rS  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||s1t||s1|j	r1t|
  }|| }|S )NDaggerr   r   rb  )r   rJ   rI   r   r   rX  rS  r<  r7   r=  rU   )r=   rE   r@  rX   ZdagrS  r<  r?   r?   r@   _print_Adjoint_  s   

zPrettyPrinter._print_Adjointc                 C   s(   |j jdkr| |j d S | |j S )Nr^   r^   r   r   )r?  shaperJ   )r=   Br?   r?   r@   _print_BlockMatrixm  s   z PrettyPrinter._print_BlockMatrixc                 C   s   d }|j D ]8}| |}|d u r|}q| d }t| r-tt|d }| |}ntt|d }tt|| }q|S )Nr   r    + )rT   rJ   Zas_coeff_mmulr   could_extract_minus_signr   r   r   )r=   rE   r   itemrX   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 ]'\}}t	|t
|||fr;t|jdkr;t| |  ||< q| |||< qtj| S )Nr   HadamardProduct)KroneckerProductMatAddr^   )r   rT   #sympy.matrices.expressions.hadamardrr  Z$sympy.matrices.expressions.kroneckerrs  !sympy.matrices.expressions.mataddru  	enumerater7   r   r   r   rJ   rU   __mul__)r=   rE   rT   rr  rs  ru  r+   ar?   r?   r@   _print_MatMul  s   

zPrettyPrinter._print_MatMulc                 C      | j r	ttdS tdS )NZIdentityMatrixIrI   r   r   rD   r?   r?   r@   _print_Identity     zPrettyPrinter._print_Identityc                 C   r|  )NZ
ZeroMatrix0r~  rD   r?   r?   r@   _print_ZeroMatrix  r  zPrettyPrinter._print_ZeroMatrixc                 C   r|  )NZ	OneMatrix1r~  rD   r?   r?   r@   _print_OneMatrix  r  zPrettyPrinter._print_OneMatrixc                 C   s4   t |j}t|D ]\}}| |||< q	tj| S rB   )r   rT   rx  rJ   r   ry  r=   rE   rT   r+   rz  r?   r?   r@   _print_DotProduct  s   

zPrettyPrinter._print_DotProductc                 C   sL   |  |j}ddlm} t|j|s|jjrt|  }||  |j }|S )Nr   rR  )	rJ   baserX  rS  r7   r=  r   rU   exp)r=   rE   rX   rS  r?   r?   r@   _print_MatPow  s   zPrettyPrinter._print_MatPowc                    sZ   ddl m  ddlm ddlm | jrtd}nd}| j|j	d d | fddd	S )
Nr   rq  rt  MatMulRingrC  c                    s   t |  fS rB   r7   rG  rr  ru  r  r?   r@   rH    rI  z6PrettyPrinter._print_HadamardProduct.<locals>.<lambda>rJ  )
rv  rr  rw  ru  !sympy.matrices.expressions.matmulr  rI   r   rS   rT   r=   rE   delimr?   r  r@   _print_HadamardProduct  s   
z$PrettyPrinter._print_HadamardProductc                 C   sp   | j rtd}n| d}| |j}| |j}t|jtd k r(t|  }tt	
||dtji}|| S )Nr  .r   r   )rI   r   rJ   r  r  r   r   r   rU   r   r   r   )r=   rE   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rdtd d}nd}| j|jd d | fddd	S )
Nr   rt  r  r   ZTensorProductz x c                    s   t |  fS rB   r  rG  ru  r  r?   r@   rH    s    z7PrettyPrinter._print_KroneckerProduct.<locals>.<lambda>rJ  )rw  ru  r  r  rI   r   rS   rT   r  r?   r  r@   _print_KroneckerProduct  s   z%PrettyPrinter._print_KroneckerProductc                 C   s"   |  |jj}t|dd }|S Nr6  r7  )rJ   lamdarE   r   rU   )r=   Xr3  r?   r?   r@   _print_FunctionMatrix  s   z#PrettyPrinter._print_FunctionMatrixc                 C   sP   |j dks|j |j}}t|t|ddddd}| |S | d| |j S )Nr^   r'  Fevaluate)r   denr   r
   
_print_MulrJ   )r=   rE   r   r  resr?   r?   r@   _print_TransferFunction  s
   

z%PrettyPrinter._print_TransferFunctionc                 C   s>   t |j}t|jD ]\}}t| |  ||< q
tj| S rB   )r   rT   rx  r   rJ   rU   ry  r  r?   r?   r@   _print_Series  s   

zPrettyPrinter._print_Seriesc                 C   s   ddl m} t|j}g }t|D ]5}t||r5t|jdkr5| |}| d |_	|
t|   q| |}| d |_	|
| qtj| S )Nr   )MIMOParallelr^   r   )sympy.physics.control.ltir  r   rT   r   r7   r   rJ   r   r   r  r   rU   ry  )r=   rE   r  rT   Zpretty_argsrz  Z
expressionr?   r?   r@   _print_MIMOSeries  s   



zPrettyPrinter._print_MIMOSeriesc                 C   sh   d }|j D ],}| |}|d u r|}qtt| }| d |_tt|d }tt|| }q|S )Nr   rl  )rT   rJ   r   r   r   r   r   )r=   rE   r   rn  rX   r?   r?   r@   _print_Parallel  s   

zPrettyPrinter._print_Parallelc                 C   s   ddl m} d }|jD ]8}| |}|d u r|}qtt| }| d |_tt|d }t	||r;| d |_tt|| }q|S )Nr   )TransferFunctionMatrixr   rl  r^   )
r  r  rT   rJ   r   r   r   r   r   r7   )r=   rE   r  r   rn  rX   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|r,t|jjn|jg}t||rEt|j|rE|g ||R  }nYt||ret|j|re|j|krZ|| }nD|g ||jR  }n9t||rt|j|r||kry|| }n%||g|R  }n||kr|| }n|j|kr|| }n	|g ||R  }t	t
| | }	|	 d |	_|jdkrt	t
|	d nt	t
|	d }	t	t
|	| | }	| ||	 S )Nr   )TransferFunctionSeriesr^   r   r'  rl   - )sympy.physics.controlr  r  sys1varr7   r   rT   sys2r   r   r   rJ   r   r   sign)
r=   rE   r  r  r   tfZnum_arg_listZden_arg_listr  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r,tt
d| ntt
d| }tt| }d|_tt
|d }| d |_t|td}t|j|rb| d	 |_tt|| }|S )
Nr   )
MIMOSeriesr  r'  zI + zI - z-1 r   r   r^   )r  r  r  rJ   r  r  r   r   r   r  re   rU   r   r   ry  r7   )r=   rE   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 )Nr^   tauz{t})rJ   Z	_expr_matr   r   rI   r!   r   re   )r=   rE   r@  	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_DrJ   r?  )r=   rE   r<  Arj  Cr3  r@  r?   r?   r@   _print_StateSpaceT  s   zPrettyPrinter._print_StateSpacec                 C   s>  ddl m} | jstd||jkrt|jjS g }g }t||r(| 	 }nd|fg}|D ]M\}}t
|j	 }|jdd d |D ]7\}	}
|
dkrU|d|	j  n |
d	krb|d
|	j  n| |
 d }||d |	j  ||	j qDq/|d dr|d dd  |d< n|d dr|d dd  |d< g }dg}g }t|D ]\}}|d d|v r=|}||| d}tdd|v rtt|D ]4}d||< || tddkr||d  dkr|d | tdd d ||  ||d d   } nqn2tdd|v r9|tdd}|d	kr9d||< |d | tdd d ||  ||d d   }|||< qdd |D }tdd |D }d|v rtt|D ]\}}t|dkrr|ddt|d   d||< qWt|D ]\}}|t|||   t|D ]}|d t|kr|t|kr|dt|d d	 dt|d     ||| kr|||   |||  d 7  < q||  || d|d	 t||  d   7  < q|t|kr|dt|d d	 dt|d     ||  d|d	 d  7  < qqxtddd |D S )Nr   )Vectorz:ASCII pretty printing of BasisDependent is not implementedc                 S   s   | d   S Nr   )__str__rG  r?   r?   r@   rH  m      z5PrettyPrinter._print_BasisDependent.<locals>.<lambda>r   r^   r   r'  z(-1) r   rl  r   
z)_extz)_lower_hookc                 S   s   g | ]}| d qS )r  )splitr*  r   r?   r?   r@   r,        z7PrettyPrinter._print_BasisDependent.<locals>.<listcomp>c                 s   s    | ]}t |V  qd S rB   )r   r  r?   r?   r@   	<genexpr>  s    z6PrettyPrinter._print_BasisDependent.<locals>.<genexpr>c                 S   s   g | ]}|d d qS )Nr?   )r*  r   r?   r?   r@   r,        )Zsympy.vectorr  rI   NotImplementedErrorzeror   Z_pretty_formr7   Zseparateitemsr   
componentsr   r  rJ   rU   
startswithrx  r   r   r   r   rfindr   insertr  join)r=   rE   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           	         sd  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 ]e}|d	 ||  d
}t| d d	d	D ]M}t	||d  |j| k r\ n=|rj|| ||d   n%|| |||d   t	||d  dkr||| d	 gg|| d	< | }g ||d < qKq4|d d }| d dkr||g}| |S )Nr   ImmutableMatrixr?   c                 S   s   g | ]}g qS r?   r?   r)  r?   r?   r@   r,    rI  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?   rG  r  r?   r@   rH    r  z0PrettyPrinter._print_NDimArray.<locals>.<lambda>r'  Tr^   r   )
Zsympy.matrices.immutabler  rankrJ   r   ri  	itertoolsproductr  r   )	r=   rE   Z	level_strZshape_rangesr@  Zouter_iZevenZback_outer_iZout_exprr?   r  r@   _print_NDimArray  s8   



zPrettyPrinter._print_NDimArrayc              	   C   sf  t |}t d|  }t d|  }d }d }|D ]}	| |	jd }
|	|v s*|rC||	jkrC|	jr;tt |d }ntt |d }|	|v r_tt |
d }
tt |
| ||	  }
d}nd}|	jrt ||
 }t |d|
   }t |d|
   }nt ||
 }t |d|
   }t |d|
   }|	j}qt|| }t|	| }|S )Nr   r   r   =TF)
r   r   rJ   rT   is_upr   r   re   r   r   )r=   rZ   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  )rT   rZ   get_indicesr  )r=   rE   rZ   r  r?   r?   r@   _print_Tensor  s   zPrettyPrinter._print_Tensorc                 C   s,   |j jd j}|j  }|j}| |||S r  )rE   rT   rZ   r  r  r  )r=   rE   rZ   r  r  r?   r?   r@   _print_TensorElement  s   
z"PrettyPrinter._print_TensorElementc                    s>   |  \}} fdd|D }tj| }|rt|| S |S )Nc                    8   g | ]}t |td  k rt |  n |qS r   r   r   r   rJ   rU   r)  rH   r?   r@   r,        z0PrettyPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr   ry  rV   )r=   rE   r  rT   rX   r?   rH   r@   _print_TensMul  s   

zPrettyPrinter._print_TensMulc                    s    fdd|j D }tj| S )Nc                    r  r   r  r)  rH   r?   r@   r,     r  z0PrettyPrinter._print_TensAdd.<locals>.<listcomp>)rT   r   __add__)r=   rE   rT   r?   rH   r@   _print_TensAdd  s   

zPrettyPrinter._print_TensAddc                 C   s    |j d }|js| }| |S r  )rT   r  rJ   )r=   rE   r   r?   r?   r@   _print_TensorIndex'  s   

z PrettyPrinter._print_TensorIndexc           	      C   s   | j rtd}nd}d }t|jD ]#}| |}t|| }|d u r&|}qt|d }t|| }qt| |j	 dtj
i}t|}t|jdkrX|| t|j }t|tj| }|jd |_tt|| }tj|_|S )Nr   r   r   r   r^   )rI   r"   r   	variablesrJ   r   rV   re   rE   rU   r   r   r   r   r   r   r   r   r   )	r=   r   r   r   variabler   r   r   rX   r?   r?   r@   _print_PartialDerivative-  s0   

z&PrettyPrinter._print_PartialDerivativec                    s  i  t |jD ]-\}}| |j |df< |jdkr#td |df< qttd| |j  |df< qd}d}t|j fddtdD }d }tD ]p}d }	tdD ]K}
 ||
f }|	 ||
 ksjJ ||
 |	  }|d }|| }t|d	|  }t|
d	|  }|	d u r|}	qXt|	d	|  }	t|	| }	qX|d u r|	}qPt|D ]	}t|d	 }qt||	 }qPt|d
d }| d |_tj|_|S )Nr   TZ	otherwiser^   zfor r   c                    s(   g | ] t  fd dtD qS )c                 3   s     | ]} |f   V  qd S rB   r(  r)  )Pr5   r?   r@   r  \  s    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   )rx  rT   rJ   rE   condr   re   r   r   r   rV   r   rU   r   r   r   r   )r=   Zpexprr   ecr0  r1  r2  r3  r+   r4  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  rJ   Zrewrite)r=   Ziter  r?   r?   r@   
_print_ITE  s   zPrettyPrinter._print_ITEc                 C   sP   d }|D ]}|}|d u r|}qt |d }t || }q|d u r&td}|S )NrT  r   )r   re   r   )r=   r  r3  rz  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)rV   re   rV  ifascii_nougly)rV   re   rV  r   )rI   rS   r   r   r   r   )	r=   p1p2rV   re   rV  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 ]} |}|d u r5|}q't|d }t|| }q'| 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                       g | ]}  |qS r?   r  r*  rz  rH   r?   r@   r,    r  z.PrettyPrinter._print_hyper.<locals>.<listcomp>c                    r  r?   r  r*  brH   r?   r@   r,    r  r   r   ra   rb   r^   Fr  r  )apbqrJ   argumentr   r   r  r   r   rV   re   r  rU   r$   r   )r=   rO   r	  r
  r  r3  r  r4  r   r   sztr  addimgr  r?   rH   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 ]} || ||< qCt	d
D ]H}t
|d|f  |d|f  }t	d
D ]0}|||f }	||	  d
 }
||
 |	  }t|	d|
  }	t|	d|  }	|	|||f< qjqSt|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rit|d|  }t|| }||_t|| }|| |_t|d| }|S )Nc                    r  r?   r  r  rH   r?   r@   r,    r  z0PrettyPrinter._print_meijerg.<locals>.<listcomp>rh  c                    r  r?   r  r  rH   r?   r@   r,    r  )r   r^   c                    r  r?   r  r  rH   r?   r@   r,    r  )r^   r   c                    r  r?   r  r  rH   r?   r@   r,    r  rg  r   r   r^   r   z  ra   rb   Gr  r  c                 S   sV   |   |   }|dkr| |fS |dkr| t|d|  fS t| d|   |fS )Nr   r   )r   r   rV   )r  r   diffr?   r?   r@   r  
  s   z,PrettyPrinter._print_meijerg.<locals>.adjustrT  )anZaotherZbmZbotherrJ   r  r   r   r  r   r   r   r   rV   re   r   r  rU   r$   r   r	  r
  ) r=   rO   r  r  Zvpidxr+   r2  r5   r   rV   re   ZD1ZD2r3  r   r   r  r  r  r  r  r  ppZpqpmZpnr  ZpuplZhtr  r?   rH   r@   _print_meijerg  sj   "

zPrettyPrinter._print_meijergc                 C   s"   t tdd}|| |jd  S )NExp1rO   r   )r   r   rJ   rT   )r=   rO   r  r?   r?   r@   _print_ExpBase%  s   zPrettyPrinter._print_ExpBasec                 C   s   t tddS )Nr  rO   )r   r   rN   r?   r?   r@   _print_Exp1+     zPrettyPrinter._print_Exp1ra   rb   c                 C   s   | j |j|j||||dS )N)r   	func_namerV   re   )_helper_print_functionrt   rT   )r=   rO   r   r  rV   re   r?   r?   r@   r   .  s   zPrettyPrinter._print_Functionc                 C      | j |ddS Nr  r  r   rN   r?   r?   r@   _print_mathieuc4  r  zPrettyPrinter._print_mathieucc                 C   r  Nr   r!  r"  rN   r?   r?   r@   _print_mathieus7  r  zPrettyPrinter._print_mathieusc                 C   r  )NzC'r!  r"  rN   r?   r?   r@   _print_mathieucprime:  r  z"PrettyPrinter._print_mathieucprimec                 C   r  )NzS'r!  r"  rN   r?   r?   r@   _print_mathieusprime=  r  z"PrettyPrinter._print_mathieusprimerT  c	                 C   s   |rt |td}|st|dr|j}|r| t|}	n	t| |  }	|rB| 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   rz   zModifier Letter Low Ringr  r   rU  rW  )r   r   hasattrrz   rJ   r   r   rU   rI   r   r   r   r   rS   r   rZ  r[  )r=   rt   rT   r   r  rV  elementwiserV   re   rZ  r  r[  rX   r?   r?   r@   r  @  s8   



z$PrettyPrinter._helper_print_functionc                 C   s$   |j }|j}|g}| j||dddS )Nr   T)rV  r)  )r   rE   r  )r=   rO   rt   r   rT   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,  Betarj  r1  )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_functionsr0  Z'sympy.functions.special.error_functionsr1  r!   )r=   r+  r,  r-  r.  r/  r0  r1  r?   r?   r@   _special_function_classesk  s   z'PrettyPrinter._special_function_classesc                 C   sf   | j D ]&}t||r)|j|jkr)| jrt| j | d   S t| j | d   S q|j}tt|S )Nr   r^   )r6  
issubclassrz   rI   r   r   )r=   rE   clsr  r?   r?   r@   _print_FunctionClass{  s   
z"PrettyPrinter._print_FunctionClassc                 C   
   |  |S rB   )rF   rD   r?   r?   r@   _print_GeometryEntity  s   
z#PrettyPrinter._print_GeometryEntityc                 C   D   |  |jd }| jrt|r| td| |jd S | |S )Nr   zLi_%sr^   rJ   rT   rI   r%   r   r   r=   rO   r  r?   r?   r@   _print_polylog     
zPrettyPrinter._print_polylogc                 C       | j rtd nd}| j||dS )Nr4  r.  r!  rI   r!   r   r=   rO   r  r?   r?   r@   _print_lerchphi     zPrettyPrinter._print_lerchphic                 C   rA  )NetaZdirichlet_etar!  rB  rC  r?   r?   r@   _print_dirichlet_eta  rE  z"PrettyPrinter._print_dirichlet_etac                 C   sZ   | j rtd nd}|jd tju r&t| |jd   }t|| }|S | j	||dS )NthetaZ	Heavisider^   r   r!  )
rI   r!   rT   r   ZHalfr   rJ   rU   rV   r   )r=   rO   r  rX   r?   r?   r@   _print_Heaviside  s   zPrettyPrinter._print_Heavisidec                 C   r  r$  r"  rN   r?   r?   r@   _print_fresnels  r  zPrettyPrinter._print_fresnelsc                 C   r  r   r"  rN   r?   r?   r@   _print_fresnelc  r  zPrettyPrinter._print_fresnelcc                 C   r  )NZAir!  r"  rN   r?   r?   r@   _print_airyai  r  zPrettyPrinter._print_airyaic                 C   r  )NZBir!  r"  rN   r?   r?   r@   _print_airybi  r  zPrettyPrinter._print_airybic                 C   r  )NzAi'r!  r"  rN   r?   r?   r@   _print_airyaiprime  r  z PrettyPrinter._print_airyaiprimec                 C   r  )NzBi'r!  r"  rN   r?   r?   r@   _print_airybiprime  r  z PrettyPrinter._print_airybiprimec                 C   r  )NWr!  r"  rN   r?   r?   r@   _print_LambertW  r  zPrettyPrinter._print_LambertWc                 C   r  )NZCovr!  r"  rN   r?   r?   r@   _print_Covariance  r  zPrettyPrinter._print_Covariancec                 C   r  )NZVarr!  r"  rN   r?   r?   r@   _print_Variance  r  zPrettyPrinter._print_Variancec                 C   r  )Nr  r!  r"  rN   r?   r?   r@   _print_Probability  r  z PrettyPrinter._print_Probabilityc                 C   s   | j |ddddS )Nr%  r6  r7  )r  rV   re   r"  rN   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r#|d jr#|d }| |}tt	||| |ddiS )Nr   ZArrowFromBar -> r^   r   r   r  )
rE   	signaturerI   r   r   Z	is_symbolrJ   r   r   r   )r=   rO   rE   sigarrowZvar_formr?   r?   r@   _print_Lambda  s   
zPrettyPrinter._print_Lambdac                 C   s  |  |j}|jrtdd |jD st|jdkr~t|d }t|jdkr4t||  |j }nt|jrFt||  |jd  }| jrWt|dt	d d }nt|d }t|jdkrqt||  |j }nt||  |jd  }t|
  }t|d	 }|S )
Nc                 s   s    | ]}|t jkV  qd S rB   )r   Zero)r*  r  r?   r?   r@   r        z-PrettyPrinter._print_Order.<locals>.<genexpr>r^   ; r   r   r   rV  O)rJ   rE   pointanyr   r  r   re   rI   r   rU   rV   r=   rE   rX   r?   r?   r@   _print_Order  s"   
zPrettyPrinter._print_Orderc                 C   s   | j r0| |jd |jd  }| |jd }td}t|| }t|d }|| }|S | |jd }| |jd |jd  }| |ddd}|| S )Nr   r^   r   r  r  r   )rI   rJ   rT   r   re   rS   )r=   rO   shiftr   r  rX   r?   r?   r@   _print_SingularityFunction  s   z(PrettyPrinter._print_SingularityFunctionc                 C   rA  )Nr5  rj  r!  rB  rC  r?   r?   r@   _print_beta  rE  zPrettyPrinter._print_betac                 C      d}| j ||dS )NzB'r!  r"  rC  r?   r?   r@   _print_betainc     zPrettyPrinter._print_betaincc                 C   rf  )Nr}  r!  r"  rC  r?   r?   r@   _print_betainc_regularized  rh  z(PrettyPrinter._print_betainc_regularizedc                 C       | j rtd nd}| j||dS Nr3  r!  rB  rC  r?   r?   r@   _print_gamma  rE  zPrettyPrinter._print_gammac                 C   rj  rk  rB  rC  r?   r?   r@   _print_uppergamma  rE  zPrettyPrinter._print_uppergammac                 C   rA  )Nr,  r-  r!  rB  rC  r?   r?   r@   _print_lowergamma  rE  zPrettyPrinter._print_lowergammac                 C   s   | j rYt|jdkr@ttd }| |jd }t|  }| |jd }t|  }|| }t|d }t|| }|S | |jd }t|  }t|td  }|S | 	|S )Nr   r2  r^   r   r   )
rI   r   rT   r   r!   rJ   rU   re   rV   r   )r=   rO   rz  r  crX   r?   r?   r@   _print_DiracDelta
  s    
zPrettyPrinter._print_DiracDeltac                 C   r<  )Nr   zE_%sr^   r=  r>  r?   r?   r@   _print_expint  r@  zPrettyPrinter._print_expintc                 C   sD   t d}t | |j  }t t||dt ji}||_||_|S )Nr1  r   )	r   rS   rT   rU   r   r   r   rZ  r[  )r=   rO   rZ  r[  rX   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   r^   r%  )rJ   rT   r   r  r   rU   rV   )r=   rO   pforma0rX   pforma1r?   r?   r@   _print_elliptic_e2  s   zPrettyPrinter._print_elliptic_ec                 C   s.   |  |jd }t|  }t|d }|S )Nr   K)rJ   rT   r   rU   rV   rW   r?   r?   r@   _print_elliptic_k=  s   zPrettyPrinter._print_elliptic_kc                 C   sJ   |  |jd }|  |jd }| ||}t|  }t|d }|S )Nr   r^   r  )rJ   rT   r  r   rU   rV   )r=   rO   rs  rt  rX   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r'| ||}n| |jd }| j||dd}t|d }t|| }t|  }t|| }|S )NPir   r^   r   Fr  r]  )	rI   r!   rJ   rT   r   r  r   rV   rU   )r=   rO   rZ   rs  rt  rX   Zpforma2Zpformar?   r?   r@   _print_elliptic_piK  s   z PrettyPrinter._print_elliptic_pic                 C       | j r	ttdS | tdS )NphiZGoldenRatiorI   r   r   rJ   r   rD   r?   r?   r@   _print_GoldenRatioZ     z PrettyPrinter._print_GoldenRatioc                 C   r|  )Nr,  Z
EulerGammar~  rD   r?   r?   r@   _print_EulerGamma_  r  zPrettyPrinter._print_EulerGammac                 C   s   |  tdS )Nr  )rJ   r   rD   r?   r?   r@   _print_Cataland  r  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 r^   )rJ   rT   r   r   r   rU   re   r   ra  r?   r?   r@   
_print_Modg  s   zPrettyPrinter._print_Modc                 C   s  | j ||d}g g }}dd }t|D ]z\}}|jrM| rM|jdd\}	}
|	dkr3t|
ddi}nt|	 g|
R ddi}| |}|||| q|jr`|j	dkr`|d  || q|j
rv|d	k rv| | }|||| q|jr|t| |   q|| | q|rd
}|D ]}|d ur| dkr nqd}|D ]4}|| d}}|d	k r| d
}}|rtt|jtt|j	 }n| |}|r|||}|||< qtj| S )Nr,   c                 S   sj   |dkr|   dkrd}nd}nd}| jtjks| jtjkr%t|   }n| }t||}t|dtjiS )z'Prepend a minus sign to a pretty form. r   r^   z- r  r  r   )r   r   r   NEGZADDr   rU   r   )rX   r  Z	pform_negr  r?   r?   r@   pretty_negativet  s   z1PrettyPrinter._print_Add.<locals>.pretty_negativeF)Zrationalr'  r  r^   r   T)Z_as_ordered_termsrx  Zis_Mulrm  Zas_coeff_mulr   rJ   r  is_RationalqZ	is_Numberis_Relationalr   rU   r   r9   r  r  )r=   rE   r,   Ztermspformsr  r  r+   r  ro  otherZnegtermrX   Zlargenegativer?   r?   r@   
_print_Addp  sL   






zPrettyPrinter._print_Addc           	         s  ddl m  |j}|d tju stdd |dd  D rIttj|}|d dk}|r5t	ddd|d< t	j
| }|rGt	d|j |j|j}|S g }g }jd	vrW| }nt|j}t| fd
dd}|D ]W}|jr|jr|jjr|jjr|jdkr|t|j|j dd qh|t|j|j  qh|jr|tjur|jdkr|t|j |jdkr|t|j qh|| qh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 )Nr   Quantityc                 s   s    | ]}t |tV  qd S rB   )r7   r   r*  r   r?   r?   r@   r    r\  z+PrettyPrinter._print_Mul.<locals>.<genexpr>r^   z-1r  r  )oldnonec                    s    t |  pt | tot | j S rB   )r7   r
   r  rG  r  r?   r@   rH    s   
 z*PrettyPrinter._print_Mul.<locals>.<lambda>r   r'  Fr  c                    r  r?   r  )r*  ZairH   r?   r@   r,    r  z,PrettyPrinter._print_Mul.<locals>.<listcomp>c                    r  r?   r  )r*  ZbirH   r?   r@   r,    r  )Zsympy.physics.unitsr  rT   r   Oner`  r   maprJ   r   ry  r   r   r   r,   Zas_ordered_factorsr   is_commutativeZis_Powr  r  Zis_negativer  r
   r  r!  r  r	   r  r   )	r=   r  rT   ZstrargsZnegoneobjrz  r  rn  r?   )r  r=   r@   r    sH   (







zPrettyPrinter._print_Mulc           	         sx  |  |}| jd r,| jr,|dkr,| dkr,| dks#|jr,|jr,t|t	d  S t
dd t
dd  }|  |}| dkrO|  ||  d|  S |dkrUdnt|d}t|dkrld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   r^   r  \r   r   r  r   c                 3   s,    | ]}d | d    d |  V  qdS )r   r^   Nr?   r)  Z_zZZ
linelengthr?   r@   r    s
    
z0PrettyPrinter._print_nth_root.<locals>.<genexpr>r   )rJ   r8   rI   r   r   r   r   r   rV   nth_rootr   r9   ljustr   r   r   r  r   re   r   r   r   )	r=   r  r'   ZbprettyZrootsignZrprettyr  Zdiagonalr   r?   r  r@   _print_nth_root  s<   




zPrettyPrinter._print_nth_rootc                 C   s   ddl m} | \}}|jrU|tju rtd| | S ||\}}|tju r?|j	r?|j
s?|js4|jr?| jd r?| ||S |jrU|dk rUtd| t|| dd S |jrgt| |  | |S | || | S )Nr   )fractionr  r1   Fr  )Zsympy.simplify.simplifyr  Zas_base_expr  r   ZNegativeOner   rJ   r  Zis_Atomr   r  r   r8   r  r
   r  rU   __pow__)r=   powerr  r  rO   r   r   r?   r?   r@   
_print_Pow!  s   
"zPrettyPrinter._print_Powc                 C   s   |  |jd S r  )rJ   rT   rD   r?   r?   r@   _print_UnevaluatedExpr3     z$PrettyPrinter._print_UnevaluatedExprc                 C   s   |dkr|dk rt t|t jdS t t|S t|dkrBt|dkrB|dk r6t t|t jdt t| S t t|t t| S d S )Nr^   r   )r   
   )r   r9   r  abs)r=   r  r  r?   r?   r@   Z__print_numer_denom6  s   z!PrettyPrinter.__print_numer_denomc                 C   &   |  |j|j}|d ur|S | |S rB   )!_PrettyPrinter__print_numer_denomr  r  rF   r=   rE   r   r?   r?   r@   _print_RationalH     
zPrettyPrinter._print_Rationalc                 C   r  rB   )r  	numeratordenominatorrF   r  r?   r?   r@   _print_FractionP  r  zPrettyPrinter._print_Fractionc                 C   sh   t |jdkrt|js| |jd | t |j S | jr#tdnd}| j|jd d d| dd dS )	Nr^   r   ZMultiplicationr   r   c                 S      | j p| jp| jS rB   )is_Unionis_Intersectionis_ProductSetsetr?   r?   r@   rH  ^      z1PrettyPrinter._print_ProductSet.<locals>.<lambda>rJ  )r   setsr   rJ   rI   r   rS   )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  }rT  )r   rT   r   rS   )r=   r   r  r?   r?   r@   _print_FiniteSeta  s   zPrettyPrinter._print_FiniteSetc                 C   s   | j rtd}nd}|jjr&|jjr&|jjr|ddd|f}nF|ddd|f}n>|jjr7||d |j |d f}n-|jjrIt|}t|t||f}nt	|dkr`t|}t|t|||d f}nt
|}| |ddd	S )
NDots...r'  r   r^   r   r  r  rT  )rI   r   startis_infinitestopstepZis_positiveiterr   r   r   rS   )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rd}nd}|jr d}nd}| |jd d ||S )	Nr^   r  r  ra   r6  rb   r7  r   )r  endrS   rT   Z	left_openZ
right_openr=   r+   rV   re   r?   r?   r@   _print_Interval~  s   zPrettyPrinter._print_Intervalc                 C   s    d}d}|  |jd d ||S )Nr  r  r   rS   rT   r  r?   r?   r@   _print_AccumulationBounds  s   z'PrettyPrinter._print_AccumulationBoundsc                 C   (   dt dd }| j|jd d |dd dS )Nr   ZIntersectionr   c                 S   r  rB   )r  r  is_Complementr  r?   r?   r@   rH    r  z3PrettyPrinter._print_Intersection.<locals>.<lambda>rJ  r   rS   rT   r=   r   rV  r?   r?   r@   _print_Intersection     z!PrettyPrinter._print_Intersectionc                 C   r  )Nr   Unionr"   c                 S   r  rB   )r  r  r  r  r?   r?   r@   rH    r  z,PrettyPrinter._print_Union.<locals>.<lambda>rJ  r  )r=   r   Zunion_delimiterr?   r?   r@   _print_Union  r  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)rI   r  r   rS   rT   )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   r  rB   )r  r  r  r  r?   r?   r@   rH    s    z1PrettyPrinter._print_Complement.<locals>.<lambda>rJ  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r8| 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 )NSmallElementOfinr^   r   r   rU  r  r  TrV   re   r  rV  c                 3   s.    | ]\}}|d  d |dfD ]}|V  qqdS )r   rT  Nr?   )r*  r  Zsetvr5   innr?   r@   r    s   
 z0PrettyPrinter._print_ImageSet.<locals>.<genexpr>r'  r   )rI   r   r  Z	base_setsrW  rJ   rE   r   rS   r  r   r   )r=   tsfunr  rW  rE   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r,| |j }n| |j}| j r@| |}t	|
  }|jtju rQ| 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  rU  )rI   r   rS   r   r   getattr	conditionrJ   r  r   rU   Zbase_setr   UniversalSetr  )	r=   r  r  Z_andr  r  r  r  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   rU  r  r  Tr  )rI   r   rS   r  rJ   rE   r  r  )r=   r  r  r  rE   Zprodsetsr  r?   r?   r@   _print_ComplexRegion  s   
z"PrettyPrinter._print_ComplexRegionc                 C   sP   |j \}}| jr"dtd d}tt| ||| |ddiS tt|S )Nr   Z	ElementOfr   r  )rT   rI   r   r   r   r   rJ   r   )r=   rO   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rtd}nd}| 	|
 | | S )Nr  r  )r  Zformular   r[  ZbnrJ   Za0rI   r   r  truncate)r=   r   r  r?   r?   r@   _print_FourierSeries	  s   
z"PrettyPrinter._print_FourierSeriesc                 C      |  |jS rB   )r  Zinfiniter=   r   r?   r?   r@   _print_FormalPowerSeries	  rG   z&PrettyPrinter._print_FormalPowerSeriesc                 C   s0   t | |j  }| td}t || S )NZSetExpr)r   rJ   r  rU   r   re   )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st|jjdkrtd|jtju rA|j}||	|d |	|d |	|d |	|f}n|jtj
u sL|jdkr\|d d }|| t|}nt|}| |S )	Nr  r  r   z@Pretty printing of sequences with symbolic bound not implementedr   r   r^   r   )rI   r   r   r  Zfree_symbolsr  r  r   r"  ro  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?   rG  r?   r?   r@   rH  3	  s    zPrettyPrinter.<lambda>c                 C   sx   g }|D ]}|  |}	||rt|	  }	|r|| ||	 q|s)td}
nttj|  }
t|
j|||d }
|
S )Nr   rz  )rJ   r   rU   r  r   r   )r=   seqrV   re   rV  rK  r  r  rn  rX   r   r?   r?   r@   rS   2	  s   


zPrettyPrinter._print_seqc                 C   sL   d }|D ]}|d u r|}qt || }t || }q|d u r$t dS |S )Nr   )r   re   )r=   rV  rT   rX   r   r?   r?   r@   r  F	  s   zPrettyPrinter.joinc                 C      |  |ddS r  rS   )r=   r   r?   r?   r@   r  U	  r  zPrettyPrinter._print_listc                 C   sH   t |dkrtt| |d d }t|jdddd S | |ddS )Nr^   r   r   ra   rb   Trz  )r   r   r   r   rJ   rU   rS   )r=   r  Zptupler?   r?   r@   _print_tupleX	  s   zPrettyPrinter._print_tuplec                 C   r:  rB   )r  rD   r?   r?   r@   _print_Tuple_	     
zPrettyPrinter._print_Tuplec                 C   s`   t | td}g }|D ]}| |}| || }tt|d| }|| q| |ddS )Nr   z: r  r  )	r   keysr   rJ   r   r   r   r  rS   )r=   r   r  r  r   rv  Vr   r?   r?   r@   _print_dictb	  s   
zPrettyPrinter._print_dictc                 C   r:  rB   )r  )r=   r   r?   r?   r@   _print_Dicto	  r  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  Trz  )r   r   r   rS   rU   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  Trz  ra   rb   )	r   r   r   rS   rU   r   r   typerz   r  r?   r?   r@   _print_frozensetz	  s   
zPrettyPrinter._print_frozensetc                 C   r|  )NZUniverser  r~  r  r?   r?   r@   _print_UniversalSet	  r  z!PrettyPrinter._print_UniversalSetc                 C   rA   rB   r   r   )r=   ringr?   r?   r@   _print_PolyRing	  rG   zPrettyPrinter._print_PolyRingc                 C   rA   rB   r  )r=   fieldr?   r?   r@   _print_FracField	  rG   zPrettyPrinter._print_FracFieldc                 C   rA   rB   rC   )r=   elmr?   r?   r@   _print_FreeGroupElement	  rG   z%PrettyPrinter._print_FreeGroupElementc                 C   rA   rB   r  )r=   Zpolyr?   r?   r@   _print_PolyElement	  rG   z PrettyPrinter._print_PolyElementc                 C   rA   rB   r  )r=   fracr?   r?   r@   _print_FracElement	  rG   z PrettyPrinter._print_FracElementc                 C   s&   |j r| |  S | | S rB   )Z
is_aliasedrJ   Zas_polyr  rD   r?   r?   r@   _print_AlgebraicNumber	  s   z$PrettyPrinter._print_AlgebraicNumberc                 C   s:   | j |jdd|jg}t| |  }t|d }|S )Nlexr  ZCRootOf)r  rE   r  r   rS   rU   rV   r=   rE   rT   rX   r?   r?   r@   _print_ComplexRootOf	  s   z"PrettyPrinter._print_ComplexRootOfc                 C   sT   | j |jddg}|jtjur|| |j t| |	  }t|
d }|S )Nr  r  ZRootSum)r  rE   r  r   ZIdentityFunctionr  rJ   r   rS   rU   rV   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))rI   r   r   r   mod)r=   rE   formr?   r?   r@   _print_FiniteField	  s   z PrettyPrinter._print_FiniteFieldc                 C   r|  )Nr  ZZZr~  rD   r?   r?   r@   _print_IntegerRing	  r  z PrettyPrinter._print_IntegerRingc                 C   r|  )NZ	RationalsZQQr~  rD   r?   r?   r@   _print_RationalField	  r  z"PrettyPrinter._print_RationalFieldc                 C   >   | j rtd}nd}|jrt|S | t|d t|j S )NZRealsZRRr   rI   r   Zhas_default_precisionr   rJ   r   r9   	precisionr=   domainprefixr?   r?   r@   _print_RealField	     
zPrettyPrinter._print_RealFieldc                 C   r  )NZ	ComplexesCCr   r  r  r?   r?   r@   _print_ComplexField	  r  z!PrettyPrinter._print_ComplexFieldc                 C   ^   t |j}|jjsttd| |j }|| | |dd}t|	| |j
 }|S Norder=r6  r7  r   symbolsr,   
is_defaultr   re   rJ   r  rS   rV   r  r=   rE   rT   r,   rX   r?   r?   r@   _print_PolynomialRing	     

z#PrettyPrinter._print_PolynomialRingc                 C   r  )Nr  ra   rb   r  r"  r?   r?   r@   _print_FractionField	  r$  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_orderrS   r   rV   rJ   r  )r=   rE   grX   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 )r  )r  r,   r  basisr=   r?   r@   r,  	  s    z6PrettyPrinter._print_GroebnerBasis.<locals>.<listcomp>rT  r6  r7  rW  c                    r  r?   r  r*  genrH   r?   r@   r,   
  r  zdomain=r  )exprsr   r  rU   gensre   rJ   r  r,   rV   ry   rz   )r=   r)  r,  r-  r  r,   rX   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 )Nr^   r   r   r  c              	      s8   g | ]} j  |d  td |d fddqS )r   r  r^   r   rU  )rS   rJ   r   )r*  r  rH   r?   r@   r,  
  s    $z-PrettyPrinter._print_Subs.<locals>.<listcomp>)rJ   rE   r   rU   r   r   r   r   re   rS   r   r  r_  )r=   rO   rX   r   Zrvertr  r?   rH   r@   _print_Subs
  s   zPrettyPrinter._print_Subsc           
      C   s   t |}| |jd }t d|  }t || }t || }t|jdkr+|S |j\}}|}t | |g  }	t t	
||	dt ji}||_|	|_|S )Nr   r   r^   r   )r   rJ   rT   r   r   re   r   rS   rU   r   r   r   rZ  r[  )
r=   rO   rZ   rX   r   r   r`  r   rZ  r[  r?   r?   r@   _print_number_function
  s$   

z$PrettyPrinter._print_number_functionc                 C      |  |dS )Nr%  r0  rN   r?   r?   r@   _print_euler3
  rG   zPrettyPrinter._print_eulerc                 C   r1  )Nr  r2  rN   r?   r?   r@   _print_catalan6
  rG   zPrettyPrinter._print_catalanc                 C   r1  )Nrj  r2  rN   r?   r?   r@   _print_bernoulli9
  rG   zPrettyPrinter._print_bernoullic                 C   r1  )NLr2  rN   r?   r?   r@   _print_lucas>
  rG   zPrettyPrinter._print_lucasc                 C   r1  )Nr  r2  rN   r?   r?   r@   _print_fibonacciA
  rG   zPrettyPrinter._print_fibonaccic                 C   r1  )Nrc  r2  rN   r?   r?   r@   _print_tribonacciD
  rG   zPrettyPrinter._print_tribonaccic                 C   s"   | j r| |td S | |dS )Nr,  Z	stieltjes)rI   r0  r!   rN   r?   r?   r@   _print_stieltjesG
  s   zPrettyPrinter._print_stieltjesc                 C   s   |  |jd }t|td }t||  |jd  }| jr(ttd}ntd}|}t|d|   }t|d|   }t|	|dtj
iS )Nr   r   r^   r2  r   r   r   )rJ   rT   r   re   rI   r   r   rV   r   r   ZPOW)r=   rO   rX   rz  r  r  r  r?   r?   r@   _print_KroneckerDeltaM
  s   z#PrettyPrinter._print_KroneckerDeltac                 C   s   t |dr| d}t|| |  }|S t |drD| d}t|| |j }t|| d }t|| |j }|S t |dr[| d}t|| |j }|S | d S )N
as_booleanzDomain: r  z in r   z
Domain on )r(  rJ   r   re   r<  r   r  )r=   r   rX   r?   r?   r@   _print_RandomDomainZ
  s   






z!PrettyPrinter._print_RandomDomainc                 C   sD   z|j d ur| |j |W S W n	 ty   Y nw | t|S rB   )r  rJ   to_sympyr   reprr=   r  r?   r?   r@   
_print_DMPl
  s   
zPrettyPrinter._print_DMPc                 C   r:  rB   )rA  r@  r?   r?   r@   
_print_DMFu
  r  zPrettyPrinter._print_DMFc                 C      |  t|jS rB   rJ   r   rZ   )r=   objectr?   r?   r@   _print_Objectx
  r  zPrettyPrinter._print_Objectc                 C   s8   t d}| |j}| |j}|||d }t|S )Nz-->r   )r   rJ   r  codomainre   r   )r=   morphismrY  r  rG  tailr?   r?   r@   _print_Morphism{
  s
   zPrettyPrinter._print_Morphismc                 C   s.   |  t|j}| |}t|d|d S )Nr]  r   )rJ   r   rZ   rJ  r   re   )r=   rH  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.categoriesrM  rL  r  rG  )r=   rH  rM  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   rZ   )r*  	componentr?   r?   r@   r,  
  s    z:PrettyPrinter._print_CompositeMorphism.<locals>.<listcomp>r]  r   )r   r  reverser  rJ   rJ  r   re   )r=   rH  circleZcomponent_names_listZcomponent_namesr  rK  r?   r?   r@   _print_CompositeMorphism
  s   

z&PrettyPrinter._print_CompositeMorphismc                 C   rC  rB   rD  )r=   categoryr?   r?   r@   _print_Category
  r  zPrettyPrinter._print_Categoryc                 C   sX   |j s	| tjS | |j }|jr&dtd }| |jd }|||}t|d S )Nr   z==>r   )ZpremisesrJ   r   ZEmptySetZconclusionsr   re   r   )r=   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  rY  )r+   r@   r,  
  s
    
z4PrettyPrinter._print_DiagramGrid.<locals>.<listcomp>)rX  rX  r   r   r5  )r=   rY  rX  matrixr?   rZ  r@   _print_DiagramGrid
  s
   
z PrettyPrinter._print_DiagramGridc                 C   r  r  r  r=   r`  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,  
  s    z2PrettyPrinter._print_SubModule.<locals>.<listcomp>r  r  )r-  rS   )r=   r/  r-  r?   r_  r@   _print_SubModule
  s   zPrettyPrinter._print_SubModulec                 C   s   |  |j|  |j S rB   )rJ   r  r  r=   r/  r?   r?   r@   _print_FreeModule
  rM   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>  rS   _moduler-  ra  r?   rc  r@   _print_ModuleImplementedIdeal
  s    z+PrettyPrinter._print_ModuleImplementedIdealc                 C      |  |j|  |j S rB   )rJ   r  
base_idealr=   Rr?   r?   r@   _print_QuotientRing
  rM   z!PrettyPrinter._print_QuotientRingc                 C   s    |  |j||  |jj S rB   )rJ   r  r>  rg  rh  r?   r?   r@   _print_QuotientRingElement
  s    z(PrettyPrinter._print_QuotientRingElementc                 C   s   |  |j|  |jj S rB   )rJ   datamodulekilled_moduler]  r?   r?   r@   _print_QuotientModuleElement
  s   z*PrettyPrinter._print_QuotientModuleElementc                 C   rf  rB   )rJ   r  rn  ra  r?   r?   r@   _print_QuotientModule
  rM   z#PrettyPrinter._print_QuotientModulec              	   C   sN   |  | }| d |_t|d|  |jdtdd |  |j }|S )Nr   z : z %s> r  )	rJ   Z_sympy_matrixr   r   r   re   r  r   rG  )r=   r   r[  rX   r?   r?   r@   _print_MatrixHomomorphism
  s   z'PrettyPrinter._print_MatrixHomomorphismc                 C   r  rB   rJ   rZ   )r=   Zmanifoldr?   r?   r@   _print_Manifold
  rG   zPrettyPrinter._print_Manifoldc                 C   r  rB   rr  )r=   patchr?   r?   r@   _print_Patch
  rG   zPrettyPrinter._print_Patchc                 C   r  rB   rr  )r=   Zcoordsr?   r?   r@   _print_CoordSystem
  rG   z PrettyPrinter._print_CoordSystemc                 C   s   |j j|j j}| t|S rB   )
_coord_sysr   _indexrZ   rJ   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"   rw  r   rx  rZ   rJ   r   )r=   r   r   r?   r?   r@   _print_BaseVectorField
  s   z$PrettyPrinter._print_BaseVectorFieldc                 C   sn   | j rtd}nd}|j}t|dr%|jj|j j}| |d t	| S | |}t
|  }t
|| S )NZDifferentialr   rw  r   )rI   r   Z_form_fieldr(  rw  r   rx  rZ   rJ   r   r   rU   rV   )r=   r  r   r   ry  rX   r?   r?   r@   _print_Differential
  s   


z!PrettyPrinter._print_Differentialc                 C   s8   |  |jd }t|d|jj  }t|d }|S )Nr   z%s(rb   )rJ   rT   r   rV   ry   rz   re   )r=   r  rX   r?   r?   r@   	_print_Tr
  s   zPrettyPrinter._print_Trc                 C   J   |  |jd }t|  }| jrt|td  }|S t|d }|S )Nr   nurJ   rT   r   rU   rI   rV   r!   rW   r?   r?   r@   _print_primenu
     zPrettyPrinter._print_primenuc                 C   r~  )Nr   Omegar  rW   r?   r?   r@   _print_primeomega  r  zPrettyPrinter._print_primeomegac                 C   s@   |j j dkr| jr| td}|S | td}|S | |S )NZdegreeZDegree   )rZ   rI   rJ   r   chrrF   rW   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   rJ   r   r   r   r   r   r?   r?   r@   _print_AssignmentBase  s
   z#PrettyPrinter._print_AssignmentBasec                 C   r  rB   rr  r  r?   r?   r@   
_print_Str#  rG   zPrettyPrinter._print_StrrB   )F)T)r6  r7  )NNr   F)FNra   rb   )FNrT  Fra   rb   )rz   
__module____qualname____doc__ZprintmethodZ_default_settingsr6   rF   propertyrI   rL   rP   rQ   rY   r[   Z_print_RandomSymbolr]   r_   rg   rm   rp   rq   ru   rw   r|   Z_print_InfinityZ_print_NegativeInfinityZ_print_EmptySetZ_print_NaturalsZ_print_Naturals0Z_print_IntegersZ_print_RationalsZ_print_ComplexesZ_print_EmptySequencer}   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&  r5  r:  rA  rM  rO  rQ  r\  ra  rd  rf  rk  rp  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*  r6  r9  r;  r?  rD  rG  rI  rJ  rK  rL  rM  rN  rO  rQ  rR  rS  rT  rU  rZ  rb  rd  re  rg  ri  rl  rm  rn  rp  rq  rr  ru  rw  rx  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_SeqPerZ_print_SeqAddZ_print_SeqMulrS   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  r3  r4  r5  Z_print_bellr7  r8  r9  r:  r;  r=  rA  rB  rF  rJ  rL  rO  rS  rU  rW  r\  r^  r`  rb  re  rj  rk  ro  rp  rq  rs  ru  rv  rz  r{  r|  r}  r  r  r  r  r  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| w )zReturns a string containing the prettified form of expr.

    For information on keyword arguments see pretty_print function.

    r.   )r(   r8   r    rL   )rE   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  )rE   kwargsr?   r?   r@   pretty_print:  s   +r  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)pydocr  localer  r  encode)rE   r>   r  r  r?   r?   r@   pager_printj  s
    r  )?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'   r  Zpprint_use_unicodeZpprint_try_use_unicoder(   r  r  pprintr  r?   r?   r?   r@   <module>   sb    @                      
-