a
    kh                     @  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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)Z1d1d*d+Z2d2d-d.Z3d,S )3    )annotations)SAddMulsympifySymbolDummyBasic)Expr)factor_terms)DefinedFunction
DerivativeArgumentIndexErrorAppliedUndef
expand_mul	PoleError)	fuzzy_notfuzzy_or)piIoo)Pow)Eq)sqrt)	Piecewisec                   @  sl   e Zd ZU dZd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
    tuple[Expr]argsTc                 C  sD  |t ju rt jS |t ju r t jS |jr*|S |js:t| jr@t jS |jrR| d S |j	rpt
|trpt|jd S g g g   }}}t|}|D ]p}|t}|d ur|js|| q|ts|jr|| q|j|d}| r||d  q|| qt|t|kr@dd |||fD \}	}
}| |	t|
 | S d S )Nr   ignorec                 s  s   | ]}t | V  qd S Nr   .0xs r%   R/var/www/auris/lib/python3.9/site-packages/sympy/functions/elementary/complexes.py	<genexpr>i       zre.eval.<locals>.<genexpr>)r   NaNComplexInfinityis_extended_realis_imaginaryr   Zero	is_Matrixas_real_imagis_Function
isinstance	conjugater   r   r   	make_argsas_coefficientappendhaslenimclsargincludedZrevertedexcludedr   ZtermZcoeffZ	real_imagabcr%   r%   r&   evalD   s8    



zre.evalc                 K  s
   | t jfS )zF
        Returns the real number with a zero imaginary part.

        r   r-   selfdeephintsr%   r%   r&   r/   m   s    zre.as_real_imagc                 C  s^   |j s| jd j r*tt| jd |ddS |js<| jd jrZt tt| jd |dd S d S Nr   Tevaluate)r+   r   r   r   r,   r   r8   rD   xr%   r%   r&   _eval_derivativet   s    zre._eval_derivativec                 K  s   | j d tt| j d   S Nr   )r   r   r8   rD   r;   kwargsr%   r%   r&   _eval_rewrite_as_im{   s    zre._eval_rewrite_as_imc                 C  s   | j d jS rM   r   Zis_algebraicrD   r%   r%   r&   _eval_is_algebraic~   s    zre._eval_is_algebraicc                 C  s   t | jd j| jd jgS rM   )r   r   r,   is_zerorR   r%   r%   r&   _eval_is_zero   s    zre._eval_is_zeroc                 C  s   | j d jrdS d S Nr   Tr   	is_finiterR   r%   r%   r&   _eval_is_finite   s    zre._eval_is_finitec                 C  s   | j d jrdS d S rV   rW   rR   r%   r%   r&   _eval_is_complex   s    zre._eval_is_complexN)T)__name__
__module____qualname____doc____annotations__r+   
unbranched_singularitiesclassmethodrA   r/   rL   rP   rS   rU   rY   rZ   r%   r%   r%   r&   r      s   
)
(
r   c                   @  sl   e Zd ZU dZd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 )r8   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   r   Tc                 C  sL  |t ju rt jS |t ju r t jS |jr,t jS |js<t| jrFt | S |jrX| d S |j	rxt
|trxt|jd  S g g g   }}}t|}|D ]p}|t}|d ur|js|| n
|| q|ts|js|j|d}| r||d  q|| qt|t|krHdd |||fD \}	}
}| |	t|
 | S d S )N   r   r   c                 s  s   | ]}t | V  qd S r    r!   r"   r%   r%   r&   r'      r(   zim.eval.<locals>.<genexpr>)r   r)   r*   r+   r-   r,   r   r.   r/   r0   r1   r2   r8   r   r   r3   r4   r5   r6   r7   r   r9   r%   r%   r&   rA      s8    




