o
    *ήc                     @   s  d dl mZ d dlmZ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mZmZmZmZ d dlmZmZ d dl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# G dd deZ$G dd deZ%G dd deZ&G dd deZ'G dd deZ(G dd deZ)G dd deZ*G dd deZ+G dd deZ,G dd deZ-d d! Z.G d"d# d#eZ/d/d%d&Z0d0d(d)Z1d/d*d+Z2d1d-d.Z3d,S )2    )Tuple)SAddMulsympifySymbolDummyBasic)Expr)factor_terms)Function
DerivativeArgumentIndexErrorAppliedUndef
expand_mul)	fuzzy_notfuzzy_or)piIoo)Pow)Eq)sqrt)	Piecewisec                   @   p   e Zd ZU dZee ed< dZdZdZ	e
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S )rea  
    Returns real part of expression. This function performs only
    elementary analysis and so it will fail to decompose properly
    more complicated expressions. If completely simplified result
    is needed then use ``Basic.as_real_imag()`` or perform complex
    expansion on instance of this function.

    Examples
    ========

    >>> from sympy import re, im, I, E, symbols
    >>> x, y = symbols('x y', real=True)
    >>> re(2*E)
    2*E
    >>> re(2*I + 17)
    17
    >>> re(2*I)
    0
    >>> re(im(x) + x*I + 2)
    2
    >>> re(5 + I + 2)
    7

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    Returns
    =======

    expr : Expr
        Real part of expression.

    See Also
    ========

    im
    argsTc                 C   sF  |t ju rt jS |t ju rt jS |jr|S |jst j| jr!t jS |jr*| d S |j	r9t
|tr9t|jd S g g g }}}t|}|D ]9}|t j}|d ur]|js\|| qH|t jsl|jrl|| qH|j|d}|r|||d  qH|| qHt|t|krdd |||fD \}	}
}| |	t|
 | S d S )Nr   ignorec                 s       | ]}t | V  qd S Nr   .0xs r%   K/tmp/pip-target-vg8gfxp4/lib/python/sympy/functions/elementary/complexes.py	<genexpr>i       zre.eval.<locals>.<genexpr>)r   NaNComplexInfinityis_extended_realis_imaginaryImaginaryUnitZero	is_Matrixas_real_imagis_Function
isinstance	conjugater   r   r   	make_argsas_coefficientappendhaslenimclsargincludedrevertedexcludedr   termcoeff	real_imagabcr%   r%   r&   evalD   s<   



zre.evalc                 K   
   | t jfS )zF
        Returns the real number with a zero imaginary part.

        r   r.   selfdeephintsr%   r%   r&   r0   m      
