Using a function without specifying it

asked 2024-01-20 12:29:05 +0100

Cyrille gravatar image

updated 2024-01-20 22:19:49 +0100

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 flag offensive close merge delete

Comments

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.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-01-20 15:30:36 +0100 )edit

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

Cyrille gravatar imageCyrille ( 2024-01-20 21:50:14 +0100 )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)).

Cyrille gravatar imageCyrille ( 2024-01-20 21:56:04 +0100 )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.

rburing gravatar imagerburing ( 2024-01-21 11:30:26 +0100 )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.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-01-21 21:37:52 +0100 )edit