zim.evalc                 K  s
   | t jfS )zC
        Return the imaginary part with a zero real part.

        rB   rC   r%   r%   r&   r/      s    zim.as_real_imagc                 C  s^   |j s| jd j r*tt| jd |ddS |js<| jd jrZt tt| jd |dd S d S rG   )r+   r   r8   r   r,   r   r   rJ   r%   r%   r&   rL      s    zim._eval_derivativec                 K  s   t  | jd t| jd   S rM   )r   r   r   rN   r%   r%   r&   _eval_rewrite_as_re   s    zim._eval_rewrite_as_rec                 C  s   | j d jS rM   rQ   rR   r%   r%   r&   rS      s    zim._eval_is_algebraicc                 C  s   | j d jS rM   r   r+   rR   r%   r%   r&   rU      s    zim._eval_is_zeroc                 C  s   | j d jrdS d S rV   rW   rR   r%   r%   r&   rY      s    zim._eval_is_finitec                 C  s   | j d jrdS d S rV   rW   rR   r%   r%   r&   rZ     s    zim._eval_is_complexN)T)r[   r\   r]   r^   r_   r+   r`   ra   rb   rA   r/   rL   rd   rS   rU   rY   rZ   r%   r%   r%   r&   r8      s   
)
'
r8   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   rT   Abs)rD   rF   s	__class__r%   r&   rh   C  s    
z	sign.doitc           	      C  s@  |j r| \}}g }t|}|D ]Z}|jr4| }q"|jr<q"|jrrt|}|jrf|t9 }|jrp| }q||	| q"|	| q"|t
ju rt|t|krd S || |j|  S |t
ju rt
jS |jrt
jS |jrt
jS |jrt
jS |jrt|tr|S |jr<|jr|jt
ju rtS t | }|jr.tS |jr<t S d S r    )is_Mulas_coeff_mulrf   is_extended_negativeis_extended_positiver,   r8   is_comparabler   r5   r   Oner7   Z_new_rawargsr)   rT   r-   NegativeOner0   r1   is_PowexpHalf)	r:   r;   r@   r   unkrj   r>   Zaiarg2r%   r%   r&   rA   I  sN    


z	sign.evalc                 C  s   t | jd jrtjS d S rM   )r   r   rT   r   rr   rR   r%   r%   r&   	_eval_Abs{  s    zsign._eval_Absc                 C  s   t t| jd S rM   )rf   r2   r   rR   r%   r%   r&   _eval_conjugate  s    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rddlm} dt| j d |dd |t | j d   S d S )Nr   )
DiracDelta   TrH   )r   r+   'sympy.functions.special.delta_functionsr{   r   r,   r   )rD   rK   r{   r%   r%   r&   rL     s    zsign._eval_derivativec                 C  s   | j d jrdS d S rV   )r   Zis_nonnegativerR   r%   r%   r&   _eval_is_nonnegative  s    zsign._eval_is_nonnegativec                 C  s   | j d jrdS d S rV   )r   Zis_nonpositiverR   r%   r%   r&   _eval_is_nonpositive  s    zsign._eval_is_nonpositivec                 C  s   | j d jS rM   )r   r,   rR   r%   r%   r&   _eval_is_imaginary  s    zsign._eval_is_imaginaryc                 C  s   | j d jS rM   re   rR   r%   r%   r&   _eval_is_integer  s    zsign._eval_is_integerc                 C  s   | j d jS rM   )r   rT   rR   r%   r%   r&   rU     s    zsign._eval_is_zeroc                 C  s&   t | jd jr"|jr"|jr"tjS d S rM   )r   r   rT   
is_integeris_evenr   rr   )rD   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 rPtj S tjS rM   )r   subsfuncdirr   r   rr   )rD   rK   nlogxcdirarg0Z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 )Nrc   r   )r   T)r+   r   rN   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|   rc   r}   r   r+   rD   r;   rO   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 rV   )r   r   ri   rN   r%   r%   r&   _eval_rewrite_as_Abs  s    zsign._eval_rewrite_as_Absc                 K  s   |  t| jd S rM   )r   r   r   )rD   rO   r%   r%   r&   _eval_simplify  s    zsign._eval_simplify)r   )r[   r\   r]   r^   Z
is_complexra   rh   rb   rA   ry   rz   rL   r~   r   r   r   rU   r   r   r   r   r   r   __classcell__r%   r%   rk   r&   rf   	  s(   6
1

	rf   c                   @  s   e Zd ZU dZd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 )/ri   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   r   TFrc   c                 C  s$   |dkrt | jd S t| |dS )zE
        Get the first derivative of the argument to Abs().

        rc   r   N)rf   r   r   )rD   Zargindexr%   r%   r&   fdiff   s    z	Abs.fdiffc                   s  ddl m} t dr*  }|d ur*|S t tsDtdt  | dd   \}}|j	rx|j	sx| || | S  j
r2g }g } jD ]v}|jr|jjr|jjr| |j}	t|	| r|| n|t|	|j q| |}
t|
| r|| q||
 qt| }|r$| t| ddntj}|| S  tju rDtjS  tju rTt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# t$|  S d S |%t&s*||' \}}|t(|  }|t!|| S t |rH|t! jd S t t)rr j*r` S  jrn  S d S  j+r %ttj,rt-dd	  ' D rtS  j.rtj/S  j r S  j0rΈ  S  j1rt(   }|j r|S  jrd S | 2 dd3t2 3t2 }|r>t4 fd
