4.2.0.5 Definition. (PDA) A pushdown automaton or PDA, M , is a NFA equipped with a stack variable whose contents we will generically denote by lowercase Greek letters from the beginning of the alphabet ( α, β, γ ) with or without primes.
Algebraically speaking, M is a toolbox
M =
Σ, Γ, Q , δ , q 0 , F
where the finite set Σ is the input alphabet; Q is a finite set of states; δ is the “program”, that is, the transition relation ; q 0 (generic name!) is a distinguished member of Q , the start state; F is a finite set of accepting states.
Γ is new: It is a finite alphabet of stack symbols. The stack variable takes values from Γ * . It is allowed to have Σ ∩ Γ ≠
.
The set of instructions (program) is encoded into the relation δ. A PDA has only four types of possible instructions, given below in flow-diagram form:
where, generically, an “ A ” denotes a member of Γ and an “ a ” denotes a member of the input alphabet Σ. 126 The first and third are “mixed” instructions (both input and stack activity), while the second and fourth are “pure” (stack activity only). The second is a “pure push instruction”.
Mixed instructions “consume input” while pure instructions do not. For the latter note the analogy with a NFA’s
-moves.
Note that instructions of type 3 and 4 are constrained by what is the leftmost (“top”) symbol of the stack: A must be the symbol at the top of the stack; otherwise the instruction is not applicable.
Very important. Jargon such as “consume input”, and “push” into or “pop” from a stack, help our intuition and guide us toward the next definition, which details how PDAs compute. Such terminology has no formal status nor is it needed, except to serve pedagogy. At the end of the day, a PDA, just like a NFA, is a string transformation formalism —we are given a set of rules and a methodology on how to construct certain sequences of strings. Such formalisms allow us to “correctly” write down finite sequences such as
I
M I′
M I ″
M I ′″
M · · ·
which we have seen before (FA and NFA). We also met such formalisms under a different guise—that of grammars— which led to a mechanism that allows us to write down derivations α
α′
α″
· · ·. Above all, we have met such string transformation formalisms way before all this: mathematical proofs (cf. 1.1.1.34 ).
Thus the above “semantics” embodies only stated intentions and guidelines no more. Once we define “computations” the above semantics will become formal.
4.2.0.6 Example. We often allow, for the sake of convenience, the following derived (simulated) types of moves that were not among the primitive (primary) moves of Definition 4.2.0.5 . Let us adopt in what follows that a
Σ ∪ {
}.
The first is an “ignore-the-stack” move (and it will also ignore the input, if a =
). In the simulation, A is a new stack symbol and
a new state. This means that if I “program” a PDA, M , with a “macro” like a ,
→
, then the expansion (implementation) of the macro is done by adding a new state
and a new stack symbol A to the respective alphabets ( Q and Γ) of my original M and by using the three-state sequence below to implement the derived move.
The next is also very useful when programming PDAs, e.g., when constructing examples. The suggested implementation takes care of the general case in a compact (recursive) manner. It says that “if you know how to macro expand (simulate) ‘ a , A → β’, then here is how to do ‘ a , A → B β’ ”. The “basis” of the recursive construction is when β =
, which is covered by one of our basic moves ( Definition 4.2.0.5 ).
Note that a, A → β means to read input a (if a ≠
) and also to pop A, provided it is the top-of-stack symbol , and then to push all of β into the stack— without consuming any more input. More precisely, if γ the stack contents, is the string A γ′ before the effect of the instruction, it will change to βγ′ after the instruction is performed.
4.2.0.7 Example. Specifically, we simulate “ a, A → B ” as follows
There are a number of concepts we need towards defining a computation of a pushdown automaton, and eventually string acceptance.
4.2.0.8 Definition. (Configurations or IDs) A configuration is a snapshot in “time”, also called an instantaneous description , for short, ID , of a PDA computation. 2 It is a triple ( q ,
, γ), where q denotes the current state,
is the unspent (“unexpended” or unprocessed, or, unread-so-far) input, and γ is the total contents of the stack, read from top to bottom (recall that the leftmost symbol of γ is the topmost symbol of the stack).
From the description of
follows that the next input that will be read, if we perform an instruction of types 1 or 2 ( 4.2.0.5 ) on this configuration, will be the leftmost symbol of
.
4.2.0.9 Definition. (Moves) If I and J are configurations of a PDA M , then I
M J or simply I
J if M is understood from the context—pronounced “I yields J” — means that there is a move 127 of M that transforms the ID I into J , in one step. The foregoing is “English” for the following mathematically precise specification by cases:
For all a
Σ ∪ {
}, y
Σ * and γ
Γ * ,
( q , ay , A γ)
( q ′, y , γ)
iff instruction 3 ( Def. 4.2.0.5 , case a
Σ), or 4 ( Def. 4.2.0.5 , case a =
) is available.
For all a
Σ ∪ {
}, y
Σ * and γ
Γ * ,
( q , ay , γ)
( q ′, y , A γ)
iff instruction 1 ( Def. 4.2.0.5 , case a
Σ), or 2 ( Def. 4.2.0.5 , case a =
) is available.
4.2.0.10 Definition. (Initial, Terminal IDs) A configuration is initial iff it has the form ( q 0 , x ,
). This captures the intended semantics that computations with input x start at state “ q 0 ” (generic initial state) and with an empty stack.
A configuration ( q ,
, γ) is terminal or final (I did not say “accepting!) iff there is no defined next move. That is,
4.2.0.11 Definition. (PDA Computations) A PDA computation is a sequence of IDs, I 0 , . . . , I n such that
(1) I 0 is initial
(2) I n is terminal (final)
(3) For i = 0, . . . , n − 1, I i
I i +1 .
As usual, we write I 0
* I n (denoting 0 or more occurrences of “
”) and say “ I 0
* I n is a computation”, which is a slight abuse of language: We should have said—if we do not want to mention I 1 , . . . , I n −1 —that “there is a computation with I 0 as initial and I n as terminal IDs”.
In this context it is sometimes best to write more specifically I 0
n I n , which is explicit that there were n steps (applications of
) in the computation, or that the computation has length n , as we say.
4.2.0.12 Remark. Thus, we require our computations to be terminating. This is implicit in PDA models that one sees in the literature. For example, in the approach taken in Hopcroft et al. (2007), a stack move of the type
→ A (push) is not allowed. Instead, the only stack moves allowed are of the type A → α (that is, “the stack must always be consulted before moving ahead”).
The PDAs in loc. cit., which simulate
→ A by an instruction of the type X → AX and accept their input by “empty stack” (see below), end up in a terminating configuration, since no move is permitted without consulting the stack. 128
4.2.0.13 Definition. (Modes of Acceptance: ES, AS, and ES+AS) The string x is ES-accepted 129 by a PDA, M , iff there is a computation ( q 0 , x ,
)
* ( q ,
,
) for some q
Q .
For ES-acceptance, the set F of accepting states is irrelevant, and is often taken to be
.
The string x is AS-accepted 130 by a PDA, M , iff there is a computation ( q 0 , x ,
)
* ( q ,
, γ) for some q
F. The stack contents, γ, at computation’s end are irrelevant to AS-acceptance.
The string x is ES+AS-accepted 131 by a PDA, M , iff there is a computation ( q 0 , x ,
)
* ( q ,
,
) for some q
F .
If the context helps, we may simply say M accepts x , without having to say in what mode (ES, AS, or ES+AS).
4.2.0.14 Definition. (Acceptance of Languages) If M is a PDA, then L ( M ) denotes the set { x
Σ* : x is accepted by M } (by ES, AS, or ES+AS acceptance, as the case may be).
L is ES- (AS-, or ES+AS-) accepted
iff there is a PDA M that accepts by ES (respectively, AS or ES+AS) such that L = L ( M ).
4.2.1 ES vs AS vs ES+AS
4.2.1.1 Theorem. (AS Can Simulate ES) If M is a PDA accepting by ES, then we can construct a PDA N that accepts by AS, so that L ( M ) = L ( N ).
Proof . We refer to the figure below. Let
M = (Σ, Γ, Q , δ , q 0 , F )
where F =
, be our ES-PDA. We build N as it is (partially) suggested in the figure below.
)
where
, and
. The symbols
and $ are new and
is δ, augmented by the new instructions pictured below. The one involving
is self-explanatory. The “pure pop” instructions that lead to
are only defined on states q that have no pure push moves (1)
Such states exist, unless M has no terminating computations, in which case L ( M ) =
and the result is trivial.
Pause. Why “trivial”?
We now proceed to prove that
L ( M ) = L ( N ) (2)
For ⊆: Let x
L ( M ). Then we have an M -computation
( q 0 , x ,
)
* ( q ,
,
)
Thus,
(
, x ,
)
( q 0 , x , $)
* ( q ,
, $)
(
,
,
) is an N -computation
Clearly the last ID is terminating, since, by construction of N ,
has no moves at all.
Let us justify the last “
”: Since ( q ,
,
) is terminal in M , q cannot have pure push moves, else the computation could continue from ( q ,
,
), a fact that would render this ID nonterminal; not possible (cf. Definition 4.2.0.10 ). Thus, this q is connected to
as shown in the figure above. For short, x
L ( N ).
For ⊇: Let x
L ( N ). Then
The only way to reach
is to reach it—in one move—from some q (of the original M ) that has no pure push moves (in M ) (see figure above). Thus, (3), in some more detail, is the N -computation below, where the first step is obvious (and inevitable) due to the construction of N:
Now, the only way for the last
to be valid (see Definition 4.2.0.9 and the construction of N ) is that γ′ = $γ. Moreover, since N can only write $ once, in the very first move (and the M -part cannot write $ at all), we conclude that γ =
.
Now we see (4) more clearly:
(
, x ,
)
( q 0 , x , $)
* ( q ,
, $)
(
,
,
)
Thus, forgetting the first and last moves, we obtain ( q 0 , x , $)
* ( q ,
, $) and hence 132
( q 0 , x ,
)
* ( q ,
,
) is an M -computation (5)
Note that the ID ( q ,
,
) is terminal in M . Thus, since M is an ES machine, x
L ( M ).
4.2.1.2 Theorem. (ES Can Simulate AS) If M is a PDA accepting by AS, then we can construct a PDA N that accepts by ES, so that L ( M ) = L ( N ).
Proof. We refer to the figure below. Let
M = (Σ, Γ, Q δ , q 0 , F )
be our AS-PDA. Without loss of generality we assume that F = { q } and that q has no moves. Indeed, if it is not so designed, then we modify the original as follows:
(i) we add a new a state q and we designate it as accepting.
(ii) for each (original) accepting state q′ , we add a move “
,
→
” (recall our macros in 4.2.0.6 ) from q′ to q .
(iii) we give no moves to q .
We build N as it is (partially) suggested in the figure below.
where
(thus, we have removed accept-status from q ), and
= Γ ∪ {$}. The symbols
,
and $ are new and
is δ , augmented by the new instructions pictured below.
We now prove that L ( M ) = L ( N ).
For ⊆: Let x
L ( M ). Then
( q 0 , x ,
)
* ( q ,
, γ) is an M -computation
Then, trivially,
(
, x ,
)
( q 0 , x , $)
* ( q ,
, γ$)
* (
,
,
) is an N -computation 133
Thus, x
L ( N ).
For ⊇: Let x
L ( N ). Then
Pause. Wait a minute! Why is
the state in the last ID of (1)? Well, because no other state can contemplate an empty stack. The only states that can erase $ are q and
, each by a move that leads to
.
As in the proof of the previous theorem, let us work back from the end:
consumes no input and is only accessible from state q (see figure). Thus, when q sent the computation to
(by popping once), the input must have been already consumed. This, coupled with the inevitable first move that places a $ in the stack—a symbol which cannot be erased by “internal” _M -moves—gives_ a more “detailed picture” of (1), below:
(
, x ,
)
( q 0 , x , $)
* ( q ,
, γ$)
* (
,
,
)
Now the part ( q 0 , x , $)
* ( q ,
, γ$), after we strip it, throughout, of the bottom $ stack symbol becomes the ( terminating —remember the fact that q has no moves in M ) computation
( q 0 , x ,
)
* ( q ,
, γ)
Since q
F , it follows that x
L ( M ).
4.2.1.3 Corollary. All three acceptance modes are equivalent .
Proof. By Theorems 4.2.1.1 and 4.2.1.2 , ES and AS acceptance modes are equivalent. What about ES+AS?
Well, if M is ES, then an N that accepts by ES+AS can be build that simulates M . We achieved this (without drawing attention to the fact, until now) in the proof of Theorem 4.2.1.1.
Conversely, let M accept by ES+AS. We can then build an ES-PDA simulator, N . The construction and proof is exactly as in Theorem 4.2.1.2 since neither the construction nor the proof there made any assumptions whatsoever on what precisely was the γ that was left in the stack at the end of the computation.
4.2.1.4 Example. Here is how to accept {0 n 1 n : n ≥ 0} by ES.
Indeed, for n > 0,
( q 0 , 0 n 1 n ,
)
n ( q 0 , 1 n , 0 n )
( q , 1 n −1 , 0 n −1 )
n − 1 ( q ,
,
)
where
0 is equality. Clearly, ( q ,
,
) is terminal. We also note that ( q 0 ,
,
)
* (q 0 ,
,
), and (q 0 ,
,
) is terminal. Thus
is accepted.
On the other hand, if the input x is “illegal”—i.e., not of the form 0 k 1 k —then it is not accepted. Here is why: Such an input starts with a 0 or it starts with a 1 :
(1) x = 0 n 1 n y , where y ≠
. Then (q 0 , 0 n 1 n y ,
)
* ( q , y ,
). But ( q , y ,
) is terminal, and the input has not been consumed (for acceptance, the middle coordinate of the last ID must be
).
(2) x = 0 m 1 n y , where m > n and y = 0 z , for some z
{0, 1}*. Then ( q 0 , x ,
)
* ( q , 0 z , 0 m − n ). We ran out of moves and did not reach ( q ,
,
)!
(3) x = 1 z , where z
{0, 1}*, clearly is not acceptable either; it gets the PDA stuck at q 0 before it can make any move at all!