Title: ON THE TURING COMPLETENESS OF MODERN NEURAL NETWORK ARCHITECTURES

Abstract: Alternatives to recurrent neural networks, in particular, architectures based on attention or convolutions, have been gaining momentum for processing input sequences. In spite of their relevance, the computational properties of these alternatives have not yet been fully explored. We study the computational power of two of the most paradigmatic architectures exemplifying these mechanisms: the Transformer (Vaswani et al., 2017) and the Neural GPU (Kaiser & Sutskever, 2016). We show both models to be Turing complete exclusively based on their capacity to compute and access internal dense representations of the data. In particular, neither the Transformer nor the Neural GPU requires access to an external memory to become Turing complete. Our study also reveals some minimal sets of elements needed to obtain these completeness results.

1. INTRODUCTION:

There is an increasing interest in designing neural network architectures capable of learning algorithms from examples (Graves et al., 2014; Grefenstette et al., 2015; Joulin & Mikolov, 2015; Kaiser & Sutskever, 2016; Kurach et al., 2016; Dehghani et al., 2018) . A key requirement for any such an architecture is thus to have the capacity of implementing arbitrary algorithms, that is, to be Turing complete. Turing completeness often follows for these networks as they can be seen as a control unit with access to an unbounded memory; as such, they are capable of simulating any Turing machine.

On the other hand, the work by Siegelmann & Sontag (1995) has established a different way of looking at the Turing completeness of neural networks. In particular, their work establishes that recurrent neural networks (RNNs) are Turing complete even if only a bounded number of resources (i.e., neurons and weights) is allowed. This is based on two conditions: (1) the ability of RNNs to compute internal dense representations of the data, and (2) the mechanisms they use for accessing such representations. Hence, the view proposed by Siegelmann & Sontag shows that it is possible to release the full computational power of RNNs without arbitrarily increasing its model complexity.

Most of the early neural architectures proposed for learning algorithms correspond to extensions of RNNs -e.g., Neural Turing Machines (Graves et al., 2014) -, and hence they are Turing complete in the sense of Siegelmann & Sontag. However, a recent trend has shown the benefits of designing networks that manipulate sequences but do not directly apply a recurrence to sequentially process their input symbols. Architectures based on attention or convolutions are two prominent examples of this approach. In this work we look at the problem of Turing completeness à la Siegelmann & Sontag for two of the most paradigmatic models exemplifying these features: the Transformer (Vaswani et al., 2017) and the Neural GPU (Kaiser & Sutskever, 2016) .

The main contribution of our paper is to show that the Transformer and the Neural GPU are Turing complete based on their capacity to compute and access internal dense representations of the data. In particular, neither the Transformer nor the Neural GPU requires access to an external additional memory to become Turing complete. Thus the completeness holds for bounded architectures (bounded number of neurons and parameters). To prove this we assume that internal activations are represented as rational numbers with arbitrary precision. For the case of the Transformer we provide a direct simulation of a Turing machine, while for the case of the Neural GPU our result follows by simulating standard sequence-to-sequence RNNs. Our study also reveals some minimal sets of elements needed to obtain these completeness results. The computational power of Transformers and of Neural GPUs has been compared in the current literature (Dehghani et al., 2018) , but both are only informally used. Our paper provides a formal way of approaching this comparison.

For the sake of space, we only include sketch of some proofs in the body of the paper. The details for every proof can be found in the appendix.

Background work:

The study of the computational power of neural networks can be traced back to McCulloch & Pitts (1943) which established an analogy between neurons with hard-threshold activations and first order logic sentences, and Kleene (1956) that draw a connection between neural networks and finite automata. As mentioned earlier, the first work showing the Turing completeness of finite neural networks with linear connections was carried out by Siegelmann & Sontag (1992; 1995) . Since being Turing complete does not ensure the ability to actually learn algorithms in practice, there has been an increasing interest in enhancing RNNs with mechanisms for supporting this task. One strategy has been the addition of inductive biases in the form of external memory, being the Neural Turing Machine (NTM) (Graves et al., 2014) a paradigmatic example. To ensure that NTMs are differentiable, their memory is accessed via a soft attention mechanism (Bahdanau et al., 2014) . Other examples of architectures that extend RNNs with memory are the Stack-RNN (Joulin & Mikolov, 2015) , and the (De)Queue-RNNs (Grefenstette et al., 2015) . By Siegelmann & Sontag's results, all these architectures are Turing complete.

The Transformer architecture (Vaswani et al., 2017) is almost exclusively based on the attention mechanism, and it has achieved state of the art results on many language-processing tasks. While not initially designed to learn general algorithms, Dehghani et al. (2018) have advocated the need for enriching its architecture with several new features as a way to learn general procedures in practice. This enrichment is motivated by the empirical observation that the original Transformer architecture struggles to generalize to input of lengths not seen during training. We, in contrast, show that the original Transformer architecture is Turing complete, based on different considerations. These results do not contradict each other, but show the differences that may arise between theory and practice. For instance, Dehghani et al. (2018) assume fixed precision, while we allow arbitrary internal precision during computation. We think that both approaches can be complementary as our theoretical results can shed light on what are the intricacies of the original architecture, which aspects of it are candidates for change or improvement, and which others are strictly needed. For instance, our proof uses hard attention while the Transformer is often trained with soft attention (Vaswani et al., 2017) . See Section 3.3 for a discussion on these differences.

The Neural GPU is an architecture that mixes convolutions and gated recurrences over tridimensional tensors. It has been shown that NeuralGPUs are powerful enough to learn decimal multiplication from examples (Freivalds & Liepins, 2018) , being the first neural architecture capable of solving this problem end-to-end. The similarity of Neural GPUs and cellular automata has been used as an argument to state the Turing completeness of the architecture (Kaiser & Sutskever, 2016; Price et al., 2016) . Cellular automata are Turing complete (Smith III, 1971; Ollinger, 2012) and their completeness is established assuming an unbounded number of cells. In the Neural GPU architecture, in contrast, the number of cells that can be used during a computation is proportional to the size of the input sequence (Kaiser & Sutskever, 2016) . One can cope with the need for more cells by padding the Neural GPU input with additional (dummy) symbols, as much as needed for a particular computation. Nevertheless, this is only a partial solution, as for a Turing-complete model of computation, one cannot decide a priori how much memory is needed to solve a particular problem. Our results in this paper are somehow orthogonal to the previous argument; we show that one can leverage the dense representations of the Neural GPU cells to obtain Turing completeness without requiring to add cells beyond the ones used to store the input.

2. PRELIMINARIES:

We assume all weights and activations to be rational numbers of arbitrary precision. Moreover, we only allow the use of rational functions with rational coefficients. Most of our positive results make use of the piecewise-linear sigmoidal activation function σ : Q → Q, which is defined as

σ(x) = 0 x < 0, x 0 ≤ x ≤ 1, 1 x > 1.

(1)

We are mostly interested in sequence-to-sequence (seq-to-seq) neural network architectures that we next formalize. A seq-to-seq network N receives as input a sequence X = (x 1 , . . . , x n ) of vectors x i ∈ Q d , for some d > 0, and produces as output a sequence Y = (y 1 , . . . , y m ) of vectors y i ∈ Q d . Most of these types of architectures require a seed vector s and some stopping criterion for determining the length of the output. The latter is usually based on the generation of a particular output vector called an end of sequence mark. In our formalization instead, we allow a network to produce a fixed number r ≥ 0 of output vectors. Thus, for convenience we see a general seq-toseq network as a function N such that the value N (X, s, r) corresponds to an output sequence of the form Y = (y 1 , y 2 , . . . , y r ). With this definition, we can view every seq-to-seq network as a language recognizer of strings as follows.

Definition 2.1. A seq-to-seq language recognizer is a tuple A = (Σ, f, N, s, F), where Σ is a finite alphabet, f : Σ → Q d is an embedding function, N is a seq-to-seq network, s ∈ Q d is a seed vector, and F ⊆ Q d is a set of final vectors. We say that A accepts the string w ∈ Σ * , if there exists an integer r ∈ N such that N (f (w), s, r) = (y 1 , . . . , y r ) and y r ∈ F. The language accepted by A, denoted by L(A), is the set of all strings accepted by A.

We impose two additional restrictions over recognizers. The embedding function f : Σ → Q d should be computed by a Turing machine in time linear w.r.t. the size of Σ. This covers the two most typical ways of computing input embeddings from symbols: the one-hot encoding, and embeddings computed by fixed feed-forward networks. Moreover, the set F should also be recognizable in lineartime; given a vector f , the membership f ∈ F should be decided by a Turing machine working in linear time with respect to the size (in bits) of f . This covers the usual way of checking equality with a fixed end-of-sequence vector. We impose these restrictions to disallow the possibility of cheating by encoding arbitrary computations in the input embedding or the stop condition, while being permissive enough to construct meaningful embeddings and stoping criterions.

Finally, a class N of seq-to-seq neural network architectures defines the class L N composed of all the languages accepted by language recognizers that use networks in N . From these notions, the formalization of Turing completeness of a class N naturally follows.

Definition 2.2. A class N of seq-to-seq neural network architectures is Turing Complete if L N is exactly the class of languages recognized by Turing machines.

Given an input sequence X = (x 1 , . . . , x n ), a seed vector y 0 , and r ∈ N, an encoder-decoder RNN is given by the following two recursions

EQUATION

where V , W , U , R are matrices, b 1 and b 2 are vectors, O(•) is an output function, and f 1 and f 2 are activations functions. Equation ( 2) is called the RNN-encoder and (3) the RNN-decoder.

The next Theorem follows by inspection of the proof by Siegelmann & Sontag (1992; 1995) after adapting it to our formalization of encoder-decoder RNNs.

Theorem 2.3 (Siegelmann & Sontag (1992; 1995) ). The class of encoder-decoder RNNs is Turing complete. Turing completeness holds even if we restrict to the class in which R is the zero matrix, b 1 and b 2 are the zero vector, O(•) is the identity function, and f 1 and f 2 are the piecewise-linear sigmoidal activation σ.

3. THE TRANSFORMER ARCHITECTURE:

In this section we present a formalization of the Transformer architecture (Vaswani et al., 2017) , abstracting away from specific choices of functions and parameters. Our formalization is not meant to produce an efficient implementation of the Transformer, but to provide a simple setting over which its mathematical properties can be established in a formal way.

