U
    -eƦ                     @   s  d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZ d dlmZmZ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! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9 G dd deZ:G dd de:Z;G dd deZ<G dd de:e<dZ=dd Z>G dd  d eZ?G d!d" d"eZ@ed#d$ ZAd%S )&    )product)Tuple)Add)cacheit)Expr)FunctionArgumentIndexError
expand_log
expand_mulFunctionClass	PoleErrorexpand_multinomialexpand_complex)	fuzzy_and	fuzzy_notfuzzy_or)Mul)IntegerRationalpiIImaginaryUnit)global_parameters)Pow)S)WildDummy)sympify)	factorial)arg
unpolarifyimreAbs)sqrt)multiplicityperfect_power)	factorintc                   @   s   e Zd ZdZejfZedd ZdddZ	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S )ExpBaseTc                 C   s   | j jS N)expkindself r.   g/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/sympy/functions/elementary/exponential.pyr+   (   s    zExpBase.kind   c                 C   s   t S )z=
        Returns the inverse function of ``exp(x)``.
        logr-   argindexr.   r.   r/   inverse,   s    zExpBase.inversec                 C   s@   | j }|j}|s | js | }|r6tj| | fS | tjfS )a-  
        Returns this with a positive exponent as a 2-tuple (a fraction).

        Examples
        ========

        >>> from sympy import exp
        >>> from sympy.abc import x
        >>> exp(-x).as_numer_denom()
        (1, exp(x))
        >>> exp(x).as_numer_denom()
        (exp(x), 1)
        )r*   is_negativecould_extract_minus_signr   Onefunc)r-   r*   Zneg_expr.   r.   r/   as_numer_denom2   s    zExpBase.as_numer_denomc                 C   s
   | j d S )z7
        Returns the exponent of the function.
        r   )argsr,   r.   r.   r/   r*   J   s    zExpBase.expc                 C   s   |  dt| j fS )z7
        Returns the 2-tuple (base, exponent).
        r0   )r9   r   r;   r,   r.   r.   r/   as_base_expQ   s    zExpBase.as_base_expc                 C   s   |  | j S r)   )r9   r*   Zadjointr,   r.   r.   r/   _eval_adjointW   s    zExpBase._eval_adjointc                 C   s   |  | j S r)   )r9   r*   	conjugater,   r.   r.   r/   _eval_conjugateZ   s    zExpBase._eval_conjugatec                 C   s   |  | j S r)   )r9   r*   Z	transposer,   r.   r.   r/   _eval_transpose]   s    zExpBase._eval_transposec                 C   s.   | j }|jr |jrdS |jr dS |jr*dS d S NTF)r*   is_infiniteis_extended_negativeis_extended_positive	is_finiter-   r   r.   r.   r/   _eval_is_finite`   s    zExpBase._eval_is_finitec                 C   sH   | j | j }|j | j kr>|jj}|r(dS |jjrDt|rDdS n|jS d S rA   )r9   r;   r*   is_zerois_rationalr   )r-   szr.   r.   r/   _eval_is_rationalj   s    zExpBase._eval_is_rationalc                 C   s   | j tjkS r)   )r*   r   NegativeInfinityr,   r.   r.   r/   _eval_is_zerou   s    zExpBase._eval_is_zeroc                 C   s"   |   \}}tt||dd|S )z;exp(arg)**e -> exp(arg*e) if assumptions allow it.
        Fevaluate)r<   r   _eval_power)r-   otherber.   r.   r/   rQ   x   s    zExpBase._eval_powerc                    sz   ddl m} ddlm}  jd }|jrH|jrHt fdd|jD S t	||rp|jrp| 
|jf|j S  
|S )Nr   )Product)Sumc                 3   s   | ]}  |V  qd S r)   )r9   ).0xr,   r.   r/   	<genexpr>   s     z1ExpBase._eval_expand_power_exp.<locals>.<genexpr>)Zsympy.concrete.productsrU   Zsympy.concrete.summationsrV   r;   is_AddZis_commutativer   Zfromiter
isinstancer9   functionlimits)r-   hintsrU   rV   r   r.   r,   r/   _eval_expand_power_exp~   s    
zExpBase._eval_expand_power_expN)r0   )__name__
__module____qualname__Z
unbranchedr   ComplexInfinity_singularitiespropertyr+   r5   r:   r*   r<   r=   r?   r@   rG   rL   rN   rQ   r_   r.   r.   r.   r/   r(   #   s"   



r(   c                   @   s@   e Zd ZdZdZdZdd Zdd Zdd	 Zd
d Z	dd Z
dS )	exp_polara<  
    Represent a *polar number* (see g-function Sphinx documentation).

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

    ``exp_polar`` represents the function
    `Exp: \mathbb{C} \rightarrow \mathcal{S}`, sending the complex number
    `z = a + bi` to the polar number `r = exp(a), \theta = b`. It is one of
    the main functions to construct polar numbers.

    Examples
    ========

    >>> from sympy import exp_polar, pi, I, exp

    The main difference is that polar numbers do not "wrap around" at `2 \pi`:

    >>> exp(2*pi*I)
    1
    >>> exp_polar(2*pi*I)
    exp_polar(2*I*pi)

    apart from that they behave mostly like classical complex numbers:

    >>> exp_polar(2)*exp_polar(3)
    exp_polar(5)

    See Also
    ========

    sympy.simplify.powsimp.powsimp
    polar_lift
    periodic_argument
    principal_branch
    TFc                 C   s   t t| jd S Nr   )r*   r"   r;   r,   r.   r.   r/   	_eval_Abs   s    zexp_polar._eval_Absc                 C   sz   t | jd }z|t kp |tk}W n tk
r<   d}Y nX |rF| S t| jd |}|dkrvt |dk rvt|S |S )z. Careful! any evalf of polar numbers is flaky r   T)r!   r;   r   	TypeErrorr*   _eval_evalfr"   )r-   precibadresr.   r.   r/   rj      s    
zexp_polar._eval_evalfc                 C   s   |  | jd | S rg   )r9   r;   )r-   rR   r.   r.   r/   rQ      s    zexp_polar._eval_powerc                 C   s   | j d jrdS d S )Nr   T)r;   is_extended_realr,   r.   r.   r/   _eval_is_extended_real   s    z exp_polar._eval_is_extended_realc                 C   s"   | j d dkr| tjfS t| S rg   )r;   r   r8   r(   r<   r,   r.   r.   r/   r<      s    
zexp_polar.as_base_expN)r`   ra   rb   __doc__is_polaris_comparablerh   rj   rQ   rp   r<   r.   r.   r.   r/   rf      s   %rf   c                   @   s   e Zd Zdd ZdS )ExpMetac                 C   s&   t |jjkrdS t|to$|jtjkS )NT)r*   	__class____mro__r[   r   baser   Exp1)clsinstancer.   r.   r/   __instancecheck__   s    zExpMeta.__instancecheck__N)r`   ra   rb   r{   r.   r.   r.   r/   rt      s   rt   c                   @   s   e Zd ZdZd,ddZdd Zedd Zed	d
 Z	e
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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 )0r*   a9  
    The exponential function, :math:`e^x`.

    Examples
    ========

    >>> from sympy import exp, I, pi
    >>> from sympy.abc import x
    >>> exp(x)
    exp(x)
    >>> exp(x).diff(x)
    exp(x)
    >>> exp(I*pi)
    -1

    Parameters
    ==========

    arg : Expr

    See Also
    ========

    log
    r0   c                 C   s   |dkr| S t | |dS )z@
        Returns the first derivative of this function.
        r0   N)r   r3   r.   r.   r/   fdiff   s    z	exp.fdiffc                 C   s   ddl m}m} | jd }|jrttj }||| fkr>tjS |	t
t }|r||d| r|||rvtjS |||rtjS |||tj rt S |||tj rtS d S )Nr   )askQ   )Zsympy.assumptionsr}   r~   r;   is_Mulr   r   InfinityNaNas_coefficientr   integerZevenr8   ZoddNegativeOneHalf)r-   Zassumptionsr}   r~   r   ZIoocoeffr.   r.   r/   _eval_refine   s"    

zexp._eval_refinec                 C   s~  ddl m} ddlm} ddlm} ddlm} t||rB|	 S t
jrTttj|S |jr|tjkrjtjS |jrvtjS |tjkrtjS |tjkrtjS |tjkrtjS n|tjkrtjS t|tr|jd S t|| r|t	|jt	|jS t||r|| S |jr|tt }|rd| j rr|j!r<tjS |j"rJtj#S |tj$ j!r^t S |tj$ j"rtS n<|j%r|d }|dkr|d8 }||kr| |t t S |& \}}|tjtjfkr<|j'r8|tjkr| }t(|jr|tjk	rtjS t(|j)r&t*|tjk	r&tjS t(|j+r8tjS d S |gd  }	}
t,-|D ]R}||}t|tr|
d kr|jd }
n d S n|j.r|	/| n d S qR|
r|
t,|	  S d S |j0rlg }g }d}|jD ]p}|tjkr|/| q| |}t|| r:|jd |kr.|/|jd  d	}n
|/| n
|/| q|sT|rlt,| | t1| dd
 S |jrztjS d S )Nr   AccumBounds)
MatrixBaseSetExpr
logcombiner   r0   FTrO   )2sympy.calculusr   Zsympy.matrices.matricesr   sympy.sets.setexprr   sympy.simplify.simplifyr   r[   r*   r   Z
exp_is_powr   r   rx   	is_Numberr   rH   r8   r   rM   Zerorc   r2   r;   minmax
_eval_funcr   r   r   r   
is_integeris_evenZis_oddr   r   is_RationalZas_coeff_Mul	is_numberr"   is_positiver!   r6   r   	make_argsrs   appendrZ   r   )ry   r   r   r   r   r   r   ZncoefftermsZcoeffsZlog_termtermZterm_outaddZ
argchangedaZnewar.   r.   r/   eval  s    















zexp.evalc                 C   s   t jS )z?
        Returns the base of the exponential function.
        )r   rx   r,   r.   r.   r/   rw   {  s    zexp.basec                 G   sT   | dk rt jS | dkrt jS t|}|rD|d }|dk	rD|| |  S ||  t|  S )zJ
        Calculates the next term in the Taylor series expansion.
        r   N)r   r   r8   r   r   )nrX   previous_termspr.   r.   r/   taylor_term  s    zexp.taylor_termTc                 K   sl   ddl m}m} | jd  \}}|rB|j|f|}|j|f|}|||| }}t|| t|| fS )aJ  
        Returns this function as a 2-tuple representing a complex number.

        Examples
        ========

        >>> from sympy import exp, I
        >>> from sympy.abc import x
        >>> exp(x).as_real_imag()
        (exp(re(x))*cos(im(x)), exp(re(x))*sin(im(x)))
        >>> exp(1).as_real_imag()
        (E, 0)
        >>> exp(I).as_real_imag()
        (cos(1), sin(1))
        >>> exp(1+I).as_real_imag()
        (E*cos(1), E*sin(1))

        See Also
        ========

        sympy.functions.elementary.complexes.re
        sympy.functions.elementary.complexes.im
        r   )cossin)(sympy.functions.elementary.trigonometricr   r   r;   as_real_imagexpandr*   )r-   deepr^   r   r   r"   r!   r.   r.   r/   r     s    zexp.as_real_imagc                 C   s   |j rt|jt|j }n|tjkr0|jr0t}t|tsD|tjkrbdd }t	|| |||S |tkr|js|| j
|| S t	| ||S )Nc                 S   s&   | j st| tr"t|  ddiS | S )NrP   F)is_Powr[   r*   r   r<   )r   r.   r.   r/   <lambda>  s
    z exp._eval_subs.<locals>.<lambda>)r   r*   r2   rw   r   rx   Zis_Functionr[   r   
_eval_subs_subsr   )r-   oldnewfr.   r.   r/   r     s    zexp._eval_subsc                 C   sB   | j d jrdS | j d jr>td t | j d  t }|jS d S )Nr   Tr   )r;   ro   is_imaginaryr   r   r   r   r-   Zarg2r.   r.   r/   rp     s
    zexp._eval_is_extended_realc                 C   s   dd }t || jd S )Nc                 s   s   | j V  | jV  d S r)   )
is_complexrC   r   r.   r.   r/   complex_extended_negative  s    z7exp._eval_is_complex.<locals>.complex_extended_negativer   )r   r;   )r-   r   r.   r.   r/   _eval_is_complex  s    zexp._eval_is_complexc                 C   s@   | j t t jrdS t| j jr<| j jr,dS | j t jr<dS d S rA   )r*   r   r   rI   r   rH   is_algebraicr,   r.   r.   r/   _eval_is_algebraic  s    zexp._eval_is_algebraicc                 C   s>   | j jr| jd tjk	S | j jr:t | jd  t }|jS d S rg   )	r*   ro   r;   r   rM   r   r   r   r   r   r.   r.   r/   _eval_is_extended_positive  s
    zexp._eval_is_extended_positiver   c              	      s  ddl m  ddlm} ddlm} ddlm} ddlm	} | j
}	|	j|||d}
|
jr`d|
 S ||
 |d}|tjkr||| |S |tjkr| S t fd	d
