Two-Dimensional Typewriter Automata

A typewriter automaton is a special variant of a two-dimensional automaton that receives two-dimensional words as input and is only capable of moving its input head through its input word in three directions: downward, leftward, and rightward. In addition, downward and leftward moves may only be made via a special"reset"move that simulates the action of a typewriter's carriage return. In this paper, we initiate the study of the typewriter automaton model and relate it to similar models, including three-way two-dimensional automata, boustrophedon automata, and returning automata. We study the recognition powers of the typewriter automaton model, establish closure properties of the class of languages recognized by the model, and consider operational state complexity bounds for the specific operation of row concatenation. We also provide a variety of potential future research directions pertaining to the model.


Introduction
A two-dimensional typewriter automaton is a variant of the three-way two-dimensional automaton model introduced by Rosenfeld [10]. Similar to the three-way model, the input head of a typewriter automaton can move downward, leftward, and rightward, but the downward and leftward moves work in a fashion similar to the carriage of a typewriter: a special "return" transition repeatedly moves the input head leftward to the leftmost symbol of the current row, then downward by one row. Thus, unlike the three-way two-dimensional automaton model, a typewriter automaton cannot make individual downward or leftward moves.
The typewriter automaton is similar to two other unconventional two-dimensional automaton models that have appeared in the literature [1]: the boustrophedon automaton, which moves its input head from left to right and from right to left on alternating rows of a Department of Computer Science, St. Francis Xavier University, Antigonish, Nova Scotia, Canada. Email: tjsmith@stfx.ca. its input word; and the returning automaton, which moves its input head from the leftmost symbol to the rightmost symbol of each row of its input word.
In this paper, we initiate the study of typewriter automata by considering the recognition and closure properties of both deterministic and nondeterministic variants of the model. We show that typewriter automata are capable of recognizing a class of languages "in between" the classes of languages recognized by two-way and three-way two-dimensional automata, and that the class of languages recognized by nondeterministic typewriter automata is equivalent to the class of languages recognized by boustrophedon automata. We further show that the class of languages recognized by typewriter automata is closed under a variety of language operations, and we establish an operational state complexity bound for the specific operation of row concatenation. We conclude by offering a number of potential directions for future research on this model.