The Transformer is heavily based on the attention mechanism introduced next. Consider a scoring function score :

Q d × Q d → Q and a normalization function ρ : Q n → Q n , for d, n > 0. Assume that q ∈ Q d , and that K = (k 1 , . . . , k n ) and V = (v 1 , . . . , v n ) are tuples of elements in Q d .

A q-attention over (K, V ), denoted by Att(q, K, V ), is a vector a ∈ Q d defined as follows.

(s 1 , . . . , s n ) = ρ(score(q, k 1 ), score(q, k 2 ), . . . , score(q, k n ))

(4) a = s 1 v 1 + s 2 v 2 + • • • + s n v n .

(5) Usually, q is called the query, K the keys, and V the values. We do not pose any restriction on the scoring and normalization functions, as some of our results hold in general. We only require the normalization function to satisfy that there is a function

f ρ from Q to Q + such that for each x = (x 1 , . . . , x n ) ∈ Q n it is the case that the i-th component ρ i (x) of ρ(x) is equal to f ρ (x i )/ n j=1 f ρ (x j )

. Thus, a in Equation ( 5) is a convex combination of the vectors in V . When proving possibility results, we will need to pick specific scoring and normalization functions. A usual choice for the scoring function is a feed forward network with input (q, k i ) sometimes called additive attention (Bahdanau et al., 2014) . Another possibility is to use the dot product q, k i called multiplicative attention (Vaswani et al., 2017) . We use a combination of both: multiplicative attention plus a non linear function. For the normalization function, softmax is a standard choice. Nevertheless, in our proofs we use the hardmax function, which is obtained by setting f hardmax (x i ) = 1 if x i is the maximum value, and f hardmax (x i ) = 0 otherwise. Thus, for a vector x in which the maximum value occurs r times, we have that hardmax i (x) = 1 r if x i is the maximum value of x, and hardmax i (x) = 0 otherwise. We call it hard attention whenever hardmax is used as normalization function. As customary, for a function F :

Q d → Q d and a sequence X = (x 1 , x 2 , . . . , x n ), with x i ∈ Q d , we write F (X) to denote the sequence (F (x 1 ), . . . , F (x n )).

Transformer Encoder and Decoder A single-layer encoder of the Transformer is a parametric function Enc(X; θ) receiving a sequence X = (x 1 , . . . , x n ) of vectors in Q d and returning a sequence Z = (z 1 , . . . , z n ) of the same length of vectors in Q d . In general, we consider the parameters in Enc(X; θ) as functions Q(•), K(•), V (•), and O(•), all of them from Q d to Q d . The single-layer encoder is then defined as follows

EQUATION

•) are typically matrix multiplications, and O(•) a feed-forward network. The + x i and + a i summands are usually called residual connections (He et al., 2016a; b) . When the particular functions used as parameters are not important, we simply write Z = Enc(X).

The Transformer encoder is defined simply as the repeated application of single-layer encoders (with independent parameters), plus two final transformation functions K(•) and V (•) applied to every vector in the output sequence of the final layer. Thus the L-layer Transformer encoder is defined by the following recursion (with 1 ≤ ≤ L -1 and X 1 = X).

X +1 = Enc(X ; θ ), K = K(X L ), V = V (X L ).

(8) We use (K, V ) = TEnc L (X) to denote an L-layer Transformer encoder over the sequence X.

A single-layer decoder is similar to a single-layer encoder but with additional attention to an external pair of key-value vectors (K e , V e ). The input for the single-layer decoder is a sequence Y = (y 1 , . . . , y k ) plus the external pair (K e , V e ), and the output is a sequence Z = (z 1 , . . . , z k ). When defining a decoder layer we denote by Y j the sequence (y 1 , . . . , y j ), for 1 ≤ j ≤ k. The layer is also parameterized by four functions Q(•), K(•), V (•) and O(•) and is defined as follows.

p i = Att(Q(y i ), K(Y i ), V (Y i )) + y i (9) a i = Att(p i , K e , V e ) + p i (10) z i = O(a i ) + a i (11) Notice that the first (self) attention over (K(Y i ), V (Y i ))

considers the subsequence of Y only until index i and is used to generate a query p i to attend the external pair (K e , V e ). We denote the single-decoder layer by Dec((K e , V e ), Y ; θ).

The Transformer decoder is a repeated application of single-layer decoders, plus a transformation function F : Q d → Q d applied to the final vector of the decoded sequence. Thus, the output of the decoder is a single vector z ∈ Q d . Formally, the L-layer Transformer decoder is defined as

EQUATION

)

We use z = TDec L ((K e , V e ), Y ) to denote an L-layer Transformer decoder.

The complete Tansformer A Transformer network receives an input sequence X, a seed vector y 0 , and a value r ∈ N. Its output is a sequence Y = (y 1 , . . . , y r ) defined as y t+1 = TDec(TEnc(X), (y 0 , y 1 , . . . , y t )), for 0 ≤ t ≤ r -1.

(13) We denote the output sequence of the transformer as Y = (y 1 , y 2 , . . . , y r ) = Trans(X, y 0 , r).

3.1. INVARIANCE UNDER PROPORTIONS:

The Transformer, as defined above, is order-invariant: two input sequences that are permutations of each other produce exactly the same output. This is a consequence of the following property of the attention function: if K = (k 1 , . . . , k n ), V = (v 1 , . . . , v n ), and π : {1, . . . , n} → {1, . . . , n} is a permutation, then Att(q, K, V ) = Att(q, π(K), π(V )) for every query q. This weakness has motivated the need for including information about the order of the input sequence by other means; in particular, this is often achieved by using the so-called positional encodings (Vaswani et al., 2017; Shaw et al., 2018) , which we study below.

But before going into positional encodings, a natural question is what languages the Transformer can recognize without them. As a standard yardstick we use the well-studied class of regular languages, i.e., languages recognized by finite automata. Order-invariance implies that not every regular language can be recognized by a Transformer network. As an example, there is no Transformer network that can recognize the regular language (ab) * , as the latter is not order-invariant. A reasonable question then is whether the Transformer can express all regular languages which are order-invariant. It is possible to show that this is not the case by proving that the Transformer actually satisfies a stronger invariance property, which we call proportion invariance.

For a string w ∈ Σ * and a symbol a ∈ Σ, we use prop(a, w) to denote the ratio between the number of times that a appears in w and the length of w. Consider now the set PropInv(w) = {u ∈ Σ * | prop(a, w) = prop(a, u) for every a ∈ Σ}. Proposition 3.1. Let Trans be a Transformer, s a seed, r ∈ N, and f : Σ → Q d an embedding function. Then Trans(f (w), s, r) = Trans(f (u), s, r), for each u, w ∈ Σ * with u ∈ PropInv(w).

As an immediate corollary we obtain the following. Corollary 3.2. Consider the order-invariant regular language L = {w ∈ {a, b} * | w has an even number of a symbols}. Then L cannot be recognized by a Transformer network.

On the other hand, languages recognized by Transformer networks are not necessarily regular. Proposition 3.3. There is a Transformer network that recognizes the non-regular language S = {w ∈ {a, b} * | w has strictly more symbols a than symbols b}.

That is, the computational power of Transformer networks without positional encoding is both rather weak (they do not even contain order-invariant regular languages) and not so easy to capture (as they can express counting properties that go beyond regularity). As we show in the next section, the inclusion of positional encodings radically changes the picture.

3.2. POSITIONAL ENCODINGS AND COMPLETENESS OF THE TRANSFORMER:

Positional encodings come to remedy the order-invariance issue by providing information about the absolute positions of the symbols in the input. A positional encoding is just a function pos : N → Q d . Function pos combined with an embedding function f : Σ → Q d give rise to a new embedding function f pos : Σ × N → Q d such that f pos (a, i) = f (a) + pos(i). Thus, given an input string w = a 1 a 2 • • • a n ∈ Σ, the result of the embedding function f pos (w) provides a "new" input f pos (a 1 , 1), f pos (a 2 , 2), . . . , f pos (a n , n) to the Transformer encoder. Similarly, the Transformer decoder instead of receiving the sequence Y = (y 0 , y 1 , . . . , y t ) as input, it receives now the sequence Y = y 0 + pos(1), y 1 + pos(2), . . . , y t + pos(t + 1)

As for the case of the embedding functions, we require the positional encoding pos(i) to be computable by a Turing machine working in linear time w.r.t. the size (in bits) of i.

The main result of this section is the completeness of Transformers with positional encodings.

# qread s1 qread sn qread # → qread sn → qread s1 → qread sn n qread s1 2 qread # qread s2 qread s1                qinit s (t-1) . . . . . . . . . . . . # 1 . . . . . . . . . . . . . . . . . . . . .

Att Att:

computes index of cell computes last symbol at the next step (t + 1)

written at cell c (t+1) implements M 's transition function t) . . .

EQUATION

              

attends to the encoder and copies the corresponding symbol uses self attention to compute next state and the next symbol under M 's head Proof Sketch. We show that for every Turing machine M = (Q, Σ, δ, q init , F ) there exists a transformer that simulates the complete execution of M . We represent a string w = s 1 s 2 • • • s n ∈ Σ * as a sequence X of one-hot vectors with their corresponding positional encodings. Denote by q (t) ∈ Q the state of M at time t when processing w, and s (t) ∈ Σ the symbol under M 's head at time t.

m (t-1) q (t) c (t+1) q (t) s (t) v (t) m (t) q (t+1) s (t+1) q (t) s (t) q (t-1) qread q (t+1) v (t-1) q (t+1) v (t)

Similarly, v (t) ∈ Σ is the symbol written by M and m (t) ∈ {←, →} the head direction. We next describe how to construct a transformer Trans M that with input X produces a sequence y 0 , y 1 , y 2 , . . . such that y i contains information about q (i) and s (i) (encoded as one-hot vectors).

The construction and proof goes by induction. Assume the decoder receives y 0 , . . . , y t such that y i contains q (i) and s (i) . To construct y t+1 , in the first layer we just implement M 's transition function δ; note that δ(q (i) , s

(i) ) = (q (i+1) , v (i) , m (i) ) thus, we use (q (i) , s (i) ) to compute (q (i+1) , v (i) , m (i) )

for every i and store them in the sequence z 1 0 , . . . , z 1 t . This computation can be done with a twolayer feed-forward network. For the next layer, lets denote by c (i) the index of the cell that M is pointing to at time i. It can be proved that given z 1 0 , . . . , z 1 t one can compute (a representation of) c (i) and c (i+1) for every i ≤ t with a self-attention layer, and store them in z 2 0 , . . . , z 2 t . In particular, z 2 t contains c (t+1) which is the index to which M is going to be pointing to in the next time step. By using the residual connections we also store q (i+1) and v (i) in z 2 i . The final piece of our construction is to compute the symbol that the tape holds at index c (t+1) , that is, the symbol under M 's head at time t + 1. For this we use the following observation: the symbol at index c (t+1) in time t + 1 coincides with the last symbol written by M at index c (t+1) . Thus, we need to find the maximum value i ≤ t such that c (i ) = c (t+1) and then copy v (i ) which is the symbol that was written by M at time step i . This last computation can also be done with a self-attention layer. Thus, we attend directly to position i (hard attention plus positional encodings) and copy v (i ) which is exactly s (t+1) . We finally copy q (t+1) and s (t+1) into the output to construct y t+1 . Figure 1 shows a high-level diagram of the decoder computation.

There are several other details in the construction, in particular, at the beginning of the computation (first n steps), the decoder needs to attend to the encoder and copy the input symbols so they can later be processed as described above. Another detail is when M reaches a cell that has not been visited before, then the symbol under the head has to be set as # (the blank symbol). We show that all these decisions can be implemented with feed-forward networks plus attention. The complete construction uses one encoder layer, three decoder layers and vectors of dimension d = 2|Q| + 4|Σ| + 11 to store one-hot representations of states, symbols and some additional working space. All details can be found in the appendix.

3.3. DIFFERENCES WITH VASWANI ET AL. (2017)'S FRAMEWORK:

Although the general architecture that we presented closely follows that of Vaswani et al. (2017) , some choices for functions and parameters in our positive results are different to the usual choices in practice. For instance, we use hard attention which allow us to attend directly to specific positions. In contrast, Vaswani et al. (2017) use softmax to attend, plus sin-cos functions as positional encodings. The softmax, sin and cos are not rational functions, and thus, are forbidden in our formalization.

An interesting line for future work is to consider arbitrary functions but with additional restrictions, such as finite precision as done by Weiss et al. (2018) . Another difference is that for the function O(•) in Equation ( 11) our proof uses a feed-forward network with various layers, while in Vaswani et al. (2017) only two layers are used.

The need of arbitrary precision Our Turing-complete proof relies on having arbitrary precision for internal representations, in particular, for storing and manipulating positional encodings. Although having arbitrary precision is a standard assumption when studying the expressive power of neural networks (Cybenko (1989); Siegelmann & Sontag (1995) ) practical implementations rely on fixed precision hardware. If fixed precision is used, then positional encodings can be seen as functions of the form pos : N → A where A is a finite subset of Q d . Thus, the embedding function f pos can be seen as a regular embedding function f : Σ → Q d where Σ = Σ × A. Thus, whenever fixed precision is used, the net effect of having positional encodings is to just increase the size of the input alphabet. Then from Proposition 3.1 we obtain that the Transformer with positional encodings and fixed precision is not Turing complete. Although no longer Turing complete, one can still study the computational power of fixed-precision Transformers. We left this as future work.

4. NEURAL GPUS:

The Neural GPU (Kaiser & Sutskever, 2016 ) is an architecture that mixes convolutions and gated recurrences over tridimensional tensors. It is parameterized by three functions U (•) (update function), R(•) (reset function), and F (•). Given a tensor S ∈ Q h×w×d and a value r ∈ N, it produces a sequence S 1 , S 2 , . . . , S r given by the following recursive definition (with S 0 = S).

U t = U (S t-1 ), R t = R(S t-1 ), S t = U t S t-1 + (1 -U) F (R t S t-1 ).

where denotes the element-wise product, and 1 is a tensor with only 1's. Neural GPUs force functions U (•) and R(•) to produce a tensor of the same shape as its input with all values in [0, 1]. Thus, a Neural GPU resembles a gated recurrent unit (Cho et al., 2014) , with U working as the update gate and R as the reset gate. Functions U (•), R(•), and F (•) are defined as a convolution of its input with a 4-dimensional kernel bank with shape (k H , k W , d, d) plus a bias tensor, followed by a point-wise transformation

EQUATION

with different kernels and biases for U (•), R(•), and F (•).

To have an intuition on how the convolution K * S works, it is illustrative to think of S as an (h × w)-grid of (row) vectors and K as a (k H × k W )-grid of (d × d) matrices. More specifically, let s ij = S i,j,: , and K ij = K i,j,:,: , then K * S is a regular two-dimensional convolution in which scalar multiplication has been replaced by vector-matrix multiplication as in the following expression

EQUATION

where

∆ 1 (u) = u -k H /2 -1 and ∆ 2 (v) = v -k W /2 -1.

This intuition makes evident the similarity between Neural GPUs and cellular automata: S is a grid of cells, and in every iteration each cell is updated considering the values of its neighbors according to a fixed rule given by K (Kaiser & Sutskever, 2016) . As customary, we assume zero-padding when convolving outside S.

4.1. THE COMPUTATIONAL POWER OF NEURAL GPUS:

To study the computational power of Neural GPUs, we cast them as a standard seq-to-seq architecture. Given an input sequence, we put every vector in the first column of the tensor S. We also need to pick a special cell of S as the output cell from which we read the output vector in every iteration.

We pick the last cell of the first column of S. Formally, given a sequence X = (x 1 , . . . , x n ) with x i ∈ Q d , and a fixed value w ∈ N, we construct the tensor S ∈ Q n×w×d by leting S i,1,: = x i and S i,j,: = 0 for j > 1. The output of the Neural GPU, denoted by NGPU(X, r), is the sequence of vectors Y = (y 1 , y 2 , . . . , y r ) such that y t = S t n,1,: . Given this definition, we can naturally view the Neural GPUs as language recognizers (as formalized in Section 2).

Since the bias tensor B in Equation ( 14) is of the same size than S, the number of parameters in a Neural GPU grows with the size of the input. Thus, a Neural GPU cannot be considered as a fixed architecture. To tackle this issue we introduce the notion of uniform Neural GPU, as one in which for every bias B there exists a matrix B ∈ Q w×d such that B i,:,: = B for each i. Thus, uniform Neural GPUs can be finitely specified (as they have a constant number of parameters, not depending on the length of the input). We now establish the Turing completeness of this model. Theorem 4.1. The class of uniform Neural GPUs is Turing complete.

Proof sketch. The proof is based on simulating a seq-to-seq RNN; thus, completeness follows from Theorem 2.3. Consider an RNN encoder-decoder language recognizer, such that N is of dimension d and its encoder and decoder are defined by the equations h i = σ(x i W + h i-1 V ) and g t = σ(g t-1 U ), respectively, where g 0 = h n and n is the length of the input. We use a Neural GPU with input tensor S ∈ Q n×1×3d+3 . Let E i = S i,1,1:d and D i = S i,1,d+1:2d . The idea is to use E for the encoder and D for the decoder. We use kernel banks of shape (2, 1, 3d + 3, 3d + 3) with uniform bias tensors to simulate the following computation. In every step t, we first compute the value of σ(E t W + E t-1 V ) and store it in E t , and then reset E t-1 to zero. Similarly, in step t we update the vector in position D t-1 storing in it the value σ(D t-1 U + E t-1 U ) (for the value of E t-1 before the reset). We use the gating mechanism to ensure a sequential update of the cells such that at time t we update only positions E i and D j for i ≤ t and j ≤ t -1. Thus the updates on the D are always one iteration behind the update of E. Since the vectors in D are never reset to zero, they keep being updated which allows us to simulate an arbitrary long computation. In particular we prove that at iteration t it holds that E t = h t , and at iteration n + t it holds that D n = g t . We require 3d + 3 components, as we need to implement several gadgets for properly using the update and reset gates.

In particular, we need to store the value of E t-1 before we reset it. The detailed construction and the correctness proof can be found in the appendix.

The proof above makes use of kernels of shape (2, 1, d, d) to obtain Turing completeness. This is, in a sense, optimal, as one can easily prove that Neural GPUs with kernels of shape (1, 1, d, d) are not Turing complete, regardless of the size of d. In fact, for kernels of this shape the value of a cell of S at time t depends only on the value of the same cell in time t -1.

Zero padding vs circular convolution The proof of Theorem 4.1 requires the application of zero padding in convolution. This allows us to clearly differentiate internal cells from cells corresponding to the endpoints of the input sequence. Interestingly, Turing-completeness is lost if we replace zero padding with circular convolution. Formally, given S ∈ Q h×w×d , a circular convolution is obtained by defining S h+n,:,: = S n,:,: for n ∈ Z. One can prove that uniform Neural GPUs with circular convolutions cannot differentiate among periodic sequences of different length; in particular, they cannot check if a periodic input sequence is of even or odd length. This yields the following: Proposition 4.2. Uniform Neural GPUs with circular convolutions are not Turing complete.

Related to this last result is the empirical observation by Price et al. (2016) that Neural GPUs that learn to solve hard problems, e.g., binary multiplication, and which generalize to most of the inputs, struggle with highly symmetric (and nearly periodic) inputs. Actually, Price et al. (2016) exhibit examples of the form 11111111 × 11111111 failing for all inputs with eight or more 1s. We leave as future work to explore the implications of our theoretical results on this practical observation. Freivalds & Liepins (2018) simplified Neural GPUs and proved that, by considering piecewise linear activations and bidimensional input tensors instead of the original smooth activations and tridimensional tensors used by Kaiser & Sutskever (2016) , it is possible to achieve substantially better results in terms of training time and generalization. Our Turing completeness proof also relies on a bidimensional tensor and uses piecewise linear activations, thus providing theoretical evidence that these simplifications actually retain the full expressiveness of Neural GPUs while simplifying its practical applicability.

Bidimensional tensors and piecewise linear activations:



5. FINAL REMARKS AND FUTURE WORK:

