Coverage for /usr/lib/python3/dist-packages/sympy/integrals/singularityfunctions.py: 19%
16 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1from sympy.functions import SingularityFunction, DiracDelta
2from sympy.integrals import integrate
5def singularityintegrate(f, x):
6 """
7 This function handles the indefinite integrations of Singularity functions.
8 The ``integrate`` function calls this function internally whenever an
9 instance of SingularityFunction is passed as argument.
11 Explanation
12 ===========
14 The idea for integration is the following:
16 - If we are dealing with a SingularityFunction expression,
17 i.e. ``SingularityFunction(x, a, n)``, we just return
18 ``SingularityFunction(x, a, n + 1)/(n + 1)`` if ``n >= 0`` and
19 ``SingularityFunction(x, a, n + 1)`` if ``n < 0``.
21 - If the node is a multiplication or power node having a
22 SingularityFunction term we rewrite the whole expression in terms of
23 Heaviside and DiracDelta and then integrate the output. Lastly, we
24 rewrite the output of integration back in terms of SingularityFunction.
26 - If none of the above case arises, we return None.
28 Examples
29 ========
31 >>> from sympy.integrals.singularityfunctions import singularityintegrate
32 >>> from sympy import SingularityFunction, symbols, Function
33 >>> x, a, n, y = symbols('x a n y')
34 >>> f = Function('f')
35 >>> singularityintegrate(SingularityFunction(x, a, 3), x)
36 SingularityFunction(x, a, 4)/4
37 >>> singularityintegrate(5*SingularityFunction(x, 5, -2), x)
38 5*SingularityFunction(x, 5, -1)
39 >>> singularityintegrate(6*SingularityFunction(x, 5, -1), x)
40 6*SingularityFunction(x, 5, 0)
41 >>> singularityintegrate(x*SingularityFunction(x, 0, -1), x)
42 0
43 >>> singularityintegrate(SingularityFunction(x, 1, -1) * f(x), x)
44 f(1)*SingularityFunction(x, 1, 0)
46 """
48 if not f.has(SingularityFunction):
49 return None
51 if isinstance(f, SingularityFunction):
52 x, a, n = f.args
53 if n.is_positive or n.is_zero:
54 return SingularityFunction(x, a, n + 1)/(n + 1)
55 elif n in (-1, -2):
56 return SingularityFunction(x, a, n + 1)
58 if f.is_Mul or f.is_Pow:
60 expr = f.rewrite(DiracDelta)
61 expr = integrate(expr, x)
62 return expr.rewrite(SingularityFunction)
63 return None