Preliminaries
A two-dimensional word consists of a finite array, or rectangle, of cells each labelled by a symbol from a finite alphabet Σ. We denote the set of m × n two-dimensional words over Σ by Σ m×n . When a two-dimensional word is written on the input tape of a two-dimensional automaton, the cells around the word are labelled by a special boundary marker # ∈ Σ. A two-dimensional automaton has a finite state control that is capable of moving its input head in four directions within its input word: up, down, left, and right (denoted by U, D, L, and R, respectively).
We can specify a nondeterministic variant of the model given in Definition 1 by changing the transition function to map to 2 Q×{U,D,L,R} . We denote the deterministic and nondeterministic two-dimensional automaton models by 2DFA-4W and 2NFA-4W, respectively.
By restricting the movement of the input head to prohibit upward movements, we obtain the restricted three-way variant of the two-dimensional automaton model. Definition 2 (Three-way two-dimensional automaton). A three-way two-dimensional automaton is a tuple (Q, Σ, δ, q 0 , q accept ) as in Definition 1, where the transition function δ is restricted to use only the directions {D, L, R}.
We denote deterministic and nondeterministic three-way two-dimensional automata by 2DFA-3W and 2NFA-3W, respectively. Likewise, we may restrict both upward and leftward movements to obtain the two-way two-dimensional automaton model, denoted in the deterministic and nondeterministic cases by 2DFA-2W and 2NFA-2W, respectively.
Additional information about the two-dimensional automaton model can be found in surveys by Inoue and Takanami [6], Kari and Salo [7], and the author [12].
Related to the two-dimensional automaton model is the notion of a boustrophedon automaton, so named because the input head of such an automaton moves from left to right # a 11 a 12 a 13 a 14 a 15 # # a 21 a 22 a 23 a 24 a 25 # Figure 1: An illustration of a typewriter automaton making a reset move after reading a symbol a 14 . Each of the moves indicated by arrows is made instantaneously; that is, symbols a 13 , a 12 , and a 11 are not read again as the input head moves to symbol a 21 . and from right to left on alternating rows of its input word, as in the boustrophedon style of writing. Although the name "boustrophedon automaton" was originally used by Pécuchet in the 1980s in reference to the two-way one-dimensional (string) automaton model [8,9], the boustrophedon automaton model considered in this paper was introduced by Fernau et al. in 2015 [1] and studied further in subsequent papers [2,3].
The set of rules R corresponding to a given boustrophedon automaton act as the transition relation of the automaton. The special marker , which indicates an erased portion of the input word, is used to distinguish symbols that have previously been read by the input head in a given configuration of an automaton. The use of the special marker is vital to defining the acceptance criterion for a boustrophedon automaton; since such an automaton must read all of the symbols in its input word before accepting, an m × n word is accepted if there exists some sequence of configurations ending in an accepting state with m × n special markers on the input tape. A complete description of the boustrophedon automaton model can be found in the papers by Fernau et al. [1,2,3]. We denote boustrophedon automata and their deterministic variant by BFA and BDFA, respectively.
We now turn to the model that forms the basis of this paper: the typewriter automaton. Like a three-way two-dimensional automaton, a typewriter automaton is only capable of moving its input head in three directions: downward, leftward, and rightward. At the same time, like a boustrophedon automaton, a typewriter automaton reads its input word row-byrow, with the distinction that it moves its input head only from left to right upon entering a given row of its input word. The name of the model is inspired by its behaviour when moving between rows: a typewriter automaton makes use of a special "reset" move, denoted by and depicted in Figure 1, which simulates the action of a typewriter's carriage return.
Definition 4 (Typewriter automaton). A (two-dimensional) typewriter automaton is a tuple (Q, Σ, δ, q 0 , q accept ), where Q, Σ, q 0 , and q accept are as in Definition 1, and where the transition function δ is restricted to use only the directions {R, }. The reset move shifts the input head leftward until it reaches the leftmost boundary marker of the current row, then moves the input head one position downward and one position rightward to the first symbol of the subsequent row.
We denote typewriter automata and their deterministic variant by TFA and TDFA, respectively.
Although the typewriter automaton model is quite similar to the three-way two-dimensional automaton model, one notable difference between the two models is that the typewriter automaton cannot make individual downward or leftward input head moves. Once the reset move is used, the input head moves repeatedly leftward and once downward without reading the symbol underneath. The input head only commences reading symbols again once its input head is positioned over the first symbol of the following row.
We define the notions of a configuration of a typewriter automaton and an accepting computation of a typewriter automaton identically to those used for traditional two-dimensional automata [12]. A configuration of a typewriter automaton T on an input word w ∈ Σ m×n is a tuple (q, i, j), where q is the current state of T and 0 ≤ i ≤ m + 1 and 0 ≤ j ≤ n + 1 are the current positions of the input head in w. We then say that T accepts its input word w if, at some point during its computation, it enters a configuration (q, i, j) where q = q accept .
To simplify the acceptance criterion for typewriter automata, we will not assume that all symbols of the input word must be read. While this choice differs from the definition of acceptance used by boustrophedon automata, it is more in line with the definition used for other two-dimensional automaton models.
Remark. Fernau et al. also studied the so-called returning automaton model, which operates in a manner similar to a boustrophedon automaton, but always moves its input head from the leftmost symbol to the rightmost symbol in a given row [1]. In this sense, a returning automaton is syntactically identical to a boustrophedon automaton, but distinct from a typewriter automaton since typewriter automata are not required to read entire rows of their input words.

