# Proving piece-wise function is one-to-one?

f: Z -> Z defined by f(x) = x/2 if x is even, (x-1)/2 if x is odd.

Proof: If x is even:

x1 = 2k1
x2 = 2k2

Suppose f(x1) = f(x2), then

2k1/2 = 2k2/2
k1 = k2

So if x is even, the function is one to one? Is this an okay proof for the first half of if x is even, then I just do the same for if x is odd correct?

Not sure if you can use a function to define the independent variable to prove if it's one-to-one or not.