TITLE: Prove/disprove: if $\det(A+X) = \det(B + X)$ for all $X$, then $A=B$
QUESTION [15 upvotes]: I have to prove/disprove this:

If $\det(A+X) = \det(B + X)~ \forall X \in M_{n \times n} (\mathbb F) \rightarrow A = B$

I believe it is true but I can not think of a direct way to prove it.
Any help is appreciated!

REPLY [3 votes]: I just see this problem today, so this is a late answer.
We can use the same trick I used in an answer to another question. By elementary row/column reductions, we have $B-A=P(I_r\oplus0)Q$ for some invertible matrices $P$ and $Q$, with $r=\operatorname{rank}(B-A)$. Therefore, by putting $Y = P^{-1}(A+X)Q^{-1}$, the given assumption is equivalent to $\det(Y)=\det((I_r\oplus0) + Y)$ for all $Y$. Since this condition does not hold if $r\neq0$ and $Y=0\oplus I_{n-r}$, we conclude that $r$ must be zero, i.e. $B=A$.