1 Introduction

Kolam-designs are visually pleasing geometric diagrams that are drawn in the ground mostly at the entrance of a home [1, 5], with this age-old tradition being more prevalent in South India. A kolam is generally drawn starting with a certain number of points arranged in a particular pattern, with curly lines being drawn around these points, resulting in the intended “kolam” drawing. In fact there are very intricate and complicated kolam patterns used by the kolam practitioners. Motivated by these “kolam” floor-designs Siromoney et al. [8], in the years 1972–74, proposed picture generating models, called array grammars, and described a technique [8], referred to as Narasimhan’s method, for the generation of kolam patterns using these array grammars. Subsequently, several researchers have developed a variety of picture-array models. These grammars make use of two-dimensional extension of Chomsky type of string grammars or contextual type of string grammars [7] in the area of formal languages. On the other hand a bio-inspired computing model with a generic name of P system was introduced by Paun [6] which has turned out to be a versatile model with applications in different areas, with the area of picture array generation being one among these application areas. Several P system models have been proposed for picture array generation [2, 9]. Based on contextual type array generating rules [4], an array P system, called contextual array P system (CAP) has been introduced in [3]. Here we construct CAP for generation of kolam patterns that cannot be handled by contextual array grammars [4] utilizing the technique of Narasimhan’s method of kolam generation.

2 Preliminaries

