How do you in general prove that a function is well-defined?

$$f:X\to Y:x\mapsto f(x)$$

I learned that I need to prove that every point has exactly one image. Does that mean that I need to prove the following two things:

  1. Every element in the domain maps to an element in the codomain:
    $$x\in X \implies f(x)\in Y$$
  2. The same element in the domain maps to the same element in the codomain: $$x=y\implies f(x)=f(y)$$

At the moment I'm trying to prove this function is well-defined: $$f:(\Bbb Z/12\mathbb Z)^∗→(\Bbb Z/4\Bbb Z)^∗:[x]_{12}↦[x]_4 ,$$ but I'm more interested in the general procedure.

  • 2,171
  • 1
  • 18
  • 38
  • 12,734
  • 12
  • 60
  • 110
  • Mostly, the second part is preferable. – Mikasa Feb 24 '13 at 18:28
  • @Kasper Are you familiar with the set of order pairs definition of a function? – Git Gud Feb 24 '13 at 18:28
  • More context would help here. What function, specifically, are you trying to prove is well-defined? – MJD Feb 24 '13 at 18:28
  • 3
    @BabakS. The second part is senseless if $f$ isn't a function and trivial if $f$ is alrady known to be a function. – Git Gud Feb 24 '13 at 18:29
  • 1
    At the moment I try to prove this function is well-defined: $f:(\Bbb{Z}/12\Bbb{Z})^*\to(\Bbb{Z}/4\Bbb{Z})^*:[x]_{12}\mapsto[x]_4$ , but I'm more intrested in the general procedure. – Kasper Feb 24 '13 at 18:30
  • @GitGud: I assumed that is just a mapping form X to Y. – Mikasa Feb 24 '13 at 18:31
  • @BabakS. He's trying to prove it is in fact a mapping, he still doesn't know it. – Git Gud Feb 24 '13 at 18:31
  • 3
    @Kasper: your original question does not make sense. A function is always defined otherwise it is not a function. What you need in the example, is to prove that there exists a function $f$ satisfying some given property, and that such a function is uniquely determined. – Emanuele Paolini Feb 24 '13 at 18:33
  • @GitGud: I get what you mean but see that he titled the question by ...function....! Do you think he assumed $f$ is at least a map? – Mikasa Feb 24 '13 at 18:33
  • 1
    @BabakS. What do you mean with *map*? I make no distinction between *map* and *function*. – Git Gud Feb 24 '13 at 18:34
  • @Kasper Please answer my question in the second comment. – Git Gud Feb 24 '13 at 18:36
  • @GitGud: Any relation from A to B can be a map and any map cannot be a function of $A\times B$ – Mikasa Feb 24 '13 at 18:36
  • @BabakS. Ok, I see what you mean with *map* now. Please read Asaf's answer below. – Git Gud Feb 24 '13 at 18:37
  • @Kasper By the way \Bbb to get $\Bbb Z$. – Git Gud Feb 24 '13 at 18:39

8 Answers8


When we write $f\colon X\to Y$ we say three things:

  1. $f\subseteq X\times Y$.
  2. The domain of $f$ is $X$.
  3. Whenever $\langle x,y_1\rangle,\langle x,y_2\rangle\in f$ then $y_1=y_2$. In this case whenever $\langle x,y\rangle\in f$ we denote $y$ by $f(x)$.

So to say that something is well-defined is to say that all three things are true. If we know some of these we only need to verify the rest, for example if we know that $f$ has the third property (so it is a function) we need to verify its domain is $X$ and the range is a subset of $Y$. If we know those things we need to verify the third condition.

But, and that's important, if we do not know that $f$ satisfies the third condition we cannot write $f(x)$ because that term assumes that there is a unique definition for that element of $Y$.