|jD r| S td}|}z||	j||d| }W n ttfk
r   d}Y nX |r|dkr||| }t
|||}t
||||
|  }|d k	rR|t|ini }||| krj|S |r|dkr|||
| | |||d |   7 }n|||
| | |7 }| }||ddd}dd }td|gd}|tj| ttj| }|S )Nr   signceiling)limitOrderpowsimpr   logxr0   c                 3   s   | ]}t | tfV  qd S r)   )r[   r   )rW   r   r   r.   r/   rY     s     z$exp._eval_nseries.<locals>.<genexpr>tr   Tr*   r   combinec                 S   s   | j o| jdkS )N)         )r   q)rX   r.   r.   r/   r         z#exp._eval_nseries.<locals>.<lambda>w)
properties) $sympy.functions.elementary.complexesr   #sympy.functions.elementary.integersr   Zsympy.series.limitsr   sympy.series.orderr   sympy.simplify.powsimpr   r*   _eval_nseriesis_OrderremoveOr   rM   r   anyr;   r   as_leading_termgetnNotImplementedErrorr   _taylorsubsr2   r   r   replacer   r   )r-   rX   r   r   cdirr   r   r   r   r   Z
arg_seriesarg0r   ZntermscfZ
exp_seriesrrepZ	simpleratr   r.   r   r/   r     sL    


