o
    oh                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	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 d
dlmZmZ ddlmZmZ G dd deZeedd Z G dd deZ!ee!dd Z"dS )zI
A Printer for generating readable representation of most SymPy classes.
    )annotations)Any)SRationalPowBasicMulNumber)_keep_coeff)Integer)
Relational)default_sort_key)sift   )
precedence
PRECEDENCE)Printerprint_function)prec_to_dpsto_strc                   @  s  e Zd ZU dZddddddddZded< i Zd	ed
< dddZd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d d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dLdM Z'dNdO Z(dPdQ Z)dRdS Z*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0d`da Z1dbdc Z2ddde Z3dfdg Z4dhdi Z5djdk Z6dldm Z7dndo Z8dpdq Z9drds Z:dtdu Z;dvdw Z<dxdy Z=dzd{ Z>d|d} Z?d~d Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdddZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd ZaddÄ Zbddń ZcddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjejZkejZlddՄ Zmddׄ Znddل Zoddۄ Zpdd݄ Zqdd߄ Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd 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 ZdS (  
StrPrinter	_sympystrNautoFT)order	full_precsympy_integersabbrevperm_cyclicminmaxzdict[str, Any]_default_settingszdict[str, str]_relationalsc                 C  s4   t ||k s|st ||krd| | S | |S )N(%s))r   _print)selfitemlevelstrict r(   f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/str.pyparenthesize"   s   
zStrPrinter.parenthesizer   c                   s   |  fdd|D S )Nc                      g | ]} | qS r(   r*   .0r%   r&   r$   r(   r)   
<listcomp>)       z(StrPrinter.stringify.<locals>.<listcomp>)join)r$   argssepr&   r(   r/   r)   	stringify(      zStrPrinter.stringifyc                 C  s(   t |tr|S t |trt|S t|S N)
isinstancestrr   reprr$   exprr(   r(   r)   emptyPrinter+   s
   

zStrPrinter.emptyPrinterc           	      C  s   | j ||d}t|}g }|D ]4}| |}|dr'|js'd}|dd  }nd}t||k s2|jr<||d| g q|||g q|d}|dkrOd}|d| S )	Nr   -r   +r"   r     )_as_ordered_termsr   r#   
startswithis_Addextendpopr2   )	r$   r<   r   termsprecltermtsignr(   r(   r)   
_print_Add3   s    

zStrPrinter._print_Addc                 C     dS )NTruer(   r;   r(   r(   r)   _print_BooleanTrueH      zStrPrinter._print_BooleanTruec                 C  rO   )NFalser(   r;   r(   r(   r)   _print_BooleanFalseK   rR   zStrPrinter._print_BooleanFalsec                 C  s   d|  |jd td  S )Nz~%sr   Not)r*   r3   r   r;   r(   r(   r)   
_print_NotN   r6   zStrPrinter._print_Notc                 C  sX   t |j}t|D ]\}}t|tr"|jjtju r"|	d|
| q	| |dtd S )Nr   z & 
BitwiseAnd)listr3   	enumerater8   r   	canonicalrhsr   NegativeInfinityinsertrG   r5   r   )r$   r<   r3   jir(   r(   r)   
_print_AndQ   s   

zStrPrinter._print_Andc                 C     |  |jdtd S )Nz | 	BitwiseOrr5   r3   r   r;   r(   r(   r)   	_print_OrY      zStrPrinter._print_Orc                 C  ra   )Nz ^ 
BitwiseXorrc   r;   r(   r(   r)   
_print_Xor\   re   zStrPrinter._print_Xorc                 C  s   d|  |j| |jdf S )N%s(%s), )r#   functionr5   	argumentsr;   r(   r(   r)   _print_AppliedPredicate_   s   z"StrPrinter._print_AppliedPredicatec                   s*    fdd|j D }|jjdd|  S )Nc                      g | ]}  |qS r(   r#   )r.   or$   r(   r)   r0   d       z+StrPrinter._print_Basic.<locals>.<listcomp>r"   ri   )r3   	__class____name__r2   )r$   r<   rJ   r(   rp   r)   _print_Basicc   s   zStrPrinter._print_Basicc                 C  s(   |j jdkr| |j d  | |j S )N)r   r   )r   r   )blocksshaper#   )r$   Br(   r(   r)   _print_BlockMatrixg   s   zStrPrinter._print_BlockMatrixc                 C  rO   )NCatalanr(   r;   r(   r(   r)   _print_Catalanl   rR   zStrPrinter._print_Catalanc                 C  rO   )Nzoor(   r;   r(   r(   r)   _print_ComplexInfinityo   rR   z!StrPrinter._print_ComplexInfinityc                   sL   t  fdd|j|jfD }|jtju rd| S | |jf7 }d| S )Nc                   rm   r(   rn   r.   r_   rp   r(   r)   r0   s   rq   z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionbase_setr   UniversalSetr#   )r$   sr3   r(   rp   r)   _print_ConditionSetr   s
   zStrPrinter._print_ConditionSetc                   s8   |j }dd |jD }dd fdd|g| D  S )Nc                 S  s$   g | ]}|d  d kr|d n|qS )r   r   r(   r}   r(   r(   r)   r0   {   s   $ z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)ri   c                 3      | ]}  |V  qd S r7   rn   r.   argrp   r(   r)   	<genexpr>|       z/StrPrinter._print_Derivative.<locals>.<genexpr>)r<   variable_countr2   )r$   r<   dexprdvarsr(   rp   r)   _print_Derivativey   s   "zStrPrinter._print_Derivativec                 C  sR   t | td}g }|D ]}d| || || f }|| qdd| S )Nkeyz%s: %s{%s}ri   )sortedkeysr   r#   appendr2   )r$   dr   itemsr   r%   r(   r(   r)   _print_dict~   s   zStrPrinter._print_dictc                 C  
   |  |S r7   )r   r;   r(   r(   r)   _print_Dict      
zStrPrinter._print_Dictc                 C  sV   t |drd| |  S t |dr#d| |j d | |j S d| |j S )N
as_booleanzDomain: setz in z
Domain on )hasattrr#   r   symbolsr   )r$   r   r(   r(   r)   _print_RandomDomain   s   