Recognition Properties
It is well-known that three-way two-dimensional automata recognize strictly fewer languages than the standard (four-way) two-dimensional automaton model [10], and a similar relationship holds between two-and three-way two-dimensional automata. Likewise, all deterministic two-dimensional automaton models recognize strictly fewer languages than their nondeterministic counterparts, resulting in a lattice-like recognition hierarchy between deterministic and nondeterministic two-, three-, and four-way two-dimensional automata [10].
In their original paper, Fernau et al. showed that both deterministic and nondeterministic boustrophedon automata recognize the same class of two-dimensional languages, as they process their input in a manner analogous to a one-dimensional (string) automaton [1]. Moreover, since boustrophedon automata and returning automata are syntactically equivalent, Fernau et al. further showed that both of these models recognize the same class of two-dimensional languages [1]. However, despite their similarities in input head movement, the class of languages recognized by boustrophedon automata is a strict subset of the class of languages recognized by nondeterministic three-way two-dimensional automata [2].
To see where typewriter automata are positioned in the two-dimensional automaton recognition hierarchy, we first compare the model to the weaker two-way two-dimensional automaton. This restricted variant model is similar to the three-way two-dimensional automaton in Definition 2, but it may only move its input head downward and rightward.
Proof. The typewriter automaton T 1s recognizes the language L 1s in the following way. Starting at the top-left symbol of the input word, T 1s moves one position rightward to read a 1 in position (1, 0). It then makes a reset move to position (0, 1), and reads another 1 before accepting.
No two-way two-dimensional automaton can recognize the language L 1s , since if such an automaton recognized the language, the same accepting computation must also accept one of the 2 × 2 words having a 0 in either of the positions (1, 0) or (0, 1).
As the previous argument works in both the deterministic and nondeterministic cases, we have that L 2DFA-2W ⊂ L TDFA and L 2NFA-2W ⊂ L TFA .
Given our previous observation that typewriter automata and three-way two-dimensional automata are closely related, Theorem 5 may not come as much of a surprise; indeed, we previously noted that L 2DFA-2W ⊂ L 2DFA-3W and L 2NFA-2W ⊂ L 2NFA-3W . However, the fact that typewriter automata cannot make independent downward or leftward moves is limiting enough that we can refine the relationships between all three models to show that typewriter automata are positioned between the two-and three-way two-dimensional models.
Theorem 6. Let L stairs denote the language of n×n two-dimensional words over the alphabet Σ = {0, 1} having a contiguous 1 path of 1s forming a staircase pattern from the top-left corner to the bottom-right corner. Then L stairs can be recognized by a three-way two-dimensional automaton A, but not by any typewriter automaton.
Proof. The three-way two-dimensional automaton A recognizes the language L stairs in the following way. Starting at the top-left symbol of the input word, A makes an alternating series of rightward and downward moves, confirming after each move that it has read a 1. If, at some point during the computation, A reads a boundary marker # after a rightward move, it makes one leftward move and one downward move to confirm that it has read the following "bottom-right corner" pattern: If A confirms that it is in the bottom-right corner, then it accepts.
No typewriter automaton can recognize the language L stairs , since there is no general way for such an automaton to count rightward moves and verify that the corner-to-corner path is contiguous upon making a reset move. Thus, a typewriter automaton that verifies "treads" of the staircase pattern-i.e., pairs of horizontally adjacent 1s in each row-could not distinguish between the subwords # # # # # # 1 1 0 0 # 0 1 1 0 and # # # # # # 1 1 0 0 # 0 0 1 1 . 1 By contiguous, we mean that pairs of 1s are adjacent either horizontally or vertically, but not diagonally.
Again, as the previous argument works in both the deterministic and nondeterministic cases, we have that L TDFA ⊂ L 2DFA-3W and L TFA ⊂ L 2NFA-3W .
Similar to the more standard two-dimensional automaton models, we can show that a separation exists between the deterministic and nondeterministic variants of the typewriter automaton model with another small example language.
Theorem 7. Let L L denote the language of m × n two-dimensional words over the alphabet Σ = {0, 1} where m, n ≥ 2, the first column and last row of each word consist entirely of 1s, and all other symbols are 0. Then L L can be recognized by a nondeterministic typewriter automaton T L , but not by any deterministic typewriter automaton.
Proof. The nondeterministic typewriter automaton T L recognizes the language L L in the following way. Starting at the top-left symbol of the input word, T L verifies that the symbol in the first position of the current row is a 1, and it then makes rightward moves to check that the remainder of the row consists of 0s. Upon reading the boundary marker # at the end of the row, the automaton makes a reset move. During the computation of T L , it can nondeterministically guess that its input head has reached the bottom row of the input word. At this stage, the automaton reads each symbol in that row to verify whether it has read a 1. When T L reaches the boundary marker #, it makes one more reset move. If, after this move, the input head reads another boundary marker #, then T L accepts. No deterministic typewriter automaton can recognize the language L L , since such an automaton cannot guess that its input head is in the last row of the input word. Thus, if a deterministic automaton (correctly) rejects upon reading a 1 outside of the first column and last row of the input word, then it must also reject upon reading the occurrence of 1 in the last row and second column of the same word.
It is known that a nondeterministic boustrophedon automaton can recognize the same language L L defined in Theorem 7 and, therefore, so too can a deterministic boustrophedon automaton [1]. More generally, given the similarities between the input head movement of a typewriter automaton and that of a returning automaton, and the equivalence in recognition power between returning automata and boustrophedon automata, we can establish the following result.

