Token Space: A Category Theory Framework for AI Computations
Organizations: College of Computer Science, Sichuan University, Chengdu, P.R. China, 610065
Abstract
We introduce Token Space, a categorical framework for AI computations based on explicit structural records. Five theses guide it: object interiors should be data; category theory should compute with its own objects; computational interfaces should specify structural obligations; equal vectors need not identify the same Token occurrence; and computation should admit an unbounded, dynamically organized population of Token computing cores. A Token is a finite tuple of carrier elements and fixed symbols. A Token class pairs a carrier with a heap of records; Token maps preserve those records. The elementary category has finite limits, finite coproducts and exponentials, but is not a topos. Algebraic tokenization is fully faithful for a fixed finitary signature with all homomorphisms. Small categories and functors have record encodings, natural transformations have endpoint-constrained encodings, and finite categorical constructions are executable. Operators and supported tree reification expose internal structure. For represented finite mappings, valid acyclic graphs evaluate through unique Token maps. Completed parts glue by pullback-pushout squares, sharing induces an adjunction on completion lattices, frontier interfaces form a functor, and certified residual replacement preserves the remaining result. Effective finite transitions preserve finite configurations; a uniform generator yields arbitrarily wide ready populations. Requests with finite dependency closures complete under stated progress conditions. Transformers are one implementation family: permutation heaps characterize equivariance and prefix-agreement heaps characterize causality under specified interfaces. Structural distillation uses teacher-induced heaps; relation-saturating quotients characterize exact preservation and reflection of recorded structure.
Figures & tables
| Construction | Mathematical contribution | Computational purpose |
|---|---|---|
| Sets and functions | A carrier and transformations . | Specify inputs, states, outputs, and their extensional behavior. |
| Fixed core | Add ; use on . | Separate transformable data from fixed relation names, operators, and protocol labels. |
| Finite words | Form . | Supply ordered records with repeated entries and explicit labels. |
| Selected heaps | Choose . | State which connections, dependencies, operation graphs, or constraints belong to this description. |
| Subsets extension | Require . | Select the computations and translations that preserve the specified records. |
| Products and exponentials | Combine interfaces and obtain map objects with evaluation. | Organize parallel composition, parameterized computation, and maps treated as data. |
| Question | Diagram to consult | What its arrows express |
|---|---|---|
| What does a Token map preserve? | Figure 1 | An ambient carrier function transports each selected record. |
| How is a natural transformation data? | Figure 3 | A lift between encoded categories has prescribed endpoint functors. |
| Why can independent work be joined? | Figures 5 and 6 | Completed classes embed and glue; their values agree. |
| Why does expansion retain behavior? | Figure 7 | Changing a description commutes with evaluation. |
| How do live interfaces change? | Figure 8 | Frontier advancement composes and preserves the remaining output. |
| What work can sharing reuse? | Figure 9 | Images of completed sets and consistent values transfer together. |
| Object | Mathematical representation | Role in a language model or in Token Space |
|---|---|---|
| Tokenizer token type | A vocabulary entry; its ID specifies an embedding-table lookup. | |
| Token occurrence | with value | One occurrence at a particular input position; repeated IDs give different occurrences. |
| Input embedding | A learned vector associated with the vocabulary item, before contextual mixing. | |
| Located hidden state | A state occurrence with its model, layer, input, and position; its vector alone omits this location. | |
| Sequence state | The input or output of a Transformer block. This is one carrier element in the sequence classes used below. | |
| Structural Token | A finite record in the mathematical description, such as or . |
| Construction | Carrier | Heap and computational role |
|---|---|---|
| Initial object | Empty heap. The empty interface has a unique map into any class. | |
| Terminal object | . A target for discarding an input; maps out of it select global elements. | |
| Product | . Combines two interfaces with matched record shapes. | |
| Coproduct | . Keeps alternatives tagged, with casewise maps. | |
| Equalizer of | , where . Restricts the interface to agreement states. | |
| Exponential | , defined in ( 4 ). Supports evaluation and currying; its global elements are the admissible maps. |
| Name | Symbol | Effect |
|---|---|---|
| Merging / meeting / deleting | Union, intersection, difference of heaps (and bases). | |
| Forgetting / stuffing / abstracting | Empty the heap; fill the heap; make the heap the base. | |
| Matchup (product) | Carrier ; a Token iff both projections are Tokens. | |
| Blending (extending product) | Carrier ; a Token iff some projection is a Token. | |
| Union / Y-union | Tagged union of bases and heaps. | |
| Referring (exponential) | Carrier ; heap of ( 4 ). |
| Representation | What is stored | How evaluation proceeds |
|---|---|---|
| Explicit table | One output for each encoded input. | Index or search the table. |
| Circuit | Primitive operations and directed connections. | Evaluate nodes in dependency order. |
| Decision diagram | Tests, branches, and shared subgraphs. | Follow the tests selected by the input. |
| Factorized calculation | Factors and compatible intermediate interfaces. | Execute the factors without materializing their composite table. |
| Parameterized model | Architecture, numerical parameters, and an execution protocol. | Run the prescribed numerical operations. |
| Hybrid description | Typed components in several representations. | Dispatch their evaluators and compose the results. |
| Representation of | Storage under the specified encoding | Evaluation work |
|---|---|---|
| Full output table | output bits | One table access plus input indexing and output bits. |
| Separate prefix expression trees | bits using indexed variables | XOR calls. |
| Shared prefix graph | bits using node indices | XOR calls plus output access. |
| What changes | What stays fixed | Required mechanism or invariant |
|---|---|---|
| Worker allocation | The graph, its input and output behavior | Readiness-based scheduling, retained values and continued progress. |
| Active work | The requested result of one invocation | Demand propagation, branch selection, node lifetimes and valid residual computations. |
| Representation and granularity | The denoted mapping at the chosen interface | Certified implementations in ; a migration condition for a running invocation. |
| Input or interface size | A specified uniform family or protocol | Effective construction of the family and any required cross-size compatibility. |
| Change of description | Required data | What is established |
|---|---|---|
| Tree reification | A supported tree Token class. | Ordered child records and shared subterms; no evaluator is assumed. |
| Term compilation | Primitive term shape, interpretation and declared ports. | A valid graph with the term’s value. |
| Module expansion | A ranked library, fresh nodes and ordered port wiring. | A valid graph with the call’s denotation. |
| Region fusion | A valid region and its complete boundary interface. | A callable component with the same boundary behavior. |
| Online replacement | A consistent completed frontier and an equivalent residual implementation. | The original invocation’s remaining result is preserved. |
| Description of | XOR work | Span | Correctness certificate |
|---|---|---|---|
| Separate left-associated prefixes | Direct term evaluation. | ||
| Shared prefix chain | Syntactic sharing Token map. | ||
| Recursive parallel prefixes | Associativity and recursive construction. | ||
| Block family , | Local prefixes, totals and associative recombination. |
| LLM component or protocol | Representation in the framework | What the execution account permits |
|---|---|---|
| Heads and known-position operations | Independent subgraphs joined at explicit consumers | Concurrent scheduling subject to actual dependencies and resource limits. |
| Layer stack and generation loop | Composed maps and explicitly supplied next inputs | Waiting on real dependencies; no general elimination of layer or generated-token dependence. |
| Key–value cache | Invocation state tied to parameters, prefix and positions | Reuse under a proved consistency invariant; migration requires preservation of that state. |
| Kernel or representation choice | Alternative descriptions at a fixed interface | Certified exact substitution, or a separately quantified approximation. |
| Request length and worker availability | Interface family, active tasks and resource protocol | Distinct forms of elasticity, with their respective consistency and progress conditions. |