Manuscript Offprint
arXiv:2611.08671Greedy Byte-Pair Encoding Achieves at Least 0.361 of the Optimal Compression
Abstract
Byte-Pair Encoding (BPE) builds a tokeniser by repeatedly merging a most frequent adjacent pair of symbols; its utility is the total reduction in string length achieved by merges. It was known that this greedy rule achieves at least a third of the optimal reduction. We prove that it always achieves at least 0.361 of the optimal reduction in string length, for every string, every budget and every tie-breaking rule; this is the first improvement of the bound one third. We also explain why one third was a barrier: the pair-packing relaxation behind it is tight, so a better bound must use more of the optimum's structure. When greedy destroys three of the optimum's merge points at once, one of them can usually be moved next door, because all copies of a rule of the optimum look alike; the remaining cases are paid for later. Along the way we determine the worst-case ratio for two merges exactly, bound it for three, and isolate a single inequality that would settle the problem.
Code for the finite checks in Appendix B: Zenodo, doi:10.5281/zenodo.23970171.
1 Introduction
Byte-Pair Encoding [2, 7] builds the vocabularies of most current language models, and it is a greedy algorithm of the simplest kind. Given a string and a budget , it finds a most frequent adjacent pair of symbols, replaces all of its occurrences by a fresh symbol, and repeats this times. Each replacement shortens the string by one, and the total shortening is the utility of the merge sequence. How much shorter could the string have become with well-chosen merges? Computing the optimum is NP-hard [8], even over bounded alphabets [3], and it is APX-complete [4]: unless P = NP, no polynomial-time algorithm approximates it within every constant factor. So the natural question is how well the greedy rule approximates it.
Kozma and Voderholzer [4, 5] formalised this question. Writing BPE for greedy's utility and OPT for the optimum, they proved
The lower bound comes from a charging argument: each greedy replacement is charged for the merge points of the optimum it destroys, counted through a pair-packing relaxation, which only records, for each rule, a set of disjoint occurrences of one letter pair; the upper bound, in the extended version [5], comes from a family of instances in which the budget grows without bound. The same upper bound was obtained independently by Yang [9], who also proved that BPE achieves at least of every pair encoding whose tokens have length at most three, so that is exact against such encodings. Against the unrestricted optimum the lower bound remained , and Yang identifies the obstacle: inside a long token of the optimum, one greedy replacement can destroy three of its merge points rather than two [9, Section 7].
Our results. We write for the utilities of greedy's successive merges and .
-
Greedy beats one third (Theorem 11). For every string, every budget and every tie-breaking rule, BPE. The proof is elementary (Section 4), apart from a finite certification in exact rational arithmetic (Appendix B). Its first layer alone gives 0.3478 (Corollary 4).
-
Why one third was stuck (Theorem 16). The pair-packing relaxation used for the bound cannot certify more: there are instances on which greedy achieves only a fraction tending to of the packing. Any improvement must therefore use more of the optimum's structure than a packing records.
-
Small budgets (Section 5). With two merges the worst-case ratio is exactly . With three it is at most , by an explicit family checkable by hand.
-
One inequality would settle the problem (Section 6). If greedy's replacements always cost the optimum at most two units each, where a destroyed merge point may be counted again at a neighbouring gap, that is, if , then .
The technique. The structural fact we add to the Kozma–Voderholzer argument is rule determinism: every copy of a rule of the optimum has the same tree. The KV charging pays three units of the optimum for a greedy replacement whenever it destroys the optimum's merge points on both sides and in the middle. We show that in such an event the destroyed central merge can usually be moved to the next gap, where by rule determinism it counts as an occurrence of a pair that is the same for all copies of the rule; when it cannot, its parent's position becomes a ghost whose pair is again fixed by a rule. This reduces the cost to 2.5 units per replacement, at the price of a weaker last term: the term of the KV inequality becomes . Interleaving the two per-step inequalities gives 0.3478. The term counts all moved nodes and ghosts that might still be alive. We show that they form groups of one type each, and that whenever greedy glues a gap that carries an object, the object's whole group disappears and never returns. So the last term shrinks over the run, as the number of rules still counted does in the KV argument, and the constant rises to 0.361.
Related work. The merge process is Re-Pair [6] in grammar compression, where the measure of interest is the size of the grammar rather than the utility; [4] explain why the two behave differently. Zouhar et al. [10] gave the first formal treatment of BPE as an optimisation problem and related greedy's performance to a curvature parameter of the objective, without worst-case bounds. In a companion paper [1] we analyse a different greedy tokeniser, GreedTok, whose objective is a coverage function.
For a string and a pair , is the number of replacements made by the full merge of ; this is the maximum number of pairwise non-overlapping occurrences of in (occurrences never overlap when , and in a run of 's the left-to-right scan is optimal). We write for the number of occurrences with overlaps allowed, and .
Greedy. BPE performs full merges, each time of a pair with maximum cnt, ties broken by an arbitrary rule. We write for the strings of a run, for the utility of its -th merge, , so , and . Every statement about greedy holds for every tie-breaking rule. A merge never increases (proved in Appendix A as Lemma 17), so and every merge has utility at most .
Tokens. After full merges (arbitrary pairs, not necessarily greedy's), each symbol of stands for an interval of , a token; a token of length one is a single letter. We write for the count of the -th merge and for the symbol it creates. The type of a gap of is the pair of symbols of the two tokens on its sides. A replacement of step glues one gap , joining the two tokens on its sides. The following fact about merge outputs is used throughout.
Lemma 1. If for some , then no two adjacent tokens of are followed by .
Proof. Right after step there is no adjacent : for every occurrence is replaced, and for a maximal run of 's becomes a run of tokens followed by at most one , so no two are adjacent. Tokens with symbol or are created before step and never later, and two tokens that exist at step and are adjacent in were already adjacent at step .
In particular a letter pair has positive count in at most one step of a full-merge sequence.
The optimum's forest. Fix a partial merge sequence on , where creates a symbol from a pair . Every replacement made by is a node with label (Figure 1). It glues two adjacent tokens, its children, and the gap of between them is its junction ; let be the set of junctions. The nodes form a forest over the positions of , and the span of a node is the interval of positions below it, and the following three facts follow from the definitions.
(F1) Distinct nodes have distinct junctions, and .
(F2) Rule determinism. The subtree below a node of label depends only on . In particular all label- nodes have the same expansion , the strings of letters below the left and the right child, and the same junction pair .

expansion of : , ; junction pair
Figure 1: The optimum's forest on the word xabz for the rules , , . Each node sits above its junction, the gap that its replacement glues. The dashed box is a greedy merge of ab, which glues gap 2 and makes all three junctions non-intact. The junction pair of a rule is the pair of letters on the two sides of its junction; for it is , the last letter of and the first letter of .
(F3) Spans are laminar (any two are nested or disjoint), and two nodes of the same label have disjoint spans, so their junctions are not adjacent.
For a string we write for its first two letters and, counting from the end, for its last two.
Intact junctions. A junction is intact after step if none of the gaps has been glued by ; in Figure 1, greedy's merge of ab glues gap 2 and so makes all three junctions non-intact. Then positions and are single letters of , so an intact junction of label is an occurrence of in ; and two intact junctions of one label are not consecutive gaps of (by (F3) and because position is a single letter). Hence each label has at most intact junctions.
3 Technical overview
Where the factor three comes from. Fix an optimal merge sequence . Suppose greedy makes a replacement at gap . Each junction of the optimum at , or now touches a token that greedy has built and is no longer intact. The intact junctions of one rule of the optimum are disjoint occurrences of one letter pair, at most of them after steps. Kozma and Voderholzer's Lemma 8 charges each greedy replacement for the (at most three) junctions of the optimum it destroys. It uses the bound on the surviving junctions only once, at the end. We apply the same deletion after every step. We also observe that a rule whose pair greedy merges loses all its intact junctions at once, so one rule can be dropped from the count at each step. This gives a slightly stronger per-step inequality: for every ,
At this is the bound . The factor 3 is paid only in a triple event, when the junctions at , and are all intact. If every replacement destroyed at most two, we would have at every step; writing , this says , so , and after steps , which tends to . So the gap between and the upper bound is the cost of triple events. Triple events need three
(a) a moved center
(b) a ghost

left child xa has length 2:
v moves to x | [ab]

ghost at x | [ab], type fixed by the rule and its side
Figure 2: Paying for a triple event. Greedy merges ab (dashed box) where the optimum has nodes at all three gaps. (a) If the center's left child has length at least two, the center is moved to the gap left of greedy's token; its new pair (x, [ab]) is the same in every copy of the rule. (b) If the center is the optimum's own merge of ab, its parent, of label , sits at a neighbouring gap and is destroyed; a ghost marks that gap, and its pair is fixed by .
consecutive junctions inside one token of the optimum, so they cannot happen when its tokens have length at most three; this is why Yang's bound [9] holds for such encodings.
Paying for triple events. In a triple event greedy glues a pair of single letters, and the optimum has a node , the center, at exactly that gap, with nodes at both neighbouring gaps (Figure 2).
-
If the left child of v is longer than one letter, the letter just before greedy's new token is determined by the rule of v, so v can be moved to the gap left of the token, where it counts as an occurrence of a pair that is the same for every copy of the rule. Symmetrically on the right. A moved node can be destroyed later, but only once.
-
If both children of v are single letters, then v is the optimum's own merge of , and its parent sits at one of the two neighbouring gaps. We leave a ghost at the parent's gap. Its pair, the last letter of the parent's other child followed by greedy's token, is fixed by the parent's rule and side, so for each of at most 2k classes the ghosts are disjoint occurrences of one pair: at most of them.
Where 2.5 comes from. Count the nodes of the optimum that greedy's replacements destroy, in two ways. First, a replacement destroys at most two nodes unless it is a triple event. Second, a replacement removes at most three objects in total, nodes or ghosts, and ghosts appear only in triple events whose center merges two letters. Averaging the two counts, those triple events cancel out. In every other triple event the center is moved and counts again, or a node moved earlier is destroyed, which happens at most once per move. What remains is plus half the number of live ghosts. There are at most live nodes and at most ghosts, so
Why the two inequalities together beat 1/3. Neither inequality alone does. Early in the run, is small and is large, and (1) is the stronger one: its last term is less than half of . Late in the run, dominates, and (2) is stronger, since . Using (1) for the first 69% of the steps and (2) for the rest (the switch point is chosen to maximise the final bound) gives BPE 0.3478 OPT.
Groups close when hit. The term in (2) does not decay, whereas the KV term does, because KV closes one rule per step. The objects of our bookkeeping also close. All moved nodes of a rule have one type, and so do all ghosts of a class; when greedy merges a pair , every object whose type is is destroyed in that step, and such a group is never populated again. Charging half a unit for each object that sits at a glued gap, every step that destroys such an object removes a whole group from the count. This turns (2) into inequalities whose last term decays like , where is the number of rules of the optimum that merge two letters. Using three inequalities in three successive phases of the run, each where it is strongest, gives 0.361.
An example. Let consist of copies of each of the six blocks xabz|, xa|, bz|, pabq|, pa|, bq|, and . Merging xa, bz, (xa)(bz), pa, bq has utility , so . The pairs ab, xa, bz, pa, bq all have count ; with the tie-break that merges ab first, and then . In each xabz block greedy's replacement is a triple event whose center, the top node, has left child xa of length two; it moves to the gap x| [ab], of the same type (x, [ab]) in every copy (Figure 2a). In each pabq block greedy kills only two nodes. So the loss after one step is , and each of the five rules keeps live nodes, at most each: , with no room to spare. This is exactly the inequality that we will conjecture, in Section 6, to hold in general; here the move makes it hold. (Adding one block ab| forces greedy's choice; then , the extra replacement kills nothing, and the same count gives .) Without the move the loss would be .
4 Greedy BPE achieves at least 0.361 of the optimum
This section proves Theorem 11. It is built in two layers. The first layer (Sections 4.1 to 4.3) introduces the bookkeeping of moved nodes and ghosts and already gives 0.3478. The second layer (Sections 4.4 and 4.5) observes that the bookkeeping objects disappear in whole groups, and gives 0.361. Throughout, is an arbitrary partial -sequence with forest and , and are full merges with counts ; for greedy, and . A replacement of step glues a gap between two adjacent tokens and of . Its affected gaps are and (those that exist): exactly the gaps whose neighbouring tokens change. The replacements of one step are processed in scan order, from left to right. Table 1 collects the terms introduced below.
4.1 The per-step Kozma–Voderholzer inequality
The first inequality is the KV charging, applied at every step. It is strong early in the run.
Lemma 2. For every greedy run and every , .
Proof. We charge every junction of the optimum to the step at which we stop counting it, and show that step is charged at most . Take optimal. Call a label open while we still count its intact junctions; initially all labels are open. Consider step . Case 1: for an open label . After the full merge of no two adjacent single letters form (Lemma 1), so has no intact junction left and we close it; the step makes at most counted (open-label) junctions non-intact, three per replacement. Case 2: otherwise. A replacement at gap makes three counted junctions
Table 1: Glossary of the bookkeeping in Section 4.
| term | meaning | defined in |
|---|---|---|
| affected gaps | the gaps , , whose neighbouring tokens a replacement changes | Section 4 |
| scan-order attribution | an object affected by several replacements of one step is charged to the leftmost | Section 4.2 |
| intact, moved, live node | a node of at its own intact junction; a node relocated once, next to the token that absorbed its junction; either of these | Section 4.2 |
| ghost | a placeholder left at the gap of a destroyed parent node | Section 4.2 |
| ghost class | the pair (parent label, side) of a ghost; it fixes the ghost's type | Section 4.2 |
| kill / destroy | what a replacement does to a live node / to a ghost at one of its affected gaps | Section 4.2 |
| original triple, center | a replacement that kills three intact nodes; the node at its glued gap is its center | Section 4.2 |
| classes JL, JR, A; save | center with left child of length ; left child a letter, right child of length ; both children letters. A save moves the center | Section 4.2 |
| failure, image | a class-JR triple that cannot move its center; the later replacement of the same step responsible | Section 4.2 |
| hit | a replacement whose glued gap carries an object | Section 4.4 |
| letter label | a rule of whose two children are single letters; is their number | Section 4.4 |
| group | all intact nodes of one label, all moved nodes of one label, or all ghosts of one class | Section 4.4 |
| potential | a weighted count of the groups not yet emptied by a hit | Section 4.4 |
| deficits | with OPT = 1: , , (one per inequality) | Sections 4.3 and 4.5 |
non-intact only if itself is an intact junction of an open label; that label then has , which is case 1. (If the label of the junction at is already closed, that junction is not counted, so the replacement makes at most two counted junctions non-intact.) So the step makes at most counted junctions non-intact; we then close the open label with the fewest intact junctions, which has at most of them. Each step therefore charges at most : in case 1, three per replacement; in case 2, plus the at most junctions of the closed label. Every step closes a distinct label, so after steps at most labels are open, each with at most intact junctions. Every junction is counted once: when it stops being intact while its label is open, when its label is closed, or at the end. Hence .
4.2 Moving centers and leaving ghosts
The second inequality needs bookkeeping that survives several greedy steps. We first fix the objects and the invariants they satisfy, then the rule for a single replacement, then check that the invariants are preserved, and finally count.
Objects and invariants. After each step we keep a set of objects, each sitting at a gap of :
- intact nodes: nodes of at their own junction, which is intact;
- moved nodes: nodes of that have been moved once, each sitting at a gap next to the token that absorbed its junction;
• ghosts, each with a class , where is a label of and the side is left or right.
Intact and moved nodes are the live nodes. Initially every node of is an intact node and there are no ghosts. The type of an object is the type of the gap it sits at. The following invariants hold after every step.
(I1) Each gap of carries at most one object.
(I2) An intact node of label r has type .
(I3) All moved nodes of a label have the same type, which is or for the step that merged the letter pair .
(I4) A ghost of class has type , and one of class has type . Here is the step that merged for a left ghost, and for a right ghost.
A replacement kills the live nodes and destroys the ghosts at its affected gaps; an object affected by several replacements of one step is attributed to the first of them in scan order. An object at a gap that no replacement affects keeps both neighbouring tokens, so its type does not change. For one replacement let be its number of kills and its number of destructions. By (I1), .
The rule for one replacement. A replacement that kills three intact nodes is an original triple. Then and were not glued, so and are single letters, the affected gaps are , and the node at , the center, has a label with , a letter pair. There are three classes.
• JL, if . Move to gap , where its type is (a save).
-
JR, if and . If position is a single letter after the step, move to gap , where its type is (a save). Otherwise gap is glued at step by a later replacement ; we call this a failure, and its image.
-
A, if . The nodes at and have spans that meet , but their junctions lie outside it. By laminarity both are ancestors of . The lower one is 's parent, killed here; call its label . Place a ghost of class at the parent's gap, with side = left if the parent's gap is (then is the right child and ) and side = right otherwise.
Every other replacement creates nothing.
Types are preserved: (I2)–(I4). A junction stops being intact only if its gap is affected, so an intact node that is not killed stays intact, of type . A JL move puts between the single letter at , which is , and the new token ; symmetrically for JR. For a ghost of class , is the expansion of , the letter pair , and the ghost sits between the single letter and . By Lemma 1, a letter pair has positive count in at most one step, so , and hence the type, is determined by (respectively by the class). This gives (I3) and (I4); it also shows that JL and JR are exclusive for a label, so a label's moved nodes have one type.

Figure 3: A failure and its image. The center at is of class JR, but a later replacement of the same step glues the next pair, so the gap is not free for the move. Because the node at was already killed by the triple, finds that gap empty. The gap determines the center, so distinct failures have distinct images.
Table 2: Charging for one replacement . In the proof of Lemma 3, bound (a) charges with and bound (b) with is an image].
| kind of replacement | creates | effect on live nodes | ||
|---|---|---|---|---|
| original triple, JL or JR, saved | 3 | 0 | a moved node | |
| original triple, JR, failure | 3 | 0 | nothing | ; its image has |
| original triple, class A | 3 | 0 | a ghost | |
| triple that is not original | 3 | 0 | nothing | , at least one of them moved |
| image of a failure | nothing | |||
| any other replacement | nothing |
At most one object per gap: (I1). A replacement removes the objects at its affected gaps, its glued gap disappears, and it creates at most one object, at or at , where the node it has just killed was sitting. We check, case by case, that no second object can arrive at that gap during the same step.
(a) An object created at (a JL move, or a ghost on the left). No earlier replacement of the step glued : it would have had as an affected gap and killed the node there first, contradicting the attribution. Later replacements of the step lie to the right of . So after the step, is the gap between the single letter at position and the new token, and a second object could be created there only by a replacement gluing gap ; there is none.
(b) A JR move to . It is made only when position is still a single letter after the step, so no replacement of the step glues and the argument of (a) applies on the right.
(c) A ghost created at . A later replacement of the step may glue ; it then has as an affected gap and destroys the ghost, which is allowed. No other object can be created at : that would need an original triple gluing , and there is none, because the node at is already dead.
Failures and their images (Figure 3). A failure would cost three kills without any compensation, so we pay for it with its image. For a failure at , the image glues , so its left token starts at and its first affected gap is . Thus is determined by , and distinct failures have distinct images. When acts, the triple has already killed the node at . Nothing was created there in between. A move to could only come from this center, which failed. A ghost at would need a class-A center at or . The center at is JR, and is not an original triple. So an image finds one of its three affected gaps empty: .
With the bookkeeping in place, the count is a short averaging argument (Table 2).
Lemma 3. For every partial k-sequence , all full merges and every , util() . For greedy, .
Proof. We count the kills in two ways, once by replacements with three kills and once by the objects each replacement can remove, and average the two counts. Let be the number of replacements (for greedy, ). Classify them as in Table 2: let , and count the original triples that are saved, that fail, and that are of class A, and let count the triples that are not original. Let be the number of replacements with , and let and be the numbers of live nodes and ghosts after step .
Bound (a). Every replacement has unless , so .
Bound (b). Every replacement has , and the images (distinct, by injectivity) have . So . Every ghost is created by a class-A triple and destroyed at most once, so , and .
Averaging. Adding (a) and (b) and halving, the terms and cancel:
The loss. Live nodes are lost only by kills and gained only by saves, so . Each triple that is not original kills a moved node, and each moved node, created by a save, dies at most once, so and .
Live nodes. Fix a label . Before the step that merges , its live nodes are intact, of type . That step makes every intact -junction non-intact (Lemma 1); a junction that stops being intact lies at an affected gap, so all intact -nodes die, and by (I3) the moved -nodes all have one type. So at any time the live -nodes have one type, and they are pairwise non-overlapping occurrences of it (for by the fact about intact junctions in Section 2; for a moved type because it consists of a single letter and a merged symbol, and (I1)). Hence .
Ghosts. By (I4) the live ghosts of one class sit at gaps of one type made of a single letter and a merged symbol, so two of them are never at consecutive gaps, and each class has at most live ghosts. The label of a class is not a letter label (its node has span at least three), and there are at most 2k classes: .
4.3 The base layer: combining the two inequalities
The two inequalities are strong at different times, and switching from one to the other already beats one third. In the proofs below we normalise OPT = 1 and track the deficit of each inequality, the amount by which its leading term falls short of OPT: for Lemma 2 and for Lemma 3. (In Section 4.5 a third deficit, , belongs to the no-ghost inequality.)
Corollary 4 (base layer). For every string , every and every greedy run with any tie-breaking rule, , where OPT is the partial-merge optimum.
Proof. For , BPE=OPT, and for the ratio is at least (see Theorem 12 in Section 5). Let and fix a switch step .
Phase 1, . Lemma 2 gives , so , and .
Phase 2, . Lemma 3 gives , so while (if some , then and we are done). At the switch, , so
For , an exact computation in rational arithmetic (Appendix B) gives . For larger , write . For the product telescopes, (each factor ), and otherwise. Since also ,
The function attains its maximum 0.34801 near , and on (checked on a grid, using on ; Appendix B). This interval is longer than for every , so it contains a point with an integer, and .
Lemma 3 does not use that the merges are greedy; Lemma 2 does, through .
4.4 Groups close when hit
Corollary 4 pays at every step for the live nodes and ghosts, although many of them are gone long before the end. The Kozma-Voderholzer inequality avoids this by closing one rule per step, so its last term decays like . We now show that the objects of Section 4.2 also come in groups that close for good, and that a group closes every time greedy glues a gap carrying an object.
Groups. The objects form groups: for each label the intact -nodes and the moved -nodes , and for each class its ghosts . By (I2)–(I4) all objects of a group have one type, and by the proof of Lemma 3 each group has at most objects. The groups and are never both non-empty: moved -nodes are created only in the step that merges , and that step kills all intact -nodes. A label is a letter label if both children of its nodes are single letters; let be the number of letter labels of , and . Letter labels never have moved nodes (they can only be centers of class A).
A sharper count per replacement. For one replacement let be the numbers of intact and of moved nodes it kills, the ghosts it destroys, and the number of objects it creates (a moved node or a ghost, so ). Let if an object sits at the glued gap when the replacement acts (a hit), and otherwise. Define
Intact nodes count fully and the other objects half. The next lemma says that a replacement costs at most 2 units in this currency, plus half a unit if it is a hit.
Lemma 5. For every partial k-sequence , all full merges and every , with the number of hits in steps , and the numbers of intact and moved nodes after step , and the number of ghosts,
Proof. One replacement. If , the only objects are at the two outer affected gaps, each contributes at most 1, and nothing is created (creation needs an original triple, which has a node at the glued gap): . If and , the three objects contribute at most : . If the replacement is an original triple; a save or a class-A triple creates one object, so . So every replacement except a failure has .
Failures and images. A failure has and , which exceeds by . Its image makes up for it (Figure 3). The image finds the gap empty, so its objects lie at its own glued gap and at its right affected gap, and it creates nothing: if its hit indicator is 0, and if . In both cases . So the pair has
exactly the bound for each of the two. Images are not original triples, so no image is itself a failure, and distinct failures have distinct images. Pairing every failure with its image and summing over all replacements gives .
The identity. Intact nodes are never created, so . Moved nodes are created by saves and ghosts by class-A triples, so . Substituting into the definition of gives the identity.
So the loss is plus half a unit per hit, and what remains is weighted by 1 for intact nodes and for moved nodes and ghosts. The next lemma shows that each hit closes a group, so that the half units are paid for.
Lemma 6 (groups close when hit). (G1) An object hit in step j has type .
(G2) After step j no object of type survives. Hence the whole group of an object hit in step j is empty after step j.
(G3) Each group is populated only once: at the start, and in a single step, and objects created in a step are not hit in that step. So a group emptied by a hit stays empty, and distinct steps containing a hit empty distinct groups.
Proof. (G1) The type of the hit object is the pair of tokens at the glued gap, which is . (G2) For with every adjacent occurrence is replaced, so every gap of type is glued. For , every gap inside a run of 's is either glued or adjacent to a glued gap under left-to-right pairing, hence affected. Either way every object of type is killed or destroyed in step , and all objects of a group share one type. (G3) Moved -nodes are created only in the step merging , and ghosts of a class only in the step fixed by its class, by (I3), (I4). A created object sits at or , and neither gap can be glued in the same step (gluing would use position , which this replacement has already used, and gluing would merge the new token again). So a hit always empties a group that was populated before, and after that the group is never populated again.
A potential. To turn “each hit closes a group” into a bound, we weight the groups that have not yet been closed by a hit. Give each label the weight until is emptied by a hit; then if is not a letter label and if it is; and once is emptied by a hit. Call a class possible if is not a letter label and the child of opposite the side is a letter label. Each possible class gets weight until a hit empties it, then 0. Let
both after step i.
Table 3: The run of Section 4.4. For each replacement: the glued gap, its affected gaps, the objects it removes (intact nodes by label, or a ghost), , , the hit indicator , its kind (Table 2), what it creates, and (Lemma 5).
| step | merge (count) | glues | affected | removes | h | kind | creates | |||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | (a, b) ( ) | 2 | 1, 2, 3 | 3 | 0 | 1 | JR, failure | — | 3 | |
| 4 | 3, 4, 5 | 2 | 0 | 1 | image | — | 2 | |||
| 9 | 8, 9, 10 | 3 | 0 | 1 | class A | ghost at 10 | ||||
| ; objects: one ghost, class ( , right), gap 10, type ([ ], ); | ||||||||||
| 2 | ([ ], ) ( ) | 5 | 3, 5, 6 | — | 0 | 0 | 0 | other | — | 0 |
| 10 | 8, 10 | ghost | 0 | 1 | 1 | other (hit) | — | |||
| ; no objects; | ||||||||||
Lemma 7. (a) . (b) . (c) Every step containing a hit lowers by at least , and by at least 1 if it empties the intact group of a letter label. (d) .
Proof. (a) We compare the two sums label by label and class by class. For a label , the contribution to is 1 if is non-empty, if is non-empty, and 0 otherwise; it is never , since and are never both non-empty. If is non-empty, it has not been emptied by a hit (by (G3) it would then stay empty), so . Suppose . Then no hit has emptied . is filled only by saves. Each save hits an intact -node, so by (G2) was emptied by a hit. Hence (the label is not a letter label, since it has moved nodes). For a class , the contribution to is if is non-empty, and then has not been emptied by a hit, so ; every class that actually receives a ghost is a possible class. Summing, .
(b) Initially every is 1. There are at most labels, of which are letter labels, and a possible class needs a label that is not a letter label and a side: at most classes. So .
(c) By (G2) a step with a hit empties the group of the hit object, and by (G3) that group had not been emptied by a hit before. Emptying lowers from 1 to , or to 0 for a letter label; emptying lowers from to 0 (by the argument in (a), at that point); emptying a class lowers from to 0. Weights never increase.
(d) Each group has at most objects, so ; use the identity of Lemma 5.
A second example. The following instance shows a failure and its image, a class-A triple that leaves a ghost, and a later hit that empties the ghost's group.
The example of Section 3 shows only a moved center; this one shows the other two outcomes of an original triple and a hit. Let k = 5 and
where parses the first block and the second (Figure 4). Positions are (the separator is position 7), and the forest has the nodes at gaps and at gaps 8,9,10. Each block is reduced to one token, so no -sequence does better and . The junction pairs are ; the only letter label is (), and the only possible ghost class is .

