I want to know the logic behind this statement, the proof. The C expression -x, ~x+1, and ~(x-1) all yield the same results for any x. I can show this is true for specific
I'll try to present an intuitive explaination that everybody should find handy. If you insist we may try a more formal approach.
In two's complement representation, in order to have a unique representation of the zero element, we sacrifice one positive element. As a result, there is an extra negative number that has no positive mirror.
So, given 2 bits, we get: {+1, 0, -1, -2} which would be represented in binary as:
-2 10
-1 11
0 00
+1 01
So, we may think of the zero as a mirror. Now, given an integer x, if we want to invert its sign, we can start by inverting all bits. This would have been enough if there was no zero between the positives and negatives. But since the zero makes a shift, in positives, we have compensate for that.
The two expressions mentioned in the question make this compensation before ~(x-1) and after ~x+1 inverting the bits. You can easily verify that using +1 and -1 in our 2-bit example.