词条 | Pushdown automaton |
释义 |
In the theory of computation, a branch of theoretical computer science, a pushdown automaton (PDA) is a type of automaton that employs a stack. Pushdown automata are used in theories about what can be computed by machines. They are more capable than finite-state machines but less capable than Turing machines. Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design. The term "pushdown" refers to the fact that the stack can be regarded as being "pushed down" like a tray dispenser at a cafeteria, since the operations never work on elements other than the top element. A stack automaton, by contrast, does allow access to and operations on deeper elements. Stack automata can recognize a strictly larger set of languages than pushdown automata.[1] A nested stack automaton allows full access, and also allows stacked values to be entire sub-stacks rather than just single finite symbols. Informal descriptionA finite state machine just looks at the input signal and the current state: it has no stack to work with. It chooses a new state, the result of following the transition. A pushdown automaton (PDA) differs from a finite state machine in two ways:
A pushdown automaton reads a given input string from left to right. In each step, it chooses a transition by indexing a table by input symbol, current state, and the symbol at the top of the stack. A pushdown automaton can also manipulate the stack, as part of performing a transition. The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack. The automaton can alternatively ignore the stack, and leave it as it is. Put together: Given an input symbol, current state, and stack symbol, the automaton can follow a transition to another state, and optionally manipulate (push or pop) the stack. If, in every situation, at most one such transition action is possible, then the automaton is called a deterministic pushdown automaton (DPDA). In general, if several actions are possible, then the automaton is called a general, or nondeterministic, PDA. A given input string may drive a nondeterministic pushdown automaton to one of several configuration sequences; if one of them leads to an accepting configuration after reading the complete input string, the latter is said to belong to the language accepted by the automaton. Formal definitionWe use standard formal language notation: denotes the set of strings over alphabet and denotes the empty string. A PDA is formally defined as a 7-tuple: where
An element is a transition of . It has the intended meaning that , in state , on the input and with as topmost stack symbol, may read , change the state to , pop , replacing it by pushing . The component of the transition relation is used to formalize that the PDA can either read a letter from the input, or proceed leaving the input untouched.{{cn|date=January 2019}} In many texts[2]{{rp|110}} the transition relation is replaced by an (equivalent) formalization, where
Here contains all possible actions in state with on the stack, while reading on the input. One writes for example precisely when because . Note that finite in this definition is essential. ComputationsIn order to formalize the semantics of the pushdown automaton a description of the current situation is introduced. Any 3-tuple is called an instantaneous description (ID) of , which includes the current state, the part of the input tape that has not been read, and the contents of the stack (topmost symbol written first). The transition relation defines the step-relation of on instantaneous descriptions. For instruction there exists a step , for every and every . In general pushdown automata are nondeterministic meaning that in a given instantaneous description there may be several possible steps. Any of these steps can be chosen in a computation. With the above definition in each step always a single symbol (top of the stack) is popped, replacing it with as many symbols as necessary. As a consequence no step is defined when the stack is empty. Computations of the pushdown automaton are sequences of steps. The computation starts in the initial state with the initial stack symbol on the stack, and a string on the input tape, thus with initial description . There are two modes of accepting. The pushdown automaton either accepts by final state, which means after reading its input the automaton reaches an accepting state (in ), or it accepts by empty stack (), which means after reading its input the automaton empties its stack. The first acceptance mode uses the internal memory (state), the second the external memory (stack). Formally one defines
Here represents the reflexive and transitive closure of the step relation meaning any number of consecutive steps (zero, one or more). For each single pushdown automaton these two languages need to have no relation: they may be equal but usually this is not the case. A specification of the automaton should also include the intended mode of acceptance. Taken over all pushdown automata both acceptance conditions define the same family of languages. Theorem. For each pushdown automaton one may construct a pushdown automaton such that , and vice versa, for each pushdown automaton one may construct a pushdown automaton such thatExampleThe following is the formal description of the PDA which recognizes the language by final state: , where
The transition relation consists of the following six instructions: , , , , , and . In words, the first two instructions say that in state {{mvar|p}} any time the symbol {{val|0}} is read, one {{mvar|A}} is pushed onto the stack. Pushing symbol {{mvar|A}} on top of another {{mvar|A}} is formalized as replacing top {{mvar|A}} by {{mvar|AA}} (and similarly for pushing symbol {{mvar|A}} on top of a {{mvar|Z}}). The third and fourth instructions say that, at any moment the automaton may move from state {{mvar|p}} to state {{mvar|q}}. The fifth instruction says that in state {{mvar|q}}, for each symbol {{val|1}} read, one {{mvar|A}} is popped. Finally, the sixth instruction says that the machine may move from state {{mvar|q}} to accepting state {{mvar|r}} only when the stack consists of a single {{mvar|Z}}. There seems to be no generally used representation for PDA. Here we have depicted the instruction by an edge from state {{mvar|p}} to state {{mvar|q}} labelled by (read {{mvar|a}}; replace {{mvar|A}} by ). Understanding the computation processThe following illustrates how the above PDA computes on different input strings. The subscript {{mvar|M}} from the step symbol is here omitted. {{ordered list|type=lower-alpha|1= Input string = 0011. There are various computations, depending on the moment the move from state {{mvar|p}} to state {{mvar|q}} is made. Only one of these is accepting.{{ordered list|type=lower-roman | The final state is accepting, but the input is not accepted this way as it has not been read. | No further steps possible. | Accepting computation: ends in accepting state, while complete input has been read.}} |2= Input string = 00111. Again there are various computations. None of these is accepting.{{ordered list|type=lower-roman | The final state is accepting, but the input is not accepted this way as it has not been read. | No further steps possible. | The final state is accepting, but the input is not accepted this way as it has not been (completely) read.}} }} PDA and context-free languagesEvery context-free grammar can be transformed into an equivalent nondeterministic pushdown automaton. The derivation process of the grammar is simulated in a leftmost way. Where the grammar rewrites a nonterminal, the PDA takes the topmost nonterminal from its stack and replaces it by the right-hand part of a grammatical rule (expand). Where the grammar generates a terminal symbol, the PDA reads a symbol from input when it is the topmost symbol on the stack (match). In a sense the stack of the PDA contains the unprocessed data of the grammar, corresponding to a pre-order traversal of a derivation tree. Technically, given a context-free grammar, the PDA has a single state, 1, and its transition relation is constructed as follows.
The PDA accepts by empty stack. Its initial stack symbol is the grammar's start symbol.{{citation needed|date=December 2016}} For a context-free grammar in Greibach normal form, defining (1,γ) ∈ δ(1,a,A) for each grammar rule A → aγ also yields an equivalent nondeterministic pushdown automaton.[1]{{rp|115}} The converse, finding a grammar for a given PDA, is not that easy. The trick is to code two states of the PDA into the nonterminals of the grammar. Theorem. For each pushdown automaton one may construct a context-free grammar such that .[1]{{rp|116}} The language of strings accepted by a deterministic pushdown automaton is called a deterministic context-free language. Not all context-free languages are deterministic.{{#tag:ref|The set of even-length palindromes of bits can't be recognized by a deterministic PDA, but is a context-free language, with the grammar S → ε | 0S0 | 1S1.[2]|group=note}} As a consequence, the DPDA is a strictly weaker variant of the PDA {{citation needed span|text=and there exists no algorithm for converting a PDA to an equivalent DPDA, if such a DPDA exists.|date=December 2016}} A finite automaton with access to two stacks is a more powerful device, equivalent in power to a Turing machine.[1]{{rp|171}} A linear bounded automaton is a device which is more powerful than a pushdown automaton but less so than a Turing machine.{{#tag:ref|Linear bounded automata are acceptors for the class of context-sensitive languages,[1]{{rp|225}} which is a proper superclass of the context-free languages, and a proper subclass of Turing-recognizable (i.e. recursively enumerable) languages.[1]{{rp|228}}|group=note}} Generalized pushdown automaton (GPDA)A GPDA is a PDA which writes an entire string of some known length to the stack or removes an entire string from the stack in one step. A GPDA is formally defined as a 6-tuple: where , and {{tmath|F}} are defined the same way as a PDA. : is the transition function. Computation rules for a GPDA are the same as a PDA except that the 's and 's are now strings instead of symbols. GPDA's and PDA's are equivalent in that if a language is recognized by a PDA, it is also recognized by a GPDA and vice versa. One can formulate an analytic proof for the equivalence of GPDA's and PDA's using the following simulation: Let be a transition of the GPDA where . Construct the following transitions for the PDA: Stack automatonAs a generalization of pushdown automata, Ginsburg, Greibach, and Harrison (1967) investigated stack automata, which may additionally step left or right in the input string (surrounded by special endmarker symbols to prevent slipping out), and step up or down in the stack in read-only mode.[3][4] A stack automaton is called nonerasing if it never pops from the stack. The class of languages accepted by nondeterministic, nonerasing stack automata is NSPACE(n2), which is a superset of the context-sensitive languages.[5] The class of languages accepted by deterministic, nonerasing stack automata is DSPACE(n⋅log(n)).[5] Alternating pushdown automataAn alternating pushdown automaton (APDA) is a pushdown automaton with a state set
States in and are called existential resp. universal. In an existential state an APDA nondeterministically chooses the next state and accepts if at least one of the resulting computations accepts. In a universal state APDA moves to all next states and accepts if all the resulting computations accept. The model was introduced by Chandra, Kozen and Stockmeyer.[6] Ladner, Lipton and Stockmeyer[7] proved that this model is equivalent to EXPTIME i.e. a language is accepted by some APDA iff it can be decided by an exponential-time algorithm. Aizikowitz and Kaminski[8] introduced synchronized alternating pushdown automata (SAPDA) that are equivalent to conjunctive grammars in the same way as nondeterministic PDA are equivalent to context-free grammars. See also
Notes1. ^1 2 3 4 5 {{cite book | isbn=0-201-02988-X | author=John E. Hopcroft and Jeffrey D. Ullman | title=Introduction to Automata Theory, Languages, and Computation | location=Reading/MA | publisher=Addison-Wesley | year=1979 }} 2. ^{{cite book|author1=John E. Hopcroft |author2=Rajeev Motwani |author3=Jeffrey D. Ullman | title=Introduction to Automata Theory, Languages, and Computation| year=2003| publisher=Addison Wesley}} Here: Sect.6.4.3, p.249 3. ^{{cite journal| author=Seymour Ginsburg, Sheila A. Greibach and Michael A. Harrison| title=Stack Automata and Compiling| journal=J. ACM| year=1967| volume=14| number=1| pages=172–201| doi=10.1145/321371.321385}} 4. ^{{cite journal| author=Seymour Ginsburg, Sheila A. Greibach and Michael A. Harrison| title=One-Way Stack Automata| journal=J. ACM| year=1967| volume=14| number=2| pages=389–418| doi=10.1145/321386.321403}} 5. ^1 2 {{cite journal|author1=John E. Hopcroft |author2=Jeffrey D. Ullman | title=Nonerasing Stack Automata| journal=Journal of Computer and System Sciences| year=1967| volume=1| number=2| pages=166–186| url=http://www.sciencedirect.com/science/article/pii/S0022000067800138/pdf?md5=493c6f31b5f19d2c0cddc2cf69b02aee&pid=1-s2.0-S0022000067800138-main.pdf| doi=10.1016/s0022-0000(67)80013-8}} 6. ^{{cite journal|last1=Chandra|first1=Ashok K.|last2=Kozen|first2=Dexter C.|last3=Stockmeyer|first3=Larry J.|title=Alternation|journal=Journal of the ACM|volume=28|issue=1|year=1981|pages=114–133|issn=0004-5411|doi=10.1145/322234.322243}} 7. ^{{cite journal|last1=Ladner|first1=Richard E.|last2=Lipton|first2=Richard J.|last3=Stockmeyer|first3=Larry J.|title=Alternating Pushdown and Stack Automata|journal=SIAM Journal on Computing|volume=13|issue=1|year=1984|pages=135–155|issn=0097-5397|doi=10.1137/0213010}} 8. ^{{cite journal|last1=Aizikowitz|first1=Tamar|last2=Kaminski|first2=Michael|title=LR(0) Conjunctive Grammars and Deterministic Synchronized Alternating Pushdown Automata|volume=6651|year=2011|pages=345–358|issn=0302-9743|doi=10.1007/978-3-642-20712-9_27}} References
External links
2 : Automata (computation)|Models of computation |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。