(zexp._eval_nseriesc                 C   sN   g }d }t |D ]4}| || jd |}|j||d}||  qt| S )Nr   r   )ranger   r;   nseriesr   r   r   )r-   rX   r   lgrl   r.   r.   r/   r     s    zexp._taylorNc                 C   s   ddl m} | jd  j||d}||d}|tjkr@tjS t||rjt	|tj
k rbt| S t|S |tjkr||d}|jdkrt|S td|  d S )Nr   r   r   FCannot expand %s around 0)Zsympy.calculus.utilr   r;   cancelr   r   r   r   r[   r"   r   r*   r   rB   r   )r-   rX   r   r   r   r   r   r.   r.   r/   _eval_as_leading_term  s    




zexp._eval_as_leading_termc                 K   s0   ddl m} |t| td  t|t|   S )Nr   )r   r   )r   r   r   r   )r-   r   kwargsr   r.   r.   r/   _eval_rewrite_as_sin*  s    zexp._eval_rewrite_as_sinc                 K   s0   ddl m} |t| t|t| td    S )Nr   )r   r   )r   r   r   r   )r-   r   r   r   r.   r.   r/   _eval_rewrite_as_cos.  s    zexp._eval_rewrite_as_cosc                 K   s,   ddl m} d||d  d||d   S )Nr   )tanhr0   r   )Z%sympy.functions.elementary.hyperbolicr   )r-   r   r   r   r.   r.   r/   _eval_rewrite_as_tanh2  s    zexp._eval_rewrite_as_tanhc                 K   sl   ddl m}m} |jrh|tt }|rh|jrh|t| |t|  }}t||sht||sh|t|  S d S )Nr   )r   r   )	r   r   r   r   r   r   r   r   r[   )r-   r   r   r   r   r   ZcosineZsiner.   r.   r/   _eval_rewrite_as_sqrt6  s    
zexp._eval_rewrite_as_sqrtc                 K   s<   |j r8dd |jD }|r8t|d jd ||d S d S )Nc                 S   s(   g | ] }t |trt|jd kr|qS )r0   )r[   r2   lenr;   )rW   r   r.   r.   r/   
<listcomp>A  s     
  z,exp._eval_rewrite_as_Pow.<locals>.<listcomp>r   )r   r;   r   r   )r-   r   r   Zlogsr.   r.   r/   _eval_rewrite_as_Pow?  s    zexp._eval_rewrite_as_Pow)r0   )T)r   )Nr   )r`   ra   rb   rq   r|   r   classmethodr   re   rw   staticmethodr   r   r   r   rp   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r*      s0   
	
i

 	
-	
	r*   )	metaclassc                 C   sR   | j tdd\}}|dkr(|jr(||fS |t}|rJ|jrJ|jrJ||fS dS dS )a  
    Try to match expr with $a + Ib$ for real $a$ and $b$.

    ``match_real_imag`` returns a tuple containing the real and imaginary
    parts of expr or ``(None, None)`` if direct matching is not possible. Contrary
    to :func:`~.re()`, :func:`~.im()``, and ``as_real_imag()``, this helper will not force things
    by returning expressions themselves containing ``re()`` or ``im()`` and it
    does not expand its argument either.

    TZas_Addr   )NNN)as_independentr   is_realr   )exprr_i_r.   r.   r/   match_real_imagF  s    
