
    wgK.                        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 Z G d	 d
e      Zd Z G d de      Z e	d      Zd Z G d de      Zd Z G d de      Zd Z G d de      Z e	d      Zd Z G d de      Zd Z G d de      Zd Z G d  d!e      Z d" Z! G d# d$e      Z" G d% d&e      Z#y')(a#  
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)sqrtc                 :    t        |       t        j                  z
  S Nr   r   Onexs    ]/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/codegen/cfunctions.py_expm1r      s    q6AEE>    c                   H    e Zd ZdZdZd
dZd Zd ZeZe	d        Z
d Zd Zy	)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                 H    |dk(  rt        | j                   S t        | |      @
        Returns the first derivative of this function.
        r   )r   argsr   selfargindexs     r   fdiffzexpm1.fdiff4   s&     q=		?"$T844r   c                 &    t        | j                   S r   )r   r   r   hintss     r   _eval_expand_funczexpm1._eval_expand_func=       tyy!!r   c                 :    t        |      t        j                  z
  S r   r   r   argkwargss      r   _eval_rewrite_as_expzexpm1._eval_rewrite_as_exp@   s    3x!%%r   c                 X    t        j                  |      }||t        j                  z
  S y r   )r   evalr   r   )clsr&   exp_args      r   r*   z
expm1.evalE   s(    ((3-QUU?" r   c                 4    | j                   d   j                  S Nr   )r   is_realr   s    r   _eval_is_realzexpm1._eval_is_realK       yy|###r   c                 4    | j                   d   j                  S r.   )r   	is_finiter0   s    r   _eval_is_finitezexpm1._eval_is_finiteN   s    yy|%%%r   Nr   )__name__
__module____qualname____doc__nargsr   r"   r(   _eval_rewrite_as_tractableclassmethodr*   r1   r5    r   r   r   r      sA    8 E5"  "6# #
$&r   r   c                 :    t        | t        j                  z         S r   )r	   r   r   r   s    r   _log1pr@   R   s    q155y>r   c                   Z    e Zd ZdZdZddZd Zd ZeZe	d        Z
d Zd Zd	 Zd
 Zd Zy)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                     |dk(  r1t         j                  | j                  d   t         j                  z   z  S t        | |      r   r   r   )r   r   r   r   r   s     r   r   zlog1p.fdiffw   s8     q=55$))A,.//$T844r   c                 &    t        | j                   S r   )r@   r   r    s     r   r"   zlog1p._eval_expand_func   r#   r   c                     t        |      S r   )r@   r%   s      r   _eval_rewrite_as_logzlog1p._eval_rewrite_as_log       c{r   c                    |j                   rt        |t        j                  z         S |j                  s&t        j
                  |t        j                  z         S |j                  r%t        t        |      t        j                  z         S y r   )is_Rationalr	   r   r   is_Floatr*   	is_numberr   r+   r&   s     r   r*   z
log1p.eval   s^    ??sQUU{##88C!%%K((]]x}quu,-- r   c                 V    | j                   d   t        j                  z   j                  S r.   )r   r   r   is_nonnegativer0   s    r   r1   zlog1p._eval_is_real   s    		!quu$444r   c                     | j                   d   t        j                  z   j                  ry| j                   d   j                  S )Nr   F)r   r   r   is_zeror4   r0   s    r   r5   zlog1p._eval_is_finite   s3    IIaL155 ))yy|%%%r   c                 4    | j                   d   j                  S r.   )r   is_positiver0   s    r   _eval_is_positivezlog1p._eval_is_positive   s    yy|'''r   c                 4    | j                   d   j                  S r.   )r   rQ   r0   s    r   _eval_is_zerozlog1p._eval_is_zero   r2   r   c                 4    | j                   d   j                  S r.   )r   rO   r0   s    r   _eval_is_nonnegativezlog1p._eval_is_nonnegative   s    yy|***r   Nr6   )r7   r8   r9   r:   r;   r   r"   rG   r<   r=   r*   r1   r5   rT   rV   rX   r>   r   r   rB   rB   V   sP    : E5" "6. .5&
($+r   rB      c                 "    t        t        |       S r   )r   _Twor   s    r   _exp2r\      s    tQ<r   c                   <    e Zd ZdZdZddZd ZeZd Ze	d        Z
y)	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                 H    |dk(  r| t        t              z  S t        | |      r   )r	   r[   r   r   s     r   r   z
exp2.fdiff   s&     q=D	>!$T844r   c                     t        |      S r   )r\   r%   s      r   _eval_rewrite_as_Powzexp2._eval_rewrite_as_Pow       Szr   c                 &    t        | j                   S r   )r\   r   r    s     r   r"   zexp2._eval_expand_func       dii  r   c                 2    |j                   rt        |      S y r   )rL   r\   rM   s     r   r*   z	exp2.eval   s    ==: r   Nr6   )r7   r8   r9   r:   r;   r   ra   r<   r"   r=   r*   r>   r   r   r^   r^      s9    2 E5 "6!  r   r^   c                 8    t        |       t        t              z  S r   )r	   r[   r   s    r   _log2rg          q6#d)r   c                   B    e Zd ZdZdZd	dZed        Zd Zd Z	d Z
e
Zy)
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                     |dk(  r0t         j                  t        t              | j                  d   z  z  S t        | |      rD   )r   r   r	   r[   r   r   r   s     r   r   z
log2.fdiff   8     q=55#d)DIIaL011$T844r   c                     |j                   r*t        j                  |t              }|j                  r|S y |j
                  r |j                  t        k(  r|j                  S y y N)base)rL   r	   r*   r[   is_Atomis_Powro   r   r+   r&   results      r   r*   z	log2.eval  L    ==XXc-F~~ ZZCHH,77N -Zr   c                 L     | j                  t              j                  |i |S r   )rewriter	   evalf)r   r   r'   s      r   _eval_evalfzlog2._eval_evalf  s#    &t||C &&777r   c                 &    t        | j                   S r   )rg   r   r    s     r   r"   zlog2._eval_expand_func  rd   r   c                     t        |      S r   )rg   r%   s      r   rG   zlog2._eval_rewrite_as_log  rb   r   Nr6   )r7   r8   r9   r:   r;   r   r=   r*   rx   r"   rG   r<   r>   r   r   rj   rj      s>    4 E5  8! "6r   rj   c                     | |z  |z   S r   r>   )r   yzs      r   _fmar~     s    Q37Nr   c                   *    e Zd ZdZdZddZd ZddZy)	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

       c                 p    |dv r| j                   d|z
     S |dk(  rt        j                  S t        | |      )r   r   rY   rY   r   )r   r   r   r   r   s     r   r   z	fma.fdiff6  s<     v99Q\**]55L$T844r   c                 &    t        | j                   S r   )r~   r   r    s     r   r"   zfma._eval_expand_funcB  s    TYYr   Nc                     t        |      S r   )r~   )r   r&   limitvarr'   s       r   r<   zfma._eval_rewrite_as_tractableE  s    Cyr   r6   r   )r7   r8   r9   r:   r;   r   r"   r<   r>   r   r   r   r      s    & E	5 r   r   
   c                 8    t        |       t        t              z  S r   )r	   _Tenr   s    r   _log10r   L  rh   r   c                   <    e Zd ZdZdZddZed        Zd Zd Z	e	Z
