o
    ¦ƒðj+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   úš/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/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   ©ÚselfÚ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%   Úexp_argr   r   r   r(   E   s   

ÿz
expm1.evalc                 C   ó   | j d jS ©Nr   )r   Ú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   r0   zexpm1._eval_is_finiteN©r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Únargsr   r"   r'   Ú_eval_rewrite_as_tractableÚclassmethodr(   r/   r2   r   r   r   r   r      s    
	
r   c                 C   s   t | tj ƒS r   )r   r   r   r   r   r   r   Ú_log1pR   r   r;   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   )r;   r   r    r   r   r   r"   �   r#   zlog1p._eval_expand_funcc                 K   ó   t |ƒS r   )r;   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   )Úis_Rationalr   r   r   Ú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_zeror1   r.   r   r   r   r2   •   s   zlog1p._eval_is_finitec                 C   r+   r,   )r   Úis_positiver.   r   r   r   Ú_eval_is_positiveš   r0   zlog1p._eval_is_positivec                 C   r+   r,   )r   rF   r.   r   r   r   Ú_eval_is_zero�   r0   zlog1p._eval_is_zeroc                 C   r+   r,   )r   rE   r.   r   r   r   Ú_eval_is_nonnegative    r0   zlog1p._eval_is_nonnegativeNr3   )r4   r5   r6   r7   r8   r   r"   r?   r9   r:   r(   r/   r2   rH   rI   rJ   r   r   r   r   r<   V   s    


r<   é   c                 C   s
   t t| ƒS r   )r   Ú_Twor   r   r   r   Ú_exp2¥   r#   rM   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   rL   r   r   r   r   r   r   Å   s   
z
exp2.fdiffc                 K   r>   r   )rM   r$   r   r   r   Ú_eval_rewrite_as_PowÎ   r@   zexp2._eval_rewrite_as_Powc                 K   r   r   )rM   r   r    r   r   r   r"   Ó   r#   zexp2._eval_expand_funcc                 C   s   |j rt|ƒS d S r   )rC   rM   rD   r   r   r   r(   Ö   s   ÿz	exp2.evalNr3   )r4   r5   r6   r7   r8   r   rO   r9   r"   r:   r(   r   r   r   r   rN   ¨   s    
	rN   c                 C   ó   t | ƒt tƒ S r   )r   rL   r   r   r   r   Ú_log2Ü   ó   rQ   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   rL   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)rC   r   r(   rL   Úis_AtomÚis_PowrX   r   ©r)   r%   Úresultr   r   r   r(     ó   ÿÿz	log2.evalc                 O   s   |   t¡j|i |¤ŽS r   )Úrewriter   Úevalf)r   r   r&   r   r   r   Ú_eval_evalf  s   zlog2._eval_evalfc                 K   r   r   )rQ   r   r    r   r   r   r"     r#   zlog2._eval_expand_funcc                 K   r>   r   )rQ   r$   r   r   r   r?     r@   zlog2._eval_rewrite_as_logNr3   )r4   r5   r6   r7   r8   r   r:   r(   r`   r"   r?   r9   r   r   r   r   rS   à   s    


rS   c                 C   s   | | | S r   r   )r   ÚyÚzr   r   r   Ú_fma  r0   rc   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   rK   rK   re   )r   r   r   r   r   r   r   r   r   6  s
   
z	fma.fdiffc                 K   r   r   )rc   r   r    r   r   r   r"   B  r#   zfma._eval_expand_funcNc                 K   r>   r   )rc   )r   r%   Úlimitvarr&   r   r   r   r9   E  r@   zfma._eval_rewrite_as_tractabler3   r   )r4   r5   r6   r7   r8   r   r"   r9   r   r   r   r   rd      s    
rd   é
   c                 C   rP   r   )r   Ú_Tenr   r   r   r   Ú_log10L  rR   rj   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   rT   r=   )r   r   r   ri   r   r   r   r   r   r   r   e  rU   zlog10.fdiffc                 C   rV   rW   )rC   r   r(   ri   rY   rZ   rX   r   r[   r   r   r   r(   o  r]   z
log10.evalc                 K   r   r   )rj   r   r    r   r   r   r"   x  r#   zlog10._eval_expand_funcc                 K   r>   r   )rj   r$   r   r   r   r?   {  r@   zlog10._eval_rewrite_as_logNr3   )r4   r5   r6   r7   r8   r   r:   r(   r"   r?   r9   r   r   r   r   rk   P  s    


rk   c                 C   s   t | tjƒS r   )r   r   ÚHalfr   r   r   r   Ú_Sqrt�  r0   rm   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   éÿÿÿÿrK   ©r   r   r   rL   r   r   r   r   r   r   ¡  s   
z
Sqrt.fdiffc                 K   r   r   )rm   r   r    r   r   r   r"   ª  r#   zSqrt._eval_expand_funcc                 K   r>   r   )rm   r$   r   r   r   rO   ­  r@   zSqrt._eval_rewrite_as_PowNr3   ©	r4   r5   r6   r7   r8   r   r"   rO   r9   r   r   r   r   ro   …  s    
	ro   c                 C   s   t | tddƒƒS )Nr   re   )r   r   r   r   r   r   Ú_Cbrt³  rR   rs   c                   @   rn   )Ú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   re   rq   r   r   r   r   r   Ó  s   
z
Cbrt.fdiffc                 K   r   r   )rs   r   r    r   r   r   r"   Ý  r#   zCbrt._eval_expand_funcc                 K   r>   r   )rs   r$   r   r   r   rO   à  r@   zCbrt._eval_rewrite_as_PowNr3   rr   r   r   r   r   rt   ·  s    

rt   c                 C   s   t t| dƒt|dƒ ƒS )NrK   )r	   r   )r   ra   r   r   r   Ú_hypotæ  s   ru   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)

    rK   r   c                 C   s4   |dv rd| j |d   t| j| j Ž   S t| |ƒ‚)r   rf   rK   r   )r   rL   Úfuncr   r   r   r   r   r     s   "
zhypot.fdiffc                 K   r   r   )ru   r   r    r   r   r   r"     r#   zhypot._eval_expand_funcc                 K   r>   r   )ru   r$   r   r   r   rO     r@   zhypot._eval_rewrite_as_PowNr3   rr   r   r   r   r   rv   ê  s    

rv   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   rC   r   rD   r   r   r   r(     s
   
z
isnan.evalN©r4   r5   r6   r8   r:   r(   r   r   r   r   ry     ó    ry   c                   @   rx   )Úisinfr   c                 C   s   |j rtS |jr
tS d S r   )Úis_infiniter   r1   r   rD   r   r   r   r(   '  s
   z
isinf.evalNr{   r   r   r   r   r}   $  r|   r}   N))r7   Ú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   r;   r<   rL   rM   rN   rQ   rS   rc   rd   ri   rj   rk   rm   ro   rs   rt   ru   rv   ry   r}   r   r   r   r   Ú<module>   s<    =M4<)1./-