0% found this document useful (0 votes)
4 views

Recursive Languages Tutorial Answers(1)

The document discusses Turing acceptable languages, decision-making deterministic Turing machines (DTMs), and recursive languages, emphasizing that a language is recursive if a decision-making DTM exists for it. It also covers the undecidability of the halting problem and presents various questions and solutions related to constructing DTMs for specific languages. Additionally, it outlines results involving recursive languages and their properties, such as closure under union, intersection, and set difference.

Uploaded by

Naga
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)
4 views

Recursive Languages Tutorial Answers(1)

The document discusses Turing acceptable languages, decision-making deterministic Turing machines (DTMs), and recursive languages, emphasizing that a language is recursive if a decision-making DTM exists for it. It also covers the undecidability of the halting problem and presents various questions and solutions related to constructing DTMs for specific languages. Additionally, it outlines results involving recursive languages and their properties, such as closure under union, intersection, and set difference.

Uploaded by

Naga
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/ 22

Foundations of Computation

Practical Class on
Recursive Languages and Decidability

Irek Ulidowski

1
Turing Acceptable Languages
• A language L is Turing acceptable,
if there exists a DTM that halts on every s in L
(and does not halt otherwise).
What is left on the work tape?
• Cleaning the work tape:
For every DTM accepting L, there is a DTM
accepting L such that work tape is clean.
• We shall use two new special work tape
symbols Y and N.

2
Decision-making DTMs
A DTM for language L such that
• for every string in L,
the DTM halts with #Y on the work tape,
• for every string not in L,
the DTM halts with #N on the work tape,
is called a decision-making DTM.

Such DTMs never hang or loop.

3
Recursive Languages
A language L is recursive if there exist a decision-
making DTM for L.

Result: Every context-free language is recursive.

The converse is not true: think of 𝑎𝑛 𝑏 𝑛 𝑐 𝑛 .

4
Universal Turing Machine
A Turing machine U (U for universal) such that
• given the blueprint of any DTM M and
• given any input s on its input tape,
it simulates execution of M on input s is called
universal Turing machine.

The blueprint: encoding of M as a string µ (see Section 9.4).

U accepts (µ,s) iff M accepts s

C(omputer) translates (p,i) to o iff P translates I to O 5


(Un)decidability
A decision problem (or language L) is decidable
when there exists a DTM such that for each s on
input tape, it always halts with the right Y/N
answer on the work tape.

A decision problem (or language) in undecidable


if it is not decidable.

Given the definition of recursive languages, we


conclude that L is decidable iff L is recursive.
6
The Halting Problem
The halting problem is the problem of deciding
whether a given DTM will halt for a given input.

It is not decidable whether, for any DTM M and


any input s, M halts on s or not.

Proof of undecidability of the halting problem


• watch the halting problem video again,
• read Section 9.5 of the Notes.

Both use proof by contradiction technique. 7


Results involving Recursive Languages
Every recursive language is also Turing acceptable.

The converse is not true:

There are some Turing acceptable languages that


are not recursive (see Result 9.5.1 in Module Notes
based on the halting problem).

There are even languages which are not Turing


acceptable! 8
Undecidable problems
Most problems involving Turing machines are
undecidable: Is L(M) empty, or is L(M)=Σ*?

Many problems are still undecidable when


restricted to context-free languages: Is L(M)=Σ*?
But “is L(M) empty” is decidable. Also, α ϵ L(M) is
decidable.

For regular languages, most problems are


decidable: Is L(M)=Σ* is decidable.
9
Question Type 1
Given a language L, show that it is recursive:

Design a decision-making DTM that halts with a


Y on the work tape for all strings in L, and halts
with an N for all strings not in L.

Typically, creating accepting DTM as the first


step is easier… Then, convert it to decision-
making DTM.
10
Question 2: Construct a decision-making
Turing machine for anbn

First Step: accepting Turing machine for anbn


a, Δ/x, R, R b, x/x, R, L

a, Δ/x, R, R b, Δ/Δ, N, L
q0 q1 q2

<, Δ/Δ, N, N

q3 <, #/#, N, N

11
Question 2: Solution
a, Δ/x, R, R b, x/x, R, L

<, Δ/Δ, N, N
a, Δ/x, R, R b, Δ/Δ, N, L
q0 q1 q2

