# Why is this function neither injective nor surjective?

Hello guys I am doing some maths revision and I am stuck. I read and I saw videos and I still can't get my head around it.

I have this example:

Determine whenever this function $\mathbb{Z}\to\mathbb{Z}$ is injective, surjective, neither, both:

$$f(x) = n^2 + 1$$

In the answer it is given that is neither without explaining why not.

If I substitute $n$ with $1$, I will get $f(1) = 2$ and, with $-1$, $f(-1) = 2$ again. So that should be surjective but it says is neither?

-
The fact that $f(1) = f(-1)$ implies that $f$ is not injective, and says nothing about surjectivity; I would suggest carefully reading the definitions of injective and surjective. – user61527 May 17 '14 at 20:36
Surjective doesn't mean "not injective". A function from $A$ to $B$ is surjective if it produces every value in $B$. – user2357112 May 17 '14 at 20:36
is it because you can't map for example 3 ? Which makes it only a general function ? – mazzer07 May 17 '14 at 20:42
@mazzer07 You can't even map to a negative number. – Eff May 17 '14 at 20:42
Did you mean f(x) = x^2 + 1? – dubiousjim May 18 '14 at 2:28

You're given a function $f$ which takes values in $\mathbb Z$ to values in $\mathbb Z$ by the rule $f(x)=x^2+1$.

Let's recall what injective means. Our function $f$ will be injective if for any $x_1,x_2\in\mathbb Z$ such that $f(x_1)=f(x_2)$, we have $x_1=x_2$. You pointed out that $f(1)=2=f(-1)$, but that $1\neq -1$. We plugged $x_1=1$ and $x_2=-1$ into $f$ and saw that $f(x_1)=f(x_2)$. But $x_1\neq x_2$. Therefore, $f$ cannot be injective. Another intuitive way to see this is to view whether or not $f$ passes the horizontal line test. Does it?

In general, to show that a function $f:X\to Y$ is injective, we can show that $$f(x_1)=f(x_2)\implies x_1=x_2$$ or we can show that $$x_1\neq x_2\implies f(x_1)\neq f(x_2).$$

So let's look at whether or not $f$ is surjective. Remember that $f$ is surjective if for any $y\in\mathbb Z$ (in the target set) there is some $x\in\mathbb Z$ (in the domain) such that $f(x)=y$. But notice that $f(x)=x^2+1>0$ for each $x\in\mathbb Z$. So what happens if we choose $y\leq 0$?

In general, to show that a function $f:X\to Y$ with some rule $f(x)$ is surjective, we pick some arbitrary $y\in Y$. Then we find some value in $x\in X$ in terms of $y$, by looking at the rule of our function, that gives $f(x)=y$.

-

I look at injectivity, surjectivity, and bijectivity this way:

A mapping $f : A \to B$ is injective if, for every element in the codomain $B$, there is at most one element in the domain $A$ that maps to it.

A mapping is surjective if, for every element in the codomain, there is at least one element in the domain that maps to it.

A mapping is bijective if, for every element in the codomain, there is exactly one element in the domain that maps to it.

Since your range is $\mathbb Z$, that means that for the function $f(n) = n^2 + 1$ to be injective, no two elements of the domain can map to the same element in the codomain. This is obviously false--$f(-n) = f(n)$ for all integers $n$.

For the function to be surjective, for any integer $m$, there must be another integer $n$ such that $n^2 + 1 = m$. This is also obviously false--if $m = 0$, then there is no integer (or even real) solution to $n^2 + 1 = 0$.

-

The fact that $f(1)=f(-1)$ implies that $f$ is not injective.

Then $n^2+1>0, \forall n\in \mathbb{Z}$, so $f(\mathbb{Z}) \subseteq \mathbb{N}$ so f is not surjective.(=there exists a so that for all b $\in \mathbb{Z}$ $f(b) \ne a$ ; ex : $a=-1$)

-

