Multiplying through by f and integrating shows that......
Then A=B, as one sees by multiplying out the product on the right.
The theory of elementary divisors now shows that by pre- and post-multiplying x by suitable elements of K we can reduce x to a diagonal matrix.