y)	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                     |dk(  r0t         j                  t        t              | j                  d   z  z  S t        | |      rD   )r   r   r	   r   r   r   r   s     r   r   zlog10.fdiffe  rl   r   c                     |j                   r*t        j                  |t              }|j                  r|S y |j
                  r |j                  t        k(  r|j                  S y y rn   )rL   r	   r*   r   rp   rq   ro   r   rr   s      r   r*   z
log10.evalo  rt   r   c                 &    t        | j                   S r   )r   r   r    s     r   r"   zlog10._eval_expand_funcx  r#   r   c                     t        |      S r   )r   r%   s      r   rG   zlog10._eval_rewrite_as_log{  rH   r   Nr6   )r7   r8   r9   r:   r;   r   r=   r*   r"   rG   r<   r>   r   r   r   r   P  s9    $ E5  " "6r   r   c                 6    t        | t        j                        S r   )r   r   Halfr   s    r   _Sqrtr     s    q!&&>r   c                   ,    e Zd ZdZdZddZd Zd ZeZy)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                 x    |dk(  r*t        | j                  d   t        dd            t        z  S t	        | |      )r   r   r   rY   r   r   r   r[   r   r   s     r   r   z
Sqrt.fdiff  s8     q=tyy|Xb!_5d::$T844r   c                 &    t        | j                   S r   )r   r   r    s     r   r"   zSqrt._eval_expand_func  rd   r   c                     t        |      S r   )r   r%   s      r   ra   zSqrt._eval_rewrite_as_Pow  rb   r   Nr6   	r7   r8   r9   r:   r;   r   r"   ra   r<   r>   r   r   r   r     s%    2 E5! "6r   r   c                 .    t        | t        dd            S )Nr   r   )r   r   r   s    r   _Cbrtr     s    q(1a.!!r   c                   ,    e Zd ZdZdZddZd Zd ZeZy)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                 ~    |dk(  r-t        | j                  d   t        t         dz              dz  S t	        | |      )r   r   r   r   r   r   s     r   r   z
Cbrt.fdiff  s=     q=tyy|XteAg%6799$T844r   c                 &    t        | j                   S r   )r   r   r    s     r   r"   zCbrt._eval_expand_func  rd   r   c                     t        |      S r   )r   r%   s      r   ra   zCbrt._eval_rewrite_as_Pow  rb   r   Nr6   r   r>   r   r   r   r     s%    2 E5! "6r   r   c                 F    t        t        | d      t        |d      z         S )NrY   )r
   r   )r   r|   s     r   _hypotr     s    Aq	C1I%&&r   c                   ,    e Zd ZdZdZddZd Zd ZeZy)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)

    rY   c                     |dv r6d| j                   |dz
     z  t         | j                  | j                    z  z  S t        | |      )r   r   rY   r   )r   r[   funcr   r   s     r   r   zhypot.fdiff  sJ     vTYYxz**DDII1F,FGG$T844r   c                 &    t        | j                   S r   )r   r   r    s     r   r"   zhypot._eval_expand_func  r#   r   c                     t        |      S r   )r   r%   s      r   ra   zhypot._eval_rewrite_as_Pow  rH   r   Nr6   r   r>   r   r   r   r     s%    . E5" "6r   r   c                       e Zd ZdZy)isnanr   N)r7   r8   r9   r;   r>   r   r   r   r     s    Er   r   N)$r:   sympy.core.functionr   r   sympy.core.numbersr   sympy.core.powerr   sympy.core.singletonr   &sympy.functions.elementary.exponentialr   r	   (sympy.functions.elementary.miscellaneousr
   r   r   r@   rB   r[   r\   r^   rg   rj   r~   r   r   r   r   r   r   r   r   r   r   r   r>   r   r   <module>r      s    = '   " ; 9:&H :&zK+H K+Z 	t18 1h968 96x&( &R 	u.6H .6b+68 +6\",68 ,6^'*6H *6ZH r   