Theorem 8. Nondeterministic typewriter automata and boustrophedon automata recognize the same class of languages.
Proof. To prove this result, we will show that a nondeterministic typewriter automaton can simulate the computation of a returning automaton and vice versa.
In one direction, a nondeterministic typewriter automaton T can recognize a language in L RFA by limiting any reset moves made by the transition function of T to occur only after reading a boundary marker. In this way, T reads each row of its input word completely from left to right.
In the other direction, to allow a returning automaton R to recognize a language in L TFA , we use the following construction. The automaton R begins by simulating the computation of the corresponding typewriter automaton. If, during this simulation, the typewriter automaton would have made a reset move, then R continues moving rightward while ignoring any non-boundary markers being read by its input head. After a boundary marker is read, R makes a deferred reset move and begins simulating the computation of the typewriter automaton on the next row.
Since boustrophedon automata and returning automata recognize the same class of languages, the preceding constructions show that boustrophedon automata and nondeterministic typewriter automata also recognize the same class of languages.
By combining Theorem 8 with the observation that L TDFA ⊂ L TFA , we see that boustrophedon automata can recognize all languages recognized by deterministic typewriter automata. However, the deterministic version of Theorem 8 does not hold, since (for example) the language L L is recognized by a boustrophedon automaton but not by a deterministic typewriter automaton.
Altogether, the results established in this section produce the inclusion hierarchy depicted in Figure 2.

