Massachusetts Institute of Technology
6.042J/18.062J, Spring ’10
: Mathematics for Computer Science
February 19
Prof. Albert R. Meyer
revised February 19, 2010, 1400 minutes
Solutions to In-Class Problems Week 3, Fri.
Problem 1.
Let’s refer to a programming procedure (written in your favorite programming language —C++,
or Java, or Python, .
. . ) as a
string
procedure
when it is applicable to data of type
string
and only
returns values of type
boolean
. When a string procedure,
P
, applied to a
string
,
s
, returns
True
, we’ll say that
P
recognizes
s
. If
R
is the set of strings that
P
recognizes, we’ll call
P
a
recognizer
for
R
.
(a)
Describe how a recognizer would work for the set of strings containing only lower case Ro-
man letter —
a,b,.
..,z
—such that each letter occurs twice in a row. For example,
aaccaabbzz
,
is such a string, but
abb
,
00bb
,
AAbb
, and
a
are not. (Even better, actually write a recognizer pro-
cedure in your favorite programming language).
Solution.
All the standard programming languages have built-in operations for scanning the
characters in a string. So simply write a procedure that checks an input string left to right, verify-
ing that successive pairs of characters in the string are duplicated, lowercase roman characters.
ACTUAL PROGRAM TBA
A set of
string
s is called
recognizable
if there is a recognizer procedure for it.
When you actually program a procedure, you have to type the program text into a computer
system. This means that every procedure is described by some
string
of typed characters. If a
string
,
s
, is actually the typed description of some string procedure, let’s refer to that procedure
as
P
s
. You can think of
P
s
as the result of compiling
s
.
1
In fact, it will be helpful to associate every string,
s
, with a procedure,
P
s
; we can do this by
deﬁning
P
s
to be some ﬁxed string procedure —it doesn’t matter which one —whenever
s
is not
the typed description of an actual procedure that can be applied to
string
s. The result of this
is that we have now deﬁned a total function,
f
, mapping every
string
,
s
, to the set,
f
(
s
)
, of
string
s recognized by
P
s
. That is we have a total function,
f
:
string
→ P
(
string
)
.
(1)
(b)
Explain why the actual range of
f
is the set of all recognizable sets of strings.
Creative Commons
2010,
Prof. Albert R. Meyer
.
1