
    Xh+0                        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	 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' G d( d)e          Z(d*S )+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)sqrt)BooleanFunctiontruefalsec                 :    t          |           t          j        z
  S Nr   r   Onexs    j/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/codegen/cfunctions.py_expm1r      s    q66AE>    c                   P    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	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                 J    |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44r   c                     t          | j         S r   )r   r   r   hintss     r   _eval_expand_funczexpm1._eval_expand_func=       ty!!r   c                 :    t          |          t          j        z
  S r   r   r   argkwargss      r   _eval_rewrite_as_expzexpm1._eval_rewrite_as_exp@   s    3xx!%r   c                 P    t          j        |          }||t          j        z
  S d S r   )r   evalr   r   )clsr)   exp_args      r   r-   z
expm1.evalE   s)    (3--QU?" r   c                 &    | j         d         j        S Nr   )r   is_realr   s    r   _eval_is_realzexpm1._eval_is_realK       y|##r   c                 &    | j         d         j        S r1   )r   	is_finiter3   s    r   _eval_is_finitezexpm1._eval_is_finiteN   s    y|%%r   Nr   )__name__
__module____qualname____doc__nargsr!   r%   r+   _eval_rewrite_as_tractableclassmethodr-   r4   r8    r   r   r   r      s         8 E5 5 5 5" " "      "6# # [#
$ $ $& & & & &r   r   c                 :    t          | t          j        z             S r   )r	   r   r   r   s    r   _log1prC   R   s    q15y>>r   c                   b    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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                 |    |dk    r't           j        | j        d         t           j        z   z  S t          | |          r   r   r   )r   r   r   r   r   s     r   r!   zlog1p.fdiffw   s7     q==5$)A,.//$T8444r   c                     t          | j         S r   )rC   r   r#   s     r   r%   zlog1p._eval_expand_func   r&   r   c                      t          |          S r   )rC   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 d S r   )is_Rationalr	   r   r   is_Floatr-   	is_numberr   r.   r)   s     r   r-   z
log1p.eval   so    ? 	.sQU{### 	.8C!%K(((] 	.x}}qu,---	. 	.r   c                 @    | j         d         t          j        z   j        S r1   )r   r   r   is_nonnegativer3   s    r   r4   zlog1p._eval_is_real   s    	!qu$44r   c                 h    | j         d         t          j        z   j        rdS | j         d         j        S )Nr   F)r   r   r   is_zeror7   r3   s    r   r8   zlog1p._eval_is_finite   s.    IaL15 ) 	5y|%%r   c                 &    | j         d         j        S r1   )r   is_positiver3   s    r   _eval_is_positivezlog1p._eval_is_positive   s    y|''r   c                 &    | j         d         j        S r1   )r   rT   r3   s    r   _eval_is_zerozlog1p._eval_is_zero   r5   r   c                 &    | j         d         j        S r1   )r   rR   r3   s    r   _eval_is_nonnegativezlog1p._eval_is_nonnegative   s    y|**r   Nr9   )r:   r;   r<   r=   r>   r!   r%   rJ   r?   r@   r-   r4   r8   rW   rY   r[   rA   r   r   rE   rE   V   s         : E5 5 5 5" " "   "6. . [.5 5 5& & &
( ( ($ $ $+ + + + +r   rE      c                 ,    t          t          |           S r   )r   _Twor   s    r   _exp2r_      s    tQ<<r   c                   D    e Zd ZdZdZddZd ZeZd Ze	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                 \    |dk    r| t          t                    z  S t          | |          r   )r	   r^   r   r   s     r   r!   z
exp2.fdiff   s-     q==D		>!$T8444r   c                      t          |          S r   )r_   r(   s      r   _eval_rewrite_as_Powzexp2._eval_rewrite_as_Pow       Szzr   c                     t          | j         S r   )r_   r   r#   s     r   r%   zexp2._eval_expand_func       di  r   c                 2    |j         rt          |          S d S r   )rO   r_   rP   s     r   r-   z	exp2.eval   s"    = 	::	 	r   Nr9   )r:   r;   r<   r=   r>   r!   rd   r?   r%   r@   r-   rA   r   r   ra   ra      sz         2 E5 5 5 5   "6! ! !   [  r   ra   c                 J    t          |           t          t                    z  S r   )r	   r^   r   s    r   _log2rj          q66#d))r   c                   J    e Zd ZdZdZd	dZed             Zd Zd Z	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                     |dk    r/t           j        t          t                    | j        d         z  z  S t          | |          rG   )r   r   r	   r^   r   r   r   s     r   r!   z
log2.fdiff   ;     q==5#d))DIaL011$T8444r   c                     |j         r&t          j        |t                    }|j        r|S d S |j        r|j        t          k    r	|j        S d S d S N)base)rO   r	   r-   r^   is_Atomis_Powrr   r   r.   r)   results      r   r-   z	log2.eval  f    = 	Xc---F~  Z 	CH,,7N	 	,,r   c                 L     |                      t                    j        |i |S r   )rewriter	   evalf)r   r   r*   s      r   _eval_evalfzlog2._eval_evalf  s&    &t||C  &7777r   c                     t          | j         S r   )rj   r   r#   s     r   r%   zlog2._eval_expand_func  rg   r   c                      t          |          S r   )rj   r(   s      r   rJ   zlog2._eval_rewrite_as_log  re   r   Nr9   )r:   r;   r<   r=   r>   r!   r@   r-   r{   r%   rJ   r?   rA   r   r   rm   rm      s         4 E5 5 5 5   [8 8 8! ! !   "6r   rm   c                     | |z  |z   S r   rA   )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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                 n    |dv r| j         d|z
           S |dk    rt          j        S t          | |          )r   r   r\   r\   r   )r   r   r   r   r   s     r   r!   z	fma.fdiff6  s@     v9Q\**]]5L$T8444r   c                     t          | j         S r   )r   r   r#   s     r   r%   zfma._eval_expand_funcB  s    TYr   Nc                      t          |          S r   )r   )r   r)   limitvarr*   s       r   r?   zfma._eval_rewrite_as_tractableE  s    Cyyr   r9   r   )r:   r;   r<   r=   r>   r!   r%   r?   rA   r   r   r   r      s\         & E	5 	5 	5 	5          r   r   
   c                 J    t          |           t          t                    z  S r   )r	   _Tenr   s    r   _log10r   L  rk   r   c                   D    e Zd ZdZdZddZed             Zd Z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                     |dk    r/t           j        t          t                    | j        d         z  z  S t          | |          rG   )r   r   r	   r   r   r   r   s     r   r!   zlog10.fdiffe  ro   r   c                     |j         r&t          j        |t                    }|j        r|S d S |j        r|j        t          k    r	|j        S d S d S rq   )rO   r	   r-   r   rs   rt   rr   r   ru   s      r   r-   z
