# Is a function onto if the output is a subset of the domain?

1. $f : \mathbb{Z} \rightarrow \mathbb{Z}, f(x)= 2x+1$

2. $f : \mathbb{R} \rightarrow \mathbb{R}, f(x)= 2x+1$

I was told that 1) is 1-1, but not onto because the image only contains odd integers, whereas 2) is a Bijection.

Why is this so? Isn't a domain of odd integers a subset of all integers? i.e. if x = 3, the function would spit out 7 which is an odd integer.

Also:

1. $f : \mathbb{Z} \rightarrow \mathbb{R}, f(n)= \pm n$

This is not a function as a single input will yield two values, namely a positive and negative value.

However,

1. $f : \mathbb{Z} \rightarrow \mathbb{R}, f(n)= n$

Is this a function? Considering that any integer will yield another integer, and since integers are a subset of real numbers, is this a valid function?

To the first question, a surjective function explicitly requires that it covers the entire codomain, not just a subset. If the definition allowed for mappings to a subset of the codomain, then every function is surjective, and the term is meaningless. Yes, $f(3) = 7$, but for what value of $x$ does $f(x)=10$?
Definition of a function has 3 ingredients, the domain set, the codomain set and the rule that associates to each element of the domain an element in the codomain. For a function written $g\colon X\to Y$, the domain is $X$, the codomain is $Y$.
The case(i) the domain and codomain are integers. 10 is not obtainable as $2x+1$ for any x in the given domain (consisting of integers), so not onto. But in case (2) 10 is obtainable as 2x+1 for $x=4.5$ which is in the given domain of real numbers.