We recall needed notions and related results [3, 4]. A point \(p = (m,n)\) in the two-dimensional digital plane with integer coordinates mn,  is identified with a unit closed square and is called a pixel or cell. The pixels \(p_1 = (m-1, n),\) \(p_2 = (m+1, n),\) \(p_3 = (m, n-1)\) and \(p_4 = (m, n+1),\) are neighbours of the pixel \(p = (m,n). \) Now let V be a finite set of symbols, referred to as an alphabet and \(\# \) a symbol not belonging to V. A two-dimensional picture array (or simply called an array) over V is a finite set of connected pixels labeled by the symbols of V. It is sufficient for our purposes to give an array in pictorial form without mentioning the coordinates of the pixels. Note that by connected picture array we mean that every pixel labelled by a symbol of V has at least another labelled pixel of the picture array as a neighbour. The symbol \(\# \) is used as a label of a pixel to indicate that it is empty i.e. it is not occupied by any label of V. When specifying a picture array we can list the coordinates of the pixels of the array with their labels in a formal manner but it is enough to specify the labels of the pixels of the array. We denote the set of all non-empty connected finite picture arrays over V by \(V^{++}.\) A subarray Y of an array X is a connected part of X. As an illustration, the picture array in Fig. 1(A) with each pixel having label a,  denotes a digitized form of the letter H while in Fig. 1(B), a labelled square array is shown with \(d_1,d_2,f_1,f_2,p_v,d\) being the labels of the pixels. A “kolam” pattern can be thought of as a picture array in the two-dimensional plane as described in [5] with the cells of the picture array labelled by primitive “kolam” patterns [5], a list of which as shown in Fig. 2 and an example “kolam” is shown in Fig. 3. We note that based on the “Narasimhan’s method” of “kolam” generation described in [8], a “kolam” pattern, which is composed of primitive “kolam” patterns, can be transformed into a picture array over the symbols of the primitive patterns and conversely. As an example, the picture array in Fig. 1(B) corresponds to the “kolam” in Fig. 3. Nagata and Robinson [5] propose an interesting view of a “kolam” as being composed of primitive kolam patterns, a partial list of which is given in Fig. 2.

Fig. 1.
figure 1

(A) An array representing the letter H; (B) a square array

Fig. 2.
figure 2

Kolam primitive patterns.

Fig. 3.
figure 3

A kolam pattern.

3 Contextual Array P System and “Kolam” Pattern Generation

In [3], contextual array P system is considered and several theoretical properties of this system are established. We first illustrate the manner of application of a rule of a contextual array grammar (CAG) [4] and then recall contextual array P system [3]. In a contextual array grammar (CAG) rule of the form \(r: \left( \alpha , \beta \right) \), the arrays \(\alpha \) and \(\beta \) are referred to as “selector” and “context” respectively. We restrict ourselves to the case with the “selector” and the “context” in the contextual array grammar rule not having empty pixels i.e. the “selector” and the “context" are connected and labeled only by symbols from an alphabet V and not by the blank symbol \(\#\). For arrays \(X, Y \in V^{++}\) where V is the alphabet, intuitively, if in X,  we find a subarray that corresponds to the selector \(\alpha \), and if the places (i.e. unit squares in the two-dimensional plane) corresponding to \(\beta \) are labeled only by the blank symbol \(\#\), then we can add the context \(\beta \) to \(\alpha \), thus deriving an array M and we write \(X \Longrightarrow _{G} M.\) If an array Z is obtained from an array X,  by a sequence of such steps, we write \(X \Longrightarrow _{G}^* Z.\) A maximal mode or t-mode of derivation, denoted \(\Longrightarrow _{G}^{t}\) corresponds to collecting only the arrays produced by blocked derivations, namely, derivations which cannot be continued. For a formal definition of CAG we refer to [4]. In the \(*\)-mode of derivation, all picture arrays derivable from an axiom are taken in the picture language (also called, array language) generated by G while in the t-mode of derivation, all picture arrays produced by blocked derivations constitute the picture language. We give an example of a contextual array grammar working in t-mode generating the array language \(L_1\) consisting of all picture arrays which are squares of side lengths \(2n+3, n \ge 1\), with the label pixels of the picture arrays belonging to V. In such a picture array of \(L_1,\) the first row is of the form \(d_1^{2n+3},\) the last row is of the form \(d_2^{2n+3}\) and every two adjacent rows starting from the second row are of the form \(f_1d^{2n+1}f_2\) and \(p_v^{2n+3}\) respectively. A \(5 \times 5 \) picture array of \(L_1\) is shown in Fig. 1(B) and represents the “kolam” in Fig. 3. We consider a contextual array grammar G with an axiom picture array \(A_1\), which is given in pictorial form: \(A_1 := \begin{array}{cc} f_1 &{} \\ d_2 &{} d_2\\ \end{array}\) The contextual array rules of G are given by the following pictorial forms where the pixels and symbols of the selector are indicated by enclosing them in boxes. In other words the rules \(p_i ( 1 \le i \le 17)\) are given as follows:

figure a

A maximal (that is, t-mode) derivation in G generating a \(5 \times 5\) picture array of the language \(L_1\) is done by the application of the rules \(p_1,p_2,p_4,p_5,p_7,p_8,p_6,p_{11},p_{11},p_{10},p_{12},f_{13},p_{17},p_{16},p_{12},p_{15}\) in this order. The first two steps of the derivation are shown below: \(\begin{array}{cc} f_1 &{} \\ d_2 &{} d_2 \\ \end{array} \,\Longrightarrow _{p_1}\, \begin{array}{ccc} &{} p &{} \\ f_1 &{} d &{} d \\ d_2 &{} d_2 &{}\\ \end{array} \,\Longrightarrow _{p_2}\, \begin{array}{cccc} &{} &{} d &{} \\ &{} p &{} p &{} p \\ f_1 &{} d &{} d &{} \\ d_2 &{} d_2 &{} &{} \end{array}\) It can be seen that the contextual array grammar rules of G generate the picture language \(L_1.\) In an array M of \(L_1\) if we replace each of the symbols by the corresponding primitive “kolam” pattern as in Fig. 2, then we obtain the “kolam” itself. For example the rectangular array in Fig. 1(B) yields the “kolam” in Fig. 3, when the symbols are substituted in this manner.

Informally expressed, the basic model of a rewriting array P system has a membrane structure \(\mu \) of a P system with m membranes, denoted by a well-formed expression of parentheses over the alphabet of left and right parentheses \([_i\) and \(]_i\), \(1 \le i \le m\). For example, \([_1\,[_2\,]_2\,[_3\,]_3\,]_1\) means that membrane 1 is the outermost membrane (also called skin membrane), which contains membranes 2 and 3. The membranes (also called regions) have arrays as objects and rewriting rules as evolution rules, which can be applied to the objects. The application of a rule at the level of a membrane is sequential but the objects in all the membranes are rewritten in a maximal parallel way in the sense that all objects that can be rewritten in the membranes should be rewritten. There is a target indication herein or out associated with every rule. The evolved array in a membrane is retained in the same membrane if the target is here and sent to an immediately inner membrane or outer membrane according as the target is in or out.

We now recall contextual array P system that has in its membranes, picture array objects and contextual array rules as in a contextual array grammar [4].

Definition 1

[3]. A contextual array P system with \(m\ge 1\) membranes is a construct \(\varPi =(V,\#,\mu ,X_1,\dots ,X_m, R_1,\dots ,R_m,i_o),\) where V is the alphabet; \(\#\) is the blank symbol; \(\mu \) is a membrane structure with m membranes or regions, labeled by \(1,\dots ,m\), in a one-to-one manner; \(X_1,\dots ,X_m\) are finite sets of arrays over V associated with the m regions of \(\mu \); \(R_1,\dots ,R_m\) are finite sets of contextual array rules over V associated with the m regions of \(\mu \); the rules have attached targets here, out, in, or \(in_j\), \(1 \le j \le m\); \(i_o\) is the label of a membrane called output membrane, wherein the results of successful computations are collected.

A computation step in a contextual array P system is done as follows: for each array \(\mathcal {A}\) in each region of the system, if a contextual array production p in the region can be applied to \(\mathcal {A}\), then it should be applied which means that the application of a rule is sequential at the level of arrays, but maximally parallel at the level of the whole system. If more than one rule is applicable at the same time, then one is chosen in a nondeterministic way. The resulting array, if any, is placed in the region indicated by the target associated with the rule having been applied with interpreting the attached target as follows: here means that the array remains in the same region, out means that the array exits the current membrane and is placed in the immediately outer membrane if one exists (we do not allow the target out to be used by a rule assigned to the skin membrane), \(in_j\) means that the array is immediately sent to the directly inner membrane with label j, and in means that the array is immediately sent to one of the directly inner membranes, chosen in a nondeterministic way if several such membranes exist (if no inner membrane exists, then a rule with the target indication in cannot be used). A computation is called successful if and only if it halts, which means that a configuration has been reached where no rule can be applied to the existing arrays. The result of a halting computation consists of the arrays collected in the membrane with label \(i_o\) in the halting configuration.

A variant of contextual array P system is considered in [10]. In this variant, instead of a sequential application of a contextual array grammar rule, a set of rules in a membrane with the same target is applied in parallel. The resulting array P system is called Parallel contextual array P system (PCAP). It has been shown in [10], that the advantage of this kind of a PCAP system is that the number of membranes required in the construction of such systems in generating picture languages, is reduced in comparison with the sequential CAP.

Fig. 4.
figure 4

P system “kolam”.

Fig. 5.
figure 5

Array representing P system “kolam”.

Fig. 6.
figure 6

Membrane structure

3.1 “Kolam” Generation Using PCAP

We now make use of PCAP in generating “Kolam” patterns. We consider the kind of “kolam” shown in Fig. 4. This kind of a kolam can be represented by an array as shown in Fig. 5. We consider the picture language \(L_2\) whose elements are picture arrays, one member of which is shown in Fig. 5. In fact in an array in \(L_2,\) the middle vertical column is a word of the form \(d_1(dp_vp_v)^{n-1}d(p_vp_vd)^{n-1}d_2, \, n \ge 1\) but written vertically while every symbol d in this column except the central symbol d has the symbol \(d_3\) to its immediate left and the symbol \(d_4\) to its immediate right. Also, the middle horizontal row is a word of the form \(d_3(dp_hp_h)^{n-1}d(p_hp_hd)^{n-1}d_4, \, n \ge 1\) while every symbol d in this row except the central symbol d has the symbol \(d_1\) immediately above it and the symbol \(d_2\) immediately below it. The picture language \(L_2\) is generated by a PCAP \(\varPi \) with a membrane structure \([_1 \, [_2 \, ]_2 \, ]_1\) as in Fig. 6. The region labelled 1 has an axiom array d while the region 2 has no array inside it initially. The region 2 is the output membrane where the picture arrays generated are collected which constitute the arrays in \(L_2.\) Region 1 has four rules \(r_1,r_2,r_3,r_4\) with target here and another four rules \(r_5,r_6,r_7,r_8\) with target in while region 2 has no rules. The rules are given below:

figure b

The generation of an array in \(L_2\) as in Fig. 5 in the PCAP \(\varPi \) takes place as follows: Starting with the axiom array d in region 1, the rules \(r_1,r_2,r_3,r_4\) are applied in parallel generating the array

$$\begin{aligned} \begin{array}{ccccccc} &{}&{}d_3&{}d&{}d_4&{}&{} \\ &{}&{}&{}p_v&{}&{}&{} \\ d_1&{}&{}&{}p_v&{}&{}&{}d_1 \\ d&{}p_h&{}p_h&{}d&{}p_h&{}p_h&{}d \\ d_2&{}&{}&{}p_v&{}&{}&{}d_2 \\ &{}&{}&{}p_v&{}&{}&{} \\ &{}&{}d_3&{}d&{}d_4&{}&{} \\ \end{array}. \end{aligned}$$

The array remains in region 1 as the target indication of the rules \(r_1,r_2,r_3,r_4\) is here. The process can be repeated. When the rules \(r_5,r_6,r_7,r_8\) are applied in parallel, then the array generated is sent to region 2, due to the target in in the rules \(r_5,r_6,r_7,r_8.\) Since region 2 is the output membrane and does not contain any rule, the array is collected in the picture language \(L_2 \).

In every array in \(L_2\) if we replace as in Narasimhan’s method [8], the label (or symbol) of every pixel by the corresponding primitive “kolam” pattern from the list in Fig. 2, then we obtain a “kolam” which will be an enlarged version of the “kolam” in Fig. 4. In fact when the rules \(r_1,r_2,r_3,r_4\) are applied in parallel once and the rules \(r_5,r_6,r_7,r_8\) are then applied once in parallel, the array generated is as in Fig. 5. The “kolam” derived from this array by Narasimhan’s method is indeed the “kolam” shown in Fig. 4.

We have shown that a class of “kolams”, an example of which is shown in Fig. 4, can be generated by the P system, namely, parallel contextual array P system (PCAP) [10]. It can be shown that the same “kolam” class can be generated by a contextual array P system (CAP) [3] but it will require more number of membranes while the PCAP considered requires only two membranes and thus is a simpler model for “kolam” generation. But a PCAP with one membrane is not enough to generate this “kolam” class as the rules can have the only target here and so the rules \(r_1\) to \(r_8\) need not be applied in the combination of rules mentioned earlier, namely, \(r_1,r_2,r_3,r_4\) together and \(r_5,r_6,r_7,r_8\) together in parallel. But then the number of pixels in the vertical middle column in Fig. 4 above and below the central symbol d as well as in the horizontal middle row in Fig. 4, in the right and left of the central d,  need not be the same.

4 Concluding Remarks

We have considered the problem of generation of kolam-designs, in the framework of the computability model of P system. The intricate kolam designs are very good examples of visual expressions of creative thought [1] and can be considered as diagrams that could be classified under “art” in a very broad sense. The contextual array P (CAP) system model considered here makes use of certain kinds of rules of object generation, thus providing a novel approach to handle such kolam designs. It will be of interest to consider more complex “kolam” patterns and examine the ability of the contextual array P system in handling such patterns.