<, Δ/Y, N, N
b, Δ/N, N, N
<, Δ/Y, N, N <, #/#, N, R <, Δ/Δ, N, L

qh q5 q4 q3 <, #/#, N, R

<, Δ/Δ, N, L <, x/Δ, N, R


w, Δ/N, N, N
b, #/#, N, R
w, #/#, N, R w, Δ/Δ, N, L <, x/x, N, R
q8 q7 q6 a, x/x, N, R
a, #/#, N, R
w, x/Δ, N, L w, x/x, N, R

Note: For each w in {<,a,b}, there is a copy of the corresponding transition. 12


q_2: we have successfully matched n b’s with n a’s. we are the end of input (<) and we are at
# on the work tape. Next need to clean up n copies of x on the work tape. Go to q_3. There
Keep going right and replacing x with Δ. When finished (facing Δ/Δ on the work tape), go back
to the beginning of the work tape by going to the left (in q_4). Finally, move to q_5, write Y
on the first blank cell of the work tape to the right of #, and halt.

When a string over {a,b}* is not in the language, then is has one of six forms, and we make
the following transitions to states where we clean up the work tape and write N.
1. It starts with b: b, Δ/N, N, N
2. After some a’s there are no b’s: <, Δ/Δ, N, R
3. There are more b’s than a’s: b, #/#, N, R
4. There are more a’s than b’s: <, x/x, N, R
5. There are some a’s after the b’s as in point 4: a, x/x, N, R
6. There are some a’s after the a’s and b’s matched 4: a, #/#, N, R

q_6: go right until you pass all x’s saved on the work tape. Then replace them with Δ by going
left in q_7 until you reach #. Finally write N and halt.

Note that you could have written x/Δ instead of x/x in q_6, and then Δ/Δ instead of x/Δ in q_7.

13
Question 3: Construct a decision-making
Turing machine for anbncn
First, construct a Turing machine accepting the language:
a, Δ/x, R, R b, x/x, R, L c, x/x, R, R

a, Δ/x, R, R b, Δ/Δ, N, L c, #/#, N, R


q0 q1 q2 q2

<, Δ/Δ, N, N

q3 <, Δ/Δ, N, N

At q2: all letters read and matched, we are at RHS of the work tape
with n letters x to the left. 14
Question 3: Solution
a, Δ/x, R, R b, x/x, R, L c, x/x, R, R

a, Δ/x, R, R b, Δ/Δ, N, L c, #/#, N, R


q0 q1 q2 q3

<, Δ/Y, N, N
b, Δ/N, N, N <, x/Δ, N, L <, Δ/Δ, N, L
c, Δ/N, N, N
<, Δ/Y, N, N <, #/#, N, R
qh q5 q4

c, Δ/Δ, N, N
a, Δ/Δ, N, N
w, #/#, N, R w, Δ/Δ, N, L
q8 q7 q6 b, Δ/Δ, N, N
w, Δ/N, N, N
a, x/x, N, R
b, x/x, N, R
w, x/Δ, N, L w, x/x, N, R <, x/x, N, R
For each w in {<,a,b,c}, there is a copy of the corresponding transition;
Moreover, for each incorrect combination of input symbols from q1 and q2, there is
a transition to the cleaning part (starting from q6) which is not shown here due to
15
the lack of space.
Question 1
Let Σ = {a, b, c}. For each of the following, either give an example of a language L satisfying
the description (no proof required) or else explain briefly why no such language can exist.

(a) L ⊆ Σ∗ such that L is context-free but not Turing acceptable.


(b) L ⊆ Σ∗ such that L is not context-free but is Turing acceptable.
(c) L ⊆ Σ∗ such that L is Turing acceptable but not regular.
(d) L ⊆ Σ∗ such that L is recursive and Σ∗ − L is Turing acceptable.

16
Question 1 Answer
(a) L ⊆ Σ* such that L is context-free but not Turing acceptable.

False: Since any CF language is also recursive, we know that it is Turing


acceptable.

(b) L ⊆ Σ* such that L is not context-free but is Turing acceptable.

Turing acceptable but not CF language: anbncn

(c) L ⊆ Σ* such that L is Turing acceptable but not regular.

Same language as answer to (b) or anbn

