Tokenisation is Not in APX: A New Breakthrough in the Computational Complexity of Tokenization Optimization

Theoretical proof: optimal tokenization is computationally extremely hard—unless P=NP, even constant-factor approximation is infeasible.
This article presents a theoretical study on the computational complexity of tokenization. The study proves that, for both direct tokenisation and bottom-up tokenisation strategies, under compression and unigram log-likelihood objectives, and for binary or larger alphabets, unless P=NP, no polynomial-time algorithm can find a tokenizer whose objective value is within any constant factor of the optimal solution—i.e., the tokenization problem is not in the APX complexity class. Furthermore, even when the alphabet degenerates to unary, the direct tokenisation problem is APX-hard, and thus no polynomial-time approximation scheme (PTAS) exists. These results explain why practical tokenizers (such as BPE and WordPiece) mostly use heuristic algorithms, and suggest that pursuing global optimality may be impractical, so attention should be paid to efficient approximation or heuristic strategies.
Introduction
Tokenisation is a fundamental step in natural language processing, but a new theoretical study reveals a surprising conclusion: finding the optimal tokenizer is computationally extremely difficult, and unless P=NP, no polynomial-time algorithm can get close to the optimal solution. This paper proves that, under various objective functions and alphabet settings, the tokenization problem is not even in the APX complexity class, meaning that even constant-factor approximation is hard to achieve.

This result has profound implications for the AI field, as it challenges our conventional understanding of the feasibility of tokenizer optimization.
The P vs NP problem is the most famous unsolved problem in computational complexity theory. It asks: does there exist an algorithm that can verify the correctness of a solution in polynomial time and also find that solution in polynomial time? Intuitively, P-class problems represent problems that are "easy to solve," while NP-class problems represent problems that are "easy to verify." The vast majority of computer scientists believe that P ≠ NP, i.e., that many seemingly difficult-to-solve problems (such as the traveling salesman problem and the Boolean satisfiability problem) inherently have no efficient algorithms. In this article, "unless P=NP" is a conditional statement: if P ≠ NP (which is the widely held conjecture), then there is no polynomial-time algorithm for the tokenization problem that can get close to the optimal solution. This assumption is a standard tool in computational complexity theory for proving problem hardness, similar to physicists assuming the invariance of the speed of light.
Core Proof and Results
The paper addresses two strategies—direct tokenisation and bottom-up tokenisation—and, under the compression objective and the unigram log-likelihood objective, proves respectively that for binary or larger alphabets, unless P=NP, it is impossible to find in polynomial time a tokenizer whose objective value is within any constant factor of the optimal solution. This means that the tokenization problem is not in the APX complexity class, i.e., no constant-factor approximation algorithm exists.
Furthermore, even when the alphabet degenerates to unary, the direct tokenisation problem is APX-hard, and therefore no polynomial-time approximation scheme (PTAS) exists. Together, these results paint a picture of the computational complexity of tokenization optimization: in the general case, we cannot efficiently obtain a near-optimal tokenization scheme.
The APX complexity class is an important category in approximation algorithm theory, containing those NP optimization problems that admit constant-factor approximation algorithms. Specifically, if a problem belongs to APX, then there exists a polynomial-time algorithm that, for any instance, can produce a solution whose objective value is no more than c times the optimal solution (where c is a constant, such as 2 or 1.5). Conversely, if a problem is APX-hard, it means that no such constant-factor approximation algorithm exists (unless P=NP). This paper proves that the tokenization problem is not even in the APX class, i.e., even constant-factor approximation is hard to achieve, which is stronger than a general NP-hard result. A PTAS (polynomial-time approximation scheme), on the other hand, is a stronger approximation guarantee: for any given ε > 0, it can obtain a solution that is (1+ε) times optimal in polynomial time. The existence of a PTAS usually means that the problem is very "close to solvable" in the approximation sense. This paper proves that direct tokenisation over a unary alphabet is APX-hard, and therefore no PTAS exists, further emphasizing the intrinsic difficulty of the problem.
Implications for NLP Practice
This theoretical finding has important implications for natural language processing practice. The tokenizers widely used today (such as BPE and WordPiece) are all heuristic algorithms and do not guarantee optimality. The paper's results suggest that this heuristic approach may not be accidental, but rather caused by the intrinsic complexity of the problem itself.
For researchers and engineers, this means that when designing tokenizers, pursuing global optimality may be impractical, and attention should instead be paid to efficient approximation or heuristic strategies under specific constraints. At the same time, it also suggests that when evaluating tokenizer performance, we need to recognize that the optimal solution may be difficult to attain, and thus set expectations more reasonably.
BPE (Byte Pair Encoding) and WordPiece are currently the two most commonly used tokenization algorithms in natural language processing. BPE was originally a data compression technique and was later introduced into NLP: it starts with a character-level vocabulary and repeatedly merges the most frequent adjacent symbol pairs until a preset vocabulary size is reached. WordPiece adopts a similar idea, but its merging criterion is based on language model likelihood gain, and it is commonly used in models such as BERT. Both algorithms are greedy heuristic methods that make only locally optimal choices at each step and do not guarantee globally optimal tokenization. The theoretical results in this paper precisely explain why these heuristic methods are widely adopted: because finding the globally optimal tokenization is computationally difficult, and even constant-factor approximation is infeasible. This suggests that heuristic methods are not merely a stopgap, but a reasonable choice determined by the nature of the problem.
Conclusion
This study provides new theoretical insights into the computational complexity of the tokenization problem, revealing that even over a unary alphabet, direct tokenisation is APX-hard. These results not only deepen our understanding of the difficulty of tokenization optimization, but also point the way for future development of more efficient tokenization algorithms—finding a balance between approximability and computational efficiency.
Related articles

Pure-Code Video Generation Tested: Which AI Model Actually Follows Instructions?
A Bilibili creator tested three AI models' pure-code video generation with unified prompts and three revisions each: Xiaonaomao has a high ceiling but lacks stability, GPT 6.2 Extra models well but only follows half the instructions, and OPAS 5.5 remains the benchmark.

GPT-6 Six-Tier Hands-On Test: Astra Ultra Dominates but Bills Double
GPT-6 six-tier test: Astra Ultra sweeps 3:0 in 3D tasks thanks to sub-agents and runs 14% faster, but hidden backend bills make its real cost 2.6x single-threaded.

GPT-6.2 Astra vs Fable 5.2: Huge Cost-Efficiency Gap Across 12 Real-World Tests
Bilibili creator tests GPT-6.2 Astra vs Fable 5.2 across 12 real tasks: Fable wins 7-5 but costs 7.2x more and takes nearly 5x longer. Token efficiency emerges as the key selection metric.