We have presented an analysis of the Turing completeness of two popular neural architectures for sequence-processing tasks; namely, the Transformer, based on attention, and the Neural GPU, based on recurrent convolutions. We plan to further refine this analysis in the future. For example, our proof of Turing completeness for the Transformer requires the presence of residual connections, i.e., the +x i , +a i , +y i , and +p i summands in Equations (6-11), while our proof for Neural GPUs heavily relies on the gating mechanism. We will study whether these features are actually essential to obtain completeness.

We presented general abstract versions of both architectures in order to prove our theoretical results. Although we closely follow their original definitions, some choices for functions and parameters in our positive results are different to the usual choices in practice, most notably, the use of hard attention for the case of the Transformer, and the piecewise linear activation functions for both architectures. As we have mentioned, Freivalds & Liepins (2018) showed that for Neural GPUs piecewise linear activations actually help in practice, but for the case of the Transformer architecture more experimentation is needed to have a conclusive response. This is part of our future work.

Although our results are mostly of theoretical interest, they might lead to observations of practical interest. For example, Chen et al. (2018) have established the undecidability of several practical problems related to probabilistic language modeling with RNNs. This means that such problems can only be approached in practice via heuristics solutions. Many of the results in Chen et al. (2018) are, in fact, a consequence of the Turing completeness of RNNs as established by Siegelmann & Sontag (1995) . We plan to study to what extent our analogous undecidability results for Transformers and Neural GPUs imply undecidability for language modeling problems based on these architectures.

Finally, our results rely on being able to compute internal representations of arbitrary precision. It would be interesting to perform a theoretical study of the main properties of both architectures in a setting in which only finite precision is allowed, as have been recently carried out for RNNs (Weiss et al., 2018) . We also plan to tackle this problem in our future work.

A PROOFS FOR SECTION 2:

A.1 PROOF OF THEOREM 2.3

We first sketch the main idea of Siegelmann & Sontag's proof. We refer the reader to the original paper for details. Siegelmann & Sontag show how to simulate a two-stack machine M (and subsequently, a Turing machine) with a single RNN N with σ as activation. They first construct a network N 1 that, with 0 as initial state (h N1 0 = 0) and with a binary string w ∈ {0, 1} * as input sequence, produces a representation of w as a rational number and stores it as one of its internal values. Their internal representation of strings encodes every w as a rational number between 0 and 1. In particular, they use base 4 such that, for example, a string w = 100110 is encoded as (0.311331) 4 that is, its encoding is

3 × 4 -1 + 1 × 4 -2 + 1 × 4 -3 + 3 × 4 -4 + 3 × 4 -5 + 1 × 4 -6 .

This representation allows one to easily simulate stack operations as affine transformations plus σ activations. For instance, if x w is the value representing string w = b 1 b 2 • • • b n seen as a stack, then the top(w) operation can be defined as simply y = σ(4x w -2), since y = 1 if and only if b 1 = 1, and y = 0 if and only if b 1 = 0. Other stack operations can de similarly simulated. Using this representation, they construct a second network N 2 that simulates the two-stacks machine by using one neuron value to simulate each stack. The input w for the simulated machine M is assumed to be at an internal value given to N 2 as an initial state (h N2 0 ). Thus, N 2 expects only zeros as input. Actually, to make N 2 work for r steps, an input of the form 0 r should be provided.

Finally, they combine N 1 and N 2 to construct a network N which expects an input of the following form:

(b 1 , 1, 0)(b 2 , 1, 0) • • • (b n , 1, 0)(0, 0, 1)(0, 0, 0)(0, 0, 0) • • • (0, 0, 0). The idea is that the first component contains the input string w = b 1 b 2 • • • b n ,

the second component states when the input is active, and the third component is 1 only when the input is inactive for the first time. Before the input vector (0, 0, 1) the network N 1 is working. The input (0, 0, 1) is used to simulate a change from N 1 to N 2 , and the rest of input vectors (0, 0, 0) are provided to continue with N 2 for as many steps as needed. The number neurons that this construction needs to simulate a machine M with m states, is 10m + 30. 1It is clear that Siegelmann & Sontag's proof resembles a modern encoder-decoder RNN architecture, where N 1 is the encoder and N 2 is the decoder, thus it is straightforward to use the same construction to provide an RNN encoder-decoder N and a language recognizer A that uses N and simulates the two-stacks machine M . There are some details that is important to notice. Assume that N is given by the formulas in Equations ( 2) and (3). First, since N 2 in the above construction expects no input, we can safely assume that R in Equation ( 3) is the null matrix. Moreover, since A defines its own embedding function, we can ensure that every vector that we provide for the encoder part of N has a 1 in a fixed component, and thus we do not need the bias b 1 in Equation ( 2) since it can be simulated with one row of matrix V . We can do a similar construction for the bias b 2 (Equation (3)). Finally, Siegelmann & Sontag show that its construction can be modified such that a particular neuron of N 2 , say n , is always 0 except for the first time an accepting state of M is reached, in which case n = 1. Thus, one can consider O(•) (Equation ( 3)) as the identity function and add to A the stopping criterion that just checks if n is 1. This completes the proof sketch of Theorem 2.3.

B PROOFS FOR SECTION 3 B.1 PROOF OF PROPOSITION 3.1:

We extend the definition of the function PropInv to sequences of vectors. Given a sequence X = (x 1 , . . . , x n ) we use vals(X) to denote the set of all vectors occurring in X. Similarly as for strings, we use prop(v, X) as the number of times that v occurs in X divided by the length of X. Now we are ready to extend PropInv with the following definition:

PropInv(X) = {X | vals(X ) = vals(X) and prop(v, X) = prop(v, X ) for all v ∈ vals(X)}

Notice that for every embedding function f : Σ → Q d and string w ∈ Σ * , we have that if u ∈ PropInv(w) then f (u) ∈ PropInv(f (w)). Thus in order to prove that Trans(f (w), s, r) = Trans(f (u), s, r) for every u ∈ PropInv(w), it is enough to prove that

EQUATION

To further simplify the exposition of the proof we introduce another notation. We denote by p X v as the number of times that vector v occurs in X. Thus we have that X ∈ PropInv(X) if and only if, there exists a value γ ∈ Q + such that for every v ∈ vals(X) it holds that p X v = γp X v . We now have all the necessary to proceed with the proof of Proposition 3.1. We will prove it by proving the property in ( 16). Let X = (x 1 , . . . , x n ) be an arbitrary sequence of vectors, and let X = (x 1 , . . . , x m ) ∈ PropInv(X). Moreover, let Z = (z 1 , . . . , z n ) = Enc(X; θ) and Z = (z 1 , . . . , z m ) = Enc(X ; θ). We first prove the following property:

For every pair of indices (i, j) ∈ {1, . . . , n} × {1, . . . , m}, if

EQUATION

Lets (i, j) be a pair of indices such that x i = x j . From Equations (6-7) we have that z i = O(a i )+a i where a i = Att(Q(x i ), K(X), V (X)) + x i . Thus, since x i = x j , in order to prove z i = z j it is enough to prove that Att(Q(x i ), K(X), V (X)) = Att(Q(x j ), K(X ), V (X )). By equations (4-5) and the restriction over the form of normalization functions we have that

Att(Q(x i ), K(X), V (X)) = 1 α n =1 f ρ (score(Q(x i ), K(x )))V (x )

where α = n =1 f ρ (score(Q(x ), K(x ))). The above equation can be rewritten as

Att(Q(x i ), K(X), V (X)) = 1 α v∈vals(X) p X v f ρ (score(Q(x i ), K(v)))V (v) with α = v∈vals(X) p X v f ρ (score(Q(v), K(v)))

. By a similar reasoning we can write

Att(Q(x j ), K(X ), V (X )) = 1 β v∈vals(X ) p X v f ρ (score(Q(x j ), K(v)))V (v) with β = v∈vals(X ) p X v f ρ (score(Q(v), K(v))

). Now, since X ∈ PropInv(X) we know that vals(X) = vals(X ) and there exists a γ ∈ Q + such that p X v = γp X v for every v ∈ vals(X). Finally, from this last property, plus the fact that x i = x j we have

Att(Q(x j ), K(X ), V (X )) = 1 γα v∈vals(X) γp X v f ρ (score(Q(x j ), K(v)))V (v) = 1 α v∈vals(X) p X v f ρ (score(Q(x i ), K(v)))V (v) = Att(Q(x i ), K(X), V (X))

Which completes the proof of Property (17) above.

Consider now the complete encoder TEnc. Let (K, V ) = TEnc(X) and (K , V ) = TEnc(X ), and let q be an arbitrary vector. We will prove now that Att(q, K, V ) = Att(q, K , V ). By following a similar reasoning as for proving Property (17) (plus induction on the layers of TEnc) we obtain that if x i = x j then k i = k j and v i = v j , for every i ∈ {1, . . . , n} and j ∈ {1, . . . , m}. Thus, there exists a mapping M K : vals(X) → vals(K) such that M K (x i ) = k i and M K (x j ) = k j and similarly a mapping M V : vals(X) → vals(V ) such that M V (x i ) = v i and M V (x j ) = v j , for every i ∈ {1, . . . , n} and j ∈ {1, . . . , m}. Lets focus now on Att(q, K, V ). We have:

Att(q, K, V ) = 1 α n i=1 f ρ (score(q, k i ))v i with α = n i=1 f ρ (score(q, k i )).

Similarly as before, we can rewrite this as

Att(q, K, V ) = 1 α n i=1 f ρ (score(q, M K (x i )))M V (x i ) = 1 α v∈vals(X) p X v f ρ (score(q, M K (v)))M V (v) with α = v∈vals(X) p X v f ρ (score(q, M K (v))).

Similarly for Att(q, K , V ) we have

Att(q, K , V ) = 1 β m j=1 f ρ (score(q, M K (x j )))M V (x j ) = 1 β v∈vals(X ) p X v f ρ (score(q, M K (v)))M V (v)

And finally using that X ∈ PropInv(X) we obtain