zStrPrinter._print_RandomDomainc                 C  s
   d|j  S N_namer;   r(   r(   r)   _print_Dummy   r   zStrPrinter._print_Dummyc                 C  rO   )N
EulerGammar(   r;   r(   r(   r)   _print_EulerGamma   rR   zStrPrinter._print_EulerGammac                 C  rO   )NEr(   r;   r(   r(   r)   _print_Exp1   rR   zStrPrinter._print_Exp1c                 C     d|  |j|  |jf S )Nz(%s, %s))r#   r<   condr;   r(   r(   r)   _print_ExprCondPair      zStrPrinter._print_ExprCondPairc                 C     |j jd| |jd  S Nr"   ri   )funcrs   r5   r3   r;   r(   r(   r)   _print_Function   r6   zStrPrinter._print_Functionc                 C  rO   )NGoldenRatior(   r;   r(   r(   r)   _print_GoldenRatio   rR   zStrPrinter._print_GoldenRatioc                 C  r   r   )r   rs   r5   pargsr;   r(   r(   r)   _print_Heaviside   s   zStrPrinter._print_Heavisidec                 C  rO   )NTribonacciConstantr(   r;   r(   r(   r)   _print_TribonacciConstant   rR   z$StrPrinter._print_TribonacciConstantc                 C  rO   NIr(   r;   r(   r(   r)   _print_ImaginaryUnit   rR   zStrPrinter._print_ImaginaryUnitc                 C  rO   )Noor(   r;   r(   r(   r)   _print_Infinity   rR   zStrPrinter._print_Infinityc                   :   fdd d  fdd|jD }d|j|f S )Nc                   :   t | dkr | d S  | d ft| dd   S Nr   r   lenr#   r~   xabrp   r(   r)   
_xab_tostr       z.StrPrinter._print_Integral.<locals>._xab_tostrri   c                      g | ]} |qS r(   r(   r.   rJ   r   r(   r)   r0          z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s)r2   limitsr#   rj   r$   r<   Lr(   r   r$   r)   _print_Integral      zStrPrinter._print_Integralc                 C  s   d}|j \}}}}|jr|jrd}n%|jr|sd}n|jr"|s"d}n|s)|s)d}n|r0|r0d}n|r5d}nd}|jdi |||dS )NzInterval{m}({a}, {b})rA   z.openz.Lopenz.Ropen)abmr(   )r3   is_infiniteformat)r$   r_   finr   r   rJ   rr   r(   r(   r)   _print_Interval   s    

zStrPrinter._print_Intervalc                 C  r   )NzAccumBounds(%s, %s))r#   r   r   )r$   r_   r(   r(   r)   _print_AccumulationBounds   s   
z$StrPrinter._print_AccumulationBoundsc                 C     d|  |jtd  S )Nz%s**(-1)r   r*   r   r   )r$   r   r(   r(   r)   _print_Inverse      zStrPrinter._print_Inversec                 C  sB   |j }|j}t|dkr|d jr|d }d| || |f S )Nr   r   zLambda(%s, %s))r<   	signaturer   	is_symbolr#   )r$   objr<   sigr(   r(   r)   _print_Lambda   s
   zStrPrinter._print_Lambdac                   s2   t |jtd}|jjdd fdd|D   S )Nr   r"   ri   c                 3  r   r7   rn   r   rp   r(   r)   r      r   z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)r   r3   r   r   rs   r2   r$   r<   r3   r(   rp   r)   _print_LatticeOp   s   $zStrPrinter._print_LatticeOpc                 C  s*   |j \}}}}dtt| j||||f S )NzLimit(%s, %s, %s, dir='%s'))r3   r~   mapr#   )r$   r<   ezz0dirr(   r(   r)   _print_Limit   s   zStrPrinter._print_Limitc                 C  s   d|  |d S )N[%s]ri   )r5   r;   r(   r(   r)   _print_list      zStrPrinter._print_listc                 C  r   r7   )r   r;   r(   r(   r)   _print_List   r   zStrPrinter._print_Listc                 C  s
   | | S r7   )_format_strr;   r(   r(   r)   _print_MatrixBase   r   zStrPrinter._print_MatrixBasec                 C  s2   | j |jtd ddd| |j| |jf  S )NAtomTr'   z[%s, %s])r*   parentr   r#   r_   r^   r;   r(   r(   r)   _print_MatrixElement   s   zStrPrinter._print_MatrixElementc                   sN    fdd} j |jtd ddd ||j|jj d ||j|jj d S )	Nc                   sZ   t | } | d dkr| d= | d dkrd| d< | d |kr!d| d< d fdd| D S )N   r   r   rA   :c                 3  r   r7   rn   r   rp   r(   r)   r      r   zBStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<genexpr>)rX   r2   )xdimrp   r(   r)   strslice   s   z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [ri   ])r*   r   r   rowslicerowscolslicecols)r$   r<   r   r(   rp   r)   _print_MatrixSlice   s   	zStrPrinter._print_MatrixSlicec                 C     |j S r7   r   r;   r(   r(   r)   _print_DeferredVector     z StrPrinter._print_DeferredVectorc                   s  t | |j}|d tju stdd |dd  D rt|dd dd\}}t|D ]0\}}|jjr7|j }nt	|jj}|d  |d< t