zre.as_real_imagc                 C   `   |j s	| jd j rtt| jd |ddS |js| jd jr.tj tt| jd |dd S d S Nr   Tevaluate)r+   r   r   r   r,   r   r-   r9   rJ   xr%   r%   r&   _eval_derivativet      zre._eval_derivativec                 K   s   | j d tjt| j d   S Nr   )r   r   r-   r9   rJ   r<   kwargsr%   r%   r&   _eval_rewrite_as_im{   s   zre._eval_rewrite_as_imc                 C      | j d jS rV   r   is_algebraicrJ   r%   r%   r&   _eval_is_algebraic~      zre._eval_is_algebraicc                 C   s   t | jd j| jd jgS rV   )r   r   r,   is_zeror]   r%   r%   r&   _eval_is_zero   s   zre._eval_is_zeroc                 C      | j d jrdS d S Nr   Tr   	is_finiter]   r%   r%   r&   _eval_is_finite      zre._eval_is_finitec                 C   rb   rc   rd   r]   r%   r%   r&   _eval_is_complex   rg   zre._eval_is_complexNT)__name__
__module____qualname____doc__tTupler
   __annotations__r+   
unbranched_singularitiesclassmethodrF   r0   rT   rY   r^   ra   rf   rh   r%   r%   r%   r&   r      s   
 )

(r   c                   @   r   )r9   a  
    Returns imaginary part of expression. This function performs only
    elementary analysis and so it will fail to decompose properly more
    complicated expressions. If completely simplified result is needed then
    use ``Basic.as_real_imag()`` or perform complex expansion on instance of
    this function.

    Examples
    ========

    >>> from sympy import re, im, E, I
    >>> from sympy.abc import x, y
    >>> im(2*E)
    0
    >>> im(2*I + 17)
    2
    >>> im(x*I)
    re(x)
    >>> im(re(x) + y)
    im(y)
    >>> im(2 + 3*I)
    3

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    Returns
    =======

    expr : Expr
        Imaginary part of expression.

    See Also
    ========

    re
    r   Tc                 C   sP  |t ju rt jS |t ju rt jS |jrt jS |jst j| jr%t j | S |jr.| d S |j	r>t
|tr>t|jd  S g g g }}}t|}|D ]9}|t j}|d urh|jsb|| qM|| qM|t jsq|js|j|d}|r||d  qM|| qMt|t|krdd |||fD \}	}
}| |	t|
 | S d S )N   r   r   c                 s   r   r    r!   r"   r%   r%   r&   r'      r(   zim.eval.<locals>.<genexpr>)r   r)   r*   r+   r.   r,   r-   r/   r0   r1   r2   r3   r9   r   r   r4   r5   r6   r7   r8   r   r:   r%   r%   r&   rF      s<   



zim.evalc                 K   rG   )zC
        Return the imaginary part with a zero real part.

        rH   rI   r%   r%   r&   r0      rM   zim.as_real_imagc                 C   rN   rO   )r+   r   r9   r   r,   r   r-   r   rR   r%   r%   r&   rT      rU   zim._eval_derivativec                 K   s    t j | jd t| jd   S rV   )r   r-   r   r   rW   r%   r%   r&   _eval_rewrite_as_re       zim._eval_rewrite_as_rec                 C   rZ   rV   r[   r]   r%   r%   r&   r^      r_   zim._eval_is_algebraicc                 C   rZ   rV   r   r+   r]   r%   r%   r&   ra      r_   zim._eval_is_zeroc                 C   rb   rc   rd   r]   r%   r%   r&   rf      rg   zim._eval_is_finitec                 C   rb   rc   rd   r]   r%   r%   r&   rh     rg   zim._eval_is_complexNri   )rj   rk   rl   rm   rn   r
   ro   r+   rp   rq   rr   rF   r0   rT   rt   r^   ra   rf   rh   r%   r%   r%   r&   r9      s   
 )

'r9   c                       s   e Zd ZdZdZdZ fddZe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  ZS )%signa  
    Returns the complex sign of an expression:

    Explanation
    ===========

    If the expression is real the sign will be:

        * $1$ if expression is positive
        * $0$ if expression is equal to zero
        * $-1$ if expression is negative

    If the expression is imaginary the sign will be:

        * $I$ if im(expression) is positive
        * $-I$ if im(expression) is negative

    Otherwise an unevaluated expression will be returned. When evaluated, the
    result (in general) will be ``cos(arg(expr)) + I*sin(arg(expr))``.

    Examples
    ========

    >>> from sympy import sign, I

    >>> sign(-1)
    -1
    >>> sign(0)
    0
    >>> sign(-3*I)
    -I
    >>> sign(1 + I)
    sign(1 + I)
    >>> _.evalf()
    0.707106781186548 + 0.707106781186548*I

    Parameters
    ==========

    arg : Expr
        Real or imaginary expression.

    Returns
    =======

    expr : Expr
        Complex sign of expression.

    See Also
    ========

    Abs, conjugate
    Tc                    s>   t   }|| kr| jd jdu r| jd t| jd  S |S )Nr   F)superdoitr   r`   Abs)rJ   rL   s	__class__r%   r&   ry   C  s   
