CS250 at CCUT Week 2: Relations

Introduction to Relations and Functions

Let A={a1,a2,...,ak}A = \{a_1, a_2, ..., a_k\} and B={b1,b2,...,bm}B = \{b_1, b_2, ..., b_m\}

Recall that a Cartesian product A×BA \times B is defined by a set of pairs {(a1,b1),(a1,b2),...,(a1,bm),...,(ak,bm)}\{(a_1, b_1), (a_1, b_2), ..., (a_1, b_m), ..., (a_k, b_m)\}.

A Cartesian product defines a product set, or a set of all ordered arrangements of elements in sets in the Cartesian product.

Binary relations:

If A={1,2}A = \{1, 2\} and B={a,b,c}B = \{a, b, c\}, then:

A×B={1,a,1,b,1,c,2,a,2,b,2,c}A \times B = \{\langle 1, a \rangle, \langle 1, b \rangle, \langle 1, c \rangle, \langle 2, a \rangle, \langle 2, b \rangle, \langle 2, c \rangle\}

A binary relation RR from AA to BB is a subset of A×BA \times B
If a,bR\langle a, b \rangle \in R, then we can write RabRab or aRbaRb.
The former is typically preferred, since it allows us an easy convention for notating relationships with >2 relata, e.g. RabcRabc, and to notate the negation ¬Rab\neg Rab, using our logical vocabulary.

The inverse relation R1R^{-1} is the relation from BB to AA which consists of the ordered pairs, which, when reversed, belong to RR. In symbolic notation: R1={b,aa,bR}R^{-1} = \{\langle b, a \rangle | \langle a, b \rangle \in R\}


  1. Relations can be depicted by graphs. Draw a graph for the following relation RR.
    R={1,2,2,2,2,4,3,2,3,4,4,1,4,3}R = \{\langle 1, 2 \rangle, \langle 2, 2 \rangle, \langle 2, 4 \rangle, \langle 3, 2 \rangle, \langle 3, 4 \rangle, \langle 4, 1\rangle, \langle 4, 3 \rangle \}

  1. What does the inverse R1R^{-1} look like?

  1. Relations can also be represented as a table or two dimensional array. What would that look like? Construct one for RR.

Relation Composition or product:
Suppose that we have three sets AA, BB, and CC, a relation RR defined from AA to BB, and a relation SS defined from BB to CC. We can define a composition of RR and SS, written (RS)(R | S) (but sometimes SRS \circ R), as follows. If aa is an element of AA and cc is an element of CC, then (RS)ac(R | S)ac iff there exists some element bb in BB such that RabRab and SbcSbc. So we have a relation RSR|S from aa to cc iff aa is RR related to bb and bb is SS related to cc.

  1. Let AA = {1, 2, 3, 4}, RR = {(1, 2), (1, 2), (2, 4), (3, 2)} ----- using () as angle brackets
    and SS = {(1, 4), (1, 3), (2, 3), (3, 1), (4, 1)}
    Find RSR|S.

Relations have many interesting properties. Some that we're interested in include: reflexivity, symmetry, antisymmetry, transitivity, equivalence, and partial and total order.


Relationship Properties

Let's come up with examples for each.


  1. Construct or name an example for each property.

  2. Consider the following relations on the set AA = {1, 2, 3}.
    RR = {(1, 1), (1, 2), (1, 3), (3, 3)}
    SS = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3)}
    TT = {(1, 1), (1, 2), (2, 2), (2, 3)}
    \emptyset = empty relation
    A×AA \times A = universal relation on AA

Determine whether or not each of the relations is (a) reflexive, (b) symmetric, (c) transitive, and (d) antisymmetric.

  1. Consider the following relations:

    1. Relation \leq (less than or equal) on the set Z\mathbb{Z} of integers.
    2. Set inclusion \subseteq on a collection CC of sets.
    3. Relation \perp (perpendicular) on the set LL of lines in the plane.
    4. Relation \parallel (parallel) on the set LL of lines in the plane.
    5. Relation \mid of divisibility on the set N\mathbb{N} of positive integers. (Recall xyx \mid y if there exists zz such that xz=yxz = y.)

Which of the relations are reflexive.

Which of these are symmetric?

Which are transitive and which not?

  1. Consider the following relations on the set A = {1, 2, 3, 4}:
    1. R1={(1,1),(1,2),(2,3),(1,3),(4,4)}R1 = \{(1, 1), (1, 2), (2, 3), (1, 3), (4, 4)\}
    2. R2={(1,1)(1,2),(2,1),(2,2),(3,3),(4,4)}R2 = \{(1, 1)(1, 2), (2, 1), (2, 2), (3, 3), (4, 4)\}
    3. R3={(1,3),(2,1)}R3 = \{(1, 3), (2, 1)\}
    4. R4=R4 = \varnothing, the empty relation
    5. R5=A×AR5 = A \times A, the universal relation