r  c                   @   s   e Zd ZU dZee ed< ejej	fZ
d+ddZd,ddZed-d	d
Zdd Zee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d0d'd(Zd1d)d*ZdS )2r2   a  
    The natural logarithm function `\ln(x)` or `\log(x)`.

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

    Logarithms are taken with the natural base, `e`. To get
    a logarithm of a different base ``b``, use ``log(x, b)``,
    which is essentially short-hand for ``log(x)/log(b)``.

    ``log`` represents the principal branch of the natural
    logarithm. As such it has a branch cut along the negative
    real axis and returns values having a complex argument in
    `(-\pi, \pi]`.

    Examples
    ========

    >>> from sympy import log, sqrt, S, I
    >>> log(8, 2)
    3
    >>> log(S(8)/3, 2)
    -log(3)/log(2) + 3
    >>> log(-1 + I*sqrt(3))
    log(2) + 2*I*pi/3

    See Also
    ========

    exp

    r;   r0   c                 C   s$   |dkrd| j d  S t| |dS )z?
        Returns the first derivative of the function.
        r0   r   N)r;   r   r3   r.   r.   r/   r|     s    z	log.fdiffc                 C   s   t S )zC
        Returns `e^x`, the inverse function of `\log(x)`.
        )r*   r3   r.   r.   r/   r5     s    zlog.inverseNc                 C   s  ddl m} ddlm} t|}|d k	rt|}|dkrL|dkrFtjS tjS zBt||}|rz|t	|||  t	|  W S t	|t	| W S W n t
