
    \hM                         S SK JrJr  S SKJrJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  S SKJr  S SKJr  S SKJr  S S	KJr   " S
 S\5      r " S S\5      rg)    )Sdiff)DefinedFunctionArgumentIndexError)	fuzzy_not)EqNe)imsign)	Piecewise)PolynomialError)roots)
filldedentc                   h    \ rS rSrSrSrSS jr\\R                  4S j5       r
S rS rS rS	 rS
rg)
DiracDelta   a2
  
The DiracDelta function and its derivatives.

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

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) $\frac{d}{d x} \theta(x) = \delta(x)$
2) $\int_{-\infty}^\infty \delta(x - a)f(x)\, dx = f(a)$ and $\int_{a-
   \epsilon}^{a+\epsilon} \delta(x - a)f(x)\, dx = f(a)$
3) $\delta(x) = 0$ for all $x \neq 0$
4) $\delta(g(x)) = \sum_i \frac{\delta(x - x_i)}{\|g'(x_i)\|}$ where $x_i$
   are the roots of $g$
5) $\delta(-x) = \delta(x)$

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

6) $\delta(x, k) = 0$ for all $x \neq 0$
7) $\delta(-x, k) = -\delta(x, k)$ for odd $k$
8) $\delta(-x, k) = \delta(x, k)$ for even $k$

Examples
========

>>> from sympy import DiracDelta, diff, pi
>>> 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
sympy.simplify.simplify.simplify, is_simple
sympy.functions.special.tensor_functions.KroneckerDelta

References
==========

.. [1] https://mathworld.wolfram.com/DeltaFunction.html