Asaf Karagila
  • 370,314
  • 41
  • 552
  • 949
  • 4
    It might be good to mention that the domain of a relation $f$ is the set $\{x : \exists y\,(x,y) \in f\}$, because many people are only familiar with the notion of domain of a _function_. – Trevor Wilson Feb 24 '13 at 18:40
  • Also technically "_the_ codomain of $f$ is $Y$" does not make sense (not in set theory anyway, maybe in category theory...) – Trevor Wilson Feb 24 '13 at 18:41
  • I don't understand #2: if $f\subseteq X\times Y$ and every $x\in X$ has a $y$ such that $\langle x,y\rangle\in f$, doesn't that automatically mean that the domain of $f$ is $X$? (Could you give an example where properties #1 and #3 are met, but property #2 is not?) – ruakh Feb 24 '13 at 20:11
  • @ruakh: Yes. But $\varnothing\subseteq X\times Y$ and the domain of $\varnothing$ is $\varnothing$. Also $X\times Y$ has domain of all $X$, but it does not obey the third rule. I do agree that the second property is redundant, but note that from the third property the first one follows as well. However often we are presented with a case where two of these properties are obvious, or almost obvious, and we need to conclude the third one. I do agree that some fix up might be in order here. I'll put some changes in. – Asaf Karagila Feb 24 '13 at 20:15
  • Thanks @AsafKaragila ! How would I prove property 3 in my example ? – Kasper Feb 24 '13 at 20:26
  • @Kasper: You need to show that whenever $x\equiv y\bmod 12$ then $x\equiv y\bmod 4$. If that **wasn't** the case then we would have $x,y$ such that $[x]_{12}=[y]_{12}$ and $[x]_4\neq[y]_4$ and then the function would not be well-defined. But luckily **it is** the case, so you just need to verify the above. – Asaf Karagila Feb 24 '13 at 20:30
  • @AsafKaragila Intuitive I feel like proving $\forall x,y \in X : x=y\implies f(x)=f(y)$ is in this case sufficient, but I don't see how $\forall x\in X,\forall y_1,y_2 \in Y : (x,y_1),(x,y_2)\in f\implies y_1=y_2$ relates to this. – Kasper Feb 24 '13 at 20:31
  • @Kasper: How did you define a function? – Asaf Karagila Feb 24 '13 at 20:33
  • $f$ is a funciton if every point has exactly one image. But does that mean $\forall x,y \in X : x=y\implies f(x)=f(y)$ and $\forall x\in X,\forall y_1,y_2 \in Y : (x,y_1),(x,y_2)\in f\implies y_1=y_2$ are equivalent in this case ? I'm a little confused here. – Kasper Feb 24 '13 at 20:34
  • @Kasper: Is a function a set, or a primitive object? – Asaf Karagila Feb 24 '13 at 20:38
  • I would say that a function is a set. But I don't know what you mean with primitive object. Also if you say that a function is a set, I think the term codomain makes no sense. – Kasper Feb 24 '13 at 20:47
  • @Kasper: This can get into a very long discussion about what exactly is a function, what is a domain and codomain, and so on. You will also see that I have removed the term "codomain" from my answer for that precise reason. The point is that we define a function as a collection of ordered pairs with a certain property. Then we say that $f\colon X\to Y$ if it is a function whose domain is exactly $X$ and its range is a subset of $Y$. This property is the 3rd in my answer, and it assures us that $f(x)$ is uniquely defined. – Asaf Karagila Feb 24 '13 at 20:56
  • 2
    @Kasper: But we cannot use $f(x)$ as a term **before** we know that it is uniquely defined. Think of the following property "$f(x)$ is the son of $x$". I have a brother, so my dad have two sons. Which one is $f(\text{Asaf Karagila's dad})$? This is *not* well-defined, and we cannot use $f(x)$ in that context. – Asaf Karagila Feb 24 '13 at 20:57
  • What's the difference between this definition and the graph of a function $f$? – user46372819 Sep 24 '18 at 15:04
  • @AlJebr: The graph is the set of ordered pairs. In some context (e.g. set theory) the graph *is* the function. In other contexts, the graph is only part of the definition, and a function also includes a domain and codomain. – Asaf Karagila Sep 24 '18 at 15:05
  • Thinking about $f$ as a subset of $X\times Y$ just blew my mind. – drfrankie Oct 25 '20 at 22:12

Okay, I'm trying to answer my own question here. This is how a function is defined in "Reading, Writing, and Proving: A Closer Look at Mathematics".

Recall that a relation $f$ from $X$ to $Y$ is a subset of $X\times Y$, and therefore the elements of $f$ are ordered pairs $(x,y)$.

A function $f:X\to Y$ is a relation $f$ from $X$ to $Y$ satisfying:
i). $\forall x\in X ,\exists y\in Y :(x,y)\in f $
ii). $\forall x\in X,\forall y_1,y_2 \in Y : (x,y_1),(x,y_2)\in f\implies y_1=y_2$

An function is often called an map or a mapping. The set is $X$ is called the domain and denoted by $\text{dom}(f)$, and the set $Y$ is called the codomain and denoted by $\text{cod}(f)$. When we know what these two sets are and the two conditions are satisfied, we say that $f$ is a well defined function.

Condition i) makes sure that each element in $X$ is related to some element of $Y$, while condition ii) makes sure that no element in $X$ is related to more than one element of $Y$. Note that it may be the case that an element of $Y$ has no element in $X$ to which it is related; or an element of $Y$ could be related to more than one element of $X$.