Surjective means that every number $n\in \mathbb{Z}$ can be written in the form $n=f(m)=m^2+1$, it is clear that negative numbers $n$ cannot be written like this, so $f$ is not surjective. $f$ injective means that different numbers $n$ and $m$ cannot have the same value by $f$, but $1$ and $-1$ are different and have the same value by $f$: $f(-1)=f(1)=2$, so $f$ is not injective.

-
Alright this confused me even more. What about if we had f(x) = x squared for every x element of R. That should be surjective right ? Or again I can't write negative numbers in the form of n squared. ? – mazzer07 May 17 '14 at 20:48
Exactly, you can't write negative numbers in the form of $n^2$, so $f:\mathbb{R}\to \mathbb{R}$ such that $f(x)=x^2$ is also non surjective. – user144542 May 17 '14 at 21:00
@mazze an example of a surjective map is $f:\mathbb{R}\to \mathbb{R}$, $f(x)=x+1$. Because every number can be written in the form $x+1$. This map is also injective. – user144542 May 17 '14 at 21:11

Loosely speaking a function is injective if it cannot map to the same element more than one place. A function is surjective if it maps into all elements (that the function is defined onto). For your example:

First remember that $\mathbb{Z} = \{0,1,-1,2,-2,...\}$. Since the function $f$ maps to $2$ both when $n=1$ and $n=-1$, i.e. $f(1)=f(-1)=2$ it maps to the same element at more than one place. So it is not injective.

Let's check if it is surjective. Then all values of $\mathbb{Z}$ must be mapped to by the function ($f: \mathbb{Z}\rightarrow\mathbb{Z}$). Since there is no $n$ that produces (for example) the value $-2\in\mathbb{Z}$ it cannot be surjective.

Here are some more for you. Is the function $g:[0,\infty)\rightarrow \mathbb{R}$ defined by $g(x)=x^2$ injective, surjective, both or none? Well, $x^2$ is positive or zero for all $x\in[0,\infty)$ so it cannot be surjective since it doesn't map to for example $-3\in\mathbb{R}$. Since $x^2$ maps into a unique element for all $x\in[0,\infty)$ it is, in fact, injective. Now if we look at $h:\mathbb{R}\rightarrow\mathbb{R}$ defined again by $h(x)=x^2$ then it is not surjective for the same reasons. But it is not injective either since we now can take $h(2)=h(-2)=4$. So the function $h$ maps different elements into the same element so it is not injective. As you can see, it is very important which spaces the functions go from and to.

-
What about this: The function f(x) = 2x from the set of natural numbers naturals to the set of non-negative even numbers is a surjective function. It says it is a surjective but isn't it also bijective cause f(1) = 2 f(2) = 4 f(3) = 6. So it is one to one mapping and it will be equal 4 inputs 4 outputs maps one one ? – mazzer07 May 17 '14 at 21:13
So $f:\{0,1,2,...\}\rightarrow\{0,2,4,...\}$ by $f(x)=2x$ is surjective, yes. Because all the elements of the set $\{0,2,4,...\}$ are mapped to by $f$. It is also injective, actually, because no matter what 2 elements of $\{0,1,2,...\}$ you choose they will never product the same element using $f$. – Eff May 17 '14 at 21:16
A function is bijective if it is both injective and surjective (per definition). So this particular $f$ is bijective since it is both injective and surjective, as explained above. Of course this depends on your definition of natural numbers. I used $\mathbb{N}=\{0,1,2,...\}$, but it is equally as often used that $\mathbb{N}=\{1,2,3,...\}$. So if we used the function $f:\{1,2,3,...\}\rightarrow\{0,2,4,...\}$ by $f(x)=2x$ then it is not surjective because no element of $\{1,2,3,...\}$ produces the value $0\in\{0,2,4,...\}$. – Eff May 17 '14 at 21:19
I have seen an example in where it is allowed A to point to B and C to point to B and I though that is one way of finding if it is surjective ? Isn't that right ? Also in what exact example it is only injective and not bijective – mazzer07 May 17 '14 at 21:23
I don't completely understand your first question. A function is injective and not bijective if it is not surjective (again from the definition of bijective). The function $g$ in my original answer satisfies this. – Eff May 17 '14 at 21:26