0% found this document useful (0 votes)
13 views4 pages

2nd Exercise Sheet: Theoretical Computer Science

The document is an exercise sheet for a Theoretical Computer Science course at Philipps University of Marburg for the winter semester 2024/25. It includes tasks on decidability, regular languages, regular expressions, syntax diagrams, and creating a regular expression for searching a telephone number. Each task has specific requirements and examples to illustrate the concepts being taught.

Uploaded by

hamidrz1372
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

2nd Exercise Sheet: Theoretical Computer Science

The document is an exercise sheet for a Theoretical Computer Science course at Philipps University of Marburg for the winter semester 2024/25. It includes tasks on decidability, regular languages, regular expressions, syntax diagrams, and creating a regular expression for searching a telephone number. Each task has specific requirements and examples to illustrate the concepts being taught.

Uploaded by

hamidrz1372
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Machine Translated by Google

Theoretical Computer Science Prof. Dr. H. Peter Gumm


winter semester 2024/25 Philipps University of Marburg
¨
2nd exercise sheet

Deadline: Saturday, November 2, 2024 until 10 p.m. via Ilias.

¨
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}.

Example: 16103928128358717334 ÿ L, because the decomposition 16|103|9|28|128|358|7|17|334 yields 16 + 103 +


9 + 28 + 128 + 358 + 7 + 17 + 334 = 1000, but e.g. 425672892 ÿ/ L.

The following algorithm A decides the language L:


Let w ÿ ÿ ÿ
= {0, 1, . . . , 9} ÿ . A(w) decomposes w into nonempty segments u1, ...,
¨ un, such that w = u1u2 . . . un.
Since every ui ÿ= ÿ, there are only finitely many such decompositions. For each decomposition, define ui as
¨
Count (ui)10 and¨ check whether ( u1)10 + . . . + (un)10 = 1000. If this happens once, give ” true"
if there is no decomposition for, give If you feel like it, ” false".
you can also program this algorithm (Here is a solution in Scala):

(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) ÿ ÿ ((ef) ÿ (e?g) ÿ ) ÿ

ÿ
(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)

Task 4 (Syntax diagrams).


¨
Determine the regular expression over the alphabet ÿ = {{, }, :=, ;, digit,letter} for the following syntax diagram:

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+

(esd+)?f? + d +esd+f? + d +(esd+)?f.

(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)

You might also like