exactly the languages accepted by PDA by empty stack. This is done by establishing the following two claims.
⋄ If a PDA accepts strings using final state acceptance then we can construct a corresponding equivalent PDA that accepts the same strings using empty stack acceptance criterion.
⋄ If a PDA accepts strings using empty stack, then we can construct a corresponding PDA that accepts the strings using a final state.
3.2.1 PDA construction for acceptance by empty stack
Theorem 3.2.1 (H&U Theorem 5.1) IfLisL(M2)for some PDAM2, thenLisN(M1) for some PDA,M1.
Proof LetM2 = (Q,Σ,Γ, δ, q0, m, Z0, F) be a PDA such thatL=L(M2). We defineM1 as follows. LetM1= (Q∪qe, q0′,Σ,Γ∪X0, δ′, q0′, X0, φ), whereδ′ is defined as follows. Rule 1 δ′(q′
0, ǫ, X0) = (q0, Z0X0).
Rule 2 For allq inF, andZ inΓ∪X0,δ′(q, ǫ, Z)contains(q e, ǫ). Rule 3 For allZ inΓ∪X0,δ′(qe, ǫ, Z)contains(qe, ǫ).
Rule 4 δ′(q, a, Z)includes the elements ofδ(q, a, Z)for allq inQ,ainΣora=ǫ, and
Z inΓ.
M1 simulatesM2 by first putting a stack marker forM2(Z0) on its stack (Rule 1). The stack for M1 starts off with the bottom of stack markerX0. This is to ensure thatM1 does not accidentally accept ifM2empties its stack without entering a final state. Rule 4 allowsM1to process the input in exactly the same manner asM2. Rule 2 allowsM1the choice of entering the state qeand erasing the remaining stack contents or to continue simulating M2 when M2 has entered a final state. Rule 3 allows M1 to pop off the
remaining stack contents onceM1 has accepted the input, thus accepting the input by empty stack criterion. One should note thatM2 may possibly erase its entire stack for some input xnot inL(M2). This is the reasonM1 has its own special bottom-of-stack marker.
The corresponding construction of the new machine (newm) in HOL is:
HOL Definition 3.2.1 (newm)
newm p (q0,x0,qe) =
(let d =
[((NONE,x0,q0),p.start,[p.ssSym; x0])] ++ p.next ++
finalStateTrans qe p.final (x0::stkSyms p p.next) ++
newStateTrans qe (x0::stkSyms p p.next)
in
hstart := q0; ssSym := x0; next := d; final := []i)
where, finalStateTrans implements the Rule 2 of the construction, newStateTrans implements Rule 3. Rule 4 simply mimics the original machine transitions (p.next). FunctionstkSymsreturns the stack alphabetsΓ.
We first prove thatx∈L(M2)⇒x∈N(M1).
Let x be in L(M2). Then (q0, x, Z0) ⊢∗M2 (q′0, ǫ, γ) for some q in F. Consider M1 with inputx. Rule 1 gives,
(q′
0, x, X0)⊢∗M1 (q0, x, Z0X0),
By Rule 2, every move ofM2 is a legal move forM1, thus (q0, x, Z0)⊢∗M1 (q, ǫ, γ).
If a PDA can make a sequence of moves from a given ID, it can make the same sequence of moves from any ID obtained from the first by inserting a fixed string of stack symbols below the original stack contents. Thus we have,
(q′
0, x, X0)⊢M1 (q0, x, Z0X0)⊢∗M1 (q, ǫ, γX0).
As an aside the premise (italicised) is deemed sufficient for deducing the above equation. This is the case for not just the presentation in Hopcroft and Ullman. Such a self-explanatory statement suffices in all presentations of this proof. It is statements like these that need to be caught and further elaborated in a mechanised version of the proof. At times, such assumptions may not even be explicitly vocalised in the text itself. In this case we have to prove this statement in HOL before we can make any further progress.
m ⊢ (q,x,stk) →∗ (q′,x′,stk′) ⇒
∀ℓ. m ⊢ (q,x,stk ++ ℓ) →∗ (q′,x′,stk′ ++ ℓ)
Coming back to the proofby Rules 3 and 4,(q, ǫ, γX0)⊢∗M1 (qe, ǫ, ǫ). Therefore,(q′
0, x, X0)⊢∗M1 (qe, ǫ, ǫ), andM1acceptsxby empty stack. This is our HOL theorem:
HOL Theorem 3.2.2
x0 ∈/ stkSyms m ∧ q0′ ∈/ states m ∧ qe ∈/ states m ⇒
x ∈ lafs m ⇒
x ∈ laes (newm m (q′
0,x0,qe))
Conversely, if x ∈ N(M1) ⇒ x ∈ L(M2). If M1 accepts x by empty stack, M2 can simulateM1 by the following sequence of moves. The first move is by Rule 1, then a sequence of moves by Rule 2 in which M1 simulates acceptance of x by M2, followed by the erasure ofM1’s stack using Rules 3 and 4. Thusxmust be inL(M2). This is our HOL theorem:
HOL Theorem 3.2.3
x0 ∈/ stkSyms m ∧ q0′ ∈/ states m ∧ qe ∈/ states m ∧ q0′ 6= qe ⇒
x ∈ laes (newm m (q′
0,x0,qe)) ⇒
x ∈ lafs m
With HOL Theorems 3.2.2 and 3.2.3 in hand, we can now conclude:
HOL Theorem 3.2.4
INFINITE U(:’ssym) ∧ INFINITE U(:’state) ⇒
∀m. ∃m′. lafs m = laes m′
(U(:’ssym)is the universal set of stack symbols andU(:’state)is the universal set of states.)
This is the HOL statement for Theorem 3.2.1.
Note that there are two extra conditions in the premise of the HOL statement. The proof works by constructing a new PDAM1 according to the rules discussed and providing it as a witness. The extra assertions correspond to the construction of machineM1. M1’s construction requires introducing two new states and a new symbol. With respect to HOL types, one can pick a fresh instance of a type if and only if the type is infinite and the set of values for that type in the PDA,i.e.the PDA states and the stack symbols are finite. The former gives rise to the two new conditions that form the part of the theorem statement in HOL. The finiteness of the states and the stack symbols had to be proven as part of the mechanisation process.
3.2.2 PDA construction for acceptance by final state
Now we present the construction of a PDA that accepts inputs via the final state criterion that is equivalent to the given PDA accepting input via the empty stack criterion.
Theorem 3.2.2 (H&U Theorem 5.2) IfLisN(M1)for some PDA M1, thenLisL(M2) for some PDAM2.
Proof We simulate M1 using M2 and detect when M1 empties its stack, M2 enters a final state when and only when this occurs. Let M1 = (Q,Σ,Γ, δ, q0, Z0, φ) be a PDA such thatL=N(M1). LetM2 = (Q∪q0′, qf,Σ,Γ∪X0, δ′, q0′, X0, qf), whereδ′is defined as follows:
Rule 1 δ′(q′
0, ǫ, X0) = (q0, Z0X0).
Rule 2 for allqinQ,ainΣ∪ǫ, andZ inΓ,δ′(q, a, Z) =δ(q, a, Z). Rule 3 for allqinQ,δ′(q, ǫ, X0)contains(q
f, ǫ).
HOL Definition 3.2.2 (newm’)
newm’ p (q′
0,x0,qf) =
(let d =
[((NONE,x0,q0′),p.start,[p.ssSym; x0])] ++ p.next ++
MAP (toFinalStateTrans x0 qf) (states p)
in
hstart := q′
0; ssSym := x0; next := d; final := [qf]i)
(Function toFinalStateTrans x0 qf st returns the next state transition ((NONE,x0,st),qf,[]).)
Rule 1 causesM2to enter the initial ID ofM1, except thatM2will have its own bottom- of-stack marker X0, which is below the symbols ofM1’s stack. Rule 2 allows M2 to simulateM1. ShouldM1 ever erase its entire stack, thenM2, when simulatingM1, will erase its entire stack except the symbolX0 at the bottom. Rule 3 causesM2, when the
X0appears, to enter a final state thereby accepting the inputx.
We proceed in a similar manner to the proof of Theorem 3.2.1 to establish L(M2) =
N(M1)by proving the following subgoals. First, ifx∈N(M1)⇒x∈L(M2):
HOL Theorem 3.2.5
x0 ∈/ stkSyms m ∧ q0′ ∈/ states m ∧ qf ∈/ states m ⇒
x ∈ laes m ⇒
Then, ifx∈L(M2)⇒x∈N(M1):
HOL Theorem 3.2.6
x0 ∈/ stkSyms m ∧ q0′ ∈/ states m ∧ qf ∈/ states m ∧ q0′ 6= qf ⇒
x ∈ lafs (newm’ m (q′
0,x0,qf)) ⇒
x ∈ laes m
From HOL Theorems 3.2.5 and 3.2.6 we can deduce:
HOL Theorem 3.2.7
INFINITE U(:’ssym) ∧ INFINITE U(:’state) ⇒
∀m. ∃m′. laes m = lafs m′
Similar to HOL Theorem 3.2.4 we have to provide the assertion about the universe of the types of symbols and states in the PDA being infinite.