COMPSCI 225:
Discrete Structures in Mathematics and Computer Science

Relations and Functions

Ordered pairs, Cartesian products, power set

Given two objects xx and yy , we can form the ordered pair (x,y)(x,y) . Unlike the pair set {x,y}\{x,y\} , the order in which the elements appear is important: given two ordered pairs (x,y)(x,y) and (u,v)(u,v) , we have

(x,y)=(u,v)x=u and y=v.(x,y)=(u,v)\qquad\Leftrightarrow\qquad x=u\text{ and }y=v.

Similarly, we have ordered triples (x,y,z)(x,y,z) , ordered 4-tuples (w,x,y,z)(w,x,y,z) , and so on, where if (x1,x2,,xn)(x_1,x_2,\dots,x_n) and (y1,y2,,yn)(y_1,y_2,\dots,y_n) are ordered nn -tuples then

(x1,x2,,xn)=(y1,y2,,yn)xi=yi(x_1,x_2,\dots,x_n)=(y_1,y_2,\dots,y_n)\Leftrightarrow x_i=y_i

for i=1,2,,n.i=1,2,\dots,n.

Cartesian product

Link copied

Given sets AA and BB , we form the Cartesian product of AA and BB , written A×BA\times B , defined by

A×B={(a,b):aA,bB}.A\times B=\{\,(a,b):a\in A, b\in B\,\}.

If AA and BB are finite sets then A×B=AB|A\times B|=|A|\cdot|B| .

If A1A_1 , A2A_2 , … , AnA_n are sets, we define A1×A2××AnA_1\times A_2\times\dots\times A_n to be the set of all nn -tuples (a1,a2,,an)(a_1,a_2,\dots,a_n) where aiAia_i\in A_i for i=1,2,,ni=1,2,\dots,n .

We sometimes write AnA^n for A×A××An times\underbrace{A\times A\times\dots\times A}_{\text{n times}} . In particular, we often write A2A^2 for A×AA\times A .

Example 4.1.Link copied The grid of squares used in the game of battleships is the example
{1,2,3,4,5,6,7,8}×{a,b,c,d,e,f,g,h}\{ 1, 2, 3, 4, 5, 6, 7, 8 \} \times \{a, b, c, d, e, f, g, h \}

of a Cartesian product.


Example 4.2 _What is the Cartesian product A×B×CA\times B\times C where A={0,1},B={1,2}A=\{ 0,1 \} , B= \{1,2 \} , and C={0,1,2}C = \{ 0,1,2 \} ? What is (A×B)×C)(A\times B)\times C) ?

Power Set

Link copied

Given a set AA we can form the power set of AA , power set denoted by P(A)\mathcal P(A) , containing all the subsets of AA .

Example 4.3.Link copied If A={1,2}A=\{1,2\} then
P(A)=_____________________\mathcal P(A)=\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

We will show later that if AA has nn elements then P(A)\mathcal P(A) has 2n2^n elements.


Relations

Let AA and BB be sets. A binary relation from AA to BB is a subset of A×BA\times B . A binary relation on AA is a subset of A×AA\times A .

We use binary relations to represent relationships between the elements of AA and the elements of BB . If RR is a binary relation from AA to BB , and (x,y)A×B(x,y)\in A\times B , then (x,y)R(x,y)\in R if and only if the relationship holds between the element xx and the element yy .

Example 4.4.Link copied Take A={1,2,3}A=\{1,2,3\} , and let RR be the relation on AA defined by

(x,y)Rx<y(x,y)\in R\qquad\Leftrightarrow\qquad x<y .

Then we have R={(1,2),(1,3),(2,3)}R=\{(1,2),(1,3),(2,3)\} .


Example 4.5.Link copied Let AA be the set of students at Auckland University, and let BB be the set of courses. Let RR be the relation that consists of those pairs (a,b)(a,b) where aa is a student in course bb . For instance, if Sooyoun Lee and Wiremu Ngata are enrolled in 225, the pair (Sooyoun Lee, 225) and (Wiremu Ngata, 225) belong to RR . If Sooyoun Lee is also enrolled in 220, then the pair (Sooyoun Lee, 220) is also in RR . However, if Wiremu Ngata is not enrolled in 220, then the pair (Wiremu Ngata, 220) is not in RR .

Properties of relations

Link copied

We often use infix notation for relations. In other words, we write (x,y)R(x,y)\in R as xRyx R y . This is particularly common with relations like << , == , \subseteq and so on that have standard names. If (x,y)R(x,y)\notin R , we write xyx\not R y .

There are various properties that a relation on a set might or might not have. We say that a relation RR on a set AA is


Example 4.6.Link copied Consider the relation == on any set AA . Which of the above properties hold?

Example 4.7.Link copied Consider the relation << on R\R . Which of the above properties hold?

Example 4.8.Link copied Consider the relation \mid on Z\Z , defined by

abfor some cZ,b=aca\mid b \qquad \Leftrightarrow \qquad \text{for some}\ c\in \Z, b=ac .

Which of the above properties hold?


Example 4.9.Link copied Can a relation be both symmetric and antisymmetric?

