LLM Data Types
LLM Data Types
4.1 Sets
Informally, a set is a bunch of objects, which are called the elements of the set.
The elements of a set can be just about anything: numbers, points in space, or even
other sets. The conventional way to write down a set is to list the elements inside
curly-braces. For example, here are some sets:
This works fine for small finite sets. Other sets might be defined by indicating how
to generate a list of them:
The order of elements is not significant, so fx; yg and fy; xg are the same set
written two different ways. Also, any object is, or is not, an element of a given set—
there is no notion of an element appearing more than once in a set.1 So, writing
fx; xg is just indicating the same thing twice: that x is in the set. In particular,
fx; xg D fxg.
The expression “e 2 S” asserts that e is an element of set S. For example,
32 2 D and blue 2 B, but Tailspin 62 A—yet.
Sets are simple, flexible, and everywhere. You’ll find some set mentioned in
nearly every section of this text.
1 It’s
not hard to develop a notion of multisets in which elements can occur more than once, but
multisets are not ordinary sets and are not covered in this text.
“mcs” — 2017/6/5 — 19:42 — page 98 — #106
Definition 4.1.1.
x 2A[B IFF x 2 A OR x 2 B:
So X [ Y D f1; 2; 3; 4g.
“mcs” — 2017/6/5 — 19:42 — page 99 — #107
4.1. Sets 99
Often all the sets being considered are subsets of a known domain of discourse
D. Then for any subset A of D, we define A to be the set of all elements of D not
in A. That is,
A WWD D A:
The set A is called the complement of A. So
A D ; IFF A D D:
For example, if the domain we’re working with is the integers, the complement
of the nonnegative integers is the set of negative integers:
NDZ :
A B is equivalent to A \ B D ;:
B 2 pow.A/ IFF B A:
For example, the elements of pow.f1; 2g/ are ;; f1g; f2g and f1; 2g.
More generally, if A has n elements, then there are 2n sets in pow.A/—see The-
orem 4.5.5. For this reason, some authors use the notation 2A instead of pow.A/.
“mcs” — 2017/6/5 — 19:42 — page 100 — #108
Theorem 4.1.2. [Distributive Law for Sets] Let A, B and C be sets. Then:
A \ .B [ C / D .A \ B/ [ .A \ C / (4.1)
z 2 A \ .B [ C / iff z 2 .A \ B/ [ .A \ C / (4.2)
z 2 A \ .B [ C /
iff .z 2 A/ AND .z 2 B [ C / (def of \)
iff .z 2 A/ AND .z 2 B OR z 2 C / (def of [)
iff .z 2 A AND z 2 B/ OR .z 2 A AND z 2 C / (AND distributivity (3.9))
iff .z 2 A \ B/ OR .z 2 A \ C / (def of \)
iff z 2 .A \ B/ [ .A \ C / (def of [)
The proof of Theorem 4.1.2 illustrates a general method for proving a set equality
involving the basic set operations by checking that a corresponding propositional
formula is valid. As a further example, from De Morgan’s Law (3.14) for proposi-
tions
NOT .P AND Q/ is equivalent to P OR Q
we can derive (Problem 4.5) a corresponding De Morgan’s Law for set equality:
A \ B D A [ B: (4.3)
Despite this correspondence between two kinds of operations, it’s important not
to confuse propositional operations with set operations. For example, if X and Y
are sets, then it is wrong to write “X AND Y ” instead of “X \ Y .” Applying AND
to sets will cause your compiler—or your grader—to throw a type error, because
an operation that is only supposed to be applied to truth values has been applied to
sets. Likewise, if P and Q are propositions, then it is a type error to write “P [ Q”
instead of “P OR Q.”
“mcs” — 2017/6/5 — 19:42 — page 102 — #110
4.2 Sequences
Sets provide one way to group a collection of objects. Another way is in a sequence,
which is a list of objects called its components, members, or elements. Short se-
quences are commonly described by listing the elements between parentheses; for
example, the sequence .a; b; c/ has three components. It would also be referred to
as a three element sequence or a sequence of length three. These phrases are all
synonyms—sequences are so basic that they appear everywhere and there are a lot
of ways to talk about them.
While both sets and sequences perform a gathering role, there are several differ-
ences.
Texts differ on notation for the empty sequence; we use for the empty
sequence.
The product operation is one link between sets and sequences. A Cartesian
product of sets, S1 S2 Sn , is a new set consisting of all sequences where
the first component is drawn from S1 , the second from S2 , and so forth. Length two
sequences are called pairs.3 For example, N fa; bg is the set of all pairs whose
first element is a nonnegative integer and whose second element is an a or a b:
N fa; bg D f.0; a/; .0; b/; .1; a/; .1; b/; .2; a/; .2; b/; : : :g
A product of n copies of a set S is denoted S n . For example, f0; 1g3 is the set of
all 3-bit sequences:
f0; 1g3 D f.0; 0; 0/; .0; 0; 1/; .0; 1; 0/; .0; 1; 1/; .1; 0; 0/; .1; 0; 1/; .1; 1; 0/; .1; 1; 1/g
3 Some texts call them ordered pairs.
“mcs” — 2017/6/5 — 19:42 — page 103 — #111
4.3 Functions
4.3.1 Domains and Images
A function assigns an element of one set, called the domain, to an element of an-
other set, called the codomain. The notation
f WA!B
indicates that f is a function with domain A and codomain B. The familiar notation
“f .a/ D b” indicates that f assigns the element b 2 B to a. Here b would be
called the value of f at argument a.
Functions are often defined by formulas, as in:
1
f1 .x/ WWD
x2
where x is a real-valued variable, or
P Q f4 .P; Q/
T T T
T F F
F T T
F F T
A function might also be defined by a procedure for computing its value at any
element of its domain, or by some other kind of specification. For example, define
“mcs” — 2017/6/5 — 19:42 — page 104 — #112
f5 .y/ to be the length of a left to right search of the bits in the binary string y until
a 1 appears, so
f5 .0010/ D 3;
f5 .100/ D 1;
f5 .0000/ is undefined:
Notice that f5 does not assign a value to any string of just 0’s. This illustrates
an important fact about functions: they need not assign a value to every element
in the domain. In fact this came up in our first example f1 .x/ D 1=x 2 , which
does not assign a value to 0. So in general, functions may be partial functions,
meaning that there may be domain elements for which the function is not defined.
The set of domain elements for which a function is defined is called the support of
the function. If a function assigns a value to every element of its domain, that is, its
support equals its domain, it is called a total function.
It’s often useful to find the set of values a function takes when applied to the
elements in a set of arguments. So if f W A ! B, and S is a subset of A, we define
f .S / to be the set of all the values that f takes when it is applied to elements of S .
That is,
f .S / WWD fb 2 B j f .s/ D b for some s 2 Sg:
For example, if we let Œr; s denote set of numbers in the interval from r to s on the
real line, then f1 .Œ1; 2/ D Œ1=4; 1.
For another example, let’s take the “search for a 1” function f5 . If we let X be
the set of binary words which start with an even number of 0’s followed by a 1,
then f5 .X / would be the odd nonnegative integers.
Applying f to a set S of arguments is referred to as “applying f pointwise to
S ”, and the set f .S / is referred to as the image of S under f .4 The set of values
that arise from applying f to all possible arguments is called the range of f . That
is,
range.f / WWD f .domain.f //:
Some authors refer to the codomain as the range of a function, but they shouldn’t.
The distinction between the range and codomain will be important later in Sec-
tions 4.5 when we relate sizes of sets to properties of functions between them.
4 There is a picky distinction between the function f which applies to elements of A and the
function which applies f pointwise to subsets of A, because the domain of f is A, while the domain
of pointwise-f is pow.A/. It is usually clear from context whether f or pointwise-f is meant, so
there is no harm in overloading the symbol f in this way.
“mcs” — 2017/6/5 — 19:42 — page 105 — #113
expressions like “m < n” or “m C n” are the usual notation used for things like the less-then relation
or the addition operation rather than prefix notation like “< .m; n/” or “C.m; n/.”
“mcs” — 2017/6/5 — 19:42 — page 106 — #114
Notice that Definition 4.4.1 is exactly the same as the definition in Section 4.3
of a function, except that it doesn’t require the functional condition that, for each
domain element a, there is at most one pair in the graph whose first coordinate is
a. As we said, a function is a special case of a binary relation.
The “in-charge of” relation Chrg for MIT in Spring ’10 subjects and instructors
is a handy example of a binary relation. Its domain Fac is the names of all the
MIT faculty and instructional staff, and its codomain is the set SubNums of subject
numbers in the Fall ’09–Spring ’10 MIT subject listing. The graph of Chrg contains
precisely the pairs of the form
.hinstructor-namei ; hsubject-numi/
such that the faculty member named hinstructor-namei is in charge of the subject
with number hsubject-numi that was offered in Spring ’10. So graph.Chrg/ con-
tains pairs like
.T. Eng; 6.UAT/
.G. Freeman; 6.011/
.G. Freeman; 6.UAT/
.G. Freeman; 6.881/
.G. Freeman; 6.882/
.J. Guttag; 6.00/
.A. R. Meyer; 6.042/ (4.4)
.A. R. Meyer; 18.062/
.A. R. Meyer; 6.844/
.T. Leighton; 6.042/
.T. Leighton; 18.062/
::
:
Some subjects in the codomain SubNums do not appear among this list of pairs—
that is, they are not in range.Chrg/. These are the Fall term-only subjects. Simi-
larly, there are instructors in the domain Fac who do not appear in the list because
they are not in charge of any Spring term subjects.
precisely when the corresponding elements are related by R. For example, here are
diagrams for two functions:
A B A B
a - 1 a - 1
b PP 2 b PP 2
PP
3 PP
3
c PP P
Pq
c Q P
Pq
3 3
PP 3
Q
Pq
d P 4 d QQ 4
QQ
e s
5
surjective when it has the Œ 1 arrows in property. That is, every point in
the right-hand, codomain column has at least one arrow pointing to it.
bijective when it has both the ŒD 1 arrow out and the ŒD 1 arrow in prop-
erty.
From here on, we’ll stop mentioning the arrows in these properties and for ex-
ample, just write Œ 1 in instead of Œ 1 arrows in.
So in the diagrams above, the relation on the left has the ŒD 1 out and Œ 1 in
properties, which means it is a total, surjective function. But it does not have the
Œ 1 in property because element 3 has two arrows going into it; it is not injective.
The relation on the right has the ŒD 1 out and Œ 1 in properties, which means
it is a total, injective function. But it does not have the Œ 1 in property because
element 4 has no arrow going into it; it is not surjective.
The arrows in a diagram for R correspond, of course, exactly to the pairs in the
graph of R. Notice that the arrows alone are not enough to determine, for example,
“mcs” — 2017/6/5 — 19:42 — page 108 — #116
if R has the Œ 1 out, total, property. If all we knew were the arrows, we wouldn’t
know about any points in the domain column that had no arrows out. In other
words, graph.R/ alone does not determine whether R is total: we also need to
know what domain.R/ is.
Example 4.4.3. The function defined by the formula 1=x 2 has the Œ 1 out prop-
erty if its domain is RC , but not if its domain is some set of real numbers including
0. It has the ŒD 1 in and ŒD 1 out property if its domain and codomain are both
RC , but it has neither the Œ 1 in nor the Œ 1 out property if its domain and
codomain are both R.
Definition 4.4.4. The image of a set Y under a relation R written R.Y /, is the set
of elements of the codomain B of R that are related to some element in Y . In terms
of the relation diagram, R.Y / is the set of points with an arrow coming in that starts
from some point in Y . The range range.R/ of R is the image R.A/ of the domain
A of R. That is, range.R/ is the set of all points in the codomain with an arrow
coming in.
For example, the set of subject numbers that Meyer is in charge of in Spring ’10
is exactly Chrg.A. Meyer/. To figure out what this is, we look for all the arrows
in the Chrg diagram that start at “A. Meyer,” and see which subject-numbers are
at the other end of these arrows. Looking at the list (4.4) of pairs in graph.Chrg/,
we see that these subject-numbers are f6.042, 18.062, 6.844g. Similarly, to find the
subject numbers that either Freeman or Eng are in charge of, we can collect all the
arrows that start at either “G. Freeman,” or “T. Eng” and, again, see which subject-
numbers are at the other end of these arrows. This is Chrg.fG. Freeman; T. Engg/.
Looking again at the list (4.4), we see that
Finally, Fac is the set of all in-charge instructors, so Chrg.Fac/ is the set of all the
subjects listed for Spring ’10.
In other words, R 1 is the relation you get by reversing the direction of the
arrows in the diagram of R.
Definition 4.4.6. The inverse image of a set X B under the relation R is defined
to be R 1 .X /, namely, the set of elements in A connected by an arrow to some
element in B. The support support.R/ is defined to R 1 .B/, namely, the set of
domain elements with at least one arrow out. The support of R is also called the
domain of definition of R.
Continuing with the in-charge example above, the set of instructors in charge
of 6.UAT in Spring ’10 is exactly the inverse image of f6.UATg under the Chrg
relation. From the list (4.4), we see that Eng and Freeman are both in charge of
6.UAT, that is,
1
fT. Eng; D. Freemang Chrg .f6.UATg/:
We can’t assert equality here because there may be additional pairs further down
the list showing that additional instructors are co-incharge of 6.UAT.
Now let Intro be the set of introductory course 6 subject numbers. These are the
subject numbers that start with “6.0.” So the set of names of the instructors who
were in-charge of introductory course 6 subjects in Spring ’10, is Chrg 1 .Intro/.
From the part of the Chrg list shown in (4.4), we see that Meyer, Leighton, Free-
man, and Guttag were among the instructors in charge of introductory subjects in
Spring ’10. That is,
1
fMeyer, Leighton, Freeman, Guttagg Chrg .Intro/:
Finally, Chrg 1 .SubNums/ is the set of all instructors who were in charge of a
subject listed for Spring ’10.
A finite set may have no elements (the empty set), or one element, or two ele-
ments,. . . , so the cardinality of finite sets is always a nonnegative integer.
“mcs” — 2017/6/5 — 19:42 — page 110 — #118
jAj #arrows:
If R is also surjective, then every element of B has an arrow into it, so there must
be at least as many arrows in the diagram as the size of B. That is,
#arrows jBj:
Lemma 4.5.3.1. has a converse: if the size of a finite set A is greater than or equal
to the size of another finite set B then it’s always possible to define a surjective
“mcs” — 2017/6/5 — 19:42 — page 111 — #119
function from A to B. In fact, the surjection can be a total function. To see how
this works, suppose for example that
A D fa0 ; a1 ; a2 ; a3 ; a4 ; a5 g
B D fb0 ; b1 ; b2 ; b3 g:
f .a0 / WWD b0 ; f .a1 / WWD b1 ; f .a2 / WWD b2 ; f .a3 / D f .a4 / D f .a5 / WWD b3 :
More concisely,
f .ai / WWD bmin.i;3/ ;
for 0 i 5. Since 5 3, this f is a surjection.
So we have figured out that if A and B are finite sets, then jAj jBj if and only if
A surj B. All told, this argument wraps up the proof of a theorem that summarizes
the whole finite cardinality story:
For example, the three-element set fa1 ; a2 ; a3 g has eight different subsets:
Theorem 4.5.5 follows from the fact that there is a simple bijection from subsets
of A to f0; 1gn , the n-bit sequences. Namely, let a1 ; a2 ; : : : ; an be the elements
of A. The bijection maps each subset of S A to the bit sequence .b1 ; : : : ; bn /
defined by the rule that
bi D 1 iff ai 2 S:
“mcs” — 2017/6/5 — 19:42 — page 112 — #120
For example, if n D 10, then the subset fa2 ; a3 ; a5 ; a7 ; a10 g maps to a 10-bit
sequence as follows:
subset: f a2 ; a 3 ; a5 ; a7 ; a10 g
sequence: . 0; 1; 1; 0; 1; 0; 1; 0; 0; 1 /
But every computer scientist knows6 that there are 2n n-bit sequences! So we’ve
proved Theorem 4.5.5!
Problem 4.2.
Express each of the following assertions about sets by a formula of set theory.7
Expressions may use abbreviations introduced earlier (so it is now legal to use “D”
because we just defined it).
(a) x D ;.
.x y AND x ¤ y/;
(e) x D y z.
(f) x D pow.y/.
S
(g) x D z2y z.
This means that y is supposed to be S S x is the union of all of
a collection of sets, and
them. A more concise notation for “ z2y z’ is simply “ y.”
Class Problems
Problem 4.3.
Set Formulas and Propositional Formulas.
(a) Verify that the propositional formula .P AND Q/ OR .P AND Q/ is equivalent
to P .
x 2 A IFF x 2 .A B/ [ .A \ B/
for all elements x using the equivalence of part (a) in a chain of IFF’s.
Problem 4.4.
Prove
A [ .B \ C / D .A [ B/ \ .A [ C / (4.8)
“mcs” — 2017/6/5 — 19:42 — page 114 — #122
x 2 A [ .B \ C / IFF x 2 .A [ B/ \ .A [ C /
for all elements x. You may assume the corresponding propositional equivalence 3.10.
Problem 4.5.
Prove De Morgan’s Law for set equality
A \ B D A [ B: (4.9)
by showing with a chain of IFF’s that x 2 the left-hand side of (4.9) iff x 2 the
right-hand side. You may assume the propositional version (3.14) of De Morgan’s
Law.
Problem 4.6.
Powerset Properties.
Let A and B be sets.
(a) Prove that
pow.A \ B/ D pow.A/ \ pow.B/:
Problem 4.7.
Subset take-away8 is a two player game played with a finite set A of numbers.
Players alternately choose nonempty subsets of A with the conditions that a player
may not choose
Homework Problems
Problem 4.8.
Let A, B and C be sets. Prove that
A [ B [ C D .A B/ [ .B C / [ .C A/ [ .A \ B \ C / (4.10)
Problem 4.9.
Union distributes over the intersection of two sets:
A [ .B \ C / D .A [ B/ \ .A [ C / (4.11)
A [ .B1 \ \ Bn 1 \ Bn /
D .A [ B1 / \ \ .A [ Bn 1/ \ .A [ Bn / (4.12)
Exam Problems
Problem 4.10.
You’ve seen how certain set identities follow from corresponding propositional
equivalences. For example, you proved by a chain of iff’s that
.A B/ [ .A \ B/ D A
using the fact that the propositional formula .P AND Q/ OR .P AND Q/ is equivalent
to P .
State a similar propositional equivalence that would justify the key step in a proof
for the following set equality organized as a chain of iff’s:
A B D A C [ .B \ C / [ A [ B \ C (4.13)
(You are not being asked to write out an iff-proof of the equality or to write out
a proof of the propositional equivalence. Just state the equivalence.)
Problem 4.11.
You’ve seen how certain set identities follow from corresponding propositional
equivalences. For example, you proved by a chain of iff’s that
.A B/ [ .A \ B/ D A
using the fact that the propositional formula .P AND Q/ OR .P AND Q/ is equivalent
to P .
State a similar propositional equivalence that would justify the key step in a proof
for the following set equality organized as a chain of iff’s:
A \ B \ C D A [ .B A/ [ C :
(You are not being asked to write out an iff-proof of the equality or to write out
a proof of the propositional equivalence. Just state the equivalence.)
Problem 4.12.
The set equation
A\B DA[B
follows from a certain equivalence between propositional formulas.
(a) What is the equivalence?
Problem 4.14. (a) Give a simple example where the following result fails, and
briefly explain why:
False Theorem. For sets A, B, C and D, let
L WWD .A [ B/ .C [ D/;
R WWD .A C / [ .B D/:
Then L D R.
(b) Identify the mistake in the following proof of the False Theorem.
Bogus proof. Since L and R are both sets of pairs, it’s sufficient to prove that
.x; y/ 2 L ! .x; y/ 2 R for all x; y.
The proof will be a chain of iff implications:
.x; y/ 2 R
iff .x; y/ 2 .A C / [ .B D/
iff .x; y/ 2 A C , or .x; y/ 2 B D
iff (x 2 A and y 2 C ) or else (x 2 B and y 2 D)
iff either x 2 A or x 2 B, and either y 2 C or y 2 D
iff x 2 A [ B and y 2 C [ D
iff .x; y/ 2 L.
Problem 4.16.
Describe a total injective function ŒD 1 out, Œ 1 in; from R ! R that is not a
bijection.
Problem 4.17.
For a binary relation R W A ! B, some properties of R can be determined from
just the arrows of R, that is, from graph.R/, and others require knowing if there
are elements in the domain A or the codomain B that don’t show up in graph.R/.
For each of the following possible properties of R, indicate whether it is always
determined by
1. graph.R/ alone,
2. graph.R/ and A alone,
3. graph.R/ and B alone,
“mcs” — 2017/6/5 — 19:42 — page 119 — #127
Properties:
(a) surjective
(b) injective
(c) total
(d) function
(e) bijection
Problem 4.18.
For each of the following real-valued functions on the real numbers, indicate whether
it is a bijection, a surjection but not a bijection, an injection but not a bijection, or
neither an injection nor a surjection.
(a) x ! x C 2
(b) x ! 2x
(c) x ! x 2
(d) x ! x 3
(e) x ! sin x
(f) x ! x sin x
(g) x ! e x
Problem 4.19.
Let f W A ! B and g W B ! C be functions and h W A ! C be their composition,
namely, h.a/ WWD g.f .a// for all a 2 A.
(a) Prove that if f and g are surjections, then so is h.
Problem 4.20.
Give an example of a relation R that is a total injective function from a set A to
itself but is not a bijection.
Class Problems
Problem 4.21. (a) Prove that if A surj B and B surj C , then A surj C .
(c) Conclude from (a) and (b) that if A inj B and B inj C , then A inj C .
(d) According to Definition 4.5.2, A inj B requires a total injective relation. Ex-
plain why A inj B iff there is a total injective function from A to B.
Problem 4.22.
Five basic properties of binary relations R W A ! B are:
1. R is a surjection Œ 1 in
2. R is an injection Œ 1 in
3. R is a function Œ 1 out
4. R is total Œ 1 out
5. R is empty ŒD 0 out
Below are some assertions about R. For each assertion, indicate all the properties
above that the relation R must have. For example, the first assertion impllies that R
is a total surjection. Variables a; a1 ; : : : range over A and b; b1 ; : : : range over B.
(a) 8a 8b: a R b.
(d) 8a 9b: a R b.
(e) 8b 9a: a R b.
(f) R is a bijection.
V
(g) 8a 9b1 a R b1 8b: a R b IMPLIES b D b1 .
“mcs” — 2017/6/5 — 19:42 — page 121 — #129
(h) 8a; b: a R b OR a ¤ b.
Problem 4.23.
Let R W A ! B be a binary relation. Each of the following formulas expresses
the fact that R has a familiar relational “arrow” property such as being surjective
or being a function.
Identify the relational property expressed by each of the following relational
expressions. Explain your reasoning.
(a) R ı R 1 IdB
(b) R 1 ı R IdA
(c) R 1 ı R IdA
(d) R ı R 1 IdB
Homework Problems
Problem 4.24.
Let f W A ! B and g W B ! C be functions.
(a) Prove that if the composition g ı f is a bijection, then f is a total injection
and g is a surjection.
(b) Show there is a total injection f and a bijection, g, such that g ı f is not a
bijection.
Problem 4.25.
Let A, B and C be nonempty sets, and let f W B ! C and g W A ! B be
functions. Let h WWD f ı g be the composition function of f and g, namely, the
function with domain A and codomain C such that h.x/ D f .g.x//.
(a) Prove that if h is surjective and f is total and injective, then g must be surjec-
tive.
“mcs” — 2017/6/5 — 19:42 — page 122 — #130
Hint: contradiction.
(b) Suppose that h is injective and f is total. Prove that g must be injective and
provide a counterexample showing how this claim could fail if f was not total.
Problem 4.26.
Let A, B and C be sets, and let f W B ! C and g W A ! B be functions. Let
h W A ! C be the composition f ı g; that is, h.x/ WWD f .g.x// for x 2 A. Prove
or disprove the following claims:
(a) If h is surjective, then f must be surjective.
(b) Give an example of a set S such that there is no total injective relation from S
to the real interval Œ0; 1.
Problem 4.28.
The language of sets and relations may seem remote from the practical world of
programming, but in fact there is a close connection to relational databases, a
very popular software application building block implemented by such software
packages as MySQL. This problem explores the connection by considering how to
manipulate and analyze a large data set using operators over sets and relations. Sys-
tems like MySQL are able to execute very similar high-level instructions efficiently
on standard computer hardware, which helps programmers focus on high-level de-
sign.
Consider a basic Web search engine, which stores information on Web pages and
processes queries to find pages satisfying conditions provided by users. At a high
level, we can formalize the key information as:
A binary relation L (for link) over pages, defined such that p1 L p2 iff page
p1 links to p2
A set E of endorsers, people who have recorded their opinions about which
pages are high-quality
Each part of this problem describes an intuitive, informal query over the data,
and your job is to produce a single expression using the standard set and relation
operators, such that the expression can be interpreted as answering the query cor-
rectly, for any data set. Your answers should use only the set and relation symbols
given above, in addition to terms standing for constant elements of E or W , plus
the following operators introduced in the text:
set union [.
“mcs” — 2017/6/5 — 19:42 — page 124 — #132
set intersection \.
set difference .
relational image—for example, R.A/ for some set A, or R.a/ for some spe-
cific element a.
relational inverse 1.
(b) The set of pages containing the word “set” that have been recommended by
“Meyer”
(c) The set of endorsers who have recommended pages containing the word “al-
gebra”
(d) The relation that relates endorser e and word w iff e has recommended a page
containing w
(e) The set of pages that have at least one incoming or outgoing link
(f) The relation that relates word w and page p iff w appears on a page that links
to p
(g) The relation that relates word w and endorser e iff w appears on a page that
links to a page that e recommends
(h) The relation that relates pages p1 and p2 iff p2 can be reached from p1 by
following a sequence of exactly 3 links
10 Note the reversal of R and S in the definition; this is to make relational composition work like
function composition. For functions, f ı g means you apply g first. That is, if we let h be f ı g,
then h.x/ D f .g.x//.
“mcs” — 2017/6/5 — 19:42 — page 125 — #133
Exam Problems
Problem 4.29.
Let A be the set containing the five sets: fag; fb; cg; fb; d g; fa; eg; fe; f g, and let
B be the set containing the three sets: fa; bg; fb; c; d g; fe; f g. Let R be the “is
subset of” binary relation from A to B defined by the rule:
XRY IFF X Y:
(a) Fill in the arrows so the following figure describes the graph of the relation,
R:
A arrows B
fag
fa; bg
fb; cg
fb; c; d g
fb; d g
fe; f g
fa; eg
fe; f g
Problem 4.30. (a) Five assertions about a binary relation R W A ! B are bulleted
below. There are nine predicate formulas that express some of these assertions.
Write the numbers of the formulas next to the assertions they express. For example,
you should write “4” next to the last assertion, since formula (4) expresses the
assertion that R is the identity relation.
Variables a; a1 ; : : : range over the domain A and b; b1 ; : : : range over the codomain
B. More than one formula may express one assertion.
R is a surjection
R is an injection
R is a function
R is total
R is the identity relation.
1. 8b: 9a: a R b.
2. 8a: 9b: a R b.
3. 8a: a R a.
4. 8a; b: a R b IFF a D b.
5. 8a; b: a R b OR a ¤ b.
6. 8b1 ; b2 ; a: .a R b1 AND a R b2 / IMPLIES b1 D b2 .
7. 8a1 ; a2 ; b: .a1 R b AND a2 R b/ IMPLIES a1 D a2 .
8. 8a1 ; a2 ; b1 ; b2 : .a1 R b1 AND a2 R b2 AND a1 ¤ a2 / IMPLIES b1 ¤ b2 .
9. 8a1 ; a2 ; b1 ; b2 : .a1 R b1 AND a2 R b2 AND b1 ¤ b2 / IMPLIES a1 ¤ a2 .
(b) Give an example of a relation R that satisfies three of the properties surjection,
injection, total, and function (you indicate which) but is not a bijection.
Problem 4.31.
Let f W D ! D be a total function from some nonempty set D to itself. In the
following propositions, x and y are variables ranging over D, and g is a variable
ranging over total functions from D to D. Indicate all of the propositions that are
equivalent to the proposition that f is an injection:
1. x D y OR f .x/ ¤ f .y/
6. NOTŒ9z8x.f .x/ ¤ z/
7. 9g8x.g.f .x// D x/
8. 9g8x.f .g.x// D x/
Problem 4.32.
Prove that if relation R W A ! B is a total injection, Œ 1 out; Œ 1 in, then
1
R ı R D IdA ;
Problem 4.33.
Let R W A ! B be a binary relation.
(a) Prove that R is a function iff R ı R 1 IdB .
Write similar containment formulas involving R 1 ıR, RıR 1 , Ida , IdB equivalent
to the assertion that R has each of the following properties. No proof is required.
(b) total.
(c) a surjection.
(d) a injection.
Problem 4.34.
Let R W A ! B and S W B ! C be binary relations such that S ı R is a bijection
and jAj D 2.
Give an example of such R; S where neither R nor S is a function. Indicate ex-
actly which properties—total, surjection, function, and injection—your examples
of R and S have.
Hint: Let jBj D 4.
“mcs” — 2017/6/5 — 19:42 — page 128 — #136
Problem 4.35.
The set f1; 2; 3g! consists of the infinite sequences of the digits 1,2, and 3, and
likewise f4; 5g! is the set of infinite sequences of the digits 4,5. For example
(b) Give an example of a bijection g W .f1; 2; 3g! f1; 2; 3g! / ! f1; 2; 3g! .
(c) Explain why there is a bijection between f1; 2; 3g! f1; 2; 3g! and f4; 5g! .
(You need not explicitly define the bijection.)
Class Problems
Problem 4.37.
Let A D fa0 ; a1 ; : : : ; an 1 g be a set of size n, and B D fb0 ; b1 ; : : : ; bm 1 g a set
of size m. Prove that jA Bj D mn by defining a simple bijection from A B to
the nonnegative integers from 0 to mn 1.
“mcs” — 2017/6/5 — 19:42 — page 129 — #137
Problem 4.38.
Let R W A ! B be a binary relation. Use an arrow counting argument to prove the
following generalization of the Mapping Rule 1.