Contextual Array Grammars with Matrix and Regular Control

. We investigate the computational power of d -dimensional contextual array grammars with matrix control and regular control languages. For d ≥ 2, d -dimensional contextual array grammars are less powerful than matrix contextual array grammars, which themselves are less powerful than contextual array grammars with regular control languages. Yet in the 1-dimensional case, for a one-letter alphabet, the family of 1-dimensional array languages generated by contextual array grammars with regular control languages coincides with the family of regular 1-dimensional array languages, whereas for alphabets with more than one letter, we obtain the array images of the linear languages.


Introduction
Contextual string grammars were introduced by Solomon Marcus [14] with motivations arising from descriptive linguistics.A contextual string grammar consists of a finite set of strings (axioms) and a finite set of productions, which are pairs (s, c) where s is a string, the selector, and c is the context, i. e., a pair of strings, c = (u, v), over the alphabet under consideration.Starting from an axiom, contexts iteratively are added as is indicated by the productions, which yields new strings.In contrast to usual sequential string grammars in the Chomsky hierarchy (e.g., see [20]), these contextual string grammars are pure grammars where new strings are not obtained by rewriting, but by adjoining strings.Several classes of contextual grammars have been introduced and investigated, e.g., see [3] and [17] for surveys on the area.
The idea of contextual productions then was also introduced for multidimensional array grammars, for instance, to carry over ideas from formal languages to the processing of digital images.In the area of two-dimensional picture languages, e.g., see [12,16,18,19], different kinds of array grammars, both isometric and non-isometric ones, have been proposed, motivated by many applications such as character recognition (also confer [4]), cluster analysis of patterns, and so on.Isometric contextual array grammars were introduced in [11].
Regulated rewriting with different control mechanisms has been studied extensively especially for string grammars (e.g., see [2]), for example, grammars with control languages and matrix grammars, but then also for array grammars, e.g., see [9].Non-isometric contextual array grammars (with regulation) were considered in [8,7,13].
In this paper we consider matrix contextual array grammars and contextual array grammars with regular control and examine their generative power.In the 1-dimensional case, we obtain special results: the family of 1-dimensional array languages generated by contextual array grammars with regular control languages coincides with the family of regular 1-dimensional array languages over unary alphabets and with array images of the linear languages over alphabets with more than one letter; already for binary alphabets, regular control is strictly more powerful than matrix control, a phenomenon rarely observed in regulated rewriting (confer [10]).

Definitions
For notions and notations as well as results related to formal language theory we refer to books like [2].The families of λ-free (λ denotes the empty string) regular string languages (over a k-letter alphabet) is denoted by L (REG) (L REG k ).For the definitions and notations for arrays and sequential array grammars we refer to [9,18,22].
Let Z be the set of integers and N be the set of positive integers.Let d ∈ N. A d -dimensional array A over the alphabet V is a mapping A :

and for any array
Usually (see [18]) arrays are regarded as equivalence classes of arrays with respect to linear translations.

The equivalence class [A] of an array
The set of all equivalence classes of d-dimensional arrays over V with respect to linear translations is denoted by V * d , and this bracket notation carries over to classes of array languages, as well.
As many results for d-dimensional arrays for a specific d can be taken over immediately for higher dimensions, we introduce special notions: We can use the well-known graph-theoretic notion of a connected graph to define connected arrays.Let W be a non-empty finite subset of Z d .We associate a graph g(W ) to W with vertex set W and an edge between v, w ∈ W if and only if v − w = 1, where the norm u of a vector There is a natural bijection between the (equivalence classes of) 1-dimensional connected arrays and strings: for any equivalence class of 1- we define its string image as str(A) = a 1 . . .a n ; the string w = a 1 . . .a n can be interpreted as the array arr (w) = {{((i − 1), a i )} | 1 ≤ i ≤ n}.In the standard way, these notions are extended from strings and arrays to sets of strings and arrays.
Example 1.Consider the language L 1 of connected 2-dimensional arrays The following results for 1-dimensional array languages are folklore: Let us mention the close similarities of the work of 1-dimensional regular array grammars and Lindenmayer systems with apical growth [21].Another similar development can be found within Watson-Crick systems [15].

