§
    OŠtjš   ã                   ó‚   — d dl 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  G d„ d	e¦  «        Zd
S )é    )ÚSÚooÚdiff)ÚDefinedFunctionÚArgumentIndexError)Ú	fuzzy_not)ÚEq)Úim)Ú	Piecewise)Ú	Heavisidec                   óV   — e Zd ZdZdZdd„Zed„ ¦   «         Zd„ Zd„ Z	d„ Z
dd„Ze	Ze	Zd	S )ÚSingularityFunctionaU	  
    Singularity functions are a class of discontinuous functions.

    Explanation
    ===========

    Singularity functions 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, 1)`` 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, 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, 1) + DiracDelta(x + 3) - DiracDelta(x, 1)
    >>> expr.rewrite(DiracDelta)
    (x - 4)**5*Heaviside(x - 4, 1) + DiracDelta(x + 3) - DiracDelta(x, 1)
    >>> expr.rewrite('HeavisideDiracDelta')
    (x - 4)**5*Heaviside(x - 4, 1) + DiracDelta(x + 3) - DiracDelta(x, 1)

    See Also
    ========

    DiracDelta, Heaviside

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Singularity_function

    Té   c                 ó0  — |dk    r�| j         \  }}}|t          j        t          j        t          d¦  «        t          d¦  «        fv r|                      |||dz
  ¦  «        S |j        r||                      |||dz
  ¦  «        z  S dS t          | |¦  «        ‚)aK  
        Returns the first derivative of a DiracDelta Function.

        Explanation
        ===========

        The difference between ``diff()`` and ``fdiff()`` is: ``diff()`` is the
        user-level function and ``fdiff()`` is an object method. ``fdiff()`` is
        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.

        r   éþÿÿÿéýÿÿÿN)Úargsr   ÚZeroÚNegativeOneÚfuncÚis_positiver   )ÚselfÚargindexÚxÚaÚns        úk/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/functions/special/singularity_functions.pyÚfdiffzSingularityFunction.fdiffX   s�   € ð  �qŠ=ˆ=Ø”i‰GˆAˆq�!Ø•Q”V�Qœ]­A¨b©E¬Eµ1°R±5´5Ð9Ð9Ð9Ø—y’y  A q¨¡sÑ+Ô+Ð+Ø”ð .Ø˜Ÿš 1 a¨¨1©Ñ-Ô-Ñ-Ð-ð.ð .õ % T¨8Ñ4Ô4Ð4ó    c                 óN  — |}|}|}||z
  }t          t          |¦  «        j        ¦  «        rt          d¦  «        ‚t          t          |¦  «        j        ¦  «        rt          d¦  «        ‚|t          j        u s|t          j        u rt          j        S |dz   j        rt          d¦  «        ‚|j        rt          j        S |j	        r"|j        rt          j        |z  S |j
        r||z  S |t          j        dddfv r(|j        s|j        rt          j        S |j        r	t          S dS dS )	aP  
        Returns a simplified form or a value of Singularity Function depending
        on the argument passed by the object.

        Explanation
        ===========

        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(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

        z8Singularity Functions are defined only for Real Numbers.z>Singularity Functions are not defined for imaginary exponents.é   zASingularity Functions are not defined for exponents less than -4.r   r   éüÿÿÿN)r   r
   Úis_zeroÚ
ValueErrorr   ÚNaNÚis_negativeÚis_extended_negativer   Úis_nonnegativeÚis_extended_nonnegativer   Úis_extended_positiver   )ÚclsÚvariableÚoffsetÚexponentr   r   r   Úshifts           r   ÚevalzSingularityFunction.evalq   sC  € ðV ˆØˆØˆØ�Q‘ˆå•R˜‘Y”YÔ&Ñ'Ô'ð 	YÝÐWÑXÔXÐXÝ•R˜‘U”U”]Ñ#Ô#ð 	_ÝÐ]Ñ^Ô^Ð^Ø•A”Eˆ>ˆ>˜Q¥!¤%˜Z˜ZÝ”5ˆLØ�‰EÔð 	bÝÐ`ÑaÔaÐaØÔ%ð 	Ý”6ˆMØÔð 	 ØŒ}ð !Ý”v˜q‘yÐ ØÔ,ð  Ø˜a‘x�Ø•”  B¨Ð+Ð+Ð+ØÔ ð  EÔ$>ð Ý”v�ØŒ}ð Ý�	ð	 ,Ð+ðð r   c                 ó*  — | j         \  }}}|t          j        t          d¦  «        t          d¦  «        t          d¦  «        fv r(t          t          t          ||z
  d¦  «        fd¦  «        S |j        rt          ||z
  |z  ||z
  dk    fd¦  «        S dS )zV
        Converts a Singularity Function expression into its Piecewise form.

        r   r   r"   r   )r   TN)r   r   r   r   r   r	   r(   ©r   r   Úkwargsr   r   r   s         r   Ú_eval_rewrite_as_Piecewisez.SingularityFunction._eval_rewrite_as_Piecewise¶   s—   € ð
 ”)‰ˆˆ1ˆaà•”¥ "¡¤¥q¨¡u¤u­a°©e¬eÐ4Ð4Ð4Ý�b¥" Q¨¡U¨A¡,¤,Ð/°Ñ;Ô;Ð;ØÔð 	BÝ˜q 1™u q™j¨!¨a©%°1ª*Ð5°yÑAÔAÐAð	Bð 	Br   c                 óR  — | j         \  }}}|dk    r8t          t          ||z
  ¦  «        |j                             ¦   «         d¦  «        S |dk    r8t          t          ||z
  ¦  «        |j                             ¦   «         d¦  «        S |dk    r8t          t          ||z
  ¦  «        |j                             ¦   «         d¦  «        S |dk    r8t          t          ||z
  ¦  «        |j                             ¦   «         d¦  «        S |j        r||z
  |z  t          ||z
  d¦  «        z  S d	S )
