BETA ZEN
Linear grammar
Texto da Wikipédia (en), licença CC BY-SA. O BETARUBI mostra o verbete inteiro nesta página — a leitura não continua fora do site.
In computer science, a linear grammar is a context-free grammar that has at most one nonterminal in the right-hand side of each of its productions.
A linear language is a language generated by some linear grammar.
Example
An example of a linear grammar is G with N = {S}, Σ = {a, b}, P with start symbol S and rules
- S → aSb
- S → ε
It generates the language .
Relationship with regular grammars
Two special types of linear grammars are the following:
- the left-linear or left-regular grammars, in which all rules are of the form A → αw where α is either empty or a single nonterminal and w is a string of terminals;
- the right-linear or right-regular grammars, in which all rules are of the form A → wα where w is a string of terminals and α is either empty or a single nonterminal.
Each of these can describe exactly the regular languages. A regular grammar is a grammar that is left-linear or right-linear.
Note that having a mix of left-linear and right-linear rules does not impose any reduction in the expressive power of linear grammars. Indeed, by adding new nonterminals as abbreviations, any linear grammar can be turned into an equivalent one where some of the rules are left-linear and some are right-linear. For instance, the rules of the grammar G above generating can be replaced with
- S → aA
- A → Sb
- S → ε
which generates the same language. It is the requirement that all rules be left-linear, or all rules be right-linear, that characterizes regular languages and thus leads to a strict decrease in the expressive power of linear grammars.
Expressive power, nondeterminism, and complexity
All regular languages are linear; conversely, is an example of a non-regular linear language. All linear languages are context-free; conversely, an example of a context-free, non-linear language is the Dyck language of well-balanced bracket pairs. Hence, the regular languages are a proper subset of the linear languages, which in turn are a proper subset of the context-free languages.
Just as the regularity problem for context-free languages is undecidable, it cannot be decided whether a given context-free language is a linear context-free language.[1]
While regular languages are deterministic, there exist linear languages that are nondeterministic. For example, the language of even-length palindromes on the alphabet of 0 and 1 has the linear grammar S → 0S0 | 1S1 | ε, but cannot be recognized by any deterministic pushdown automaton.[2] In particular, the existence of nondeterministic linear languages can be used to derive Ω(n²/log n) lower bounds for the online recognition problem for linear grammars.[3]
One-turn pushdown automata and ultralinear grammars
A language is linear iff it can be generated by a one-turn pushdown automaton – a pushdown automaton that, once it starts popping, never pushes again. If one instead places a finite bound on the number of turns then one obtains a more general class of languages known as ultralinear, still strictly contained in the context-free languages, and which have a corresponding grammatical characterization.[4] A grammar is ultralinear if the set of nonterminals can be decomposed as a disjoint union of sets , such that for each nonterminal , each production rule is of the form or , where and . (Thus linear grammars correspond to the case .)
Closure properties
Positive cases
Linear languages are closed under union. Construction is the same as the construction for the union of context-free languages. Let be two linear languages, then is constructed by a linear grammar with , and playing the role of the linear grammars for .
If L is a linear language and M is a regular language, then the intersection is again a linear language; in other words, the linear languages are closed under intersection with regular sets.
Linear languages are closed under homomorphism and inverse homomorphism.[5]
As a corollary, linear languages form a full trio. Full trios in general are language families that enjoy a couple of other desirable mathematical properties.
Negative cases
Linear languages are not closed under intersection. For example, let , then their intersection is not only not linear, but also not context-free. See pumping lemma for context-free languages.
As a corollary, linear languages are not closed under complement (as intersection can be constructed by de Morgan's laws out of union and complement).
References
- ↑ Greibach, Sheila (October 1966). "The Unsolvability of the Recognition of Linear Context-Free Languages". Journal of the ACM. 13 (4): 582–587. doi:10.1145/321356.321365. S2CID 37003419.
- ↑ Hopcroft, John; Rajeev Motwani; Jeffrey Ullman (2001). Introduction to automata theory, languages, and computation 2nd edition. Addison-Wesley. pp. 249–253.
- ↑ Gallaire, Hervé (1969). "Recognition time of context-free languages by on-line Turing machines". Information and Control. 15 (3): 288–295. doi:10.1016/S0019-9958(69)90463-X. Seiferas, Joel I. (1986). "A simplified lower bound for context-free-language recognition". Information and Control. 69 (1–3): 255–260. doi:10.1016/S0019-9958(86)80048-1.
- ↑ Ginsburg, Seymour; Spanier, Edwin H. (1966). "Finite-turn pushdown automata". SIAM Journal on Control. 4 (3): 429–453. doi:10.1137/0304034.
- ↑ John E. Hopcroft and Jeffrey D. Ullman, Introduction to Automata Theory, Languages, and Computation, Addison-Wesley Publishing, Reading Massachusetts, 1979. ISBN 0-201-02988-X., Ex. 11.1, pp. 282f