Figure 4: The instance of Section 4.4. Small numbers are positions; gap lies between positions and , and each node sits above its junction. Greedy's first merge ab (dashed boxes) makes three replacements. is an original triple of class JR whose save fails, because glues gap 4; is its image. is a class-A triple: its center has two single-letter children, its parent sits at gap , and a ghost is left there. Greedy's second merge ([ab], y) glues gap 10, hits the ghost, and empties the group for good.
Step 1. The pair (a, b) has count 3 and every other pair at most 2, so greedy merges it (Table 3). The first replacement glues gap 2; gaps 1, 2, 3 carry the intact nodes , so it is an original triple with center . Since and , the center is of class JR and would move to gap 3 with type ([ab], a); but gap 4 is glued by the next replacement , so this is a failure and is its image. As in Figure 3, the first affected gap of is gap 3, already emptied by , so kills only and at gaps 4, 5. The third replacement glues gap 9 and kills at gaps 8, 9, 10: an original triple whose center is a letter label, so it is of class A. Of the two ancestors at gaps 8 and 10, the lower is (span 9..11), the parent, so . It sits at , so we place a ghost of class at gap 10; its type is , as (I4) requires. After the step all eight nodes are dead and one ghost is alive: , .
The counts after step 1 are tight. With , , , and , every bound of Lemmas 3 and 5 holds with equality:
Step 2: the group closes when hit. In the pair ([ab], y) has count 2 and every other pair count 1, so and greedy merges it. The replacement at gap 10 glues exactly the ghost's gap: a hit, of type as (G1) says. After the step no object of that type survives (G2), and the group can never be populated again (G3), since its ghosts are created only in the step that merges ab. The potential of Lemma 7 records this: ; step 1 hits intact nodes of (not a letter label, ) and of (a letter label, ), so ; step 2 hits the ghost, so . Now , , and Lemma 7(d) holds with equality: . The remaining three steps each merge a pair of count 1, so for every tie-breaking rule.
The ghost bookkeeping now gives an inequality whose last term decays over the run.
Lemma 8. Let be an optimal partial -sequence with letter labels. For every greedy run and every ,
Proof. Let be the steps containing a hit and . A step has replacements, so . By Lemma 7(b,c), . With Lemma 5 and Lemma 7(d),
Each term is non-negative for , so the sum over is at most the sum over all , which is . This is .
When the optimum has many letter labels, ghosts are numerous, and it is better not to create them at all. The no-ghost bookkeeping is the same as before except for one rule: a class-A triple creates nothing; its center simply dies. Its objects are intact and moved nodes only, the invariants (I1)–(I3) hold with the same proofs (there is no (I4)), and Lemma 6 holds with the same proof, with groups and only.
Lemma 9 (no-ghost bookkeeping). Let be an optimal partial -sequence with letter labels. For every greedy run and every ,
Proof. Define , hits and as before, now with and with only for saves. Every replacement except failures and class-A triples satisfies as in Lemma 5, and failures are paired with their images as there. A class-A triple now kills three intact nodes and creates nothing, so . Hence , where is the number of class-A triples, and the identity becomes .
Use the potential with label weights only, , so , and as in Lemma 7(a). Let be the steps containing a hit and those containing a class-A triple. A class-A triple hits an intact node of a letter label and, by (G2), empties its group, lowering by 1 instead of . Distinct steps of empty distinct letter groups, so , and . With ,
The first sum is at most as before, and the second, over at most steps, is at most , because . This is .
For , reads , which is Lemma 2. The number is a property of the optimum, unknown to the analysis, so the final bound takes the worst case over .
4.5 The main theorem
The three inequalities are now combined in three phases: Lemma 2 while it is strongest, then the no-ghost inequality, then the ghost inequality. The deficits are , and . Where the second phase hands over to the third, the unknown value enters; the next lemma removes it in closed form.
Lemma 10. Write . Let , and . Then .
Proof. For the difference of the two pieces is , so the minimum is , which is linear in and equals at . For the minimum is . Hence the maximum is the larger of the values at and at , that is .
Theorem 11. For every string , every and every greedy run with any tie-breaking rule, , where OPT is the partial-merge optimum.
Proof. For the ratio is at least (see Theorem 12 in Section 5). Let , normalise OPT = 1, and let be the number of letter labels of an optimal sequence. We use Lemma 2 for , then for , then for , for a switch step .
Phase 1. As in Corollary 4, .
Phase 2. (NG_{i}) gives , so while , starting from . So with and .
Phase 3. (GH_{i}) gives while , so with .
Joining the phases. At the switch, and also , since . The value is unknown but at least , so by Lemma 10 with , . A second schedule, Lemma 2 for and then , needs no joining. Since , the two schedules give with
Both are non-decreasing in each of , , , so any upper bounds on these quantities may be substituted. The products telescope: for .
Small . For each and each , an exact computation in rational arithmetic (Appendix B) finds switch steps for which ; the smallest value found is 0.361545.
Large k. For k > 1000, see the summary below and Appendix C.
Large budgets, in summary. For the proof is a calculation, given in full in Appendix C. First, , and are bounded by simple expressions in and . Second, as the three recursions become the differential inequalities , and in the time , whose solutions give the best switch points in closed form; the value of the scheme, minimised over , is at . Third, finite multiplies the final deficit by at most , where for (no-ghost schedule) and for (ghost schedule). A table of 27 rows, each checkable with a calculator, shows that the value is at least 0.3613 for every , and the value for is at least 0.364269. At this gives , and more for larger .
5 Exact ratios for small budgets
At a fixed small budget the worst case can be pinned down. Both values below are far above the general upper bound: the families of [5] and [9] need budgets in the hundreds before their ratio drops below one half (k = 1248 in [5], k = 528 for the smallest string tabulated in [9]). Here , the infimum taken also over tie-breaking.
Theorem 12. For every string, every greedy run and every partial merge sequence of length two, util . Consequently .
Proof of from the inequality. If then and . If then ; otherwise , since . For the matching upper bound let , where is a separator. The pair aa has count and every other pair has count at most 2t, so every greedy run merges aa first, after which every count is at most t; greedy's utility is at most . Merging ab and then a · ab gives 4t. Hence , for every tie-breaking rule.
The inequality is proved in Appendix A. The proof compares the optimum with greedy's first token: after greedy merges , every junction of the optimum either disappears inside an -token or survives as a junction between two tokens of of one of four kinds; each kind occurs at most times, except that two adjacent -tokens can occur up to times. The hard case is an optimum that merges , which competes with greedy for the same letters; there the tokens of greedy are a shared resource of size , and a decomposition into chains settles the count. The bound is tight on aaabaab, where , and OPT=4.
At three merges the worst case is more delicate. For let
a string of length with all separators distinct.
Proposition 13. For every and every tie-breaking rule, greedy's utility on with three merges is , while . Consequently .
Proof. No pair spans a separator, so pair counts are sums over blocks. In the counts of ab, bx, xa, ba and xx are , , , and , and every pair with a separator has count 1, so every greedy run merges ab C first, with . In the blocks read bxxCxxa, xCa, bCCx, bx, xa, ba, C, xx; now xx has count and every other pair at most , so greedy merges xx E with . In the blocks are bECEa, xCa, bCCx, bx, xa, ba, C, E, and every pair has count at most , with equality attained; so and BPE = . The full-merge sequence ba, bx, xa has utilities , , : the first turns xaba xaB, bababx BBbx and ba B; the second then finds bx twice in each bxxabxxa, once in each BBbx and once per block bx; the third finds xa twice in each XxaXxa (where X is the new symbol for bx), once in each xaB and once per block xa. Hence .
The member , of 156 symbols, already has ratio 0.6167, below the upper bound 5/8 for given in the conference version of [4].
6 One inequality would settle the problem
The overview showed that the whole gap is the cost of triple events. The following conjecture says that, after re-typing, there is no such cost.
Conjecture 14 (re-typing conjecture, RC). For every string , every budget , every greedy run and every ,
Proposition 15. If holds for a string , a budget , a greedy run and all , then . In particular, if holds then .
Proof. Let . If for some then . Otherwise gives , so for , and . The sequence increases to . The reverse inequality for is the upper bound of [5, 9].
If the optimum's tokens have length at most three, no triple event can occur, and the per-step count of the overview gives for every ; this is Yang's Theorem 1 [9]. RC asks for the same conclusion with tokens of arbitrary length, and Lemma 3 obtains it with 2.5 in place of 2 and 2k in place of k. We have partial results toward RC and are continuing this work.
7 Why one third was stuck
The KV lower bound passes through a relaxation. A -packing of is a union of sets of gaps, each set consisting of pairwise non-adjacent occurrences of one letter pair, no gap used twice; is its maximum size. The junctions of any partial -sequence, grouped by label, form a -packing (by (F2) and (F3)), so , and Kozma and Voderholzer prove [4]. The second inequality cannot be improved.
Theorem 16. .
Proof. Fix and rationals and for , where ; scale them to integers keeping . Let , partitioned as with , “differences of level ”. Work with letters , ; the edge , , is a letter pair, and edges with different are different pairs. For each level and each , deal out the differences of lower levels, each exactly once, as pairs . Let . For every the string contains, each block followed by its own separator:
- copies of the middle block for each level , each and each of its pairs ; its three letter pairs are edges with differences ;
• copies of for each , and extra copies of for each .
The four letters of a middle block are distinct mod , and no pair spans a separator.
Counts. An edge of level occurs times as a middle edge (or times in the two-letter blocks if ), times as a side edge of the blocks of higher levels, and times in the extra blocks: in all.
Greedy. We claim greedy merges all edges of level , then all of level , and so on, each edge of level with utility , whatever the tie-breaking. Suppose levels are done. Merging a middle edge destroys the two side edges of its blocks and creates only pairs containing the new symbol, each of count at most (the blocks of one middle edge have distinct partners). So an unmerged edge of level has count , an edge of level has count , and every other pair has count at most . Edges of the same level never share a block, so merging one does not change the count of another, and the order within a level is irrelevant. After all levels, exactly merges have been made, and .
Packing. All occurrences of one edge are pairwise non-adjacent (the three pairs of a block have different differences), so taking all occurrences of all edges is a -packing: .
Ratio. Hence , which tends to as . Now and , so for a constant . Therefore and , and the ratio tends to as . The reverse inequality is 's.
The loss is in the relaxation: a k-packing may credit the pairs at gaps and together, which no merge sequence can, and in each middle block of the construction a greedy replacement destroys three packing elements at once. A packing records only which pair sits at each counted gap. It does not record that all copies of a rule have the same tree, and that is exactly what Lemma 3 uses: the type of a moved center or of a ghost is read off the rule. So any improvement over 1/3 has to use rule determinism, or some other structure that packings forget.
8 Discussion
Greedy BPE achieves more than a third of the optimal reduction in string length: at least 0.361, against the strongest optimum. The proof rests on two observations: rule determinism lets us pay for triple events by moving centers and leaving ghosts, and the resulting objects form groups that close for good when greedy hits them. This method has a limit. Optimising the schedule of Section 4.5 over all switch points gives at most 0.361484 as , and that value is reached by optima with about 0.32 letter labels. The remaining gap to the upper bound is the gap between this accounting, which pays 2.5 units per greedy replacement, and an accounting that pays 2. Closing it needs a different idea: a way to re-type a destroyed merge point that never fails and never leaves a placeholder. The re-typing conjecture (Conjecture 14) states exactly this, as a single inequality; it would give . At fixed budgets, the values (beyond the bound 7/12), and are open.
Use of AI tools. AI-assisted tools, including Claude (Anthropic), were used throughout the research process to support mathematical reasoning, computational experimentation, proof verification, and manuscript preparation. The authors guided the research direction, directed and evaluated the central arguments, and oversaw the computational and verification workflows. Additional independent AI-assisted checks were employed to assess proof consistency and computational correctness. The authors take full responsibility for the results and conclusions presented.
References
[1] Kundan Baliga, Aiden Xie, and Aditya Byju. GreedTok is a constant-factor approximation for partition-cover tokenization. Preprint, Zenodo, 2026. doi:10.5281/zenodo.23954767.
[2] Philip Gage. A new algorithm for data compression. The C Users Journal, 12(2):23–38, 1994.
[3] Violeta Kastreva, Philip Whittington, Dennis Komm, and Tiago Pimentel. Tokenisation over bounded alphabets is hard. In The Fourteenth International Conference on Learning Representations (ICLR 2026), 2026. arXiv:2511.15709.
[4] László Kozma and Johannes Voderholzer. Theoretical analysis of byte-pair encoding. In Philip Bille, Seth Pettie, and Sabine Storandt, editors, 34th Annual European Symposium on Algorithms (ESA 2026), volume 388 of Leibniz International Proceedings in Informatics (LIPIcs), pages 80:1–80:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2026. doi: 10.4230/LIPIcs.ESA.2026.80.
[5] László Kozma and Johannes Voderholzer. Theoretical analysis of byte-pair encoding. arXiv:2411.08671v2, 2026. Version 2, extended version of the ESA 2026 paper. URL: https://arxiv.org/abs/2411.08671v2.
[6] N. Jesper Larsson and Alistair Moffat. Off-line dictionary-based compression. Proceedings of the IEEE, 88(11):1722–1732, 2000. doi:10.1109/5.892708.
[7] Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1715–1725, Berlin, Germany, 2016. Association for Computational Linguistics. doi:10.18653/v1/P16-1162.
[8] Philip Whittington, Gregor Bachmann, and Tiago Pimentel. Tokenisation is NP-complete. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 28133–28153, Vienna, Austria, 2025. Association for Computational Linguistics. doi:10.18653/v1/2025.acl-long.1365.
[9] Hanyu Yang. Byte-pair encoding can lose more than half of the optimal compression. Preprint, Zenodo, version 1.0, October 2026. doi:10.5281/zenodo.23207123.
[10] Vilém Zouhar, Clara Meister, Juan Gastaldi, Li Du, Tim Vieira, Mrinmaya Sachan, and Ryan Cotterell. A formal perspective on byte-pair encoding. In Findings of the Association for Computational Linguistics: ACL 2023, pages 598–614, Toronto, Canada, 2023. Association for Computational Linguistics. doi:10.18653/v1/2023.findings-acl.38.
A Proof of the two-merge inequality
This appendix proves the inequality of Theorem 12. Its notation is local: is the symbol created by greedy's first merge, is a merge of , is a position, and , , , are counts used only in the component argument. We first recall an elementary fact and the lemma that describes how greedy's first merge fragments the junctions of any other merge sequence.
Lemma 17 (max-count monotonicity). If is obtained from by one full or partial merge, then . Consequently every merge of a partial merge sequence on has utility at most , and .
Proof. Let the merge be . Take any pair of and a maximum set of non-overlapping occurrences of it. If neither symbol is , each occurrence is an occurrence of in (merging never creates a new adjacency between two old symbols), and the set stays non-overlapping, so . If , each occurrence of arises from a factor of ; map it to the occurrence of at the same place. Distinct occurrences of occupy disjoint tokens of and hence disjoint positions of , so the images are non-overlapping and . Symmetrically and . Thus every count in is at most some count in .
Fix a string and let greedy's first merge be , producing , so and . For a position of let be the token of containing it. Let be any partial merge sequence and one of its merges, with junction pair and set of junctions ; so is the utility of , the elements of are pairwise non-overlapping occurrences of in , and the sets of different merges are disjoint (Section 2).
Lemma 18 (image kinds). Every is either absorbed, meaning that it is one of the occurrences replaced by greedy's first merge, which requires , or has an image kind , where the kinds and require and the kinds and require . For the positions of of kind are pairwise non-overlapping occurrences of in , hence at most of them; those of kind number at most .