z	sign.doitc           	      C   sD  |j rX| \}}g }t|}|D ].}|jr| }q|jrq|jr:t|}|jr4|tj	9 }|jr3| }q|
| q|
| q|tju rOt|t|krOd S || |j|  S |tju r`tjS |jrftjS |jrltjS |jrrtjS |jr|t|tr||S |jr|jr|jtju rtj	S tj	 | }|jrtj	S |jrtj	 S d S d S r    )is_Mulas_coeff_mulrw   is_extended_negativeis_extended_positiver,   r9   is_comparabler   r-   r6   Oner8   _new_rawargsr)   r`   r.   NegativeOner1   r2   is_PowexpHalf)	r;   r<   rE   r   unkr{   rC   aiarg2r%   r%   r&   rF   I  sT   


z	sign.evalc                 C   s   t | jd jrtjS d S rV   )r   r   r`   r   r   r]   r%   r%   r&   	_eval_Abs{  s   zsign._eval_Absc                 C   s   t t| jd S rV   )rw   r3   r   r]   r%   r%   r&   _eval_conjugate     zsign._eval_conjugatec                 C   s   | j d jrddlm} dt| j d |dd || j d  S | j d jrBddlm} dt| j d |dd |tj | j d   S d S )Nr   )
DiracDelta   TrP   )r   r+   'sympy.functions.special.delta_functionsr   r   r,   r   r-   )rJ   rS   r   r%   r%   r&   rT     s   zsign._eval_derivativec                 C   rb   rc   )r   is_nonnegativer]   r%   r%   r&   _eval_is_nonnegative  rg   zsign._eval_is_nonnegativec                 C   rb   rc   )r   is_nonpositiver]   r%   r%   r&   _eval_is_nonpositive  rg   zsign._eval_is_nonpositivec                 C   rZ   rV   )r   r,   r]   r%   r%   r&   _eval_is_imaginary  r_   zsign._eval_is_imaginaryc                 C   rZ   rV   rv   r]   r%   r%   r&   _eval_is_integer  r_   zsign._eval_is_integerc                 C   rZ   rV   )r   r`   r]   r%   r%   r&   ra     r_   zsign._eval_is_zeroc                 C   s.   t | jd jr|jr|jrtjS d S d S d S rV   )r   r   r`   
is_integeris_evenr   r   )rJ   otherr%   r%   r&   _eval_power  s   zsign._eval_powerr   c                 C   sV   | j d }||d}|dkr| |S |dkr|||}t|dk r(tj S tjS rV   )r   subsfuncdirr   r   r   )rJ   rS   nlogxcdirarg0x0r%   r%   r&   _eval_nseries  s   

zsign._eval_nseriesc                 K   s&   |j rtd|dkfd|dk fdS d S )Nrs   r   )r   T)r+   r   rW   r%   r%   r&   _eval_rewrite_as_Piecewise  s   zsign._eval_rewrite_as_Piecewisec                 K   s&   ddl m} |jr||d d S d S )Nr   	Heavisider   rs   r   r   r+   rJ   r<   rX   r   r%   r%   r&   _eval_rewrite_as_Heaviside  s   zsign._eval_rewrite_as_Heavisidec                 K   s    t dt|df|t| dfS rc   )r   r   rz   rW   r%   r%   r&   _eval_rewrite_as_Abs  ru   zsign._eval_rewrite_as_Absc                 K   s   |  t| jd S rV   )r   r   r   )rJ   rX   r%   r%   r&   _eval_simplify  s   zsign._eval_simplifyr   )rj   rk   rl   rm   
is_complexrq   ry   rr   rF   r   r   rT   r   r   r   r   ra   r   r   r   r   r   r   __classcell__r%   r%   r|   r&   rw   	  s*    6
1

	rw   c                   @   s   e Zd ZU dZee ed< dZdZdZ	dZ
dZd,ddZe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+S ).rz   ab  
    Return the absolute value of the argument.

    Explanation
    ===========

    This is an extension of the built-in function ``abs()`` to accept symbolic
    values.  If you pass a SymPy expression to the built-in ``abs()``, it will
    pass it automatically to ``Abs()``.

    Examples
    ========

    >>> from sympy import Abs, Symbol, S, I
    >>> Abs(-1)
    1
    >>> x = Symbol('x', real=True)
    >>> Abs(-x)
    Abs(x)
    >>> Abs(x**2)
    x**2
    >>> abs(-x) # The Python built-in
    Abs(x)
    >>> Abs(3*x + 2*I)
    sqrt(9*x**2 + 4)
    >>> Abs(8*I)
    8

    Note that the Python built-in will return either an Expr or int depending on
    the argument::

        >>> type(abs(-1))
        <... 'int'>
        >>> type(abs(S.NegativeOne))
        <class 'sympy.core.numbers.One'>

    Abs will always return a SymPy object.

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    Returns
    =======

    expr : Expr
        Absolute value returned can be an expression or integer depending on
        input arg.

    See Also
    ========

    sign, conjugate
    r   TFrs   c                 C   s    |dkrt | jd S t| |)zE
        Get the first derivative of the argument to Abs().

        rs   r   )rw   r   r   )rJ   argindexr%   r%   r&   fdiff   s   
z	Abs.fdiffc                    s  ddl m} t dr  }|d ur|S t ts"tdt  | dd   \}}|j	r<|j	s<| || | S  j
rg }g } jD ];}|jrm|jjrm|jjrm| |j}	t|	| rc|| qF|t|	|j qF| |}
t|
| r||| qF||
 qFt| }|r| t| ddntj}|| S  tju rtjS  tju rtjS ddlm}m}  jr  \}}|jr|jr|jrĈ S |tju rtjS t|| S |j r|t!| S |j"r| t!| |tj# t$|  S d S |%t&s||' \}}|t(|  }|t!|| S t |r|t! jd S t t)r1 j*r( S  jr/  S d S  j+rM %tjtj,rMt-dd	  ' D rMtjS  j.rTtj/S  j rZ S  j0ra  S  j1rqtj2   }|j rq|S  jrwd S | 3 dd4t3 4t3 }|rt5 fd
d	|D rd S  krӈ  krՈ 4t} 6dd |D }dd |j	D }|rt5fdd	|D st7t8  S d S d S d S )Nr   )signsimpr   zBad argument type for Abs(): %sFrP   )r   logc                 s   s    | ]}|j V  qd S r    )is_infiniter#   rC   r%   r%   r&   r'   P  s    zAbs.eval.<locals>.<genexpr>c                 3   s     | ]}  |jd  V  qdS )r   N)r7   r   r#   ir<   r%   r&   r'   b  s    c                 S   s   i | ]}|t d dqS )T)real)r   r   r%   r%   r&   
<dictcomp>f      zAbs.eval.<locals>.<dictcomp>c                 S   s   g | ]	}|j d u r|qS r    )r+   r   r%   r%   r&   
<listcomp>g      zAbs.eval.<locals>.<listcomp>c                 3   s    | ]
}  t|V  qd S r    )r7   r3   )r#   u)conjr%   r&   r'   h  s    )9sympy.simplify.simplifyr   hasattrr   r2   r
   	TypeErrortypeas_numer_denomfree_symbolsr~   r   r   r   r   is_negativebaser6   r   r   r   r   r)   r*   Infinity&sympy.functions.elementary.exponentialr   as_base_expr+   r   r   rz   is_extended_nonnegativer   r   Pir9   r7   r   r0   r   r   is_positiveis_AddNegativeInfinityanyr`   r.   is_extended_nonpositiver,   r-   r3   atomsallxreplacer   r   )r;   r<   r   objr   dknownr   tbnewtnewr   r   r   exponentrC   rD   zr   new_conjr   abs_free_argr%   )r<   r   r&   rF   
  s   