|}|d rUt|j|d	d
n|j||< q*g }	|rs|d jss|d  rs|dg}	|	 fdd|D  }
|
sdg}
t|dkr|d  r|dg}	ng }	|	 fdd|D  }d|
}d|}t|dkrd||f S |rd||f S |S | \}}|dk rt| |}d}nd}g }g }g }jdvr| }nt
|}dd }|D ]s}|jr?t|tr?t|j d dk r?|jtjur||| qt|jd jdkr8t|jt
tfr8|| ||j q|jrf|tjurf|j dkrW|t!|j  |j"dkre|t!|j" q|| q|prtjg} fdd|D } fdd|D }|D ]}|j|v rd||#|j  ||#|j< q|s|d| S t|dkr|d| d |d  S |d| dd|  S )Nr   c                 s  s4    | ]}t |tp|jotd d |jD V  qdS )c                 s  s    | ]}|j V  qd S r7   )
is_Integer)r.   air(   r(   r)   r     s    z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>N)r8   r	   is_Powallr3   r.   r   r(   r(   r)   r     s    

z(StrPrinter._print_Mul.<locals>.<genexpr>r   c                 S  s    t | tot| j d dk S Nr   )r8   r   boolexpas_coeff_Mul)r   r(   r(   r)   <lambda>  s    z'StrPrinter._print_Mul.<locals>.<lambda>T)binaryFevaluatec                      g | ]
}j | d dqS Fr   r,   r  rI   r$   r(   r)   r0   #      z)StrPrinter._print_Mul.<locals>.<listcomp>1c                   r  r  r,   r  r  r(   r)   r0   -  r  *z%s/(%s)%s/%sr?   rA   )oldnonec                 S  sv   |   \}}tt|}|d tju r|dd  }n|d  |d< t|}t| tr4| j	||ddS | j	|ddS )Nr   r   Fr  )
as_base_exprX   r   	make_argsr   NegativeOne
_from_argsr8   r   r   )r_   r   r   eargsr(   r(   r)   apowK  s   

z#StrPrinter._print_Mul.<locals>.apowc                   r  r  r,   r.   r   r  r(   r)   r0   l      c                   r  r  r,   r  r  r(   r)   r0   m  r  r"   /z/(%s))$r   r3   r   Oneanyr   rY   r	  	is_NumberrX   r   r  r   baserE   could_extract_minus_signr#   rG   r   r2   r
  r
   r   as_ordered_factorsr  is_commutativer8   r  r  r   is_RationalInfinitypr   qindex)r$   r<   r3   r   nr_   dir   dargsprenfactorsdfactorscrM   r   r   	pow_parenr  r%   a_strb_strr(   r  r)   
_print_Mul  s   




