Abstract
Large Language Models (LLMs) are often treated as "black boxes," with their behaviors described through intuitive but imprecise terms like "hallucination" or "alignment." This paper introduces HEX, a formal mathematical framework that uses commutative diagrams to define and analyze LLM operations. By mapping the relationship between concrete data (text) and abstract representations (embeddings), HEX provides a rigorous way to distinguish between Chain-of-Thought prompting and true reasoning, while formalizing the mechanisms behind model failure and success.
Introduction
Despite the ubiquity of LLMs, the field lacks a unified mathematical language to describe the internal processes that lead to specific outputs. Currently, evaluation relies heavily on benchmarking—testing models on thousands of tasks to observe what they can do. The HEX framework aims to bridge this gap by providing a structural understanding of why models behave as they do, moving from empirical observation to formal theory.
The HEX Framework
The core of the HEX framework is the use of commutative diagrams, a tool from category theory used to show that different paths to a result are equivalent. The framework identifies several key components:
- Concrete State ($\sigma$): The raw data or variables (e.g., $x=12, y=13$).
- Abstract State ($\hat{\sigma}$): The internal vector or embedding the LLM uses to process information.
- Abstraction Map ($\alpha$): The process of encoding a problem into an internal embedding.
- Concretization Map ($\gamma$): The decoding of an internal state back into natural language.
- Functionals ($\Lambda$): The operations performed on these states.
A HEX diagram is considered "commutative" if the path of human logic (solving a problem directly in the concrete space) matches the path taken by the LLM (encoding, processing in the abstract space, and decoding). When these paths align, the model is considered "aligned"; when they diverge, the model has "hallucinated."
Redefining LLM Phenomena
Hallucination as Non-Commutativity
Mathematically, hallucination occurs when the path through the LLM’s abstract state fails to reach a concrete state compatible with the ground truth. This formal definition moves hallucination from a psychological metaphor to a measurable structural failure.
CoT Prompting vs. CoT Reasoning
A significant insight of the HEX framework is the distinction between Chain-of-Thought (CoT) prompting and CoT reasoning.
- CoT Prompting is a single LLM call where the model is asked to "think step-by-step."
- CoT Reasoning is a multi-step process where each intermediate step is verified or used as a fresh input for a subsequent call.
The paper proves that CoT prompting is only equivalent to actual reasoning under strict conditions of "step-wise" commutativity, explaining why single-prompt solutions often fail on complex logic.
Experimental Proof of Concept
The researchers validated the framework using GPT-4 on several "toy problems," most notably in TikZ code generation.
In one experiment, GPT-4 was asked to draw a "circle inside a hexagon and a square inside the circle" using a single prompt. The model failed to produce correct code. However, when the HEX framework was applied to decompose the task into three distinct sub-problems (actual reasoning), the model succeeded perfectly. This demonstrates that breaking down tasks into commutative steps allows the model to overcome the limitations of its internal abstract processing.
Limitations and Future Work
While HEX provides a powerful theoretical lens, it faces challenges in defining "compatibility" for creative tasks (like poetry) where mathematical distance metrics are harder to apply. Furthermore, the "Abstract States" remain unobservable in proprietary models. Future research may involve applying HEX to open-source models to verify if internal embeddings align with the framework's predictions, and scaling the theory to handle long-form creative writing and multi-turn conversations.
Summary updated