o
    8Vaz                     @   s  d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ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mZ d
d ZG dd deZdd 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(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,S )-    )	FuzzyBool)SsympifycacheitpiIRational)Add)FunctionArgumentIndexError_coeff_isneg)	factorialRisingFactorial)explogmatch_real_imag)sqrt)floor)fuzzy_or	fuzzy_andc                 C   s"   t | } | dd | tD S )Nc                 S   s   i | ]}|| tqS  )Zrewriter   ).0hr   r   G/usr/lib/python3/dist-packages/sympy/functions/elementary/hyperbolic.py
<dictcomp>   s    z/_rewrite_hyperbolics_as_exp.<locals>.<dictcomp>)r   ZxreplaceZatomsHyperbolicFunction)exprr   r   r   _rewrite_hyperbolics_as_exp   s   
r   c                   @   s   e Zd ZdZdZdS )r   ze
    Base class for hyperbolic functions.

    See Also
    ========

    sinh, cosh, tanh, coth
    TN)__name__
__module____qualname____doc__Z
unbranchedr   r   r   r   r      s    	r   c                 C   s   t | D ]%}|tjtj krtj} n|jr*| \}}|tjtj kr*|jr* nq| tj	fS |tj
 tj tj }|tj tj | }| | |fS )a  
    Split ARG into two parts, a "rest" and a multiple of I*pi/2.
    This assumes ARG to be an Add.
    The multiple of I*pi returned in the second position is always a Rational.

    Examples
    ========

    >>> from sympy.functions.elementary.hyperbolic import _peeloff_ipi as peel
    >>> from sympy import pi, I
    >>> from sympy.abc import x, y
    >>> peel(x + I*pi/2)
    (x, I*pi/2)
    >>> peel(x + I*2*pi/3 + I*pi*y)
    (x + I*pi*y + I*pi/6, I*pi/2)
    )r	   Z	make_argsr   PiImaginaryUnitOneis_Mulas_two_termsZis_RationalZeroHalf)argaKpZm1Zm2r   r   r   _peeloff_ipi%   s   
r-   c                   @   s   e Zd ZdZd.ddZd.ddZedd Zee	d	d
 Z
dd Zd/ddZd/ddZd/ddZd0ddZdd Zdd Zdd Zdd Zd1d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- ZdS )2sinha  
    sinh(x) is the hyperbolic sine of x.

    The hyperbolic sine function is $\frac{e^x - e^{-x}}{2}$.

    Examples
    ========

    >>> from sympy import sinh
    >>> from sympy.abc import x
    >>> sinh(x)
    sinh(x)

    See Also
    ========

    cosh, tanh, asinh
       c                 C       |dkrt | jd S t| |)z@
        Returns the first derivative of this function.
        r/   r   )coshargsr   selfargindexr   r   r   fdiffZ   s   
z
sinh.fdiffc                 C      t S z7
        Returns the inverse of this function.
        )asinhr3   r   r   r   inversec      zsinh.inversec                 C   s  ddl m} t|}|jr6|tju rtjS |tju rtjS |tju r%tjS |jr+tj	S |j
r4| |  S d S |tju r>tjS |tj}|d urOtj|| S t|rY| |  S |jrtt|\}}|rtt|t| t|t|  S |jrztj	S |jtkr|jd S |jtkr|jd }t|d t|d  S |jtkr|jd }|td|d   S |jtkr|jd }dt|d t|d   S d S )Nr   )sinr/      )sympyr<   r   	is_Numberr   NaNInfinityNegativeInfinityis_zeror'   is_negativeComplexInfinityas_coefficientr#   r   is_Addr-   r.   r1   funcr9   r2   acoshr   atanhacoth)clsr)   r<   i_coeffxmr   r   r   evali   sN   



 







z	sinh.evalc                 G   s^   | dk s
| d dkrt jS t|}t|dkr'|d }||d  | | d   S ||  t|  S )zG
        Returns the next term in the Taylor series expansion.
        r   r=   r/   r   r'   r   lenr   nrN   previous_termsr,   r   r   r   taylor_term   s   zsinh.taylor_termc                 C      |  | jd  S Nr   rH   r2   	conjugater4   r   r   r   _eval_conjugate      zsinh._eval_conjugateTc                 K      ddl m}m} | jd jr%|r d|d< | j|fi |tjfS | tjfS |r8| jd j|fi | \}}n	| jd  \}}t	||| t
||| fS )z@
        Returns this function as a complex coordinate.
        r   cosr<   Fcomplexr>   ra   r<   r2   is_extended_realexpandr   r'   as_real_imagr.   r1   r4   deephintsra   r<   reimr   r   r   rf      s   