k
r   Y nX |tjk	r| || | S | |S |jr@|jrtjS |tjkrtjS |tjk rtjS |tjkrtjS |tjkr tjS |jr@|jdkr@| |j S |jrf|jtjkrf|jjrf|jS t|tr|jjr|jS t|tr|jjrt|j\}}|rh|jrh|dt ; }|tkr|dt 8 }|t|t dd S n|t|t rt!|jS t||rR|j"j#r.|t	|j"t	|j$S |j"jrJ|tjt	|j$S tjS nt||rh|%| S |jr|j&rtt | |  S |tjkrtjS |tjkrtjS |jrtjS |j's<|(t}|d k	r<|tjkrtjS |tjkrtjS |jr<|j)r"tt tj* | | S t t tj* | |  S |jr|j+r|j,tdd\}}	|j&rv|d	9 }|	d	9 }	t|	dd}	|	j,td
d\}}|(t}|j-r|r|j-r|j-r|jr|j#rtt tj* | ||  S |j&rt t tj* | ||   S nddl.m/}
 || 0 }| 0 }t1 }||kr|
|t2|	 }|j#rl| |t||   S | |t|| t   S nP||kr|
|t2|	 }|j#r| |t||    S | |tt||    S d S )Nr   r   r   r0   r   Fr   r   r   T)ratsimp)3r   r   r   r   r   r   r   rc   r%   r2   
ValueErrorrx   r   rH   r8   r   r   rM   r   r   r   r   rw   r*   ro   r[   r   r  rs   r   r
   r   rf   r    r   r   r   r   r6   rZ   r   is_nonnegativer   r   r   r   Zsympy.simplifyr  r   _log_atan_tabler#   )ry   r   rw   r   r   r   r  r  r   Zarg_r  r   t1Z
atan_tablemodulusr.   r.   r/   r     s    


 







 


zlog.evalc                 C   s
   | t jfS )zE
        Returns this function in the form (base, exponent).
        )r   r8   r,   r.   r.   r/   r<     s    zlog.as_base_expc                 G   s   ddl m} | dk rtjS t|}| dkr.|S |rb|d }|dk	rb||  | | | d  dddS dd	| d	   || d   | d  S )
zV
        Returns the next term in the Taylor series expansion of `\log(1+x)`.
        r   r   r   Nr0   Tr*   r   r   )r   r   r   r   r   )r   rX   r   r   r   r.   r.   r/   r     s     zlog.taylor_termTc                 K   sn  ddl m}m} |dd}|dd}t| jdkrLt| j| j ||dS | jd }|jrt	|}d }	d}
|dk	r|\}}
| |}	|rt
|}|| krtd	d
 | D }	|	d k	r|