log10.evalo  rw   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   rJ   zlog10._eval_rewrite_as_log{  rK   r   Nr9   )r:   r;   r<   r=   r>   r!   r@   r-   r%   rJ   r?   rA   r   r   r   r   P  sv         $ E5 5 5 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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                     |dk    r1t          | j        d         t          dd                    t          z  S t	          | |          )r   r   r   r\   r   r   r   r^   r   r   s     r   r!   z
Sqrt.fdiff  s@     q==ty|Xb!__55d::$T8444r   c                     t          | j         S r   )r   r   r#   s     r   r%   zSqrt._eval_expand_func  rg   r   c                      t          |          S r   )r   r(   s      r   rd   zSqrt._eval_rewrite_as_Pow  re   r   Nr9   	r:   r;   r<   r=   r>   r!   r%   rd   r?   rA   r   r   r   r     s[         2 E5 5 5 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dS )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    r4t          | j        d         t          t           dz                      dz  S t	          | |          )r   r   r   r   r   r   s     r   r!   z
Cbrt.fdiff  sF     q==ty|XteAg%6%67799$T8444r   c                     t          | j         S r   )r   r   r#   s     r   r%   zCbrt._eval_expand_func  rg   r   c                      t          |          S r   )r   r(   s      r   rd   zCbrt._eval_rewrite_as_Pow  re   r   Nr9   r   rA   r   r   r   r     s[         2 E5 5 5 5! ! !   "6r   r   c                 ^    t          t          | d          t          |d          z             S )Nr\   )r
   r   )r   r   s     r   _hypotr     s%    Aq		C1II%&&&r   c                   .    e Zd ZdZdZddZd Z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)

    r\   r   c                     |dv r+d| j         |dz
           z  t           | j        | j          z  z  S t          | |          )r   r   r\   r   )r   r^   funcr   r   s     r   r!   zhypot.fdiff  sJ     vTYxz**DDI1F,FGG$T84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   rd   zhypot._eval_rewrite_as_Pow  rK   r   Nr9   r   rA   r   r   r   r     s[         . E5 5 5 5" " "   "6r   r   c                   (    e Zd ZdZed             ZdS )isnanr   c                 L    |t           j        u rt          S |j        rt          S d S r   )r   NaNr   rO   r   rP   s     r   r-   z
isnan.eval  s&    !%<<K] 	L4r   Nr:   r;   r<   r>   r@   r-   rA   r   r   r   r     2        E  [  r   r   c                   (    e Zd ZdZed             ZdS )isinfr   c                 >    |j         rt          S |j        rt          S d S r   )is_infiniter   r7   r   rP   s     r   r-   z
isinf.eval'  s%    ? 	K] 	L4r   Nr   rA   r   r   r   r   $  r   r   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
   sympy.logic.boolalgr   r   r   r   r   rC   rE   r^   r_   ra   rj   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r   <module>r      s5    = < < < < < < < ' ' ' ' ' '             " " " " " " ; ; ; ; ; ; ; ; 9 9 9 9 9 9 < < < < < < < < < <  :& :& :& :& :&H :& :& :&z  K+ K+ K+ K+ K+H K+ K+ K+Z 	qtt  1 1 1 1 18 1 1 1h  96 96 96 96 968 96 96 96x  & & & & &( & & &R 	quu  .6 .6 .6 .6 .6H .6 .6 .6b  +6 +6 +6 +6 +68 +6 +6 +6\" " ",6 ,6 ,6 ,6 ,68 ,6 ,6 ,6^' ' '*6 *6 *6 *6 *6H *6 *6 *6Z
 
 
 
 
O 
 
 

 
 
 
 
O 
 
 
 
 
r   