Example 4.10.Link copied A relation on a finite set SS can be pictured as a directed (pseudo)graph. Let the vertex set of the graph be SS and the pairs (x,y)(x,y) satisfying the relation are represented as directed edges (x,y)(x,y) . Draw the relation \mid on the set S={1,2,3,4,5,6}S = \{ 1, 2, 3, 4, 5, 6 \} .

Equivalence relations

Let AA be a set. An equivalence relation on AA is a binary relation on AA that is reflexive, symmetric and transitive. We often use symbols like \sim , \equiv and \cong for equivalence relations.

Example 4.11.Link copied On the set of students attending Auckland University, define one student to be related to another whenever their surnames begin with the same letter. Is this an equivalence relation?

Example 4.12.Link copied Let SS denote the set of all people in New Zealand. Define a relation RR on SS by letting xRyx\R y mean that xx has the same mother as yy . Is this an equivalence relation?

Does the answer change if we define xRyx\R y to mean that xx has the same mother or father as yy ?

Example 4.13.Link copied Consider the set Z\Z of integers. Fix some integer m>1m>1 . Then the relation of_ congruence modulo mm , _defined by
xy(modm)mxy,x\equiv y\pmod m\qquad\Leftrightarrow\qquad m\mid x-y,

is an equivalence relation.

Example 4.14.Link copied Let G=(V,E)G = (V,E) be a simple graph. Consider the binary relation on VV such that, for u,vVu, v \in V , uRvu \R v if and only if there is a path from uu to vv . This is an equivalence relation, which we call connectivity.

Example 4.15.Link copied Let C\mathcal{C} denote the set of all computer programs. Define a relation \sim on C\mathcal{C} as follows: For C,CCC, C' \in \mathcal{C} (in other words, for any two computer programs CC and CC' ) we write CCC \sim C' if, for all possible program inputs xx , either CC and CC' both do not terminate on input xx , or else both CC and CC' terminate on input xx and return the same output.

Example 4.16.Link copied Let f:ABf:A\to B be a function. Then the relation f\sim_f on AA , defined by
xfyf(x)=f(y) x\sim_f y\qquad\Leftrightarrow\qquad f(x)=f(y)

is an equivalence relation. We call this relation the equivalence relation induced by ff .

Equivalence classes, partitions

Link copied

Let \sim be an equivalence relation on a set AA , and let xAx\in A . The equivalence class of xx under \sim , denoted by [x][x] , is the set of all elements of AA that are related to xx under \sim , i.e.

[x]={yA:xy}[x]=\{\,y\in A:x\sim y\,\}

We denote the set of equivalence classes of elements of AA under \sim by [A][A] or by A/A/{\sim} .

Example 4.17.Link copied Consider the relation of congruence modulo~2 on the set Z\Z . What are [0][0] , [1][1] ?

Example 4.18.Link copied Let GG be a simple graph and let RR be the relation of connectivity. The equivalence classes are the connected components of the graph.

Solution. [1]={1,1}[1]=\{1,-1\} , [14]={14,14}[14]=\{14,-14\} , and [0]={0}[0]=\{0\} .

Equivalence class lemma

Link copied

If \sim is an equivalence relation on AA , and x,yAx,y\in A , then the following are equivalent:

  1. xyx\sim y .
  2. [x]=[y][x]=[y] .
  3. [x][y][x]\cap[y]\ne\emptyset .

Proof: We show that (1) implies (2), (2) implies (3) and (3) implies (1).

(1)(2)(1)\Rightarrow(2) Suppose xyx\sim y . Let z[y]z\in[y] . Then yzy\sim z , so we have xyzx\sim y\sim z , and so by transitivity we have xzx\sim z . Thus z[x]z\in[x] . Hence [y][x][y]\subseteq [x] . Conversely, let w[x]w\in[x] . Then xwx\sim w , so by symmetry we have wx.w\sim x. So wxyw\sim x\sim y , and so wyw\sim y . Hence ywy\sim w , so w[y]w\in[y] . Thus [x][y][x]\subseteq[y] , so [x]=[y][x]=[y] .

(2)(3)(2)\Rightarrow(3) Suppose [x]=[y][x]=[y] . Then [x][y]=[x][x]=[x][x]\cap[y]=[x]\cap[x]=[x] . By reflexivity, xxx\sim x , so x[x] x\in [x] , so [x][x]\ne\emptyset . Thus [x][y].[x]\cap[y]\ne\emptyset.

(3)(1)(3)\Rightarrow(1) Suppose [x][y][x]\cap[y]\ne\emptyset . Let z[x][y]z\in[x]\cap[y] . Then xzx\sim z and yzy\sim z . By symmetry, we have zyz\sim y , so xzyx\sim z\sim y , and therefore by transitivity we have xyx\sim y .

Hence (1), (2) and (3) are equivalent.


In other words, if [x][x] and [y][y] are equivalence classes then either [x]=[y][x]=[y] or [x][x] and [y][y] are disjoint. We say that the relation \sim partitions the set AA .


