CENTER FOR MACHINE PERCEPTION
New Models for Recognition of Picture Languages: Sgraffito and Restarting Tiling Automata
CZECH TECHNICAL
Daniel Pr˚ uˇsa, Frantiˇsek Mr´az1
UNIVERSITY IN PRAGUE
[email protected],
[email protected] 1
Charles University, Faculty of Mathematics and Physics Department of Computer Science Malostransk´e n´am. 25, 118 25 Prague 1
CTU–CMP–2012–08
Available at ftp://cmp.felk.cvut.cz/pub/cmp/articles/prusa/Prusa-TR-2012-08.pdf The authors were supported by the Grant Agency of the Czech Republic: the first author under the project P103/10/0783 and the second author under the projects P103/10/0783 and P202/10/1333. Research Reports of CMP, Czech Technical University in Prague, No. 8, 2012 ISSN 1213-2365
RESEARCH REPORT
March 20, 2012
Published by Center for Machine Perception, Department of Cybernetics Faculty of Electrical Engineering, Czech Technical University Technick´a 2, 166 27 Prague 6, Czech Republic fax +420 2 2435 7385, phone +420 2 2435 7637, www: http://cmp.felk.cvut.cz
Abstract We introduce two new models of two-dimensional computing devices called sgraffito automaton and restarting tiling automaton. The models fulfill two conditions. Firstly, they do not exceed the power of finite-state automata when working over one-dimensional inputs. And secondly, they allow a clear design of important computations. We study properties of the induced families of picture languages. We show that they include strictly REC and that restarting tiling automata are able to simulate sgraffito automata. An interesting family is settled by deterministic sgraffito automata. It can be seen as an alternative to DREC.
1
Introduction
The theory of two-dimensional languages generalizes concepts and techniques from the theory of formal languages. The basic element, which is a string, is extended to a two-dimensional array, usually called a picture. Various classes of languages over pictures can be formed, especially by generalizing one-dimensional computational or generative models, which possibly leads to some two-dimensional variant of the Chomsky hierarchy. A natural question is to ask, whether the classes inherit properties of their one-dimensional counterparts. The answer is typically negative. A more complex topology of pictures causes that families of picture languages are of a different founding. A four-way finite automaton (4FA) can serve as a good example. It is a finite-state device composed of a control unit equipped with a head moving over an input picture in four directions: left, right, up and down. Even the automaton is a simple extension of (one-dimensional) two-way finite automaton, the formed family of languages shows properties different to those of regular languages [6]. In 1991, D. Giammaresi and A. Restivo proposed the family of recognizable languages (REC) [5]. The languages in REC are defined using tiling systems. They also coincide with the languages recognizable by the two-dimensional on-line tessellation automata [8] or definable on existential monadic second order logic. The family is well established. It has many remarkable properties and the defined recognizability is a very robust notion. It is even presented as the ground-level class among the families of two-dimensional languages. The non-determinism exhibited by REC makes it quite powerful. There are even NP-complete problems belonging to REC [10]. It contradicts the vision of a ground level class, taking into account the simplicity of resources sufficient to recognize (one-dimensional) regular languages. This fact has inspired the further proposal of deterministically recognizable languages. The related family DREC has been characterized and studied in [1]. 1
In this report, we introduce two new models of two-dimensional computing devices – sgraffito automata and restarting tiling automata. We show that sgraffito automata can be simulated by restarting tiling automata. Moreover, both induced classes of picture languages strictly include REC, have the same closure properties as REC and collapse to the class of regular languages for one-row pictures. The same statement can be claimed for the deterministic variants of the classes. They strictly include DREC and exhibit the same closure properties. This clearly demonstrates the importance of the proposed classes and the models. We bring an extension to REC and DREC, respectively, that still keeps all its good properties.
2
Basic definitions
In this section, we give some definitions of two-dimensional (2D) objects and languages. We extend the basic notations from the theory of onedimensional languages and we define some 2D specific operations. The notation comes mainly from [6]. Definition A picture over a finite alphabet Σ is a two-dimensional rectangular array of elements from Σ. The set of all pictures over Σ is denoted by Σ∗,∗ . A picture language over Σ is a subset of Σ∗,∗ . Let P be a picture over Σ. We denote the number of rows and columns of P by rows(P ) and cols(P ), respectively. The pair (rows(P ), cols(P )) is called the size of P . The empty picture Λ is defined as the only picture of the size (0, 0). The set of all pictures of size (m, n) over Σ is denoted by Σm,n . Assuming 1 ≤ i ≤ rows(P ) and 1 ≤ j ≤ cols(P ), P (i, j) (or shortly Pi,j ) identifies the symbol in the i-th row and the j-th column in P . Two (partial) binary operations are used to concatenate pictures. Let P and Q be pictures over Σ of sizes (k, l) and (m, n), respectively. The horizontal concatenation P dQ is defined iff k = m, the vertical concatenation P dQ is defined iff l = n. The corresponding products are depicted below:
P dQ =
P1,1 . . . P1,l Q1,1 . . . Q1,n .. .. .. .. .. .. . . . . . . Pk,1 . . . Pk,l Qm,1 . . . Qm,n
P1,1 .. . Pk,1 P dQ = Q1,1 .. .
... .. . ... ... .. .
P1,l .. . Pk,l Q1,n .. .
Qm,1 . . . Qm,n We also define Λ dP = P dΛ = Λ dP = P dΛ = P for any picture P .
2
In addition, we introduce the clockwise rotation P R , vertical mirroring and horizontal mirroring P HM .
P VM
P
R
Pm,1 . . . P1,1 .. .. .. = . . . Pm,n . . . P1,n
P
HM
P
VM
P1,n . . . P1,1 .. .. .. = . . . Pm,n . . . Pm,1
Pm,1 . . . Pm,n .. .. .. = . . . P1,1 . . . P1,n
Remark Note that the vertical mirroring can be expressed by the horizontal mirroring and rotation (and vice-versa). P
VM
=
P
R HM R
R .
Let π : Σ → Γ be a mapping between two alphabets. The projection by π of P ∈ Σm,n is the picture P 0 ∈ Γm,n such that P 0 (i, j) = π (P (i, j)) for all 1 ≤ i ≤ m, 1 ≤ j ≤ n. We can extend all introduced operations to languages. Let L, L0 be picture languages over Σ and π : Σ → Γ be a mapping. Then L dL0 L dL0 π (L) LR VM L LHM
= = = = = =
{P dP 0 | P ∈ L ∧ P 0 ∈ L0 }, {P dP 0 | P ∈ L ∧ P 0 ∈ L0 }, {π(P ) | P ∈ L}, {P R | P ∈ L}, {P VM | P ∈ L}, {P HM | P ∈ L}.
Let S = {`, a, >, ⊥, #} be a set of special markers (sentinels), Σ be a finite alphabet such that Σ ∩ S = ∅ and P ∈ Σm,n be a picture over Σ of size m × n. We define a boundary picture of P as picture Pb over Σ ∪ S of size (m + 2, n + 2). Its symbols are given by the following scheme. # > > ... > > ` .. . P ` # ⊥ ⊥ ... ⊥ ⊥
3
# a .. . a #
Formally P (i − 1, j − 1) ` a > Pb(i, j) = ⊥ #
3
for 2 ≤ i ≤ m + 1 and 2 ≤ i ≤ n + 1, for 2 ≤ i ≤ m + 1 and j = 1, for 2 ≤ i ≤ m + 1 and j = m + 2, for i = 1 and 2 ≤ j ≤ n + 1, for i = n + 2 and 2 ≤ i ≤ n + 1, for (i, j) ∈ {(1, 1), (1, n + 2), (m + 2, 1), (m + 2, n + 2)} .
REC, DREC, tiling systems
The two-dimensional on-line tessellation automaton, proposed by K. Inoue and A. Nakamura [8], is a restricted type of cellular automaton. For an input P ∈ Σ∗,∗ , a computation is performed in rows(P )+cols(P )−1 parallel steps. During the k-th step, each cell at a coordinate (i, j), where i + j − 1 = k, performs a state-transition depending on P (i, j) and the final states of the left and top neighbor cells. If the neighbor lies at the border of P , then it is a fictive cell and its final state is defined as the corresponding symbol in Pb. The result of the computation is determined by the final state of the bottom right cell. A formal definition follows. Definition A two-dimensional on-line tessellation automaton (2OTA) is a tuple A = (Q, Σ, δ, QA ), where • Σ is an input alphabet, • Q is a finite set of states, such that Σ ∪ S ⊆ Q, • QA ⊆ Q is the set of accepting states, and • δ : Q × Q × Q → 2Q is a transition relation. We call a tile each picture of the size (2, 2). Given a picture P , we denote B2,2 (P ) the set of all tiles that are subpictures of P . Let Θ be a set of tiles over Γ ∪ S. Define a language L(Θ) as follows n o L(Θ) = P | P ∈ Γ∗,∗ ∧ B2,2 (Pb) ⊆ Θ . We say a language L is local if there exists a set of tiles Θ such that L = L(Θ). The family of all local languages is denoted LOC. Definition A tiling system (TS) is tuple T = (Σ, Γ, Θ, π), where Σ and Γ are finite alphabets, Θ is a finite set of tiles over Γ ∪ S and π : Γ → Σ is a mapping.
4
The tiling system T defines the language L = π(L0 ) over Σ, where L0 = L(Θ). We say that L is tiling recognizable. The families L(TS) and L(2OTA) are identical [5]. Related languages are referred simply as recognizable twodimensional languages and the family is denoted by REC. The projection implants a non-determinism to REC. One possibility to get rid of it is to require that each tile of the final picture corresponds to a single tile in the underlying local language. This is the idea behind the family DREC. Definition A tiling system T = (Σ, Γ, Θ, π) is tl2br-deterministic if for all γ γ2 γ1 , γ2 , γ3 ∈ Γ ∪ S and σ ∈ Σ there exists at most one tile 1 ∈ Θ, γ3 γ4 such that π(γ4 ) = σ. The abbreviation tl2br stands for top-left to bottom-right and denotes a corner-to-corner direction in a picture. Analogously, a d-deterministic tiling system is defined for three more directions (tr2bl, br2tl, bl2tr ). A recognizable picture language L is in DREC if it admits a d-deterministic tiling system for some corner-to-corner direction. If tiling systems and 2OTA’s are restricted to one row input pictures, then their recognition power coincides with the power of finite-state automata. Several other important properties of REC and DREC are listed below. • REC is not closed under the complement operation, • DREC is not closed under the concatenation (vertical, neither horizontal) and the projection operations, • DREC is strictly included in REC, • L(4FA) is strictly included in REC and incomparable with DREC, and • DREC equals the closure under rotation of L(2DOTA).
4
Sgraffito automata
Let H = {R, L, D, U, Z} be the set of head movements. First four elements denote directions: left, right, up, down. Z stands for zero (none) movement. We define a mapping ν : S → H such that ν(`) = R,
ν(a) = L,
ν(>) = D,
ν(⊥) = U and
ν(#) = Z.
Definition A (non-deterministic) two-dimensional bounded Turing machine, bounded 2TM for short, is a tuple A = (Q, Σ, Γ, δ, q0 , QF ) where • Σ is an input alphabet, 5
• Γ is a working alphabet such that Σ ⊆ Γ and Γ ∩ S = ∅, • Q is a finite, nonempty set of states, • q0 ∈ Q is the initial state, • QF ⊆ Q is the set of final states, and • δ : (Q \ QF ) × (Γ ∪ S) → 2Q×(Γ∪S)×H is a transition relation. Moreover, for any pair (q, a) ∈ Q × (Γ ∪ S), each element (q 0 , a0 , d) ∈ δ (q, a) satisfies: • a ∈ S implies d = ν(a) and a0 = a, and • a∈ / S implies a0 ∈ / S. If for for each q ∈ Q and a ∈ Γ ∪ S we have |δ(q, a)| ≤ 1, we say that A is deterministic 2TM. Let P ∈ Σ∗,∗ be an input to a bounded 2TM A. In the initial configuration of A on P , its tape contains Pb, its control unit is in state q0 and the head scans the top-left corner of P . When P = Λ, the head scans the bottom-right corner of Pb containing #. The machine accepts P iff there is a computation of A starting in the initial configuration on P and finishing in an accepting state from QF . Definition Let M = (Q, Σ, Γ, δ, q0 , QF ) be a bounded 2TM. Let us assume that each computation of M over any P ∈ Σ∗,∗ is finite. Then, the time complexity of M is a function t : N × N → N defined as t(m, n) = max t(P ), m,n P ∈Σ
where t(P ) is the number of steps of the longest computation over P . Definition A sgraffito automaton (Q, Σ, Γ, δ, q0 , QF , µ) where
(2SA)
is
a
tuple
A
=
• (Q, Σ, Γ, δ, q0 , QF ) is a two-dimensional bounded Turing machine, • µ : Γ → N is a weight function and • the transition relation satisfies (q 0, a0, d) ∈ δ(q, a) ∧ a ∈ / S ⇒ µ(a0 ) < µ(a) for all q, q 0 ∈ Q, d ∈ H, a, a0∈ Γ∪S . A is a deterministic 2SA, if the underlying 2TM (Q, Σ, Γ, δ, q0 , QF ) is deterministic. 6
In contrast to 2TM, all computations of an 2SA are finite. Lemma 4.1 Let A = (Q, Σ, Γ, δ, q0 , QF , µ) be a 2SA and t(m, n) be its time complexity. Then t(m, n) = O(mn). Proof Let P be a non-empty picture in Σ∗,∗ of size (m, n). When computing over P , during each step A either decreases the weight of a scanned symbol or moves its head back from a border field containing a sentinel. Hence, at least one of two consecutive steps decreases the weight of some field. Since there are mn fields storing initially P and the weight of a field can be decreased at most |Γ| − 1 times, A can perform at most 2mn (|Γ| − 1) steps.
Lemma 4.2 Let M = (Q, Σ, Γ, δ, q0 , QF ) be a bounded Turing machine. Let k ∈ N be an integer such that during each computation of M over any picture in Σ∗,∗ each tape field is visited at most k times. Then, there is a 2SA A such that L(A) = L(M). Moreover, if M is deterministic, A is deterministic too. Proof Define A = (Q, Σ, Γ2 , δ2 , q0 , QF ), where Γ2 = Σ ∪ Γ × {1, . . . , k} and each instruction (q, a) → (q 0 , a0 , d) from δ is represented in δ2 by the following instruction set: (q, a) → (q 0 , (a0 , 1) , d) (q, (a, i) , d) → (q 0 , (a0 , i + 1) , d)
∀i ∈ {1, . . . , k − 1}.
Finally, µ(a) = k µ ((a, i)) = k − i
∀a ∈ Σ ∀(a, i) ∈ (Γ × {1, . . . , k}) .
It should be clear that no configuration in which A scans (a, k) (for some a ∈ Γ) is reachable. Moreover, if δ is a deterministic transition relation, then δ2 is deterministic as well. The following definition is a two-dimensional generalization of the crossing sequence defined in [7]. Definition Let M = (Q, Σ, Γ, δ, q0 , QF ) be a bounded two-dimensional Turing machine, P an input picture, i an integer such that 1 ≤ i ≤ cols(P ) + 1, and let C = (c0 , c1 , . . . , cm ) be an m-step computation of M over P , for some m ≥ 0. The horizontal crossing sequences of C between columns i and i + 1, denoted Ki (i = 1, . . . , cols(P ) + 1), are constructed using the following algorithm: 1. Initialize Ki := {q0 } for i = 1, and Ki := ∅ for i = 2, . . . , cols(P ) + 1. 7
2. Iterate through all configurations in C = (c0 , c1 , . . . , cm ), except the last one. Let cj be the current one. Consider the computation step of M that changes cj to cj+1 . If the head is moved from the i-th column to the i + 1-st column or vice versa, append (q, r) to Ki , where r denotes the index of row the head is placed on and q is the state entered by the control unit in cj+1 . Continue with the next iteration. The horizontal crossing sequence Ki records all head movements between tape’s column i and i + 1. The first item of Ki records the state in which column i + 1 was visited for the first time by a move from the left (except for K1 which starts with the initial state q0 ) and further in Ki alternate states corresponding to moves from the column i + 1 to the column i and the states corresponding to moves from the column i to the column i + 1. Note that vertical crossing sequence could be defined analogously for crossings between two neighboring rows. For our purposes, we do not need this second definition. For a picture Q, let τ (left, Q, k) denote the portion of the tape occupied b and let τ (right, Q, j) be the portion of the by the first k + 1 columns of Q b (in the initial contape occupied by the columns k + 2, . . . , cols(Q) + 2 of Q figuration for the input Q). If we know the content of one of τ (left, Q, k) or τ (right, Q, j), the crossing sequence between columns k and k + 1 determines how the part will change during the computation, even without knowledge of the content of the second part. For example, let the left part be known. Then, each time the head reenters the left part from the right part, the entry point and the current state are uniquely determined by the crossing sequence, thus it is possible to simulate the computation until the head leaves the left part again. This observation is used in the following lemma. Proposition 4.3 Let M be a bounded two-dimensional Turing machine. Let us assume M accepts two pictures: PA = A1 dA2 d. . . dAm and
PB = B1 dB2 d. . . dBn ,
where A1 , . . . , Am , B1 , . . . , Bn are one-column pictures. Let CA and CB be accepting computations of M over PA and PB , respectively. Let us further assume there are two integers i, j such that 1 ≤ i < m, 1 ≤ j < n, and the crossing sequence between i and i + 1 in CA and the crossing sequence of M between j and j + 1 in CB are identical. Then M accepts P = A1 d. . . dAi dBj+1 d. . . dBn .
8
Proof The computation of M in τ (left, P, i) and τ (rigth, P, i) is exactly the same as the computation of M in τ (left, PA , i) and τ (right, PB , j), respectively. In both cases, whenever M leaves the left part, it enters the right part in the state and row determined by the crossing sequence. Proposition 4.4 Let M = (Q, Σ, Γ, δ, q0 , QA ) be a bounded twodimensional Turing machine having time complexity t, P be an input picture over Σ, C a computation. Then the sum of the lengths of all different nonempty crossing sequences related to C is at most t(rows(P ), cols(P )). Proof Inspecting the algorithm defining crossing sequences, we can see that each horizontal head movement contributes to one of the considered crossing sequences. The number of head movements is bounded by the number of computation steps. A one-dimensional sgraffito automaton (SA) is a sgraffito automaton working over one-row pictures. It never moves the head up, neither down. In such a case, it is sufficient to consider the initial content of the input tape to be of the form ` w a, where w ∈ Σ∗ is an input. At the beginning, the head scans the field next to `, which contains the first character of w or a if w = λ. We show that SA’s can be simulated by finite-state automata, thus implying L(SA) = REG. Theorem 4.5 Let A1 = (Q, Σ, Γ, δ, q0 , QF , µ) be a (one-dimensional) SA. There is a finite-state automaton A2 such that L(A2 ) = L(A1 ). Proof Without losing any generality, we assume that A1 always moves the head when it performs an instruction. Moreover, if it enters a state in QF , the head finishes at the end of input. Let C be an accepting computation of A1 over some w ∈ Σ∗ of the length n. The proof is based on a representation of C by a directed multigraph. In the initial configuration, the working tape contains ` w a in fields f0 , f1 , . . . fn+1 . We take the fields as vertices of the multigraph. Edges are defined algorithmically as follows. Let c(fi ) be an integer counter assigned to fi , initially set to 0. Iterate trough instructions given by C in the natural order in which they are performed. Let (q, a) → (q 0 , a0 , d) be the current one, applied when the head scans fi and moves then to fj , where j ∈ {i−1, i+1}. Then, the counters c(fi ), c(fj ) are increased by 1 and (fi , fj ) is added to the graph. The edge is labeled by the instruction and two numbers, the outgoing index c(fi ) and the incoming index c(fj ). Figure 4 shows an example of such constructed multigraph. It is easy to see, the computation can be reconstructed based on the graph, outgoing and incoming indices determine an Eulerian trail starting in f1 and ending in fn . It traverses instructions on the edges in the order in which they are performed in C.
9
(q0,b)→(q1,b1,R)
1
`
b
(q1,b)→(q2,b1,R)
1
2
b
(q2,b1 )→(q3,b2,R) 4 3
(q3,a1 )→(q3,a2,R) 4
1
3 2
(q2,a)→(q2,a1,L)
1
a
a 5
2
(q3,a)→(qf,a,L)
Figure 1: A multigraph representing an accepting computation consisting of six instructions. The numbers assigned to the beginnings and ends of edges, respectively depict outgoing and ingoing indices. Nodes are labeled with symbols initially stored on the tape. Given a directed multigraph G on vertices f0 , . . . , fn+1 , where nodes are labeled with symbols from Σ ∪ {`, a} and edges by instructions from δ and by outgoing and incoming indices, we describe, how to check whether the graph is a correct representation of some accepting computation of A1 . Two properties have to be preserved. The first one is related to the graph structure – the Eulerian trail from f1 to fn has to exist. We say, an edge is incoming to fi from the left or from the right if it goes from fi−1 or fi+1 , respectively, to fi . Analogously, there are defined outgoing edges from fi to the left and to the right. Let E(i) be the sequence of outgoing and incoming edges from/to fi , sorted by their indices in the ascending order. Consider fk such that 2 ≤ k ≤ n − 1 and E(k) = {e1 , . . . , es }. If G is a correct representation, then 1. s ≥ 2 and it is an even number 2. if ej is incoming to fk , then j is odd, otherwise j is even 3. e1 is incoming to fk from the left, es is outgoing from fk to the right 4. for each j < s, if ej is outgoing to the left or to the right, then ej+1 is incoming from the right or from the left, respectively. Similar conditions can be stated for f0 , f1 , fn and fn+1 . Specifically, E(1) contains an odd number of edges and the first edge is outgoing from f1 . Now, assume G satisfies the conditions. Construct a directed path, starting in f1 , traversing edges in the order determined by outgoing indices. This process ends in fn , since all nodes, except f1 and fn , has the number of incoming and outgoing edges. By contradiction, let there be edges not contained in the constructed path. Take such an edge (fi , fi−1 ) where i is maximal possible. Assuming the first three conditions are fulfilled, the fourth one is violated. The second property relates to the sequence of instructions induced by the trail. They have to define an admissible accepting computation. Consider a node fi , labeled by a ∈ Σ, and an outgoing edge (from fi ) of outgoing index j. Let the edge be labeled (q1 , a1 ) → (q10 , a01 , d1 ). If j = 1, then fi = f1 10
and (q1 , a1 ) has to equal (q0 , a). Otherwise, there is an incoming edge of index j − 1, labeled (q2 , a2 ) → (q20 , a02 , d2 ). In this case q1 has to equal q20 . Furthermore, if j > 2, there is an outgoing edge with outgoing index j − 2, labeled (q3 , a3 ) → (q30 , a03 , d3 ). Now, a1 has to equal a03 , otherwise it has to equal a. Finally, the last incoming edge to fn has to be labeled by an instruction which ends in some q ∈ QF . Note that both properties can be verified locally per each node (taking into account its edges). This allows to design a non-deterministic finite-state automaton A2 that non-deterministically guesses a multigraph representing an accepting computation of A1 . The graph is built in the states, from f0 to fn+1 . Before constructing fi , where i > 0, A2 moves the head to the field fi . At any time, A2 needs to represent one node (plus the coinciding edges) fulfilling the required properties. Since the incoming and the outgoing degree of each node is limited by |Γ|, finitely many states suffice to perform the task. Theorem 4.6 L(4FA) is included in L(2DSA). Proof Let A = (Q, Σ, δ, q0 , QF ) be a 4FA and P be an input over Σ. Define a directed graph G = (V, E) as follows: • vertices are all triples of the form (q, i, j), where 1 ≤ i ≤ rows(P ) + 2, 1 ≤ j ≤ cols(P ) + 2 and q ∈ Q, • ((q1 , i1 , j1 ), (q2 , i2 , j2 )) is an edge in E iff δ contains (q1 , Pb(i1 , j1 )) → (q2 , d) and (i2 , j2 ) is the coordinate next to (i1 , j1 ) in the direction given by d. A accepts P iff there is a vertex (qf , i, j) reachable from (q0 , 2, 2) and qf ∈ QF . To decide this, it suffices to perform a depth first search in G. We give a related procedure that labels visited nodes and edges. Vertices are in two states – unexplored and explored, edges in three states – unexplored, tree edge, cross edge. In both cases, unexplored state is the initial one. 1: v := (q0 , 2, 2) 2: label v as explored 3: if v represents an accepting configuration then 4: ACCEPT 5: end if 6: if there is an unexplored edge e = (v, w) then 7: if w is unexplored then 8: label e as tree edge, move to w, set v := w 9: goto 2 10: else 11: label e as cross edge 11
goto 6 end if 14: else if there is an incoming tree edge (u, v) then 15: move to u, set v := u 16: goto 6 17: end if 18: REJECT Labels of a vertex (q, i, j) as well as its outgoing edges can be recorded in the tape field storing Pb(i, j). The exceptions are vertices on the border, their labels are represented in the nearest tape field storing an inner part of Pb. Since each vertex has the number of outgoing edges limited by | H | · |Q|, the proposed algorithm can be performed by a 2DSA – a constant memory usage as well as a constant number of traversals are guaranteed for each tape field. 12: 13:
5
Lower bound on time complexity
We use the crossing sequence tool and the proved lemmas to derive results on lower bounds on time complexity. Let Lpal be a language over Σ = {0, 1, 2} containing exactly all pictures P ∈ Σ∗,∗ that can be written as P = P1 dP2 d. . . dPk , where each Pi is a palindrome of the form w2wVM , w ∈ {0, 1}∗ . Theorem 5.1 The language Lpal is not accepted by a bounded 2D Turing machine of time complexity t(m, n) unless lim sup t(m, n) · n→∞
log m > 0. mn2
Proof Let M = (Q, Σ, Γ, δ, q0 , QF ) be a bounded 2D Turing machine recognizing LP in time t. We start with an auxiliary observation. Consider two pictures P , Q in Lpal of the same size. Let us write them as follows P = P1 dP2 dC dP2VM dP1VM dQVM , Q = Q1 dQ2 dC dQVM 2 1
where C is the one-column picture over {2}, r = cols(P1 ) = cols(Q1 ). Let C1 and C2 be accepting computations of M over P and Q, respectively. Moreover, let K1 and K2 be crossing sequences at position r related to C1 and C2 , respectively. If K1 and K2 are identical, then Proposition 4.3 implies 12
VM too. This is possible only when P = Q . If M accepts P1 Q2 CQVM 1 1 2 Q1 P1 6= Q1 , K1 and K2 must always differ. We denote this observation by (1). Let L1 be the subset of Lpal consisting of all pictures of size (m, n), where n is odd. For L1 , we define function p : Z → N, where p(i) is equal to the average length of a crossing sequence at the position i for pictures from L1 . n−1 There are 2m 2 pictures in L1 . At least one half of these pictures (i.e., n−1 2m 2 −1 ) must have the length of the corresponding crossing sequence at position i less than or equal to 2p(i) (since p(i) the arithmetical average of the lengths of all crossing sequences at the position i). We need to estimate the number of all crossing sequences at the position i crossing sequences of length at most 2p(i). Each element from a crossing sequence is of the form (q, r). The first component of this pair is one of s = |Q| different values. Since M can move horizontally on m different rows during its computation, the second component is one of m different values. It means the number of all different crossing sequences of length k is (sm)k . An estimate of the number of all crossing sequences of length less or equal to 2p(i) can be obtained using the formula for the sum of numbers in a geometric sequence: N X
qi = q ·
i=1
qN − 1 ≤ q N +1 , q−1
where the inequality surely holds for every q ≥ 2. In our case, we set q = sm and N = 2p(i), so we get that the number of required sequences is at most (sm)2p(i)+1 . Let i be an integer in {1, . . . , n−1 2 }. Using two previous paragraphs, we get there exist at least n−1 2m 2 −1 (sm)2p(i)+1 pictures with identical crossing sequences at position i. By observation (1), n−1 all these pictures have identical prefixes of length i. There are 2m( 2 −i) such different prefixes of length i, which implies the inequality: n−1
n−1 2m 2 −1 ≤ 2m 2 −mi . 2p(i)+1 (sm)
We derive 2m
n−1 −1 2
m n−1 −mi 2
≤ (sm)2p(i)+1 ,
2
2mi−1 ≤ (sm)2p(i)+1 , mi − 1 ≤ (2p(i) + 1) · log2 (sm) .
13
Summing these inequalities for i ∈ {1, . . . , n−1 2 } gives m
n−1
n−1
2 X
2 X
(i − 1) ≤
i=1
m·
n−1 · 4
(2p(i) + 1) · log2 (sm) ,
i=1
n−1 2 X n−1 n − 1 − 1 ≤ 2 · p(i) + · log2 (sm) . 2 2 i=1
By Proposition 4.4, n−1 2 X
p(i) ≤ t(m, n)
i=1
and thus n−1 2 · t(m, n) + · log2 (sm) 2 (n − 1)(n − 3) n−1 m ≤ 2 t(m, n) + · log2 (sm) 8 4
m
n−1 n−3 · 4 2
≤
(n − 1)(n − 3) n − 1 m − ≤ t(m, n) . 2 log2 (sm) 8 4 The time complexity of M has to satisfy the derived inequality for every mn2 odd n > 0. The expression on the left-hand side is Ω( log m ). This implies the statement of the theorem.
6
Closure properties
Theorem 6.1 Both L(2SA) and L(2DSA) are closed under union, intersection, rotation and mirroring. Proof Let A1 , A2 be two 2SA’s. Denote L1 = L(A1 ), L2 = L(A2 ). We can construct a 2SA that starts to compute as A1 and when A1 finishes, it computes as A2 . The recognition of L1 ∪ L2 or L1 ∩ L2 requires to accept iff both or at least one of the simulations accepts, respectively. To recognize LR 1 , a 2SA moves its head to the top-right corner of the input and simulates A1 , treating columns as row and vice versa. Similarly, in order to recognize LVM or LHM 1 1 , a 2SA moves its head to the top-right or bottom-left corner, respectively, and simulates A1 , taking rows or columns, respectively, in the reversed order. When A1 , A2 are deterministic, the designed automata are deterministic too.
14
Theorem 6.2 L(2SA) is closed under projection and concatenations (row and column). Proof Let A1 , A2 be two 2SA’s. Denote L1 = L(A1 ), L2 = L(A2 ). To recognize L1 dL2 , a 2SA non-deterministically chooses a column in the input and marks it. Then it simulates A1 over the left part (including the marked column) and, after that, A2 over the right part (excluding the marked column). Let L = π(L1 ), where π is a projection. For an input P , a 2SA nondeterministically guesses and writes on the tape a picture P 0 such that π(P 0 ) = P . Then it simulates A1 over P 0 . Theorem 6.3 L(2DSA) is closed under complement. Proof Let L = L(A) for some 2DSA A = (Q, σ, Γ, δ, q0 , QF , µ). The automaton A rejects an input picture P if its computation on P finishes on a tape cell containing a symbol a in a state q such that δ(q, a) is empty. The complement of the language L, the language L = Σ∗,∗ r L, is recognized by the 2SA A¯ = (Q ∪ {qa }, Σ, Γ ∪ {#a }, δ, q0 , {qa }, µ), where qa is a new (accepting) state, #a is a new auxiliary symbol, the weight function is defined as follows µ(x) + 1 for x ∈ Γ µ(x) = 0 for x = #a and the transition function δ extends δ: for δ(q, a) 6= ∅ δ(q, x) {(qa , #a , ν(x))} for x ∈ Γ such that δ(q, x) = ∅ δ(q, x) = {(qa , x, ν(x))} for x ∈ S such that δ(q, x) = ∅ It is easy to see that A¯ is deterministic and A¯ enters its single accepting state during a computation on an input picture P iff A rejects P . Let LC be a picture language over Σ = {0, 1, 2} consisting of all pictures of the form P = Q1 dC dQ2 , where • Q1 and Q2 are non-empty square pictures over {0, 1}, and • C is a column over {2}. It is easy to see that each P ∈ LC is of size (n, 2n + 1) for some n ≥ 1. Furthermore, let LP be a subset of LC consisting of pictures P = d Q1 C dQ2 , where Q2 = QVM 1 . Note that LP = Lpal ∩ LC . Lemma 6.4 LC is recognizable by a 4DFA.
15
Proof We will design a 4DFA A accepting LC . Each computation of A consists of two phases. During the first phase, A checks whether the given input P is of size (n, 2n + 1) and whether the middle column contains only 2’s. This is done by traversing P as given in Figure 2(a). In the diagonal movements, horizontal and vertical steps alternate. In the end, the head has to reach the bottom right corner of P . During the second phase, A scans column by column (see Figure 2(b)) and verifies that all occurrences of 2’s are located only in single column. P is accepted iff both phases succeed. n
1
n ...
n
(a) The first phase.
...
(b) The second phase.
Figure 2: Arrows depict traversals done during the first two phases. The used picture is of size (n, 2n + 1) as it is given by the partial sizes printed along its border. Lemma 6.5 The complement of LP is in L(2SA) as well as in REC. Proof LP can be decomposed into two disjoint subsets: L1 = LC and L2 = LC ∩ LP . By Lemma 6.4, LC ∈ L(4DFA), thus it is sufficient to show that L2 is in L(2SA) ∩ REC. Define a one-row pictures language over Σ. n o LR = x dv1 d2 dv2 dy | v1 , v2 ∈ {0, 1}1,∗ ∧ x, y ∈ {0, 1}1,1 ∧ x 6= y Pictures in LR have the following properties: • there is exactly one occurrence of the symbol 2, the symbol is placed neither at the first nor at the last position, • the first and the last fields contain different symbols. Now, define L3 as a subset of LC , where for each P ∈ L3 of size (n, 2n + 1) there exists a row with index i such that P (i, 1) 6= P (i, 2n + 1). L3 = LC ∩ (Σ∗,∗ dLR dΣ∗,∗ ) Finally, L2 is expressed as follows. L2 = LC ∩ (Σ∗,∗ d(Σ∗,∗ dL3 dΣ∗,∗ ) dΣ∗,∗ ) Closure properties of L(2SA) and REC guarantee that L2 belongs to L(2SA) and REC, respectively. 16
Theorem 6.6 L(2SA) is not closed under complement. Proof According to Theorem 5.1, LP cannot be recognized by a bounded Turing machine in time O(n2 ), thus LP is not in L(2SA) (as implied by Lemma 4.1). On the other hand, by Lemma 6.5, LP is recognizable by a 2SA. Theorem 6.7 L(2DSA) is not closed under row, neither column concatenation. Proof In the proof of Lemma 6.5, we have shown that LP = LC ∪ (LC ∩ (Σ∗,∗ d(Σ∗,∗ d(LC ∩ (Σ∗,∗ dLR dΣ∗,∗ )) dΣ∗,∗ ) dΣ∗,∗ )) . Since languages LC , LR and Σ∗,∗ are in L(4FA) and L(2DSA) is closed under intersection as well as union, it is not closed under at least one of the concatenations, e.g. (w.l.o.g.) under row concatenation. Since it holds R R R d R R d P1 P2 = P2 P1 and L(2DSA) is closed under rotation, it cannot be closed under column concatenation as well. Theorem 6.8 L(2DSA) is not closed under projection. Proof Let Σ1 = {0, 1}, Γ = {2}, Σ2 = {0, 1}, Σ = Σ1 ∪ Γ ∪ Σ2 and let π : Σ → Σ1 ∪ Γ be a projection such that π(0) = 0, π(1) = 1, π(2) = 2, π(0) = 0 and π(1) = 1. Define language L1 over Σ containing pictures of the form Q1 dC dQ2 , where • Q1 is a square picture containing exactly one symbol from Σ2 (at some position (i, j)); the remaining symbols are in Σ1 , • C is a column over Γ, and • Q2 is a square picture over Σ1 , where QVM 2 (i, j) 6= π(Q1 (i, j)). Now, let L2 = LC ∪ L1 . We have π(L2 ) = LP , thus it suffices to show that L2 is recognizable by a 2DSA. Lemma 6.4 implies that LC is in L(2DSA) and as L(2DSA) is closed under union, it is enough to show that L1 ∈ L(2DSA). A 2DSA recognizing L1 can be obtained by a slight modification of the procedure for recognition of LP by a 4DFA. During the second phase not only the presence of a single column of 2’s is verified, but the sgraffito automaton checks also that • the part to the right from the column containing 2’s contains only symbols from Σ1 , and 17
• the part to the left from the column containing 2’s contains only symbols from Σ1 with exactly one exception – a symbol from from Σ2 . During an additional third phase, the single symbol x ∈ Σ2 within the left part of the picture is located. Then we mark the whole row containing x and subsequently using a billiard ball-like movement from x we locate the corresponding symbol to the right from the column of 2’s – see Fig. 6 and we verify that it differs from π(x).
(a) Case one.
(b) Case two.
Figure 3: Locating the corresponding field in the opposite side using billiard ball-like movements. Dashed lines denote a marked working row.
7
A Comparison of L(2SA) with REC and DREC
Theorem 7.1 REC is included in L(2SA), DREC is included in L(2DSA). Proof Let L be a language in REC. It is recognizable by a 2OTA A1 . We can easily construct a 2SA A2 simulating A1 . It goes through the input row by row and writes the final state of each cell in the corresponding tape field. It non-deterministically branches when A1 does so. If A1 is a 2DOTA, then A2 is a 2DSA, thus L(2DOTA) ⊆ L(2DSA). Since L(2DSA) is closed under rotation, it includes the closure by rotation of L(2DOTA) which equals DREC (shown in [1]). Let LD be a subset of LP consisting of pictures P = Q dC dQVM , where C ∈ {2}∗,1 and Q fulfills • each row of Q contains exactly one symbol 1, and • each diagonal of Q parallel to the minor diagonal contains at most one symbol 1. If Q is of size (n, n), it contains n occurrences of the symbol 1. An example is given in Figure 7. Lemma 7.2 LD is in L(2DSA).
18
0 1 0 0 2 0 0 1 0 0 1 0 0 2 0 0 1 0 0 0 0 1 2 1 0 0 0 1 0 0 0 2 0 0 0 1 Figure 4: A picture from LD . Proof We describe a 2DSA A recognizing LD . Let P denote an input picture. First of all, A performs the following verifications: 1. P is in LC , i.e., P = Q1 dC dQ2 , where Q1 , Q2 ∈ {0, 1}n,n and C ∈ {2}n,1 . This can be done simulating the 4DFA from Lemma 6.4. 2. Each row in Q1 and Q2 contains exactly one symbol 1. Checked by traversing P row by row. 3. Each diagonal parallel to the minor diagonal in Q1 and Q2 contains at most one symbol 1. Done by traversing P diagonal by diagonal. If one of the verifications fails, A rejects P . During the next stage, A checks if Q2 is the vertical mirroring of Q1 . In each row of P the following procedure is performed. Mark the i-th row as ”working“. Find the symbol 1 in Q1 , let it be at a position (i, j). Locate the field at the corresponding position (i, 2n − j + 1) in the opposite half Q2 . To do that, apply a billiard ball-like traversing shown in Figure 6 until the marked line is reached. There are two different progressions, depending on the starting position. Check if P (i, 2n − j + 1) = 1. Unmark the working row and move the head to the first field of the subsequent row. It remains to show that A visits each field of the working tape constantly many times and thus it can be correctly defined (Lemma 4.2). At most four traversals trough P are performed in the first stage. In the second stage, consider working rows, which involve the first type of the billiard ball-like localization. A unique diagonal and row is always used in Q1 and Q2 , respectively, to arrive at the opposite field. This implies the definition of LD . The same statement holds among the working rows involving the second case. Lemma 7.3 LD is not in REC. Proof Suppose, by contradiction, that LD is in REC. Then there is a projection π and a local language L ⊆ Γ∗,∗ such that LD = π(L). For an integer n define LD (n) = {P | P ∈ LD ∧ rows(P ) = n} .
19
The number of pictures in LD (n) is at least n!. To see it, consider placing symbols 1 in P row by row. Each placed 1 reserves one diagonal and restricts the choice for next rows at most by one position. This implies the given estimation. Let L(n) be the set of all pictures in L which are projected into LD (n) by π. For pictures in L(n), there are at most |Γ|2n possibilities, how columns n and n + 1 can look like. It holds n n < n!, e thus we can find n sufficiently large so that |Γ|2n < n! ≤ |LD (n)|, implying there are two different pictures π(P ) dπ(C1 ) dπ(P )VM , π(Q) dπ(C2 ) dπ(Q)VM in LD (n), such that the corresponding pictures P dC1 dP VM , Q dC2 dQVM in L(n) have identical columns n and n+1 (meaning that C1 = C2 ). According to the definition of a local language, the picture P dC1 dQVM is also in L(n), therefore π(P ) dπ(C1 ) dπ(Q)VM belongs to LD (n). Since P 6= Q, this is a contradiction. Theorem 7.4 Classes L(2DSA) and REC are incomparable. Proof We argued in the proof of Theorem 6.6 that LP ∈ / L(2SA). Since L(2DSA) is closed under complement, we have LP ∈ / L(2DSA). By Lemma 6.5, LP ∈ REC, thus REC * L(2DSA). On the other hand, by Lemmas 7.3 and 7.2, LD ∈ L(2DSA) \ REC, implying L(2DSA) * REC.
8
Two-dimensional restarting tiling automata
Our model of a two-dimensional restarting automaton is based on the following two concepts. The first one is the tiling automaton [2], which nondeterministically guesses an inverse image of an input picture according to rewriting rules of a given tiling system and checks whether the inverse image belongs to a given local language. The second one is the (one-dimensional) restarting automaton (namely shrinking restarting automaton [9]) that iteratively simplifies the input string until either a correct “simple” string is obtained and the input is accepted or until the simplification gets stuck in which case the input is rejected. During each simplification, the automaton scans the current string, performs a single rewriting operation and restarts. Each rewriting must be shrinking, i.e., weight-decreasing. A variant of the following model has been already studied by Bart´ak in [3]. His model called two-dimensional restarting automaton used a fixed scanning strategy. 20
A tiling automaton [2] is a tiling system equipped with a scanning strategy, which determines the order in which all the positions of an input picture are visited. A scanning strategy must satisfy several requirements: each position must be visited exactly once, when a position is scanned, all three neighbors of the position needed for computing inverse image of the respective tile must have been already visited (and stored in a suitable data structure). Cherubini and Pradella [4] added some more requirements to the scanning strategy and later they studied such scanning strategies together with another model of automata which use tiles with colors on their border, the so-called Wang tiles [11, 12], but we will keep the more general approach based on [2]. A scanning strategy is represented by a single starting position in the picture which will be one of its corners and a partial computable function f : N4 → N2 where f (i, j, m, n) is the next scanned position after scanning the position (i, j) in a picture of size (m, n). The starting position will be represented simply as an integer cs ∈ {1, 2, 3, 4} with the meaning 1 for the left-top corner, 2 for the right-top corner, 3 for the right-bottom corner and 4 for the left-bottom corner of a picture. In contrast to [2] and [4], we will not consider any additional restrictions on the scanning strategy only that if (i0 , j0 ) is a starting position on a picture P of size (m, n) (for any m, n > 0), then the sequence of positions visited according to this strategy (i0 , j0 ), (i1 , j1 ), . . . , (i(m+1)(n+1)−1 , j(m+1)(n+1)−1 ) is a permutation of the set of positions of all tiles of size (2, 2) in the extended picture Pb. A scanning strategy will be represented as a pair ν = (cs , f ). Bart´ ak [3] used the following fixed scanning strategy νrow = (1, frow ) scanning a picture row by row from left to right with the starting position (1, 1) and the next position function (i, j + 1) if j < n + 1; frow (i, j, m, n) = (i + 1, 1) if j = n + 1, i < m. Definition A two-dimensional restarting tiling automaton, referred to as 2RTA, is a 6-tuple M = (Σ, Γ, Θf , δ, ν, µ), where Σ is a finite input alphabet, Γ is a finite working alphabet (Γ ⊇ Σ), Θf ⊆ (Γ ∪ S)2,2 is a set of accepting tiles, ν = (cs , f ) is a scanning strategy, µ : Γ → N is a weight function and δ ⊆ {(u → v) | u, v ∈ (Γ ∪ S)2,2 } is a set of rewriting rules satisfying the condition that in every rule only a single pixel on the tile is changed and all rewriting rules u → v conform with µ(u) > µ(v). Symbols from Γ r Σ are called auxiliary symbols and must not be contained in any input word. On a given input picture P ∈ Σ∗,∗ of size (m, n), the automaton M works in phases. Each phase starts in a starting position (i0 , j0 ) corresponding to the corner cs of the boundary picture Pb, that is, • (1, 1) for cs = 1,
21
• (1, n + 1) for cs = 2, • (m + 1, n + 1) for cs = 3, and • (m + 1, 1) for cs = 4. Then M scans the current picture using a window of size (2, 2) which is moved according to the scanning strategy ν. Let ν(r, m, n) denote the sequence of the first r positions of a picture of size (m, n) visited according to the scanning strategy ν. When M finds a tile for which a rewriting rule is defined it performs one of the possible rewritings and finishes the phase by restart (i.e., it goes to the upper left corner again). When no rewriting rule can be executed for the whole picture, the automaton verifies whether the picture belongs to the local language defined by Θf and if so, it accepts. Formally: Definition Let M = (Σ, Γ, Θf , δ, ν, µ) be a two-dimensional restarting tiling automaton, P1 , P2 be two pictures over the alphabet Γ of the same size (m, n) and ν((m + 1)(n + 1), m, n) = (i0 , j0 ), . . . , (i(m+1)(n+1)−1 , j(m+1)(n+1)−1 ). We say that the picture P1 can be directly reduced to picture P2 , denoted by P1 `M P2 , if there exists an integer s, 0 ≤ s < (m + 1)(n + 1), such that Pb1 (k, l) = Pb2 (k, l) for all c1 ), 1 ≤ l ≤ cols(P c1 ) except pairs of the indices k, l, where 1 ≤ k ≤ rows(P the pairs (is , js ), (is , js + 1), (is + 1, js ), (is + 1, js + 1) and there exists a rule P1 (is , js ) P1 (is + 1, js )
P1 (is , js + 1) P1 (is + 1, js + 1)
→
P2 (is , js ) P2 (is + 1, js )
P2 (is , js + 1) P2 (is + 1, js + 1)
.
Moreover, there is no rule in δ that could be applied to any tile P1 (ir , jr ) P1 (ir , jr + 1) , where 0 ≤ r < s. We say that P1 P1 (ir + 1, jr ) P1 (ir + 1, jr + 1) can be reduced to P2 (denoted by P1 `∗M P2 ) if there exists a sequence of reductions Q1 `M Q2 , Q2 `M Q3 , . . . , Qn−1 `M Qn , where n ≥ 1, Q1 = P1 and Qn = P2 . Obviously, the relation `∗M is the reflexive and transitive closure of the relation `M . Let M = (Σ, Γ, Θf , δ, ν, µ) be a 2RTA. The language accepted by M is the set L(M ) = {P ∈ Σ∗,∗ | ∃Q ∈ Γ∗,∗ : P `∗M Q and Q ∈ L(Θf )}. 2RTA is by definition nondeterministic, as on a tile one of several rewriting rules with the same left-hand side can be applied. We define a deterministic version of two-dimensional restarting automata (2DRTA) by requiring that no two rewriting rules can have the same left-hand side. Definition A deterministic two-dimensional restarting automaton, referred to as 2DRTA, is a 2RTA M = (Σ, Γ, Θf , δ, ν, µ) with the set of rewriting rules δ satisfying one additional condition that for every tile T ∈ (Γ ∪ S)2,2 there exists at most one rule with the left-hand side T in δ. 22
To illustrate our definition we present a deterministic 2RTA accepting the language of all squares over a one-letter alphabet L = {P ∈ an,n | n ≥ 0}. Example Let M = (Σ, Γ, Θf , δ, µ) be a deterministic 2RTA with Σ = {a}, # > # > 1 a 1 a , Θf = Γ = {a, 1}, δ = → , → ` a ` 1 a a a 1 # > > > > > > # a a a a , , , , , , ` 1 1 a a a a a a a 1 a 1 a a 1 a a ` a ` a ` 1 , , , , , , ⊥ # ⊥ ⊥ ⊥ ⊥ # ⊥ ` a ` a 1 a a 1 a a a a # # . , , , , a 1 a a 1 a a a # # The automaton has the single auxiliary symbol 1, which is used to mark a diagonal in order to check that the input is a square picture. The weight function µ is defined in a way that the only allowed rewriting is from a to 1, e.g. µ(a) = 2 and µ(1) = 1. Bart´ ak [3] showed several closure properties of his two-dimensional restarting automata and related them to other classes of picture languages like 2OTA, REC and tiling systems. Unfortunately several of his results are conjectures only. The class 2RTA with the scanning strategy ν will be denoted as ν-2RTA. Next we will show that for any scanning strategy ν, the class of languages recognizable by ν-2RTA (denoted as L(ν-2RTA)) is closed under projection. Lemma 8.1 For each scanning strategy ν, L(ν-2RTA) is closed under projection. Proof Let Σ1 , Σ2 be two finite alphabets and let ϕ : Σ1 → Σ2 be a projection. We will prove that if a picture language L1 ⊆ Σ∗,∗ 1 is accepted by a ν-2RTA A1 , then L2 = ϕ(L1 ) is accepted by a ν-2RTA A2 . Let A1 = (Σ1 , Γ1 , Θf 1 , δ1 , ν1 , µ1 ) be a two-dimensional restarting automaton recognizing L1 . We can construct a two-dimensional restarting automaton A2 = (Σ2 , Γ2 , Θf 2 , δ2 , ν2 , µ2 ) recognizing L2 as it follows. A2 will use the the scanning strategy ν2 = ν1 and the working alphabet Γ2 = Σ2 ∪ (Σ2 × Γ1 ) ∪ S. For each symbol x ∈ Γ2 , let π1 , π2 denote the projections x for x ∈ S, π1 (x) = y for x = (y, s) ∈ Σ2 × Γ1 x for x ∈ S, π2 (x) = s for x = (y, s) ∈ Σ2 × Γ1
23
Then, Θf 2 = π2−1 (Θf 1 ), that is, a tile π2 (x1 ) π2 (x3 ) (1)
π2 (x2 ) π2 (x4 ) (2)
x1 x3
x2 x4
is in Θf 2 iff
is in Θf 1 . The set of rewriting rules of A2 will be (1)
δ2 = δ2 ∪ δ2 , where δ2 will contain rules corresponding to the transformation inverse to ϕ: ϕ(s) x (ϕ(s), s) x (1) → | s ∈ Σ1 , x, y, z ∈ Σ2 × Γ1 ∪ S . δ2 = y z y z (1)
By applying rules form δ2 , the content of the tape can be rewritten into a pre-image of an input picture, which uses symbols of the form (ϕ(s), s) instead of simply s from Σ1 . Further, x1 x2 y1 y2 (2) δ2 = → | x3 x4 y3 y4 π2 (x1 ) π2 (x2 ) π2 (y1 ) π2 (y2 ) → is in δ1 π2 (x3 ) π2 (x4 ) π2 (y3 ) π2 (y4 ) and π1 (xi ) = π1 (yi ), for i = 1, 2, 3, 4
.
The automaton A2 , first starts to “reverse” the projection applied to input alphabet starting from the lower right corner of the picture. A rule (2) from δ2 can be applied in a tile only when the whole tile is rewritten into Γ2,2 2 . The process of reversing the projection and the simulation of rewriting according to δ1 can be mixed. Nevertheless, the picture is accepted only when all symbols of the picture are “reversed”. Note that for single picture P there could be multiple pre-images P1 . A2 has to choose non-deterministically one of them. It is also clear that A2 cannot accept any pictures outside the ϕ(L(A1 )) as it actually simulates A1 in its own computation. The weight function µ2 can be designed as follows. Let m = maxx∈Γ1 µ1 (x). Then µ2 (s) = m + 1, for all s ∈ Σ2 , and µ2 ((x, y)) = µ1 (y), for all (x, y) ∈ Σ2 × Γ1 . Actually the technique used in the proof of Lemma 8.1 can be easily extended in such a way that each symbol x of the input picture is first replaced by the pair (x, x) and then two computations of two different 2RTAs can be simulated – the first one operating on the first elements of the pairs and the second one operating on the second elements of the pairs. Clearly, in this way it is possible to construct 2RTA for accepting union and intersection of any given 2RTAs. Hence we have. Corollary 8.2 For any scanning strategy ν, L(ν-2RTA) is closed under union and intersection. 24
Theorem 8.3 Let ν be a scanning strategy such that the last position scanned according to ν on pictures of all (positive) sizes is always the same corner (containing the sentinel #). Then the class L(ν-2DRTA) is closed under complement. Proof A deterministic 2RTA M = (Σ, Γ, Θf , δ, ν, µ) rejects an input picture P , when P `∗M Q, no rule from δ can be applied on any subpicture of Q and Q 6∈ L(Θf ). It is possible deterministically detect the situation when M has no applicable rewriting rule – when it scans the last position according to ν and it has no applicable rule in δ. At this moment, an ν-2DRTA M0 = (Σ, Γ0 , Θ0f , δ 0 , ν, µ0 ) accepting the complement of L(M) can start additional verification whether M accepts the picture. M starts rewriting the content of its tape from the position of the picture scanned in the last position according to ν. If a scanned tile belongs to Θf a symbol x from Γ is rewritten into the pair (x, A), where A is a new symbol, with the meaning that the tile belongs to Θf . However when the tile does not belong to Θf , then M0 rewrites it in the pair (x, R), where R is a new symbol, with the meaning that the tile does not belong to Θf . Thereafter, M0 continues to rewrite tiles which contain at least one symbol from Γ × {A, R} according to the following algorithm: • If the tile contains a symbol from Γ × {R} and a symbol x ∈ Γ, then x is rewritten into (x, R). If there is more than one such x, then the symbol which is higher and more to the left is rewritten. • If the tile contains no symbol from Γ × {R} and a symbol x ∈ Γ, then x is rewritten into (x, A). If there is more than one such x, then the symbol which is higher and more to the left is rewritten. • If the tile contains a symbol from Γ × {R}, no symbols from Γ and a symbol (x, A) for some x ∈ Γ, then (x, A) is rewritten into (x, R). If there is more than one such (x, A), then the symbol which is higher and more to the left is rewritten. • Otherwise, the tile is not rewritten. Clearly, M0 finishes rewriting when all the symbols on its tape (beside the sentinels) are either from Γ × {A} or from Γ × {A}. Then M0 accepts using Θ0f containing all the tiles with symbol from Γ × {A} ∪ S only. Hence, Γ0 = Γ × {A, R}, we can set µ0 ((x, A)) = 2, µ0 ((x, R)) = 1 and 0 µ (x) = µ(x) + 2, for all x ∈ Γ. δ 0 extends δ and can be built according to the above description. Obviously, L(M0 ) is the complement of L(M).
25
9
2RTA working over one-row pictures
In this section we study the power of 2RTA when working over one-row pictures. We show that 2RTA could be quite powerful when we have freedom to design a suitable scanning strategy. On the other hand, a simple strategy νrow leads to regular languages recognition. Lemma 9.1 There is a 2DRTA accepting a language L ⊆ Σ1,∗ = Σ∗ which is not regular. Proof Define a 2DRTA M = (Σ, Γ, Θf , δ, ν, µ) where Σ = {a, b}, {a, b, c, d, r}, µ(a) = µ(b) = 1, µ(c) = µ(d) = µ(r) = 0, # > > > > > > > > Θf = , , , , ` c c c c a a d d > # ` c c c c a a d d , , , , , d a # ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ d a , ⊥ # > > > > > > > δ = → , → b a c a a b a > > > > > > > > > > → , → , b c c c d b d d a c > > > > > > > > > , → , → r c d a d r a a r > > > > → . b b r a ν = (1, f ) with f specified as follows: (1, bn/2c + 1) if (i, j) = (1, 1); (1, j − 1) if i = 1 ∧ 3 ≤ j ≤ bn/2c + 1; (1, bn/2c + 2) if (i, j) = (1, 2); f (i, j, m, n) = (1, j + 1) if i = 1 ∧ bn/2c + 2 ≤ j ≤ n; (2, 1) if (i, j) = (1, n + 1); (2, j + 1) if i = 2 ∧ 2 ≤ j ≤ n.
Γ = > , d d , ⊥
> , d → > , a
Figure 5: Scanning strategy (the first half over the first row). The main part of the strategy is depicted in Figure 5. Consider an input w ∈ Σ∗ of length n accepted by M. Denote k = bn/2c+1. Tiles of Θf imply that w is accepted only when rewritings produce 26
a word ci adj for some i, j ≥ 1, i + j = n − 1. It gives n ≥ 3. Let us follow the computation of M. Rules of δ can be applied only to tiles located in the first row of w, b thus only the first part of the scanning strategy, depicted in Figure 5, is relevant. No rewriting will occur at position (1, 1), which is first in the order. The next position is (1, k). If wk wk+1 is aa or bb, the computation fails, since one of the symbols is rewritten by r which is “permanent”. Assume wk wk+1 = ab. This pair is rewritten to ad. After restart, M will proceed till wk−1 wk . Here must be wk−1 = b and wk−1 wk is changed to ca. From now, there must be only b’s from wk−2 to w1 , otherwise r is produced. Moreover, from wk+2 to wn , there must be b’s only too. This means, M accepts bk−1 abn−k . The second situation wk wk+1 = ba can be analyzed analogously and leads to bk abn−k−1 being the only accepted word. It is easy to see that L(M) is not a regular language. Lemma 9.2 Let A = (Σ, Γ, Θf , δ, νrow , µ) be a 2RTA accepting a onedimensional picture language (L(A) ⊆ Σ1,∗ = Σ∗ ). There is a 2SA M such that L(M) = L(A). Proof Consider a (nonempty) one-row picture w ∈ Σ∗ of length n and a computation of A over it. Let R = ((r1 , c1 ), . . . , (rm , cm )) be a time ordered sequence of tile positions on which A applied rewriting instructions. Scanning strategy νrow goes trough two first rows of w, b thus each ri ∈ {1, 2} and 1 ≤ ci ≤ n + 1. We will construct a 2SA M that locates all positions in R and simulates each correspondent rewriting. By locating a tile position (ri , ci ) we mean moving the head to the first symbol of w which is intersected by the tile. The important part of the construction will be to show that it can be done in a manner which requires only a constant number of visits for any tape field. Let k be the first index fulfilling rk = 2. We will describe the behavior of M until it is about to locate (rk , ck ). If there is no such k, then we consider the whole computation of A. W.l.o.g. we assume, besides the scanned tape field, M sees the left and right neighbor. The simulation starts by moving the head right to locate (1, c1 ). The related rewriting changes the symbol at (2, c1 ) or (2, c1 + 1) in w. b This implies a restriction for c2 which cannot be less than c1 − 1. Hence, to get to (1, c2 ), M moves one tape field left, stays at the same place or proceeds towards the right end of w. In a tape field, A can decrease the weight at most C = maxa∈Σ µ(a) times, thus the number of moves to the left of M across the field is bounded by C. This fact consequently implies there is also a constant bound for the number of moves to the right across any field. When M reaches the right end of w for the first time, it remembers this event in states and starts to operate in a more general mode. First, it returns to the left end of w. This is followed by moving right to locate (2, ck ). Now, there are more options for (rk+1 , ck+1 ) that can equal (1, ck −1), 27
(1, ck ) or some (2, ck+1 ) with ck+1 ≥ ck − 1. If rk+1 = 2, M behaves in the same manner as described for the initial phase. Assuming rk+1 = 1, let R0 = ((rk+1 , ck+1 ), . . . , (rl , cl )) be a continuous subsequence of R such that ri = 1 for all i ∈ I = {k + 1, . . . , l} and rl+1 = 2. M maintains information on the rightmost, resp. leftmost rewritable tile in the first, resp. second row of w, b located right, resp. left with respect to the current position of the head. It memorizes in states whether there are such tiles. If so, it represents their positions by markers mR and mL placed at the corresponding tape fields. M removes mR , resp. mL when it is about to cross it right, resp. left. The markers help M to decide, where to search for the next tile to rewrite. If it has simulated a rewriting at (1, c), the next position is searched from column c − 1 to mR . If it does not exist, M is done with R0 . If mL is set, M moves there, otherwise it simply searches rightwards for a rewritable tile in the second row of w. b Denote bL = mini∈I ci and bR = maxi∈I ci . Since new rewritable tiles can emerge in the first row only in the neighborhood of rewritten symbols, it holds bR − bL ≤ l − k. Moreover, the number of moves M performs on R0 is proportional to bR − bL and the number of visits of each field in range (bL , bR ) is linear in the number of simulated rewritings over it. mL , resp. position (rk , ck ) is in the range (bL , bR ), thus reaching it contributes at most by one more visit to each field from the range. These observations ensure that M is a 2SA.
10
Relationship between 2SA and 2RTA
Proposition 10.1 L(2SA) is included in L(2RTA), L(2DSA) is included in L(2DRTA). Proof Let A = (Q, Σ, Γ, δ, q0 , QF , µ) be a 2SA. We describe a 2RTA T = (Σ, Γ0 , Θf , δ 0 , ν 0 , µ0 ) such that L(T ) = L(A). The idea is to simulate a computation of A over any input P ∈ Σ∗,∗ . If A scans the tape field f and the control unit is in state q, then T stores q into f . A set of rewriting rules is designed for changing the current configuration of A into a configuration after a single step of A. Let k = |Γ|, m = max{k, 5} and I = {0, . . . , k}. Elements in Γ0 are of five types: 1. a ∈ (Σ ∪ S), µ0 (a) = mk + 4, is an initial input symbol, 2. (i, a) ∈ (I × Γ), µ0 ((i, a)) = mi + 3, represents a field containing a, the head of A is not placed here, at most i instructions of A can be performed over the field, 3. (i, a, q) ∈ (I × Γ × Q), µ0 ((i, a, q)) = mi + 1, the same meaning of a and i as above, moreover, the head of A scans this field and the control 28
unit is in the state q, 4. (i, a, q, d) ∈ (I × Γ × Q × H), µ0 ((i, a, q, d)) = mi, the same meaning of a, i and q as above, moreover, A will move from this field in the direction d, 5. (i, a, q, b) ∈ (I × Γ × Q × Γ), µ((i, a, q, b)) = mi + 2, an auxiliary symbol with the meaning: A moved to this field containing a in the state q from a neighboring field by an instruction which writes b. There is no loss of generality in assuming that A moves the head in each computation step and enters a state in QF only when it scans the bottom right corner of P . The specification of rewriting rules and Θf follows. For each a ∈ Σ, there is a rule creating the representation of the initial configuration: # > # > → . ` a ` (k, a, q0 ) For each instruction (q, a) → (q 0 , a0 , R) in δ, rules matching the following patterns are added: (i, a, q) s
(j, b) t
(i, a, q) s (i, a, q, R) s
(j, b) t
(i, a, q, R) s (i, a, q, R) s (i − 1, a0 ) s
b t
b t
→
(i, a, q, R) s
(j, b) , t
→
(i, a, q, R) s
b , t
→ →
(i, a, q, R) s
(j, b, q 0 , a0 ) t (j, b, q 0 , a0 ) t
(j, b, q 0 , a0 ) t
(i, a, q, R) s
→ →
(0, b, q 0 , a0 ) , t
(i − 1, a0 ) s (i − 1, a0 ) s
(j, b, q 0 , a0 ) , t (j, b, q 0 ) , t
where i, j ∈ I, 0 < i ≤ k, b ∈ Γ \ S, s, t ∈ Σ ∪ S ∪ (I × Γ). By writing an auxiliary symbol of the form (i, a, q, d) on the tape, we ensure that T cannot start to simulate simultaneously two instructions of A moving from a field in different (e.g. opposite) directions. A special attention has to be paid to the situation, when the head of A moves outside P . We do not represent such a configuration, but rather the following configuration reached by applying a next instruction of the form (q 0 , a) → (q 00 , a, L). Thus, the set of rules is completed by (i, a, q) s
a t
→
(i − 1, a0 , q 00 ) s 29
a . t
The weight function µ has been defined to conform the rules. Similar rules are added also for the remaining instructions which move the head of A left, up or down. (i, a, qf ) a Θf contains all the tiles of the form , for all a ∈ Γ, i ∈ I, ⊥ # a b qf ∈ QF and all the tiles of the form , where a, b, c, d ∈ (Σ∪S)∪(I × c d a a Γ) except the tiles of the form , where a ∈ (Σ ∪ S) ∪ (I × Γ). This ⊥ # ensures the rewriting process finishes only if A reaches an accepting state # # . (with its head at the bottom right corner). If P = Λ, then Pb = # # This tile is in Θf iff A accepts Λ. To finish the proof, it is easy to see that when A is deterministic, T is deterministic as well. Note that the simulation of a 2SA by a 2RTA does not depend on the employed scanning strategy. Using Theorem 7.1 and Theorem 4.6 we obtain the following. Corollary 10.2 REC is a proper subclass of L(2RTA), DREC is a subclass of L(2DRTA), L(4FA) ⊂ L(2DRTA).
11
Conclusions
We have introduced new models working over pictures called sgraffito automaton and tiling restarting automaton. They both induce interesting families of two-dimensional languages. The nondeterministic variants strictly include REC, while the deterministic variants strictly include DREC. A complete hierarchy related to sgraffito automata is depicted in Figure 6(a). Closure properties of L(2SA), resp. L(2DSA) coincide with the properties of REC, resp. DREC. This is summarized in Table 6(b). In our opinion, sgraffito and restarting tiling automata should be a subject to further research since they define a solid extension of the recognizable languages. The study of the automata can give an additional insight on the fundamental differences between one-dimensional and picture languages.
References [1] M. Anselmo, D. Giammarresi, and M. Madonia. From determinism to non-determinism in recognizable two-dimensional languages. In T. Harju, J. Karhum¨ aki, and A. Lepist¨o, editors, Developments in Language Theory, volume 4588 of Lecture Notes in Computer Science, pages 36–47. Springer, 2007. 30
L(2SA) REC
L(2DSA)
DREC
L(4FA)
(a) A hierarchy of classes.
REC L(2SA) DREC L(2DSA)
∪ yes yes yes yes
∩ yes yes yes yes
\ no no yes yes
d, d
yes yes no no
π yes yes no no
R,VM,HM
yes yes yes yes
(b) Closure properties.
Figure 6: (a) Relationships between REC, DREC and languages recognizable by sgraffito automata. Arrows denote proper inclusions, the dashed lines connects incomparable classes. (b) A summary of closure properties. [2] M. Anselmo, D. Giammarresi, and M. Madonia. A computational model for tiling recognizable two-dimensional languages. Theoretical Computer Science, 410:3520–3529, 2009. [3] J. Bart´ ak. Recognition of picture languages. Master thesis, Faculty of Mathematics and Physics, Charles University, Prague, 2008. [4] A. Cherubini and M. Pradella. Picture languages: From Wang tiles to 2D grammars. In S. Bozapalidis and G. Rahonis, editors, Algebraic Informatics, volume 5725 of Lecture Notes in Computer Science, pages 13–46. Springer Berlin / Heidelberg, 2009. [5] D. Giammarresi and A. Restivo. Recognizable picture languages. International Journal of Pattern Recognition and Artificial Intelligence, 6(2-3):32–45, 1992. [6] D. Giammarresi and A. Restivo. Two-dimensional languages. In G. Rozenberg and A. Salomaa, editors, Handbook of formal languages, Vol. 3, pages 215–267. Springer-Verlag New York, Inc., New York, NY, USA, 1997. [7] J. Hopcroft and J. Ullman. Formal languages and their relation to automata. Addison-Wesley, 1969. [8] K. Inoue and A. Nakamura. Some properties of two-dimensional online tessellation acceptors. In Information Sciences, volume 13, pages 95–121, 1977. 31
[9] T. Jurdzi´ nski and F. Otto. Shrinking restarting automata. Int. J. Found. Comput. Sci., 18(2):361–385, 2007. [10] K. Lindgren, C. Moore, and M. Nordahl. Complexity of twodimensional patterns. Journal of Statistical Physics, 91(5-6):909–951, 1998. [11] V. Lonati and M. Pradella. Picture recognizability with automata based on Wang tiles. In J. van Leeuwen et al., editor, SOFSEM 2010, volume 5901 of LNCS, pages 576–587, Berlin, 2010. Springer. [12] V. Lonati and M. Pradella. Towards more expressive 2d deterministic automata. In B. Bouchou-Markhoff, P. Caron, J.-M. Champarnaud, and D. Maurel, editors, Implementation and Application of Automata, volume 6807 of Lecture Notes in Computer Science, pages 225–237. Springer Berlin / Heidelberg, 2011. 10.1007/978-3-642-22256-6 21.
32