Abstract
This paper investigates the internal mechanisms of Large Language Models (LLMs) when solving mixed arithmetic expressions. By employing mechanistic interpretability techniques like Edge Attribution Patching and Patchscopes, we demonstrate that LLMs perform structured, layer-wise reasoning rather than simple pattern memorization. Our findings reveal a "vertical" reasoning process where intermediate results are computed in middle layers before the final answer is resolved. Furthermore, we introduce Causal Effect Driven Fine-tuning (CEDF), which leverages these internal circuits to improve mathematical performance and generalization.
Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in solving complex mathematical problems, the internal mechanics of these computations remain largely a "black box." Previous research has primarily focused on simple, single-step arithmetic. This study addresses the fundamental question: Memory or Reasoning? When presented with mixed operators and parentheses (PEMDAS), does an LLM simply retrieve a memorized pattern, or does it execute a multi-step logical computation? Understanding this is critical for assessing the reliability of LLMs in tasks requiring rigorous logical consistency.
Methodology
The researchers utilized a suite of mechanistic interpretability tools to dissect the model's internal state:
- Edge Attribution Patching with Integrated Gradients (EAP-IG): Used to identify the specific "circuit"—the network of neurons and attention heads—responsible for the calculation by measuring causal effects on the output.
- Patchscopes: A technique that "translates" internal hidden vector representations into natural language, allowing researchers to inspect what information the model "knows" at specific layers.
- CEDF (Causal Effect Driven Fine-tuning): A novel method that adaptively adjusts learning rates based on a component's causal importance, focusing training on the identified "math circuit."
The Vertical Reasoning Workflow
A key discovery of this research is that arithmetic reasoning in LLMs is "vertical" rather than "horizontal." Unlike Chain-of-Thought (CoT) prompting, where reasoning steps are distributed across multiple output tokens, internal arithmetic reasoning occurs layer-by-layer at the final token position.
As shown in the figure above, the model first parses the expression in the early layers (resolving operands X1, X2, and X3). Around layers 31-33, an "Aha! moment" occurs where the intermediate result (IR) of a sub-expression is formed in the residual stream. Only after this intermediate step is the final result (FR) resolved in the later layers. This suggests a structured internal workflow mimicking human-like PEMDAS logic.
Causal Circuits and Functional Specialization
The model does not use its entire parameter set equally for these tasks. Instead, it relies on specialized "circuits." EAP-IG analysis revealed that specific attention heads and MLP layers are dedicated to distinct sub-tasks, such as parsing parentheses or performing specific operations like multiplication.
By identifying the top 1% of edges with the highest causal effect, the researchers were able to recover 85% of the full model's performance. This concentration of logic allows for more efficient fine-tuning. The proposed CEDF method, which targets these high-causal-effect components, significantly outperformed standard fine-tuning, reaching 86% accuracy on complex datasets where standard tuning only reached 77%.
Key Results and Generalization
- Circuit Efficiency: Mathematical logic is highly localized; a tiny fraction of the model's connections carries the bulk of the reasoning capability.
- Generalization: CEDF showed superior zero-shot generalization on more complex expressions (e.g., moving from $D_4$ to $D_7$ complexity), suggesting that the model is learning underlying logic rather than memorizing specific patterns.
- Hybrid Nature: While the model utilizes learned patterns, its heavy reliance on intermediate computations confirms that it performs a form of internal reasoning.
Conclusion and Future Work
This research provides a roadmap for understanding how LLMs process structured logic. By demonstrating that reasoning happens vertically across layers, it opens new avenues for model optimization and interpretability. Future work will explore whether these circuits scale to larger models (400B+ parameters) and how they interact with explicit Chain-of-Thought prompting. Currently, the study is limited to synthetic arithmetic and does not yet cover more complex operations like exponentiation or word-problem contexts.
Summary updated