" zsinh.as_real_imagc                 K   &   | j dd|i|\}}||tj  S Nrh   r   rf   r   r#   r4   rh   ri   Zre_partZim_partr   r   r   _eval_expand_complex      zsinh._eval_expand_complexc                 K   s   |r| j d j|fi |}n| j d }d }|jr | \}}n|jdd\}}|tjur=|jr=|tjur=|}|d | }|d urUt|t	| t|t	|  jddS t|S Nr   TZrationalr/   )Ztrig)
r2   re   rG   r&   as_coeff_Mulr   r$   
is_Integerr.   r1   r4   rh   ri   r)   rN   ycoefftermsr   r   r   _eval_expand_trig      
(zsinh._eval_expand_trigNc                 K      t |t |  d S Nr=   r   r4   r)   limitvarkwargsr   r   r   _eval_rewrite_as_tractable      zsinh._eval_rewrite_as_tractablec                 K   r|   r}   r~   r4   r)   r   r   r   r   _eval_rewrite_as_exp   r   zsinh._eval_rewrite_as_expc                 K       t j t|t jt j d   S r}   r   r#   r1   r"   r   r   r   r   _eval_rewrite_as_cosh       zsinh._eval_rewrite_as_coshc                 K   s"   t tj| }d| d|d   S Nr=   r/   tanhr   r(   r4   r)   r   Z	tanh_halfr   r   r   _eval_rewrite_as_tanh      zsinh._eval_rewrite_as_tanhc                 K   s"   t tj| }d| |d d  S r   cothr   r(   r4   r)   r   Z	coth_halfr   r   r   _eval_rewrite_as_coth   r   zsinh._eval_rewrite_as_cothr   c                 C   sd   | j d j|||d}||d}|tju r#|j|d|jrdndd}|jr(|S |jr0| 	|S | S Nr   )logxcdir-+)dir)
r2   as_leading_termsubsr   r@   limitrD   rC   	is_finiterH   r4   rN   r   r   r)   Zarg0r   r   r   _eval_as_leading_term   s   

zsinh._eval_as_leading_termc                 C   s*   | j d }|jr
dS | \}}|t jS Nr   Tr2   is_realrf   r   rC   r4   r)   rj   rk   r   r   r   _eval_is_real   s
   

zsinh._eval_is_realc                 C      | j d jrdS d S r   r2   rd   r\   r   r   r   _eval_is_extended_real      zsinh._eval_is_extended_realc                 C      | j d jr| j d jS d S rY   r2   rd   is_positiver\   r   r   r   _eval_is_positive     zsinh._eval_is_positivec                 C   r   rY   r2   rd   rD   r\   r   r   r   _eval_is_negative  r   zsinh._eval_is_negativec                 C      | j d }|jS rY   r2   r   r4   r)   r   r   r   _eval_is_finite     
zsinh._eval_is_finitec                 C      | j d }|jr
dS d S r   r2   rC   r   r   r   r   _eval_is_zero     
zsinh._eval_is_zeror/   TNrY   )r   r   r    r!   r6   r:   classmethodrP   staticmethodr   rW   r]   rf   rp   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r.   F   s2    

	
3





r.   c                   @   s   e Zd ZdZd(ddZedd Zeedd Z	d	d
 Z
d)ddZd)ddZd)ddZd*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S ),r1   a  
    cosh(x) is the hyperbolic cosine of x.

    The hyperbolic cosine function is $\frac{e^x + e^{-x}}{2}$.

    Examples
    ========

    >>> from sympy import cosh
    >>> from sympy.abc import x
    >>> cosh(x)
    cosh(x)

    See Also
    ========

    sinh, tanh, acosh
    r/   c                 C   r0   Nr/   r   r.   r2   r   r3   r   r   r   r6   )  s   
z
cosh.fdiffc                 C   sv  ddl m} t|}|jr5|tju rtjS |tju rtjS |tju r%tjS |jr+tj	S |j
r3| | S d S |tju r=tjS |tj}|d urK||S t|rT| | S |jrot|\}}|rot|t| t|t|  S |jrutj	S |jtkrtd|jd d  S |jtkr|jd S |jtkrdtd|jd d   S |jtkr|jd }|t|d t|d   S d S )Nr   )ra   r/   r=   )r>   ra   r   r?   r   r@   rA   rB   rC   r$   rD   rE   rF   r#   r   rG   r-   r1   r.   rH   r9   r   r2   rI   rJ   rK   )rL   r)   ra   rM   rN   rO   r   r   r   rP   /  sJ   





 





z	cosh.evalc                 G   s^   | dk s
| d dkrt jS t|}t|dkr'|d }||d  | | d   S ||  t|  S )Nr   r=   r/   rQ   rR   rT   r   r   r   rW   `  s   zcosh.taylor_termc                 C   rX   rY   rZ   r\   r   r   r   r]   n  r^   zcosh._eval_conjugateTc                 K   r_   )Nr   r`   Frb   )r>   ra   r<   r2   rd   re   r   r'   rf   r1   r.   rg   r   r   r   rf   q  s   
" zcosh.as_real_imagc                 K   rl   rm   rn   ro   r   r   r   rp     rq   zcosh._eval_expand_complexc                 K   s   |r| j d j|fi |}n| j d }d }|jr | \}}n|jdd\}}|tjur=|jr=|tjur=|}|d | }|d urUt|t| t	|t	|  jddS t|S rr   )
r2   re   rG   r&   rt   r   r$   ru   r1   r.   rv   r   r   r   rz     r{   zcosh._eval_expand_trigNc                 K      t |t |  d S r}   r~   r   r   r   r   r     r   zcosh._eval_rewrite_as_tractablec                 K   r   r}   r~   r   r   r   r   r     r   zcosh._eval_rewrite_as_expc                 K   r   r}   r   r#   r.   r"   r   r   r   r   _eval_rewrite_as_sinh  r   zcosh._eval_rewrite_as_sinhc                 K   s"   t tj| d }d| d|  S r   r   r   r   r   r   r        zcosh._eval_rewrite_as_tanhc                 K   s"   t tj| d }|d |d  S r   r   r   r   r   r   r     r   zcosh._eval_rewrite_as_cothr   c                 C   sf   | j d j|||d}||d}|tju r#|j|d|jrdndd}|jr)tjS |j	r1| 
|S | S r   )r2   r   r   r   r@   r   rD   rC   r$   r   rH   r   r   r   r   r     s   