boxes: elements of (ba)
braces: Z-tokens (greedy's ab)
Figure 5: A component of linked elements of (boxes) with three interior Z-tokens and a left end token, marked (the ab formed with the preceding letter a); there is no right end token because the component is followed by . In the component's Z-tokens form a run of length .
Proof. If and lie in the same Z-token, is absorbed. Otherwise position can lie in a Z-token only as its second letter, which requires , i.e. , and position only as the first letter of a Z-token, which requires ; so is one of the four listed kinds, with the stated requirements. The non-overlap statements below use only that is a set of pairwise non-overlapping occurrences of in , and therefore apply to any such set.
Non-overlap. Two positions of of kind give the token pairs and of single letters, which overlap only if , excluded because is non-overlapping in . For kind the images are with covering ; the two images share a token only if the single-letter token equals , impossible, or , impossible for . Kind is symmetric. For kind the images are occurrences of at distinct places, hence at most ; in a run of consecutive 's there are raw and non-overlapping occurrences, and , so . If then occurrences of never overlap, so greedy replaces all of them and every with is absorbed. The case is identical with read as the token .
Corollary 19. A merge whose junction pair is neither nor has utility at most ; if moreover and , at most .
Proof. No position is absorbed. If then , so only the kinds and occur; if then and only and occur; if neither, only occurs. Each kind other than contributes at most by Lemma 18.
The exclusion of is necessary: on babababa followed by ten blocks |ab, greedy merges ab with and then has , while the merge ba has utility 4.
Proof of the inequality of Theorem 12
Let greedy first merge , , . Let , be the junction pairs of ; merges two letters, , and merges two tokens of the string after . By Lemma 17, .
Case 1: . Corollary 19 gives , and .
Case 2: . Symmetrically and .
It remains to treat junction pairs both in . We first assume .
Components (Figure 5). For a set of pairwise non-overlapping occurrences of in , call two elements linked (the letters then form an occurrence of , a Z-token of , which we call interior). A component is a maximal chain of linked elements;
it has elements and interior Z-tokens. Its left end token is the Z-token covering if , and its right end token the Z-token covering if ; write for their existence. The Z-tokens of a component (interior and end tokens) are distinct tokens, and distinct components have disjoint sets of Z-tokens: a shared token would be an end token of both, forcing their extreme elements to be linked. Each Z-token touched by contains a letter glued by . In the Z-tokens of a component form consecutive 's, and the blocks of different components are disjoint; a run of consecutive 's containing disjoint blocks of lengths has non-overlapping occurrences of , so . Finally, by Lemma 18 (applied to the non-overlapping set ) the first element of a component has kind if and if , the last has kind if ; the number of components with is therefore at most , and likewise for , and the number of components with is at most (a component with and no end tokens starts with kind and ends with kind ).
Case 3: . Then replaces a set of ab-occurrences, creating . If , then replaces ab-occurrences disjoint from and . Otherwise and .
-
: every Z-token touched by is not in (its or is a single token when acts). With the component decomposition of : and the touched tokens number , so .
-
: each glued position has its left Z-token (covering ) in , distinct for distinct ; its kind is (at most such) or , in which case its right Z-token is not in and distinct for distinct . So . is symmetric.
-
: the glued positions are pairwise at distance at least 4 and each yields an occurrence of in ; these are non-overlapping, so .
Case 4: . replaces a set of ba-occurrences, creating . If then replaces further ba-occurrences and . Otherwise and . Decompose into components.
-
: can only use Z-tokens not touched by , so and, with , .
-
: a glued position is a Z-token covering whose (at ) is the first letter of an element of and whose (at ) is a single token; the latter means , so is the first element of its component and, as , that component has a left end token, namely this one; so and . is symmetric.
-
: within a component with interior tokens at most pairs of consecutive 's can be merged, and . Summing, , and .
Case 5: . Now over the maximal runs of , and in each run becomes , so and . Cases A and B cover all junction pairs other than (Lemma 18 with read as ).
If both junction pairs are , then replaces a set of -occurrences creating , and ; both act inside the -runs independently. Let be the numbers of replacements of inside run . For , . For , each replacement of uses one single and one token , so and , whence . For and . Writing , the elementary inequalities
In every case .
Remark 20. The argument uses only three properties of greedy's first merge: every merge has utility at most , every kind of image has count at most in , and the Z-tokens are a shared resource of size . The bound is tight in two different ways: at aaabaab (, , OPT = 4) and at the family obtained by concatenating copies each of the blocks xbay, abaz, wbab, abab, each block preceded by its own separator symbol: there , the greedy run that merges ab first has and , and the sequence ba, a ba has utility .
B The finite checks
The base layer. The proof of Corollary 4 uses two finite checks: that for , in exact rational arithmetic, and that on . The second is checked on equally spaced points; since has absolute value at most 1 on , the minimum over the interval is at least the minimum over the grid minus half a grid step, which the script checks. The script below performs both checks in about two seconds; the smallest exact value is 0.34829.
Finite checks in the proof of the main theorem (BPE >= 0.3478 OPT).
import math from fractions import Fraction as Fr C = Fr(3478, 10000) def B(k, m): # exact lower bound on BPE/OPT for budget k and switch step m eta = Fr(1) for i in range(m): eta == max(Fr(0), Fr(k - i - 3, k - i)) p = max(Fr(0), 1 - Fr(5, 6) * (1 - eta)) return Fr(2, 5) * (1 - p * (1 - Fr(5, 4 * k)) ** (k - m)) def f(u): # fluid bound, B(k, m) >= f((k - m)/k) return 0.4 * (1 - (1 - 5 / 6 * (1 - u ** 3)) * math.exp(-1.25 * u)) K = 200 exact = min(max(B(k, m) for m in range(k)) for k in range(3, K + 1)) lo, hi, n = 0.275, 0.344, 10 ** 6 step = (hi - lo) / n fmin = min(f(lo + step * j) for j in range(n + 1))
|f'| <= 1 on [0, 1], so f >= fmin - step / 2 on [lo, hi]
assert exact >= C and fmin - 0.5 * step >= C and 1 / (hi - lo) <= 15 ustar = max((j / 10 ** 5 for j in range(10 ** 5)), key=f) out = dict(C=float(C), K=K, ustar=ustar, fmax=f(ustar), exact_min=float(exact), lo=lo, hi=hi, fmin=fmin, kmin=math.ceil(1 / (hi - lo))) print(out)
The main theorem, small . The script cert.py, run through cert_run.py, handles and every : it pre-selects switch points in floating point and then confirms the value of the chosen schedule exactly, with the telescoped products in rational arithmetic. The smallest confirmed value is 0.361545.
The main theorem, large . The script hand_table.py recomputes every row of Table 4 in exact rational arithmetic, including the conditions and (with a rational upper bound on ), and the bounds at are recomputed exactly from its output. The script check_large_k.py performs the independent nine-breakpoint check (0.361329 for , 0.361 for ) and evaluates the closed forms of Proposition 21.
The second example. The script check_example2.py replays the run of Section 4.4, recomputes every object, kill, destruction, hit and potential value of Table 3, and checks each inequality of this section on the instance.
C The large-budget calculation
This appendix proves the large- case of Theorem 11. We first bound , and by simple expressions in and , then compute the best switch points as , and finally show that finite loses only an explicit .
Four elementary bounds. Each holds for every ; switch points are written and for fractions .
(B1) . Proof: for , and if .
(B2) for . Proof: , since ; the right side telescopes.
(B3) (No-ghost switch.) If and , then
Proof: and of ; apply (B2), divide by , and use in and in .
(B4) (Ghost switch.) If and , then and . Proof: (B1) with , and (B2) with .
The fluid optimum. At the bounds are the solutions of the continuous versions of the three recursions: with , the deficits satisfy , and , whose solutions are , and at . Let be the best value of over all switch points at . It is convenient to write , , (the threshold appears below).
Proposition 21 (fluid optimum). Let
The best no-ghost switch is and the best ghost switch is . With (the root of ) and (where , equivalently for ),
is decreasing on and increasing on ; its minimum is at , with switch .
Proof. We minimise separately for the two schedules, by locating the zero of its derivative in the switch point, and then compare the two minima. No-ghost schedule. With , , and : where (that is, ), , whose derivative in is ; it changes sign once, at , the displayed formula. Where , is decreasing in . So the minimiser is clipped to . At , and , which gives the middle formula; at , gives the first.
Ghost schedule. has -derivative of the sign of ; this cubic decreases on from 1 to , so the minimiser over is .
Regimes. The no-ghost schedule with and the ghost schedule with coincide. At the cubic is , and reads , the same equation; so for the ghost optimum is , dominated by the no-ghost schedule, and for the no-ghost optimum is , dominated by the ghost schedule. With , is strictly increasing in , so exactly on and exactly on .
Shape. On the ratio has derivative of the sign of , so decreases. On , at fixed decreases in , and stays admissible as grows, so increases. The cubic increases in at fixed (its -derivative is ) and decreases in , so its root increases with ; in particular on . The value is obtained by minimising the middle branch numerically; the proof of Theorem 11 does not use it.
Finite loses an explicit . For fixed switch fractions, the bounds (B1)–(B4) at exceed their values at by a factor at most , for an explicit .
Proposition 22. Fix . For the no-ghost schedule with switch fraction and , or for the ghost schedule with switch fraction and , let be the value of the bounds (B1)–(B4) at . Then for every ,
If and , then ; if , then .
Proof. Let be the bound on obtained from (B1)–(B4), so . For the no-ghost schedule, (note ),
, and for . For the ghost schedule, and for . So , which is the displayed inequality.
For the bounds on : if then , and with gives , since . For the ghost schedule, and .
A table a reader can check. It remains to bound from below. On an interval fix one switch fraction for the no-ghost schedule. As grows, and decrease and increases (the ratios and have derivatives of the signs of and ). Since is non-decreasing in all three, its value anywhere on the interval is at most
so on the whole interval. Table 4 lists 27 intervals covering ; each row can be checked with a calculator. In every row , and holds on the whole interval (the difference increases in and is non-negative at ), so by Proposition 22. The table gives for every .
Conclusion for . For (note , since at ) use the switch of the row of Table 4 containing : and . For use the fluid-optimal ghost switch : then , because increases on (Proposition 21); by the last row of Table 4; and , so . The right side of Proposition 22 is increasing in , and for . At it is therefore at least 0.361105 for and at least 0.363850 for , and it only increases with . Together with the exact computation for , this proves Theorem 11; the margins are 0.361545 - 0.361 for small and 0.361105 - 0.361 for large .
The fluid value of Proposition 21 is the value of this scheme as with the best switch points. As an independent check of the large-k case, a piecewise linear switch rule through nine breakpoints and the bounds (B1)–(B4), evaluated in exact arithmetic at the corners of 4000 intervals of , certify for every and for every (Appendix B).
Table 4: Lower bounds on the large- value of the no-ghost schedule. On the switch fraction is , and is a lower bound for the value, with computed from the two displayed products. Generated by hand_table.py (Appendix B), which repeats every row in exact rational arithmetic.
| 0.000 | 0.052 | 0.602 | 0.18032 | 0.53640 | 0.361311 |
| 0.052 | 0.102 | 0.623 | 0.18031 | 0.54233 | 0.361323 |
| 0.102 | 0.148 | 0.642 | 0.18054 | 0.54749 | 0.361300 |
| 0.148 | 0.190 | 0.661 | 0.17948 | 0.55402 | 0.361308 |
| 0.190 | 0.225 | 0.677 | 0.17838 | 0.55918 | 0.361328 |
| 0.225 | 0.254 | 0.691 | 0.17677 | 0.56446 | 0.361307 |
| 0.254 | 0.276 | 0.703 | 0.17430 | 0.56951 | 0.361311 |
| 0.276 | 0.291 | 0.712 | 0.17183 | 0.57342 | 0.361322 |
| 0.291 | 0.301 | 0.716 | 0.17188 | 0.57392 | 0.361311 |
| 0.301 | 0.308 | 0.703 | 0.18634 | 0.55777 | 0.361316 |
| 0.308 | 0.314 | 0.695 | 0.19661 | 0.54774 | 0.361310 |
| 0.314 | 0.319 | 0.689 | 0.20496 | 0.54009 | 0.361322 |
| 0.319 | 0.324 | 0.684 | 0.21265 | 0.53376 | 0.361315 |
| 0.324 | 0.329 | 0.680 | 0.21959 | 0.52845 | 0.361314 |
| 0.329 | 0.334 | 0.675 | 0.22795 | 0.52218 | 0.361320 |
| 0.334 | 0.339 | 0.671 | 0.23552 | 0.51691 | 0.361333 |
| 0.339 | 0.345 | 0.668 | 0.24279 | 0.51263 | 0.361316 |
| 0.345 | 0.352 | 0.664 | 0.25232 | 0.50712 | 0.361309 |
| 0.352 | 0.360 | 0.659 | 0.26442 | 0.50039 | 0.361316 |
| 0.360 | 0.370 | 0.655 | 0.27744 | 0.49434 | 0.361301 |
| 0.370 | 0.382 | 0.650 | 0.29464 | 0.48679 | 0.361316 |
| 0.382 | 0.397 | 0.645 | 0.31629 | 0.47865 | 0.361327 |
| 0.397 | 0.417 | 0.641 | 0.34416 | 0.47053 | 0.361306 |
| 0.417 | 0.443 | 0.636 | 0.38625 | 0.45993 | 0.361333 |
| 0.443 | 0.478 | 0.634 | 0.44521 | 0.45006 | 0.361331 |
| 0.478 | 0.525 | 0.636 | 0.53727 | 0.44068 | 0.361329 |
| 0.525 | 0.545 | 0.582 | 0.81258 | 0.37867 | 0.364269 |