Contextual Array Grammars
We now turn our attention to the main variants of contextual array grammars considered in this paper.Definition 2. A d-dimensional contextual array grammar (d ∈ N) is a construct G = (d, V, #, P, A) where V is an alphabet not containing the blank symbol #, A is a finite set of axioms, i. e., of d-dimensional arrays in V +d , and P is a finite set of rules of the form (U α , α, U β , β) where and U α , U β are finite and non-empty; (U α , α) corresponds with the selector and (U β , β) with the context of the production (U α , α, U β , β) ; U α is called the selector area, and U β is the context area.As the sets U α and U β are uniquely determined by α and β, we will also represent Hence, if in C 1 we find a subpattern that corresponds with the selector α and only blank symbols at the places corresponding with β, we can add the context β thus obtaining C 2 .For every B 1 , B 2 ∈ V +d we say that B 2 is directly derivable from B 1 by the contextual array production p ∈ P , p = (U α , α, U β , β), denoted The array language generated by G is defined as which means specifying an axiom A i by one array from [A i ].
Example 2. Any finite d-dimensional array language of connected arrays Example 3. We now show how the language L 1 from Example 1 can be generated by the contextual array grammar G 1 , i.e., where A 1 = {((0, 0) , a) , ((0, 1) , a) , ((1, 0) , a)} is the only axiom and P 1 consists of the two productions p u and p r : As the selector area U α and the context area U β in a contextual array production of the form (U α , α, U β , β) are disjoint, both α and β can be represented within only one pattern, i. e., p u and p r can be represented in a more depictive way by the patterns shown on the right (the symbols of the selector are enclosed in boxes).
The example of the L-shaped array for n = 3 and m = 4 then is generated by twice applying rule p u and three times applying rule p r , in any order.We also observe that every intermediate array obtained by applying these rules is in L 1 , too.Obviously, by the definition of equivalence classes of arrays, we also have [A 1 ] can be described in a more depictive way by a a a , i.e., the contextual array grammar [G 1 ] for [L (G 1 )] can also be written as [G 1 ] = 2, {a} , #, P 1 , a a a (see Remark 1).In the following, the axiom(s) often will just be given in such a pictorial variant.
Example 4. For the singleton language As we can take L ⊥ (as any finite language) as a set of axioms, containment in [L (2-ContA)] is clear.Conversely, any regular array grammar has to scan the non-blank symbols of the array A, which is impossible, as the underlying graph g(shape(A)) is not Hamiltonian.
Proof.Due to the results from Theorem 1, it only remains to show that arr L REG 1  ⊆ L 1-ContA 1 .From [1, Theorem 4.4], we deduce that any infinite language L ⊆ {a} + in L REG 1 can be written in the form L = {a s1 , a s2 , . . ., a st }∪ The 1-dimensional contextual array grammar now is constructed using a context of length k and putting the words a sj , 1 ≤ j ≤ t, and a di , 1 ≤ i ≤ m, into the set of axioms, i.e., we define the 1-dimensional contextual array grammar For the sake of completeness we mention that every finite array language A = {arr (a sj ) | 1 ≤ j ≤ t} is generated by the 1-dimensional contextual array grammar G (L) = (1, {a} , #, P, A) with P = ∅.
Remark 2. Following the definition already given in [11], our d-dimensional extension of (external) contextual grammars only appends at one location, while external contextual string grammars as originally defined by Solomon Marcus, see [14], append to both ends of a string at the same time.This design decision has two main reasons.First, it is not quite clear what the d-dimensional counterpart of external contextual grammars would really mean: for instance, for d = 2, should we allow appending on both ends of a row or column at the same time, as we did in [8] for the case of non-isometric contextual array grammars?Or, should we rather append on 'all ends' ?Obviously, this situation becomes even more intricate for higher dimensions.Yet second and even more important, appending at both sides of a string, i.e., a 1-dimensional array, in parallel can easily be simulated sequentially by a matrix with two components.It is therefore easy to see that in the 1-dimensional case, the string images of the arrays generated by contextual array grammars with matrix control exactly correspond with the string languages generated by external contextual string grammars.This means that for the regulated variants discussed in the following, any variant that can be conceivably defined for the d-dimensional analogue of external contextual grammars, in the 1-dimensional case should lead to the same results as the original variant of contextual array grammars defined in [11] and taken as the basis in this paper, too.
The single matrix p u , p r , p u = a a a , p r = a a a , guarantees that both arms of the array grow in a synchronized way.In the 1-dimensional case, the situation is different: as we shall prove later, see Theorem 6, L 1- Even more, there is no 1-dimensional contextual array grammar for L n .Namely, if this would be the case, then first observe that there must be rules that append something to the right, as well as to the left of the array, and this should be possible infinitely often.Otherwise, the sequence of context additions would happen (finally) only on one side, which means that this behavior can again be simulated by some regular array grammar, contradicting our previous reasoning.Hence, there must be a rule that contains a sequence of a's as its selector, say, arr(a rs ), and also a sequence of a's, say, arr(a rc ) as its context in order to append a rc to the right of the current array, and likewise, there must be a rule that contains a sequence of a's as its selector, say, arr(a s ), and also a sequence of a's, say, arr(a c ) as its context in order to append a lc to the left of the current array.For sufficiently long arrays arr(a n ba n ), both rules can be applied, and arrays like arr(a n ba n+rc ) can generated that do not belong to L n .Hence, L n / ∈ L(1-ContA).

Yet for the 1-dimensional matrix contextual array grammar [G
{a, b} , #, P, {aba}) where p l = a a , p r = a a , and The single matrix p l , p r guarantees that the number of symbols a grows to the left and to the right in a synchronized way.
In addition, the following example even yields that for any k

Contextual Array Grammars with Regular Control
Definition 4. A d-dimensional contextual array grammar with regular control is a pair G C = (G, L) where G = (d, V, #, P, A) is a d-dimensional contextual array grammar and L is a regular string language over P .Derivations in a d-dimensional contextual array grammar with regular control are defined as in the contextual array grammar G except that in a successful derivation the sequence of applied rules has to be a word from L. The array language generated by G C is the set of all d-dimensional arrays which can be derived from any of the axioms in A following a control word from L. The family of d-dimensional array languages of arrays generated by d-dimensional contextual array grammars over a k-letter alphabet with regular control is denoted by L ((d-ContA, REG)).The corresponding family of array languages of equivalence classes of arrays is denoted by using brackets in the notations.
As a general result (following [10]) we can state: Theorem 4. For any d ≥ 1 and any k ≥ 1, {a, b} , #, P, {arr (ba)}) and P = {p aa , p ab } with p aa = a a , and p ab = a b , as well as Theorem 5.For any d ≥ 1 and any k ≥ 2, we have: Proof.The inclusions directly follow from Theorem 4. The strictness of the first inclusion follows from Example 6 by taking the non-regular string language The strictness of the second inclusion follows from Example 8 by taking On the other hand, in the 1-dimensional case, the following theorem says that even with the regulating mechanisms of matrix control or regular control languages, with 1-dimensional contextual array grammars over a one-letter alphabet we cannot go beyond regularity, i.e., beyond L 1-REGA 1 .
Proof.(Sketch) According to Theorems 4 and 2, we only have to show that L 1-REGA 1 ⊇ L 1-ContA 1 , REG .The main ideas of the corresponding technically non-trivial proof can be described as follows: -Without loss of generality, right-hand sides of rules have the form a m a n .-Context information is irrelevant for the unary 1-dimensional case, assuming that the set of axioms collects all arrays of sufficient size.-The state information of the regular control is then encoded in the nonterminals of the regular array grammar.
Allowing for more than one symbol, 1-dimensional contextual array grammars can generate exactly the array images of linear languages.The proof is based on the following normal form: Lemma 1.For any 1-dimensional contextual array grammar with regular control G C = (G, L), where G = (1, V, #, P, A), L ⊆ P * , we can construct an equivalent 1-dimensional contextual array grammar with regular control G C = (G , L ) with G = (1, V, #, P , A ), L ⊆ P * , such that for P we have: -All rules in P are of the form a b or b a for some a, b ∈ V , i.e., we only have the minimal non-empty size of selectors and minimal contexts of size 1.
-If there is a rule of the form a b / b a in P , then also all rules of the form c b or b c are in P , for any c ∈ V , i.e., the selector contents is irrelevant, only direction of growth of the array is important.
The rules in this normal form nicely correspond with the operations of left and right insertions for strings, which operations together with regular control languages also characterize the family of linear languages.Proof.(Sketch) The main ideas of the proof can be described as follows: -Adding strings in a controlled way "on both ends" corresponds to applying linear rules, but in reverse order.-The information about the finitely many selectors possible can be stored in the nonterminal; on the other hand, the nonterminal can be stored in the state of the finite automaton of the control language.
For d ≥ 2, i.e., in the case of at least two symbols, we can prove the incomparability of the families of array languages generated by contextual array grammars and those equipped with control mechanisms: Proof.For the singleton language L ⊥ from Example 4, we have i On the other hand, for L r from Example 7 we have i Yet even for the case of one-letter alphabets we can find an array language of 2-dimensional arrays in L 2-REGA 1 \ L 2-ContA 1 , REG : we consider -shaped arrays with the left vertical line having a length being a multiple of 3 and the right vertical line having a length being a multiple of 5.These arrays can easily be generated by a regular array grammar by first generating the left vertical line from up to down, followed by the horizontal line, finally generating the right vertical line upwards.On the other hand, this set of 2-dimensional arrays cannot be generated by a contextual array grammar even when using regular control: as soon as the vertical lines have become long enough, we cannot distinguish any more between the left and the right one, so either the lengths will not necessarily fulfill the constraints of being a multiple of 3 and 5, respectively, any more, or even worse, the lines might even be prolonged below the horizontal line yielding arrays of the shape of an H.

Decidability Questions
As the size of the arrays generated by contextual array grammars (even with any control mechanism) increases with every derivation step, the generated array languages are computable (i.e., recursive).
Yet for higher dimensions, we obtain a completely different situation: Theorem 9. Emptiness is not decidable for L d-ContA k , REG for d ≥ 2, even for k = 1.
Proof.(Sketch) As, for example, described in [5], the derivation carpet of a Turing machine can be described using 2-dimensional contextual array productions in the t-mode of derivation, i.e., a derivation only stops if no rule can be applied any more.The goal of only halting with specific conditions being fulfilled can also be obtained using suitable regular control languages, as we can require specific final rules to be applied.Hence, we will obtain a non-empty array language if and only if there is a derivation simulating the acceptance of a string by the given Turing machine.The proof given in [5] does not bound the number of symbols used.Yet m symbols can be encoded by 2 × m rectangles with the k-th of these m symbols being encoded by leaving the k-th position in the second vertical line free, which then can be checked by the selector in the contextual array productions.Hence, simulating successful computations of the given Turing machine will result in the generation of 2k × mn rectangles for accepting computations.

Picture Generation
Another interesting topic is to consider the generation of geometric objects such as solid rectangles and squares, which has been used to exhibit the generative power of various array grammar variants.Both of them, i.e., the 2-dimensional array language L rect of all solid rectangles of size m × n, m, n ≥ 2, made of a single symbol a and the 2-dimensional array language L square of all solid squares of side length n, n ≥ 2, made of a single symbol a are well-known to be in L 2-REGA 1 , see [23], but as we are able to show they can also be generated by 2-dimensional contextual array grammars with regular control, i.e., {L rect , L square } ⊂ L 2-ContA 1 , REG .We now only exhibit the contextual array grammar with regular control for the squares.The rules are listed in the following: Notice that the rules s ur and s dl check if a complete new border layer was actually generated, so they provide "keystones" as used in architecture, and it somehow replaces the t-mode of derivation, e.g., see [6].
As already with the t-mode of derivation, e.g., see [6], only eight contextual array rules were needed in Example 9 to generate the squares.This shows that the ability of contextual array grammars to insert new parts on different positions in the current array allows for a significantly smaller number of rules when using specific control mechanisms as the t-mode of derivation or regular control languages, in comparison with the construction of an extended regular array grammar as described in [23], where the construction has to be carried out along a Hamiltonian path.The inserted pieces used in [23] in fact could also be used as arrays inserted by a contextual array grammar with regular control, yet even for the subset of squares of side lengths 5k + 16, k ≥ 0, as exhibited in [23], 27 rules (arrays) were used.As these are in fact a kind of macro-rules, a complete list of regular array rules based on [23] would correspond to about one thousand rules.This is an example showing that contextual array grammars may allow for a succinct description of specific picture languages with rather small descriptional complexity.
An example of these L-shaped arrays (for n = 3 and m = 4) from [L 1 ] can be depicted as shown on the left.Observe that both arms of these arrays can have arbitrary lengths.Definition 1.A regular d-dimensional array grammar is specified as G = (d, N, T, #, P, {(v S , S})) where N is the alphabet of non-terminal symbols, T is the alphabet of terminal symbols, N ∩ T = ∅, # / ∈ N ∪ T ; P is a finite non-empty set of regular d-dimensional array productions over N ∪ T, as well as v S ∈ Z d and S ∈ N is the start symbol.A regular d -dimensional array production either is of the form A → b, A ∈ N , b ∈ T , or Av# → bC, A, C ∈ N , b ∈ T , v ∈ Z d with v = 1.The application of A → b means replacing A by b in a given array.Av# → bC can be applied if in the underlying array we find a position u occupied by A and a blank symbol at position u + v; A then is replaced by b, and # by C. The array language generated by G is the set of all d-dimensional arrays derivable from the initial array {(v S , S)}.The family of Λ-free d-dimensional array languages (of equivalence classes) of arrays over a k-letter alphabet generated by regular d-dimensional array grammars is denoted by L d-REGA k ( L d-REGA k ).For arbitrary alphabets, we omit the superscript k.

Remark 1 .
The special type of d-dimensional contextual array grammars where axioms are connected and rule applications preserve connectedness is denoted by d-ContA, the corresponding family of d-dimensional array languages by L (d-ContA); by L d-ContA k we denote the corresponding family of d-dimensional array languages over a k-letter alphabet.As we mostly are interested in (families of) equivalence classes of arrays, a d-dimensional contextual array grammar [G] for generating [L] for L ∈ L (d-ContA) being generated by a d-dimensional contextual array grammar

3. 1 Example 5 .
Matrix Contextual Array Grammars Definition 3. A d-dimensional matrix contextual array grammar is a pair G M = (G, M ) where G = (d, V, #, P, A) is a d-dimensional contextual array grammar and M is a finite set of sequences, called matrices, of rules from P , i.e., each element of M is of the form p 1 , • • • , p n , n ≥ 1, where p i ∈ P for 1 ≤ i ≤ n.Derivations in a matrix contextual array grammar are defined as in a contextual array grammar except that a single derivation step now consists of the sequential application of the rules of one of the matrices in M, in the order in which the rules are given in the matrix.The array language generated by G M is the set of all d-dimensional arrays which can be derived from any of the axioms in A. The family of d-dimensional array languages of arrays generated by d-dimensional matrix contextual array grammars (over a k-letter alphabet) is denoted by L (d-M ContA) (L d-M ContA k ).Consider the language L 2 of connected arrays given byL 2 = ((0, 0) , a) ∪ ((0, i) , a) , ((i, 0) , a) | 1 ≤ i ≤ n n ∈ N ,which contains L-shaped arrays as L 1 from Example 1, but now with both arms having the same length.L 2 ∈ L 2-M ContA 1 , as it can be generated by the 2-dimensional matrix contextual array grammar G M = (G 1 , M ) where G 1 is the 2-dimensional contextual array grammar from Example 3 and M = { p u , p r }.The only derivations possible in G M for [L 2 ] ∈ L 2-M ContA 1 (see Remark 1) are:

Theorem 3 .
For any d ≥ 2 and any k ≥ 1, we have L d-ContA k L d-M ContA k and L d-ContA k L d-M ContA k .Proof.The inclusion L d-ContA k ⊆ L d-M ContA k and therefore also L d-ContA k ⊆ L d-M ContA k is obvious from general results for grammars working on various kinds of objects and with specific regulating mechanisms, see [10].For showing the strictness of the inclusion, we prove that the array language L 2 from Example 5 cannot be generated by a 2-dimensional contextual array grammar; for dimensions d > 2, we just take [i 2,d (L 2 )] .Now assume we could find a 2-dimensional contextual array grammar [G = (2, {a} , #, P, A)] that generates [L 2 ].As contextual grammars are pure grammars, [A] is a finite subset of [L (G)].As [L (G)] is infinite, we would need an infinite number of rules to get [L 2 ] which resembles the case of external contextual string grammars; in fact, as soon as the arms get long enough, we have to apply a rule which only grows the arm going up or only grows the arm going to the right, resulting in an array which contradicts the definition of [L 2 ].It is obvious that we also have [i 2,d (L 2 )] ∈ L d-M ContA k \ L d-ContA k ; this observation completes the proof.

as the following example shows. Example 6 .
Consider the non-regular language L n = {a n ba n | n ≥ 1}.By Theorem 1, there cannot exist an array grammar G of type 1-REGA 2 such that [L (G)] = [arr (L n )].

Example 7 .
Consider the regular string language L r = {ba n b | n ≥ 1}.Due to Theorem 1, there exists an array grammar of type 1-REGA 2 G r such that [L (G r )] = [arr (L r )].Yet on the other hand, there cannot exist an array grammar of type 1-M ContA 2 [G] such that L ([G]) = [arr (L r )], which can be proved by a simple pumping argument: The number of symbols a between the two symbols b can become arbitrarily large, but we only have a finite set of axioms A; as [G] is a pure grammar, [A] ⊂ [L]; yet [G] can only grow these arrays in an external way, i.e., by adding symbols on the left or on the right, but in this way we are not able to grow the number of symbols a in the middle.

Theorem 8 .
For any d ≥ 2 and any k ≥ 1, all the three families L d-ContA k , L d-M ContA k , and L d-ContA k , REG are incomparable with L d-REGA k .

Example 9 .
L square is generated by the 2-dimensional contextual array grammar with regular control G squareRC = (G square , C square ) with G square = ({a}, P square , A square ), where A square collects the 2 × 2 and 3 × 3 squares, P square = {s ul , s dr , s ur , s dl , r ul , r uu , r dr , r dd } , and C square = ({s ul s dr } {r ul r dr } * {r uu r dd } * {s ur s dl }) + .
How to derive a 4 × 4 square is shown below: