o
    FZh+0                     @   st  d Z ddl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mZmZ d	d
 ZG dd deZdd ZG dd deZe	dZdd ZG dd deZdd ZG dd deZdd ZG dd deZe	dZdd  ZG d!d" d"eZ d#d$ Z!G d%d& d&eZ"d'd( Z#G d)d* d*eZ$d+d, Z%G d-d. d.eZ&G d/d0 d0eZ'G d1d2 d2eZ(d3S )4a#  
This module contains SymPy functions mathcin corresponding to special math functions in the
C standard library (since C99, also available in C++11).

The functions defined in this module allows the user to express functions such as ``expm1``
as a SymPy function for symbolic manipulation.

    )ArgumentIndexErrorFunction)Rational)Pow)S)explog)sqrt)BooleanFunctiontruefalsec                 C   s   t | tj S Nr   r   Onex r   G/var/www/auris/lib/python3.10/site-packages/sympy/codegen/cfunctions.py_expm1      r   c                   @   sN   e Zd ZdZdZdddZdd Zdd ZeZe	d	d
 Z
dd Zdd ZdS )expm1a*  
    Represents the exponential function minus one.

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

    The benefit of using ``expm1(x)`` over ``exp(x) - 1``
    is that the latter is prone to cancellation under finite precision
    arithmetic when x is close to zero.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import expm1
    >>> '%.0e' % expm1(1e-99).evalf()
    '1e-99'
    >>> from math import exp
    >>> exp(1e-99) - 1
    0.0
    >>> expm1(x).diff(x)
    exp(x)

    See Also
    ========

    log1p
       c                 C   s   |dkr	t | j S t| |@
        Returns the first derivative of this function.
        r   )r   argsr   selfZargindexr   r   r   fdiff4   s   

zexpm1.fdiffc                 K   
   t | j S r   )r   r   r   hintsr   r   r   _eval_expand_func=      
zexpm1._eval_expand_funcc                 K   s   t |tj S r   r   r   argkwargsr   r   r   _eval_rewrite_as_exp@   r   zexpm1._eval_rewrite_as_expc                 C   s    t |}|d ur|tj S d S r   )r   evalr   r   )clsr$   Zexp_argr   r   r   r'   E   s   

z
expm1.evalc                 C      | j d jS Nr   )r   Zis_realr   r   r   r   _eval_is_realK      zexpm1._eval_is_realc                 C   r)   r*   )r   	is_finiter+   r   r   r   _eval_is_finiteN   r-   zexpm1._eval_is_finiteNr   )__name__
__module____qualname____doc__nargsr   r!   r&   _eval_rewrite_as_tractableclassmethodr'   r,   r/   r   r   r   r   r      s    
	
r   c                 C   s   t | tj S r   )r   r   r   r   r   r   r   _log1pR   r   r8   c                   @   sf   e Zd ZdZdZdddZdd Zdd ZeZe	d	d
 Z
dd Zdd Zdd Zdd Zdd ZdS )log1paf  
    Represents the natural logarithm of a number plus one.

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

    The benefit of using ``log1p(x)`` over ``log(x + 1)``
    is that the latter is prone to cancellation under finite precision
    arithmetic when x is close to zero.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import log1p
    >>> from sympy import expand_log
    >>> '%.0e' % expand_log(log1p(1e-99)).evalf()
    '1e-99'
    >>> from math import log
    >>> log(1 + 1e-99)
    0.0
    >>> log1p(x).diff(x)
    1/(x + 1)

    See Also
    ========

    expm1
    r   c                 C   s(   |dkrt j| jd t j  S t| |r   r   r   )r   r   r   r   r   r   r   r   r   w   s   
zlog1p.fdiffc                 K   r   r   )r8   r   r   r   r   r   r!      r"   zlog1p._eval_expand_funcc                 K      t |S r   )r8   r#   r   r   r   _eval_rewrite_as_log      zlog1p._eval_rewrite_as_logc                 C   sF   |j r
t|tj S |jst|tj S |jr!tt|tj S d S r   )Zis_Rationalr   r   r   Zis_Floatr'   	is_numberr   r(   r$   r   r   r   r'      s   z
log1p.evalc                 C   s   | j d tj jS r*   )r   r   r   is_nonnegativer+   r   r   r   r,      s   zlog1p._eval_is_realc                 C   s"   | j d tj jrdS | j d jS )Nr   F)r   r   r   is_zeror.   r+   r   r   r   r/      s   zlog1p._eval_is_finitec                 C   r)   r*   )r   Zis_positiver+   r   r   r   _eval_is_positive   r-   zlog1p._eval_is_positivec                 C   r)   r*   )r   rA   r+   r   r   r   _eval_is_zero   r-   zlog1p._eval_is_zeroc                 C   r)   r*   )r   r@   r+   r   r   r   _eval_is_nonnegative   r-   zlog1p._eval_is_nonnegativeNr0   )r1   r2   r3   r4   r5   r   r!   r<   r6   r7   r'   r,   r/   rB   rC   rD   r   r   r   r   r9   V   s    


