K i zddlmZmZmZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZGdd eZy ) )Soodiff)DefinedFunctionArgumentIndexError) fuzzy_not)Eq)im) Piecewise) HeavisidecNeZdZdZdZd dZedZdZdZ dZ d d Z e Z e Z y) 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) := ^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 Tc(|dk(r|j\}}}|tjtjtdtdfvr|j |||dz S|j r||j |||dz zSyt ||)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. N)argsrZero NegativeOnefunc is_positiver)selfargindexxans s/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/singularity_functions.pyfdiffzSingularityFunction.fdiffXs q=iiGAq!QVVQ]]AbE1R599yyAqs++1a1---%T84 4c|}|}|}||z }tt|jr tdtt|jr td|tj us|tj urtj S|dzj r td|jrtjS|jr0|jrtj|zS|jr||zS|tjdddfvr;|j s |jrtjS|jrtSyy) 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.rrN)rr is_zero ValueErrorrNaN is_negativeis_extended_negativeris_nonnegativeis_extended_nonnegativeris_extended_positiver)clsvariableoffsetexponentrrrshifts revalzSingularityFunction.evalqsV   Q RY&& 'WX X RU]] #]^ ^ AEE>Q!%%Z55L E  `a a  % %66M  }}vvqy ,,ax B+ +  E$>$>vv }}  ,rc|j\}}}|tjtdtdtdfvrttt ||z dfdS|j rt||z |z||z dk\fdSy)zV Converts a Singularity Function expression into its Piecewise form. rrr"r)rTN)rrrr rr r(rrkwargsrrrs r_eval_rewrite_as_Piecewisez.SingularityFunction._eval_rewrite_as_Piecewises ))1a "quae4 4b"QUA,/; ;   q1uqj!a%1*5yA Arc|j\}}}|dk(r1tt||z |jj dS|dk(r1tt||z |jj dS|dk(r1tt||z |jj dS|dk(r1tt||z |jj dS|j r||z |zt||z dzSy ) z_ Rewrites a Singularity Function expression using Heavisides and DiracDeltas. r"r!rrrN)rrr free_symbolspopr(r2s r_eval_rewrite_as_Heavisidez.SingularityFunction._eval_rewrite_as_Heavisides ))1a 7 !a%(!..*<*<*>B B 7 !a%(!..*<*<*>B B 7 !a%(!..*<*<*>B B 7 !a%(!..*<*<*>B B  EA:iAq11 1 rc2|j\}}}||z j|d}|dkrtjS|jr1|jr%|dk(rtjStj S|j r||zStjS)Nrr8)rsubsrrr#Oner)rrlogxcdirzrrr/s r_eval_as_leading_termz)SingularityFunction._eval_as_leading_termsv))1aQ Q" q566M YY5==!RZ166 2QUU 2   !8Ovv rNc^|j\}}}||z j|d}|dkrtjS|jr1|jr%|dk(rtjStj S|j r||z |zj||||StjS)Nrr8)r?r@)rr=rrr#r>r _eval_nseries)rrrr?r@rArr/s rrDz!SingularityFunction._eval_nseriess))1aQ Q" q566M YY5==!RZ166 2QUU 2   UQJ--aD-I Ivv r)r)Nr)__name__ __module__ __qualname____doc__is_realr classmethodr0r4r;rBrD_eval_rewrite_as_DiracDelta$_eval_rewrite_as_HeavisideDiracDeltarrrrsOENG52BBH B2$  #=+E(rrN) sympy.corerrrsympy.core.functionrrsympy.core.logicrsympy.core.relationalr $sympy.functions.elementary.complexesr $sympy.functions.elementary.piecewiser 'sympy.functions.special.delta_functionsr rrMrrrUs-""C&$3:=]F/]Fr