Indexed grammar#Linear indexed grammars

Indexed grammars are a generalization of context-free grammars in that nonterminals are equipped with lists of flags, or index symbols.

The language produced by an indexed grammar is called an indexed language.

Definition

=Modern definition by Hopcroft and Ullman=

In contemporary publications following Hopcroft and Ullman (1979),

{{refn|Hopcroft and Ullman (1979),{{cite book | last = Hopcroft | author-link = John Hopcroft | first = John E. | author2 = Jeffrey D. Ullman | title = Introduction to Automata Theory, Languages, and Computation | year = 1979 | publisher = Addison-Wesley | isbn = 978-0-201-02988-8| title-link = Introduction to Automata Theory, Languages, and Computation | author2-link = Jeffrey D. Ullman }} Sect.14.3, p.389-390. This section is omitted in the 2nd edition 2003.}}

an indexed grammar is formally defined a 5-tuple G = ⟨N,T,F,P,S⟩ where

In productions as well as in derivations of indexed grammars, a string ("stack") σF* of index symbols is attached to every nonterminal symbol AN, denoted by A[σ]."[" and "]" are meta symbols to indicate the stack.

Terminal symbols may not be followed by index stacks.

For an index stack σF* and a string α ∈ (NT)* of nonterminal and terminal symbols, α[σ] denotes the result of attaching [σ] to every nonterminal in α; for example if α equals {{math|a B C d E}} with a,dT terminal, and {{math|B,C,EN}} nonterminal symbols, then α[σ] denotes {{math|a B[σ] C[σ] d E[σ].}}

Using this notation, each production in P has to be of the form

  1. A[σ] → α[σ],
  2. A[σ] → B[fσ], or
  3. A[fσ] → α[σ],

where A, BN are nonterminal symbols, fF is an index, σF* is a string of index symbols, and α ∈ (NT)* is a string of nonterminal and terminal symbols. Some authors write ".." instead of "σ" for the index stack in production rules; the rule of type 1, 2, and 3 then reads {{math|A[..]→α[..],   A[..]→B[f..]}}, and {{math|A[f..]→α[..]}}, respectively.

Derivations are similar to those in a context-free grammar except for the index stack attached to each nonterminal symbol.

When a production like e.g. A[σ] → B[σ]C[σ] is applied, the index stack of A is copied to both B and C.

Moreover, a rule can push an index symbol onto the stack, or pop its "topmost" (i.e., leftmost) index symbol.

Formally, the relation ⇒ ("direct derivation") is defined on the set (N[F*]∪T)* of "sentential forms" as follows:

  1. If A[σ] → α[σ] is a production of type 1, then β A[φ] γβ α[φ] γ, using the above definition. That is, the rule's left hand side's index stack φ is copied to each nonterminal of the right hand side.
  2. If A[σ] → B[] is a production of type 2, then β A[φ] γβ B[] γ. That is, the right hand side's index stack is obtained from the left hand side's stack φ by pushing f onto it.
  3. If A[] → α[σ] is a production of type 3, then β A[] γβ α[φ] γ, using again the definition of α[σ]. That is, the first index f is popped from the left hand side's stack, which is then distributed to each nonterminal of the right hand side.

As usual, the derivation relation {{overset||⇒}} is defined as the reflexive transitive closure of direct derivation ⇒.

The language L(G) = { wT*: S {{overset|∗|⇒}} w } is the set of all strings of terminal symbols derivable from the start symbol.

=Original definition by Aho=

Historically, the concept of indexed grammars was first introduced by Alfred Aho (1968){{cite journal | last = Aho | author-link = Alfred Aho | first = Alfred | year = 1968 | title = Indexed grammars—an extension of context-free grammars | journal = Journal of the ACM | volume = 15 | issue = 4 | pages = 647–671 | doi = 10.1145/321479.321488 | s2cid = 9539666 | doi-access = free }} using a different formalism.

Aho defined an indexed grammar to be a 5-tuple (N,T,F,P,S) where

  1. N is a finite alphabet of variables or nonterminal symbols
  2. T is a finite alphabet of terminal symbols
  3. F2N × (NT)* is the finite set of so-called flags (each flag is itself a set of so-called index productions)
  4. PN × (NF*T)* is the finite set of productions
  5. SN is the start symbol