"
zAbs.evalc                 C   rb   rc   rd   r]   r%   r%   r&   _eval_is_realk  rg   zAbs._eval_is_realc                 C      | j d jr| j d jS d S rV   )r   r+   r   r]   r%   r%   r&   r   o     zAbs._eval_is_integerc                 C      t | jd jS rV   r   _argsr`   r]   r%   r%   r&   _eval_is_extended_nonzeros     zAbs._eval_is_extended_nonzeroc                 C   rZ   rV   )r   r`   r]   r%   r%   r&   ra   v  r_   zAbs._eval_is_zeroc                 C   r   rV   r   r]   r%   r%   r&   _eval_is_extended_positivey  r   zAbs._eval_is_extended_positivec                 C   r   rV   )r   r+   is_rationalr]   r%   r%   r&   _eval_is_rational|  r   zAbs._eval_is_rationalc                 C   r   rV   )r   r+   r   r]   r%   r%   r&   _eval_is_even  r   zAbs._eval_is_evenc                 C   r   rV   )r   r+   is_oddr]   r%   r%   r&   _eval_is_odd  r   zAbs._eval_is_oddc                 C   rZ   rV   r[   r]   r%   r%   r&   r^     r_   zAbs._eval_is_algebraicc                 C   sP   | j d jr&|jr&|jr| j d | S |tjur&|jr&| j d |d  |  S d S )Nr   rs   )r   r+   r   r   r   r   
is_Integer)rJ   r   r%   r%   r&   r     s   zAbs._eval_powerr   c                 C   sd   ddl m} | jd |d }|||r||||}| jd j|||d}t||  S )Nr   )r   )r   r   )	r   r   r   leadtermr7   r   r   rw   expand)rJ   rS   r   r   r   r   	directionr{   r%   r%   r&   r     s   zAbs._eval_nseriesc                 C   s   | j d js| j d jrt| j d |ddtt| j d  S t| j d tt| j d |dd t| j d tt| j d |dd  t| j d  }|	tS rO   )
r   r+   r,   r   rw   r3   r   r9   rz   rewrite)rJ   rS   rvr%   r%   r&   rT     s   
zAbs._eval_derivativec                 K   s,   ddl m} |jr|||||   S d S )Nr   r   r   r   r%   r%   r&   r     s   zAbs._eval_rewrite_as_Heavisidec                 K   sL   |j rt||dkf| dfS |jr$tt| t| dkft | dfS d S rc   )r+   r   r,   r   rW   r%   r%   r&   r     s
   $zAbs._eval_rewrite_as_Piecewisec                 K   s   |t | S r    rw   rW   r%   r%   r&   _eval_rewrite_as_sign  r_   zAbs._eval_rewrite_as_signc                 K   s   t |t| S r    )r   r3   rW   r%   r%   r&   _eval_rewrite_as_conjugate  r   zAbs._eval_rewrite_as_conjugateN)rs   r   )rj   rk   rl   rm   rn   r
   ro   r+   r   r   rp   rq   r   rr   rF   r   r   r   ra   r   r   r   r   r^   r   r   rT   r   r   r   r   r%   r%   r%   r&   rz     s6   
 9


