Abstract
Large Language Models (LLMs) often struggle with multi-digit arithmetic due to a reliance on memorization rather than algorithmic reasoning. This paper introduces the Composable Arithmetic Execution Framework (CAEF), which fine-tunes LLMs to emulate Turing Machine (TM) transition functions. By decomposing complex operations into modular, step-by-step logic, CAEF achieves near-perfect accuracy on 100-digit calculations, demonstrating significant improvements in length generalization over state-of-the-art models like GPT-4o.
Introduction
Despite their impressive capabilities, LLMs are notoriously unreliable for basic mathematics involving large numbers. When tasked with adding two 50-digit numbers, even powerful models like GPT-4o frequently fail. This failure stems from a fundamental issue: LLMs tend to memorize specific training examples rather than learning the underlying computational logic. As the number of digits increases, the "sample space" of possible problems grows exponentially, making memorization an impossible strategy for general arithmetic.
Current solutions, such as external tool-use or Chain-of-Thought prompting, often fail to provide true length generalization—the ability to apply rules learned on small numbers to arbitrarily large ones. CAEF addresses this by treating the LLM as the transition function of a Turing Machine, focusing on the logic of individual steps rather than the final output.
The CAEF Framework
The authors propose a modular architecture that separates the formatting of data from the execution of logic.
- The Aligner: This component acts as an interface between human-readable input (e.g.,
89 x 2 =) and the structured, text-based representation of a Turing Machine tape. It ensures the data is correctly formatted for the Executor and translates the final "halt" state back into a result. - The Executor: Instead of predicting a final answer, the model is trained to predict the next state and next command based on the current tape status.
- Operator Composition: Complex operations are built from simpler ones. For example, a multiplication task is handled by an Executor Composer that iteratively calls "Addition" and "Less Than" modules.
- LoRA Adapters: Each arithmetic operator is implemented as a separate Low-Rank Adaptation (LoRA) module. This modularity allows the system to switch between specialized "brain modules" for different tasks, maintaining high precision with low memory overhead.
Algorithmic Execution and Length Invariance
The core insight of CAEF is that by focusing on the transition function—the logic of a single computational step—the model becomes "length-invariant." The logic required to add two digits and a carry remains constant regardless of the total number of digits in the operands.
The framework also reinforces Right-to-Left (R2L) processing, aligning the model's execution with standard human arithmetic algorithms. This approach ensures that the model's performance does not degrade as the complexity of the problem scales.
Experimental Evaluation
The researchers evaluated CAEF using synthetic datasets of execution traces for seven operators: +, -, ×, ÷, >, <, and ==. The models were tested on operands ranging from 5 to 100 digits and compared against LLaMA 3.1-8B and GPT-4o.
Key Results
- 100-Digit Addition: CAEF achieved 98.6% accuracy, while GPT-4o's performance dropped to 43.0%. Standard LLaMA models failed entirely.
- Multiplication & Division: CAEF maintained 99.3% accuracy on complex multi-step operations, significantly outperforming baselines which struggled to exceed 65%.
- Stability: CAEF showed virtually no performance degradation as operand length increased from 5 to 100 digits, confirming that it had successfully internalized the algorithm.
Discussion and Future Work
While CAEF represents a significant step forward in LLM reasoning, it faces challenges regarding computational efficiency. Because the model must generate every intermediate step of a Turing Machine, processing very large numbers is slow. Additionally, the "Aligner" remains a bottleneck; correctly reversing and formatting extremely long strings is a non-trivial task for current transformers.
Future research directions include optimizing the Key-Value (KV) cache for iterative processing and exploring methods for LLMs to autonomously design their own Turing Machine prototypes for novel tasks. By moving toward "plug-and-play" logic modules, CAEF suggests a path for enhancing the specialized reasoning capabilities of general-purpose language models.
Summary updated