K i TddlmZddlmZddlmZddlmZmZddl m Z m Z dZ dZ y ) )Mul)S)default_sort_key) DiracDelta Heaviside)Integral integratec g}d}|j\}}t|t}|j||D]}|jr^t |j trD|j|j|j |jdz |j }|$t |tr|j|r|}|j||sg}|D]}t |tr#|j|jd|6|jrat |j trG|j|j|j jd||j|j|||k7rt|j}d|fSd}d|fS|t|fS)achange_mul(node, x) Rearranges the operands of a product, bringing to front any simple DiracDelta expression. Explanation =========== If no simple DiracDelta expression was found, then all the DiracDelta expressions are simplified (using DiracDelta.expand(diracdelta=True, wrt=x)). Return: (dirac, new node) Where: o dirac is either a simple DiracDelta expression or None (if no simple expression was found); o new node is either a simplified DiracDelta expressions or None (if it could not be simplified). Examples ======== >>> from sympy import DiracDelta, cos >>> from sympy.integrals.deltafunctions import change_mul >>> from sympy.abc import x, y >>> change_mul(x*y*DiracDelta(x)*cos(x), x) (DiracDelta(x), x*y*cos(x)) >>> change_mul(x*y*DiracDelta(x**2 - 1)*cos(x), x) (None, x*y*cos(x)*DiracDelta(x - 1)/2 + x*y*cos(x)*DiracDelta(x + 1)/2) >>> change_mul(x*y*DiracDelta(cos(x))*cos(x), x) (None, None) See Also ======== sympy.functions.special.delta_functions.DiracDelta deltaintegrate N)keyrT diracdeltawrt)args_cncsortedrextendis_Pow isinstancebaserappendfuncexp is_simpleexpandr) nodexnew_argsdiraccnc sorted_argsargnnodes d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/integrals/deltafunctions.py change_mulr%sNH E MMOEAr 01Kr! ::*SXXz: OOCHHSXXsww{; <((C =jj9cmmA>NE OOC !  %C#z* d BC 388Z @Da)PRURYRY Z[$  % { "N))+Ee}Ee} 3> ""c|jtsy|jtk(r|jd|}||k(r|j |rt |j dks|j ddk(rt|j dSt|j d|j ddz |j djjz St||}|Sy|js |jre|j}||k7r!t||}|t|ts|Syt||\}}|s|rt||}|Syddlm}|jd|}|jrt||\}}||z}||j d|d} t |j dk(rdn|j d} d} | dk\r{t$j&| z|j)|| j+|| z} | j,r | dz} | dz } n(| dk(r| t|| z zS| t|| dz zS| dk\r{t$j.Sy)a deltaintegrate(f, x) Explanation =========== The idea for integration is the following: - If we are dealing with a DiracDelta expression, i.e. DiracDelta(g(x)), we try to simplify it. If we could simplify it, then we integrate the resulting expression. We already know we can integrate a simplified expression, because only simple DiracDelta expressions are involved. If we couldn't simplify it, there are two cases: 1) The expression is a simple expression: we return the integral, taking care if we are dealing with a Derivative or with a proper DiracDelta. 2) The expression is not simple (i.e. DiracDelta(cos(x))): we can do nothing at all. - If the node is a multiplication node having a DiracDelta term: First we expand it. If the expansion did work, then we try to integrate the expansion. If not, we try to extract a simple DiracDelta term, then we have two cases: 1) We have a simple DiracDelta term, so we return the integral. 2) We didn't have a simple term, but we do have an expression with simplified DiracDelta terms, so we integrate this expression. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.integrals.deltafunctions import deltaintegrate >>> from sympy import sin, cos, DiracDelta >>> deltaintegrate(x*sin(x)*cos(x)*DiracDelta(x - 1), x) sin(1)*cos(1)*Heaviside(x - 1) >>> deltaintegrate(y**2*DiracDelta(x - z)*DiracDelta(y - z), y) z**2*DiracDelta(x - z)*Heaviside(y - z) See Also ======== sympy.functions.special.delta_functions.DiracDelta sympy.integrals.integrals.Integral NTr rr)solve)hasrrrrlenargsras_polyLCr is_Mulrrr r% sympy.solversr(r NegativeOnediffsubsis_zeroZero) frhfhg deltaterm rest_multr( rest_mult_2pointnmrs r$deltaintegrater@Qs_p 55  vv HH!H , 6{{1~K1$q Q$QVVAY//&qvvay!&&)a-@q ))+..0121aBI^ ] QXX HHJ 61aB~jX&> R M$.a#3 Iy"9a0BIB ?0%,,!,D ##-7 1-E*I{ )+ 5IinnQ/3A6inn-q0QinnQ6G1f q(1)=)B)B1e)LLAyyQQ6#$Yq5y%9#99#$Z!A#%6#661fvv r&N)sympy.core.mulrsympy.core.singletonrsympy.core.sortingrsympy.functionsrr integralsr r r%r@r&r$rGs!"/1*F#Rxr&