Matrix grammar

From HandWiki

A matrix grammar is a formal grammar in which instead of single productions, productions are grouped together into finite sequences. A production cannot be applied separately, it must be applied in sequence. In the application of such a sequence of productions, the rewriting is done in accordance to each production in sequence, the first one, second one etc. till the last production has been used for rewriting. The sequences are referred to as matrices.

Matrix grammar is an extension of context-free grammar, and one instance of a controlled grammar.

Formal definition

A matrix grammar is an ordered quadruple [math]\displaystyle{ G = (V_N, V_T, X_0, M) }[/math] where

  • [math]\displaystyle{ V_N }[/math] is a finite set of non-terminals
  • [math]\displaystyle{ V_T }[/math] is a finite set of terminals
  • [math]\displaystyle{ X_0 }[/math] is a special element of [math]\displaystyle{ V_N }[/math], viz. the starting symbol
  • [math]\displaystyle{ M }[/math] is a finite set of non-empty sequences whose elements are ordered pairs [math]\displaystyle{ (P, Q) }[/math] where

[math]\displaystyle{ \quad P \in V^* V_N V^*, \quad Q \in V^*, \quad V = V_N \cup V_T. }[/math][1]


The pairs are called productions, written as [math]\displaystyle{ P \to Q }[/math]. The sequences are called matrices and can be written as

[math]\displaystyle{ m = [P_1 \to Q_1, \ldots, P_r \to Q_r]. }[/math]

Let [math]\displaystyle{ F }[/math] be the set of all productions appearing in the matrices [math]\displaystyle{ m }[/math] of a matrix grammar [math]\displaystyle{ G }[/math]. Then the matrix grammar [math]\displaystyle{ G }[/math] is of type-[math]\displaystyle{ i, i = 0, 1, 2, 3 }[/math], length-increasing, linear, [math]\displaystyle{ \lambda }[/math]-free, context-free or context-sensitive if and only if the grammar [math]\displaystyle{ G_1 = (V_N, V_T, X_0, F) }[/math] has the following property.

For a matrix grammar [math]\displaystyle{ G }[/math], a binary relation [math]\displaystyle{ \Rightarrow_G }[/math] is defined; also represented as [math]\displaystyle{ \Rightarrow }[/math]. For any [math]\displaystyle{ P, Q \in V^* }[/math], [math]\displaystyle{ P \Rightarrow Q }[/math] holds if and only if there exists an integer [math]\displaystyle{ r \ge 1 }[/math] such that the words

[math]\displaystyle{ \alpha_1,, \ldots, \alpha_{r + 1}, \quad P_1, \ldots, P_r, \quad Q_1, \ldots, Q_r, \quad R_1, \ldots, R_r, \quad, R^1, \ldots, R^r }[/math]

over V exist and

  • [math]\displaystyle{ \alpha_1 = P }[/math] and [math]\displaystyle{ \alpha_{r + 1} = Q }[/math]
  • [math]\displaystyle{ [P_1 \to Q_1, \ldots, P_r \to Q_r] }[/math] is one of the matrices of [math]\displaystyle{ G }[/math]
  • [math]\displaystyle{ \alpha_i = R_i P_i R^i }[/math] and [math]\displaystyle{ \alpha_{i + 1} = R_i Q_i R^i }[/math] for all [math]\displaystyle{ i }[/math] such that [math]\displaystyle{ 1 \leq i \leq r. }[/math]

Let [math]\displaystyle{ \Rightarrow^{*} }[/math] be the reflexive transitive closure of the relation [math]\displaystyle{ \Rightarrow }[/math]. Then, the language generated by the matrix grammar [math]\displaystyle{ G }[/math] is given by

[math]\displaystyle{ L(G) = \{P \in {V_T}^* | X_0 \Rightarrow^{*} P\}. }[/math]

Examples

Consider the matrix grammar

[math]\displaystyle{ G = (\{S, X, Y\}, \{a, b, c\}, S, M) }[/math]

where [math]\displaystyle{ M }[/math] is a collection containing the following matrices:

[math]\displaystyle{ m_0 : [S \rightarrow XY], \quad m_1 : [X \rightarrow aXb, Y \rightarrow cY], \quad m_2 : [X \rightarrow ab, Y \rightarrow c] }[/math]

These matrices, which contain only context-free rules, generate the context-sensitive language

[math]\displaystyle{ L = \{a^nb^nc^n|n \ge 1\}. }[/math] The associate word of [math]\displaystyle{ a^nb^nc^n }[/math] is [math]\displaystyle{ Aw(a^nb^nc^n) = m_0m^{n-2}_1m_2 , \forall n \geq 2 }[/math] and [math]\displaystyle{ Aw(abc) = m_0m_2 }[/math].

This example can be found on pages 8 and 9 of [1] in the following form: Consider the matrix grammar

[math]\displaystyle{ G = (\{S, X, Y, Z\}, \{a, b, c\}, S, M) }[/math]

where [math]\displaystyle{ M }[/math] is a collection containing the following matrices:

[math]\displaystyle{ m_0 : [S \rightarrow abc], \quad m_1 : [S \rightarrow aXbYcZ], \quad m_2 : [X \rightarrow aX, Y \rightarrow bY, Z \rightarrow cZ], \quad m_3 : [X \rightarrow ab, Y \rightarrow b, Z \rightarrow c] }[/math]

These matrices, which contain only context-regular rules, generate the context-sensitive language

[math]\displaystyle{ L = \{a^nb^nc^n|n \ge 1\}. }[/math]

The associate word of [math]\displaystyle{ a^nb^nc^n }[/math] is [math]\displaystyle{ Aw(a^nb^nc^n) = m_1m^{n-2}_2m_3 , \forall n \geq 2 }[/math] and [math]\displaystyle{ Aw(abc) = m_0 }[/math].

Properties

Let [math]\ce{ MAT^\lambda }[/math] be the class of languages produced by matrix grammars, and MAT the class of languages produced by [math]\displaystyle{ \lambda }[/math]-free matrix grammars.

  • Trivially, MAT is included in [math]\ce{ MAT^\lambda }[/math].
  • All context-free languages are in MAT, and all languages in [math]\ce{ MAT^\lambda }[/math] are recursively enumerable.
  • MAT is closed under union, concatenation, intersection with regular languages and permutation.
  • All languages in MAT can be produced by a context-sensitive grammar.
  • There exists a context-sensitive language which does not belong to [math]\ce{ MAT^\lambda }[/math] [2].
  • Each language produced by a matrix grammar with only one terminal symbol is regular.

Open problems

It is not known whether there exist languages in [math]\ce{ MAT^\lambda }[/math] which are not in MAT, and it is neither known whether [math]\ce{ MAT^\lambda }[/math] contains languages which are not context-sensitive [3].

References

Footnotes

  • ^ Ábrahám, S. Some questions of language theory. International Conference on Computational Linguistic, 1965. pp 1–11. [4]
  • ^ Gheorghe Păun, Membrane Computing: An Introduction, Springer-Verlag New York, Inc., Secaucus, NJ, USA, 2002. pp 30–32