d	|D r>d S  kr  kr 3t} 5dd |D }dd |j	D }|rt4fdd	|D st6t7  S d S )Nr   )signsimpry   zBad argument type for Abs(): %sFrH   )ru   logc                 s  s   | ]}|j V  qd S r    )is_infiniter#   r>   r%   r%   r&   r'   P  r(   zAbs.eval.<locals>.<genexpr>c                 3  s   | ]}  |jd  V  qdS )r   N)r6   r   r#   ir;   r%   r&   r'   b  r(   c                 S  s   i | ]}|t d dqS )T)real)r   r   r%   r%   r&   
<dictcomp>f  r(   zAbs.eval.<locals>.<dictcomp>c                 S  s   g | ]}|j d u r|qS r    )r+   r   r%   r%   r&   
<listcomp>g  r(   zAbs.eval.<locals>.<listcomp>c                 3  s   | ]}  t|V  qd S r    )r6   r2   )r#   u)conjr%   r&   r'   h  r(   )8Zsympy.simplify.simplifyr   hasattrry   r1   r
   	TypeErrortypeZas_numer_denomfree_symbolsrm   r   rt   ru   r   is_negativebaser5   r   r   r   rr   r)   r*   r   &sympy.functions.elementary.exponentialr   Zas_base_expr+   r   rs   ri   is_extended_nonnegativer   ro   r   r8   r6   r   r/   r   r   is_positiveis_AddNegativeInfinityanyrT   r-   Zis_extended_nonpositiver,   r2   atomsallZxreplacer   r   )r:   r;   r   objr   dZknownrw   tZbnewZtnewru   r   r   exponentr>   r?   zrx   Znew_conjr   Zabs_free_argr%   )r;   r   r&   rA   
  s    





 

zAbs.evalc                 C  s   | j d jrdS d S rV   rW   rR   r%   r%   r&   _eval_is_realk  s    zAbs._eval_is_realc                 C  s   | j d jr| j d jS d S rM   )r   r+   r   rR   r%   r%   r&   r   o  s    zAbs._eval_is_integerc                 C  s   t | jd jS rM   r   _argsrT   rR   r%   r%   r&   _eval_is_extended_nonzeros  s    zAbs._eval_is_extended_nonzeroc                 C  s   | j d jS rM   )r   rT   rR   r%   r%   r&   rU   v  s    zAbs._eval_is_zeroc                 C  s   t | jd jS rM   r   rR   r%   r%   r&   _eval_is_extended_positivey  s    zAbs._eval_is_extended_positivec                 C  s   | j d jr| j d jS d S rM   )r   r+   Zis_rationalrR   r%   r%   r&   _eval_is_rational|  s    zAbs._eval_is_rationalc                 C  s   | j d jr| j d jS d S rM   )r   r+   r   rR   r%   r%   r&   _eval_is_even  s    zAbs._eval_is_evenc                 C  s   | j d jr| j d jS d S rM   )r   r+   Zis_oddrR   r%   r%   r&   _eval_is_odd  s    zAbs._eval_is_oddc                 C  s   | j d jS rM   rQ   rR   r%   r%   r&   rS     s    zAbs._eval_is_algebraicc                 C  sP   | j d jrL|jrL|jr&| j d | S |tjurL|jrL| j d |d  |  S d S )Nr   rc   )r   r+   r   r   r   rs   Z
is_Integer)rD   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   Zleadtermr6   r   r   rf   expand)rD   rK   r   r   r   r   	directionrj   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 rG   )
r   r+   r,   r   rf   r2   r   r8   ri   Zrewrite)rD   rK   rvr%   r%   r&   rL     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rHtt| t| dkft | dfS d S rV   )r+   r   r,   r   rN   r%   r%   r&   r     s    zAbs._eval_rewrite_as_Piecewisec                 K  s   |t | S r    rf   rN   r%   r%   r&   _eval_rewrite_as_sign  s    zAbs._eval_rewrite_as_signc                 K  s   t |t| S r    )r   r2   rN   r%   r%   r&   _eval_rewrite_as_conjugate  s    zAbs._eval_rewrite_as_conjugateN)rc   )r   )r[   r\   r]   r^   r_   r+   ro   r   r`   ra   r   rb   rA   r   r   r   rU   r   r   r   r   rS   r   r   rL   r   r   r   r   r%   r%   r%   r&   ri     s4   
9


`
	ri   c                   @  sN   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	d
 Zd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 ]6}t|| r&|jd }q|dkr>|jr>tj  S  qJqtjS ddlm}m} t||rnt	|t