Direct derivations were as follows:

  • A production p = (AX1η1Xkηk) from P matches a nonterminal AN followed by its (possibly empty) string of flags ζF*. In context, γ δ, via p, derives to γ X1θ1Xkθk δ, where θi = ηiζ if Xi was a nonterminal and the empty word otherwise. The old flags of A are therefore copied to each new nonterminal produced by p. Each such production can be simulated by appropriate productions of type 1 and 2 in the Hopcroft/Ullman formalism.
  • An index production p = (AX1Xk) ∈ f matches Afζ (the flag f it comes from must match the first symbol following the nonterminal A) and copies the remaining index string ζ to each new nonterminal: γ Afζ δ derives to γ X1θ1Xkθk δ, where θi is the empty word when Xi is a terminal and ζ when it is a nonterminal. Each such production corresponds to a production of type 3 in the Hopcroft/Ullman formalism.

This formalism is e.g. used by Hayashi (1973, p. 65-66).{{cite journal | url=http://www.ems-ph.org/journals/show_pdf.php?issn=0034-5318&vol=9&iss=1&rank=3| doi=10.2977/prims/1195192738| title=On derivation trees of indexed grammars: An extension of the uvwxy-theorem| journal=Publications of the Research Institute for Mathematical Sciences| volume=9| pages=61–92| year=1973| last1=Hayashi| first1=Takeshi| doi-access=free}}

Examples

In practice, stacks of indices can count and remember what rules were applied and in which order. For example, indexed grammars can describe the context-sensitive language of word triples { www : w ∈ {a,b}* }:

:

S[σ]S[]

| T[]

a T[σ]
S[σ]S[]

| T[]

b T[σ]
S[σ]T[σ] T[σ] T[σ]      

| T[]

ε

A derivation of {{not a typo|abbabbabb}} is then

:{{math|size=100%|S[]}} ⇒ {{math|size=100%|S[g]}} ⇒ {{math|size=100%|S[gg]}} ⇒ {{math|size=100%|S[fgg]}} ⇒ {{math|size=100%|T[fgg] T[fgg] T[fgg]}} ⇒ {{math|size=100%|a T[gg] T[fgg] T[fgg]}} ⇒ {{math|size=100%|ab T[g] T[fgg] T[fgg]}} ⇒ {{math|size=100%|abb T[] T[fgg] T[fgg]}} ⇒ {{math|size=100%|abb T[fgg] T[fgg]}} ⇒ {{math|size=100%|...}} ⇒ {{math|size=100%|abb abb T[fgg]}} ⇒ {{math|size=100%|...}} ⇒ {{math|size=100%|abb abb abb}}.

As another example, the grammar G = ⟨ {S,T,A,B,C}, {a,b,c}, {f,g}, P, S ⟩ produces the language { anbncn: n ≥ 1 }, where the production set P consists of

:

S[σ] → T[]A[] → a A[σ]A[] → a
T[σ] → T[]B[] → b B[σ]B[] → b
T[σ] → A[σ] B[σ] C[σ]      C[] → c C[σ]      C[] → c

An example derivation is

:{{math|size=100%|S[]}} ⇒ {{math|size=100%|T[g]}} ⇒ {{math|size=100%|T[fg]}} ⇒ {{math|size=100%|A[fg] B[fg] C[fg]}} ⇒ {{math|size=100%|aA[g] B[fg] C[fg]}} ⇒ {{math|size=100%|aA[g] bB[g] C[fg]}} ⇒ {{math|size=100%|aA[g] bB[g] cC[g]}} ⇒ {{math|size=100%|aa bB[g] cC[g]}} ⇒ {{math|size=100%|aa bb cC[g]}} ⇒ {{math|size=100%|aa bb cc}}.

Both example languages are not context-free by the pumping lemma.

Properties

Hopcroft and Ullman tend to consider indexed languages as a "natural" class, since they are generated by several formalisms other than indexed grammars, viz.{{refn|Hopcroft and Ullman (1979), Bibliographic notes, p.394-395}}

  • Aho's one-way nested stack automata{{cite journal| author=Alfred Aho| title=Nested Stack Automata| journal=Journal of the ACM| year=1969| volume=16| number=3| pages=383–406| doi=10.1145/321526.321529| s2cid=685569| doi-access=free}}
  • Fischer's macro grammars{{cite book| author=Michael J. Fischer| chapter=Grammars with Macro-Like Productions| title=Proc. 9th Ann. IEEE Symp. on Switching and Automata Theory (SWAT)| year=1968| pages=131–142| doi=10.1109/SWAT.1968.12}}
  • Greibach's automata with stacks of stacks{{cite journal| author=Sheila A. Greibach| title=Full AFL's and Nested Iterated Substitution| journal=Information and Control| year=1970| volume=16| number=1| pages=7–35| doi=10.1016/s0019-9958(70)80039-0| doi-access=free}}
  • Maibaum's algebraic characterization{{cite journal| author=T.S.E. Maibaum| title=A Generalized Approach to Formal Languages| journal=Journal of Computer and System Sciences| year=1974| volume=8| number=3| pages=409–439| doi=10.1016/s0022-0000(74)80031-0| doi-access=free}}