$





 zStrPrinter._print_Mulc                   s|      \}}d}|jr.| \}}|jr |jr t| | d}n|jr.|jr.t| | d}|d fdd jD  S )NrA   r?   r  c                      g | ]
} |t qS r(   r*   r   r   r<   r$   r(   r)   r0     r  z,StrPrinter._print_MatMul.<locals>.<listcomp>)as_coeff_mmul	is_numberas_real_imagis_zerois_negativer
   r2   r3   )r$   r<   r3  r   rM   reimr(   r:  r)   _print_MatMul{  s   zStrPrinter._print_MatMulc                 C  s   d |j| |jS )Nz{}.({}))r   rj   r#   r<   r;   r(   r(   r)   _print_ElementwiseApplyFunction  s   
z*StrPrinter._print_ElementwiseApplyFunctionc                 C  rO   )Nnanr(   r;   r(   r(   r)   
_print_NaN  rR   zStrPrinter._print_NaNc                 C  rO   )Nz-oor(   r;   r(   r(   r)   _print_NegativeInfinity  rR   z"StrPrinter._print_NegativeInfinityc                 C  sh   |j rtdd |jD r*t|j dkrd| |j S d| |jf|j  dd S d| |jdd S )Nc                 s  s    | ]}|t ju V  qd S r7   )r   Zero)r.   r*  r(   r(   r)   r     r   z*StrPrinter._print_Order.<locals>.<genexpr>r   zO(%s)ri   r   )	variablesr  pointr   r#   r<   r5   r3   r;   r(   r(   r)   _print_Order  s
   zStrPrinter._print_Orderc                 C     |  S r7   __str__r;   r(   r(   r)   _print_Ordinal     zStrPrinter._print_Ordinalc                 C  rK  r7   rL  r;   r(   r(   r)   _print_Cycle  rO  zStrPrinter._print_Cyclec                 C  sZ  ddl m}m} ddlm} |j}|d ur"|d| ddddd	 n| jd
d}|rf|js0dS |||jd 	 t
dd  }|d}|dks^d||d  vr^||d  |d |  }|dd}|S | }|s|jdk ryd| |j S d| |j S | |jd |d d  d| |j  }| |j }	}
t
|t
|
k r|}	d|	 S )Nr   )PermutationCycle)sympy_deprecation_warningzw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclic   )deprecated_since_versionactive_deprecations_target
stacklevelr   Tz()r   rR  (,rA      zPermutation(%s)zPermutation([], size=%s)z	, size=%s) sympy.combinatorics.permutationsrQ  rR  sympy.utilities.exceptionsrS  print_cyclic	_settingsgetsize__repr__r   rfindreplacesupportr#   
array_form)r$   r<   rQ  rR  rS  r   r   lasttrimusefullr(   r(   r)   _print_Permutation  s@   
"

,zStrPrinter._print_Permutationc                 C  sJ   |j \}}}t|jdkr|d }|d }d| || || |f S )Nr   r   zSubs(%s, %s, %s))r3   r   rI  r#   )r$   r   r<   r  newr(   r(   r)   _print_Subs  s   zStrPrinter._print_Subsc                 C  rK  r7   rn   r;   r(   r(   r)   _print_TensorIndex  rO  zStrPrinter._print_TensorIndexc                 C  rK  r7   rn   r;   r(   r(   r)   _print_TensorHead  rO  zStrPrinter._print_TensorHeadc                 C  rK  r7   rn   r;   r(   r(   r)   _print_Tensor  rO  zStrPrinter._print_Tensorc                   s*      \}}|d fdd|D  S )Nr  c                   r8  r(   r9  r   r:  r(   r)   r0     r  z-StrPrinter._print_TensMul.<locals>.<listcomp>)!_get_args_for_traditional_printerr2   )r$   r<   rM   r3   r(   r:  r)   _print_TensMul  s   zStrPrinter._print_TensMulc                 C  rK  r7   rn   r;   r(   r(   r)   _print_TensAdd  rO  zStrPrinter._print_TensAddc                 C     |  |jS r7   r#   r   r;   r(   r(   r)   _print_ArraySymbol     zStrPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz%s[%s]FuncTri   c                   rm   r(   rn   r}   rp   r(   r)   r0     rq   z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r*   r   r   r2   indicesr;   r(   rp   r)   _print_ArrayElement  s   *zStrPrinter._print_ArrayElementc                   s"    fdd|j D }dd| S )Nc                   s   g | ]	}d   | qS )z    %srn   r  rp   r(   r)   r0     s    z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r3   r2   )r$   r<   r*  r(   rp   r)   _print_PermutationGroup  s   z"StrPrinter._print_PermutationGroupc                 C  rO   )Npir(   r;   r(   r(   r)   	_print_Pi  rR   zStrPrinter._print_Pic                   4   dd  fdd|jD  |j |jf S )Nz+Polynomial ring in %s over %s with %s orderri   c                 3  r   r7   rn   )r.   rsrp   r(   r)   r     r   z-StrPrinter._print_PolyRing.<locals>.<genexpr>r2   r   r#   domainr   )r$   ringr(   rp   r)   _print_PolyRing  
   zStrPrinter._print_PolyRingc                   r~  )Nz3Rational function field in %s over %s with %s orderri   c                 3  r   r7   rn   )r.   fsrp   r(   r)   r      r   z.StrPrinter._print_FracField.<locals>.<genexpr>r  r$   fieldr(   rp   r)   _print_FracField  r  zStrPrinter._print_FracFieldc                 C  rK  r7   rL  )r$   elmr(   r(   r)   _print_FreeGroupElement  rO  z"StrPrinter._print_FreeGroupElementc                 C  s   d|j |jf S )Nz(%s + %s*I))r   yr$   polyr(   r(   r)   _print_GaussianElement  r   z!StrPrinter._print_GaussianElementc                 C  s   | | tddS )N%s**%sr  )r9   r   r  r(   r(   r)   _print_PolyElement	  r   zStrPrinter._print_PolyElementc                 C  sN   |j dkr| |jS | j|jtd dd}| j|j td dd}|d | S )Nr   r   Tr   r   r   )denomr#   numerr*   r   )r$   fracr  r  r(   r(   r)   _print_FracElement  s
   
zStrPrinter._print_FracElementc                   sD  t d d  g  fdd|jD }}| D ]\}}g }t|D ]\}}|dkrA|dkr6|||  q"||| d|   q"d|}|jr\|rVd| d	 }	n'|}	n!|rx|tj	u rk|
d
|g q|tju rx|
d|g q|}	|s|	}
n|	d | }
|
dr|
d|
dd  g q|
d
|
g q|d dv r|d}|dkrd|d  |d< |jjd }ddlm} z
|d|  7 }W n |y   |d|  7 }Y nw |d	7 }t|D ]-\}}t|dkr|d d dkr|t|d d  d	kr|dt|d  ||< q|d|d|f S )Nr   r   c                   r+   r(   r,   )r.   r   	ATOM_PRECr$   r(   r)   r0     r1   z*StrPrinter._print_Poly.<locals>.<listcomp>r   z**%dr  rX  )r@   r?   )r?   r@   z(%s, %s)PolynomialErrorz, modulus=%sz, domain='%s'r   rB   ri   )r   gensrH   rY   r   r2   rE   r#   r   r!  rF   r  rD   rG   rr   rs   sympy.polys.polyerrorsr  get_modulus
get_domainr   )r$   r<   rH   r  monomcoeffs_monomr_   r   s_coeffs_termmodifierr   r  r,  r%   r(   r  r)   _print_Poly  s\   