Tc                     US:X  aL  Sn[        U R                  5      S:  a  U R                  S   nU R                  U R                  S   US-   5      $ [        X5      e)a`  
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.

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)

Parameters
==========

argindex : integer
    degree of derivative

   r   )lenargsfuncr   )selfargindexks      _/var/www/auris/envauris/lib/python3.13/site-packages/sympy/functions/special/delta_functions.pyfdiffDiracDelta.fdiffg   sV    N q=A499~!IIaL99TYYq\1q511$T44    c           
         UR                   (       a  UR                  (       a  [        SU< S35      eU[        R                  L a  [        R                  $ UR
                  (       a  [        R                  $ [        [        U5      R                  5      (       a8  [        [        S[        [        U5      5      < S[        U5      < S35      5      eUR                  5       u  p4U(       a^  US   [        R                  L aH  UR                  (       a  U " U* U5      * $ UR                  (       a  U(       a
  U " U* U5      $ U " U* 5      $ g	UR                  (       a  U " USS9$ g	)
a  
Returns a simplified form or a value of DiracDelta depending on the
argument passed by the DiracDelta object.

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

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
>>> 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 - 100).subs(x, 5)
0

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

Parameters
==========

k : integer
    order of derivative

arg : argument passed to DiracDelta

zUError: the second argument of DiracDelta must be             a non-negative integer, z given instead.zV
                Function defined only for Real Values.
                Complex part:   found in  .r   F)evaluateN)
is_Integeris_negative
ValueErrorr   NaN
is_nonzeroZeror   r
   is_zeror   reprargs_cncNegativeOneis_oddis_even)clsargr   cncs        r   evalDiracDelta.eval   s   r ||q}}:;> ? ?!%%<55L>>66MRW__%%Z RWtCy)* + , , 1& xxSD!}$'(sC4|7c3$i7 YYsU++ r   c                    UR                  SS5      nUc@  U R                  n[        U5      S:X  a  UR                  5       nO[	        [        S5      5      eU R                  S   R                  U5      (       a,  [        U R                  5      S:  a  U R                  S   S:w  a  U $  [        U R                  S   U5      nSnSn[        [        U R                  S   U5      5      nUR                  5        HE  u  pUR                  SLa/  U	S:X  a)  XPR                  X(-
  5      UR                  X(5      -  -  nMC  Sn  O   U(       a  U$  U $ ! [         a     U $ f = f)a  
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.

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

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

wrtNr   z
            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.r   TF)getfree_symbolsr   pop	TypeErrorr   r   hasr   absr   itemsis_realr   subsr   )
r   hintsr6   freeargrootsresultvaliddargrms
             r   _eval_expand_diracdelta"DiracDelta._eval_expand_diracdelta   sN   D iit$;$$D4yA~hhj
 ,  !! " "
 yy|$$TYY!);		!PQ@QK	TYYq\3/HFEtDIIaL#./D (99E)a1fii031BBBF
 "E )     		s   (B E 
EEc                 t    U R                   S   R                  U5      nU(       a  UR                  5       S:H  $ g)a  
Tells whether the argument(args[0]) of DiracDelta is a linear
expression in *x*.

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

Parameters
==========

x : can be a symbol

See Also
========

sympy.simplify.simplify.simplify, DiracDelta

r   r   F)r   as_polydegree)r   xps      r   	is_simpleDiracDelta.is_simple*  s3    B IIaL  #88:?"r   c                 j    [        U5      S:X  a$  [        [        S5      [        US   S5      4S5      $ g)a  
Represents DiracDelta in a piecewise form.

Examples
========

>>> from sympy import DiracDelta, Piecewise, Symbol
>>> 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, True))

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

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

r   r   )r   TN)r   r   r   r   )r   r   kwargss      r   _eval_rewrite_as_Piecewise%DiracDelta._eval_rewrite_as_PiecewiseP  s4    . t9>jmRQ^<iHH r   c                    SSK Jn  SSKJn  U [	        S5      :X  a
  U" SSS5      $ U [	        SS5      :X  a
  U" SSS5      $ U R
                  n[        U5      S:X  aR  UR                  5       n[        U5      S:X  a  U" Xc" US   U5      S   S5      $ U" Xc" US   U5      S   US   * S-
  5      $ [        [        S5      5      e)zR
Returns the DiracDelta expression written in the form of Singularity
Functions.

r   solveSingularityFunctionr   zu
                rewrite(SingularityFunction) does not support
                arguments with more that one variable.)
sympy.solversrW   -sympy.functions.special.singularity_functionsrY   r   r8   r   r9   r:   r   )r   r   rR   rW   rY   rA   rM   s          r   $_eval_rewrite_as_SingularityFunction/DiracDelta._eval_rewrite_as_SingularityFunctionj  s     	(U:a= &q!R00:a##&q!R00  t9>A4yA~*1eDGQ.?.BBGG&q%Q*;A*>a1MM J (: ; < <r    Nr   )__name__
__module____qualname____firstlineno____doc__r>   r   classmethodr   r(   r3   rH   rO   rS   r^   __static_attributes__r`   r   r   r   r      sL    Qf G.5`  M, M,^AF$LI4<r   r   c                      ^  \ rS rSrSrSrSS jr\R                  4U 4S jjr	\
S 5       r\\R                  4S j5       rSS jr\R                  4S	 jr\R                  4S
 jrSrU =r$ )	Heavisidei  a  
Heaviside step function.

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

The Heaviside step function has the following properties:

1) $\frac{d}{d x} \theta(x) = \delta(x)$
2) $\theta(x) = \begin{cases} 0 & \text{for}\: x < 0 \\ \frac{1}{2} &
   \text{for}\: x = 0 \\1 & \text{for}\: x > 0 \end{cases}$
3) $\frac{d}{d x} \max(x, 0) = \theta(x)$

Heaviside(x) is printed as $\theta(x)$ with the SymPy LaTeX printer.

The value at 0 is set differently in different fields. SymPy uses 1/2,
which is a convention from electronics and signal processing, and is
consistent with solving improper integrals by Fourier transform and
convolution.

To specify a different value of Heaviside at ``x=0``, a second argument
can be given. Using ``Heaviside(x, nan)`` gives an expression that will
evaluate to nan for x=0.

.. versionchanged:: 1.9 ``Heaviside(0)`` now returns 1/2 (before: undefined)

Examples
========

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

See Also
========

DiracDelta

References
==========

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

Tc                 T    US:X  a  [        U R                  S   5      $ [        X5      e)a`  
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)

Parameters
==========

argindex : integer
    order of derivative

