ó
¡¼™\c           @   s¥  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 d	 e f d
 „  ƒ  YZ d „  Z d e f d „  ƒ  YZ e	 d ƒ Z d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ e	 d ƒ Z d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d „  Z d  e f d! „  ƒ  YZ  d" „  Z! d# e f d$ „  ƒ  YZ" d% S(&   s#  
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.

iÿÿÿÿ(   t   ArgumentIndexErrort   Function(   t   Rational(   t   Pow(   t   S(   t   expt   log(   t   sqrtc         C   s   t  |  ƒ t j S(   N(   R   R   t   One(   t   x(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _expm1   s    t   expm1c           B   sY   e  Z d  Z d Z d d „ Z d „  Z d „  Z e Z e d „  ƒ Z	 d „  Z
 d „  Z RS(   s  
    Represents the exponential function minus one.

    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
    i   c         C   s,   | d k r t  |  j Œ  St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   N(   R   t   argsR    (   t   selft   argindex(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   fdiff1   s    c         K   s   t  |  j Œ  S(   N(   R
   R   (   R   t   hints(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_expand_func:   s    c         K   s   t  | ƒ t j S(   N(   R   R   R   (   R   t   argt   kwargs(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_rewrite_as_exp=   s    c         C   s*   t  j | ƒ } | d  k	 r& | t j Sd  S(   N(   R   t   evalt   NoneR   R   (   t   clsR   t   exp_arg(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   B   s    c         C   s   |  j  d j S(   Ni    (   R   t   is_real(   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_is_realH   s    c         C   s   |  j  d j S(   Ni    (   R   t	   is_finite(   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_is_finiteK   s    (   t   __name__t
   __module__t   __doc__t   nargsR   R   R   t   _eval_rewrite_as_tractablet   classmethodR   R   R   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR      s   				c         C   s   t  |  t j ƒ S(   N(   R   R   R   (   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _log1pO   s    t   log1pc           B   st   e  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 RS(   sS  
    Represents the natural logarithm of a number plus one.

    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.core.function 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
    i   c         C   s8   | d k r% t  j |  j d t  j St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i    N(   R   R   R   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   q   s    c         K   s   t  |  j Œ  S(   N(   R#   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   {   s    c         K   s
   t  | ƒ S(   N(   R#   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_rewrite_as_log~   s    c         C   s[   | j  r t | t j ƒ S| j s7 t j | t j ƒ S| j rW t t | ƒ t j ƒ Sd  S(   N(   t   is_RationalR   R   R   t   is_FloatR   t	   is_numberR   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   ƒ   s    			c         C   s   |  j  d t j j S(   Ni    (   R   R   R   t   is_nonnegative(   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   Œ   s    c         C   s)   |  j  d t j j r t S|  j  d j S(   Ni    (   R   R   R   t   is_zerot   FalseR   (   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR      s    c         C   s   |  j  d j S(   Ni    (   R   t   is_positive(   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_is_positive”   s    c         C   s   |  j  d j S(   Ni    (   R   R*   (   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_is_zero—   s    c         C   s   |  j  d j S(   Ni    (   R   R)   (   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_is_nonnegativeš   s    (   R   R   R   R    R   R   R%   R!   R"   R   R   R   R-   R.   R/   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR$   S   s   
							i   c         C   s   t  t |  ƒ S(   N(   R   t   _Two(   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _exp2Ÿ   s    t   exp2c           B   sG   e  Z d  Z d Z d d „ Z d „  Z e Z d „  Z e d „  ƒ Z	 RS(   s¦  
    Represents the exponential function with base two.

    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
    True
    >>> exp2(x).diff(x)
    log(2)*exp2(x)

    See Also
    ========

    log2
    i   c         C   s-   | d k r |  t  t ƒ St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   N(   R   R0   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   ¼   s    c         K   s
   t  | ƒ S(   N(   R1   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _eval_rewrite_as_PowÅ   s    c         K   s   t  |  j Œ  S(   N(   R1   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   Ê   s    c         C   s   | j  r t | ƒ Sd  S(   N(   R(   R1   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   Í   s    	(
   R   R   R   R    R   R3   R!   R   R"   R   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR2   ¢   s   			c         C   s   t  |  ƒ t  t ƒ S(   N(   R   R0   (   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _log2Ó   s    t   log2c           B   sG   e  Z d  Z d Z d d „ Z e d „  ƒ Z d „  Z d „  Z e Z	 RS(   sµ  
    Represents the logarithm function with base two.

    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
    True
    >>> log2(x).diff(x)
    1/(x*log(2))

    See Also
    ========

    exp2
    log10
    i   c         C   s;   | d k r( t  j t t ƒ |  j d St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i    N(   R   R   R   R0   R   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   ñ   s    c         C   sQ   | j  r. t j | d t ƒ} | j rM | Sn | j rM | j t k rM | j Sd  S(   Nt   base(   R(   R   R   R0   t   is_Atomt   is_PowR6   R   (   R   R   t   result(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   û   s    		c         K   s   t  |  j Œ  S(   N(   R4   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR     s    c         K   s
   t  | ƒ S(   N(   R4   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR%     s    (
   R   R   R   R    R   R"   R   R   R%   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR5   ×   s   
			c         C   s   |  | | S(   N(    (   R	   t   yt   z(    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _fma  s    t   fmac           B   s2   e  Z d  Z d Z d d „ Z d „  Z d „  Z RS(   so  
    Represents "fused multiply add".

    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

    i   i   c         C   sA   | d k r |  j  d | S| d k r. t j St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i   i   N(   i   i   (   R   R   R   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   $  s
    c         K   s   t  |  j Œ  S(   N(   R<   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   0  s    c         K   s
   t  | ƒ S(   N(   R<   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR!   3  s    (   R   R   R   R    R   R   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR=     s
   	i
   c         C   s   t  |  ƒ t  t ƒ S(   N(   R   t   _Ten(   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _log10:  s    t   log10c           B   sG   e  Z d  Z d Z d d „ Z e d „  ƒ Z d „  Z d „  Z e Z	 RS(   s"  
    Represents the logarithm function with base ten.

    Examples
    ========

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

    See Also
    ========

    log2
    i   c         C   s;   | d k r( t  j t t ƒ |  j d St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i    N(   R   R   R   R>   R   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   S  s    c         C   sQ   | j  r. t j | d t ƒ} | j rM | Sn | j rM | j t k rM | j Sd  S(   NR6   (   R(   R   R   R>   R7   R8   R6   R   (   R   R   R9   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   ]  s    		c         K   s   t  |  j Œ  S(   N(   R?   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   f  s    c         K   s
   t  | ƒ S(   N(   R?   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR%   i  s    (
   R   R   R   R    R   R"   R   R   R%   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR@   >  s   
			c         C   s   t  |  t j ƒ S(   N(   R   R   t   Half(   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _Sqrto  s    t   Sqrtc           B   s8   e  Z d  Z d Z d d „ Z d „  Z d „  Z e Z RS(   sÍ  
    Represents the square root function.

    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
    i   c         C   s;   | d k r( t  |  j d t j ƒ t St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i    N(   R   R   R   RA   R0   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   Œ  s    c         K   s   t  |  j Œ  S(   N(   RB   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   •  s    c         K   s
   t  | ƒ S(   N(   RB   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR3   ˜  s    (   R   R   R   R    R   R   R3   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyRC   s  s   			c         C   s   t  |  t d d ƒ ƒ S(   Ni   i   (   R   R   (   R	   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _Cbrtž  s    t   Cbrtc           B   s8   e  Z d  Z d Z d d „ Z d „  Z d „  Z e Z RS(   sÔ  
    Represents the cube root function.

    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
    i   c         C   sB   | d k r/ t  |  j d t t d ƒ ƒ d St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i    i   N(   R   R   R   R0   R    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   »  s    #c         K   s   t  |  j Œ  S(   N(   RD   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   Å  s    c         K   s
   t  | ƒ S(   N(   RD   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR3   È  s    (   R   R   R   R    R   R   R3   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyRE   ¢  s   
		c         C   s    t  t |  d ƒ t | d ƒ ƒ S(   Ni   (   R   R   (   R	   R:   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   _hypotÎ  s    t   hypotc           B   s8   e  Z d  Z d Z d d „ Z d „  Z d „  Z e Z RS(   sÑ  
    Represents the hypotenuse function.

    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
    True
    >>> hypot(x, y)
    hypot(x, y)
    >>> hypot(x, y).diff(x)
    x/hypot(x, y)

    i   i   c         C   sF   | d k r3 d |  j  | d t |  j |  j  Œ  St |  | ƒ ‚ d S(   s@   
        Returns the first derivative of this function.
        i   i   N(   i   i   (   R   R0   t   funcR    (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   é  s    'c         K   s   t  |  j Œ  S(   N(   RF   R   (   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR   ó  s    c         K   s
   t  | ƒ S(   N(   RF   (   R   R   R   (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyR3   ö  s    (   R   R   R   R    R   R   R3   R!   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyRG   Ò  s   
		N(#   R   t   sympy.core.functionR    R   t   sympy.core.numbersR   t   sympy.core.powerR   t   sympy.core.singletonR   t&   sympy.functions.elementary.exponentialR   R   t(   sympy.functions.elementary.miscellaneousR   R
   R   R#   R$   R0   R1   R2   R4   R5   R<   R=   R>   R?   R@   RB   RC   RD   RE   RF   RG   (    (    (    s7   lib/python2.7/site-packages/sympy/codegen/cfunctions.pyt   <module>   s4   	9	J	1	6	&	1	+	,	