`
	rz   c                   @   s<   e Zd ZdZdZdZdZdZedd Z	dd Z
dd Zd	S )
r<   a  
    Returns the argument (in radians) of a complex number. The argument is
    evaluated in consistent convention with ``atan2`` where the branch-cut is
    taken along the negative real axis and ``arg(z)`` is in the interval
    $(-\pi,\pi]$. For a positive number, the argument is always 0; the
    argument of a negative number is $\pi$; and the argument of 0
    is undefined and returns ``nan``. So the ``arg`` function will never nest
    greater than 3 levels since at the 4th application, the result must be
    nan; for a real number, nan is returned on the 3rd application.

    Examples
    ========

    >>> from sympy import arg, I, sqrt, Dummy
    >>> from sympy.abc import x
    >>> arg(2.0)
    0
    >>> arg(I)
    pi/2
    >>> arg(sqrt(2) + I*sqrt(2))
    pi/4
    >>> arg(sqrt(3)/2 + I/2)
    pi/6
    >>> arg(4 + 3*I)
    atan(3/4)
    >>> arg(0.8 + 0.6*I)
    0.643501108793284
    >>> arg(arg(arg(arg(x))))
    nan
    >>> real = Dummy(real=True)
    >>> arg(arg(arg(real)))
    nan

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    Returns
    =======

    value : Expr
        Returns arc tangent of arg measured in radians.

    Tc                 C   s
  |}t dD ]}t|| r|jd }q|dkr|jrtj  S  ntjS ddlm} t||r4t|t	S |j
sSt| \}}|jrLtdd |jD  }t|| }n|}tdd |tD rcd S dd	lm} | \}}	||	|}
|
jry|
S ||kr| |d
dS d S )N   r   r   	exp_polarc                 S   s$   g | ]}t |d vr|nt |qS ))r   rs   r   r   r%   r%   r&   r     s
    zarg.eval.<locals>.<listcomp>c                 s   s    | ]}|j d u V  qd S r    )r   r   r%   r%   r&   r'     s    zarg.eval.<locals>.<genexpr>atan2FrP   )ranger2   r   r+   r   r)   r   r   periodic_argumentr   is_Atomr   as_coeff_Mulr~   r   rw   r   r   r   (sympy.functions.elementary.trigonometricr   r0   	is_number)r;   r<   rC   r   r   rE   arg_r   rS   yr   r%   r%   r&   rF     s:   




zarg.evalc                 C   sF   | j d  \}}|t||dd |t||dd  |d |d   S )Nr   TrP   r   )r   r0   r   )rJ   r   rS   r  r%   r%   r&   rT     s   zarg._eval_derivativec                 K   s(   ddl m} | jd  \}}|||S )Nr   r   )r   r   r   r0   )rJ   r<   rX   r   rS   r  r%   r%   r&   _eval_rewrite_as_atan2  s   
zarg._eval_rewrite_as_atan2N)rj   rk   rl   rm   r+   is_realre   rq   rr   rF   rT   r  r%   r%   r%   r&   r<     s    /
 r<   c                   @   sX   e Zd ZdZdZe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S )r3   a>  
    Returns the *complex conjugate* [1]_ of an argument.
    In mathematics, the complex conjugate of a complex number
    is given by changing the sign of the imaginary part.

    Thus, the conjugate of the complex number
    :math:`a + ib` (where $a$ and $b$ are real numbers) is :math:`a - ib`

    Examples
    ========

    >>> from sympy import conjugate, I
    >>> conjugate(2)
    2
    >>> conjugate(I)
    -I
    >>> conjugate(3 + 2*I)
    3 - 2*I
    >>> conjugate(5 - I)
    5 + I

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    Returns
    =======

    arg : Expr
        Complex conjugate of arg as real, imaginary or mixed expression.

    See Also
    ========

    sign, Abs

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Complex_conjugation
    Tc                 C      |  }|d ur
|S d S r    )r   r;   r<   r   r%   r%   r&   rF   G     zconjugate.evalc                 C   s   t S r    )r3   r]   r%   r%   r&   inverseM  s   zconjugate.inversec                 C      t | jd ddS rO   rz   r   r]   r%   r%   r&   r   P  r   zconjugate._eval_Absc                 C      t | jd S rV   	transposer   r]   r%   r%   r&   _eval_adjointS     zconjugate._eval_adjointc                 C   
   | j d S rV   r   r]   r%   r%   r&   r   V     
zconjugate._eval_conjugatec                 C   sB   |j rtt| jd |ddS |jrtt| jd |dd S d S rO   )r  r3   r   r   r,   rR   r%   r%   r&   rT   Y  s
   zconjugate._eval_derivativec                 C   r  rV   adjointr   r]   r%   r%   r&   _eval_transpose_  r  zconjugate._eval_transposec                 C   rZ   rV   r[   r]   r%   r%   r&   r^   b  r_   zconjugate._eval_is_algebraicN)rj   rk   rl   rm   rq   rr   rF   r	  r   r  r   rT   r  r^   r%   r%   r%   r&   r3     s    +
r3   c                   @   s4   e Zd ZdZedd Zdd Zdd Zdd	 Zd
S )r  a  
    Linear map transposition.

    Examples
    ========

    >>> from sympy import transpose, Matrix, MatrixSymbol
    >>> A = MatrixSymbol('A', 25, 9)
    >>> transpose(A)
    A.T
    >>> B = MatrixSymbol('B', 9, 22)
    >>> transpose(B)
    B.T
    >>> transpose(A*B)
    B.T*A.T
    >>> M = Matrix([[4, 5], [2, 1], [90, 12]])
    >>> M
    Matrix([
    [ 4,  5],
    [ 2,  1],
    [90, 12]])
    >>> transpose(M)
    Matrix([
    [4, 2, 90],
    [5, 1, 12]])

    Parameters
    ==========

    arg : Matrix
         Matrix or matrix expression to take the transpose of.

    Returns
    =======

    value : Matrix
        Transpose of arg.

    c                 C   r  r    )r  r  r%   r%   r&   rF     r  ztranspose.evalc                 C   r  rV   r3   r   r]   r%   r%   r&   r    r  ztranspose._eval_adjointc                 C   r  rV   r  r]   r%   r%   r&   r     r  ztranspose._eval_conjugatec                 C   r  rV   r  r]   r%   r%   r&   r    r  ztranspose._eval_transposeN)	rj   rk   rl   rm   rr   rF   r  r   r  r%   r%   r%   r&   r  f  s    (
r  c                   @   sF   e Zd ZdZedd Zdd Zdd Zdd	 ZdddZ	dd Z
d
S )r  a  
    Conjugate transpose or Hermite conjugation.

    Examples
    ========

    >>> from sympy import adjoint, MatrixSymbol
    >>> A = MatrixSymbol('A', 10, 5)
    >>> adjoint(A)
    Adjoint(A)

    Parameters
    ==========

    arg : Matrix
        Matrix or matrix expression to take the adjoint of.

    Returns
    =======

    value : Matrix
        Represents the conjugate transpose or Hermite
        conjugation of arg.

    c                 C   s0   |  }|d ur
|S | }|d urt|S d S r    )r  r  r3   r  r%   r%   r&   rF     s   zadjoint.evalc                 C   r  rV   r  r]   r%   r%   r&   r    r  zadjoint._eval_adjointc                 C   r  rV   r  r]   r%   r%   r&   r     r  zadjoint._eval_conjugatec                 C   r  rV   r  r]   r%   r%   r&   r    r  zadjoint._eval_transposeNc                 G   s,   | | jd }d| }|rd||f }|S )Nr   z%s^{\dagger}z\left(%s\right)^{%s})_printr   )rJ   printerr   r   r<   texr%   r%   r&   _latex  s
   zadjoint._latexc                 G   sJ   ddl m} |j| jd g|R  }|jr||d }|S ||d }|S )Nr   )
prettyFormu   †+) sympy.printing.pretty.stringpictr  r  r   _use_unicode)rJ   r  r   r  pformr%   r%   r&   _pretty  s   zadjoint._prettyr    )rj   rk   rl   rm   rr   rF   r  r   r  r  r!  r%   r%   r%   r&   r    s    

r  c                   @   s4   e Zd ZdZdZdZedd Zdd Zdd	 Z	d
S )
polar_lifta  
    Lift argument to the Riemann surface of the logarithm, using the
    standard branch.

    Examples
    ========

    >>> from sympy import Symbol, polar_lift, I
    >>> p = Symbol('p', polar=True)
    >>> x = Symbol('x')
    >>> polar_lift(4)
    4*exp_polar(0)
    >>> polar_lift(-4)
    4*exp_polar(I*pi)
    >>> polar_lift(-I)
    exp_polar(-I*pi/2)
    >>> polar_lift(I + 2)
    polar_lift(2 + I)

    >>> polar_lift(4*x)
    4*polar_lift(x)
    >>> polar_lift(4*p)
    4*p

    Parameters
    ==========

    arg : Expr
        Real or complex expression.

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    periodic_argument
    TFc           	      C   s  ddl m} |jr*||}|dtd t d tfv r*ddlm} |t| t| S |jr1|j	}n|g}g }g }g }|D ]}|j
rG||g7 }q<|jrP||g7 }q<||g7 }q<t|t|k r|rlt||  tt|  S |rtt||  S ddlm} t| |d S d S )Nr   r   r   r   )$sympy.functions.elementary.complexesr<   r  r   r   r   r   absr~   r   is_polarr   r8   r   r"  )	r;   r<   argumentarr   r   r=   r?   positiver%   r%   r&   rF   
  s4   zpolar_lift.evalc                 C   s   | j d |S )z. Careful! any evalf of polar numbers is flaky r   )r   _eval_evalf)rJ   precr%   r%   r&   r)  .  s   zpolar_lift._eval_evalfc                 C   r
  rO   r  r]   r%   r%   r&   r   2  r   zpolar_lift._eval_AbsN)
rj   rk   rl   rm   r%  r   rr   rF   r)  r   r%   r%   r%   r&   r"    s    %
#r"  c                   @   s0   e Zd ZdZedd Zedd Zdd ZdS )	r   a  
    Represent the argument on a quotient of the Riemann surface of the
    logarithm. That is, given a period $P$, always return a value in
    $(-P/2, P/2]$, by using $\exp(PI) = 1$.

    Examples
    ========

    >>> from sympy import exp_polar, periodic_argument
    >>> from sympy import I, pi
    >>> periodic_argument(exp_polar(10*I*pi), 2*pi)
    0
    >>> periodic_argument(exp_polar(5*I*pi), 4*pi)
    pi
    >>> from sympy import exp_polar, periodic_argument
    >>> from sympy import I, pi
    >>> periodic_argument(exp_polar(5*I*pi), 2*pi)
    pi
    >>> periodic_argument(exp_polar(5*I*pi), 3*pi)
    -pi
    >>> periodic_argument(exp_polar(5*I*pi), pi)
    0

    Parameters
    ==========

    ar : Expr
        A polar number.

    period : Expr
        The period $P$.

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    polar_lift : Lift argument to the Riemann surface of the logarithm
    principal_branch
    c           	      C   s   ddl m}m} |jr|j}n|g}d}|D ]I}|js"|t|7 }qt||r1||j	 d 7 }q|j
rN|j	 \}}||t|j ||t|j  7 }qt|tr]|t|jd 7 }q d S |S )Nr   )r   r   rs   )r   r   r   r~   r   r%  r<   r2   r   r0   r   unbranched_argumentr   r$  r"  )	r;   r'  r   r   r   rp   rC   r   r9   r%   r%   r&   _getunbranched_  s*   

z periodic_argument._getunbranchedc           	      C   s
  |j sd S |tkrt|trt|j S t|tr&|dt kr&t|jd |S |jrAdd |jD }t	|t	|jkrAtt
| |S | |}|d u rLd S ddlm}m} |t||r]d S |tkrc|S |tkrddlm} ||| tj | }||s|| S d S d S )Nr   r   c                 S   s   g | ]}|j s|qS r%   )r   r#   rS   r%   r%   r&   r         z*periodic_argument.eval.<locals>.<listcomp>)atanr   ceiling)r   r   r2   principal_branchr   r   r"  r   r~   r8   r   r,  r   r/  r   r7   #sympy.functions.elementary.integersr1  r   r   )	r;   r'  periodnewargsrp   r/  r   r1  r   r%   r%   r&   rF   v  s2   


zperiodic_argument.evalc                 C   sn   | j \}}|tkrt|}|d u r| S ||S t|t|}ddlm} |||| tj |  |S )Nr   r0  )	r   r   r   r,  r)  r3  r1  r   r   )rJ   r*  r   r4  rp   ubr1  r%   r%   r&   r)    s   


 zperiodic_argument._eval_evalfN)rj   rk   rl   rm   rr   r,  rF   r)  r%   r%   r%   r&   r   6  s    (

r   c                 C   s
   t | tS )a\  
    Returns periodic argument of arg with period as infinity.

    Examples
    ========

    >>> from sympy import exp_polar, unbranched_argument
    >>> from sympy import I, pi
    >>> unbranched_argument(exp_polar(15*I*pi))
    15*pi
    >>> unbranched_argument(exp_polar(7*I*pi))
    7*pi

    See also
    ========

    periodic_argument
    )r   r   r   r%   r%   r&   r+    s   
r+  c                   @   s,   e Zd ZdZdZdZedd Zdd ZdS )	r2  a  
    Represent a polar number reduced to its principal branch on a quotient
    of the Riemann surface of the logarithm.

    Explanation
    ===========

    This is a function of two arguments. The first argument is a polar
    number `z`, and the second one a positive real number or infinity, `p`.
    The result is ``z mod exp_polar(I*p)``.

    Examples
    ========

    >>> from sympy import exp_polar, principal_branch, oo, I, pi
    >>> from sympy.abc import z
    >>> principal_branch(z, oo)
    z
    >>> principal_branch(exp_polar(2*pi*I)*3, 2*pi)
    3*exp_polar(0)
    >>> principal_branch(exp_polar(2*pi*I)*3*z, 2*pi)
    3*principal_branch(z, 2*pi)

    Parameters
    ==========

    x : Expr
        A polar number.

    period : Expr
        Positive real number or infinity.

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    polar_lift : Lift argument to the Riemann surface of the logarithm
    periodic_argument
    TFc                 C   s  ddl m} t|trt|jd |S |tkr|S t|t}t||}||krj|tsj|tsjt|}dd }|	t|}t|t}|tsj||krX|t
||  | }n|}|jsh||sh||d9 }|S |jss|d}	}
n|j|j \}	}
g }|
D ]}|jr|	|9 }	q||g7 }qt|}
t|	|}|trd S |jrt|	|ks|dkr|
dkr|	dkr|dkrt|	tt|
 | S t|t
| t|
  |t|	 S |jrt||d k dks||d kr|
dkr||t
 t|	 S d S d S d S )	Nr   r   c                 S   s   t | ts	t| S | S r    )r2   r   r"  )exprr%   r%   r&   mr  s   
z!principal_branch.eval.<locals>.mrr%   rs   r   T)r   r   r2   r"  r2  r   r   r   r7   replacer   r%  r   r   r   tupler  r+  r$  r   )rJ   rS   r4  r   r6  bargplr8  resrE   mothersr  r<   r%   r%   r&   rF     s`   







