ó
¡¼™\c           @  sî   d  d l  m Z m Z d  d l m Z m Z m Z d  d l m Z d  d l	 m
 Z
 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 d  d
 l m Z d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functiont   division(   t   St   sympifyt   diff(   t
   deprecated(   t   Functiont   ArgumentIndexError(   t	   fuzzy_not(   t   Eq(   t   imt   sign(   t	   Piecewise(   t   PolynomialError(   t
   filldedentt
   DiracDeltac           B  sƒ   e  Z d  Z e Z d d „ Z e d d „ ƒ Z e d d d d d	 d
 ƒ d „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z RS(   sD  
    The DiracDelta function and its derivatives.

    DiracDelta is not an ordinary function. It can be rigorously defined either
    as a distribution or as a measure.

    DiracDelta only makes sense in definite integrals, and in particular, integrals
    of the form ``Integral(f(x)*DiracDelta(x - x0), (x, a, b))``, where it equals
    ``f(x0)`` if ``a <= x0 <= b`` and ``0`` otherwise. Formally, DiracDelta acts
    in some ways like a function that is ``0`` everywhere except at ``0``,
    but in many ways it also does not. It can often be useful to treat DiracDelta
    in formal ways, building up and manipulating expressions with delta functions
    (which may eventually be integrated), but care must be taken to not treat it
    as a real function.
    SymPy's ``oo`` is similar. It only truly makes sense formally in certain contexts
    (such as integration limits), but SymPy allows its use everywhere, and it tries to be
    consistent with operations on it (like ``1/oo``), but it is easy to get into trouble
    and get wrong results if ``oo`` is treated too much like a number.
    Similarly, if DiracDelta is treated too much like a function, it is easy to get wrong
    or nonsensical results.

    DiracDelta function has the following properties:

    1) ``diff(Heaviside(x), x) = DiracDelta(x)``
    2) ``integrate(DiracDelta(x - a)*f(x),(x, -oo, oo)) = f(a)`` and
       ``integrate(DiracDelta(x - a)*f(x),(x, a - e, a + e)) = f(a)``
    3) ``DiracDelta(x) = 0`` for all ``x != 0``
    4) ``DiracDelta(g(x)) = Sum_i(DiracDelta(x - x_i)/abs(g'(x_i)))``
       Where ``x_i``-s are the roots of ``g``
    5) ``DiracDelta(-x) = DiracDelta(x)``

    Derivatives of ``k``-th order of DiracDelta have the following property:

    6) ``DiracDelta(x, k) = 0``, for all ``x != 0``
    7) ``DiracDelta(-x, k) = -DiracDelta(x, k)`` for odd ``k``
    8) ``DiracDelta(-x, k) = DiracDelta(x, k)`` for even ``k``

    Examples
    ========

    >>> from sympy import DiracDelta, diff, pi, Piecewise
    >>> from sympy.abc import x, y

    >>> DiracDelta(x)
    DiracDelta(x)
    >>> DiracDelta(1)
    0
    >>> DiracDelta(-1)
    0
    >>> DiracDelta(pi)
    0
    >>> DiracDelta(x - 4).subs(x, 4)
    DiracDelta(0)
    >>> diff(DiracDelta(x))
    DiracDelta(x, 1)
    >>> diff(DiracDelta(x - 1),x,2)
    DiracDelta(x - 1, 2)
    >>> diff(DiracDelta(x**2 - 1),x,2)
    2*(2*x**2*DiracDelta(x**2 - 1, 2) + DiracDelta(x**2 - 1, 1))
    >>> DiracDelta(3*x).is_simple(x)
    True
    >>> DiracDelta(x**2).is_simple(x)
    False
    >>> DiracDelta((x**2 - 1)*y).expand(diracdelta=True, wrt=x)
    DiracDelta(x - 1)/(2*Abs(y)) + DiracDelta(x + 1)/(2*Abs(y))


    See Also
    ========

    Heaviside
    simplify, is_simple
    sympy.functions.special.tensor_functions.KroneckerDelta

    References
    ==========

    .. [1] http://mathworld.wolfram.com/DeltaFunction.html
    i   c         C  se   | d k rR d } t  |  j ƒ d k r7 |  j d } n  |  j |  j d | d ƒ St |  | ƒ ‚ d S(   s©  
        Returns the first derivative of a DiracDelta Function.

        The difference between ``diff()`` and ``fdiff()`` is:-
        ``diff()`` is the user-level function and ``fdiff()`` is an object method.
        ``fdiff()`` is just a convenience method available in the ``Function`` class.
        It returns the derivative of the function without considering the chain rule.
        ``diff(function, x)`` calls ``Function._eval_derivative`` which in turn calls
        ``fdiff()`` internally to compute the derivative of the function.

        Examples
        ========

        >>> from sympy import DiracDelta, diff
        >>> from sympy.abc import x

        >>> DiracDelta(x).fdiff()
        DiracDelta(x, 1)

        >>> DiracDelta(x, 1).fdiff()
        DiracDelta(x, 2)

        >>> DiracDelta(x**2 - 1).fdiff()
        DiracDelta(x**2 - 1, 1)

        >>> diff(DiracDelta(x, 1)).fdiff()
        DiracDelta(x, 3)

        i   i    N(   t   lent   argst   funcR   (   t   selft   argindext   k(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   fdifff   s    i    c         C  s*  t  | ƒ } | j s | j r5 t d | f ƒ ‚ n  t  | ƒ } | t j k rW t j S| j rg t j St t	 | ƒ j
 ƒ r­ t t d t t	 | ƒ ƒ t | ƒ f ƒ ƒ ‚ n  | j ƒ  \ } } | r&| d d k r&| d d k rô |  | | ƒ S| d d k r&| r|  | | ƒ S|  | ƒ Sn  d S(   se  
        Returns a simplified form or a value of DiracDelta depending on the
        argument passed by the DiracDelta object.

        The ``eval()`` method is automatically called when the ``DiracDelta`` class
        is about to be instantiated and it returns either some simplified instance
        or the unevaluated instance depending on the argument passed. In other words,
        ``eval()`` method is not needed to be called explicitly, it is being called
        and evaluated once the object is called.

        Examples
        ========

        >>> from sympy import DiracDelta, S, Subs
        >>> from sympy.abc import x

        >>> DiracDelta(x)
        DiracDelta(x)

        >>> DiracDelta(-x, 1)
        -DiracDelta(x, 1)

        >>> DiracDelta(1)
        0

        >>> DiracDelta(5, 1)
        0

        >>> DiracDelta(0)
        DiracDelta(0)

        >>> DiracDelta(-1)
        0

        >>> DiracDelta(S.NaN)
        nan

        >>> DiracDelta(x).eval(1)
        0

        >>> DiracDelta(x - 100).subs(x, 5)
        0

        >>> DiracDelta(x - 100).subs(x, 100)
        DiracDelta(0)

        sf   Error: the second argument of DiracDelta must be             a non-negative integer, %s given instead.sg   
                Function defined only for Real Values.
                Complex part: %s  found in %s .i    iÿÿÿÿi   i   N(   R   t
   is_Integert   is_negativet
   ValueErrorR   t   NaNt
   is_nonzerot   ZeroR   R
   t   is_zeroR   t   reprt   args_cnc(   t   clst   argR   t   ct   nc(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   eval   s&    1	(t
   useinsteads   expand(diracdelta=True, wrt=x)t   issuei;2  t   deprecated_since_versions   1.1c         C  s   |  j  d t d | ƒ S(   Nt
   diracdeltat   wrt(   t   expandt   True(   R   t   x(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   simplifyÕ   s    c         K  s}  d d l  m } | j d d ƒ } | d k rm |  j } t | ƒ d k rX | j ƒ  } qm t t d ƒ ƒ ‚ n  |  j	 d j
 | ƒ s¬ t |  j	 ƒ d k r° |  j	 d d k r° |  Syµ | |  j	 d | ƒ } d } t } t t |  j	 d | ƒ ƒ } xf | j ƒ  D]X \ }	 }
 |	 j t k	 rO|
 d k rO| |  j | |	 ƒ | j | |	 ƒ 7} qþ t } Pqþ W| rd| SWn t k
 rxn X|  S(   s=  Compute a simplified representation of the function using
           property number 4. Pass wrt as a hint to expand the expression
           with respect to a particular variable.

           wrt is:

           - a variable with respect to which a DiracDelta expression will
           get expanded.

           Examples
           ========

           >>> from sympy import DiracDelta
           >>> from sympy.abc import x, y

           >>> DiracDelta(x*y).expand(diracdelta=True, wrt=x)
           DiracDelta(x)/Abs(y)
           >>> DiracDelta(x*y).expand(diracdelta=True, wrt=y)
           DiracDelta(y)/Abs(x)

           >>> DiracDelta(x**2 + x - 2).expand(diracdelta=True, wrt=x)
           DiracDelta(x - 1)/3 + DiracDelta(x + 2)/3

           See Also
           ========

           is_simple, Diracdelta

        iÿÿÿÿ(   t   rootsR)   i   s»   
            When there is more than 1 free symbol or variable in the expression,
            the 'wrt' keyword is required as a hint to expand when using the
            DiracDelta hint.i    N(   t   sympy.polys.polyrootsR.   t   gett   Nonet   free_symbolsR   t   popt	   TypeErrorR   R   t   hasR+   t   absR   t   itemst   is_realt   FalseR   t   subsR   (   R   t   hintsR.   R)   t   freet   argrootst   resultt   validt   dargt   rt   m(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   _eval_expand_diracdeltaÙ   s2    	?*c         C  s0   |  j  d j | ƒ } | r, | j ƒ  d k St S(   s  is_simple(self, x)

           Tells whether the argument(args[0]) of DiracDelta is a linear
           expression in x.

           x can be:

           - a symbol

           Examples
           ========

           >>> from sympy import DiracDelta, cos
           >>> from sympy.abc import x, y

           >>> DiracDelta(x*y).is_simple(x)
           True
           >>> DiracDelta(x*y).is_simple(y)
           True

           >>> DiracDelta(x**2 + x - 2).is_simple(x)
           False

           >>> DiracDelta(cos(x)).is_simple(x)
           False

           See Also
           ========

           simplify, Diracdelta

        i    i   (   R   t   as_polyt   degreeR9   (   R   R,   t   p(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt	   is_simple  s    !c         O  sB   t  | ƒ d k r> t t d ƒ t | d d ƒ f d t f ƒ Sd S(   s‚  Represents DiracDelta in a Piecewise form

           Examples
           ========

           >>> from sympy import DiracDelta, Piecewise, Symbol, SingularityFunction
           >>> x = Symbol('x')

           >>> DiracDelta(x).rewrite(Piecewise)
           Piecewise((DiracDelta(0), Eq(x, 0)), (0, True))

           >>> DiracDelta(x - 5).rewrite(Piecewise)
           Piecewise((DiracDelta(0), Eq(x - 5, 0)), (0, True))

           >>> DiracDelta(x**2 - 5).rewrite(Piecewise)
           Piecewise((DiracDelta(0), Eq(x**2 - 5, 0)), (0, True))

           >>> DiracDelta(x - 5, 4).rewrite(Piecewise)
           DiracDelta(x - 5, 4)

        i   i    N(   R   R   R   R	   R+   (   R   R   t   kwargs(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   _eval_rewrite_as_Piecewise@  s    c         O  s  d d l  m } d d l m } |  t d ƒ k rB | d d d ƒ S|  t d d ƒ k rg | d d d ƒ S|  j } t | ƒ d k rë | j ƒ  } t | ƒ d k rÁ | | | | d | ƒ d d ƒ S| | | | d | ƒ d | d d ƒ St t	 d ƒ ƒ ‚ d S(	   sb   
        Returns the DiracDelta expression written in the form of Singularity Functions.

        iÿÿÿÿ(   t   solve(   t   SingularityFunctioni    i   iþÿÿÿsr   
                rewrite(SingularityFunction) doesn't support
                arguments with more that 1 variable.N(
   t   sympy.solversRJ   t   sympy.functionsRK   R   R2   R   R3   R4   R   (   R   R   RH   RJ   RK   R<   R,   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt$   _eval_rewrite_as_SingularityFunctionY  s    	!*c         C  s)   d d  l  j } | j |  j d j ƒ  ƒ S(   Niÿÿÿÿi    (   t   sage.allt   allt   dirac_deltaR   t   _sage_(   R   t   sage(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRR   q  s    (   t   __name__t
   __module__t   __doc__R+   R8   R   t   classmethodR$   R   R-   RC   RG   RI   RN   RR   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyR      s   O'G$	A	&		t	   Heavisidec           B  sh   e  Z d  Z e Z d d „ Z d	 d „ Z e d	 d „ ƒ Z	 d	 d „ Z
 d	 d „ Z d „  Z d „  Z RS(
   s  Heaviside Piecewise function

    Heaviside function has the following properties [1]_:

    1) ``diff(Heaviside(x),x) = DiracDelta(x)``
                        ``( 0, if x < 0``
    2) ``Heaviside(x) = < ( undefined if x==0 [1]``
                        ``( 1, if x > 0``
    3) ``Max(0,x).diff(x) = Heaviside(x)``

    .. [1] Regarding to the value at 0, Mathematica defines ``H(0) = 1``,
           but Maple uses ``H(0) = undefined``.  Different application areas
           may have specific conventions.  For example, in control theory, it
           is common practice to assume ``H(0) == 0`` to match the Laplace
           transform of a DiracDelta distribution.

    To specify the value of Heaviside at x=0, a second argument can be given.
    Omit this 2nd argument or pass ``None`` to recover the default behavior.

    >>> from sympy import Heaviside, S
    >>> from sympy.abc import x
    >>> Heaviside(9)
    1
    >>> Heaviside(-9)
    0
    >>> Heaviside(0)
    Heaviside(0)
    >>> Heaviside(0, S.Half)
    1/2
    >>> (Heaviside(x) + 1).replace(Heaviside(x), Heaviside(x, 1))
    Heaviside(x, 1) + 1

    See Also
    ========

    DiracDelta

    References
    ==========

    .. [2] http://mathworld.wolfram.com/HeavisideStepFunction.html
    .. [3] http://dlmf.nist.gov/1.16#iv

    i   c         C  s0   | d k r t  |  j d ƒ St |  | ƒ ‚ d S(   s}  
        Returns the first derivative of a Heaviside Function.

        Examples
        ========

        >>> from sympy import Heaviside, diff
        >>> from sympy.abc import x

        >>> Heaviside(x).fdiff()
        DiracDelta(x)

        >>> Heaviside(x**2 - 1).fdiff()
        DiracDelta(x**2 - 1)

        >>> diff(Heaviside(x)).fdiff()
        DiracDelta(x, 1)

        i   i    N(   R   R   R   (   R   R   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyR   «  s    c         K  sK   | d  k r( t |  |  ƒ j |  | |  St |  |  ƒ j |  | | |  Sd  S(   N(   R1   t   supert   __new__(   R    R!   t   H0t   options(    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRZ   Å  s    c         C  sŸ   t  | ƒ } t  | ƒ } | j r( t j S| j r8 t j S| j rE | S| t j k r[ t j St t	 | ƒ j ƒ r› t
 d t t	 | ƒ ƒ t | ƒ f ƒ ‚ n  d S(   s  
        Returns a simplified form or a value of Heaviside depending on the
        argument passed by the Heaviside object.

        The ``eval()`` method is automatically called when the ``Heaviside`` class
        is about to be instantiated and it returns either some simplified instance
        or the unevaluated instance depending on the argument passed. In other words,
        ``eval()`` method is not needed to be called explicitly, it is being called
        and evaluated once the object is called.

        Examples
        ========

        >>> from sympy import Heaviside, S
        >>> from sympy.abc import x

        >>> Heaviside(x)
        Heaviside(x)

        >>> Heaviside(19)
        1

        >>> Heaviside(0)
        Heaviside(0)

        >>> Heaviside(0, 1)
        1

        >>> Heaviside(-5)
        0

        >>> Heaviside(S.NaN)
        nan

        >>> Heaviside(x).eval(100)
        1

        >>> Heaviside(x - 100).subs(x, 5)
        0

        >>> Heaviside(x - 100).subs(x, 105)
        1

        sF   Function defined only for Real Values. Complex part: %s  found in %s .N(   R   R   R   R   t   is_positivet   OneR   R   R   R
   R   R   (   R    R!   R[   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyR$   Ë  s    .			c         K  sâ   | d k rI t d | d k  f t d ƒ t | d ƒ f d | d k f ƒ S| d k rz t d | d k f d | d k f ƒ S| d k r« t d | d k  f d | d k f ƒ St d | d k  f | t | d ƒ f d | d k f ƒ S(   sR  Represents Heaviside in a Piecewise form

           Examples
           ========

           >>> from sympy import Heaviside, Piecewise, Symbol, pprint
           >>> x = Symbol('x')

           >>> Heaviside(x).rewrite(Piecewise)
           Piecewise((0, x < 0), (Heaviside(0), Eq(x, 0)), (1, x > 0))

           >>> Heaviside(x - 5).rewrite(Piecewise)
           Piecewise((0, x - 5 < 0), (Heaviside(0), Eq(x - 5, 0)), (1, x - 5 > 0))

           >>> Heaviside(x**2 - 1).rewrite(Piecewise)
           Piecewise((0, x**2 - 1 < 0), (Heaviside(0), Eq(x**2 - 1, 0)), (1, x**2 - 1 > 0))

        i    i   N(   R1   R   RX   R	   (   R   R!   R[   RH   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRI     s    =%%c         K  s=   | j  r9 | d k s$ | t j k r9 t | ƒ d d Sn  d S(   s¹  Represents the Heaviside function in the form of sign function.
        The value of the second argument of Heaviside must specify Heaviside(0)
        = 1/2 for rewritting as sign to be strictly equivalent.  For easier
        usage, we also allow this rewriting when Heaviside(0) is undefined.

        Examples
        ========

        >>> from sympy import Heaviside, Symbol, sign
        >>> x = Symbol('x', real=True)

        >>> Heaviside(x).rewrite(sign)
        sign(x)/2 + 1/2

        >>> Heaviside(x, 0).rewrite(sign)
        Heaviside(x, 0)

        >>> Heaviside(x - 2).rewrite(sign)
        sign(x - 2)/2 + 1/2

        >>> Heaviside(x**2 - 2*x + 1).rewrite(sign)
        sign(x**2 - 2*x + 1)/2 + 1/2

        >>> y = Symbol('y')

        >>> Heaviside(y).rewrite(sign)
        Heaviside(y)

        >>> Heaviside(y**2 - 2*y + 1).rewrite(sign)
        Heaviside(y**2 - 2*y + 1)

        See Also
        ========

        sign

        i   i   N(   R8   R1   R   t   HalfR   (   R   R!   R[   RH   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   _eval_rewrite_as_sign!  s    &	c         K  sœ   d d l  m } d d l m } |  t d ƒ k rB | d d d ƒ S|  j } t | ƒ d k r† | j ƒ  } | | | | | ƒ d d ƒ St t	 d ƒ ƒ ‚ d S(   sa   
        Returns the Heaviside expression written in the form of Singularity Functions.

        iÿÿÿÿ(   RJ   (   RK   i    i   sr   
                rewrite(SingularityFunction) doesn't
                support arguments with more that 1 variable.N(
   RL   RJ   RM   RK   RX   R2   R   R3   R4   R   (   R   R   RH   RJ   RK   R<   R,   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRN   K  s    	c         C  s)   d d  l  j } | j |  j d j ƒ  ƒ S(   Niÿÿÿÿi    (   RO   RP   t	   heavisideR   RR   (   R   RS   (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRR   b  s    N(   RT   RU   RV   R+   R8   R   R1   RZ   RW   R$   RI   R`   RN   RR   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyRX   {  s   ,:*	N(   t
   __future__R    R   t
   sympy.coreR   R   R   t   sympy.core.decoratorsR   t   sympy.core.functionR   R   t   sympy.core.logicR   t   sympy.core.relationalR	   t$   sympy.functions.elementary.complexesR
   R   t$   sympy.functions.elementary.piecewiseR   t   sympy.polys.polyerrorsR   t   sympy.utilitiesR   R   RX   (    (    (    sF   lib/python2.7/site-packages/sympy/functions/special/delta_functions.pyt   <module>   s   ÿ i