z_
        Rewrites a Singularity Function expression using Heavisides and DiracDeltas.

        r"   r!   r   é   r   é   éÿÿÿÿr   N)r   r   r   Úfree_symbolsÚpopr(   r2   s         r   Ú_eval_rewrite_as_Heavisidez.SingularityFunction._eval_rewrite_as_HeavisideÂ   s  € ð
 ”)‰ˆˆ1ˆaà�Š7ˆ7Ý�	 ! a¡%Ñ(Ô(¨!¬.×*<Ò*<Ñ*>Ô*>ÀÑBÔBÐBØ�Š7ˆ7Ý�	 ! a¡%Ñ(Ô(¨!¬.×*<Ò*<Ñ*>Ô*>ÀÑBÔBÐBØ�Š7ˆ7Ý�	 ! a¡%Ñ(Ô(¨!¬.×*<Ò*<Ñ*>Ô*>ÀÑBÔBÐBØ�Š7ˆ7Ý�	 ! a¡%Ñ(Ô(¨!¬.×*<Ò*<Ñ*>Ô*>ÀÑBÔBÐBØÔð 	2Ø˜‘E˜A‘:�i¨¨A©¨qÑ1Ô1Ñ1Ð1ð	2ð 	2r   c                 óö   — | j         \  }}}||z
                       |d¦  «        }|dk     rt          j        S |j        r%|j        r|dk    rt          j        nt          j        S |j        r||z  S t          j        S )Nr   r8   )r   Úsubsr   r   r#   ÚOner   )r   r   ÚlogxÚcdirÚzr   r   r/   s           r   Ú_eval_as_leading_termz)SingularityFunction._eval_as_leading_termÔ   sz   € Ø”)‰ˆˆ1ˆaØ�Q‘—’˜Q Ñ"Ô"ˆØˆqŠ5ˆ5Ý”6ˆMØŒYð 	˜5œ=ð 	Ø! RšZ˜Z•1”6�6­Q¬UÐ2ØÔð 	Ø˜!‘8ˆOÝŒvˆr   Nr   c                 ó*  — | j         \  }}}||z
                       |d¦  «        }|dk     rt          j        S |j        r%|j        r|dk    rt          j        nt          j        S |j        r||z
  |z                       ||||¬¦  «        S t          j        S )Nr   r8   )r?   r@   )r   r=   r   r   r#   r>   r   Ú_eval_nseries)r   r   r   r?   r@   rA   r   r/   s           r   rD   z!SingularityFunction._eval_nseriesß   s™   € Ø”)‰ˆˆ1ˆaØ�Q‘—’˜Q Ñ"Ô"ˆØˆqŠ5ˆ5Ý”6ˆMØŒYð 	J˜5œ=ð 	JØ! RšZ˜Z•1”6�6­Q¬UÐ2ØÔð 	JØ˜‘U˜Q‘J×-Ò-¨a°¸ÀDÐ-ÑIÔIÐIÝŒvˆr   )r   )Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_realr   Úclassmethodr0   r4   r;   rB   rD   Ú_eval_rewrite_as_DiracDeltaÚ$_eval_rewrite_as_HeavisideDiracDelta© r   r   r   r      s©   € € € € € ðEð EðN €Gð5ð 5ð 5ð 5ð2 ðBð Bñ „[ðBðH
Bð 
Bð 
Bð2ð 2ð 2ð$	ð 	ð 	ð	ð 	ð 	ð 	ð #=ÐØ+EÐ(Ð(Ð(r   r   N)Ú
sympy.corer   r   r   Úsympy.core.functionr   r   Úsympy.core.logicr   Úsympy.core.relationalr	   Ú$sympy.functions.elementary.complexesr
   Ú$sympy.functions.elementary.piecewiser   Ú'sympy.functions.special.delta_functionsr   r   rM   r   r   ú<module>rU      sÝ   ðØ "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ &Ð &Ð &Ð &Ð &Ð &Ø $Ð $Ð $Ð $Ð $Ð $Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø :Ð :Ð :Ð :Ð :Ð :Ø =Ð =Ð =Ð =Ð =Ð =ð]Fð ]Fð ]Fð ]Fð ]F˜/ñ ]Fô ]Fð ]Fð ]Fð ]Fr   