r   r   )r   r   r   )r   r   s     r   r   Heaviside.fdiff  s)    4 q=diil++$T44r   c                    > [        U[        5      (       a)  [        UR                  5      S:X  a  [        R
                  n[        X ]  " XU40 UD6$ )Nr   )
isinstancerj   r   r   r   Halfsuper__new__)r/   r0   H0options	__class__s       r   rq   Heaviside.__new__  s?    b)$$RWW):BS&s?w??r   c                 T    U R                   nUS   [        R                  L a  USS nU$ )zArgs without default S.Halfr   N)r   r   ro   )r   r   s     r   pargsHeaviside.pargs  s-     yy7aff8Dr   c                    UR                   (       a  [        R                  $ UR                  (       a  [        R                  $ UR
                  (       a  U$ U[        R                  L a  [        R                  $ [        [        U5      R
                  5      (       a/  [        S[        [        U5      5      < S[        U5      < S35      eg)an  
Returns a simplified form or a value of Heaviside depending on the
argument passed by the Heaviside object.

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

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)
1/2

>>> Heaviside(0, 1)
1

>>> Heaviside(-5)
0

>>> Heaviside(S.NaN)
nan

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

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

Parameters
==========

arg : argument passed by Heaviside object

H0 : value of Heaviside(0)

z5Function defined only for Real Values. Complex part: r    r!   N)is_extended_negativer   r(   is_extended_positiveOner)   r&   r   r
   r%   r*   )r/   r0   rr   s      r   r3   Heaviside.eval  s    j ##66M%%55L[[IAEE\55Lr#w''imnpqtnuivx|  ~A  yB  C  E  E (r   c                     US:X  a  [        SUS:*  4S5      $ US:X  a  [        SUS:  4S5      $ [        SUS:  4U[        US5      4S5      $ )a  
Represents Heaviside in a Piecewise form.

Examples
========

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

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

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

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

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

r   )r   Tr   )r   r   )r   r0   rr   rR   s       r   rS   $Heaviside._eval_rewrite_as_Piecewise/  s^    . 7a]I667aq\955!S1WBsAJ'7CCr   c           
      
   UR                   (       ar  [        [        U5      S-   S-  [        US5      4[	        SUS9S45      n[        [        U5      S-   S-  [        [	        SUS9[        R                  5      4US45      nU$ g)ai  
Represents the Heaviside function in the form of sign function.

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

The value of Heaviside(0) must be 1/2 for rewriting 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, nan
>>> x = Symbol('x', real=True)
>>> y = Symbol('y')

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

>>> Heaviside(x, 0).rewrite(sign)
Piecewise((sign(x)/2 + 1/2, Ne(x, 0)), (0, True))

>>> Heaviside(x, nan).rewrite(sign)
Piecewise((sign(x)/2 + 1/2, Ne(x, 0)), (nan, True))

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

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

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

See Also
========

sign

r      r   )rr   TN)is_extended_realr   r   r	   rj   r   r   ro   )r   r0   rr   rR   pw1pw2s         r   _eval_rewrite_as_signHeaviside._eval_rewrite_as_signL  s    Z s)a-"BsAJ/1$d+-C s)a-"Byr':AFF$CDdC J  r   c                     SSK Jn  SSKJn  U [	        S5      :X  a
  U" SSS5      $ U R
                  n[        U5      S:X  a"  UR                  5       nU" Xt" X5      S   S5      $ [        [        S5      5      e)zQ
Returns the Heaviside expression written in the form of Singularity
Functions.

r   rV   rX   r   zu
                rewrite(SingularityFunction) does not
                support arguments with more that one variable.)
r\   rW   r]   rY   rj   r8   r   r9   r:   r   )r   r   rr   rR   rW   rY   rA   rM   s           r   r^   .Heaviside._eval_rewrite_as_SingularityFunction  s}     	(U9Q<&q!Q//  t9>A&q%.*;Q?? J (B C D Dr   r`   ra   )N)rb   rc   rd   re   rf   r>   r   r   ro   rq   propertyrw   rg   r3   rS   r   r^   rh   __classcell__)rt   s   @r   rj   rj     s    5n G5> VV @
   && =E =E~D: -.FF 4l =>FF D Dr   rj   N)
sympy.corer   r   sympy.core.functionr   r   sympy.core.logicr   sympy.core.relationalr   r	   $sympy.functions.elementary.complexesr
   r   $sympy.functions.elementary.piecewiser   sympy.polys.polyerrorsr   sympy.polys.polyrootsr   sympy.utilities.miscr   r   rj   r`   r   r   <module>r      s?     C & ( 9 : 2 ' +p< p<pOD ODr   