[Math] Injective and Surjective Function Examples

discrete mathematicsfunctions

I am having trouble with this problem:

Give an example of a function $f:Z \rightarrow N$ that is

a. surjective but not injective

b. injective but not surjective

Work: I came up with examples such as $f=2|x-1|$ only to realize that it is not injective or surjective.

Best Answer

Bijection $\mathbb{Z} \to \mathbb{N}$:

$$f(x) = \left|2x-\frac{1}{2}\right|+\frac{1}{2}$$

Injections $\mathbb{Z} \to \mathbb{N}$:

$$g(x) = f(2x)\quad \text{ or } \quad g'(x) = 2f(x)$$

Surjections $\mathbb{Z} \to \mathbb{N}$:

$$h(x) = f\left(\left\lfloor\frac{x}{2}\right\rfloor\right) \quad \text{ or } \quad h'(x) = \left\lfloor\frac{f(x)}{2}\right\rfloor$$

I hope this helps $\ddot\smile$