Att(q, K , V ) = 1 β v∈vals(X ) p X v f ρ (score(q, M K (v)))M V (v) = 1 γα v∈vals(X) γp X v f ρ (score(q, M K (v)))M V (v) = 1 α v∈vals(X) p X v f ρ (score(q, K(v))V (v)

= Att(q, K, V ) which is what we wanted.

To complete the rest proof, consider Trans(X, y 0 , r) which is defined by the recursion y k+1 = TDec(TEnc(X), (y 0 , y 1 , . . . , y k ))

To prove that Trans(X, y 0 , r) = Trans(X , y 0 , r) we use an inductive argument. We know that y 1 = TDec(TEnc(X), (y 0 )) = TDec((K, V ), (y 0 )). Now TDec only access (K, V ) via attentions of the form Att(q, K, V ) and for the case of y 1 the vector q can only depend on y 0 , thus, from Att(q, K, V ) = Att(q, K , V ) we have that y 1 = TDec((K, V ), (y 0 )) = TDec((K , V ), (y 0 )) = TDec(TEnc(X ), (y 0 )). The rest of the steps follow by a simple induction on k.

B.2 PROOF OF COROLLARY 3.2:

To obtain a contradiction, assume that there is a language recognizer A that uses a Transformer network and such that L = L(A). Now consider the strings w 1 = aabb and w 2 = aaabbb. Since w 1 ∈ PropInv(w 2 ) by Proposition 3.1 we have that w 1 ∈ L(A) if and only if w 2 ∈ L(A) which is a contradiction since w 1 ∈ L but w 2 / ∈ L. This completes the proof of the corollary. Assume that the output for the encoder part of the transformer is X = (x 1 , . . . , x n ). First we use an encoder layer that implements the identity function. This can be trivially done using null functions for the self attention and through the residual connections this encoder layer shall preserve the original x i values. For the final V (•) and K(•) functions of the Transformer encoder (Equation ( 8)), we use V (x) = x the identity function and K(x) = [0, 0], giving V e = X and K e = ([0, 0], [0, 0], . . . , [0, 0]).

For the decoder we use a similar approach. We consider the identity in the self attention plus the residual (which can be done by just using the null functions for the self attention). Considering the external attention, that is the attention over (K e , V e ), we let score and ρ be arbitrary scoring and normalization functions. And finally for the function O(•) (Equation ( 11 In order to complete the proof we introduce some notation. Lets denote by # a (w) as the number of a's in w, and similarly # b (w) for the number of b's in w. Lets call c w as the value #a(w)-# b (w) n . We now prove that, for any string w ∈ {a, b} * if we consider f (w) = X = (x 1 , . . . , x n ) as the input sequence for Trans and we use initial value s = [0, 0] for the decoder, the complete network shall compute a sequence y 1 , y 2 , . . . , y r such that:

y i = [0, 0] i = 0 [c w , 0] i > 0

We proceed by induction. The base case trivially holds since y 0 = s = [0, 0]. Assume now that we are at step r and the input for the decoder is (y 0 , y 1 , . . . , y r ). We will show that y r+1 = [c w , 0]. Since we consider the identity in the self attention (Equation ( 9)), we have that p i = y i for every i in {0, . . . , i}. Now considering the external attention, that is the attention over (K e , V e ), Since all key vectors in K e are [0, 0], the external attention will produce the same score value for all positions. That is, score(p i , k j1 ) = score(p i , k j2 ) for every j 1 , j 2 . Lets call this value s . Thus we have that

ρ(score(p i , k 1 ), . . . , score(p i , k n )) = ρ(s , s , . . . , s ) = 1 n , 1 n , . . . , 1 n .

Then, since V e = X we have that

Att(p i , K e , V e ) = 1 n n =1 x = 1 n [0, # a (w) -# b (w)]

for every i ∈ {0, . . . , r}. The last equality holds since our embedding are f (a) = [0, 1] and f (b) = [0, -1], and so every a in w sums one and every b subtracts one. Thus, we have that

Att(p i , K e , V e ) = [0, c w ].

for every i ∈ {0, . . . , r}. In the next step, after the external attention plus the residual connection (Equation ( 10)) we have

a i = Att(p i , K e , V e ) + p i = Att(p i , K e , V e ) + y i = [0, c w ] + [c w , 0] = [c w , c w ] z i = O(a i ) + a i = O([c w , c w ]) + [c w , c w ] = [c w -c w , -c w ] + [c w , c w ] = [c w , 0] Finally, y r+1 = F (z r ) = z r = [c w , 0]

which is exactly what we wanted to prove.

To complete the proof, notice that # a (w) > # b (w) if and only if c w > 0. If we define F as Q + × Q, the recognizer A = (Σ, f, Trans, s, F) will accept the string w exactly when c w > 0, that is, w ∈ L(A) if and only if # a (w) > # b (w). That is exactly the language S, and so the proof is complete.

B.4 PROOF OF THEOREM 3.4

Let M = (Q, Σ, δ, q init , F ) be a Turing machine with a infinite tape and assume that the special symbol # ∈ Σ is used to mark blank positions in the tape. We make the following assumptions about how M works when processing an input string:

• M always moves its head either to the left or to the right (it never stays at the same cell).

• M begins at state q init pointing to the cell immediately to the left of the input string.

• M never makes a transition to the left of the initial position.

• Q has a special state q read used to read the complete input.

• Initially (time 0), M makes a transition to state q read and move its head to the right.

• While in state q read it moves to the right until symbol # is read.

• There are no transitions going out from accepting states (states in F ).

It is easy to prove that every general Turing machine is equivalent to one that satisfies the above assumptions. We prove that one can construct a transformer network Trans M that is able to simulate M on every possible input string.

The construction is somehow involved and uses several helping values, sequences and intermediate results.

To make the reading more easy we divide the construction and proof in three parts. We first give a high-level view of the strategy we use. Then we give some details on the architecture of the encoder and decoder needed to implement our strategy, and finally we formally prove that every part of our architecture can be actually implemented.

B.4.1 OVERVIEW OF THE CONSTRUCTION AND HIGH-LEVEL STRATEGY:

In the encoder part of Trans M we receive as input the string w = s 1 s 2 . . . s n . We first use an embedding function to represent every s i as a one-hot vector and add a positional encoding for every index. The encoder produces output (K e , V e ) where K e = (k e 1 , . . . , k e n ) and V e = (v e 1 , . . . , v e n ) are sequences of keys and values such that v e i contains the information of s i and k e i contains the information of the i-th positional encoding. We later show that this allows us to attend to every specific position and copy every input symbol from the encoder to the decoder (Lemma B.1).

In the decoder part of Trans M we simulate a complete execution of M over w = s 1 s 2 • • • s n . For this we define the following sequences (for i ≥ 0): q (i) : state of M at time i s (i) : symbol under the head of M at time i v (i) : symbol written by M at time i m (i) : head direction in the transition of M at time i For the case of m (i) we assume that -1 represents a movement to the left and 1 represents a movement to the right. In our construction we show how to build a decoder that computes all the above values for every time step i using self attention plus attention over the encoder part. Since the above values contain all the needed information to reconstruct the complete history of the computation, we can effectively simulate M .

In particular our construction produces the sequence of output vectors y 1 , y 2 , . . . such that, for every i, the vector y i contains information about q (i) and s (i) encoded as one-hot vectors. The construction and proof goes by induction. We begin with an initial vector y 0 that represents the state of the computation before it has started, that is q (0) = q init and s (0) = #. For the induction step we assume that we have already computed y 1 , . . . , y r such that y i contains information about q (i) and s (i) , and we show how with input (y 0 , y 1 , . . . , y r ) the decoder produces the next vector y r+1 containing q (r+1) and s (r+1) .

The overview of the construction is as follows. First notice that the transition function δ relates the above values with the following equation:

EQUATION

)

We prove that we can use a two-layer feed-forward network to mimic the transition function δ (Lemma B.2). Thus, given that the input vector y i contains q (i) and s (i) , we can produce the values q (i+1) , v (i) and m (i) (and store them as values in the decoder). In particular, since y r is in the input, we can produce q (r+1) which is part of what we need for y r+1 . In order to complete the construction we also need to compute the value s (r+1) , that is, we need to compute the symbol under the head of machine M at the next time step (time r + 1). We next describe at a high level, how this symbol can be computed with two additional decoder layers.

We first make some observations about s (i) that are fundamental in our computation. Assume that at time i the head of M is pointing to the cell at index k. Then we have three possibilities:

1. If i ≤ n, then s (i) = s i since M is still reading its input string.

2. If i > n and M has never written at index k, then s (i) = #, the blank symbol.

3. In other case, that is, if i > n and time i is not the first time that M is pointing to index k, then s (i) is the last symbol written by M at index k.

For the case (1) we can produce s (i) by simply attending to position i in the encoder part. Thus, if r + 1 ≤ n to produce s (r+1) we can just attend to index r + 1 in the encoder and copy this value to y r+1 . For cases ( 2) and ( 3) the solution is a bit more complicated, but almost all the important work is to compute what is the index that M is going to be pointing to in time r + 1.

To formalize this computation, lets denote by c (i) ∈ Z the following value:

c (i)

: the index of the cell to which the head of M is pointing to at time i Notice that value c (i) satisfies that c (i) = c (i-1) + m (i-1) . If we unroll this equation and assuming that c (0) = 0 we obtain that

c (i) = m (0) + m (1) + • • • + m (i-1) .

Then, at the step i in the decoder we have all the necessary to compute value c (i) but also the necessary to compute c (i+1) . We actually show that the computation (of a representation) of c (i) and c (i+1) can be done by using one layer of self attention (Lemma B.3).

We still need to define a final notion. With c (i) one can define the helping value (i) as follows:

(i) = max{j | j < i and c (j) = c (i) }.

Thus, (i) is a value such that c ( (i)) = c (i) , which means that at time i and at time (i) the head of M was pointing to the same cell. Moreover, (i) is the maximum value less than i that satisfies such condition. That is (i) is the last time (previous to i) in which M was pointing to position c (i) . First notice that in every step, M moves its head either to the right or to the left (it never stays in the same cell). This implies that for every i it holds that c (i) = c (i-1) , from which we obtain that (i) < i -1. Moreover, in the case that c (i) is visited for the first time at time step i, the value (i) is ill-defined. In such a case we let (i) = i -1. This makes (i) ≤ i -1 for all i, and allows us to check that c (i) is visited for the first time at time step i by just checking that (i) = i -1.

We now have all the necessary to explain how we compute our desired s (r+1) value. Assume that r + 1 > n (the case r + 1 ≤ n was already covered before). We first note that if (r + 1) = r then s (r+1) = # since this is the first time that cell c (r+1) is visited. On the other hand, if (r + 1) < r then s (r+1) is the value written by M at time (r + 1) which is exactly v ( (r+1)) . Thus, in this case we only need to attend to position (r + 1) and copy the value v ( (r+1)) to produce s (r+1) . We show that all this can be done with an additional self-attention decoder layer (Lemma B.4).

We have described at a high-level a decoder that, with input (y 0 , y 1 , . . . , y r ), computes the values q (r+1) and s (r+1) which is what we need to produce y r+1 . We next show all the details of this construction.

B.4.2 DETAILS OF THE ARCHITECTURE OF Trans M:

In this section we give more details on the architecture of the encoder and decoder needed to implement our strategy. We let several intermediate claims as lemmas that we formally prove in Section B.4.3.

ATTENTION MECHANISM:

For our attention mechanism we use the following non-linear function:

EQUATION

We note that ϕ(x) = -|x| and it can be implemented as ϕ(x) = -relu(x) -relu(-x). We use ϕ(•) to define a scoring function score ϕ :

R d × R d → R such that score ϕ (u, v) = ϕ( u, v ) = -| u, v |. Now, let q ∈ Q d , and K = (k 1 , . . . , k n ) and V = (v 1 , . . . , v n ) be tuples of elements in Q d .

We now describe how Att(q, K, V ) is generally computed when hard attention is considered. Assume first that there exists a single j ∈ {1, . . . , n} that maximizes score ϕ (q, k j ). In that case we have that Att(q, K, V ) = v j with

EQUATION

Thus, when computing hard attention with the function score ϕ (•) we essentially select the vector v j such that the dot product q, k j is as close to 0 as possible. If there is more than one index, say indexes j 1 , j 2 , . . . , j r , that minimizes the dot product q, k j then we have that

Att(q, K, V ) = 1 r v j1 + v j2 + • • • + v jr .

Thus, in the extreme case in which all dot products are equal q, k j for every index j, attention behaves just as an average of all value vectors, that is Att(q, K, V ) = 1 n n j=1 v j . We use all these properties of the hard attention in our proof.

VECTORS AND ENCODINGS:

We now describe the vectors that we use in the encoder and decoder parts of Trans M . The vectors that we use in the Trans M layers are of dimension d = 2|Q|+4|Σ|+11. To simplify the exposition, whenever we use a vector v ∈ Q d , we write it arranged in four groups of values as follows

v = [ q 1 , s 1 , x 1 , q 2 , s 2 , x 2 , x 3 , x 4 , x 5 , s 3 , x 6 , s 4 , x 7 x 8 , x 9 , x 10 , x 11 ]

where q i ∈ Q |Q| , s i ∈ Q |Σ| , and x i ∈ Q. Whenever in a vector of the above form any of the four groups of values is composed only of 0's, we just write '0, . . . , 0' where the length of this sequence is implicit in the length of the corresponding group. Finally, we denote by 0 q the vector in Q |Q| that has only 0's, and similarly 0 s the vector in Q |Σ| that has only 0's.

For a symbol s ∈ Σ, we use s to denote a one-hot vector in Q |Σ| that represents s. That is, given an enumeration π : Σ → {1, . . . , |Σ|}, the vector s has a 1 in position π(s) and a 0 in all other positions. Similarly, for q ∈ Q, we use q to denote a one-hot vector in Q |Q| that represents q.

EMBEDDINGS AND POSITIONAL ENCODINGS:

We have the necessary to introduce the embedding and positional encoding used in our construction.

We use an embedding function f : Σ → Q d defined as f (s) = [ 0, . . . , 0, 0, . . . , 0, s i , 0, 0 s , 0, 0, . . . , 0 ]

Our construction uses the positional encoding pos :

N → Q d such that pos(i) = [ 0, . . . , 0, 0, . . . , 0, 0, . . . , 0, 1, i, 1/i, 1/i 2 ]

Thus, given an input sequence

s 1 s 2 • • • s n ∈ Σ * , we have that f pos (s i ) = f (s i ) + pos(i) = [ 0, . . . , 0, 0, . . . , 0, s i , 0, 0 s , 0, 1, i, 1/i, 1/i 2 ]

We denote this last vector by x i . That is, if M receives the input string w = s 1 s 2 • • • s n , then the input for Trans M is the sequence (x 1 , x 2 , . . . , x n ). The need for using a positional encoding having values 1/i and 1/i 2 will be clear when we formally prove the correctness of our construction.

We need a final preliminary notion. In the formal construction of Trans M we also use the following helping sequences:

α (i) = s i 1 ≤ i ≤ n s n i > n β (i) = i i ≤ n n i > n

These are used to identify when M is still reading the input string.

CONSTRUCTION OF TEnc M:

The encoder part of Trans M is very simple. For TEnc M we use a single-layer encoder, such that TEnc M (x 1 , . . . , x n ) = (K e , V e ) where K e = (k 1 , . . . , k n ) and V e = (v 1 , . . . , v n ) such that k i = [ 0, . . . , 0, 0, . . . , 0, 0, . . . , 0, i, -1, 0, 0 ]

v i = [ 0, . . . , 0, 0, . . . , 0, s i , i, 0 s , 0, 0, . . . , 0 ]

It is straightforward to see that these vectors can be produced with a single encoder layer by using a trivial self attention, taking advantage of the residual connections in Equations ( 6) and ( 7), and then using linear transformations for V (•) and K(•) in Equation ( 8).

When constructing the decoder we use the following property. Lemma B.1. Let q ∈ Q d be a vector such that q = [ , . . . , , 1, j, , ] where j ∈ N and ' ' denotes an arbitrary value. Then we have that Att(q, K e , V e ) = [ 0, . . . , 0, 0, . . . , 0, α (j) , β (j) , 0 s , 0, 0, . . . , 0 ]

CONSTRUCTION OF TDec M

We next show how to construct the decoder part of Trans M to produce the sequence of outputs y 1 , y 2 , . . ., where y i is given by: ) , s (i) , m (i-1) , 0, . . . , 0, 0, . . . , 0, 0, . . . , 0 ]

y i = [ q (i

That is, y i contains information about the state of M at time i, the symbol under the head of M at time i, and the last direction followed by M (the direction of the head movement at time i -1). The need to include m (i-1) will be clear in the construction.

We consider as the starting vector for the decoder the vector y 0 = [ q init , # , 0, 0, . . . , 0, 0, . . . , 0, 0, . . . , 0 ]

We are assuming that m (-1) = 0 to represent that previous to time 0 there was no head movement.

Our construction resembles a proof by induction; we describe the architecture piece by piece and at the same time we show how for every r ≥ 0 our architecture constructs y r+1 from the previous vectors (y 0 , . . . , y r ).

Thus, assume that y 0 , . . . , y r satisfy the properties stated above. Since we are using positional encodings, the actual input for the first layer of the decoder is the sequence y 0 + pos(1), y 1 + pos(2), . . . , y r + pos(r + 1).

We denote by y i the vector y i plus its positional encoding. Thus we have that ) , s (i) , m (i-1) , 0, . . . , 0, 0, . . . , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ] For the first self attention in Equation ( 9) we just produce the identity which can be easily implemented with a trivial attention plus the residual connection. Thus, we produce the sequence of vectors (p 1 0 , p 1 1 , . . . , p 1 r ) such that p 1 i = y i . Since p 1 i is of the form [ , . . . , , 1, i + 1, , ] by Lemma B.1 we know that if we use p 1 i to attend over the encoder we obtain Att(p 1 i , K e , V e ) = [ 0, . . . , 0, 0, . . . , 0, α (i+1) , β (i+1) , 0 s , 0, 0, . . . , 0 ]

y i = [ q (i

Thus in Equation ( 10) we finally produce the vector a 1 i given by ) , s (i) , m (i-1) , 0, . . . , 0, α (i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ] (21)

a 1 i = Att(p 1 i , K e , V e ) + p 1 i = [ q (i

As the final piece of the first decoder layer we use a function O 1 (•) (Equation ( 11)) that satisfies the following lemma. Lemma B.2. There exists a two-layer feed-forward network O 1 : i) , -m (i-1) , q (i+1) , v (i) , m (i) , m (i-1) , 0, 0 0, . . . , 0, 0, . . . , 0 ]

Q d → Q d such that with input vector a 1 i (21) produces as output O 1 (a 1 i ) = [ -q (i) , -s (

That is, function O 1 (•) simulates transition δ(q (i) , s (i) ) to construct q (i+1) , v (i) , and m (i) besides some other linear transformations.

We finally produce as the output of the first decoder layer, the sequence (z 1 0 , z 1 1 , . . . , z 1 r ) such that i+1) , v (i) , m (i) , m (i-1) , 0, 0, α (i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ]

EQUATION

(22)

Notice that z 1 r already holds info about q (r+1) and m (r) which we need for constructing vector y r+1 . The single piece of information that we still need to construct is s (r+1) , that is, the symbol under the head of machine M at the next time step (time r + 1). We next describe how this symbol can be computed with two additional decoder layers.

Recall that c (i) is the cell to which M is pointing to at time i, and that it satisfies that c -1) . We can take advantage of this property to prove the following lemma.

(i) = m (0) + m (1) + • • • + m (i

Lemma B.3. Let Z 1 i = (z 1 0 , z 1 1 , . . . , z 1 i ).

There exists functions Q 2 (•), K 2 (•), and V 2 (•) defined by feed-forward networks such that

EQUATION

Lemma B.3 essentially shows that one can construct a representation for values c (i) and c (i+1) for every possible index i. In particular we will know the value c (r+1) that represents the cell to which the machine is pointing to in the next time step.

Continuing with the decoder layer, when using the self attention above and after adding the residual in Equation ( 9) we obtain the sequence of vectors (p 2 0 , p 2 1 , . . . , p 2 r ) such that: i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ]

EQUATION

From vectors (p 2 0 , p 2 1 , . . . , p 2 r ) and by using the residual connection in Equation ( 10) plus the output function O(•) in Equation ( 11) it is not difficult to produce the sequence of vectors (z 2 0 , z 2 1 , . . . , z 2 r ) such that z 2 i = p 2 i , as the output of the second decoder layer. That is, we have that i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ]

EQUATION

We now describe how can we use a third and final decoder layer to produce our desired s (r+1) value (the symbol under the head of M in the next time step). Recall that (i) is the last time (previous to i) in which M was pointing to position c (i) , or it is i -1 if this is the first time that M is pointing to c (i) . We can prove the following lemma. Lemma B.4. There exists functions Q 3 (•), K 3 (•), and V 3 (•) defined by feed-forward networks such that

Att(Q 3 (z 2 i ), K 3 (Z 2 i ), V 3 (Z 2 i )) = [ 0, .

. . , 0, 0, . . . , 0, 0 s , 0, v ( (i+1)) , (i + 1), 0, . . . , 0 ]

B.4.3 DETAILED PROOFS OF INTERMEDIATE LEMMAS:

Proof of Lemma B.1. Let q ∈ Q d be a vector such that q = [ , . . . , , 1, j, , ] where j ∈ N and ' ' is an arbitrary value. We next prove that Att(q, K e , V e ) = [ 0, . . . , 0, 0, . . . , 0, α (j) , β (j) , 0 s , 0, 0, . . . , 0 ]

where α (j) and β (j) are defined as

α (j) = s j 1 ≤ j ≤ n s n j > n β (j) = j j ≤ n n j > n Recall that K e = (k 1 , . . . , k n ) is such that k i = [ 0, . . . , 0, i, -1, 0, 0 ]. Then we have that score ϕ (q, k i ) = ϕ( q, k i ) = -| q, k i | = -|i -j|.

Notice that, if j ≤ n, then the above expression is maximized when i = j. Otherwise, if j > n then the expression is maximized when i = n. Then Att(q, K e , V e ) = v i where i = j if j ≤ n and i = n if j > n. We note that i as just defined is exactly β (j) . Thus, given that v i is defined as

v i = [ 0, . . . , 0, 0, . . . , 0, s i , i, 0 s , 0, 0, . . . , 0 ]

we obtain that Att(q, K e , V e = v i = [ 0, . . . , 0, 0, . . . , 0, s i , i , 0 s , 0, 0, . . . , 0 ] = [ 0, . . . , 0, 0, . . . , 0, α (j) , β (j) , 0 s , 0, 0, . . . , 0 ]

which is what we wanted to prove.

Proof of Lemma B.2. In order to prove the lemma we need some intermediate notions and properties. Assume that the enumeration π 1 : Σ → {1, . . . , |Σ|} is the one used to construct the one-hot vectors s for s ∈ Σ, and that π 2 : Q → {1, . . . , |Q|} is the one used to construct q with q ∈ Q. Using π 1 and π 2 one can construct an enumeration for the pairs in Q × Σ and then construct one-hot vectors for pairs in this set. Formally, given (q, s) ∈ Q × Σ we denote by (q, s) a one-hot vector with a 1 in position (π 1 (s) -1)|Q| + π 2 (q) and a 0 in every other position. To simplify the notation we use π(q, s) to denote (π 1 (s) -1)|Q| + π 2 (q). One can similarly construct an enumeration π for Q × Σ × {-1, 1} such that π (q, s, m) = π(q, s) if m = -1 and π (q, s, m) = |Q||Σ| + π(q, s) if m = 1. We denote by (q, s, m) the corresponding one-hot vector for every (q, s, m) ∈ Q × Σ × {-1, 1}. We next prove three helping properties. In every case q ∈ Q, s ∈ Σ, m ∈ {-1, 1}, and δ(•, •) is the transition function of machine M .

1. There exists f 1 :

Q |Q|+|Σ| → Q |Q||Σ| such that f 1 ([ q , s ]) = (q, s) .

2. There exists f δ : Q |Q||Σ| → Q 2|Q||Σ| such that f δ ( (q, s) ) = δ(q, s) .

3.. There exists f:

2 : Q 2|Q||Σ| → Q |Q|+|Σ|+1 such that f 2 ( (q, s, m) ) = [ q , s , m ].

To show (1), lets denote by S i , with i ∈ {1, . . . , |Σ|}, a matrix of dimensions |Σ| × |Q| such that S i has its i-th row with 1's and it is 0 everywhere else. We note that for every s ∈ Σ it holds that s S i = 1 if and only if i = π 1 (s) and it is 0 otherwise. Now, consider the vector v (q,s)

v (q,s) = [ q + s S 1 , q + s S 2 , . . . , q + s S |Σ| ]

We first note that for every i ∈ {1, . . . , |Σ|}, if i = π 1 (s) then q + s S i = q + 0 = q . Moreover q + s S π1(s) = q + 1 is a vector that has a 2 exactly at index π 2 (q), and it is 1 in all other positions. Thus, the vector v (q,s) has a 2 exactly at position (π 1 (s) -1)|Q| + π 2 (q) and it is either 0 or 1 in every other position. Now, lets denote by o a vector in Q |Q||Σ| that has a 1 in every position and consider the following affine transformation

EQUATION

Vector g 1 ([ q , s ]) has a 1 only at position (π 1 (s) -1)|Q| + π 2 (q) = π(q, s) and it is less than or equal to 0 in every other position. Thus, to construct f 1 (•) we apply the piecewise-linear sigmoidal activation σ(•) (see Equation ( 1)) to obtain

f 1 ([ q , s ]) = σ(g 1 ([ q , s ])) = σ(v (q,s) -o) = (q, s) ,

which is what we wanted. Now, to show (2), lets denote by M δ a matrix of dimensions (|Q||Σ|) × (2|Q||Σ|) constructed as follows. For (q, s) ∈ Q × Σ, if δ(q, s) = (p, r, m) then M δ has a 1 at position (π(q, s), π (p, r, m))

and it has a 0 in every other position, that is M δ π(q,s),: = (p, r, m) = δ(q, s) . It is straightforward to see that (q, s) M δ = δ(q, s) , and thus we can define f 2 (•) as f 2 ( (q, s) ) = (q, s) M δ = δ(q, s) .

To show (3), consider the matrix A of dimensions (2|Q||Σ|) × (|Q| + |Σ| + 1) such that A π (q,s,m),: = [ q , s , m ].

Then we define f 3 (•) as f 3 ( (q, s, m) ) = (q, s, m) A = [ q , s , m ].

We are now ready to begin with the proof of the lemma. Recall that a 1 i is given by a i) , m (i-1) , 0, 0 0, . . . , 0, 0, . . . , 0 ]

EQUATION

We first use function h 1 (•) that works as follows. Lets denote by m(i-1) the value 1 2 m

(i-1) + 1 2 . Note that m(i-1) is 0 if m (i-1) = -1, it is 1 2 if m (i-1) = 0 and it is 1 if m (i-1) = 1.

We use this transformation just to represent m (i-1) with a value between 0 and 1. Now, consider h 1 (a 1 i ) defined by h 1 (a 1 i ) = [ q (i) , s (i) , m(i-1) , g 1 ([ q (i) , s (i) ]) ] where g 1 (•) is the function defined above in Equation ( 25). It is clear that h 1 (•) is an affine transformation. Moreover, we note that except for g 1 ([ q (i) , s (i) ]) all values in h 1 (a 1 i ) are between 0 and 1. Thus if we apply function σ( ) , s (i) , m(i-1) , (q (i) , s (i) ) ]

