# Using a function without specifying it

I want to ask sagemath if

$\int_{-\infty}^\infty |x - a| f(x) dx = \int_{-\infty}^a (a -x) f(x) dx + \int_{a}^\infty (x -a) f(x) dx$

which is obviously true without specifying $f(x)$ (a probability density). Is this possible in SageMath ?

edit retag close merge delete

I would assume the left-hand side is computed via

from sage.symbolic.integration.integral import definite_integral
x,a = var('x a')
f = function('f')
definite_integral(abs_symbolic(x-a)*f(x), x, -oo, +oo)


but it somehow fails.

( 2024-01-20 15:30:36 +0200 )edit

Sorry there was a little mistake. I correct it in the text

( 2024-01-20 21:50:14 +0200 )edit

According to your remark the question is why SageMath is not able return true to

bool(definite_integral(abs_symbolic(x-a)*f(x), x, -oo, +oo)==definite_integral(abs_symbolic(a-x)*f(x), x, -oo, a)+definite_integral(abs_symbolic(x-a)*f(x), x, a, +oo)).

( 2024-01-20 21:56:04 +0200 )edit

One could imagine rewriting the left-hand side by substituting $\lvert x-a \rvert = (x-a)\cdot \chi_{\geqslant a}(x) + (a-x)\cdot \chi_{\lt a}(x)$ where the $\chi$'s are indicator functions, expanding the integrand, using linearity of the integral, and replacing the indicator function factors by narrowed integration bounds. That's easier said than done-with-Sage, though.

( 2024-01-21 11:30:26 +0200 )edit
1

This is true for a real function of a real variable and for a real ; in this case,$|x-a|$ is of course either $x-a$ or $a-x$ depending on the sign of $x-a$. If either $x$ or $a$ is complex, this is no longer true.

Furthermore, in the complex case, you may have discrepancies if the integration paths of the left and right hands of your equation loop around different poles.

( 2024-01-21 21:37:52 +0200 )edit