|	 S n|jrt|jt|j S |jrg }g }|jD ]}|s|js|jrN| |}t|trB|| |jf | n
|| q|jrz| | }|| |tj q|| qt| tt|  S |jst|tr2|s|jjr|j js|jd jr|jd j!s|j jrd|j }|j}| |}t|tr$t"||jf | S t"|| S n2t||rd|sN|j#jrd|t|j#f|j$ S | |S )Nr   )rV   rU   forceFfactorr   )r   r  r0   c                 s   s   | ]\}}|t | V  qd S r)   r1   )rW   valr   r.   r.   r/   rY   9  s     z'log._eval_expand_log.<locals>.<genexpr>)%Zsympy.concreterV   rU   getr   r;   r	   r9   Z
is_Integerr&   r'   keyssumitemsr   r2   r   r   r   r   rr   r[   r   _eval_expand_logr6   r   r   r   r   r   r*   ro   rw   is_nonpositiver    r\   r]   )r-   r   r^   rV   rU   r  r  r   r   Zlogargr   r   ZnonposrX   r   rS   rT   r.   r.   r/   r  &  sh    




(

zlog._eval_expand_logc                 K   s~   ddl m}m}m} t| jdkr6|| j| j f|S | || jd f|}|d r^||}||dd}t|| g|d dS )	Nr   )r	   simplifyinversecombiner   r5   Tr  measure)key)r   r	   r  r  r   r;   r9   r   )r-   r   r	   r  r  r   r.   r.   r/   _eval_simplify_  s    zlog._eval_simplifyc                 K   s~   | j d }|r"| j d j|f|}t|}||kr<| tjfS t|}|ddrnd|d< t|j|f||fS t||fS dS )a  
        Returns this function as a complex coordinate.

        Examples
        ========

        >>> from sympy import I, log
        >>> from sympy.abc import x
        >>> log(x).as_real_imag()
        (log(Abs(x)), arg(x))
        >>> log(I).as_real_imag()
        (0, pi/2)
        >>> log(1 + I).as_real_imag()
        (log(sqrt(2)), pi/4)
        >>> log(I*x).as_real_imag()
        (log(Abs(x)), arg(I*x))

        r   r2   FcomplexN)r;   r   r#   r   r   r   r  r2   )r-   r   r^   ZsargZsarg_absZsarg_argr.   r.   r/   r   j  s    

zlog.as_real_imagc                 C   s\   | j | j }|j | j krR| jd d jr,dS |jd jrXt| jd d jrXdS n|jS d S Nr   r0   TF)r9   r;   rH   rI   r   r-   rJ   r.   r.   r/   rL     s     zlog._eval_is_rationalc                 C   s\   | j | j }|j | j krR| jd d jr,dS t| jd d jrX| jd jrXdS n|jS d S r  )r9   r;   rH   r   r   r  r.   r.   r/   r     s    zlog._eval_is_algebraicc                 C   s   | j d jS rg   r;   rD   r,   r.   r.   r/   rp     s    zlog._eval_is_extended_realc                 C   s   | j d }t|jt|jgS rg   )r;   r   r   r   rH   )r-   rK   r.   r.   r/   r     s    
zlog._eval_is_complexc                 C   s   | j d }|jrdS |jS Nr   F)r;   rH   rE   rF   r.   r.   r/   rG     s    
zlog._eval_is_finitec                 C   s   | j d d jS Nr   r0   r  r,   r.   r.   r/   r     s    zlog._eval_is_extended_positivec                 C   s   | j d d jS r  )r;   rH   r,   r.   r.   r/   rN     s    zlog._eval_is_zeroc                 C   s   | j d d jS r  )r;   Zis_extended_nonnegativer,   r.   r.   r/   _eval_is_extended_nonnegative  s    z!log._eval_is_extended_nonnegativer   c           $         s  ddl m} ddlm} ddlm} | jd |krF|d krBt|S |S | jd }|ddd}	|dkrhd}||||	 }
t	d	t	d
 }}|