zcosh._eval_as_leading_termc                 C   s0   | j d }|js|jrdS | \}}|t jS r   )r2   r   Zis_imaginaryrf   r   rC   r   r   r   r   r     s
   

zcosh._eval_is_realc              	   C   sr   | j d }| \}}|dt  }|j}|rdS |j}|du r!|S t|t|t|td k |dt d kgggS Nr   r=   TF   r2   rf   r   rC   r   r   r4   zrN   rw   ZymodZyzeroZxzeror   r   r   r     s    
zcosh._eval_is_positivec              	   C   sr   | j d }| \}}|dt  }|j}|rdS |j}|du r!|S t|t|t|td k|dt d kgggS r   r   r   r   r   r   _eval_is_nonnegative  s    
zcosh._eval_is_nonnegativec                 C   r   rY   r   r   r   r   r   r     r   zcosh._eval_is_finiter   r   r   rY   )r   r   r    r!   r6   r   rP   r   r   rW   r]   rf   rp   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r1     s,    

0




 r1   c                   @   s   e Zd ZdZd,ddZd,ddZedd Zee	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dZd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ ZdS )0r   a  
    tanh(x) is the hyperbolic tangent of x.

    The hyperbolic tangent function is $\frac{\sinh(x)}{\cosh(x)}$.

    Examples
    ========

    >>> from sympy import tanh
    >>> from sympy.abc import x
    >>> tanh(x)
    tanh(x)

    See Also
    ========

    sinh, cosh, atanh
    r/   c                 C   s*   |dkrt jt| jd d  S t| |Nr/   r   r=   )r   r$   r   r2   r   r3   r   r   r   r6     s   
z
tanh.fdiffc                 C   r7   r8   )rJ   r3   r   r   r   r:     r;   ztanh.inversec                 C   s  ddl m} t|}|jr6|tju rtjS |tju rtjS |tju r%tj	S |j
r+tjS |jr4| |  S d S |tju r>tjS |tj}|d ur\t|rUtj ||  S tj|| S t|rf| |  S |jrt|\}}|rt|}|tju r~t|S t|S |j
rtjS |jtkr|jd }|td|d   S |jtkr|jd }t|d t|d  | S |jtkr|jd S |jtkrd|jd  S d S )Nr   )tanr/   r=   )r>   r   r   r?   r   r@   rA   r$   rB   NegativeOnerC   r'   rD   rE   rF   r#   r   rG   r-   r   r   rH   r9   r2   r   rI   rJ   rK   )rL   r)   r   rM   rN   rO   Ztanhmr   r   r   rP     sV   











