CS 21 Decidability and Tractability Winter 2024
Posted: February 1
Solution Set 3
If you have not yet turned in the Problem Set, you should not consult these solutions.
Copyright By PowCoder代写 加微信 powcoder
A 2-NPDA is a 7-tuple (Q,Σ,Γ1,Γ2,δ,q0,F), where Q,Σ,Γ1,Γ2 and F are all finite sets, and
• Q is the set of states.
• Σ is the input alphabet.
• Γ1 is the alphabet of stack 1.
• Γ2 is the alphabet of stack 2.
• δ : Q×(Σ∪{ε})×(Γ1 ∪{ε})×(Γ2 ∪{ε}) → P(Q×(Γ1 ∪{ε})×(Γ2 ∪{ε})) is the
transition function.
• q0 ∈ Q is the start state.
• F ⊆Qisasetofacceptstates.
A 2-NPDA M = (Q,Σ,Γ1,Γ2,δ,q0,F) accepts string w ∈ Σ∗ if w can be written as w1,w2,…,wm ∈(Σ∪{ε})∗,
and there exist states and pairs of strings
r0,r1,…rm (s0,t0),(s1,t1),…,(sm,tm)∈(Γ1 ∪{ε})∗ ×(Γ2 ∪{ε})∗
• r0 = q0, and
• (s0,t0)=(ε,ε),and
• (ri+1,c,d) ∈ δ(ri,wi+1,a,b), where si = au and si+1 = cu for some u ∈ Γ∗1, and
ti = bv and ti+1 = dv for some v ∈ Γ∗2, and
(b) The 2-NPDA pushes “$” onto stack 1 and stack 2. The machine operates in three phases. In phase one, it reads 0 or more a’s from the tape, pushing an equal number of a’s onto stack 1. In phase two it reads 0 or more b’s from the tape, popping an a from stack 1 and pushing a b onto stack 2 for each b it reads from the tape. If it runs out of a’s to pop, it rejects. In phase three it reads 0 or more c’s from the tape, popping a b from stack 2 for each c it reads from the tape. If the machine enters phase three and there is not a “$” on stack 1, it rejects. If the machine runs out of b’s to pop from stack 2, it rejects. If the machine reaches the end of the string and there is not a “$” on stack 2, it rejects.
To prove the two types of machines are equivalent, we need to show that given any Turing Machine, we can construct an equivalent 2-NPDA, and vice-versa.
First we will simulate a Turing Machine with a 2-NPDA. The main idea is two use S1 (the first stack) to represent everything to the left of the Turing Machine head. Use S2 (the other stack) to represent the spot under the head and everything to its right. Given this representation, we can now simulate the operations of the Turing Machine. Reading is equivalent to popping from S2 and writing is equivalent to pushing the new symbol onto S2. Moving right is equivalent to popping from S2 and pushing the popped symbol onto S1. Moving left is simply the reverse operation of moving right.
There are some details we have to note here. First, we need to initialize the 2-NPDA. In the Turing Machine, the head begins at the start of the input string. In our 2-NPDA representation, this is the same as the input string residing in S2 with the start of the string at the top of the stack. To get this, we read the input string and push each symbol onto S1. Then we pop each symbol from S1 and push it onto S2 yielding the desired starting point and string orientation. We can now begin executing the simulated Turing Machine. Another point to note is that the Turing Machine can move over an arbitrary length of tape left or right of the input string. This could result in an empty stack after enough moves. So if during a move, a pop from a stack indicates an empty stack, we would push a blank symbol onto the other stack to maintain the head positioning.
Now we will show that given a 2-NPDA, we can construct an equivalent Turing Machine. From lecture we know that multi-tape (nondeterministic) Turing Machines are equivalent to single tape Turing Machines. Therefore, we can construct a 3-tape nondeterministic Turing Machine, where the input tape is identical to the 2-NPDA input tape, and the two work tapes simulate the two stacks of the 2-NPDA. Call the tapes in the Turing Machine T0, T1, T2, and the stacks in the 2-NPDA S1 and S2. Write a special symbol on each of the work tapes to simulate the bottom of the 2-NPDA stacks. To simulate pushing a onto S1 we move right in T1 and then write a. To simulate pushing a onto S2 we move right in T2 and then write a. To pop from S1 read from T1 and move left. If the read yields the special symbol, then we have reached the bottom of the stack so we do not move left. Popping from S2 is identical. With this construction, we have simulated the use of the two stacks of the 2-NPDA, so can fully simulate execution of the 2-NPDA. Importantly, the simulating machine is nondeterministic, so each of the several possible “next step” of the 2-NPDA is correctly simulated (in separated nondeterministic computation paths) by the TM using its nondeterminism.
A Queue Automaton is a 6-tuple (Q,Σ,Γ,δ,q0,F), where Q,Σ,Γ and F are all finite sets, and
• Q is the set of states.
• Σ is the input alphabet.
• Γ is the queue alphabet.
• δ:Q×(Σ∪{ε})×(Γ∪{ε})→P(Q×(Γ∪{ε}))isthetransitionfunction. • q0 ∈ Q is the start state.
• F ⊆Qisasetofacceptstates.
A Queue Autmomaton M = (Q,Σ,Γ1,Γ2,δ,q0,F) accepts string w ∈ Σ∗ if w can be written as
and there exist states
and strings
• r0 = q0, and
w1,w2,…,wm ∈(Σ∪{ε})∗, r0,r1,…rm s0,s1,…,sm ∈(Γ∪{ε})∗
• s0 = ε, and
• (ri+1,c) ∈ δ(ri,wi+1,a), where si = au and si+1 = uc for some u ∈ Γ∗1, • rm ∈F.
(b) First, we show how to simulate a Turing Machine with a Queue Automaton (QA). Our queue will contain the contents of the Turing Machine tape at all times, with the symbol currently being read at the head of the queue. We will use “$” to mark the beginning of the tape. Thus at all times the queue looks like:
head of queue → ax$y ← tail of queue,
where a ∈ Σ is the symbol currently under the head of the Turing Machine, x ∈ Σ∗ is the contents of the tape to the right of the head, and y ∈ Σ∗ is the contents of the tape to the left of the head.
We will describe a queue “primitive” that we will use in simulating the TM.
Cyclically shift right. We perform this operation is three phases. We will keep a running example to illustrate. Suppose we start out with queue contents
In Phase 1 we place a # marker at the end of the queue, and then replace each queue symbol x with a new symbol (w,x), where w is the symbol immediately to x’s left in the queue. For this we use a special set of separate states that “remember” the last symbol shifted. That is, for each w ∈ Σ, after having shifted symbol w, we are in a special state qw. Then when we encounter the next symbol x, we enqueue not x, but the new symbol (w,x). To start the process we enqueue # and move to state q#. We then repeat the following: From a given state qw, dequeue a symbol x, enqueue the new symbol (w,x), and move to state qx. When we dequeue # and enqueue the final new symbol we complete Phase 1. In our example the queue will now look like this:
(#, a)(a, b)(b, $)($, c)(c, #)
In Phase 2, we repeat the following: dequeue (w,x), enqueue (w,x) until we dequeue (w, x) where x = #. We then enqueue #, enqueue w, and dequeue whatever symbol is at the head of the queue. In our example the queue will now look like this:
(a, b)(b, $)($, c)#c
In Phase 3, we repeatedly dequeue (w, x) and enqueue w, until we dequeue #, at which point we complete Phase 3. In our example the queue will now look like this:
which is our original queue cyclically shifted right one step.
Now to simulate a given step of the Turing Machine, we dequeue the symbol a at the head of the queue and then:
• if the TM transition that would be taken on reading a writes symbol b and moves right, then our QA enqueues b at the tail of the queue.
• if the TM transition that would be taken on reading a writes symbol b and moves left, then our QA enqueues b and then performs two cyclic shifts to the right.
At all points, the following sequence of transitions are available to the QA: dequeue $, enqueue −$ and perform 2 cyclic shifts to the right. This amounts to adding a blank “−” at the end of the tape. As with 2-NPDAs, we initialize the QA by copying the contents of the input into the queue, followed by a $.
Finally, we need to show how to simulate a QA with TM. Since 2-tape TM is equivalent to a single tape TM, as shown in lecture, it is sufficient to show how to simulate a QA with a 2-tape TM. The first tape will simply contain the input string, and the second tape will contain the queue. The tape alphabet of the QA contains special symbol $ that denotes the beginning of the queue. At first, one $ is written on the tape corresponding to the queue. When a symbol is pushed onto the queue, the head finds the first blank space on the tape and writes the symbol there. When a symbol is popped, the tape finds the first symbol on the tape other than $, reads the symbol and substitutes the symbol with $. The queue shifts on the tape to the right as the TM pops, but this is acceptable since the tape is infinite.
3. Suppose we have a language expressible as:
L = {x : there exists y for which (x,y) ∈ R},
where R is decidable. Then L is RE, because given an input x, we can simply enumerate all y’s in lexicographic order, and for each one decide whether (x, y) ∈ R. If the answer is ever “yes” then we accept x; otherwise, we will continue on forever. Clearly the language accepted is exactly L.
In the other direction, suppose we have a RE language L. Fix an enumerater E for L. That is, E is a machine that writes a (potentially infinite) sequence of strings on its tape with the guarantee that the set of these strings is exactly L. Define R as follows (y is treated as an integer):
R = {(x, y) : x is output within the first y steps of E’s execution}.
Clearly R is decidable, because we can just simulate machine E for y steps to decide whether (x,y) ∈ R. Also, it is clear that L is exactly the set of x for which there exists some y for which (x, y) ∈ R – this is just another way of saying that a string x is in language L iff it is eventually output by the enumerater E.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com