ó
¡¼™\c           @  s¸   d  d l  m Z m Z d  d l m Z m Z m Z 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  d l m Z d  d l m Z d	 e	 f d
 „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functiont   division(   t   St   sympifyt   oot   diff(   t   Functiont   ArgumentIndexError(   t	   fuzzy_not(   t   Eq(   t   im(   t	   Piecewise(   t	   Heavisidet   SingularityFunctionc           B  sM   e  Z d  Z e Z d d „ Z e d „  ƒ Z d „  Z d „  Z	 e	 Z
 e	 Z RS(   s	  
    The Singularity functions are a class of discontinuous functions. They take a
    variable, an offset and an exponent as arguments. These functions are
    represented using Macaulay brackets as :

    SingularityFunction(x, a, n) := <x - a>^n

    The singularity function will automatically evaluate to
    ``Derivative(DiracDelta(x - a), x, -n - 1)`` if ``n < 0``
    and ``(x - a)**n*Heaviside(x - a)`` if ``n >= 0``.


    Examples
    ========

    >>> from sympy import SingularityFunction, diff, Piecewise, DiracDelta, Heaviside, Symbol
    >>> from sympy.abc import x, a, n
    >>> SingularityFunction(x, a, n)
    SingularityFunction(x, a, n)
    >>> y = Symbol('y', positive=True)
    >>> n = Symbol('n', nonnegative=True)
    >>> SingularityFunction(y, -10, n)
    (y + 10)**n
    >>> y = Symbol('y', negative=True)
    >>> SingularityFunction(y, 10, n)
    0
    >>> SingularityFunction(x, 4, -1).subs(x, 4)
    oo
    >>> SingularityFunction(x, 10, -2).subs(x, 10)
    oo
    >>> SingularityFunction(4, 1, 5)
    243
    >>> diff(SingularityFunction(x, 1, 5) + SingularityFunction(x, 1, 4), x)
    4*SingularityFunction(x, 1, 3) + 5*SingularityFunction(x, 1, 4)
    >>> diff(SingularityFunction(x, 4, 0), x, 2)
    SingularityFunction(x, 4, -2)
    >>> SingularityFunction(x, 4, 5).rewrite(Piecewise)
    Piecewise(((x - 4)**5, x - 4 > 0), (0, True))
    >>> expr = SingularityFunction(x, a, n)
    >>> y = Symbol('y', positive=True)
    >>> n = Symbol('n', nonnegative=True)
    >>> expr.subs({x: y, a: -10, n: n})
    (y + 10)**n

    The methods ``rewrite(DiracDelta)``, ``rewrite(Heaviside)`` and ``rewrite('HeavisideDiracDelta')``
    returns the same output. One can use any of these methods according to their choice.

    >>> expr = SingularityFunction(x, 4, 5) + SingularityFunction(x, -3, -1) - SingularityFunction(x, 0, -2)
    >>> expr.rewrite(Heaviside)
    (x - 4)**5*Heaviside(x - 4) + DiracDelta(x + 3) - DiracDelta(x, 1)
    >>> expr.rewrite(DiracDelta)
    (x - 4)**5*Heaviside(x - 4) + DiracDelta(x + 3) - DiracDelta(x, 1)
    >>> expr.rewrite('HeavisideDiracDelta')
    (x - 4)**5*Heaviside(x - 4) + DiracDelta(x + 3) - DiracDelta(x, 1)

    See Also
    ========

    DiracDelta, Heaviside

    Reference
    =========

    .. [1] https://en.wikipedia.org/wiki/Singularity_function
    i   c         C  s®   | d k r› t  |  j d ƒ } t  |  j d ƒ } t  |  j d ƒ } | d k s] | d k rt |  j | | | d ƒ S| j rª | |  j | | | d ƒ Sn t |  | ƒ ‚ 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.

        i   i    i   iÿÿÿÿN(   R   t   argst   funct   is_positiveR   (   t   selft   argindext   xt   at   n(    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyt   fdiffU   s    	c         C  s-  t  | ƒ } t  | ƒ } t  | ƒ } | | } t t | ƒ j ƒ rR t d ƒ ‚ n  t t | ƒ j ƒ rv t d ƒ ‚ n  | t j k s” | t j k r› t j S| d j r· t d ƒ ‚ n  | j rÇ t j S| j	 rå | j	 rå | | | S| d k sý | d k r)| j s| j
 rt j S| j r)t j Sn  d S(   sm  
        Returns a simplified form or a value of Singularity Function depending on the
        argument passed by the object.

        The ``eval()`` method is automatically called when the ``SingularityFunction`` 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 SingularityFunction, Symbol, nan
        >>> from sympy.abc import x, a, n
        >>> SingularityFunction(x, a, n)
        SingularityFunction(x, a, n)
        >>> SingularityFunction(5, 3, 2)
        4
        >>> SingularityFunction(x, a, nan)
        nan
        >>> SingularityFunction(x, 3, 0).subs(x, 3)
        1
        >>> SingularityFunction(x, a, n).eval(3, 5, 1)
        0
        >>> SingularityFunction(x, a, n).eval(4, 1, 5)
        243
        >>> x = Symbol('x', positive = True)
        >>> a = Symbol('a', negative = True)
        >>> n = Symbol('n', nonnegative = True)
        >>> SingularityFunction(x, a, n)
        (-a + x)**n
        >>> x = Symbol('x', negative = True)
        >>> a = Symbol('a', positive = True)
        >>> SingularityFunction(x, a, n)
        0

        s8   Singularity Functions are defined only for Real Numbers.s>   Singularity Functions are not defined for imaginary exponents.i   sA   Singularity Functions are not defined for exponents less than -2.iÿÿÿÿiþÿÿÿN(   R   R   R
   t   is_zerot
   ValueErrorR   t   NaNt   is_negativet   Zerot   is_nonnegativeR   t   Infinity(   t   clst   variablet   offsett   exponentR   R   R   t   shift(    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyt   evall   s*    (
		c         O  s£   |  j  d } |  j  d } t |  j  d ƒ } | d k sE | d k rk t t t | | d ƒ f d t f ƒ S| j rŸ t | | | | | d k f d t f ƒ Sd S(   sV   
        Converts a Singularity Function expression into its Piecewise form.

        i    i   i   iÿÿÿÿiþÿÿÿN(   R   R   R   R   R	   t   TrueR   (   R   R   t   kwargsR   R   R   (    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyt   _eval_rewrite_as_Piecewise«   s    &	c         O  s²   |  j  d } |  j  d } t |  j  d ƒ } | d k r\ t t | | ƒ | j j ƒ  d ƒ S| d k r‹ t t | | ƒ | j j ƒ  d ƒ S| j r® | | | t | | ƒ Sd S(   s_   
        Rewrites a Singularity Function expression using Heavisides and DiracDeltas.

        i    i   i   iþÿÿÿiÿÿÿÿN(   R   R   R   R   t   free_symbolst   popR   (   R   R   R%   R   R   R   (    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyt   _eval_rewrite_as_Heaviside¹   s    ##	(   t   __name__t
   __module__t   __doc__R$   t   is_realR   t   classmethodR#   R&   R)   t   _eval_rewrite_as_DiracDeltat$   _eval_rewrite_as_HeavisideDiracDelta(    (    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyR      s   A?		N(   t
   __future__R    R   t
   sympy.coreR   R   R   R   t   sympy.core.functionR   R   t   sympy.core.logicR   t   sympy.core.relationalR	   t$   sympy.functions.elementary.complexesR
   t$   sympy.functions.elementary.piecewiseR   t'   sympy.functions.special.delta_functionsR   R   (    (    (    sL   lib/python2.7/site-packages/sympy/functions/special/singularity_functions.pyt   <module>   s   "