:zStrPrinter._print_Polyc                 C  rO   )Nr   r(   )r$   r*  r(   r(   r)   _print_UniversalSetV  rR   zStrPrinter._print_UniversalSetc                 C  s&   |j r| |  S | | S r7   )
is_aliasedr#   as_polyas_exprr;   r(   r(   r)   _print_AlgebraicNumberY  s   z!StrPrinter._print_AlgebraicNumberc                   s  t |}|jtju r|sd |j S |jrI|j tju r1|s1dt fddtj|jfD  S |jtj u rId tj j	|j|ddf S  j	|j|dd} j
dkrw|jjrw|jjd	krw|d
rwd j	|j|dd|d	d f S d j	|j|dd|f S )a$  Printing helper function for ``Pow``

        Parameters
        ==========

        rational : bool, optional
            If ``True``, it will not attempt printing ``sqrt(x)`` or
            ``x**S.Half`` as ``sqrt``, and will use ``x**(1/2)``
            instead.

            See examples for additional details

        Examples
        ========

        >>> from sympy import sqrt, StrPrinter
        >>> from sympy.abc import x

        How ``rational`` keyword works with ``sqrt``:

        >>> printer = StrPrinter()
        >>> printer._print_Pow(sqrt(x), rational=True)
        'x**(1/2)'
        >>> printer._print_Pow(sqrt(x), rational=False)
        'sqrt(x)'
        >>> printer._print_Pow(1/sqrt(x), rational=True)
        'x**(-1/2)'
        >>> printer._print_Pow(1/sqrt(x), rational=False)
        '1/sqrt(x)'

        Notes
        =====

        ``sqrt(x)`` is canonicalized as ``Pow(x, S.Half)`` in SymPy,
        so there is no need of defining a separate printer for ``sqrt``.
        Instead, it should be handled here as well.
        zsqrt(%s)z%s/sqrt(%s)c                 3  r   r7   rn   r   rp   r(   r)   r     r   z(StrPrinter._print_Pow.<locals>.<genexpr>r  Fr   
_sympyreprr   z	(Rationalr  r[  )r   r	  r   Halfr#   r$  r'  r~   r!  r*   printmethodr(  r+  rD   )r$   r<   rationalPRECr   r(   rp   r)   
_print_Pow_  s   &"
"zStrPrinter._print_Powc                 C  s   |  |jd S r  r#   r3   r;   r(   r(   r)   _print_UnevaluatedExpr  r   z!StrPrinter._print_UnevaluatedExprc                 C  s0   t |}d| j|j|dd| j|j|ddf S )Nr  Fr   )r   r*   r$  r	  )r$   r<   r  r(   r(   r)   _print_MatPow  s   zStrPrinter._print_MatPowc                 C  s    | j ddrd| S t|jS )Nr   FzS(%s))r_  r`  r9   r*  r;   r(   r(   r)   _print_Integer  s   
zStrPrinter._print_Integerc                 C  rO   )NIntegersr(   r;   r(   r(   r)   _print_Integers  rR   zStrPrinter._print_Integersc                 C  rO   )NNaturalsr(   r;   r(   r(   r)   _print_Naturals  rR   zStrPrinter._print_Naturalsc                 C  rO   )N	Naturals0r(   r;   r(   r(   r)   _print_Naturals0  rR   zStrPrinter._print_Naturals0c                 C  rO   )N	Rationalsr(   r;   r(   r(   r)   _print_Rationals  rR   zStrPrinter._print_Rationalsc                 C  rO   )NRealsr(   r;   r(   r(   r)   _print_Reals  rR   zStrPrinter._print_Realsc                 C  rO   )N	Complexesr(   r;   r(   r(   r)   _print_Complexes  rR   zStrPrinter._print_Complexesc                 C  rO   )NEmptySetr(   r;   r(   r(   r)   _print_EmptySet  rR   zStrPrinter._print_EmptySetc                 C  rO   )NEmptySequencer(   r;   r(   r(   r)   _print_EmptySequence  rR   zStrPrinter._print_EmptySequencec                 C     t |S r7   r9   r;   r(   r(   r)   
_print_int  rO  zStrPrinter._print_intc                 C  r  r7   r  r;   r(   r(   r)   
_print_mpz  rO  zStrPrinter._print_mpzc                 C  sB   |j dkr
t|jS | jddrd|j|j f S d|j|j f S )Nr   r   FzS(%s)/%sr  )r+  r9   r*  r_  r`  r;   r(   r(   r)   _print_Rational  s
   

zStrPrinter._print_Rationalc                 C  $   |j dkr
t|jS d|j|j f S )Nr   z%d/%d)r+  r9   r*  r;   r(   r(   r)   _print_PythonRational     

z StrPrinter._print_PythonRationalc                 C  r  Nr   r  denominatorr9   	numeratorr;   r(   r(   r)   _print_Fraction  r  zStrPrinter._print_Fractionc                 C  r  r  r  r;   r(   r(   r)   
_print_mpq  r  zStrPrinter._print_mpqc                 C  s   |j }|dk r
d}nt|j }| jd du rd}n| jd du r#d}n| jd dkr/| jdk}d| jv r9| jd nd }d	| jv rE| jd	 nd }t|j||||d
}|dr_d|dd   }n|drld|dd   }|drw|dd  }|S )NrZ  r   r   TFr   r   r   r   )strip_zeros	min_fixed	max_fixedz-.0z-0.   z.0z0.r   r@   )_precr   r_  _print_levelmlib_to_str_mpf_rD   )r$   r<   rI   dpsstriplowhighrvr(   r(   r)   _print_Float  s(   




zStrPrinter._print_Floatc              	   C  s~   ddddddddd	}|j |v r"d
||j  | |j| |jf S d| |jt|| j|j p4|j | |jt|f S )NEqNe
AssignmentAddAugmentedAssignmentSubAugmentedAssignmentMulAugmentedAssignmentDivAugmentedAssignmentModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=
%s(%s, %s)z%s %s %s)rel_opr#   lhsr[   r*   r   r!   r`  )r$   r<   charmapr(   r(   r)   _print_Relational  s"   

zStrPrinter._print_Relationalc                 C  s   d| j |jdd|jf S )NzCRootOf(%s, %d)lexr>   )rN   r<   r,  r;   r(   r(   r)   _print_ComplexRootOf  s   zStrPrinter._print_ComplexRootOfc                 C  s>   | j |jddg}|jtjur|| |j dd| S )Nr  r>   zRootSum(%s)ri   )rN   r<   funr   IdentityFunctionr   r#   r2   r   r(   r(   r)   _print_RootSum  s   zStrPrinter._print_RootSumc                   s    j j} fdd jD }dd| }fdd jD }d j }d j }|g| ||g }d|d|f S )	Nc                   s   g | ]
}j | jd qS )r>   )rN   r   r   basisr$   r(   r)   r0     r  z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   ri   c                   rm   r(   rn   )r.   genrp   r(   r)   r0      rq   zdomain='%s'z
order='%s'rh   )rr   rs   exprsr2   r  r#   r  r   )r$   r  clsr  r  r  r   r3   r(   r  r)   _print_GroebnerBasis  s   zStrPrinter._print_GroebnerBasisc                   s4   t |td}d fdd|D }|sdS d| S )Nr   ri   c                 3  r   r7   rn   r-   rp   r(   r)   r   +  r   z(StrPrinter._print_set.<locals>.<genexpr>zset()r   )r   r   r2   r$   r   r   r3   r(   rp   r)   
_print_set(  s
   zStrPrinter._print_setc                   sZ   ddl m  t|td}dfdd|D }t fdd|D r(d|S d	|S )
Nr   	FiniteSetr   ri   c                 3  r   r7   rn   r-   rp   r(   r)   r   4  r   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 3  s    | ]}|  V  qd S r7   )hasr-   r  r(   r)   r   5  r   zFiniteSet({})z{{{}}})sympy.sets.setsr  r   r   r2   r"  r   r  r(   )r  r$   r)   _print_FiniteSet0  s   