r9      c                 C   s
   t t| S r   )r   _Twor   r   r   r   _exp2   r"   rG   c                   @   s>   e Zd ZdZdZdddZdd ZeZdd Ze	d	d
 Z
dS )exp2a  
    Represents the exponential function with base two.

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

    The benefit of using ``exp2(x)`` over ``2**x``
    is that the latter is not as efficient under finite precision
    arithmetic.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import exp2
    >>> exp2(2).evalf() == 4.0
    True
    >>> exp2(x).diff(x)
    log(2)*exp2(x)

    See Also
    ========

    log2
    r   c                 C   s   |dkr
| t t S t| |r   )r   rF   r   r   r   r   r   r      s   
z
exp2.fdiffc                 K   r;   r   )rG   r#   r   r   r   _eval_rewrite_as_Pow   r=   zexp2._eval_rewrite_as_Powc                 K   r   r   )rG   r   r   r   r   r   r!      r"   zexp2._eval_expand_funcc                 C   s   |j rt|S d S r   )r>   rG   r?   r   r   r   r'      s   z	exp2.evalNr0   )r1   r2   r3   r4   r5   r   rI   r6   r!   r7   r'   r   r   r   r   rH      s    
	rH   c                 C      t | t t S r   )r   rF   r   r   r   r   _log2      rK   c                   @   sF   e Zd ZdZdZdddZedd Zdd Zd	d
 Z	dd Z
e
ZdS )log2a  
    Represents the logarithm function with base two.

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

    The benefit of using ``log2(x)`` over ``log(x)/log(2)``
    is that the latter is not as efficient under finite precision
    arithmetic.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import log2
    >>> log2(4).evalf() == 2.0
    True
    >>> log2(x).diff(x)
    1/(x*log(2))

    See Also
    ========

    exp2
    log10
    r   c                 C   *   |dkrt jtt| jd   S t| |r:   )r   r   r   rF   r   r   r   r   r   r   r         
z
log2.fdiffc                 C   @   |j rtj|td}|jr|S d S |jr|jtkr|jS d S d S N)base)r>   r   r'   rF   is_Atomis_PowrR   r   r(   r$   resultr   r   r   r'        z	log2.evalc                 O   s   |  tj|i |S r   )Zrewriter   Zevalf)r   r   r%   r   r   r   _eval_evalf  s   zlog2._eval_evalfc                 K   r   r   )rK   r   r   r   r   r   r!     r"   zlog2._eval_expand_funcc                 K   r;   r   )rK   r#   r   r   r   r<     r=   zlog2._eval_rewrite_as_logNr0   )r1   r2   r3   r4   r5   r   r7   r'   rX   r!   r<   r6   r   r   r   r   rM      s    


rM   c                 C   s   | | | S r   r   )r   yzr   r   r   _fma  r-   r[   c                   @   s0   e Zd ZdZdZdddZdd Zdd	d
ZdS )fmaa  
    Represents "fused multiply add".

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

    The benefit of using ``fma(x, y, z)`` over ``x*y + z``
    is that, under finite precision arithmetic, the former is
    supported by special instructions on some CPUs.

    Examples
    ========

    >>> from sympy.abc import x, y, z
    >>> from sympy.codegen.cfunctions import fma
    >>> fma(x, y, z).diff(x)
    y

       r   c                 C   s.   |dv r| j d|  S |dkrtjS t| |)r   r   rE   rE   r]   )r   r   r   r   r   r   r   r   r   6  s
   
z	fma.fdiffc                 K   r   r   )r[   r   r   r   r   r   r!   B  r"   zfma._eval_expand_funcNc                 K   r;   r   )r[   )r   r$   Zlimitvarr%   r   r   r   r6   E  r=   zfma._eval_rewrite_as_tractabler0   r   )r1   r2   r3   r4   r5   r   r!   r6   r   r   r   r   r\      s    
r\   
   c                 C   rJ   r   )r   _Tenr   r   r   r   _log10L  rL   ra   c                   @   s>   e Zd ZdZdZdddZedd Zdd Zd	d
 Z	e	Z
dS )log10a$  
    Represents the logarithm function with base ten.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import log10
    >>> log10(100).evalf() == 2.0
    True
    >>> log10(x).diff(x)
    1/(x*log(10))

    See Also
    ========

    log2
    r   c                 C   rN   r:   )r   r   r   r`   r   r   r   r   r   r   r   e  rO   zlog10.fdiffc                 C   rP   rQ   )r>   r   r'   r`   rS   rT   rR   r   rU   r   r   r   r'   o  rW   z
