Why must every element of the domain be mapped to some element in the codomain? Is it possible for one element of the domain to be mapped to more than one element in the codomain, why?
Is it possible to have a function with elements on the domain that is not mapped?
$\endgroup$ 51 Answer
$\begingroup$There are lots of ways one can associate objects in one set to objects in another set (or the same set). We call these associations relations. A relation $R$ from $A$ to $B$ is a set of pairs $(a,b) \in A \times B$. Relations can have all kinds of properties, and different properties are appropriate in different situations.
Here is an example: suppose a networking event is attended by job applicants ($A$) and recruiters ($B$). We can define a relation from $A$ to $B$ by $a \mathrel{R} b$ if applicant $a$ got an interview with recruiter $b$.
Must every element of $A$ be related to some element of $B$? Not necessarily. If an applicant $a$ came to the event but didn't get any interviews, then there is no $b \in B$ for which $a \mathrel{R} b$ is true.
Is it possible for an element of $A$ to be related to more than one element of $B$? Sure. If an applicant $a$ got many interviews, then $a \mathrel{R} b$ would be true for several different elements $b \in B$.
Now let's change the example. Keep $A$ as the set of job applicants at the event. Let $B$ be the set of days of the year, from January 1 through December 31, including February 29. Let's define a relation from $A$ to $B$ by $a \mathrel{R} b$ if $a$'s birthday is $b$.
Must every element of $A$ be related to some element of $B$? Yes. Every job applicant has a birthday.
Is it possible for an element of $A$ to be related to more than one element of $B$? No. Nobody has more than one birthday.
Relations like the second get a special name. We call them functions.
Yes, it is possible for a relation to behave “almost” like a function, except that some elements of the “domain” have no image in the codomain. In that case, the domain can be restricted to the subset of elements which do have an image in the codomain, and then you have a true function.
It's more problematic to treat relations where elements of the domain can be related to more than one element of the codomain as functions. Notice we write $f(a)$ for the element of $B$ associated to $a$ by the function $f$. This is ambiguous notation if there's more than one such element of $B$. Like Thomas Andrews says in the comments, such “multi-valued functions” aren't really functions. One way to treat them as functions is (again) to restrict the domain to a subset on which the function is single-valued. One important example is the complex logarithm function.
On its face, your question says, why do functions have these properties? And the answer is, “Because that's the definition of function.” Maybe the question behind that question is, why do we make this part of the definition? The answer to that is, “Relations which behave this way are all around us and it's useful to give them a common name.”
$\endgroup$