# Can $f(x)=x$ ever be an injective function but not a surjective function, if we restrict the domain of $f$?

If I consider the function function $$f:A \rightarrow B$$ for $$A=[{x:1\leq x \leq 2}]$$ and $$B= [x:x\in \mathbb{R}]$$ where, $$f(x)=x$$. Then we can see that $$f$$ is injective, but it is not surjective (as all members of $$B$$ are not covered).

My first question is, is my reasoning valid?

If so then is it also valid that this function has a left inverse $$g:B\rightarrow A$$ where $$g(x)=x$$,thus $$g(f(a))=a$$, $$\forall a\in A$$ , which is true. But it is ture that $$f$$ does not have a right inverse?

• The $g:B\to A$ is not well-defined, sincerity is not true that $g(x)\in A$ for all $x\in B.$ Sep 21 '19 at 21:16
• You can define $g:B\to A$ which is a left inverse, but your definition is not one. Sep 21 '19 at 21:18
• And you are correct that $f$ has no right-inverse Sep 21 '19 at 21:19
• I understand that $g$ is not well-defined but does $f$ have a left inverse? If so then what could that function be ? Sep 21 '19 at 21:21

Any injective function $$f: A \to B$$ has a left inverse $$g: B \to A$$: for every point $$b$$ in $$B$$ pick its unique (by injectivity) $$f$$-preimage as $$g(b)$$, otherwise define $$g(b) \in A$$ how you like (map everything to a point e.g.). That way, $$g(f(a)) = a$$ for all $$a$$ by construction.
If $$f: A \to B$$ has a left inverse $$g: B \to A$$ then it is injective: $$f(a) = f(a') \to a= g(f(a)) = g(f(a')) = a'$$.
$$f$$ has a right inverse $$g: B \to A$$ iff it is surjective: if $$f$$ is surjective "define" $$g(b)$$ by by picking any element from $$\{a: f(a)=b\}$$ which is a non-empty set (well-order $$A$$ and pick the minimal element from that set, e.g.) and then $$f(g(b))=b$$ by construction. And given a right inverse $$g$$ and $$b \in B$$ then $$f(g(b))=b$$ shows that every $$b$$ has a pre-image $$g(b)$$ so $$f$$ is onto.
So you have $$f : [1,2] \to \mathbb{R}$$ with $$x \mapsto x$$ (e.g. $$f = id_{[1,2]}$$). You want to find a function $$g : \mathbb{R} \to [1,2]$$ so that $$g\circ f : [1,2] \to [1,2]$$ and $$g \circ f (x) = id_{[1,2]}(x) = x$$. So you are right by taking $$g\big|_{[1,2]}(x) = x$$. Now think about what needs to happen with $$x \in [1,2]^c$$? Is there anything you want it to be? Yes, it must be send to $$[1,2]$$, but expect of that? So really it is up to what value you assign it, since all that $$g$$ will be subjected to in the composition $$g\circ f$$ is the image of $$f$$ and that is $$[1,2]$$.