Closure Properties
The closure properties of three-way two-dimensional automata are well-known. In the nondeterministic case, closure holds for the operations of union, row concatenation, and reversal (or row reflection) [4,5,16,17], while the model is not closed under the operations of intersection, complement, column concatenation, or rotation [5]. Focusing on the deterministic model, on the other hand, closure holds only for the operation of complement [17].
For boustrophedon automata, it is known that the class of languages recognized by this model is closed under union, intersection, complement, row concatenation, and reversal [1,2,11], but not under column concatenation or rotation [2,11].
Returning to the two-way two-dimensional automaton model briefly mentioned earlier, it is known that the deterministic variant is closed under complement while the nondeterministic variant is closed under union; closure does not hold for any other operation [13,15].
Since typewriter automata are positioned between the two-and three-way two-dimensional Row concatenation of two words v and w Things become more interesting, however, when we consider operations having positive closure results for the three-way model but not the two-way model; namely, the operations of row concatenation and reversal. Both operations are illustrated in Figure 3, and the operations can be extended to two-dimensional languages in the usual manner. For row concatenation, we can make use of nondeterminism in a typewriter automaton to establish closure. First, however, we must make a slight modification to our model.
Let us say that a typewriter automaton is "bottom-accepting" if it meets one of two conditions: either (i) upon following a transition to q accept , the input head of the automaton repeatedly makes reset moves until it reaches the bottom border of its input word; or (ii) upon reading a boundary marker # following a reset move, the automaton immediately halts and accepts if q accept is reachable from its current state. Note that, in the second condition, the boundary marker read following a reset move must necessarily be on the bottom border of the input word. Proof. We consider each of the two conditions for a typewriter automaton to be "bottomaccepting" separately.
If T follows a transition to q accept at some point during its computation, then we may take T ′ to be the same as T apart from the existing transitions to q accept . We add a new state p, redirect all existing transitions leading to q accept to instead lead to p, add a looping transition on p to make a reset move upon reading Σ \ {#}, and add a transition from p to q accept upon reading a boundary marker #.
If T reads a boundary marker # following a reset move and transitions to some state q, then its input head can only read boundary markers for the remainder of its computation. We may then take T ′ to be the same as T apart from its transition upon reading the first boundary marker following a reset move. In this case, we check whether q accept is reachable from q via some sequence of transitions on an arbitrary number of boundary markers, and we modify the transition function of T ′ to transition to q accept in the positive case or be undefined in the negative case.
Using this modification, we present the closure result for row concatenation.
Theorem 11. L TFA is closed under row concatenation.
Proof. Let L 1 and L 2 be languages recognized by bottom-accepting nondeterministic typewriter automata T 1 and T 2 , respectively. We construct a nondeterministic typewriter automaton S that recognizes the language L 1 ⊖ L 2 in the following way.
First, S simulates the bottom-accepting computation of T 1 . If this simulated computation accepts, then S nondeterministically makes some number of reset moves in the input word before simulating the bottom-accepting computation of T 2 and accepting if T 2 accepts. Since the row concatenation operation does not separate concatenated words by boundary markers, the nondeterministic reset moves allow S to guess when it has positioned its input head at the top-left symbol of the input word to T 2 .
Moving to the reversal operation, we will again make use of the bottom-accepting version of our typewriter automaton model.
Proof. Let L be a language recognized by a bottom-accepting nondeterministic typewriter automaton T . We construct a nondeterministic typewriter automaton T ′ that recognizes the reversal language L R in the following way.
Since T is bottom-accepting, its input head will be positioned in the bottom border of the input word at the end of its accepting computation. At the beginning of the computation of T ′ on some word from the language L R , its input head will be positioned at the topleft (non-boundary marker) symbol of the input word. For each row of the input word, T ′ searches the computation tree in reverse starting from a vertex c accept corresponding to an accepting configuration. If T ′ encounters a transition on the symbol currently being read by its input head at some vertex c of the computation tree, then T ′ simulates the computation from vertex c forward to vertex c accept . When T ′ encounters the first transition resulting in a reset move during this simulation, it moves its input head to the next row and begins another reverse search starting from the vertex c. If, at some point, T ′ arrives at the initial vertex c init of the computation tree, then it checks for a boundary marker after making its first reset move during the simulated computation. If the input head reads a boundary marker after the reset move, then T ′ accepts.

Operational State Complexity
Although state complexity is a well-studied measure for traditional automaton models, the same cannot be said for two-dimensional automaton models. The primary barrier to obtaining such results is the fact that there are currently no known general techniques for proving state complexity lower bounds in two dimensions, in contrast to the techniques known for one-dimensional (string) automata.
That being said, one-dimensional state complexity techniques have been used successfully to obtain bounds for projections of two-dimensional languages [14], and a number of elementary operational state complexity upper bounds have been obtained directly for certain two-dimensional language operations [13]. Of these elementary bounds, one pertaining to the three-way two-dimensional automaton model is particularly relevant: Proposition 13. Given two nondeterministic three-way two-dimensional automata A and B with m and n states, respectively, the automaton A ⊖ B contains at most m + n + 2 states.
The idea underlying the proof of Proposition 13 is that an additional two states are needed to move the input head from its accepting position in the input word to A to its initial position in the input word to B.
Since the operation of row concatenation is closed for nondeterministic typewriter automata, we can investigate its state complexity. Due to the fact that typewriter automata use a single reset move to shift the input head leftward and downward, we immediately incur a savings in the number of states needed to recognize a row concatenation language.
Theorem 14. Given two nondeterministic typewriter automata T 1 and T 2 with m and n states, respectively, the automaton T 1 ⊖ T 2 contains at most m + n states.
Proof. The proof of this theorem is analogous to the proof of Proposition 13, but with the two additional states-one for moving leftward repeatedly and one for moving downward to the following row-replaced by a single reset move transition.
Note that m+n states is presumably the matching lower bound for the row concatenation of two typewriter automaton languages, since the individual automata require m and n states to recognize their respective languages. However, as mentioned before, there is no known general technique for establishing lower bounds for two-dimensional automaton models.

Conclusion
In this paper, we introduced the notion of a typewriter automaton, drew connections between this model and the existing models of boustrophedon and returning automata, established recognition properties of the model relative to other two-dimensional automaton models, showed closure properties of certain language operations, and considered operational state complexity bounds. We showed that a typewriter automaton is capable of recognizing languages in between the two-and three-way variants of the standard two-dimensional automaton model, while the nondeterministic typewriter automaton has a recognition power equivalent to that of both boustrophedon and returning automata. We further established closure of the union, row concatenation, and reversal language operations for typewriter automata, and of the complement operation for the deterministic variant. Lastly, we investigated the operational state complexity of row concatenation for nondeterministic typewriter automata.
A number of fruitful questions remain surrounding the typewriter automaton model. For instance, knowing that the reversal operation is closed for nondeterministic typewriter automata and that the union operation is closed for the deterministic variant, it would be interesting to establish state complexity bounds for these operations, possibly using some as-yet-unknown proof technique. Beyond settling the question for typewriter automata, the same techniques may be applicable to boustrophedon automata or to the more general three-way two-dimensional automaton model. Future research may also consider the computational complexity of certain decision problems for typewriter automata, as has been done for boustrophedon automata.
In one of their papers on boustrophedon automata [2], Fernau et al. mention that boustrophedon scanning is not a new innovation, and that the technique is used widely in image processing applications; for example, in converting two-dimensional data to a one-dimensional string for compression, or in preprocessing data for optical character recognition. As the action of a typewriter automaton is somewhat similar to that of a boustrophedon (or a returning) automaton, it is not unreasonable to assume that the typewriter automaton model might also find applications in image processing or recognition. In particular, the left-toright movement of the input head combined with access to the reset move may be suitable for applications such as edge finding or mapping contiguous segments in images represented as two-dimensional words. Alongside the restricted two-and three-way two-dimensional automaton models, typewriter automata present a conceptually simpler model of computation relative to the standard four-way two-dimensional automaton model.