•) to h 1 (a 1 i ) we obtain σ(h 1 (a 1 i )) = [ q (i) , s (i) , m(i-1) , σ(g 1 ([ q (i) , s (i) ])) ] = [ q (i

Then we can define h 2 (•) such that

h 2 (σ(h 1 (a 1 i ))) = [ q (i) , s (i) , 2 m(i-1) -1, f 2 ( (q (i) , s (i) ) ) ] = [ q (i) , s (i) , m (i-1) , δ(q (i) , s (i) ) ] = [ q (i) , s (i) , m (i-1) , (q (i+1) , v (i) , m (i) ) ]

Now we can define h 3 (•) as

h 3 (h 2 (σ(h 1 (a 1 i )))) = [ q (i) , s (i) , m (i-1) , f 3 ( (q (i+1) , v (i) , m (i) ) ) ] = [ q (i) , s (i) , m (i-1) , q (i+1) , v (i) , m (i) ]

Finally we can apply a function h 4 (•) to just reorder the values and multiply some components by -1 to complete our construction i) , m (i-1) , 0, 0 0, . . . , 0, 0, . . . , 0 ]

EQUATION

We note that we applied a single non-linearity and all other functions are affine transformations.

Thus O 1 (•) can be implemented with a two-layer feed-forward network.