||	|  }|d k	r|| ||  }}|dkr||	s||	s|d kr|t| n|| }|t||t|  7 }|S dd }z|
j|	|dd\}}W n tttfk
r   |
j|	 |dd}|jr d7  |
j|	 |dd}q\z| j|	dd\}}W n0 tk
r   | j|	ddtj }}Y nX Y nX |
||	|   d j|	 |dd}|tr
||}t||r|  |||	\}}|d kr>t|n|}|jst||t|  ||  }|}dddddddddd	}| jf |}| s| r|| t| jf |}n||t|jf |}||kr|S |||  | S  fdd}i }t| D ]*}|||	\}}||tj| ||< qtj}i }|}||  k rtj |  | } |D ],}!||!tj| ||!   }|! ||!< qr|||}|tj7 }qPt||t|  ||  }|D ]}!|||! |	|!  7 }q|j"rt#|
dkrddl$m%}" t&|
'|	D ]"\}#}|j(r>|#dkr$ qHq$|#dk r|)|	\} }|dt* t+ |"t#|  d 7 }||	|| }|||  | S )Nr   r   r   )r   r   TZpositiver0   kr   c              	   S   s   t jt j }}t| D ]`}||rp| \}}||krxz| |W   S  tk
rl   | t jf Y   S X q||9 }q||fS r)   )	r   r8   r   r   r   hasr<   leadtermr  )r   rX   r   r*   r  rw   r.   r.   r/   	coeff_exp  s    

z$log._eval_nseries.<locals>.coeff_expr   r   )r   r   r   )r   F)	r   r2   mulZ	power_expZ
power_baseZmultinomialbasicr  r  c                    sN   i }t | |D ]:\}}|| }| k r||tj| | ||   ||< q|S r)   )r   r  r   r   )Zd1Zd2rn   e1e2exr   r.   r/   r&     s    $zlog._eval_nseries.<locals>.mul	Heaviside   ),r   r   r   r   sympy.core.symbolr   r;   r2   r   r   matchr"  r#  r  r   r   r   r   r   r   r   r   r*   r[   r   r   r   r7   r   r   r  r8   r   Z	nsimplifyr6   r!   'sympy.functions.special.delta_functionsr,  	enumeratelseriesr   as_coeff_exponentr   r   )$r-   rX   r   r   r   r   r   r   r   r   rK   r!  r   r   r$  r   rS   rJ   r   _drn   Z_resZlogflagsr   r&  Zptermsr   Zco1r(  r   pkr   r*  r,  rl   r.   r   r/   r     s    

"&"   




 zlog._eval_nseriesc                 C   s  | j d  }tddd}|dkr&d}|||| }z|j||dd\}}W n, tk
