2nd Exercise Sheet: Theoretical Computer Science
2nd Exercise Sheet: Theoretical Computer Science
¨
Task 1 (decidability). Show that the following language over ÿ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
is decidable:
L = {w ÿ ÿ + un ÿ| ÿn
ÿ +.ÿ w
N.ÿu1,
= u1u2
. . . ., . un ÿ (u1 + u2 + . . . + un) = 1000}.
(2 points)
1
Machine Translated by Google
¨ ÿ
Task 2 (regular languages). Let ÿ be an alphabet. Show that for all languages L, M ÿ ÿ applies:
(a) (L + M) ÿ = (L ÿMÿ ) ÿ ,
(b) M ÿ L ÿ M ÿÿ ÿ ÿ L ÿ M = ÿ ie M is a subset ,of L ÿ M if and only if L contains the empty word or M is the empty language.
(c) If ÿ is single-element, L ÿ M = M ÿ L.
1
(a) L = L = L ÿ{ÿ}ÿ ÿ L ÿMÿ L =L ÿ
nnÿN and analogously M ÿ Mÿ ÿ L ÿMÿ (L ÿMÿ ), from which (L + M) ÿ ÿ (L ÿMÿ ) , thus (L + M) ÿ
ÿ follows.
ÿ
Conversely, L ÿ (L + M) ÿ and Mÿ ÿ (L + M) ÿ and therefore also L ÿMÿ ÿ (L + M) ÿ (L + M) ÿ ÿ (L + M) ÿ . From this we
conclude: (L ÿMÿ ) ÿ ÿ (L + M) ÿÿ = (L + M) ÿ .
(b) Let M ÿ LÿM and M ÿ= ÿ. Then there is a word w of minimal length in M. From the assumption it follows that w ÿ L ÿ M, so
there are u ÿ L and v ÿ M with w = u ÿ v. Since w and v are in M and w has minimal length, u must have length 0, so u =
ÿ. The converse is trivial: From ÿ ÿ L it follows that M = {ÿ} ÿ M ÿ L ÿ M, and from M = ÿ it follows that M = ÿ ÿ L ÿ M.
(c) If ÿ is single-element, i.e. ÿ = {a}, then ÿÿ = {a n | n ÿ N}, so every word is of the form a n. Let ÿ L, v = a ÿ M ÿL.
k+r r+k ÿ M, so w = a k
w = LÿM, then w = uv with u = a
k r
=a =a r
ÿa
(2+2+1=5 points)
Task 3 (regular expressions). Show, by transformations, that the following equation holds for regular expressions:
¨
ÿ
(e(g + f) + g) ÿ = (eg + ef + g) = ((ef) (Distributive law) (+ is
+ (eg + g))ÿ = ((ef) = associative and commutative)
ÿ ÿ ÿ
((ef) = (eg + g) ) ((r+s)*=(r*s*)*)
ÿ ÿ ÿ
((ef) ((e + ÿ)g) ) (distributive law) (e+ÿ
ÿ ÿ ÿ
(e?g) ) = e?)
(3 points)
2
Machine Translated byÿ Google
b) L2 = {w ÿ | the number of a's in w is odd}, bmc n | k + m + n
k
c) L3 = {w = a even}.
(3 points)
Task 4
¨
a) Determine the regular expression over the alphabet ÿ = { { , } , := , ; , digit , letter } to
the following syntax diagram:
{ letter := digit }
¨
b) Create a syntax diagram for the following expression over the alphabet ÿ = {d, e, f, p, s}: d +pdÿ (esd+)?f? + pd+
(3 points)
r = {(letter+ := digit+( ; letter+ := digit+) ÿ )?}
1
(3 points)
¨
Task 5 (regular expression). You have forgotten a telephone number. Luckily you have a telephone book to
look for the number in. The number belongs to your friend Hanna Maier – or was it Hannah Meyer? You are
no longer sure whether Hanna was written with or without an h at the
¨ end and Meier with e or a and i or y.
Luckily you remember that the number did not end in 0, 3 or 7.
¨
Create a regular expression to search for the phone number and check it against the file Telefonbuch.txt, which you can find on Ilias.
You are free to use notepad++, egrep, Word, OpenOffice, python, java or scala to solve this task.
Please note the different formatting options for telephone numbers. If necessary,
demonstrate your correct solution with a screenshot that at least shows which system you used, which regular
expression was used, and the result.
3
Machine Translated by Google
(3 points)