log10.evalc                 K   r   r   )ra   r   r   r   r   r   r!   x  r"   zlog10._eval_expand_funcc                 K   r;   r   )ra   r#   r   r   r   r<   {  r=   zlog10._eval_rewrite_as_logNr0   )r1   r2   r3   r4   r5   r   r7   r'   r!   r<   r6   r   r   r   r   rb   P  s    


rb   c                 C   s   t | tjS r   )r   r   ZHalfr   r   r   r   _Sqrt  r-   rc   c                   @   2   e Zd ZdZdZd
ddZdd Zdd ZeZd	S )Sqrta  
    Represents the square root function.

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

    The reason why one would use ``Sqrt(x)`` over ``sqrt(x)``
    is that the latter is internally represented as ``Pow(x, S.Half)`` which
    may not be what one wants when doing code-generation.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import Sqrt
    >>> Sqrt(x)
    Sqrt(x)
    >>> Sqrt(x).diff(x)
    1/(2*sqrt(x))

    See Also
    ========

    Cbrt
    r   c                 C   s,   |dkrt | jd tddt S t| |)r   r   r   rE   r   r   r   rF   r   r   r   r   r   r     s   
z
Sqrt.fdiffc                 K   r   r   )rc   r   r   r   r   r   r!     r"   zSqrt._eval_expand_funcc                 K   r;   r   )rc   r#   r   r   r   rI     r=   zSqrt._eval_rewrite_as_PowNr0   	r1   r2   r3   r4   r5   r   r!   rI   r6   r   r   r   r   re     s    
	re   c                 C   s   t | tddS )Nr   r]   )r   r   r   r   r   r   _Cbrt  rL   ri   c                   @   rd   )Cbrta  
    Represents the cube root function.

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

    The reason why one would use ``Cbrt(x)`` over ``cbrt(x)``
    is that the latter is internally represented as ``Pow(x, Rational(1, 3))`` which
    may not be what one wants when doing code-generation.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy.codegen.cfunctions import Cbrt
    >>> Cbrt(x)
    Cbrt(x)
    >>> Cbrt(x).diff(x)
    1/(3*x**(2/3))

    See Also
    ========

    Sqrt
    r   c                 C   s0   |dkrt | jd tt d d S t| |)r   r   r   r]   rg   r   r   r   r   r     s   
z
Cbrt.fdiffc                 K   r   r   )ri   r   r   r   r   r   r!     r"   zCbrt._eval_expand_funcc                 K   r;   r   )ri   r#   r   r   r   rI     r=   zCbrt._eval_rewrite_as_PowNr0   rh   r   r   r   r   rj     s    

rj   c                 C   s   t t| dt|d S )NrE   )r	   r   )r   rY   r   r   r   _hypot  s   rk   c                   @   s2   e Zd ZdZdZdddZdd Zdd	 ZeZd
S )hypota  
    Represents the hypotenuse function.

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

    The hypotenuse function is provided by e.g. the math library
    in the C99 standard, hence one may want to represent the function
    symbolically when doing code-generation.

    Examples
    ========

    >>> from sympy.abc import x, y
    >>> from sympy.codegen.cfunctions import hypot
    >>> hypot(3, 4).evalf() == 5.0
    True
    >>> hypot(x, y)
    hypot(x, y)
    >>> hypot(x, y).diff(x)
    x/hypot(x, y)

    rE   r   c                 C   s4   |dv rd| j |d   t| j| j    S t| |)r   r^   rE   r   )r   rF   funcr   r   r   r   r   r     s   "
zhypot.fdiffc                 K   r   r   )rk   r   r   r   r   r   r!     r"   zhypot._eval_expand_funcc                 K   r;   r   )rk   r#   r   r   r   rI     r=   zhypot._eval_rewrite_as_PowNr0   rh   r   r   r   r   rl     s    

rl   c                   @      e Zd ZdZedd ZdS )isnanr   c                 C   s   |t ju rtS |jrtS d S r   )r   NaNr   r>   r   r?   r   r   r   r'     s
   
z
isnan.evalNr1   r2   r3   r5   r7   r'   r   r   r   r   ro         ro   c                   @   rn   )isinfr   c                 C   s   |j rtS |jr
tS d S r   )is_infiniter   r.   r   r?   r   r   r   r'   '  s
   z
isinf.evalNrq   r   r   r   r   rs   $  rr   rs   N))r4   Zsympy.core.functionr   r   Zsympy.core.numbersr   Zsympy.core.powerr   Zsympy.core.singletonr   Z&sympy.functions.elementary.exponentialr   r   Z(sympy.functions.elementary.miscellaneousr	   Zsympy.logic.boolalgr
   r   r   r   r   r8   r9   rF   rG   rH   rK   rM   r[   r\   r`   ra   rb   rc   re   ri   rj   rk   rl   ro   rs   r   r   r   r   <module>   s<    =M4<)1./-