Proof of Lemma B.3. Recall that z 1 i is the following vector

z 1 i = [ 0, . . . , 0, q (i+1) , v (i) , m (i) , m (i-1) , 0, 0, α (i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ] We consider Q 2 : Q d → Q d and K 2 : Q d → Q d as

trivial functions that for every input produce an output vector composed of only 0's. Moreover, we consider V 2 : Q d → Q d such that for every j ∈ {0, 1, . . . , i} V 2 (z 1 j ) = [ 0, . . . , 0, 0 q , 0 s , 0, 0, m (j) , m (j-1) , 0, . . . , 0, 0, . . . , 0 ] Then, since K 2 (z 1 j ) is the vector with only zeros, then score ϕ (Q 2 (z 1 i ), K 2 (z 1 j )) = 0 for every j ∈ {0, . . . , i}. Thus, we have that the attention Att(Q

EQUATION

i j=0 m (j-1) , 0, . . . , 0, 0, . . . , 0 ]

Then, since m

(0) + • • • + m (i) = c (i+1) and m (-1) + m (0) + • • • + m (i-1) = c (i) we have that Att(Q 2 (z 1 i ), K 2 (Z 1 i ), V 2 (Z 1 i ))

= [ 0, . . . , 0, 0 q , 0 s , 0, 0, c (i+1) (i+1) , c (i) (i+1) , 0, . . . , 0, 0, . . . , 0 ]

which is exactly what we wanted to show.

Proof of Lemma B.4. Recall that z 2 i is the following vector z 2 i = [ 0, . . . , 0, q (i+1) , v (i) , m (i) , m (i-1) , c (i+1) (i+1) , c (i) (i+1) , α (i+1) , β (i+1) , 0 s , 0, 1, (i + 1), 1/(i + 1), 1/(i + 1) 2 ]

We need to construct functions Q 3 (•), K 3 (•), and V 3 (•) such that Att(Q 3 (z 2 i ), K 3 (Z 2 i ), V 3 (Z 2 i )) = [ 0, . . . , 0, 0, . . . , 0, 0 s , 0, v ( (i+1)) , (i + 1), 0, . . . , 0 ]

We first define the query function

