# Regulated rewriting

Regulated rewriting is a specific area of formal languages studying grammatical systems which are able to take some kind of control over the production applied in a derivation step. For this reason, the grammatical systems studied in Regulated Rewriting theory are also called "Grammars with Controlled Derivations". Among such grammars can be noticed:

## Matrix Grammars

### Basic concepts

Definition
A Matrix Grammar, ${\displaystyle MG}$, is a four-tuple ${\displaystyle G=(N,T,M,S)}$ where
1.- ${\displaystyle N}$ is an alphabet of non-terminal symbols
2.- ${\displaystyle T}$ is an alphabet of terminal symbols disjoint with ${\displaystyle N}$
3.- ${\displaystyle M={m_{1},m_{2},...,m_{n}}}$ is a finite set of matrices, which are non-empty sequences ${\displaystyle m_{i}=[p_{i_{1}},...,p_{i_{k(i)}}]}$, with ${\displaystyle k(i)\geq 1}$, and ${\displaystyle 1\leq i\leq n}$, where each ${\displaystyle p_{i_{j}}1\leq j\leq k(i)}$, is an ordered pair ${\displaystyle p_{i_{j}}=(L,R)}$ being ${\displaystyle L\in (N\cup T)^{*}N(N\cup T)^{*},R\in (N\cup T)^{*}}$ these pairs are called "productions", and are denoted ${\displaystyle L\rightarrow R}$. In these conditions the matrices can be written down as ${\displaystyle m_{i}=[L_{i_{1}}\rightarrow R_{i_{1}},...,L_{i_{k(i)}}\rightarrow R_{i_{k(i)}}]}$
4.- S is the start symbol

Definition
Let ${\displaystyle MG=(N,T,M,S)}$ be a matrix grammar and let ${\displaystyle P}$ the collection of all productions on matrices of ${\displaystyle MG}$. We said that ${\displaystyle MG}$ is of type i according to Chomsky's hierarchy with ${\displaystyle i=0,1,2,3}$, or "increasing length" or "linear" or "without ${\displaystyle \lambda }$-productions" if and only if the grammar ${\displaystyle G=(N,T,P,S)}$ has the corresponding property.

### The classic example

Note: taken from Abraham 1965, with change of nonterminals names

The context-sensitive language ${\displaystyle L(G)=\{a^{n}b^{n}c^{n}:n\geq 1\}}$ is generated by the ${\displaystyle CFMG}$ ${\displaystyle G=(N,T,M,S)}$ where ${\displaystyle N=\{S,A,B,C\}}$ is the non-terminal set, ${\displaystyle T=\{a,b,c\}}$ is the terminal set, and the set of matrices is defined as ${\displaystyle M:}$ ${\displaystyle \left[S\rightarrow abc\right]}$, ${\displaystyle \left[S\rightarrow aAbBcC\right]}$, ${\displaystyle \left[A\rightarrow aA,B\rightarrow bB,C\rightarrow cC\right]}$, ${\displaystyle \left[A\rightarrow a,B\rightarrow b,C\rightarrow c\right]}$.

## Time Variant Grammars

Basic concepts
Definition
A Time Variant Grammar is a pair ${\displaystyle (G,v)}$ where ${\displaystyle G=(N,T,P,S)}$ is a grammar and ${\displaystyle v:\mathbb {N} \rightarrow 2^{P}}$ is a function from the set of natural numbers to the class of subsets of the set of productions.

## Programmed Grammars

Basic concepts

### Definition

A Programmed Grammar is a pair ${\displaystyle (G,s)}$ where ${\displaystyle G=(N,T,P,S)}$ is a grammar and ${\displaystyle s,f:P\rightarrow 2^{P}}$ are the success and fail functions from the set of productions to the class of subsets of the set of productions.

## Grammars with regular control language

### Basic concepts

Definition
A Grammar With Regular Control Language, ${\displaystyle GWRCL}$, is a pair ${\displaystyle (G,e)}$ where ${\displaystyle G=(N,T,P,S)}$ is a grammar and ${\displaystyle e}$ is a regular expression over the alphabet of the set of productions.

### A naive example

Consider the CFG ${\displaystyle G=(N,T,P,S)}$ where ${\displaystyle N=\{S,A,B,C\}}$ is the non-terminal set, ${\displaystyle T=\{a,b,c\}}$ is the terminal set, and the productions set is defined as ${\displaystyle P=\{p_{0},p_{1},p_{2},p_{3},p_{4},p_{5},p_{6}\}}$ being ${\displaystyle p_{0}=S\rightarrow ABC}$ ${\displaystyle p_{1}=A\rightarrow aA}$, ${\displaystyle p_{2}=B\rightarrow bB}$, ${\displaystyle p_{3}=C\rightarrow cC}$ ${\displaystyle p_{4}=A\rightarrow a}$, ${\displaystyle p_{5}=B\rightarrow b}$, and ${\displaystyle p_{6}=C\rightarrow c}$. Clearly, ${\displaystyle L(G)=\{a^{*}b^{*}c^{*}\}}$. Now, considering the productions set ${\displaystyle P}$ as an alphabet (since it is a finite set), define the regular expression over ${\displaystyle P}$: ${\displaystyle e=p_{0}(p_{1}p_{2}p_{3})^{*}(p_{4}p_{5}p_{6})}$.

Combining the CFG grammar ${\displaystyle G}$ and the regular expression ${\displaystyle e}$, we obtain the CFGWRCL ${\displaystyle (G,e)=(G,p_{0}(p_{1}p_{2}p_{3})^{*}(p_{4}p_{5}p_{6}))}$ which generates the language ${\displaystyle L(G)=\{a^{n}b^{n}c^{n}:n\geq 1\}}$.

Besides there are other grammars with regulated rewriting, the four cited above are good examples of how to extend context-free grammars with some kind of control mechanism to obtain a Turing machine powerful grammatical device.

## Sources

[1] Salomaa, Arto (1973) Formal languages Academic Press, ACM monograph series

[2] Rozenberg, G.; Salomaa, A. (eds.) 1997 Handbook of formal languages Berlin; New York : Springer ISBN 3-540-61486-9 (set) (3540604200 : v. 1; 3540606483 : v. 2; 3540606491: v. 3)

[3] Dassow, Jurgen; Paun, G. 1990 Regulated Rewriting in Formal Language Theory ISBN 0387514147. Springer-Verlag New York, Inc. Secaucus, NJ, USA Pages: 308. Medium: Hardcover.

[4] Dassow, Jurgen; von-Guericke, Otto Grammars with Regulated Rewriting Available at: [1] and [2] ([3])

[5] Abraham, S. 1965. "Some questions of language theory", Proceedings of the 1965 International Conference On Computational Linguistics, pp 1 – 11, Bonn, Germany Available at: [4]