Definition 4.1 A (finite) partition of a set XX is a set {X1,,Xt}\{ X_1, \dots, X_t \} where XiXX_i \subseteq X , XiX_i \ne \emptyset and:

  1. XiXj=X_i \cap X_j = \emptyset when 1i<jt1 \le i < j \le t ;
  2. X1X2Xt=XX_1 \cup X_2 \cup \cdots \cup X_t = X .

An example of a partition is cutting a cake into pieces: No slice of cake is empty, slices of cake have no crumbs in common, putting the slices together forms the whole cake.


Example 4.19.Link copied Let RR be the relation on Z\Z such that xRyx\R y if and only if x=yx=y or x=yx=-y . Show that RR is an equivalence relation. What are [1][1] , [14][-14] , and [0][0] ?

Solution. [1]={1,1}[1]=\{1,-1\} , [14]={14,14}[14]=\{14,-14\} , and [0]={0}[0]=\{0\} .

The graph representing an equivalence relation on a finite set is a union of complete graphs (with loops at every vertex).


Partial orderings

Introduction

Link copied

A commonly used type of relation is an ordering. For instance, words in a dictionary are ordered using a relation called “lexicographical ordering”. We also order real numbers and integers in familiar ways.

Consider the usual ordering on Z\Z . Then the set of integers satisfying the relation is {(x,y)Z2xy}\{ (x, y) \in \Z^2 \mid x \le y \} . One can verify that this relation is reflexive, antisymmetric, and transitive. Other relations that have these properties can be considered to be somehow “analogous” to familiar orderings.

Poset

Link copied

A relation RR on a set SS is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive. A set SS together with a partial ordering RR is called partially ordered set, or poset, and is denoted by (S,R).

Example 4.20.Link copied Show that the “greater than or equal” relation ()(\geq) is a partial ordering on the set of integers.

Example 4.21.Link copied The divisibility relation \mid is a partial ordering on the set of positive integers P=Z1\mathbb{P} = \Z_{\ge 1} , since it is reflexive, antisymmetric, and transitive, as was shown in Example 4.2. We see that (P,)(\mathbb{P}, \mid) is a poset.

Example 4.22.Link copied Show that the inclusion relation \subseteq is a partial ordering on the power set of a set SS .

Example 4.23.Link copied Let AA be the set of all strings over the alphabet {0,1}\{ 0, 1 \} . We say that xAx \in A is a_ prefix _of yAy \in A if y=xvy = xv for some vAv \in A . For example 0101 is a prefix of 0111101111 , while 0101 is not a prefix of 11111111 . Show that this relation is a partial ordering.

Example 4.24.Link copied Let SS be the set of all students in COMPSCI 225. Define a partial ordering \preceq such that xyx\preceq y if and only if xx ‘s height is less than or equal to yy ‘s height. Is (S,)(S,\preceq) a poset?

Notation

Link copied

In a poset the notation aba \preceq b denotes that (a,b)R(a, b) \in R . This symbol is used to emphasise the similarity to the familiar “less than or equal to” relation. But be careful: Just because a relation is denoted by a symbol like \preceq does not automatically imply it has exactly the same properties as \le . We write aba \prec b to mean aba \preceq b , but aba \ne b . Also, we say ”aa is less than bb ” or ”bb is greater than aa ” if aba \prec b .

Comparable

Link copied

When aa and bb are elements of the poset (S,)(S, \preceq) , it is not necessary that either aba \preceq b or bab \preceq a . For instance, in (P(Z),)(\mathcal P( \Z ), \subseteq) , {1,2}\{1, 2\} is not related to {1,3}\{1, 3\} , and vice versa, since neither set is contained within the other. Similarly, in (P,)(\mathbb{P}, \mid ) , 22 is not related to 33 and 33 is not related to 22 , since 232 \nmid 3 and 323 \nmid 2 . This leads to the following definition.

The elements aa and bb of a poset (S,)(S, \prec) are called comparable if either aba \preceq b or bab \preceq a . When aa and bb are elements of SS such that neither aba \preceq b nor ba,b \preceq a, a and b are called incomparable.

Example 4.25.Link copied In the poset (P,)(\mathbb{P}, \mid) , are the integers 3 and 9 comparable? Are 5 and 7 comparable?

Example 4.26.Link copied In the poset (P(S),)(\mathcal P(S), \subseteq) , where S={a,b,c}S=\{a,b,c\} , {a}\{a\} is not comparable to {b}\{b\} , and {a,b}\{a,b\} is not comparable to {b,c}\{b,c\} .

Totally ordered set

Link copied

The adjective “partial” is used to describe partial orderings since pairs of elements may be incomparable. When every two elements in the set are comparable, the relation is called a total ordering.

Definition 4.2 If (S,)(S, \preceq) is a poset and every two elements of SS are comparable, SS is called a totally ordered or linearly ordered set, and \preceq is called a total order or a linear order. A totally ordered set is also called a chain.


Example 4.27.Link copied The poset (Z,)(\Z, \le) is totally ordered, since aba \le b or bab \le a whenever a and b are integers.

Example 4.28.Link copied The poset (P,)(\mathbb{P}, \mid) is not totally ordered since it contains elements that are incomparable, such as 5 and 7.

Well ordered set

Link copied

