Integration with respect to functions

I observe some strange behaviour of Mathematica when pulling functions into the integrator. I know that Mathematica's capabilities are limited when computing Stieltje or Lebesgue Integrals. But even simple outputs behave quite strangely:

Integrate[f'[x], x]
Integrate[1, f[x]]


Gives, correctly:

f[x]
f[x]


But

Integrate[x  f'[x], x]
Integrate[x, f[x]]


Returns quite strangely:

Hence, as @Ulrich Neumann suggests, the second formulation contains the implicit assumption that g'[x] is Riemann integrable. It seems that Mathematica treats f[x] as a separate variable with not dependence on x.

• Probably Mathematica "knows" Integrate[x, f[x]]==Integrate[x f'[x]],x] Commented Jul 2 at 9:26

You can write is as

\begin{align*} \int xd\left( f\left( x\right) \right) & =\int x\frac{df}{dx}dx\\ & =\int xf^{\prime}dx \end{align*}

And Mathematica gives now

 Integrate[x*f'[x], x]


I do not understand how Mathematica operates when Integrating with respect to functions

It looks like you need to reformulate the command yourself like the above so that the integration is with respect to a variable and not a function.

I do not know why Mathematica gave the result it did with your input.

update

fyi, I tried this in Rubi, and Maple 20204 and Fricas and Maxima and XCas/GIAC. Out of these, maxima and giac returned back same result as Mathematica. This is the result

<< Rubi
Int[x, f[x]]


Maple:

int(x,f(x))


Fricas:

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.3, Release Date: 2024-03-19                    │
│ Using Python 3.11.1. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: var('x')
x
sage: f=function("f",nargs=1)

sage: integrate(f(x),x, algorithm="fricas")
integral(f(x), x)

sage: integrate(x,f(x), algorithm="fricas")


Gives

TypeError: An error occurred when FriCAS evaluated 'integrate(sage4,sage3)':


Maxima:

sage: integrate(x,f(x), algorithm="maxima")
x*f(x)


Giac:

sage: integrate(x,f(x), algorithm="giac")
x*f(x)


The Mathematica result seems to be correct if we assume Integrate[x, f[x]]==Integrate[x f'[x]],x]

Integration by parts

Integrate[u f'[u],{u,x0,x}]==x f[x]-x0 f[x0]-Integrate[f[u],{u,x0,x}]

differentiate result

D[x f[x]-x0 f[x0]-Integrate[f[u],{u,x0,x}],x] (* x Derivative[1][f][x] *)

• Thank you -I specified the details of the question accordingly.
– oyy
Commented Jul 2 at 11:50
• May I ask you why you can differentiate the result? I don't see it.
– oyy
Commented Jul 4 at 9:22
• @oyy I differentiate the result to confirm that integral Integrate[x f'[x]],x] is correct Commented Jul 4 at 9:32
• But then the Mathematica output is incorrect. Integrate[x,f[x]] should not evaluate to x f[x]. Without differentiation, we should get with integration by parts: Integrate[x f'[x]],x]==x f[x]-Integrate[f[x],x].
– oyy
Commented Jul 4 at 9:45
• Correct, and D[x f[x]-Integrate[f[x],x],x] evaluates to x f'[x]` Commented Jul 4 at 10:01