"&zprincipal_branch.evalc                 C   sZ   | j \}}t|||}t|tks|t kr| S ddlm} t||t|  |S )Nr   )r   )r   r   r)  r$  r   r   r   r   )rJ   r*  r   r4  pr   r%   r%   r&   r)    s   
zprincipal_branch._eval_evalfN)	rj   rk   rl   rm   r%  r   rr   rF   r)  r%   r%   r%   r&   r2    s    (
3r2  Fc           
         s`  ddl m} | jr| S | jrst| S t| tr!s! r!t| S | jr&| S | jr>| j	 fdd| j
D  } r<t|S |S | jrT| jtjkrT| 	tjt| j ddS | jrd| j	 fdd| j
D  S t| |rt| j d}g }| j
dd  D ]}t|d dd	}t|dd   d	}	||f|	  qz||ft|  S | j	 fd
d| j
D  S )Nr   )Integralc                       g | ]	}t | d dqS )Tpause	_polarifyr#   r<   liftr%   r&   r   *  r   z_polarify.<locals>.<listcomp>FrC  c                    rB  )FrC  rE  rG  rH  r%   r&   r   1  r   rs   rI  rD  c                    s(   g | ]}t |trt| d n|qS )rC  )r2   r
   rF  rG  rJ  r%   r&   r   <  s
    
)sympy.integrals.integralsrA  r%  r  r"  r2   r   r   r   r   r   r   r   r   Exp1rF  r   r1   functionr6   r:  )
eqrI  rD  rA  rr   limitslimitvarrestr%   rJ  r&   rF    s:   

rF  Tc                 C   sN   |rd}t t| |} |s| S dd | jD }| |} | dd | D fS )a  
    Turn all numbers in eq into their polar equivalents (under the standard
    choice of argument).

    Note that no attempt is made to guess a formal convention of adding
    polar numbers, expressions like $1 + x$ will generally not be altered.

    Note also that this function does not promote ``exp(x)`` to ``exp_polar(x)``.

    If ``subs`` is ``True``, all symbols which are not already polar will be
    substituted for polar dummies; in this case the function behaves much
    like :func:`~.posify`.

    If ``lift`` is ``True``, both addition statements and non-polar symbols are
    changed to their ``polar_lift()``ed versions.
    Note that ``lift=True`` implies ``subs=False``.

    Examples
    ========

    >>> from sympy import polarify, sin, I
    >>> from sympy.abc import x, y
    >>> expr = (-x)**y
    >>> expr.expand()
    (-x)**y
    >>> polarify(expr)
    ((_x*exp_polar(I*pi))**_y, {_x: x, _y: y})
    >>> polarify(expr)[0].expand()
    _x**_y*exp_polar(_y*I*pi)
    >>> polarify(x, lift=True)
    polar_lift(x)
    >>> polarify(x*(1+y), lift=True)
    polar_lift(x)*polar_lift(y + 1)

    Adds are treated carefully:

    >>> polarify(1 + sin((1 + I)*x))
    (sin(_x*polar_lift(1 + I)) + 1, {_x: x})
    Fc                 S   s   i | ]
}|t |jd dqS )T)polar)r   name)r#   r{   r%   r%   r&   r   m  s    zpolarify.<locals>.<dictcomp>c                 S   s   i | ]\}}||qS r%   r%   )r#   r{   rO  r%   r%   r&   r   o  r.  )rF  r   r   r   items)rN  r   rI  repsr%   r%   r&   polarify@  s   (
rX  c                    sR  t | tr| jr
| S |slddlm}m} t | |r!|t| j S t | tr7| jd dt	 kr7t| jd  S | j
sR| jsR| jsR| jr_| jdv rMd| jv sR| jdvr_| j fdd| jD  S t | trlt| jd  S | jrt| j }t| j |jo~|  }|| S | jrt| jdd	r| j fd
d| jD  S | j fdd| jD  S )Nr   )r   r   rs   r   )z==z!=c                    s   g | ]}t | qS r%   _unpolarifyr-  exponents_onlyr%   r&   r     r.  z_unpolarify.<locals>.<listcomp>rp   Fc                    s   g | ]}t |  qS r%   rY  r-  r[  r%   r&   r     s    c                    s   g | ]}t | d qS ri   rY  r-  r[  r%   r&   r     r   )r2   r	   r   r   r   r   rZ  r2  r   r   r   r~   
is_Booleanis_Relationalrel_opr   r"  r   r   r   r1   getattr)rN  r\  rD  r   r   expor   r%   r[  r&   rZ  r  sH   

rZ  Nc                 C   s   t | tr| S t| } |durt| |S d}d}|rd}|r9d}t| ||}|| kr0d}|} t |tr7|S |s ddlm} ||ddtddiS )a  
    If `p` denotes the projection from the Riemann surface of the logarithm to
    the complex line, return a simplified version `eq'` of `eq` such that
    `p(eq') = p(eq)`.
    Also apply the substitution subs in the end. (This is a convenience, since
    ``unpolarify``, in a certain sense, undoes :func:`polarify`.)

    Examples
    ========

    >>> from sympy import unpolarify, polar_lift, sin, I
    >>> unpolarify(polar_lift(I + 2))
    2 + I
    >>> unpolarify(sin(polar_lift(I + 7)))
    sin(7 + I)
    NTFr   r   rs   )	r2   boolr   
unpolarifyr   rZ  r   r   r"  )rN  r   r\  changedrD  r=  r   r%   r%   r&   rc    s(   


rc  )F)TF)NF)4typingr   rn   
sympy.corer   r   r   r   r   r   r	   sympy.core.exprr
   sympy.core.exprtoolsr   sympy.core.functionr   r   r   r   r   sympy.core.logicr   r   sympy.core.numbersr   r   r   sympy.core.powerr   sympy.core.relationalr   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.piecewiser   r   r9   rw   rz   r<   r3   r  r  r"  r   r+  r2  rF  rX  rZ  rc  r%   r%   r%   r&   <module>   s:    $z{ 6 {aM9BUj
i
!
2!