Therefore, like Asaf Karagila mentioned, if you want to prove that $f$ is a well defined funciton, and the domain $X$ and codomain $Y$ are given, then you need to show that:

  1. $f$ is a relation from $X$ to $Y$
    $f\subseteq X\times Y$

  2. The domain of $f$ is $X$, every element in $X$ is related to some element of $Y$ $\forall x\in X ,\exists y\in Y :(x,y)\in f $

  3. No element of $X$ is related to more than one element of $Y$ $\forall x\in X,\forall y_1,y_2 \in Y : (x,y_1),(x,y_2)\in f\implies y_1=y_2$

  • 2,881
  • 1
  • 9
  • 22
  • 12,734
  • 12
  • 60
  • 110

The issue here is that $[x]_{12}$ means an equivalence class of elements of $\def\Z{\mathbb Z}\Z$, specifically the class of all $y$ such that $x-y$ is a multiple of 12. You have some procedure that says you are given one of these equivalence classes, $[x]_{12}$, and you are calculating a value by selecting a representative element, say $y$, from $[x]_{12}$, and then doing something to that representative to get the answer, in this case the object $[y]_4$. But this does not make sense—it is not "well defined"—if the value you get for the given class $[x]_{12}$ depends on which representative $y$ you selected from $[x]_{12}$.

So your job here is to show that the result you get does not depend on which $y$ you pick as a representative of $[x]_{12}$.

As a counterexample, let's consider the "function" that says that $f\left(\frac ab\right) = a+ b$. So for example $f\left(\frac 12\right) = 3$, simple. But no, wait. $\frac12$ is actually an equivalence class; it is the class $\left[\frac12\right]_\mathbb Q$, which contains not only $\frac12$ but also $\frac24$, $\frac36$, and $\frac{576}{288}$. And with the definition given, the value of $f$ does depend on which representative of $\left[\frac12\right]_\mathbb Q$ you chose. $\frac12 = \frac 24$, but if you use $\frac24$ to calculate $f\left(\frac 12\right)$ you get 6 instead of 3. So this is not a well-defined function; it's not a function at all.

In your example you need to show that if you are given a class, say $[x]_{12}$, and you select an element $y$ from it (which could be any integer at all, as long as $y-x\equiv 0\pmod{12}$), and then you consider the equivalence class $[y]_4$, the class you get does not depend on which $y$ you chose from $[x]_{12}$. If it does, then this $f$ operation is an meaningless as the one in the previous paragraph that claimed to have $f\left(\frac ab\right) = a+b$.

  • 62,206
  • 36
  • 276
  • 489

You're trying to prove $$f:(\Bbb{Z}/12\Bbb{Z})^*\to(\Bbb{Z}/4\Bbb{Z})^*:[x]_{12}\mapsto[x]_4$$

So, you have to prove that this rule of assignment doesn't depend on the representative of the equivalence class. That is $$[x]_{12}=[y]_{12} \implies [x]_{4}=[y]_{4}$$

For example $[16]_{12}=[4]_{12}$ then $[16]_{4}=[4]_{4}$.

You also need to prove that $$ [x]_{12} \in (\Bbb{Z}/12\Bbb{Z})^* \implies [x]_{4} \in (\Bbb{Z}/4\Bbb{Z})^* $$

  • 13,820
  • 17
  • 72
  • 125

An option would be to resort to Relational Algebra, in a pointfree style.
A logic of relations was first proposed by Augustus de Morgan, in 1867.

Functions are just special cases of Relations (binary relations, for that matter).

Given types $A$ and $B$, we denote a relation $R$, from $A$ to $B$, as $B \xleftarrow{R} A$.
We write $b \, R \, a$, to denote $(b,a) \in R$.
In the particular case of functions, for a function $f$, writing $b \, f \, a$ simply means $b = f \, a$, since we expect $b$ to be unique.

Therefore, $b \, R \, a$ is a generalization of $b \, f \, a$.
This generalization applies in many ways. For instance, equality on functions, $f=g$, generalizes to inclusion on relations, $R \subseteq S$, meaning $R$ is (at most) $S$.

Besides inclusion, an important concept to have in mind is the converse of a relation.
The converse of $R$, $B \xleftarrow{R} A$, is $R^\circ$, $A \xleftarrow{R^\circ} B$ (just turn the arrows the other way around).