Which of the relations are reflexive.

Which of these are symmetric?


Functions Examples and Exercises

Some definitions first.

Functions are ordinarily denoted by symbols. Suppose that for each element of a set AA, the domain, we assign a unique element of a set BB, the codomain. The collection of these assignments is called a function from AA to BB. Let ff denote that function. We write:

f:ABf: A \to B

We can also say that ff maps AA to BB.

Functions are often expressed by means of a mathematical formula. For example, consider the function which maps each real number to its square. We can denote this function by writing

In the first notation, xx is called a variable or argument and the letter ff denotes the function.
In the second, the barred arrow \mapsto is read "goes to" or "maps to". (The LaTeX command is \mapsto).
In the last, xx is called the independent variable and yy is called the dependent variable since the value of yy depends on the value of xx.

Exercises:
Find the domain DD of each of the following real-valued functions of a real variable:

(a) f(x)=1x2f(x) = \frac{1}{x-2}

(b) f(x)=x23x4f(x) = x^2 - 3x - 4

(c) f(x)=25x2f(x) = \sqrt{25-x^2}

Functions as Relations

Every function f:ABf: A \to B defines a relation from AA to BB called the graph of ff

Graph of f={a,baA,f(a)=bB}f = \{\langle a, b \rangle | a \in A,f(a) = b \in B\}

Two functions f:ABf: A \to B and g:ABg: A \to B are equal if for every aAa \in A, f(a)=g(a)f(a) = g(a), i.e. they have the same graph.

Exercise: Map the function f(x)=x22x3f(x) = x^2 - 2x - 3

Classes of Functions

A function is injective (one-to-one) if each element of the codomain is mapped to by at most one element of the domain.
That is, for all x,xAx, x' \in A, f(x)=f(x)x=xf(x) = f(x') \to x = x'

A function is surjective (onto) if each element of the codomain is mapped to by at least one element of the domain.
That is, for all yBy \in B, there exists an xAx \in A such that f(x)=yf(x) = y

A function is bijective (one-to-one and onto or one-to-one correspondence) if each element of the codomain is mapped to by exactly one element of the domain.

Exercises:

  1. Consider functions f:ABf: A \to B and g:BCg: B \to C.

Prove the following:
(a) if ff and gg are injective (one-to-one), then the composition function gfg \circ f is injective (one-to-one)$.

Proof:

Suppose (gf)(x)=(gf)(y)(g \circ f)(x) = (g \circ f)(y), then g(f(x))=g(f(y))g(f(x)) = g(f(y)). So f(x)=f(y)f(x) = f(y) because gg is injective. Further, x=yx = y since ff is injective. Thus, gfg \circ f is injective.

(b) if ff and gg are surjective (onto) functions, then gfg \circ f is an surjective (onto) function.

Proof:

Let cc be an arbitrary element of CC. Since gg is surjective, there exists a bBb \in B such that g(b)=cg(b) = c. Since ff is surjective, there exists an aAa \in A such that f(a)=bf(a) = b. But also (gf)(a)=g(f(a))=g(b)=c(g \circ f)(a) = g(f(a)) = g(b) = c. Hence, each cCc \in C is the mapping of some element aAa \in A. Therefore, gfg \circ f is a surjective function.

  1. Determine if each function is injective (one-to-one):
    (c) To each person on the earth, assign the number which corresponds to her or his age.
    (d) To each country in the world, assign the latitude and longitude of its capital.
    (e) To each book written by only one author, assign the author.
    (f) To each country in the world which has a prime minister, assign its prime minister.
Answers: no, yes, no, yes
  1. Problem: Show that if ff is bijective, an inverse gg of ff exists. (define such a gg show that it is a function, and show that it is an inverse of ff.)
Proof:

Let f:ABf: A \to B be bijective. We'll define a function g:ABg: A \to B = f1f^{-1} as follows. Let bBb \in B. since ff is surjective, there exists aAa \in A such that f(a)=bf(a) = b. Let g(b)=ag(b) = a. Since ff is injective, this aa is unique, so gg is a well-defined function.

Next, we show that gg is the inverse of ff. First, we show that gf=idAg \circ f = id_A.
First, let aAa \in A. Let b=f(a)b = f(a). Then by definition g(b)=ag(b) = a. then gf(a)=g(f(a))=g(b)=ag \circ f(a) = g(f(a)) = g(b) = a.
Second, show that fg=idBf \circ g = id_B. Let bBb \in B and f1(b)=g(b)=af^{-1}(b) = g(b) = a. By definition, f(a)=bf(a) = b. It follows that fg(b)=f(g(b))=f(a)=bf \circ g(b) = f(g(b)) = f(a) = b.