S t||rt|jd }|jr|dtj ; }|tjkr|dtj 8 }|S |jst| \}}|jrtdd |jD  }t|| }n|}tdd |tD rd S dd	lm}	 | \}
}|	||
}|jrD|S ||krZ| |d
dS d S )N   r   r|   ru   	exp_polarc                 S  s$   g | ]}t |d vr|nt |qS ))r   rc   r   r   r%   r%   r&   r     s   zarg.eval.<locals>.<listcomp>c                 s  s   | ]}|j d u V  qd S r    )rp   r   r%   r%   r&   r'     r(   zarg.eval.<locals>.<genexpr>atan2FrH   )ranger1   r   r+   r   r)   r   ru   r   periodic_argumentr   r8   rq   Piis_Atomr   Zas_coeff_Mulrm   r   rf   r   r   r   (sympy.functions.elementary.trigonometricr   r/   	is_number)r:   r;   r>   r   ru   r   Zi_r@   Zarg_r   rK   yr   r%   r%   r&   rA     sF    







zarg.evalc                 C  sF   | j d  \}}|t||dd |t||dd  |d |d   S )Nr   TrH   r|   )r   r/   r   )rD   r   rK   r   r%   r%   r&   rL     s    zarg._eval_derivativec                 K  s(   ddl m} | jd  \}}|||S )Nr   r   )r   r   r   r/   )rD   r;   rO   r   rK   r   r%   r%   r&   _eval_rewrite_as_atan2  s    zarg._eval_rewrite_as_atan2c                 C  sZ   | j d }tddd}|dkr"d}|||| }|jr>tjS |jrJtjS td|  d S )Nr   r   T)positiverc   zCannot expand %s around 0)	r   r   r   r   r   r-   r   r   r   )rD   rK   r   r   r   r   r   r%   r%   r&   _eval_as_leading_term   s    
zarg._eval_as_leading_termr   c                 C  s,   ddl m} |dkr|dS | j|||dS )Nr   )Orderrc   )r   r   )Zsympy.series.orderr   r   )rD   rK   r   r   r   r   r%   r%   r&   r   -  s    zarg._eval_nseriesN)r   )r[   r\   r]   r^   r+   is_realrX   ra   rb   rA   rL   r   r   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 )r2   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  s   |  }|d ur|S d S r    )rz   r:   r;   r   r%   r%   r&   rA   b  s    zconjugate.evalc                 C  s   t S r    )r2   rR   r%   r%   r&   inverseh  s    zconjugate.inversec                 C  s   t | jd ddS rG   ri   r   rR   r%   r%   r&   ry   k  s    zconjugate._eval_Absc                 C  s   t | jd S rM   	transposer   rR   r%   r%   r&   _eval_adjointn  s    zconjugate._eval_adjointc                 C  s
   | j d S rM   r   rR   r%   r%   r&   rz   q  s    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 rG   )r   r2   r   r   r,   rJ   r%   r%   r&   rL   t  s    zconjugate._eval_derivativec                 C  s   t | jd S rM   adjointr   rR   r%   r%   r&   _eval_transposez  s    zconjugate._eval_transposec                 C  s   | j d jS rM   rQ   rR   r%   r%   r&   rS   }  s    zconjugate._eval_is_algebraicN)r[   r\   r]   r^   ra   rb   rA   r   ry   r   rz   rL   r   rS   r%   r%   r%   r&   r2   4  s   +
