If we are given a function of $x$, $a(x)$, how hard is it to find an $f(x)$ and $g(x)$ such that $$a(x)=f(x)g'(x)+f'(x)g(x)$$ For comparison, I'd like to know when this is easier than symbolically or numerically integrating $a(x)$.
I'd like to know, if possible, what general conditions allow us to efficiently find $f(x)$ and $g(x)$. I'm hoping this isn't too general a question. Additionally, I'd like to know the methods that allow us to do so.
Suppose $a(x)=x^2\cos x + 2x\sin x$.
Recognizing that as $f'(x)g(x)+ f(x)g'(x)$, with $f(x)= \sin x$ and $g(x)= x^2$, seems like the quickest way of finding the antiderivative of the whole expression.