§
    «³ÙgK.  ã                   óÔ  — 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#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)Úsqrtc                 ó:   — t          | ¦  «        t          j        z
  S ©N©r   r   ÚOne©Úxs    úN/granary/edev/quantum/lib/python3.11/site-packages/sympy/codegen/cfunctions.pyÚ_expm1r      s   € Ýˆq‰6Œ6•A”E‰>Ðó    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Š=ˆ=Ý˜œ	�?Ð"å$ T¨8Ñ4Ô4Ð4r   c                 ó   — t          | j        Ž S r   )r   r   ©r   Úhintss     r   Ú_eval_expand_funczexpm1._eval_expand_func=   ó   € Ý�t”yÐ!Ð!r   c                 ó:   — t          |¦  «        t          j        z
  S r   r   ©r   ÚargÚkwargss      r   Ú_eval_rewrite_as_expzexpm1._eval_rewrite_as_exp@   s   € Ý�3‰xŒx�!œ%ÑÐ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‘-”-ˆØÐØ�QœU‘?Ð"ð Ð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 r.   )r   Ú	is_finiter0   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*   r1   r5   © 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   Ú_log1pr@   R   s   € Ýˆq•1”5‰y‰>Œ>Ð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œ,­¬Ñ.Ñ/Ð/å$ T¨8Ñ4Ô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 d S r   )Úis_Rationalr	   r   r   Úis_Floatr*   Ú	is_numberr   ©r+   r&   s     r   r*   z