(d) L ⊆ Σ*such that L is recursive and Σ∗ − L is Turing acceptable.

Since L is recursive, Σ*- L is also recursive by Result 9.3.2. So, by Result 9.3.1,
Σ*- L is also Turing acceptable
17
Questions 4, 5 and 6
Assume that languages L1 and L2 are recursive. Show that

4. L1 ∪ L2 is recursive;
5. L1 ꓵ L2 is recursive; and
6. L1 \ L2 is also recursive.

We can construct decision-making DTMs for L1 and L2.


We can then use these DTMs to construct new
decision-making DTMs for each of the three languages.

As an example, consider L1 ꓵ L2 of Question 5.

18
Questions 4, 5 and 6 Answers
A word α is in L1 ꓵ L2 if it is in L1 AND it is in L2. We have decision-making
DTMs M1 and M2 for L1 and L2 respectively, and they decide α. We construct
a new DTM by connecting the halt state h of M1 with the start state s of M2. There
will also be an additional state q between h and s, where we move
left on the input tape to the very beginning of the input string (doing nothing on work
tape). We transition from h to q if the working tape has Y on it (namely if we have
accepted α) replacing Y with Δ. If the tape has N instead of Y, we halt with N and
clearly do not move to q. When we reach s, the head of our new DTM points to the
first letter of α and the work tape is clean.

Consider an arbitrary string β. If β is accepted by M1, then we move to the start


state of M2 with head pointing at the first symbol of β. We then let M2 work on β.
If it halts with Y, we are done. If it fails to accept β, then we end up with N on the work
tape (because M2 would do that). If β is not accepted by M1, we halt and also end up
with N on the work tape (and never progress to M2 states).

19
Question 4 Answer
A word α is in L1 ∪ L2 if it is in L1 OR it is in L2. We have decision-making
DTMs M1 and M2 for L1 and L2 respectively, and they decide α. We construct
a new DTM by connecting the halt state h of M1 with the start state s of M2. There
will also be an additional state q between h and s, where we move
left on the input tape to the very beginning of the input string (doing nothing on work
tape). We transition from h to q if the working tape has N on it (namely if we have
not accepted α yet) replacing N with Δ. If the tape has Y instead of N, we halt with Y
and finish, and clearly there is no need to move to q. When we reach s, the head of
our new DTM points to the first letter of α and the work tape is clean.

Consider an arbitrary string β. If β is accepted by M1, then we halt and we are done.
If β is not accepted by M1, then we need to check if it can be accepted by M2. So,
we move to M2 with head pointing at the first symbol of β. We then let M2 work on β.
If it halts with Y, we are done. If it fails to accept β, then we end up with N on the work
tape (because M2 would do that).

20
Question 6 Answer
Since L1 and L2 are recursive, we can construct decision-making DTMs
for them. We can then use these DTMs to construct new decision-making
TMs for L1 \ L2 of Question 6.

A word α is in L1 \ L2 if it is in L1 AND it is NOT in L2. We have decision-making


DTMs M1 and M2 for L1 and L2 respectively, and they decide α. We construct
a new DTM by connecting the halt state h of M1 with the start state s of -M2
(explained below). There will also be an additional state q between h and s, where we
move left on the input tape to the very beginning of the input string (doing nothing
on work tape). We transition from h to q if the working tape has Y on it (namely
if we have accepted α with M1) replacing Y with Δ. If the tape has N instead of N,
we halt with N and finish: such α in not in L1\L2. Once α is accepted by M1, we want
α to be rejected by M2. So instead connecting M1 with M2, we connect M1 with
a decision-making DTM for Σ* \ L2, denoted by –M2, which can be obtained from M2
(use Result 9.3.2). When we reach s, the head of our new DTM points to the first letter
of α and the work tape is clean.

Consider an arbitrary string β. If β is accepted by M1, then we move to M2, which will
decide if β in not in L2. If β is not accepted by M1, then we are done.

21
Question 7, 8 and 9 Answers
Question 7: use the fact that every CF language is recursive and try to use Result 9.3.2

Question 8: Not true. You will be able to answer this question once you have read
carefully Section 9.5, and use Theorems 9.3.3 and 9.5.1.

Question 9: use the fact that every CF language is recursive, and then use the answer
to Question 4.

22

You might also like