Hayashi generalized the pumping lemma to indexed grammars.

Conversely, Gilman{{cite journal| author=Robert H. Gilman| title=A Shrinking Lemma for Indexed Languages| journal=Theoretical Computer Science| year=1996| volume=163| issue=1–2| pages=277–281| doi=10.1016/0304-3975(96)00244-7| arxiv=math/9509205| s2cid=14479068}}{{cite arXiv| author=Robert H. Gilman| title=A Shrinking Lemma for Indexed Languages|date=Sep 1995| eprint=math/9509205}} gives a "shrinking lemma" for indexed languages.

Linear indexed grammars

Gerald Gazdar has defined a second class, the linear indexed grammars (LIG),{{refn|According to Staudacher (1993, p.361 left, Sect.2.2), the name "linear indexed grammars" wasn't used in Gazdar's 1988 paper, but appeared later, e.g. in Weir and Joshi (1988).{{cite book|author1=David J. Weir |author2=Aravind K. Joshi | chapter=Combinatory Categorial Grammars: Generative Power and Relationship to Linear Context-Free Rewriting Systems| title=Proc. 26th Meeting Assoc. Comput. Ling.| year=1988| pages=278–285| chapter-url=http://acl.ldc.upenn.edu/P/P88/P88-1034.pdf?origin=publication_detail}}}} by requiring that at most one nonterminal in each production be specified as receiving the stack,all other nonterminals receive an empty stack

whereas in an ordinary indexed grammar, all nonterminals receive copies of the stack.

Formally, a linear indexed grammar is defined similar to an ordinary indexed grammar, but the production's form requirements are modified to:

  1. A[σ] → α[] B[σ] β[],
  2. A[σ] → α[] B[] β[],
  3. A[] → α[] B[σ] β[],

where A, B, f, σ, α are used as above, and β ∈ (NT)* is a string of nonterminal and terminal symbols like α.In order to generate any string at all, some productions must be admitted having no nonterminal symbol on their right hand side. However, Gazdar didn't discuss this issue. Also, the direct derivation relation ⇒ is defined similar to above. This new class of grammars defines a strictly smaller class of languages,{{cite book | chapter=Applicability of Indexed Grammars to Natural Languages | year=1988 | last=Gazdar | first=Gerald | title=Natural Language Parsing and Linguistic Theories | editor=U. Reyle and C. Rohrer | pages=69–94 | publisher=D. Reidel Publishing Company | isbn=978-1-55608-055-5 | series=Studies in linguistics and philosophy |volume=35}}

which belongs to the mildly context-sensitive classes.

The language { www : w ∈ {a,b}* } is generable by an indexed grammar, but not by a linear indexed grammar, while both { ww : w ∈ {a,b}* } and { an bn cn : n ≥ 1 } are generable by a linear indexed grammar.

If both the original and the modified production rules are admitted, the language class remains the indexed languages.Gazdar (1988), Appendix, p.89

=Example=

Letting σ denote an arbitrary sequence of stack symbols, we can define a grammar for the language L = {an bn cn | n ≥ 1 }{{refn|Cf. the properly indexed grammar for the same language given above. The last rule, viz. T[]→ε, of the linear indexed grammar doesn't conform to Gazdar's definition in a strict sense, cf. |group=note}} as

:

S[σ]a S[] c
S[σ]T[σ]
T[]T[σ] b
T[]ε

To derive the string abc we have the steps:

:S[] ⇒ aS[f]caT[f]caT[]bcabc

Similarly:

:S[] ⇒ aS[f]caaS[ff]ccaaT[ff]ccaaT[f]bccaaT[]bbccaabbcc

=Computational power=

The linearly indexed languages are a subset of the indexed languages, and thus all LIGs can be recoded as IGs, making the LIGs strictly less powerful than the IGs. A conversion from a LIG to an IG is relatively simple.Gazdar 1988, Appendix, p.89-91 LIG rules in general look approximately like X[\sigma] \to \alpha Y[\sigma] \beta, modulo the push/pop part of a rewrite rule. The symbols \alpha and \beta represent strings of terminal and/or non-terminal symbols, and any non-terminal symbol in either must have an empty stack, by the definition of a LIG. This is, of course, counter to how IGs are defined: in an IG, the non-terminals whose stacks are not being pushed to or popped from must have exactly the same stack as the rewritten non-terminal. Thus, somehow, we need to have non-terminals in \alpha and \beta which, despite having non-empty stacks, behave as if they had empty stacks.

Consider the rule X[\sigma] \to Y[] Z[\sigma f] as an example case. In converting this to an IG, the replacement for Y[] must be some Y^{\prime}[\sigma] that behaves exactly like Y[] regardless of what \sigma is. To achieve this, we can simply have a pair of rules that takes any Y^{\prime}[\sigma] where \sigma is not empty, and pops symbols from the stack. Then, when the stack is empty, it can be rewritten as Y[].

: Y^{\prime}[\sigma f] \to Y^{\prime}[\sigma]

: Y^{\prime}[] \to Y[]

We can apply this in general to derive an IG from an LIG. So for example if the LIG for the language \{a^n b^n c^n d^m | n \geq 1, m \geq 1\} is as follows:

: S[\sigma] \to T[\sigma]V[]

: V[] \to d ~|~ dV[]

: T[\sigma] \to aT[\sigma f]c ~|~ U[\sigma]

: U[\sigma f] \to bU[\sigma]

: U[] \to \epsilon

The sentential rule here is not an IG rule, but using the above conversion algorithm, we can define new rules for V^{\prime}, changing the grammar to:

: S[\sigma] \to T[\sigma]V^{\prime}[\sigma]

: V^{\prime}[\sigma f] \to V^{\prime}[\sigma]

: V^{\prime}[] \to V[]

: V[] \to d ~|~ dV[]

: T[\sigma] \to aT[\sigma f]c ~|~ U[\sigma]

: U[\sigma f] \to bU[\sigma]

: U[] \to \epsilon

Each rule now fits the definition of an IG, in which all the non-terminals in the right hand side of a rewrite rule receive a copy of the rewritten symbol's stack. The indexed grammars are therefore able to describe all the languages that linearly indexed grammars can describe.

=Relation to other formalisms=

Vijay-Shanker and Weir (1994){{cite journal |author=Vijay-Shanker, K. |author2=Weir, David J. 1994. |title=The Equivalence of Four Extensions of Context-Free Grammars |journal=Mathematical Systems Theory |volume=27 |issue=6 |pages=511–546 |url=http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.52.4044&rep=rep1&type=pdf |doi=10.1007/bf01191624|year=1994 |s2cid=12336597 }} demonstrates that Linear Indexed Grammars, Combinatory Categorial Grammars, Tree-adjoining Grammars, and Head Grammars all define the same class of string languages.

Their formal definition of linear indexed grammarsp.517-518 differs from the above.{{clarify|date=August 2014}}

LIGs (and their weakly equivalents) are strictly less expressive (meaning they generate a proper subset) than the languages generated by another family of weakly equivalent formalism, which include: LCFRS, MCTAG, MCFG and minimalist grammars (MGs). The latter family can (also) be parsed in polynomial time.{{cite book|author1=Johan F.A.K. van Benthem|author2=Alice ter Meulen|author2-link=Alice ter Meulen|title=Handbook of Logic and Language|url=https://books.google.com/books?id=K7yJLmZCbFUC&pg=PA404|year=2010|publisher=Elsevier|isbn=978-0-444-53727-0|page=404|edition=2nd}}

Distributed index grammars

Another form of indexed grammars, introduced by Staudacher (1993),{{citation |author=Staudacher, Peter |year=1993 |contribution=New frontiers beyond context-freeness: DI-grammars (DIGs) and DI-automata. | title=Sixth Conference of the European Chapter of the Association for Computational Linguistics (EACL '93) |contribution-url=https://aclanthology.org/E93-1042.pdf |pages=358–367 }} is the class of Distributed Index grammars (DIGs). What distinguishes DIGs from Aho's Indexed Grammars is the propagation of indexes. Unlike Aho's IGs, which distribute the whole symbol stack to all non-terminals during a rewrite operation, DIGs divide the stack into substacks and distributes the substacks to selected non-terminals.

The general rule schema for a binarily distributing rule of DIG is the form

: X[f1...fifi+1...fn] → α Y[f1...fi] β Z[fi+1...fn] γ

Where α, β, and γ are arbitrary terminal strings. For a ternarily distributing string:

: X[f1...fifi+1...fjfj+1...fn] → α Y[f1...fi] β Z[fi+1...fj] γ W[fj+1...fn] η

And so forth for higher numbers of non-terminals in the right hand side of the rewrite rule. In general, if there are m non-terminals in the right hand side of a rewrite rule, the stack is partitioned m ways and distributed amongst the new non-terminals. Notice that there is a special case where a partition is empty, which effectively makes the rule a LIG rule. The Distributed Index languages are therefore a superset of the Linearly Indexed languages.

See also

Notes

{{Reflist|group=note}}

References

{{Reflist}}