Recursive Languages Tutorial Answers(1)
Recursive Languages Tutorial Answers(1)
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.
3
Recursive Languages
A language L is recursive if there exist a decision-
making DTM for L.
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.
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
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
<, Δ/Δ, 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
<, Δ/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.
16
Question 1 Answer
(a) L ⊆ Σ* such that L is context-free but not 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.
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.
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.
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