zStrPrinter._print_FiniteSetc                   s.   t |td}d fdd|D }d|S )Nr   ri   c                 3  r   r7   rn   r   rp   r(   r)   r   <  r   z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))r   r   r2   r   r  r(   rp   r)   _print_Partition9  s   
zStrPrinter._print_Partitionc                 C  s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))r  r$   r   r(   r(   r)   _print_frozenset?  s   zStrPrinter._print_frozensetc                   r   )Nc                   r   r   r   r   rp   r(   r)   r   E  r   z)StrPrinter._print_Sum.<locals>._xab_tostrri   c                   r   r(   r(   r   r   r(   r)   r0   J  r   z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s)r   r   r(   r   r)   
_print_SumD  r   zStrPrinter._print_Sumc                 C  r   r7   r   r;   r(   r(   r)   _print_SymbolM  r  zStrPrinter._print_Symbolc                 C  rO   r   r(   r;   r(   r(   r)   _print_IdentityR  rR   zStrPrinter._print_Identityc                 C  rO   )N0r(   r;   r(   r(   r)   _print_ZeroMatrixU  rR   zStrPrinter._print_ZeroMatrixc                 C  rO   )Nr  r(   r;   r(   r(   r)   _print_OneMatrixX  rR   zStrPrinter._print_OneMatrixc                 C  
   d|j  S )NzQ.%sr   r;   r(   r(   r)   _print_Predicate[  r   zStrPrinter._print_Predicatec                 C  r  r7   r  r;   r(   r(   r)   
_print_str^  rO  zStrPrinter._print_strc                 C  s.   t |dkrd| |d  S d| |d S )Nr   z(%s,)r   r"   ri   )r   r#   r5   r;   r(   r(   r)   _print_tuplea  s   zStrPrinter._print_tuplec                 C  r   r7   )r
  r;   r(   r(   r)   _print_Tupleg  r   zStrPrinter._print_Tuplec                 C  r   )Nz%s.Tr   r   )r$   Tr(   r(   r)   _print_Transposej  r   zStrPrinter._print_Transposec                 C  r   )NzUniform(%s, %s))r#   r   r   r;   r(   r(   r)   _print_Uniformm  r   zStrPrinter._print_Uniformc                 C  s"   | j ddrd|j S d|j S )Nr   Fz%s)r_  r`  r   r   r;   r(   r(   r)   _print_Quantityp  s   

zStrPrinter._print_Quantityc                   sD    fdd|j D }|d gdd t|dd  dD  }d|S )Nc                   s    g | ]} j |td  ddqS )r   Tr   )r*   r   r}   rp   r(   r)   r0   v  s     z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | qS )r  r(   )r.   r_   r^   r(   r(   r)   r0   w  r  r   ijkz + )r3   zipr2   )r$   r<   r   r   r(   rp   r)   _print_Quaternionu  s   &
zStrPrinter._print_Quaternionc                 C  r  r7   r  r;   r(   r(   r)   _print_Dimensionz  rO  zStrPrinter._print_Dimensionc                 C  
   |j d S r   r   r;   r(   r(   r)   _print_Wild}  r   zStrPrinter._print_Wildc                 C  r  r   r   r;   r(   r(   r)   _print_WildFunction  r   zStrPrinter._print_WildFunctionc                 C  r   r7   r   r;   r(   r(   r)   _print_WildDot  r  zStrPrinter._print_WildDotc                 C  r   r7   r   r;   r(   r(   r)   _print_WildPlus  r  zStrPrinter._print_WildPlusc                 C  r   r7   r   r;   r(   r(   r)   _print_WildStar  r  zStrPrinter._print_WildStarc                 C  s    | j ddr	dS | tdS )Nr   FzS(0)r   )r_  r`  r  r   r;   r(   r(   r)   _print_Zero  s   zStrPrinter._print_Zeroc                 C  s0   |j j}| | }| |j}d|||f S Nr  )rr   rs   r#   to_listdom)r$   r*  r  repr  r(   r(   r)   
_print_DMP  s   zStrPrinter._print_DMPc                 C  s<   |j j}| |j}| |j}| |j}d||||f S )Nz%s(%s, %s, %s))rr   rs   r#   numdenr  )r$   r<   r  r   r!  r  r(   r(   r)   
_print_DMF  s
   zStrPrinter._print_DMFc                 C  r  )NzObject("%s")r   )r$   r   r(   r(   r)   _print_Object  r   zStrPrinter._print_Objectc                 C  r  )NzIdentityMorphism(%s))r  r$   morphismr(   r(   r)   _print_IdentityMorphism  r   z"StrPrinter._print_IdentityMorphismc                 C  s   d|j |j|jf S )NzNamedMorphism(%s, %s, "%s"))r  codomainr   r$  r(   r(   r)   _print_NamedMorphism  s   zStrPrinter._print_NamedMorphismc                 C  r  )NzCategory("%s")r   )r$   categoryr(   r(   r)   _print_Category  r   zStrPrinter._print_Categoryc                 C     |j j S r7   r   )r$   manifoldr(   r(   r)   _print_Manifold  rO  zStrPrinter._print_Manifoldc                 C  r+  r7   r   )r$   patchr(   r(   r)   _print_Patch  rO  zStrPrinter._print_Patchc                 C  r+  r7   r   )r$   coordsr(   r(   r)   _print_CoordSystem  rO  zStrPrinter._print_CoordSystemc                 C  s   |j j|j jS r7   
_coord_sysr   _indexr   r  r(   r(   r)   _print_BaseScalarField  r   z!StrPrinter._print_BaseScalarFieldc                 C  s   d|j j|j j S )Nze_%sr2  r  r(   r(   r)   _print_BaseVectorField  re   z!StrPrinter._print_BaseVectorFieldc                 C  s2   |j }t|drd|jj|j j S d| | S )Nr3  zd%szd(%s))_form_fieldr   r3  r   r4  r   r#   )r$   diffr  r(   r(   r)   _print_Differential  s   
zStrPrinter._print_Differentialc                 C  s   dd|  |jd f S )Nrh   Trr   r  r;   r(   r(   r)   	_print_Tr     zStrPrinter._print_Trc                 C  rt  r7   ru  r  r(   r(   r)   
_print_Str  rw  zStrPrinter._print_Strc                 C  s*   |j }d| || |j| |jf S r  )rj   r#   r  r[   )r$   r<   relr(   r(   r)   _print_AppliedBinaryRelation  s
   


z'StrPrinter._print_AppliedBinaryRelation)F)r   r7   )rs   
__module____qualname__r  r    __annotations__r!   r*   r5   r=   rN   rQ   rT   rV   r`   rd   rg   rl   rt   rx   rz   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   r7  rB  rC  rE  rF  rJ  rN  rP  rk  rm  rn  ro  rp  rr  rs  rv  rz  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  _print_MatrixSymbol_print_RandomSymbolr  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  r5  r6  r9  r;  r=  r?  r(   r(   r(   r)   r      s$  
 

		v	)B=		r   c                 K     t |}|| }|S )ab  Returns the expression as a string.

    For large expressions where speed is a concern, use the setting
    order='none'. If abbrev=True setting is used then units are printed in
    abbreviated form.

    Examples
    ========

    >>> from sympy import symbols, Eq, sstr
    >>> a, b = symbols('a b')
    >>> sstr(Eq(a + b, 0))
    'Eq(a + b, 0)'
    )r   doprintr<   settingsr*  r   r(   r(   r)   sstr  s   
rI  c                   @  s    e Zd ZdZdd Zdd ZdS )StrReprPrinterz(internal) -- see sstrreprc                 C  r  r7   )r:   r  r(   r(   r)   r	    rO  zStrReprPrinter._print_strc                 C  s   d|j j| |jf S )Nrh   )rr   rs   r#   r   r  r(   r(   r)   r=    r<  zStrReprPrinter._print_StrN)rs   r@  rA  __doc__r	  r=  r(   r(   r(   r)   rJ    s    rJ  c                 K  rE  )zreturn expr in mixed str/repr form

       i.e. strings are returned in repr form with quotes, and everything else
       is returned in str form.

       This function could be useful for hooking into sys.displayhook
    )rJ  rF  rG  r(   r(   r)   sstrrepr  s   

rL  N)#rK  
__future__r   typingr   
sympy.corer   r   r   r   r   r	   sympy.core.mulr
   sympy.core.numbersr   sympy.core.relationalr   sympy.core.sortingr   sympy.utilities.iterablesr   r   r   printerr   r   mpmath.libmpr   r   r  r   rI  rJ  rL  r(   r(   r(   r)   <module>   s2            D