We say that (S,)(S, \preceq) is a well-ordered set if it is a poset such that \preceq is a total ordering and such that every nonempty subset of S has a least element. (aa is a least element of (S,)(S, \preceq) if aba \preceq b for all bSb \in S .)

Example 4.29.Link copied The most familiar example of a well-ordered set is the set (N,)(\N,\le) of natural numbers, with the usual “less than or equals” ordering.

Example 4.30.Link copied The set of ordered pairs of positive integers, P×P \mathbb{P} \times \mathbb{P} , with (a1,a2)(b1,b2)(a_{1}, a_{2}) \preceq (b_{1}, b_{2}) if a1<b1a_{1} < b_{1} , or if a1=b1a_{1} = b_{1} , and a2b2a_{2} \le b_{2} (the lexicographic ordering), is a well-ordered set.

Example 4.31 The set Z\Z , with the usual \le ordering, is not well ordered since the set of negative integers, which is a subset of Z\Z , has no least element.

Lexicographic order

Link copied

The letters of the alphabet have a standard ordering a<b<<z 'a'<'b'<\cdots <`z' . The “dictionary” or “lexicographic” ordering turns this ordering on letters into an ordering on words. This is a special case of a general principle: given an alphabet set AA that is a poset one can impose an ordering on strings over the alphabet AA . We now explain this construction.

First, we will show how to construct a partial ordering on the Cartesian product of two posets, (A1,1)(A_{1}, \preceq_{1}) and (A2,2)(A_{2}, \preceq_{2}) . The lexicographic ordering \preceq on A1×A2A_{1} \times A_{2} is defined by specifying that one pair is less than a second pair if the first entry of the first pair is less than (in A1A_{1} ) the first entry of the second pair, or if the first entries are equal, but the second entry of this pair is less than (in A2A_{2} ) the second entry of the second pair. In other words, (a1,a2)(a_{1}, a_{2}) is less than (b1,b2)(b_{1}, b_{2}) , that is

(a1,a2)(b1,b2),(a_{1}, a_{2}) \prec (b_{1}, b_{2}),

either if a11b1a_{1} \prec_{1} b_{1} or if both a1=b1a_{1} = b_{1} and a22b2a_{2} \prec_{2} b_{2} .

We obtain a partial ordering \preceq by adding equality to the ordering \prec on A×BA \times B . The verification of this is left as an exercise.

Example 4.32.Link copied Determine whether (3,5)(4,8)(3, 5) \prec (4, 8) , whether (3,8)(4,5)(3,8) \prec (4, 5) , and whether (4,9)(4,11)(4, 9) \prec (4, 11) in the poset (Z×Z,)(\Z \times \Z, \preceq) , where \preceq is the lexicographic ordering constructed from the usual \le relation on Z\Z .

Example 4.33.Link copied On figure below, indicate the set of ordered pairs in P×P\mathbb{P} \times \mathbb{P} that are less than (3, 4).

Cartesian product of posets

Link copied

A lexicographic ordering can be defined on the Cartesian product of nn posets (A1,1),(A2,2),,(An,n)(A_{1}, {\preceq_{1}}), (A_{2}, {\preceq_2}),\ldots, (A_{n}, {\preceq_{n}}) . Define the partial ordering \preceq on A1×A2××AnA_{1} \times A_{2} \times \cdots \times A_{n} by

(a1,a2,,an)(b1,b2,,bn)(a_{1}, a_{2}, \ldots, a_{n}) \prec (b_{1}, b_{2}, \ldots, b_{n})

if a11b1a_{1} \prec_{1} b_{1} , or if there is an integer i>0i > 0 such that a1=b1,,ai=bia_{1} = b_{1}, \ldots, a_{i} = b_{i} , and ai+1i+1bi+1a_{i+1} \prec_{i+1} b_{i+1} . In other words, one nn -tuple is less than a second nn -tuple if the entry of the first nn -tuple in the first position where the two nn -tuples disagree is less than the entry in that position in the second nn -tuple.

Example 4.34.Link copied Note that (1,2,3,5)(1,2,4,3)(1, 2, 3, 5) \prec (1, 2, 4, 3) , since the entries in the first two positions of these 4-tuples agree, but in the third position the entry in the first 4-tuple, 3, is less than that in the second 4-tuple, 4. (Here the ordering on 4-tuples is the lexicographic ordering that comes from the usual “less than or equals” relation on the set of integers.)

Lexicographic ordering of strings

Link copied

Consider the strings ala2ama_{l}a_{2} \cdots a_{m} and b1b2bnb_{1}b_{2} \cdots b_{n} on a partially ordered set SS . Suppose these strings are not equal in length. Let tt be the minimum of mm and nn . The definition of lexicographic ordering is that the string a1a2ama_{1}a_{2} \cdots a_{m} is less than b1b2bnb_{1}b_{2} \cdots b_{n} if and only if

(a1,a2,,at)(b1,b2,,bt),or(a_{1}, a_{2}, \ldots, a_{t}) \prec (b_{1}, b_{2}, \ldots, b_{t}), or (a1,a2,,at)=(b1,b2,bt)andm<n,(a_{1}, a_{2}, \ldots, a_{t}) = (b_{1}, b_{2}, \ldots b_{t}) \qquad and \qquad m < n,

where \prec in this inequality represents the lexicographic ordering of StS^{t} . In other words, to determine the ordering of two different strings, the longer string is truncated to the length of the shorter string, namely, to t=min(m,n)t = \min(m, n) terms. Then the tt -tuples made up of the first tt terms of each string are compared using the lexicographic ordering on StS^{t} . One string is less than another string if the tt -tuple corresponding to the first string is less than the tt -tuple of the second string, or if these two tt -tuples are the same, but the second string is longer. The verification that this is a partial ordering is left as an exercise.

Directed graph

Link copied

We can draw a directed graph of a poset (called a Hasse diagram or lattice diagram) as follows. Each element of the poset is represented by a dot, called a vertex. An arrow, called a directed edge, is drawn from element aa to element bb if aba\preceq b . The diagram (a) below is a digraph of the poset ({1,2,3,4},)(\{1, 2, 3, 4\}, \le) .

Redundant edges

Link copied

Many edges in the directed graph for a finite poset do not have to be shown since they must be present. For instance, consider the directed graph for the partial ordering {(a,b)ab}\{(a, b) \mid a \le b\} on the set {l,2,3,4},\{l, 2, 3, 4\}, shown in diagram (a) below. Since this relation is a partial ordering, it is reflexive, and its directed graph has loops at all vertices.

Consequently, we do not have to show these loops since they must be present; in diagram (b) loops and arrows are not shown.


Because a partial ordering is transitive, we do not have to show those edges that must be present because of transitivity. For example, in diagram (c) the edges (1,3),(1,4)(1, 3), (1, 4) , and (2,4)(2, 4) are not shown since they must be present. If we assume that all edges are pointed “upward” (as they are drawn in the figure), we do not have to show the directions of the edges; diagram (c) does not show directions.

Hasse diagrams

Link copied

To draw the diagram, execute the following procedure. Start with the directed graph for this relation. Draw it so that arrows are always pointing upwards. Because a partial ordering is reflexive, a loop is present at every vertex. Remove these loops. Remove all edges whose presence is imposed by transitivity. For instance, if (a,b)(a, b) and (b,c)(b, c) are in the partial ordering, remove the edge (a,c)(a, c) , since it must be present also. Furthermore, if (c,d)(c, d) is also in the partial ordering, remove the edge (a,d)(a, d) , since is must be present also. Finally, arrange each edge so that its initial vertex is below its terminal vertex (as it is drawn on paper). Remove all the arrows on the directed edges, since the direction on the edges is now indicated by which vertices are “higher” on the page. Note that Hasse diagrams never have horizontal edges!

These steps are well-defined, and only a finite number of steps need to be carried out for a finite poset. When all the steps have been taken, the resulting diagram contains sufficient information to find the partial ordering. This diagram is called a Hasse diagram, named after the 20th century German mathematician Helmut Hasse.


Example 4.35.Link copied Draw the Hasse diagram representing the partial ordering {(a,b):ab}\{(a, b) : a \mid b \} on {1,2,3,4,6,8,12}.\{1, 2, 3, 4, 6, 8, 12\}.

Example 4.36.Link copied Draw the Hasse diagram for the poset (P(S),)(\mathcal P(S),\subseteq) , where SS is the set {a,b,c}\{a,b,c\} .

Maximal and minimal elements

Link copied

For many applications it is useful to be able to identify certain extremal elements of partially ordered students. For example, a prize might be given to the student in a course with the highest grade.

An element of a poset is called maximal if it is not less than any element of the poset. That is, aa is maximal in the poset (S,)(S, \preceq) if there is no bSb \in S such that aba \prec b . Similarly, an element of a poset is called minimal if it is not greater than any element of the poset. That is, aa is minimal if there is no element bSb \in S such that bab \prec a . Maximal and minimal elements are easy to spot using a Hasse diagram. They are the elements with nothing above them or with nothing below them.

Example 4.37.Link copied Which elements of the poset
({2,4,5,10,12,20,25},)(\{2, 4, 5, 10, 12, 20, 25\}, \mid)

are maximal, and which are minimal?

Greatest and least elements

Link copied

Sometimes there is an element in a poset that is greater than every other element. Such an element is called the greatest element. That is, aa is the greatest element of the poset (S,)(S, \preceq) if bab \preceq a for all bSb \in S . The greatest element is unique when it exists. Likewise, an element is called the least element if it is less than all the other elements in the poset. That is, aa is the least element of (S,)(S, \preceq) if aba \preceq b for all bSb \in S . The least element is unique when it exists.

Example 4.38.Link copied Determine whether the posets represented by the Hasse diagrams below have a greatest element and a least element. Determine whether the posets have maximal and minimal elements. Is a maximal element always a greatest element? Is a greatest element always a maximal element?
Example 4.39.Link copied Let SS be a set. Determine whether there is a greatest element and a least element in the poset (P(S),)(\mathcal P(S), \subseteq) .

Solution. The least element is the empty set, since T\emptyset \subseteq T for any subset T<LT<L of SS . The set SS is the greatest element in this poset, since TST \subseteq S whenever TT is a subset of SS .

Example 4.40.Link copied Is there a greatest element and a least element in the poset (P,)(\mathbb{P}, \mid) ?

Solution. The integer 1 is the least element since 1n1 \mid n whenever nn is a positive integer. Since there is no integer that is divisible by all positive integers, there is no greatest element.

*Upper and lower bounds

Link copied

Let (S,)(S, \preceq) be a poset and ASA \subseteq S a subset of it. Then (A,)(A , \preceq) is also a poset. Sometimes it is possible to find an element in SS that is greater than all the elements in the subset AA . An element uSu \in S such that aua \preceq u for all elements aAa \in A is called an upper bound of AA . Likewise, an element lSl \in S such that lal \preceq a for all elements aAa \in A is called a lower bound of AA .

Example 4.41.Link copied Find the lower and upper bounds of the subsets {a,b,c},{j,h}\{a, b, c\}, \{j, h\} , and ” {a,c,d,f}\{a, c, d, f\} in the poset with the Hasse diagram shown below

*Least upper bound and greatest lower bound

Link copied

An element xx is called the least upper bound of the subset AA if xx is an upper bound that is less than every other upper bound of AA . Since there is only one such element, if it exists, it makes sense to call this element the least upper bound. That is, xx is the least upper bound of AA if axa \preceq x whenever aAa \in A , and xzx \preceq z whenever zz is an upper bound of AA . Similarly, the element yy is called the greatest lower bound of AA if yy is a lower bound of AA and zyz \preceq y whenever zz is a lower bound of AA . The greatest lower bound of AA is unique if it exists. The greatest lower bound and least upper bound of a subset AA are denoted by glb(A)glb(A) and lub(A)lub(A) , respectively.

Example 4.42.Link copied Find the greatest lower bound and the least upper bound of {b,d,g}\{b, d, g\} , if they exist, in the poset shown above.

Example 4.43.Link copied Find the greatest lower bound and the least upper bound of the sets {3,9,12}\{3, 9, 12\} and {1,2,4,5,10}\{1, 2, 4, 5, 10\} if they exist, in the poset (P,)(\mathbb{P}, \mid) .

Solution. An integer is a lower bound of {3,9,12}\{3, 9, 12\} if 3, 9, and 12 are divisible by this integer. The only such integers are 1 and 3. Since 131 \mid 3 , 3 is the greatest lower bound of {3,9,12}\{3, 9, 12\} . The only lower bound for the set {1,2,4,5,10} \{1, 2, 4, 5, 10\} with respect to \mid is the element 1. Hence, 1 is the greatest lower bound for {1,2,4,5,10}\{1, 2, 4, 5, 10\} .


Relational calculus

There are various operations that can be performed on relations to obtain a new relation.

Complement relation

Link copied

Let RR be a binary relation from AA to BB , so that RA×BR \subseteq A \times B . The complement relation is R=(A×B)RR' = (A \times B) \setminus R . In otherwords, a R ba~R~b if and only if a R ba~\cancel{R}'~b .

Example 4.44.Link copied The complement of the binary relation << on R\mathbb{R} is \geq .

The complement of the binary relation == on R\mathbb{R} is \neq .

Converse relation

Link copied

Let RR be a binary relation from AA to BB , so that RA×BR \subseteq A \times B . The converse relation is RB×AR' \subseteq B \times A defined by

R={(b,a)B×A:(a,b)R}R' = \{ (b,a) \in B \times A : (a,b) \in R \}
Example 4.45.Link copied The converse of the binary relation << on R\mathbb{R} is \geq .

The converse of the binary relation == on R\mathbb{R} is == .

Relational images and preimages

Link copied

If RR is a relation from AA to BB and we have CAC \subseteq A , DBD \subseteq B , then we define the relational image of CC under R,R, R(C)R(C) , by

R(C)={yB:xC(x R y)}R(C) = \{y\in B: \exists x\in C (x~R~y)\}

and we define the relational preimage of DD under RR by

R(D)={xA:yD(x R y)}.R^←(D) = \{x\in A: \exists y\in D (x~R~y)\}.

In the special case where the relation is a function f,f, we can rewrite these definitions as

f(C)={f(x):xC}f (C ) = \{ f (x) : x \in C \} f(D)={xA:f(x)D}.f^←(D) = \{x \in A : f(x) \in D \}.
Example 4.46.Link copied Let S={1,2,3,4}S = \{1, 2, 3, 4\} . Define a relation RR from SS to SS by letting x R yx~R~y mean x<y.x < y. Then find

a R({1,2})R(\{1,2\})

b R({3})R(\{3\})

c R({2,3})R^←(\{2,3\})

d R({4})R^←(\{4\})


Example 4.47.Link copied Consider the relation | on Z\mathbb{Z} , defined by a  ba~|~b \Leftrightarrow for some cZ,b=ac.c \in \mathbb{Z}, b=ac.

Find:

a R({12})R(\{12\})

b R({12})R^←(\{12\})

Solution. R({12})={,36,24,12,0,12,24,36, }R(\{12\}) = \{\dots, -36, -24, -12, 0, 12, 24, 36, ~\dots \}

R({12})={±1,±2,±3,±4,±6,±12}R^←(\{12\}) = \{ \pm1, \pm2, \pm3, \pm4, \pm6, \pm12 \}

Union and Intersection operations

Link copied

Let R1R_1 and R2R_2 be two binary relations on A×BA \times B . We define the union

R1R2={(a,b)A×B:(a,b)R1(a,b)R2}.R_1 \cup R_2 =\{ (a,b) \in A \times B : (a,b) \in R_1 \lor (a,b) \in R_2 \}.

Example 4.48.Link copied The union of the relations == and >> on R\mathbb{R} is \geq .

Let R1R_1 and R2R_2 be two binary relations on A×BA \times B . We define the intersection

R1R2={(a,b)A×B:(a,b)R1(a,b)R2}.R_1 \cap R_2 =\{ (a,b) \in A \times B : (a,b) \in R_1 \land (a,b) \in R_2 \}.

Example 4.49.Link copied The intersection of the relations \geq and \leq on R\mathbb{R} is == .

Functions

Let AA and BB be sets. Informally, a function ff from AA to BB is a rule that assigns, to each element xx of AA a unique element f(x)f(x) of BB , called the image of xx under ff .

Formally, a function is a special type of relation. A function from AA to BB is a binary relation ff from AA to BB such that for every xAx\in A there is exactly one yBy\in B such that (x,y)f(x,y)\in f . We never use infix notation for functions: instead, we use the notation we are already familiar with, by abbreviating (x,y)f(x,y)\in f as y=f(x)y=f(x) .

We indicate that ff is a function from AA to BB by writing f:ABf:A\to B . We call AA the domain of ff , denoted by Dom(f)\operatorname{Dom}(f) , and BB the codomain of ff . Note that not every element of BB has to be the image of some element of AA : the set of all such elements of BB is called the range or image of ff , in other words

Im(f)={y:for some xDom(f),y=f(x)}. \operatorname{Im}(f)= \{\, y: \text{for some} \ x\in\operatorname{Dom}(f), y=f(x)\}.
Example 4.50.Link copied Let XX be the set of all real numbers between 00 and 100100 inclusive, and let YY be the set of all real numbers between 3232 and 212212 inclusive. The function F:XYF:X \rightarrow Y that assigns to each Celsius temperature cc its corresponding Fahrenheit temperature F(c)F(c) is defined by F(c)=95c+32F(c) = \frac{9}{5}c + 32

What are the domain, codomain and image of FF ?

Equality of functions

We say the functions f ⁣:ABf\!:A \to B and g ⁣:CDg\!:C \to D are equal if

In other words, all three things making up the function must be the same.

The range of a function

Link copied

We define the range or image of f ⁣:ABf\!:A \to B as the set

Im(f)={f(a):aA}.\operatorname{Im}(f)= \{f(a) : a \in A\}.

This is the set of all values of ff taken (in BB ) by ff .

Example 4.51.Link copied
  • The negation function f ⁣:ZZf\!: \Z \to \Z (taking nn to n-n ) has range Z\Z itself.
  • The successor function S ⁣:NNS\!: \N \to \N (which takes nn to n+1n+1 ) has range N{0}={1,2,3,4,5,6,7,}\N \setminus \{0\} = \{1,2,3,4,5,6,7,\dots \} .
  • The squaring function f ⁣:ZZf\!: \Z \to \Z (which takes nn to n2n^2 ) has range {0,1,4,9,16,25,36,49,64,81,} \{0,1,4,9,16,25,36, 49,64,81,\dots \} .
  • The range of the sign function σ ⁣:ZZ\sigma\!:\Z \to \Z is {1,0,1}\{-1,0,1\} .

Function composition

Let f:ABf:A\to B and g:BCg:B\to C be functions. We define the composition gf:ACg\circ f:A\to C by declaring that, for every xAx\in A ,

(gf)(x)=g(f(x)).(g\circ f)(x)=g(f(x)).

Composition is associative

Link copied

If f:ABf:A\to B , g:BCg:B\to C and h:CDh:C\to D are functions then

h(gf)=(hg)f. h\circ(g\circ f)=(h\circ g)\circ f.

Proof Notice that h(gf)h\circ(g\circ f) and (hg)f(h\circ g)\circ f both have domain AA and codomain DD . For every xAx\in A we have

(h(gf))(x)(h\circ(g\circ f))(x)
=h(gf(x))=h(g\circ f(x))
=h(g(f(x)))=h(g(f(x)))
=hg(f(x))=h\circ g(f(x))
=((hg)f)(x)=((h\circ g)\circ f)(x)

So h(gf)h\circ(g\circ f) and (hg)f(h\circ g)\circ f have the same domain, and take the same values for every element of the domain, that is they are equal.


Partial functions

A partial function f ⁣:ABf\!:A \to B is a weaker form of a function, still having an input set AA and an output set or codomain BB , but with a rule ff that assigns to each element aa of a subset of AA a unique element f(a)f(a) of BB .

In other words, a partial function is defined for just some of the elements of its input set.

For example, take A=B=RA = B = \R and define f(x)=1/xf(x) = 1/x when xx is non-zero.

The domain of a partial function f ⁣:ABf\!:A \to B is the set of all aAa \in A for which f(a)f(a) is defined. Hence if DD is the domain of ff , then the restriction hh of ff to DD is a function h ⁣:DBh\! :D \to B .

The range of a partial function f ⁣:ABf\!:A \to B is still the set of values it takes, i.e. {f(a):aD}\{f(a) : a \in D\} , where DD is the domain.

A partial function f ⁣:ABf\!:A \to B is called a total function(or just a function) if its domain is A.A.

Equality of partial functions

Link copied

The partial functions f ⁣:ABf\!:A \to B and g ⁣:XYg\!:X \to Y are equal if


Types of functions

1-1 and onto

Link copied

We say that f:ABf:A\to B is 1-1 or injective if, for every x,yAx,y\in A with xyx\ne y we have f(x)f(y)f(x)\ne f(y) (or, equivalently, if f(x)=f(y)f(x)=f(y) implies that x=yx=y ).

We say that ff is onto or surjective if, for every yBy\in B there is some xAx\in A with f(x)=yf(x)=y (or, equivalently, if Im(f)=B\operatorname{Im}(f)=B ).

We say that ff is a correspondence or bijection if it is both 1-1 and onto.

Identity function, inverse function

Link copied

For any set AA , we define the identity function 1A:AA1_A:A\to A by declaring that, for every xAx\in A ,

1A(x)=x1_A(x)=x

Notice that 1A1_A is a bijection. If f:ABf:A\to B is a function then f1A=f=1Bff\circ1_A=f=1_B\circ f .

Warning: Be careful not to confuse the identity function 1A1_A with the constant function f(x)=1f(x) = 1 for all xAx \in A .

Let f:ABf:A\to B be a function. An inverse of ff is a function g:BAg:B\to A such that gf=1Ag\circ f=1_A and fg=1Bf\circ g=1_B .

Inverses are unique

Link copied

If ff has an inverse gg , then it is unique. To prove this, note that if hh is also an inverse of ff then

hh
=h1B=h\circ 1_B
=h(fg)=h\circ(f\circ g)
=(hf)g)=(h\circ f)\circ g)
=1Ag=1_A\circ g
=g=g

If ff has an inverse, it is denoted by f1f^{-1} .

Invertible functions are bijections

Link copied

Theorem 4.1 If f:ABf:A\to B is a function, then ff has an inverse if and only if ff is a bijection.

Proof: Suppose first that ff is a bijection. If yBy\in B then there is some xAx\in A with f(x)=yf(x)=y . Since ff is 1-1, this xx is unique. So we can define g:BAg:B\to A by


g(y)=the unique xA such thatf(x)=y.g(y)=\text{the unique} \ x\in A \text{ such that} f(x)=y.

For any xAx\in A we have g(f(x))=xg(f(x))=x , and for every yBy\in B we have f(g(y))=yf(g(y))=y . So g=f1g=f^{-1} .

Conversely, suppose that ff has an inverse. We must show ff is 1-1 and onto.

ff is 1-1 Suppose x,yAx,y\in A with f(x)=f(y)f(x)=f(y) . Then f1(f(x))=f1(f(y))f^{-1}(f(x))=f^{-1}(f(y)) , that is x=yx=y .

ff is onto Let yBy\in B . Put x=f1(y)x=f^{-1}(y) . Then y=f(x)y=f(x) .

So ff is a bijection, as required.


Example 4.52.Link copied Let ff be the function from {a,b,c}\{a,b,c\} to {1,2,3}\{1,2,3\} such that f(a)=2f(a)=2 , f(b)=3f(b)=3 , f(c)=1f(c)=1 . Is ff invertible? If it is, what is its inverse?

Example 4.53.Link copied Let ff be the function from Z\Z to Z\Z with f(x)=x2f(x) = x^{2} . Is ff invertible?

What about if we restrict it to a function from N\N to N\N ?

Example 4.54.Link copied Let ff be the function from Z\Z to Z\Z with f(x)=2xf(x) = 2x . Is ff invertible?

Solution. No. ff is not onto as Im(f)={x:x=2p,pZ,}Im(f) = \{ \, x:x=2p, p\in\Z, \} , and Im(f)=ZIm(f)= \subset\Z . So ff is not invertible.

Preimages

Link copied

If a function is not invertible all is not lost. We call the set of elements in the domain of a function f:STf:S\to T that are mapped to yTy\in T by ff the preimage of yy under ff . This is denoted by f(y)f^\leftarrow(y) .

f(y)={x:f(x)=y} f^\leftarrow(y)=\{x:f(x)=y\}

We can also consider the preimage of a set.

f(B)={x:f(x)B,BT}f^\leftarrow(B)=\{x:f(x)\in B, B \subseteq T\}
Example 4.54.Link copied Let ff be the function from Z\Z to Z\Z with f(x)=x2f(x) = x^{2} . What is the preimage of 4? What is the preimage of {4,9}\{4,9\} ?