Abstract
While Recurrent Neural Networks (RNNs) are famously known to be Turing complete, this relies on infinite precision in the states and unbounded computation time. We consider the case of RNNs with finite precision whose computation time is linear in the input length. Under these limitations, we show that different RNN variants have different computational power. In particular, we show that the LSTM and the Elman-RNN with ReLU activation are strictly stronger than the RNN with a squashing activation and the GRU. This is achieved because LSTMs and ReLU-RNNs can easily implement counting behavior. We show empirically that the LSTM does indeed learn to effectively use the counting mechanism.
Introduction: The "Counting" Gap
In theoretical computer science, Recurrent Neural Networks (RNNs) are often described as "Turing complete." However, this proof relies on two unrealistic assumptions: infinite precision and unbounded computation time. In practical applications, such as Natural Language Processing (NLP), we use finite-precision arithmetic (e.g., 32-bit floats) and process sequences in linear time. This research investigates whether different RNN architectures possess distinct computational limits under these practical constraints. Specifically, we challenge the common assumption that LSTMs and GRUs are computationally equivalent.
Theoretical Framework: Input-Bound Finite-Precision RNNs
We introduce the concept of Input-Bound Finite-Precision RNNs (IBFP-RNNs) to model how RNNs operate in real-world scenarios. To compare architectures, we map RNNs to Simplified $k$-Counter Machines (SKCM)—finite-state automata equipped with $k$ counters that can be incremented, decremented, or compared to zero.
The Saturation Barrier and Counting Mechanisms
Standard RNNs (SRNNs) and GRUs utilize "squashing" functions (tanh or sigmoid), which force state values into a narrow range (e.g., [-1, 1]). As a network attempts to count higher, values converge, eventually becoming indistinguishable due to finite precision.
Conversely, the LSTM's "cell state" ($c_t$) is uniquely suited for counting. Its additive update mechanism ($c_t = f_t \circ c_{t-1} + i_t \circ \tilde{c}_t$) allows it to function as a linear accumulator. By appropriately setting gates, an LSTM can increment, decrement, or hold a value indefinitely without saturation.
The GRU lacks this capability due to its interpolation gate, which ties the "forget" and "input" mechanisms ($h_t = z_t \circ h_{t-1} + (1 - z_t) \circ \tilde{h}_t$). This structure prevents the state from growing linearly, effectively restricting the GRU to a finite-state regime. Interestingly, even a simple RNN can count if it employs ReLU activations, as the lack of saturation allows for linear growth across multiple dimensions.
Empirical Evaluation
We evaluated these models on formal languages requiring counting: $a^n b^n$ (context-free, one counter) and $a^n b^n c^n$ (context-sensitive, two counters). Models were trained on small values of $n$ and tested on significantly larger values to assess algorithmic generalization.
Key Results
- Generalization Performance: LSTMs trained on $a^n b^n$ for $n \le 100$ generalized perfectly to $n=256$. GRUs failed to generalize beyond their training range, typically failing around $n=38$.
- Accuracy: On a 1000-sample test set, the LSTM achieved 100% accuracy on $a^n b^n$ and 98.6% on $a^n b^n c^n$. The GRU scored significantly lower, at approximately 87% and 86.9%, respectively.
- Visual Evidence: State visualizations confirm these findings. As shown in the figure below, LSTM dimensions exhibit perfect linear ramps, indicating an explicit counting mechanism. In contrast, GRU activations appear erratic and saturated, failing to capture the underlying counting logic.
Conclusion and Future Work
While LSTMs are theoretically limited by floating-point precision (e.g., 32-bit floats can represent integers exactly up to $2^{24}$), they are practically more powerful than GRUs for tasks requiring counting or tracking nested structures. Although ReLU-RNNs (IRNNs) are theoretically capable of counting, they remain difficult to train due to gradient instability. This research suggests that the LSTM's architectural advantage in "counting" is a key factor in its success with complex linguistic structures, such as nested dependencies in linearized trees. Future work will explore these dynamics in non-synthetic, real-world linguistic data.
Summary updated