I assume that you are asking the following:
"If we have
$$a\cdot f(x) + b\cdot g(x) = f(x)\cdot h(x) + g(x)\cdot p(x)$$
can we conclude that $a = h(x) $ and $ b = p(x)$, where $f$, $g$, $h$, $p$ are functions of $ x $ and $ a $ and $ b $ are constants?"
The short answer is no, we cannot assume that, because we don't know that multiplying $f(x) $ by $ h(x) $ won't give us any copies of $ g(x) $, and we don't know that multiplying $ g(x) $ by $ p(x) $ won't give us any copies of $ f(x) $.
For example, what if we had $ f(x) = x$, $g(x) = x^2 $, $ h(x = 1+x $, and $ p(x) = 1 $? Then we have:
$$ a\cdot f(x) + b\cdot g(x) = x(x+1) + x^2(1)$$
$$a\cdot x + b\cdot x^2 = x^2 + x + x^2 $$
$$ a\cdot x + b\cdot x^2 = x + 2x^2 $$
Therefore, $ a = 1 $ and $ b = 2 $, which are not equal to what we defined for $ h(x) $ and $ g(x) $.