z	tanh.evalc                 G   sn   ddl m} | dk s| d dkrtjS t|}d| d  }|| d }t| d }||d  | | ||   S )Nr   	bernoullir=   r/   )r>   r   r   r'   r   r   )rU   rN   rV   r   r*   BFr   r   r   rW   W  s   ztanh.taylor_termc                 C   rX   rY   rZ   r\   r   r   r   r]   g  r^   ztanh._eval_conjugateTc                 K   s   ddl m}m} | jd jr%|r d|d< | j|fi |tjfS | tjfS |r8| jd j|fi | \}}n	| jd  \}}t	|d ||d  }t	|t
| | |||| | fS Nr   r`   Frb   r=   rc   r4   rh   ri   ra   r<   rj   rk   denomr   r   r   rf   j  s   
"(ztanh.as_real_imagc                 K   s2  | j d }|jr=ddlm} t|j }dd |j D }ddg}t|d D ]}||d   |||7  < q%|d |d  S |jrddlm} |	 \}	}
|	j
r|	dkrg }g }t|
}td|	d dD ]}||t|	|||   qctd|	d dD ]}||t|	|||   q|t| t|  S t|S )Nr   symmetric_polyc                 S      g | ]
}t |d d qS FZevaluate)r   rz   r   rN   r   r   r   
<listcomp>~  s    z*tanh._eval_expand_trig.<locals>.<listcomp>r/   r=   )nC)r2   rG   r>   r   rS   ranger%   %sympy.functions.combinatorial.numbersr   rt   ru   r   appendr	   )r4   ri   r)   r   rU   ZTXr,   ir   rx   ry   dTkr   r   r   rz   y  s0   

ztanh._eval_expand_trigNc                 K   s$   t | t |}}|| ||  S r   r~   r4   r)   r   r   neg_exppos_expr   r   r   r        ztanh._eval_rewrite_as_tractablec                 K   s$   t | t |}}|| ||  S r   r~   r4   r)   r   r   r   r   r   r   r     r   ztanh._eval_rewrite_as_expc                 K   s&   t jt| tt jt j d |  S r}   r   r   r   r   r   r        &ztanh._eval_rewrite_as_sinhc                 K   s&   t jtt jt j d |  t| S r}   r   r   r   r   r   r     r   ztanh._eval_rewrite_as_coshc                 K      dt | S Nr/   r   r   r   r   r   r        ztanh._eval_rewrite_as_cothr   c                 C   D   ddl m} | jd |}||jv r|d||r|S | |S Nr   Orderr/   r>   r   r2   r   free_symbolscontainsrH   r4   rN   r   r   r   r)   r   r   r   r     
   
ztanh._eval_as_leading_termc                 C   sJ   | j d }|jr
dS | \}}|dkr|t td krd S |td  jS )Nr   Tr=   r   r   r   r   r   r     s   
ztanh._eval_is_realc                 C   r   r   r   r\   r   r   r   r     r   ztanh._eval_is_extended_realc                 C   r   rY   r   r\   r   r   r   r     r   ztanh._eval_is_positivec                 C   r   rY   r   r\   r   r   r   r     r   ztanh._eval_is_negativec                 C   sb   ddl m}m} | jd }| \}}||d ||d  }|dkr%dS |jr*dS |jr/dS d S )Nr   )r.   ra   r=   FT)r>   r.   ra   r2   rf   	is_numberrd   )r4   r.   ra   r)   rj   rk   r   r   r   r   r     s   
ztanh._eval_is_finitec                 C   r   r   r   r   r   r   r   r     r   ztanh._eval_is_zeror   r   r   rY   )r   r   r    r!   r6   r:   r   rP   r   r   rW   r]   rf   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s0    


7


	r   c                   @   s   e Zd ZdZd$ddZd$ddZedd Zee	d	d
 Z
dd Zd%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 d!Zd"d# ZdS )(r   a#  
    coth(x) is the hyperbolic cotangent of x.

    The hyperbolic cotangent function is $\frac{\cosh(x)}{\sinh(x)}$.

    Examples
    ========

    >>> from sympy import coth
    >>> from sympy.abc import x
    >>> coth(x)
    coth(x)

    See Also
    ========

    sinh, cosh, acoth
    r/   c                 C   s(   |dkrdt | jd d  S t| |)Nr/   r   r=   r   r3   r   r   r   r6        
z
coth.fdiffc                 C   r7   r8   )rK   r3   r   r   r   r:     r;   zcoth.inversec                 C   s  ddl m} t|}|jr6|tju rtjS |tju rtjS |tju r%tj	S |j
r+tjS |jr4| |  S d S |tju r>tjS |tj}|d ur\t|rTtj||  S tj || S t|rf| |  S |jrt|\}}|rt|}|tju r~t|S t|S |j
rtjS |jtkr|jd }td|d  | S |jtkr|jd }|t|d t|d   S |jtkrd|jd  S |jtkr|jd S d S )Nr   )cotr/   r=   )r>   r   r   r?   r   r@   rA   r$   rB   r   rC   rE   rD   rF   r#   r   rG   r-   r   r   rH   r9   r2   r   rI   rJ   rK   )rL   r)   r   rM   rN   rO   Zcothmr   r   r   rP     sV   











z	coth.evalc                 G   sv   ddl m} | dkrdt| S | dk s| d dkrtjS t|}|| d }t| d }d| d  | | ||   S )Nr   r   r/   r=   r>   r   r   r   r'   r   rU   rN   rV   r   r   r   r   r   r   rW   2  s   zcoth.taylor_termc                 C   rX   rY   rZ   r\   r   r   r   r]   B  r^   zcoth._eval_conjugateTc                 K   s   ddl m}m} | jd jr%|r d|d< | j|fi |tjfS | tjfS |r8| jd j|fi | \}}n	| jd  \}}t	|d ||d  }t	|t
| | || || | fS r   rc   r   r   r   r   rf   E  s   
"*zcoth.as_real_imagNc                 K   s$   t | t |}}|| ||  S r   r~   r   r   r   r   r   T  r   zcoth._eval_rewrite_as_tractablec                 K   s$   t | t |}}|| ||  S r   r~   r   r   r   r   r   X  r   zcoth._eval_rewrite_as_expc                 K   s(   t j tt jt j d |  t| S r}   r   r   r   r   r   r   \     (zcoth._eval_rewrite_as_sinhc                 K   s(   t j t| tt jt j d |  S r}   r   r   r   r   r   r   _  r   zcoth._eval_rewrite_as_coshc                 K   r   r   r   r   r   r   r   r   b  r   zcoth._eval_rewrite_as_tanhc                 C   r   rY   r   r\   r   r   r   r   e  r   zcoth._eval_is_positivec                 C   r   rY   r   r\   r   r   r   r   i  r   zcoth._eval_is_negativer   c                 C   sH   ddl m} | jd |}||jv r|d||rd| S | |S r   r   r   r   r   r   r   m  s
   
zcoth._eval_as_leading_termc                 K   s  | j d }|jrBddlm} dd |j D }g g g}t|j }t|ddD ]}||| d  ||| q%t|d  t|d   S |jrddlm	} |j
d	d
\}	}
|	jr|	dkrt|
dd}g g g}t|	ddD ]}||	| d  ||	|||   qjt|d  t|d   S t|S )Nr   r   c                 S   r   r   )r   rz   r   r   r   r   r   z  s    z*coth._eval_expand_trig.<locals>.<listcomp>r   r=   r/   )binomialTrs   Fr   )r2   rG   r>   r   rS   r   r   r	   r%   r   rt   ru   r   )r4   ri   r)   r   ZCXr,   rU   r   r   rx   rN   cr   r   r   rz   v  s&   

&zcoth._eval_expand_trigr   r   r   rY   )r   r   r    r!   r6   r:   r   rP   r   r   rW   r]   rf   r   r   r   r   r   r   r   r   rz   r   r   r   r   r     s(    


7


	r   c                   @   s   e 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 Zd#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dZdd  Zd!d" ZdS )&ReciprocalHyperbolicFunctionz=Base class for reciprocal functions of hyperbolic functions. Nc                 C   sj   |  r| jr| | S | jr| |  S | j|}t|dr+| | kr+|jd S |d ur3d| S |S )Nr:   r   r/   )Zcould_extract_minus_sign_is_even_is_odd_reciprocal_ofrP   hasattrr:   r2   )rL   r)   tr   r   r   rP     s   

z!ReciprocalHyperbolicFunction.evalc                 O   s$   |  | jd }t|||i |S rY   )r  r2   getattr)r4   method_namer2   r   or   r   r   _call_reciprocal  s   z-ReciprocalHyperbolicFunction._call_reciprocalc                 O   s,   | j |g|R i |}|d urd| S |S r   )r	  )r4   r  r2   r   r  r   r   r   _calculate_reciprocal  s   z2ReciprocalHyperbolicFunction._calculate_reciprocalc                 C   s2   |  ||}|d ur|| |krd| S d S d S r   )r	  r  )r4   r  r)   r  r   r   r   _rewrite_reciprocal  s   z0ReciprocalHyperbolicFunction._rewrite_reciprocalc                 K      |  d|S )Nr   r  r   r   r   r   r     r   z1ReciprocalHyperbolicFunction._eval_rewrite_as_expc                 K   r  )Nr   r  r   r   r   r   r     r   z7ReciprocalHyperbolicFunction._eval_rewrite_as_tractablec                 K   r  )Nr   r  r   r   r   r   r     r   z2ReciprocalHyperbolicFunction._eval_rewrite_as_tanhc                 K   r  )Nr   r  r   r   r   r   r     r   z2ReciprocalHyperbolicFunction._eval_rewrite_as_cothTc                 K   s"   d|  | jd  j|fi |S r   )r  r2   rf   )r4   rh   ri   r   r   r   rf     s   "z)ReciprocalHyperbolicFunction.as_real_imagc                 C   rX   rY   rZ   r\   r   r   r   r]     r^   z,ReciprocalHyperbolicFunction._eval_conjugatec                 K   s&   | j dddi|\}}|tj|  S )Nrh   Tr   rn   ro   r   r   r   rp     rq   z1ReciprocalHyperbolicFunction._eval_expand_complexc                 K   s   | j di |S )Nrz   )rz   )r
  )r4   ri   r   r   r   rz     s   z.ReciprocalHyperbolicFunction._eval_expand_trigr   c                 C   s   d|  | jd  |S r   )r  r2   r   )r4   rN   r   r   r   r   r   r     s   z2ReciprocalHyperbolicFunction._eval_as_leading_termc                 C   s   |  | jd jS rY   )r  r2   rd   r\   r   r   r   r     s   z3ReciprocalHyperbolicFunction._eval_is_extended_realc                 C   s   d|  | jd  jS r   )r  r2   r   r\   r   r   r   r     r   z,ReciprocalHyperbolicFunction._eval_is_finiter   r   rY   )r   r   r    r!   r  r  r  r   rP   r	  r
  r  r   r   r   r   rf   r]   rp   rz   r   r   r   r   r   r   r   r     s*    




r   c                   @   sJ   e Zd ZdZeZdZdddZee	dd Z
dd	 Zd
d Zdd ZdS )cscha0  
    csch(x) is the hyperbolic cosecant of x.

    The hyperbolic cosecant function is $\frac{2}{e^x - e^{-x}}$

    Examples
    ========

    >>> from sympy import csch
    >>> from sympy.abc import x
    >>> csch(x)
    csch(x)

    See Also
    ========

    sinh, cosh, tanh, sech, asinh, acosh
    Tr/   c                 C   0   |dkrt | jd  t| jd  S t| |)z?
        Returns the first derivative of this function
        r/   r   )r   r2   r  r   r3   r   r   r   r6     s   
z
csch.fdiffc                 G   sz   ddl m} | dkrdt| S | dk s| d dkrtjS t|}|| d }t| d }ddd|    | | ||   S )zF
        Returns the next term in the Taylor series expansion
        r   r   r/   r=   r   r   r   r   r   rW     s    zcsch.taylor_termc                 K      t jt|t jt j d   S r}   r   r   r   r   r   r   	     zcsch._eval_rewrite_as_coshc                 C   r   rY   r   r\   r   r   r   r     r   zcsch._eval_is_positivec                 C   r   rY   r   r\   r   r   r   r     r   zcsch._eval_is_negativeNr   )r   r   r    r!   r.   r  r  r6   r   r   rW   r   r   r   r   r   r   r   r    s    
	r  c                   @   sB   e Zd ZdZeZdZdddZee	dd Z
dd	 Zd
d ZdS )secha2  
    sech(x) is the hyperbolic secant of x.

    The hyperbolic secant function is $\frac{2}{e^x + e^{-x}}$

    Examples
    ========

    >>> from sympy import sech
    >>> from sympy.abc import x
    >>> sech(x)
    sech(x)

    See Also
    ========

    sinh, cosh, tanh, coth, csch, asinh, acosh
    Tr/   c                 C   r  r   )r   r2   r  r   r3   r   r   r   r6   ,  s   
z
sech.fdiffc                 G   sF   ddl m} | dk s| d dkrtjS t|}|| t|  ||   S )Nr   )eulerr=   r/   )r   r  r   r'   r   r   )rU   rN   rV   r  r   r   r   rW   2  s
   zsech.taylor_termc                 K   r  r}   r   r   r   r   r   r   <  r  zsech._eval_rewrite_as_sinhc                 C   r   r   r   r\   r   r   r   r   ?  r   zsech._eval_is_positiveNr   )r   r   r    r!   r1   r  r  r6   r   r   rW   r   r   r   r   r   r   r    s    
r  c                   @   s   e Zd ZdZdS )InverseHyperbolicFunctionz,Base class for inverse hyperbolic functions.N)r   r   r    r!   r   r   r   r   r  H  s    r  c                   @   sZ   e Zd ZdZdddZedd Zeedd Z	dddZ
dd ZdddZdd Zd	S )r9   aE  
    asinh(x) is the inverse hyperbolic sine of x.

    The inverse hyperbolic sine function.

    Examples
    ========

    >>> from sympy import asinh
    >>> from sympy.abc import x
    >>> asinh(x).diff(x)
    1/sqrt(x**2 + 1)
    >>> asinh(1)
    log(1 + sqrt(2))

    See Also
    ========

    acosh, atanh, sinh
    r/   c                 C   s,   |dkrdt | jd d d  S t| |r   r   r2   r   r3   r   r   r   r6   d     
zasinh.fdiffc           
      C   s  ddl m} t|}|jrO|tju rtjS |tju rtjS |tju r%tjS |jr+tj	S |tj
u r8ttdd S |tju rEttdd S |jrN| |  S n)|tju rWtjS |jr]tj	S |tj}|d urntj|| S t|rx| |  S t|tr|jd jr|jd }|jr|S t|\}}|d ur|d urt|td  t }|tt |  }|j}	|	du r|S |	du r| S d S d S d S d S d S )Nr   )asinr=   r/   TF)r>   r  r   r?   r   r@   rA   rB   rC   r'   r$   r   r   r   rD   rE   rF   r#   r   
isinstancer.   r2   r   r   r   r   r   r   is_even)
rL   r)   r  rM   r   rr   frO   evenr   r   r   rP   j  sV   






z
asinh.evalc                 G   s   | dk s
| d dkrt jS t|}t|dkr2| dkr2|d }| | d d  | | d   |d  S | d d }tt j|}t|}d| | | ||   |  S )Nr   r=   rQ   r/   r   )r   r'   r   rS   r   r(   r   rU   rN   rV   r,   r   Rr   r   r   r   rW     s   &zasinh.taylor_termNr   c                 C   r   r   r   r   r   r   r   r     r   zasinh._eval_as_leading_termc                 K   s   t |t|d d  S r   r   r   r4   rN   r   r   r   r   _eval_rewrite_as_log  s   zasinh._eval_rewrite_as_logc                 C   r7   r8   )r.   r3   r   r   r   r:     r;   zasinh.inversec                 C   r   r   r   r   r   r   r   r     r   zasinh._eval_is_zeror   rY   )r   r   r    r!   r6   r   rP   r   r   rW   r   r!  r:   r   r   r   r   r   r9   N  s    

0
	
r9   c                   @   R   e Zd ZdZdddZedd Zeedd Z	dddZ
dd ZdddZd	S )rI   a:  
    acosh(x) is the inverse hyperbolic cosine of x.

    The inverse hyperbolic cosine function.

    Examples
    ========

    >>> from sympy import acosh
    >>> from sympy.abc import x
    >>> acosh(x).diff(x)
    1/sqrt(x**2 - 1)
    >>> acosh(1)
    0

    See Also
    ========

    asinh, atanh, cosh
    r/   c                 C   s,   |dkrdt | jd d d  S t| |r   r  r3   r   r   r   r6     r  zacosh.fdiffc           
   
   C   sT  t |}|jr=|tju rtjS |tju rtjS |tju rtjS |jr*tjtj d S |tj	u r2tj
S |tju r=tjtj S |jrri tjttjdtd  tj ttj dtd  tjtjd tddtjtdd tdd tjd td d tjtdd dtd tjd dtd tjtdd tdd tjd td d tjtdd tdd td tjtdd	 tdd  td tjtd
d	 tdtd d tjd tdtd  d tjtd
d tdtd d tjtdd tdtd  d tjtdd dtd dtd  tjd	 dtd  dtd  tjtdd	 tdd d tjd tdd  d tjtdd i}||v rr|jrn|| tj S || S |tju r{tjS |tjtj krtjtjtj d  S |tj tj krtjtjtj d  S |jrtjtj tj S t|tr|jd jr |jd }|jrddlm} ||S t|\}}|d ur"|d ur$t|t }|tt |  }|j}	|	du r|jr|S |jr| S d S |	du r&|tt 8 }|j r| S |j!r(|S d S d S d S d S d S d S )Nr=   r/   r   r                        r   )AbsTF)"r   r?   r   r@   rA   rB   rC   r"   r#   r$   r'   r   r   r   r   r(   r   rd   rE   r  r1   r2   r   Z$sympy.functions.elementary.complexesr*  r   r   r   r   r  Zis_nonnegativerD   Zis_nonpositiver   )
rL   r)   	cst_tabler   r*  r  r   r  rO   r  r   r   r   rP     s   




	
 "" "&



	z
acosh.evalc                 G   s   | dkrt jt j d S | dk s| d dkrt jS t|}t|dkr=| dkr=|d }|| d d  | | d   |d  S | d d }tt j|}t|}| | t j ||   |  S )Nr   r=   rQ   r/   )	r   r"   r#   r'   r   rS   r   r(   r   r  r   r   r   rW   .  s   $zacosh.taylor_termNr   c                 C   P   ddl m} | jd |}||jv r#|d||r#tjtj d S | 	|S Nr   r   r/   r=   
r>   r   r2   r   r   r   r   r#   r"   rH   r   r   r   r   r   @  
   
zacosh._eval_as_leading_termc                 K   s    t |t|d t|d   S r   r  r   r   r   r   r!  I  r   zacosh._eval_rewrite_as_logc                 C   r7   r8   )r1   r3   r   r   r   r:   L  r;   zacosh.inverser   rY   r   r   r    r!   r6   r   rP   r   r   rW   r   r!  r:   r   r   r   r   rI     s    

N
	rI   c                   @   sZ   e Zd ZdZdddZedd Zeedd Z	dddZ
dd Zdd ZdddZd	S )rJ   a!  
    atanh(x) is the inverse hyperbolic tangent of x.

    The inverse hyperbolic tangent function.

    Examples
    ========

    >>> from sympy import atanh
    >>> from sympy.abc import x
    >>> atanh(x).diff(x)
    1/(1 - x**2)

    See Also
    ========

    asinh, acosh, tanh
    r/   c                 C   (   |dkrdd| j d d   S t| |r   r2   r   r3   r   r   r   r6   g  r   zatanh.fdiffc                 C   s  ddl m} t|}|jrO|tju rtjS |jrtjS |tju r#tj	S |tj
u r+tjS |tj	u r8tj || S |tju rEtj||  S |jrN| |  S n5|tju riddlm} tj|tj d tjd  S |tj}|d urztj|| S t|r| |  S |jrtjS t|tr|jd jr|jd }|jr|S t|\}}|d ur|d urtd| t }|j}	|t| t d  }
|	du r|
S |	du r|
tt d  S d S d S d S d S d S )Nr   )atanAccumBoundsr=   TF)r>   r3  r   r?   r   r@   rC   r'   r$   rA   r   rB   r#   rD   rE   sympy.calculus.utilr5  r"   rF   r   r  r   r2   r   r   r   r   r   r  r   )rL   r)   r3  r5  rM   r   r  r   r  r  rO   r   r   r   rP   m  sX   






z
atanh.evalc                 G   s.   | dk s
| d dkrt jS t|}||  |  S Nr   r=   )r   r'   r   rU   rN   rV   r   r   r   rW     s   zatanh.taylor_termNr   c                 C   r   r   r   r   r   r   r   r     r   zatanh._eval_as_leading_termc                 K   s   t d| t d|  d S Nr/   r=   r   r   r   r   r   r!    s   zatanh._eval_rewrite_as_logc                 C   r   r   r   r   r   r   r   r     r   zatanh._eval_is_zeroc                 C   r7   r8   r   r3   r   r   r   r:     r;   zatanh.inverser   rY   )r   r   r    r!   r6   r   rP   r   r   rW   r   r!  r   r:   r   r   r   r   rJ   S  s    

1
	rJ   c                   @   r"  )rK   a%  
    acoth(x) is the inverse hyperbolic cotangent of x.

    The inverse hyperbolic cotangent function.

    Examples
    ========

    >>> from sympy import acoth
    >>> from sympy.abc import x
    >>> acoth(x).diff(x)
    1/(1 - x**2)

    See Also
    ========

    asinh, acosh, coth
    r/   c                 C   r1  r   r2  r3   r   r   r   r6     r   zacoth.fdiffc                 C   s   ddl m} t|}|jrJ|tju rtjS |tju rtjS |tju r%tjS |j	r0tj
tj d S |tju r8tjS |tju r@tjS |jrI| |  S n$|tju rRtjS |tj}|d urdtj || S t|rn| |  S |j	rztj
tj tj S d S )Nr   )acotr=   )r>   r;  r   r?   r   r@   rA   r'   rB   rC   r"   r#   r$   r   rD   rE   rF   r   r(   )rL   r)   r;  rM   r   r   r   rP     s8   





z
acoth.evalc                 G   sF   | dkrt jt j d S | dk s| d dkrt jS t|}||  |  S r7  )r   r"   r#   r'   r   r8  r   r   r   rW     s   zacoth.taylor_termNr   c                 C   r,  r-  r.  r   r   r   r   r   	  r/  zacoth._eval_as_leading_termc                 K   s$   t dd|  t dd|   d S r9  r:  r   r   r   r   r!    s   $zacoth._eval_rewrite_as_logc                 C   r7   r8   r   r3   r   r   r   r:     r;   zacoth.inverser   rY   r0  r   r   r   r   rK     s    

"
		rK   c                   @   sH   e Zd ZdZdddZedd Zeedd Z	dd	d
Z
dd ZdS )asecha  
    asech(x) is the inverse hyperbolic secant of x.

    The inverse hyperbolic secant function.

    Examples
    ========

    >>> from sympy import asech, sqrt, S
    >>> from sympy.abc import x
    >>> asech(x).diff(x)
    -1/(x*sqrt(1 - x**2))
    >>> asech(1).diff(x)
    0
    >>> asech(1)
    0
    >>> asech(S(2))
    I*pi/3
    >>> asech(-sqrt(2))
    3*I*pi/4
    >>> asech((sqrt(6) - sqrt(2)))
    I*pi/12

    See Also
    ========

    asinh, atanh, cosh, acoth

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Hyperbolic_function
    .. [2] http://dlmf.nist.gov/4.37
    .. [3] http://functions.wolfram.com/ElementaryFunctions/ArcSech/

    r/   c                 C   s4   |dkr| j d }d|td|d    S t| |Nr/   r   r   r=   r2   r   r   r4   r5   r   r   r   r   r6   B  s   

zasech.fdiffc                 C   s  t |}|jrB|tju rtjS |tju rtjtj d S |tju r)tjtj d S |jr/tjS |tj	u r7tj
S |tju rBtjtj S |jri tjtjtj d  tdtd  tj tjtj d tdtd  tdtd tjd tdtd dtj d tddtd  tjd tddtd   dtj d dtdtd  tjd	 d
tdtd  dtj d	 dtd tjd d
td dtj d tdd tjd dtd dtj d tdtjd td dtj d tddtd  dtj d tddtd   dtj d tdtjd td dtj d tddtd  dtj d	 tddtd   dtj d	 dtd dtj d dtd dtj d tdtd dtj d td td dtj d i}||v r|jr|| tj S || S |tju rddlm} tj|tj d tjd  S |jrtjS d S )Nr=   r/   r$  r'  r)  r%  
   	   r&  rQ   r(  r   r#  r   r   r4  )r   r?   r   r@   rA   r"   r#   rB   rC   r$   r'   r   r   r   r   rd   rE   r6  r5  )rL   r)   r+  r5  r   r   r   rP   I  s   




$$ 	
  
z
asech.evalc                 G   s   | dkr
t d| S | dk s| d dkrtjS t|}t|dkr=| dkr=|d }|| d d  | d d  |d  d S | d }ttj||  }t||  d |  d }d| | ||   d S )Nr   r=   r/   rQ   r#  r   )r   r   r'   r   rS   r   r(   r   r  r   r   r   expansion_term  s   (zasech.expansion_termc                 C   r7   r8   )r  r3   r   r   r   r:     r;   zasech.inversec                 K   s,   t d| td| d td| d   S r   r  r   r   r   r   r!    s   ,zasech._eval_rewrite_as_logNr   )r   r   r    r!   r6   r   rP   r   r   rB  r:   r!  r   r   r   r   r<    s    
%
9
r<  c                   @   s8   e Zd ZdZdddZedd ZdddZd	d
 ZdS )acscha  
    acsch(x) is the inverse hyperbolic cosecant of x.

    The inverse hyperbolic cosecant function.

    Examples
    ========

    >>> from sympy import acsch, sqrt, S
    >>> from sympy.abc import x
    >>> acsch(x).diff(x)
    -1/(x**2*sqrt(1 + x**(-2)))
    >>> acsch(1).diff(x)
    0
    >>> acsch(1)
    log(1 + sqrt(2))
    >>> acsch(S.ImaginaryUnit)
    -I*pi/2
    >>> acsch(-2*S.ImaginaryUnit)
    I*pi/6
    >>> acsch(S.ImaginaryUnit*(sqrt(6) - sqrt(2)))
    -5*I*pi/12

    See Also
    ========

    asinh

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Hyperbolic_function
    .. [2] http://dlmf.nist.gov/4.37
    .. [3] http://functions.wolfram.com/ElementaryFunctions/ArcCsch/

    r/   c                 C   s<   |dkr| j d }d|d tdd|d     S t| |r=  r>  r?  r   r   r   r6     s   
 
zacsch.fdiffc                 C   sN  t |}|jr@|tju rtjS |tju rtjS |tju rtjS |jr%tjS |tj	u r2t
dtd S |tju r@t
dtd  S |jr
tjtj d tjtdtd  tj d tjdtd  tj d tjd tdtd  tj d tjd tj d tjtddtd   tj d tjtd tj d tjtdd  d	tj d tjd td
 tj d
 tjd tdtd  d	tj d tjtddtd   dtj d tjtdtd  dtj d tdtj t
dtd d  i}||v r
|| tj S |tju rtjS |jrtjS t|r%| |  S d S )Nr/   r=   r$  r'  r%  r@  r&  r#  r   rQ   )r   r?   r   r@   rA   r'   rB   rC   rE   r$   r   r   r   r   r#   r"   r   )rL   r)   r+  r   r   r   rP     sL   




""$$  

z
acsch.evalc                 C   r7   r8   )r  r3   r   r   r   r:     r;   zacsch.inversec                 K   s    t d| td|d  d  S r9  r  r   r   r   r   r!    r   zacsch._eval_rewrite_as_logNr   )	r   r   r    r!   r6   r   rP   r:   r!  r   r   r   r   rC    s    
%

.rC  N)-Zsympy.core.logicr   Z
sympy.corer   r   r   r   r   r   Zsympy.core.addr	   Zsympy.core.functionr
   r   r   Z(sympy.functions.combinatorial.factorialsr   r   Z&sympy.functions.elementary.exponentialr   r   r   Z(sympy.functions.elementary.miscellaneousr   Z#sympy.functions.elementary.integersr   r   r   r   r   r-   r.   r1   r   r   r   r  r  r  r9   rI   rJ   rK   r<  rC  r   r   r   r   <module>   s@     ! P k \ 3J?3u n[ 