Q 3 : Q d → Q d such that Q 3 (z 2 i ) = [ 0, .

. . , 0 0, . . . , 0, 0, . . . , 0, 0, c (i+1) (i+1) , 1 (i+1) , 1

3(i+1) 2 ]

Now, for every j ∈ {0, 1, . . . , i} we define K 3 :

Q d → Q d and V 3 : Q d → Q d such that

K 3 (z 2 j ) = [ 0, . . . , 0 0, . . . , 0, 0, . . . , 0, 0, 1 (j+1) , -c (j) (j+1) , 1 (j+1) 2 ] V 3 (z 2 j ) = [ 0, . . . , 0, 0, . . . , 0, 0 s , 0, v (j) , j, 0, . . . , 0 ] It is clear that the three functions are linear transformations and thus they can be defined by feedforward networks. Consider now the attention Att(Q 3 (z 2 i ), K 3 (Z 2 i ), V 3 (Z 2 i )). In order to compute this value, and since we are considering hard attention, we need to find the value j ∈ {0, 1, . . . , i} that maximizes score ϕ (Q 3 (z 2 i ), K 3 (z 2 j )) = ϕ( Q 3 (z 2 i ), K 3 (z 2 j ) ). Actually, assumming that such value is unique, lets say j , then we have that Att(Q 3 (z 2 i ), K 3 (Z 2 i ), V 3 (Z 2 i )) = V 3 (z 2 j ). We next show that given our definitions above, it always holds that j = (i + 1) and then V 3 (z 2 j ) is exactly the vector that we wanted to obtain.

To simplify the notation, we denote by χ i j the dot product Q 3 (z 2 i ), K 3 (z 2 j ) . Thus, we need to find j = arg max j ϕ(χ i j ). Moreover, given the definition of ϕ (see Equation ( 20))we have that arg max j∈{0,...,i} ϕ(χ i j ) = arg min j∈{0,...,i}

|χ i j |.

Then, it is enough to prove that arg min j∈{0,...,i} |χ i j | = (i + 1). Now, by our definition of Q 3 (•) and K 3 (•) we have that

EQUATION

i+1) (i + 1)(j + 1) -c (j) (i + 1)(j + 1) + 1 3(i + 1) 2 (j + 1) 2 = ε i ε j • c (i+1) -c (j) + ε i ε j 3

where ε k = 1 (k+1) . We next prove the following auxiliary property.

If j 1 is such that c (j1) = c (i+1) and j 2 is such that c (j2) = c (i+1) , then

EQUATION

In order to prove (26), assume first that j 1 ∈ {0, . . . , i} is such that c (j1) = c (i+1) . Then we have that |c (i+1) -c (j1) | ≥ 1 since c (i+1) and c (j1) are integer values. From this we have two possibilities for χ i j1 :

where b 1 = σ((r + 1) -β (r+1) ) and b 2 = σ( (r + 1) -(r -1)). By the definition of β (r+1) we know that β (r+1) = r + 1 whenever r + 1 ≤ n, and β (r+1) = n if r + 1 > n. Thus we have that

b 1 = 0 if r + 1 ≤ n 1 if r + 1 > n

For the case of b 2 , since (r + 1) ≤ r we have that b 2 = 1 if (r + 1) = r and it is 0 otherwise, thus b 2 = 1 if (r + 1) = r 0 if (r + 1) = r

Then, we can use the if function in Lemma B.6 to implement a function f 2 (•) such that ) , m (r) , α (r+1) , b 1 , v ( (r+1)) ] if b 2 = 0, [ q (r+1) , m (r) , α (r+1) , b 1 , # ] if b 2 = 1.

f 2 (σ(f 1 (z 3 r ))) = [ q (r+1

We can use again the if function in Lemma B.6 to implement a function f 3 (•) such that ) , m (r) , α (r+1) ] if b 2 = 0 and b 1 = 0, [ q (r+1) , m (r) , v ( (r+1)) ] if b 2 = 0 and b 1 = 1, [ q (r+1) , m (r) , α (r+1) ] if b 2 = 1 and b 1 = 0, [ q (r+1) , m (r) , # ] if b 2 = 1 and b 1 = 1, which can be rewritten as ) , m (r) , α (r+1) ] if r + 1 ≤ n, [ q (r+1) , m (r) , # ] if r + 1 > n and (r + 1) = r, [ q (r+1) , m (r) , v ( (r+1)) ] if r + 1 > n and (r + 1) = r.

f 3 (f 2 (σ(f 1 (z 3 r )))) =        [ q (r+1

f 3 (f 2 (σ(f 1 (z 3 r )))) =    [ q (r+1

From this, it is easy to prove that f 3 (f 2 (σ(f 1 (z 3 r )))) = [ q (r+1) , m (r) , s (r+1) ].

This can be obtained from the following observation. If r + 1 ≤ n then α (r+1) = s r+1 = s (r+1) . If r + 1 > n and (r + 1) = r then we know that c (r+1) is visited by M for the first time at time r + 1 and it is outside the original input, which implies that s (r+1) = #. Finally, If r + 1 > n and (r + 1) = r, then we know that c (r+1) has been visited before at time (r + 1), and thus s (r+1) = v ( (r+1)) .

The final piece of the proof is to just convert m (r) back to its value m (r) , reorder the values and add 0's to obtain y r+1 . We do all this with a final linear transformation f 4 (•) such that r+1) , s (r+1) , m (r) , 0, . . . , 0, 0, . . . , 0, 0, . . . , 0 ] = y r+1 which completes our proof.

EQUATION

C PROOFS FOR SECTION 4

C.1 PROOF OF THEOREM 4.1

The formulas of the Neural GPU in detail are as follows (with S 0 the initial input tensor):

U t = U (S t-1 ) R t = R(S t-1 ) S t = U t S t-1 + (1 -U) F (R t S t-1 )

With U (•), R(•), and F (•) defined as

U (X) = f U (K U * X + B U ) R(X) = f R (K R * X + B R ) F (X) = f F (K F * X + B F )

Consider now an RNN encoder-decoder N of dimension d and composed of the equations

h i = σ(x i W + h i-1 V ) g t = σ(g t-1 U )

with h 0 = 0 and g 0 = h n where n is the length of the input.

CONSTRUCTING THE NEURAL GPU TO SIMULATE N:

We construct a Neural GPU network NGPU that simulates N as follows. Assume that the input of N is X = (x 1 , . . . , x n ). Then we first construct the sequence X = (x 1 , . . . , x n ) such that x i = [x i , 0, 0, 1, 1, 0] with 0 ∈ Q d the vector with all values as 0. Notice that x i ∈ Q 3d+3 , moreover it is straightforward that if x i was constructed from an embedding function f : Σ → Q d applied to a symbol a ∈ Σ, then x i can also be constructed with an embedding function f : Σ → Q 3d+3 such that f (a) = [f (a), 0, 0, 1, 1, 0].

We consider an input tensor S ∈ Q n×1×3d+3 such that for every i ∈ {1, . . . , n} it holds that S i,1,: = x i = [x i , 0, 0, 1, 1, 0]. Notice that since we picked w = 1, our tensor S is actually a 2D grid. Our proof shows that a bi-dimensional tensor is enough for simulating an RNN.

We now describe how to construct the kernel banks K U , K R and K F of shape (2, 1, 3d + 3, 3d + 3).

Notice that for each kernel K X we essentially have to define two matrices K X 1,1,:,: and K X 2,1,:,: each one of dimension (3d + 3) × (3d + 3). We begin by defining every matrix in K F as block matrices. When defining the matrices, all blank spaces are considered to be 0.

K F 1,1,:,: =    V V F 1    K F 2,1,:,: =    W W U U F 2   

where F 1 and F 2 are 3 × 3 matrices defined by F 1 = 1 0 0 0 0 0 0 0 0 F 2 = 0 1 0 0 0 0 0 0 0

:

The idea presented above allows one to linearly simulate M , that is, each step of M is simulated with a constant number of steps of the corresponding RNN. Siegelmann & Sontag show that, with a refinement of the above encoding one can simulate M in real-time, that is, a single step of M is simulated with a single step of the recurrent network. The 10m + 30 is the bound given by a simulation with slow-down of two. See the original paper for details(Siegelmann & Sontag, 1995).

Figures and Tables:

Figure 1: High-level structure of the decoder part of Trans M . Theorem 3.4. The class of Transformer networks with positional encodings is Turing complete.

PROOF OFPROPOSITION 3.3    We construct a language recognizer A = (Σ, f, Trans, s, F) with Trans a very simple Transformer network with dimension d = 2 and using just one layer of encoder and one layer of decoder, such that L(A) = {w ∈ {a, b} * | w has strictly more symbols a than symbols b}. As embedding function, we use f (a) = [0, 1] and f (b) = [0, -1].

)) we use a single layer neural network implementing the affine transformation O([x, y]) = [y -x, -y] such that O([x, y]) + [x, y] = [y, 0]. The final function F (•) is just the identity function.

Peer review (iclr2019):
 This paper presents interesting theoretical results on Turing completeness of the Transformer and Neural GPU architectures, as modern architectures based on attention and convolutions, under particular assumptions. The basis of proofs in the paper relies on Turing completeness of the seq2seq architecture, which is Turing complete since it contains Turing complete RNNs. Turing completeness of the Transformer and the Neural GPU is proven by showing they can simulate seq2seq architecture. The Transformer, using additive hard attention and residual connections, is Turing complete in the case when positional encoding is used. Otherwise, if no positional encoding is used, the model is order-invariant which makes it not Turing complete. A version of the Neural GPU, dubbed Uniform Neural GPU is proven to be Turing complete. Moreover, the presented theoretical results are backed by a recent publication by Karlis and Liepins. Interestingly, Neural GPUs using circular convolutions are not Turing complete, while the ones using zero padding are. The repercussion of the paper for similar architectures is the not just in the theoretical section but also in a set of discoveries of practical importance, like the importance of the use of residual connections, positional coding in Transformers, and zero padding in Neural GPUs. Albeit the paper presents an original and significant theoretical progress and is well written, it is not fit for ICLR, primarily as the paper is impossible to review and verify without a thorough perusal and analysis of the appendix. Although the results and the proof sketches fit the body of the paper, the necessity of verifying proofs makes this paper 23 pages long and makes it a better fit for a journal and not a conference.