r2   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  s   |  }|d ur|S d S r    )r   r   r%   r%   r&   rA     s    ztranspose.evalc                 C  s   t | jd S rM   r2   r   rR   r%   r%   r&   r     s    ztranspose._eval_adjointc                 C  s   t | jd S rM   r   rR   r%   r%   r&   rz     s    ztranspose._eval_conjugatec                 C  s
   | j d S rM   r   rR   r%   r%   r&   r     s    ztranspose._eval_transposeN)	r[   r\   r]   r^   rb   rA   r   rz   r   r%   r%   r%   r&   r     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   r2   r   r%   r%   r&   rA     s    zadjoint.evalc                 C  s
   | j d S rM   r   rR   r%   r%   r&   r     s    zadjoint._eval_adjointc                 C  s   t | jd S rM   r   rR   r%   r%   r&   rz     s    zadjoint._eval_conjugatec                 C  s   t | jd S rM   r   rR   r%   r%   r&   r     s    zadjoint._eval_transposeNc                 G  s,   | | jd }d| }|r(d||f }|S )Nr   z%s^{\dagger}z\left(%s\right)^{%s})_printr   )rD   printerru   r   r;   Ztexr%   r%   r&   _latex  s
    zadjoint._latexc                 G  sH   ddl m} |j| jd g|R  }|jr8||d }n||d }|S )Nr   )
prettyFormu   †+)Z sympy.printing.pretty.stringpictr   r   r   Z_use_unicode)rD   r   r   r   Zpformr%   r%   r&   _pretty  s    zadjoint._pretty)N)r[   r\   r]   r^   rb   rA   r   rz   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rT||}|dtd t d tfv rTddlm} |t| t| S |jrb|j	}n|g}g }g }g }|D ]2}|j
r||g7 }qx|jr||g7 }qx||g7 }qxt|t|k r|rt||  tt|  S |rt||  S ddlm} t| |d S d S )Nr   r   r|   r   )Z$sympy.functions.elementary.complexesr;   r   r   r   r   r   absrm   r   is_polarr   r7   r   r   )	r:   r;   argumentarr   r   r<   r=   r   r%   r%   r&   rA   %  s2    zpolar_lift.evalc                 C  s   | j d |S )z. Careful! any evalf of polar numbers is flaky r   )r   _eval_evalf)rD   precr%   r%   r&   r   I  s    zpolar_lift._eval_evalfc                 C  s   t | jd ddS rG   r   rR   r%   r%   r&   ry   M  s    zpolar_lift._eval_AbsN)
r[   r\   r]   r^   r   rq   rb   rA   r   ry   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 ]}|jsD|t|7 }q,t||rb||j	 d 7 }q,|j
r|j	 \}}||t|j ||t|j  7 }q,t|tr|t|jd 7 }q, d S q,|S )Nr   )r   r   rc   )r   r   r   rm   r   r   r;   r1   ru   r/   rt   unbranched_argumentr   r   r   )	r:   r   r   r   r   r`   r>   r   r8   r%   r%   r&   _getunbranchedz  s*    

z periodic_argument._getunbranchedc           	      C  s
  |j s
d S |tkr&t|tr&t|j S t|trL|dt krLt|jd |S |jrdd |jD }t	|t	|jkrtt
| |S | |}|d u rd S ddlm}m} |t||rd S |tkr|S |tkrddlm} ||| tj | }||s|| S d S )Nr|   r   c                 S  s   g | ]}|j s|qS r%   )r   r#   rK   r%   r%   r&   r     r(   z*periodic_argument.eval.<locals>.<listcomp>)atanr   ceiling)rp   r   r1   principal_branchr   r   r   r   rm   r7   r   r   r   r   r   r6   #sympy.functions.elementary.integersr   r   rv   )	r:   r   periodZnewargsr`   r   r   r   r   r%   r%   r&   rA     s.    