The converse of a function always exists, as a relation (sometimes, in special cases, as a function too).

Function composition, $f \cdot g$, also generalizes to relations, $R \cdot S$, in the same way.

So, what is it that really defines when a given relation is a function?$\vphantom{Some commands added; A.K.}\newcommand{\img}{\operatorname{img}}\newcommand{\id}{\mathrm{id}}$

Let's look at a special function, $\id$.
We have $b \, \id \, a \equiv b = a$. Not too hard.

Why does $id$ matter?

  • $R$ is reflexive iff $\id \subseteq R$.
  • $R$ is coreflexive iff $R \subseteq \id$.

We then define:

  • Kernel of $R$ as $\ker R \doteq R^\circ \cdot R$.
  • Image of $R$ as $\img R \doteq R \cdot R^\circ$.

Finally, we have the following facts:

  • $\ker R$ is reflexive $\equiv$ $R$ is entire.
  • $\ker R$ is coreflexive $\equiv$ $R$ is injective.
  • $\img R$ is reflexive $\equiv$ $R$ is surjective.
  • $\img R$ is coreflexive $\equiv$ $R$ is simple.

We say relation $f$ is a function iff $f$ is entire and $f$ is simple.
Put in another way, what you want to prove is:

  • $\id \subseteq ker f$ (simplifies to $\id \subseteq f^\circ \cdot f$)
  • $\img f \subseteq \id$ (simplifies to $f \cdot f^\circ \subseteq \id$)

Bonus facts:

  • $\ker (R^\circ) = \img R$
  • $\img (R^\circ) = \ker R$
Asaf Karagila
  • 370,314
  • 41
  • 552
  • 949
  • 131
  • 1
  • 1
  • 5

For predictably wise words about this from Tim Gowers (that's Professor Sir Timothy Gowers to you ...), see http://gowers.wordpress.com/2009/06/08/why-arent-all-functions-well-defined/

Peter Smith
  • 49,532
  • 3
  • 58
  • 138

First, note that any function from $X$ to $Y$ defined by

$$ x \mapsto E $$

or by

$$ f(x) = E$$

is well-defined, where $x$ is an indeterminate variable that ranges over $X$ and $E$ is a (well-formed) Y-valued expression depending (only) on $x$. (to fix the edge cases, $1$ depends on $x$, albeit in a degenerate fashion)

However, this is not the only way we define functions. There are two ways of thinking about the common alternative:

The more set-theoretic viewpoint is that we can define $f$ by a relation. We might define a function on the rational numbers by thinking

$f$ relates $x/y$ with $(x+y)/y$

Of course, we would normally write it as $x/y \mapsto (x+y)/y$ or as $f(x/y) = (x+y)/y$. But we are thinking in terms of a relation.

To check that such a mapping is well-defined, we need to check that the relation passes the 'vertical line test': specifically, that set of values

$$ \left\{ \left(\frac{x}{y}, \frac{x+y}{y} \right) \mid x,y \in \mathbb{Q}, y \neq 0 \right\} $$

contains exactly one pair $(q, \square)$ for each $q \in \mathbb{Q}$.

A more algebraic viewpoint is that we define our mapping in terms of preimages. If we define functions $g : Z \to Y$ and $p : Z \to X$, then we think of defining $f$ as a mapping

$$ g(z) \mapsto p(z) $$

or by

$$f(g(z)) = p(z) $$

This is well-defined when we can prove

$$ g(z) = g(z') \implies p(z) = p(z') $$

This can be thought of as the third isomorphism theorem as applied to sets. An extremely natural example in this viewpoint is anything to do modular arithmetic. e.g. we can define "multiplication by 5" on $\mathbb{Z} / 2 \mathbb{Z} \to \mathbb{Z} / 10 \mathbb{Z}$ by

$$ [x]_2 \mapsto [5x]_{10} $$

In this case, the maps are

$$p(z) : \mathbb{Z} \to \mathbb{Z} / 2 \mathbb{Z} : x \mapsto [x]_2 $$ $$g(z) : \mathbb{Z} \to \mathbb{Z} / 10 \mathbb{Z} : x \mapsto [5x]_{10} $$


I've been wrestling with this for a whole semester, and today, while talking with the assistant professor, I think I came to a fairly easy way to understand if the function (or the map in question) is well defined if no element in the domain is mapped to more than one element in the codomain. It is probably not that simple, but I think for the purpose of my course (Algebra I), it is.

  • 977
  • 6
  • 12