AlgoTrace: Algorithmic Primitives and Compositional Geometry of Reasoning in Language Models

Samuel Lippl, Thomas Austin McGee, Kimberly Lopez, Ziwen Pan, Pierce Zhang, Salma Ziadi, Oliver Eberle, Ida Momennejad

Introduction

While reasoning-finetuned models like Phi-4-Reasoning demonstrate remarkable performance gains on complex tasks, the internal mechanics of how they reason largely remain a black box. We can observe their Chain-of-Thought (CoT) outputs, but it is often unclear whether the model is executing a consistent internal algorithm or merely predicting the next likely token based on surface-level patterns.

AlgoTrace introduces a framework that peers into this black box, revealing that large language models (LLMs) solve complex reasoning tasks by navigating a sequence of "algorithmic primitives." These primitives act as discrete, reusable computational building blocks within the model's latent space. By extracting these primitives as "function vectors," researchers can directly steer a model’s reasoning process using vector arithmetic—even transferring "math" primitives to solve "spatial" problems.

The Core Questions

The research addresses three fundamental questions about LLM reasoning:

  1. What are the fundamental algorithmic atoms (primitives) that LLMs use across different domains?
  2. Are these primitives organized geometrically, allowing for algebraic composition (e.g., can we "add" two reasoning steps together)?
  3. How does reasoning-specific finetuning alter a model's internal "algorithmic phenotype"?

The AlgoTrace Methodology

To map the internal reasoning pathways of LLMs, the authors developed AlgoTrace, a multi-step framework for mechanistic interpretability:

  • Primitive Identification: The researchers performed k-means clustering on the latent activations (specifically Layer 17 of Phi-4) while the model solved reasoning problems.
  • Automated Annotation: To interpret these clusters, they utilized an LLM-based pipeline (powered by GPT-4o) that analyzes the tokens associated with a cluster and its context to assign human-readable labels (e.g., "nearest-neighbor heuristic").
  • Vector Extraction: Using "function vector" techniques, they isolated specific directions in the model's activation space that correspond to these identified primitives.
  • Algorithmic Steering (Intervention): Finally, they injected these primitive vectors back into the model during inference to test if they could force the model to adopt specific reasoning strategies.

The framework was rigorously evaluated across four diverse reasoning benchmarks: the Traveling Salesperson Problem (TSP), 3-SAT (Boolean satisfiability), AIME (high-level mathematical olympiad problems), and Graph Navigation.

Key Insights and Results

Reasoning as a "Walk" Through Latent Space

LLM reasoning is effectively a trajectory through latent space, stepping from one algorithmic primitive to the next. Fine-tuning for reasoning (e.g., comparing Phi-4 to Phi-4-Reasoning) does not just improve accuracy; it fundamentally structures this internal "walk." The authors found that Phi-4-Reasoning uses highly consistent internal paths, whereas the base Phi-4 model often fractures into less effective sub-groups of internal strategies, such as brute-force or random guessing.

Geometric Compositionality and Zero-Shot Boosting

Primitives are not isolated states; they are vectors that can be mathematically combined. In Llama-3-8B, injecting a combination of two primitive vectors—Terminal Node Recognition (TNR) and Reward Comparison (RC)—allowed the model to match few-shot performance in a zero-shot setting. This effectively "teaches" the model a composite algorithm mid-inference.

Cross-Task Transfer and Behavioral Induction

Algorithmic primitives proved to be surprisingly universal. A "verification" or "spatial reasoning" vector extracted from a math task (AIME) successfully steered a model's behavior when solving a completely different routing task (TSP).

Quantitative interventions yielded striking results:

  • Behavioral Induction: Injecting a nearest_neighbor vector increased the proportion of nearest-neighbor paths generated by the model by 56.1%.
  • Steering Verification: Injecting a compare_verify vector increased the generation of verification-related words by over 700%.

Limitations and Future Directions

While AlgoTrace provides a powerful new lens for understanding LLMs, the authors note several limitations. The study relies on a linearity assumption for vector arithmetic, though more complex, non-linear manifolds likely exist in the latent space. Furthermore, while many clusters were highly interpretable, some do not yet map to known human algorithms, leaving the definition of a "universal primitive library" as an open challenge.

Currently focused on multi-step symbolic and logical reasoning, future work will need to explore how these primitives manifest in creative or multi-modal contexts. Ultimately, this research points toward a compelling future paradigm: training models not just on "next-token prediction," but on "next-primitive prediction" to drastically improve compositional generalization.

Summary updated

BibTeX
@inproceedings{lippl2026algotrace,
  author = {Samuel Lippl and Thomas Austin McGee and Kimberly Lopez and Ziwen Pan and Pierce Zhang and Salma Ziadi and Oliver Eberle and Ida Momennejad},
  title = {{AlgoTrace: Algorithmic Primitives and Compositional Geometry of Reasoning in Language Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=ppirVueEj6},
}
Figure