zperiodic_argument.evalc                 C  sn   | j \}}|tkr2t|}|d u r(| S ||S t|t|}ddlm} |||| tj |  |S )Nr   r   )	r   r   r   r   r   r   r   r   rv   )rD   r   r   r   r`   ubr   r%   r%   r&   r     s    


zperiodic_argument._eval_evalfN)r[   r\   r]   r^   rb   r   rA   r   r%   r%   r%   r&   r   Q  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 )	r   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r2|S t|t}t||}||kr|ts|tst|}dd }|	t|}t|t}|ts||kr|t
||  | }n|}|js||s||d9 }|S |js|d }	}
n|j|j \}	}
g }|
D ]"}|jr|	|9 }	n
||g7 } qt|}
t|	|}|trDd S |jrt|	|ksx|dkr|
dkr|	dkr|dkrt|	tt|
 | S t|t
| t|
  |t|	 S |jrt||d k dks||d kr|
dkr||t
 t|	 S d S )	Nr   r   c                 S  s   t | tst| S | S r    )r1   r   r   )exprr%   r%   r&   mr
  s    
z!principal_branch.eval.<locals>.mrr%   rc   r|   T)r   r   r1   r   r   r   r   r   r6   replacer   r   r   rn   r   tupler   r   r   r   )rD   rK   r   r   r   Zbargplr   resr@   mothersr   r;   r%   r%   r&   rA     s^    







",zprincipal_branch.evalc                 C  sZ   | j \}}t|||}t|tks0|t kr4| S ddlm} t||t|  |S )Nr   )ru   )r   r   r   r   r   r   ru   r   )rD   r   r   r   pru   r%   r%   r&   r   1  s    
zprincipal_branch._eval_evalfN)	r[   r\   r]   r^   r   rq   rb   rA   r   r%   r%   r%   r&   r     s   (
3r   Fc           
        sh  ddl m} | jr| S | jr(s(t| S t| trBsB rBt| S | jrL| S | jr|| j	 fdd| j
D  } rxt|S |S | jr| jtjkr| 	tjt| j ddS | jr| j	 fdd| j
D  S t| |rHt| j d}g }| j
dd  D ]>}t|d dd	}t|dd   d	}	||f|	   q||ft|  S | j	 fd
d| j
D  S d S )Nr   )Integralc                   s   g | ]}t | d dqS )Tpause	_polarifyr#   r;   liftr%   r&   r   E  r(   z_polarify.<locals>.<listcomp>Fr  c                   s   g | ]}t | d dqS )Fr  r  r  r	  r%   r&   r   L  r(   rc   r
  r  c                   s(   g | ] }t |tr t| d n|qS )r  )r1   r
   r  r  r  r%   r&   r   W  s   
)Zsympy.integrals.integralsr  r   r   r   r1   r   r   r   r   r   rt   r   r   ZExp1r  ru   r0   functionr5   r   )
eqr
  r  r  rr   Zlimitslimitvarrestr%   r  r&   r  :  s:    
r  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)Zpolar)r   name)r#   rj   r%   r%   r&   r     r(   zpolarify.<locals>.<dictcomp>c                 S  s   i | ]\}}||qS r%   r%   )r#   rj   r  r%   r%   r&   r     r(   )r  r   r   r   items)r  r   r
  Zrepsr%   r%   r&   polarify[  s    (
r  c                   sX  t | tr| jr| S |sddlm}m} t | |rB|t| j S t | trn| jd dt	 krnt| jd  S | j
s| js| js| jr| jdv rd| jv s| jdvr| j fdd| jD  S t | trt| jd  S | jrt| j }t| j |jo|  }|| S | jr>t| jdd	r>| j fd
d| jD  S | j fdd| jD  S )Nr   r   rc   r|   )z==z!=c                   s   g | ]}t | qS r%   _unpolarifyr   exponents_onlyr%   r&   r     r(   z_unpolarify.<locals>.<listcomp>r`   Fc                   s   g | ]}t |  qS r%   r  r   r  r%   r&   r     s   c                   s   g | ]}t | d qS )Tr  r   r  r%   r&   r     r(   )r1   r	   r   r   ru   r   r  r   r   r   r   rm   Z
is_BooleanZis_RelationalZrel_opr   r   rt   r   r   r0   getattr)r  r  r  ru   r   Zexpor   r%   r  r&   r    sH    

r  Nc                 C  s   t | tr| S t| } |dur,t| |S d}d}|r<d}|rpd}t| ||}|| kr`d}|} t |tr<|S q<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   rc   )	r1   boolr   
unpolarifyr   r  r   r   r   )r  r   r  changedr  r   r   r%   r%   r&   r    s&    

r  )F)TF)F)NF)4
__future__r   Z
sympy.corer   r   r   r   r   r   r	   Zsympy.core.exprr
   Zsympy.core.exprtoolsr   Zsympy.core.functionr   r   r   r   r   r   Zsympy.core.logicr   r   Zsympy.core.numbersr   r   r   Zsympy.core.powerr   Zsympy.core.relationalr   Z(sympy.functions.elementary.miscellaneousr   Z$sympy.functions.elementary.piecewiser   r   r8   rf   ri   r;   r2   r   r   r   r   r   r   r  r  r  r  r%   r%   r%   r&   <module>   s8   $ z{ 6 {|M9BUji
!
2
!