log1p.eval‰   so   € àŒ?ð 	.Ý�s�QœU‘{Ñ#Ô#Ð#Ø”ð 	.Ý”8˜C¥!¤%™KÑ(Ô(Ð(ØŒ]ð 	.Ý•x ‘}”}¥q¤uÑ,Ñ-Ô-Ð-ð	.ð 	.r   c                 ó@   — | j         d         t          j        z   j        S r.   )r   r   r   Úis_nonnegativer0   s    r   r1   zlog1p._eval_is_real’   s   € Ø”	˜!”�qœuÑ$Ô4Ð4r   c                 óh   — | j         d         t          j        z   j        rdS | j         d         j        S )Nr   F)r   r   r   Úis_zeror4   r0   s    r   r5   zlog1p._eval_is_finite•   s.   € ØŒI�aŒL�1œ5Ñ Ô)ð 	Ø�5ØŒy˜Œ|Ô%Ð%r   c                 ó&   — | j         d         j        S r.   )r   Úis_positiver0   s    r   Ú_eval_is_positivezlog1p._eval_is_positiveš   s   € ØŒy˜Œ|Ô'Ð'r   c                 ó&   — | j         d         j        S r.   )r   rQ   r0   s    r   Ú_eval_is_zerozlog1p._eval_is_zero�   r2   r   c                 ó&   — | j         d         j        S r.   )r   rO   r0   s    r   Ú_eval_is_nonnegativezlog1p._eval_is_nonnegative    s   € ØŒy˜Œ|Ô*Ð*r   Nr6   )r7   r8   r9   r:   r;   r   r"   rG   r<   r=   r*   r1   r5   rT   rV   rX   r>   r   r   rB   rB   V   sÃ   € € € € € ðð ð: €Eð5ð 5ð 5ð 5ð"ð "ð "ðð ð ð "6Ðàð.ð .ñ „[ð.ð5ð 5ð 5ð&ð &ð &ð
(ð (ð (ð$ð $ð $ð+ð +ð +ð +ð +r   rB   é   c                 ó,   — t          t          | ¦  «        S r   )r   Ú_Twor   s    r   Ú_exp2r\   ¥   s   € Ý�t�Q‰<Œ<Ð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™	œ	‘>Ð!å$ T¨8Ñ4Ô4Ð4r   c                 ó    — t          |¦  «        S r   )r\   r%   s      r   Ú_eval_rewrite_as_Powzexp2._eval_rewrite_as_PowÎ   ó   € Ý�S‰zŒzÐr   c                 ó   — t          | j        Ž S r   )r\   r   r    s     r   r"   zexp2._eval_expand_funcÓ   ó   € Ý�d”iÐ Ð r   c                 ó2   — |j         rt          |¦  «        S d S 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^   ¨   sz   € € € € € ðð ð2 €Eð5ð 5ð 5ð 5ðð ð ð "6Ðð!ð !ð !ð ðð ñ „[ðð ð r   r^   c                 óJ   — t          | ¦  «        t          t          ¦  «        z  S r   )r	   r[   r   s    r   Ú_log2rg   Ü   ó   € Ýˆq‰6Œ6•#•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          | |¦  «        ‚rD   )r   r   r	   r[   r   r   r   s     r   r   z
log2.fdiffý   ó;   € ð �qŠ=ˆ=Ý”5�#�d™)œ) D¤I¨a¤LÑ0Ñ1Ð1å$ T¨8Ñ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)rL   r	   r*   r[   Úis_AtomÚis_Powro   r   ©r+   r&   Úresults      r   r*   z	log2.eval  óf   € àŒ=ð 	Ý”X˜c­Ð-Ñ-Ô-ˆFØŒ~ð Ø�ðð àŒZð 	˜CœH­Ò,Ð,Ø”7ˆNð	ð 	Ð,Ð,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   )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ð 5ð 5ð 5ð ðð ñ „[ðð8ð 8ð 8ð!ð !ð !ðð ð ð "6ÐÐÐr   rj   c                 ó   — | |z  |z   S r   r>   )r   ÚyÚzs      r   Ú_fmar~     s   € ØˆQ‰3�‰7€Nr   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   rY   rY   r�   )r   r   r   r   r   s     r   r   z	fma.fdiff6  s@   € ð �vÐÐØ”9˜Q ™\Ô*Ð*Ø˜Š]ˆ]Ý”5ˆLå$ T¨8Ñ4Ô4Ð4r   c                 ó   — t          | j        Ž S r   )r~   r   r    s     r   r"   zfma._eval_expand_funcB  s   € Ý�T”YÐÐr   Nc                 ó    — t          |¦  «        S r   )r~   )r   r&   Úlimitvarr'   s       r   r<   zfma._eval_rewrite_as_tractableE  s   € Ý�C‰yŒyÐr   r6   r   )r7   r8   r9   r:   r;   r   r"   r<   r>   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  rh   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          | |¦  «        ‚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 d S |j        r|j        t          k    r	|j        S d S d S 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  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   éÿÿÿÿrY   ©r   r   r   r[   r   r   s     r   r   z
Sqrt.fdiff¡  s@   € ð �qŠ=ˆ=Ý�t”y ”|¥X¨b°!¡_¤_Ñ5Ô5µdÑ:Ð:å$ T¨8Ñ4Ô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ð 5ð 5ð 5ð!ð !ð !ðð ð ð "6ÐÐÐr   r•   c                 ó>   — t          | t          dd¦  «        ¦  «        S )Nr   r�   )r   r   r   s    r   Ú_Cbrtr�   ³  s   € Ýˆq•(˜1˜a‘.”.Ñ!Ô!Ð!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Š=ˆ=Ý�t”y ”|¥X­t¨e°A©gÑ%6Ô%6Ñ7Ô7¸Ñ9Ð9å$ T¨8Ñ4Ô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ð 5ð 5ð 5ð!ð !ð !ðð ð ð "6ÐÐÐr   rŸ   c                 ó^   — t          t          | d¦  «        t          |d¦  «        z   ¦  «        S )NrY   )r
   r   )r   r|   s     r   Ú_hypotr¤   æ  s%   € Ý•�A�q‘	”	�C  1™IœIÑ%Ñ&Ô&Ð&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)

    rY   r   c                 ó€   — |dv r+d| 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ÐÐØ�T”Y˜x¨™zÔ*Ñ*­D°°´¸D¼IÐ1FÑ,FÑGÐGå$ T¨8Ñ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   ra   zhypot._eval_rewrite_as_Pow  rH   r   Nr6   r›   r>   r   r   r¦   r¦   ê  s[   € € € € € ðð ð. €Eð5ð 5ð 5ð 5ð"ð "ð "ðð ð ð "6ÐÐÐr   r¦   c                   ó   — e Zd ZdZdS )Úisnanr   N)r7   r8   r9   r;   r>   r   r   r¬   r¬     s   € € € € € Ø€E€E€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Ð 9Ð 9Ð 9Ð 9Ð 9ðð ð ð:&ð :&ð :&ð :&ð :&ˆHñ :&ô :&ð :&ðzð ð ðK+ð K+ð K+ð K+ð K+ˆHñ K+ô K+ð K+ðZ 	€qˆ�t„t€ðð ð ð1ð 1ð 1ð 1ð 1ˆ8ñ 1ô 1ð 1ðhð ð ð96ð 96ð 96ð 96ð 96ˆ8ñ 96ô 96ð 96ðxð ð ð&ð &ð &ð &ð &ˆ(ñ &ô &ð &ðR 	€qˆ�u„u€ðð ð ð.6ð .6ð .6ð .6ð .6ˆHñ .6ô .6ð .6ðbð ð ð+6ð +6ð +6ð +6ð +6ˆ8ñ +6ô +6ð +6ð\"ð "ð "ð,6ð ,6ð ,6ð ,6ð ,6ˆ8ñ ,6ô ,6ð ,6ð^'ð 'ð 'ð*6ð *6ð *6ð *6ð *6ˆHñ *6ô *6ð *6ðZð ð ð ð ˆHñ ô ð ð ð r   