rz   |j|||d}	t|	 Y S X ||r|||| }|dkrt	d|  t|S |t
jkr|t
jkr|t
j j||dS t||t|  }
|d kr t|n|}|
|| 7 }
|jrt|dkrdd	lm} t||D ]"\}}|jrZ|d
kr@ qdq@|d
k r||\}}|
dt t |t| d 7 }
|
S )Nr   r   Tr   r0   r%  r   r   r+  r-  r.  )r;   Ztogetherr   r   r#  r  r   r2   r"  r   r   r8   r   r6   r!   r1  r,  r2  r3  r   r4  r   r   )r-   rX   r   r   r   r   rK   crT   r   rn   r,  rl   r   r   r5  r.   r.   r/   r   *  s:    


 zlog._eval_as_leading_term)r0   )r0   )N)T)T)r   )Nr   ) r`   ra   rb   rq   tTupler   __annotations__r   r   rc   rd   r|   r5   r   r   r<   r   r   r   r  r  r   rL   r   rp   r   rG   r   rN   r  r   r   r.   r.   r.   r/   r2   [  s0   
!
	
}
9
 

ur2   c                       s|   e Zd ZdZeejddd ejfZe	dddZ
dd	d
Zdd Zdd Zdd ZdddZd fdd	Zdd Z  ZS )LambertWa  
    The Lambert W function $W(z)$ is defined as the inverse
    function of $w \exp(w)$ [1]_.

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

    In other words, the value of $W(z)$ is such that $z = W(z) \exp(W(z))$
    for any complex number $z$.  The Lambert W function is a multivalued
    function with infinitely many branches $W_k(z)$, indexed by
    $k \in \mathbb{Z}$.  Each branch gives a different solution $w$
    of the equation $z = w \exp(w)$.

    The Lambert W function has two partially real branches: the
    principal branch ($k = 0$) is real for real $z > -1/e$, and the
    $k = -1$ branch is real for $-1/e < z < 0$. All branches except
    $k = 0$ have a logarithmic singularity at $z = 0$.

    Examples
    ========

    >>> from sympy import LambertW
    >>> LambertW(1.2)
    0.635564016364870
    >>> LambertW(1.2, -1).n()
    -1.34747534407696 - 4.41624341514535*I
    >>> LambertW(-1).is_real
    False

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Lambert_W_function
    r   FrO   Nc                 C   sN  |t jkr| |S |d kr t j}|jr|jr2t jS |t jkrBt jS |dt j krVt jS |td d krrtd S |dtd krtdS |t d krtt d S |t	dt j krt jS |t j
krt j
S |jrt jS t|jr|jrt jS |t jkrJ|t d krt t d S |dt j kr.t jS |dt	d krJtd S d S )Nr   r   r0   r.  )r   r   rH   rx   r8   r   r2   r   r   r*   r   r   rM   r   )ry   rX   r!  r.   r.   r/   r   |  sB    




zLambertW.evalr0   c                 C   sv   | j d }t| j dkr:|dkrht||dt|   S n.| j d }|dkrht|||dt||   S t| |dS )z?
        Return the first derivative of this function.
        r   r0   N)r;   r   r;  r   )r-   r4   rX   r!  r.   r.   r/   r|     s    

zLambertW.fdiffc                 C   s   | j d }t| j dkr tj}n
| j d }|jrZ|dtj  jrDdS |dtj  jrdS nb|d jr|jr~|dtj  jr~dS |js|dtj  j	rdS n"t
|jrt
|d jr|jrdS d S r  )r;   r   r   r   rH   rx   r   r  r6   r  r   ro   )r-   rX   r!  r.   r.   r/   rp     s"    


zLambertW._eval_is_extended_realc                 C   s   | j d jS rg   )r;   rE   r,   r.   r.   r/   rG     s    zLambertW._eval_is_finitec                 C   sD   | j | j }|j | j kr:t| jd jr@| jd jr@dS n|jS d S r  )r9   r;   r   rH   r   r  r.   r.   r/   r     s
    zLambertW._eval_is_algebraicr   c                 C   sF   t | jdkrB| jd }||d }|js8| |S ||S d S )Nr0   r   )r   r;   r   r   rH   r9   r   )r-   rX   r   r   r   r   r.   r.   r/   r     s    

zLambertW._eval_as_leading_termc           
         s   t | jdkrddlm} ddlm} | jd j|||d  j||d}d}|jrZ|j	}||| dkrt
 fddtd||| D  }	t|	}	ntj}	|	||| | S t |||S )	Nr0   r   r   r   r   r   c                    s@   g | ]8}t j |d   t||d   t|d    |  qS )r0   r   )r   r8   r   r   )rW   r!  r   r.   r/   r     s   
z*LambertW._eval_nseries.<locals>.<listcomp>)r   r;   r   r   r   r   r   r   r   r*   r   r   r   r   r   superr   )
r-   rX   r   r   r   r   r   ltZlterJ   ru   r   r/   r     s     
zLambertW._eval_nseriesc                 C   s8   | j d }t| j dkr|jS t|j| j d jgS d S r  )r;   r   rH   r   )r-   rX   r.   r.   r/   rN     s    
zLambertW._eval_is_zero)N)r0   )Nr   )r   )r`   ra   rb   rq   r   r   rx   rc   rd   r   r   r|   rp   rG   r   r   r   rN   __classcell__r.   r.   r>  r/   r;  W  s   "%

r;  c                )   C   s"  t dtd dtd t ddt d  td t dt dt d  dt d  td t ddt d  ttdd t dt t dd  dt d  ttdd t dd td t dd td t dt d t t dd  td t dd ttdd t t dd t dt d  ttdd t ddt d d  td	 t d t d	 dt t dd   td	 t ddt d d  ttdd	 t dt d	 dt dt d   ttdd	 dt d td
 dt d dt d  td
 dt d ttdd
 dt d dt d  ttdd
 iS )Nr   r0   r   r-  r   r   r      
      )r$   r   r   r.   r.   r.   r/   r    sN       "  " 
 
  
   $  " 
  
  r  N)B	itertoolsr   typingr   r9  Zsympy.core.addr   Zsympy.core.cacher   Zsympy.core.exprr   Zsympy.core.functionr   r   r	   r
   r   r   r   r   Zsympy.core.logicr   r   r   Zsympy.core.mulr   Zsympy.core.numbersr   r   r   r   r   Zsympy.core.parametersr   Zsympy.core.powerr   Zsympy.core.singletonr   r/  r   r   Zsympy.core.sympifyr   Z(sympy.functions.combinatorial.factorialsr   r   r   r    r!   r"   r#   Z(sympy.functions.elementary.miscellaneousr$   Zsympy.ntheoryr%   r&   Zsympy.ntheory.factor_r'   r(   rf   rt   r*   r  r2   r;  r  r.   r.   r.   r/   <module>   sD   (fI  o      