Manuscript Offprint
arXiv:2611.09157Word Subtraction Games
Abstract
This note is a self-contained text on word subtraction games, combinatorial games in which players alternately remove a nonempty suffix belonging to a prescribed subtraction set from the current word. It collects and develops basic results on these games from the viewpoints of combinatorial game theory and formal language theory. We focus on the relationship between subtraction sets and the resulting languages of winning and losing positions. The topics include finite, regular, and context-free subtraction sets, as well as several variants and further developments.
Preface
Around the beginning of 2026, the first author began studying word subtraction games, a class of combinatorial games in which positions are finite words and moves consist of removing prescribed nonempty suffixes. They can be viewed as a natural generalization of classical subtraction games, obtained by replacing heaps with finite words.
Word subtraction games connect combinatorial game theory with automata theory and formal language theory. Both the subtraction set specifying the legal moves and the resulting sets of winning and losing positions can be viewed as languages. This allows us to ask how the structure of the rules is reflected in the structure of the outcomes, and to study that relationship using tools from formal language theory.
The goal of this note is to give a self-contained introduction to word subtraction games, their basic properties, and several variants. We collect the results obtained so far and discuss questions for further study. This note is intended to be accessible to readers without prior knowledge of combinatorial game theory or formal language theory. The basic notions needed for the main development are introduced along the way.
The main development begins with finite subtraction sets in Section 2, followed by regular subtraction sets in Section 3 and context-free subtraction sets in Section 4. Section 5 considers what happens when moves can remove prefixes as well as suffixes, or factors from within a word. Section 6 presents a selection of advanced topics, including misère play and algorithmic questions about word subtraction games. The final section describes the research background and discusses broader directions for further study.
Although this note is primarily intended to be read in order, readers who have completed Section 3 can proceed to Section 4, Section 5, or any of the topics in Section 6, according to their interests.
*Nagoya University, y-inoue@sqlab.jp †Hiroshima University, hiroki.inazu@gmail.com
Several sections include exercises and open problems. The exercises are intended to help readers check their understanding, fill in details of selected proofs, and explore further results not developed in the main text. Some of the more challenging exercises are marked with a star. The open problems collect questions that the authors currently find interesting. Some have not yet been investigated in depth, and we hope that readers will find useful starting points for their own investigations among them.
AI tools were used to assist with drafting and editing parts of the English text and to help check and improve some mathematical arguments. The authors carefully reviewed the AI-assisted material and take full responsibility for the content of this note.
We would also like to thank Shun-ichi Kimura and the members of his research group, including Hiyu Inoue, Yuto Terakura, Haruki Wada, Kosaku Watanabe, and Takahiro Yamashita. The second author, as a member of this group, is especially grateful for the continuous guidance and stimulating discussions that have supported his research in combinatorial game theory. The first author would also like to thank the group for the many fruitful discussions and interactions in combinatorial game theory.
The first author would particularly like to thank Yuji Komatsu, who first introduced him to combinatorial game theory and continues to discuss these ideas with him. We are also deeply grateful to Ryuya Hora, whose broad knowledge and insight have contributed greatly to our understanding of both formal language theory and combinatorial game theory, as well as the connections between these two areas. In addition, we would like to thank Tomoaki Abuku, Kengo Hashimoto, Hironori Kiya, Hikaru Manabe, Nanako Omiya, Yu Tokumoto, Takuho Yamada, and Ryo Yoshinaka for many valuable discussions on several occasions during the summer of 2026.
As mentioned above, this note was written with the help and support of many people in various ways. Nevertheless, any errors or inaccuracies in this note are entirely the responsibility of the authors.
Contents
1 Word Subtraction Games 4 1.1 Combinatorial Games ..... 4 1.2 Words and Languages ..... 5 1.3 Word Subtraction ..... 7
2 Finite Subtraction Sets 10 2.1 Motivation ..... 10 2.2 Finite Automata ..... 12 2.3 Periodic Structure of Regular Languages ..... 15 2.4 Back to Word Subtraction ..... 19
3 Regular Subtraction Sets 23 3.1 Motivation ..... 23 3.2 Nondeterminism ..... 24 3.3 Universal and Alternating Automata ..... 27 3.4 Back to Word Subtraction ..... 27
4 Beyond Regular Languages 35 4.1 Motivation ..... 35 4.2 Context-Free Grammars ..... 35 4.3 Pumping Lemma for Context-Free Languages ..... 39 4.4 Closure Properties of Context-Free Languages ..... 43 4.5 Back to Word Subtraction ..... 44
5 Variants 51 5.1 Prefix and Suffix Removal ..... 51 5.2 Infix Removal and Merging ..... 54
6 Advanced Topics 56 6.1 Misère Play ..... 56 6.2 Reflexivity ..... 59 6.3 Realizability ..... 61 6.4 Decidability ..... 63
7 Research Background and Further Directions 69
1 Word Subtraction Games
In this note, let and denote the set of all non-negative integers and the set of all positive integers, respectively. For a set , let denote the cardinality of .
1.1 Combinatorial Games
Combinatorial game theory studies a broad class of two-player games in which the players move alternately, all information is available to both players, and no chance moves are involved. In this note, we mainly focus on a class of combinatorial games satisfying the following assumptions:
-
Impartial: The available moves from a position depend only on the position itself and not on whose turn it is.
-
Loop-free: Every play eventually terminates after finitely many moves. Games that do not satisfy this assumption are called loopy.
-
Finite-option: Every position has only finitely many available moves. A game that is both loop-free and finite-option is often called short.
-
Normal-play: The player making the last move wins. Equivalently, the player who has no legal move loses. In contrast, under the misère convention, the player who has no legal move wins.
A position that can be reached from a position by a single legal move is called an option of . A position with no legal moves is called a terminal position. Under the normal-play convention, the player to move at a terminal position loses.
Example 1.1 (Subtraction Games). A classical example of a combinatorial game is the subtraction game. Let be a set of positive integers. The game is played as follows. A position consists of a single heap (or pile) of stones, represented by a nonnegative integer , where denotes the number of stones in the heap. Starting from an initial heap, the two players alternately remove stones from the heap, where and , with denoting the current number of stones.
For example, if , then each player can remove either one or two stones on each turn. Starting from a heap of five stones, one possible play is
where the first player removes two stones, the second player also removes two stones, and finally the first player removes the last remaining stone. Under the normal-play convention, the first player wins because they make the last move. Representing each stone by a symbol , the same play can be visualized as
where denotes the empty heap, namely the position with no remaining stones.
One of the most fundamental notions in combinatorial game theory is the classification of positions into -positions and -positions. An -position is a position from which the player to move has a winning strategy, regardless of how the opponent plays. A -position is a position from which the opponent has such a strategy. Here, stands for Next and for Previous: after a move has been made, the opponent of the player to move is the player who made the previous move. These terms apply to initial positions as well. For impartial, short, normal-play games, the following recursive characterization holds:
Proposition 1.2 (Partition Theorem). For an impartial short normal-play game,
-
a position is a -position if and only if all of its options are -positions, and
-
a position is an -position if and only if it has at least one option that is a -position.
In particular, the set of positions is partitioned into -positions and -positions.
Every terminal position is a -position, since the player to move has no legal move and therefore loses. For any fixed starting position, there are only finitely many possible plays because each position has only finitely many options and no infinite play is possible. Thus, we can classify the starting position by working backwards from the terminal positions and applying the rules above. The game can have infinitely many positions in total, but the classification of any particular position requires only finitely many steps.
Example 1.3. Let us return to Subtraction({1,2}) in Example 1.1. We first observe that position 0 is a terminal position, and hence it is a -position. The positions 1 and 2 are -positions because the next player can move directly to the -position 0. Next, both options from 3 are -positions, and hence 3 is a -position. Continuing this procedure, we observe that a position is a -position if and only if is a multiple of 3. Indeed, every legal move from a multiple of 3 leads to a number that is not a multiple of 3, while from any other position one can reach a multiple of 3 by removing one or two stones.
The classification distinguishes only between winning and losing positions. We can obtain more information by assigning a nonnegative integer, called the Grundy number, to each position. Grundy numbers play a central role in the theory of normal-play impartial games. Because they are not needed for the main development of this note, we do not explore them in detail here. For a general introduction to combinatorial game theory, including Grundy numbers, see, for example, Albert, Nowakowski, and Wolfe [2] and Siegel [20].
The games studied in this note generalize subtraction games from integers to words. To illustrate the basic idea, consider a row of stones of two types, labeled and . A position is represented by the sequence of these labels. Suppose that, on each turn, a player can remove , , or from the right end of the sequence, whenever the sequence ends with the chosen word. For example, one possible play is
Although this rule is easy to describe informally, studying such games systematically requires a mathematical framework for words and sets of words. The next subsection introduces the basic notions of formal language theory, which provides such a framework.
1.2 Words and Languages
A set of symbols is called an alphabet. The elements of an alphabet are called letters. For example, is an alphabet consisting of two letters and . Throughout this note, we assume that alphabets are finite and nonempty. A word (or string) over is a finite sequence of letters from . For example, is a word of length 5 over the alphabet . We usually omit commas and parentheses and write this word simply as abbaa. The length of a word is denoted as . The empty word, denoted by , is the unique word of length 0. The set of all words over , including the empty word , is denoted by . The concatenation of two words and , denoted by , is obtained by writing immediately after . For example, the concatenation of and is abbaa. The order matters: in general, . For every , we have . Because concatenation is associative, forms a monoid with as its identity element, and this monoid is called the free monoid on .¹
¹Some of the terminology and additional remarks concerning monoids and monoid actions are included mainly to help readers with a background in algebra. These remarks are not essential for following the main discussion, and readers who are not familiar with the terminology can skip them.
A subset of is called a language over . In other words, a language is a set of words over . The concatenation of words naturally extends to an operation on languages. For two languages , their concatenation is defined by
We often identify a word with the singleton language . For example, and stand for and , respectively. For a language and a nonnegative integer , we write for the -fold concatenation of , with the convention . Equivalently, for every . For a word , we similarly write
with . The Kleene star of a language is defined by
Thus, consists of all words obtained by concatenating zero or more words from ; in particular, it always contains . Equivalently, is the smallest submonoid of containing . Similarly, the positive closure (or Kleene plus) of is defined by
Thus, consists of all words obtained by concatenating one or more words from . In particular, for an alphabet . For a language , its complement is taken relative to and is denoted by
Example 1.4. The following examples illustrate languages over :
-
is the language consisting only of the empty word. It is different from the empty language .
-
is the full language, consisting of all words over , including the empty word.
-
is the finite language consisting of three words , and .
-
is the language of even length words.
-
is the language of words that either start with and have even length, or start with and have odd length.
-
is the language of all words formed by an arbitrary number of 's followed by an arbitrary number of 's.
-
is the language of all words containing as a consecutive pair of letters. This language is the complement of : a word contains no such pair if and only if all its 's precede all its 's.
-
is the language of all words formed by some number of 's followed by the same number of 's.
Let be a word. A word is called a prefix of if there exists a word such that . If , that is, if , then is also called a proper prefix of . For example, , and are prefixes of . In this case, , and are proper prefixes. Similarly, a word is called a suffix of if there exists a word such that . A word is called a factor (or an infix) of if there exist words such that . A suffix or factor of is called proper if it is different from itself. Note that both and are prefixes, suffixes, and factors of .
1.3 Word Subtraction
We are now ready to give the formal definition of a word subtraction game.
Definition 1.5 (Word Subtraction Games). Let be a language over an alphabet such that . We call the subtraction set. The word subtraction game WordSubtraction() is the normal-play game in which each player removes a suffix belonging to from the current word. More formally, a position is a word over , and a move from a word to a word is legal if
for some .
The game is impartial because the legal moves depend only on the current word. It is also short. Indeed, every word has only finitely many suffixes, so every position has finitely many options. Moreover, since , every move strictly decreases the length of the current word, and hence no infinite play is possible. A word has a legal move if and only if it has a suffix belonging to , or equivalently, if it belongs to . Thus, the language of terminal positions is .
Example 1.6. Let and . Then, WordSubtraction(S) is the game introduced informally in Section 1.1: A position is represented by a word over , and each player alternately removes ‘a’, ‘b’, or ‘aa’ from the right end of the position.
Example 1.7. Let and . Then, WordSubtraction(S) is the game in which a player can remove any nonempty suffix consisting of an arbitrary number of 's followed by an arbitrary number of 's. One possible play is given by
In this example, the empty word is the only terminal position. More generally, is the unique terminal position if and only if . Indeed, if every letter belongs to , then every nonempty word has a legal move obtained by removing its last letter. Conversely, if some letter does not belong to , then the one-letter word is a terminal position.
Example 1.8. If is unary, that is, consists of only one letter , then WordSubtraction(S) is equivalent to Subtraction(S') where
For example, WordSubtraction( ) is equivalent to Subtraction( ).
Note that the sets of - and -positions are also languages over . We denote these languages by and , respectively. By the Partition Theorem, these languages satisfy
Moreover, a word is an -position if and only if it can be written as , where is a -position and . Thus,
The central theme of this note is to understand the relationship between the subtraction set S and the resulting - and -position languages. In particular, we ask the following question:
In this example, the set of -positions is . More generally, the first author has recently shown that, whenever is closed under taking nonempty prefixes, the set of -positions is . Several subtraction sets considered later in this note also satisfy this condition. We leave a detailed discussion for another occasion.
For a given class of languages, what can we say about and when ?
In this note, we mainly consider word subtraction games in which suffixes are removed. A prefix-removal version can also be defined, but it is essentially equivalent to the suffix-removal version: reversing every position and every word in the subtraction set gives a direct correspondence between the two games. Moreover, many standard language classes are closed under reversal. Thus, for our main purpose of studying how the language class of the subtraction set is related to those of the resulting and -position languages, there is little essential difference between prefix and suffix removal. Therefore, we take suffix removal as our basic convention.
Exercises
Exercise 1.1. Let . Give a brief description of each of the following languages:
◇
Exercise 1.2. Let . Determine whether is a -position or an -position in WordSubtraction with .
◇
Exercise 1.3. Let and consider WordSubtraction with .
-
Verify that is a -position.
-
Verify that is a -position.
-
Prove that a word is a -position if and only if . (Hint: Any word that does not contain as a factor belongs to .)
◇
Exercise 1.4. Let and . Use the Partition Theorem to show that .
◇
Exercise 1.5*. Let be any language with , and let
Show that
(Hint: Every position from which a suffix in can be removed is already an -position of WordSubtraction. Consider how the additional moves affect the two conditions in the Partition Theorem.)
Together with the previous exercise, this shows that
for every language . The -position language is fixed and simple: it is regular, in the terminology introduced in the next section. Nevertheless, the subtraction set can be arbitrarily complex, depending on . Thus, the simplicity of a -position language alone does not imply simplicity of the subtraction set.
◇
Exercise 1.6. Let . Find an infinite subtraction set such that there is a constant for which every position has at most options.
Exercise 1.7. A language is called suffix-free if no word in is a proper suffix of another word in . For example, with is suffix-free. Prove that is suffix-free if and only if every position in WordSubtraction() has at most one option.
Exercise 1.8*. Let be an alphabet. For a language , the value
is the proportion of words of length that belong to . Equivalently, it is the probability that a uniformly chosen word of length belongs to . We define the density of by
provided that the limit exists. Thus, the density measures the limiting average of these proportions over word lengths. For example, the language of even-length words has density 1/2. Note that this limit need not exist for every language. For more details on the density of languages, see, e.g., Section III.6 of [18].
Now let satisfy . For each , put
-
Show that for every .
-
Show that
for every . Hence, if exists, then .
Therefore, in this density-based sense, the first player is at no disadvantage when .
2 Finite Subtraction Sets
2.1 Motivation
In this section, we study word subtraction games with finite subtraction sets. For ordinary subtraction games, it is well known that when the subtraction set is finite, the set of -positions is ultimately periodic (see, e.g., Theorem 2.4 in Chapter IV of [20]). A similar phenomenon occurs for word subtraction games: for a finite subtraction set , the language has a certain form of “periodicity.” However, there is an important difference. In word subtraction games, positions are words rather than nonnegative integers, and their outcomes can depend on the arrangement of letters, not just on their length. What might play the role of ultimate periodicity in this setting? Finite automata and regular languages provide a natural framework for answering this question. Before introducing these notions formally, let us first examine the concrete example .
For a fixed subtraction set , we introduce a useful notation called the pattern. For a word , we record the status of each prefix by placing a or symbol at each boundary between letters, including the beginning and the end of the word. More precisely, for a word with , its pattern, denoted by , is the sequence
where
for each . Note that because is always a -position.
Let us see how the pattern is computed in a concrete example. Consider the subtraction set and the word . Since the pattern is computed from left to right, let us start with . Next, the pattern of is
because the only option from is , which is a -position, as indicated by the last entry of . Hence is an -position. Next,
The options from are and , whose statuses are and , respectively. Because a move to the -position is possible, is an -position. We then obtain
The only option from is , which is an -position. Thus, is a -position. On the other hand, we have
since has as an option, and is a -position. Finally, we have
because the options from are and , and is a -position.
The key observation is that only a short final portion of the pattern is needed to compute the next status. Let with , and suppose that a new letter is appended to . Removing the final letter is always legal, and it leaves the prefix with status . The only other possible move is to remove . This move is legal precisely when , and it leaves the prefix with status . Thus, together with the new letter , the last three entries
of determine . After reading , we retain
Together with the next letter , this information is sufficient to determine the status of . The initial case is handled separately: the empty word has pattern , and either first letter produces an -position.
This observation can be illustrated as follows:
This figure shows that, when a letter is appended to the right of a word whose pattern ends with , the resulting word has a pattern ending with . Notice that there are at most
possible triples of the form
Together with the initial state , these triples give only finitely many possible states. In fact, for , the status of a word can be determined by the following finite-state diagram:

Figure 1: A finite-state diagram for WordSubtraction({a,b,aa}).
The diagram should be read as follows. Let be the word under consideration. Starting from the state in the upper left, follow the edges labeled in order. If the final state is marked with a double border, then is an -position; otherwise, is a -position. For example, when the input is , we start at and successively visit
and the corresponding run is
Because the final state is marked with a double border, we conclude that is an -position.
The finite-state diagram we have just constructed is, in fact, a finite automaton. Although we have considered only the case , the same idea works for every nonempty finite subtraction set . Let be the maximum length of a word in . To determine the status after appending a new letter, it suffices to remember the last entries of the current pattern, or the entire pattern if it is shorter. Indeed, this information identifies every removable suffix of the new word and the status of the position left after its removal. Because the alphabet is finite, only finitely many such patterns are possible. We can therefore construct a finite-state diagram that determines whether a given word is a - or an -position. This observation will be formalized in Theorem 2.9.
We will now introduce finite automata more formally and examine some of their basic properties. Also, we will explain how regular languages generalize the periodicity found in ordinary subtraction games.
2.2 Finite Automata
We have seen that, for a finite subtraction set, the status of a word can be determined by reading it from left to right and updating a record with only finitely many possible states. This naturally leads us to the notion of a finite automaton. A finite automaton is a machine that classifies words using finitely many states. As illustrated in Figure 1, it can be represented by a directed graph whose edges are labeled by letters from an alphabet. One state is distinguished as the initial state, and zero or more states are designated as accepting states. Starting from the initial state, the automaton reads the input word from left to right, following the edge labeled by each successive letter. After the entire word has been read, the word is accepted if the automaton is in an accepting state, and rejected otherwise. The formal definition is as follows:
Definition 2.1 (Deterministic Finite Automata). A deterministic finite automaton (DFA for short) is a 5-tuple
where
-
is a finite set of states,
-
is an alphabet,
-
is the transition function,
-
is the initial state, and
-
is the set of accepting states (or final states).
For a word , its run on is the sequence of states
where is the initial state and
for each . The run can also be written as
We say that accepts if , and rejects otherwise. In particular, is accepted if and only if . The language
is called the language recognized (or accepted) by .
The word “deterministic” means that, for each input word, there is a unique run on the automaton. Indeed, from any state and for each input letter , there is exactly one possible next state . Thus, there is exactly one run for every input word.
Note that the transition function naturally extends from letters to words. Define
recursively by
for each , , and . By definition,
holds. Moreover,
for all and . In other words, reading is the same as first reading and then reading . Together with , this identity says that defines a right action of the free monoid on .
As illustrated in Figure 1, a finite automaton can be visualized as a directed graph: the states are vertices, and each transition is represented by an edge from to labeled by . The initial state is usually indicated by an arrow coming from nowhere, while accepting states are distinguished by double circles.
Example 2.2. The following examples are DFAs with :
• The finite language
is recognized by the DFA defined as follows:

More generally, every finite language is recognized by some DFA.
• The language
of even length words is recognized by the DFA defined as follows:

More generally, for every integer , the language is recognized by a DFA that keeps track of the input length modulo .
- The language
is recognized by the DFA defined as follows:

- The language
is recognized by the DFA defined as follows:

On the other hand, the complement of ,
is recognized by the DFA defined as follows:

More generally, suppose that a language is recognized by a DFA
Then, its complement is recognized by the DFA
In other words, we can obtain a DFA for the complement by switching the accepting and rejecting states.
As these examples illustrate, DFAs can recognize languages of many different forms. On the other hand, as we will see later, there exist languages that cannot be recognized by any DFA. This motivates the following definition.
Definition 2.3 (Regular Languages). A language is called regular if there exists a deterministic finite automaton such that .
For example, the languages , and considered above are all regular. Moreover, as we saw earlier, the language of -positions of WordSubtraction({a, b, aa}) can be described by a finite automaton, and hence is regular as well.
Regular languages also have a number of useful closure properties. For example, as observed at the end of Example 2.2, the complement of a regular language is again regular. (Therefore, is also regular.) More generally, regular languages are closed under union, intersection, concatenation, and Kleene star, as well as under images and inverse images of homomorphisms between free monoids. These properties make regular languages particularly convenient to work with, and we will return to some of them when they become relevant.
2.3 Periodic Structure of Regular Languages
We have seen that the set of -positions of WordSubtraction({a, b, aa}) is regular. What does this tell us about these positions? In particular, how is regularity related to the periodicity found in ordinary subtraction games?
In this section, we look at two remarkable phenomena of regular languages. The first is the so-called pumping lemma, which shows that sufficiently long words in a regular language contain a factor that can be repeated any number of times. The second is semilinearity, which appears when we forget the order of the letters in a word and record only the number of occurrences of each letter.
Let us first look at the pumping lemma. Suppose that is regular, and hence is recognized by some DFA
Let . Consider an accepting run of a word :
By the assumption that , the final state is accepting.
Now suppose that, during this run, reads a factor of whose length is at least . In other words, the run has the form
with some where . By the assumption , the corresponding segment of the run contains at least state occurrences:
On the other hand, there are only states in total. Thus, by the pigeonhole principle, two of these states must be equal. That is, there exist indices such that .
Let be the factor of read between these two occurrences. Then the run contains a loop of the form
Thus, the accepting run can be written as
with some .
The important point is that this loop can be removed, or repeated any number of times, without changing the state reached after reading . Indeed, both
and
are valid runs. In every case, the run still starts at and ends at the accepting state . Therefore, for every ,
holds. This is precisely the conclusion of the pumping lemma.
Theorem 2.4 (Pumping Lemma for Regular Languages). Let be a regular language. Then there exists a positive integer such that, whenever for some with , there exist satisfying
• ,
• , and
• for every .
It is worth noting what the pumping lemma tells us intuitively. If is finite, choose a positive integer larger than the length of every word in . Then the condition in the pumping lemma is automatically satisfied because there is no word with .
On the other hand, if is infinite, the pumping lemma says that must contain a language of the form
for some fixed words with . Roughly speaking, every infinite regular language contains an analogue of an infinite arithmetic progression. For example, we have the following:
Proposition 2.5. The language
over {a} is not regular.
Proof. Suppose, for contradiction, that is regular. Then there exists a constant as given by the pumping lemma.
Let be any prime number greater than , and consider the word
Because and , the pumping lemma gives a factorization
with such that
for every . Since all words are over the unary alphabet, there exist nonnegative integers such that
where
and . Hence
However, taking gives
which is a composite number because and . This contradicts the conclusion that every word belongs to . Therefore, is not regular.
Similarly, the languages , , and over the unary alphabet are not regular. In fact, under the identification of with , the regular languages over are exactly the ultimately periodic subsets of . These observations can be described more elegantly using the notions of Parikh images and semilinear sets. Before turning to these notions, let us take a moment to see another use of the pumping lemma.
We have focused on the linear periodicity inherent in regular languages. But there is another important limitation: a DFA has only finitely many states, so it cannot remember arbitrarily large counts. A standard example is the language
which is not regular. To see the intuition, consider feeding a word of the form
into a DFA from left to right. In order to accept exactly those words for which m = n, the automaton must remember the length of the first block of a's. After reading the separator b, this information must still be available so that the automaton can determine whether the final block contains exactly the same number of a's. However, the length of the first block can be 100, 1000, or arbitrarily large. A DFA has only finitely many states, and therefore cannot keep track of all these possibilities. The pumping lemma makes this intuition precise:
Proposition 2.6. The language
over is not regular.
Proof. Suppose, for contradiction, that is regular. Then there exists a constant as given by the pumping lemma. Let , , and . Because and , the pumping lemma gives a factorization with such that
for every . Taking i = 2, the pumping lemma gives
However, by , the two blocks of 's have different lengths. Thus, this word does not belong to , a contradiction. Therefore, is not regular.
Similarly, the language of nonempty palindromes
is also not regular. Here, denotes the word obtained by writing the letters of in reverse order. For example, .
Proposition 2.7. The language PAL is not regular.
Proof. Suppose, for contradiction, that PAL is regular. Then there exists a constant as given by the pumping lemma. Let , , and . Note that because is a palindrome. Thus, for the same reason as in Proposition 2.6, the pumping lemma implies that
with some . However, this word is not a palindrome, which is a contradiction.
Finally, let us briefly discuss the semilinearity of regular languages. We begin with the Parikh mapping
defined as
for each , where denotes the number of occurrences of the letter in . Thus, the Parikh mapping forgets the order of the letters in a word and records only how many times each letter occurs. For example,
with . As with any mapping, we can consider the image of a language under the Parikh mapping,
which is called the Parikh image of . For example,
and
Now, it turns out that the Parikh image of a regular language has a particularly simple form. A set is called linear if there exist vectors with such that
For example,
is a linear set. A finite union of linear sets is called a semilinear set. For example, is a semilinear set because it is the union of linear sets , and . Then, we have the following fundamental result.
Theorem 2.8 (Semilinearity of Regular Languages). The Parikh image of every regular language is a semilinear set.
We omit the proof here. The theorem gives another perspective on the periodic structure of regular languages: after forgetting the order of letters, the resulting set of vectors is a finite union of linear sets.
It is worth noting that neither the pumping lemma nor semilinearity gives a sufficient condition for regularity. They only provide necessary conditions. For example, the Parikh image of
is
which is a semilinear set. Nevertheless, as we saw above, is not regular.
2.4 Back to Word Subtraction
We have introduced the basic notions of DFAs and regular languages. Let us return to word subtraction games and summarize what we have learned in this section.
As we briefly saw in Section 2.1, when the subtraction set is finite, the set of -positions of WordSubtraction() can be recognized by a DFA, and hence is a regular language. The basic idea is exactly the same as in the example from Section 2.1. When is finite, the pattern of a word can be updated by keeping track of only finitely much information. More precisely, for nonempty , let
Together with the next input letter, the last entries of the pattern, or the entire pattern if it is shorter, determine the next status. Thus, only finitely many states are needed:
Theorem 2.9 (Regularity for Finite Subtraction Sets). Let be an alphabet and be a finite language. Then, the -position language of WordSubtraction() is regular.
Proof. If , then , which is regular. Assume that , and let
We construct a DFA
as follows. Let
For a state and an input letter , we define in the following way. First, let
Then, we append and to . If the resulting sequence has more than entries, we delete its first two entries. The resulting state is . Finally, let
We claim that, after reading a word , the state of is the final entries of , or the entire pattern if it is shorter. We prove this by induction on .
For , the claim holds because the initial state is . Now suppose that the claim holds for , and let . Every removable suffix of has length at most . Hence, the stored pattern, together with the new letter , contains both the letters of every possible removable suffix and the status of the prefix left after its removal. By the Partition Theorem, the rule defining the new status gives exactly the status of . Appending the new letter and its status, and deleting the first two entries if necessary, gives precisely the required final portion of . This proves the claim.
Consequently, the state reached after reading belongs to if and only if is an -position. Thus, , and is regular.
Because the complement of a regular language is again regular, we immediately obtain the following corollary.
Corollary 2.10. Let be an alphabet and be a finite language. Then, the -position language of WordSubtraction is regular.
These results generalize the familiar fact that, in an ordinary subtraction game with a finite subtraction set, the set of -positions is ultimately periodic. Indeed, ordinary subtraction games can be viewed as word subtraction games over a unary alphabet. Over a unary alphabet, a word is completely determined by its length. Then, the Parikh image of a regular language is a semilinear subset of , and every such set is ultimately periodic. Thus, the result above recovers the familiar ultimate periodicity of -positions in ordinary subtraction games with finite subtraction sets.
We have restricted our discussion in this section to the binary classification. Let us briefly note that the same idea extends to Grundy numbers as well. When the subtraction set is finite, every position has at most options. Consequently, its Grundy number is at most , so only finitely many distinct Grundy numbers can occur. Thus, if we replace each entry in the pattern by the corresponding Grundy number, while retaining the letters, the same finite-state construction applies. Therefore, we can use a finite automaton with a nonnegative integer attached to each state as its output. Such an automaton is often called a Moore machine [13]. In particular, for every Grundy number , the language
is again a regular language.
Exercises
Exercise 2.1. Let . Construct a DFA that recognizes each of the following languages:
◇
Exercise 2.2. Let . Use the pumping lemma to prove that
is not regular.
◇
Exercise 2.3*. Let . Use the pumping lemma to prove that
is not regular. Note that there are several variants of the pumping lemma for regular languages. The version used in this note is not the most standard one, but it can be more convenient in practice. If you know another version, try using it to solve this exercise and compare the resulting proofs. ◇
Exercise 2.4. Let . Compute the Parikh images of the following regular languages:
◇
Exercise 2.5. Consider the DFA in Figure 1. Verify that, for every state , the state has as its last entry. What is the game-theoretic interpretation of this property? ◇
Exercise 2.6. Choose a nonempty finite language . Then construct a DFA recognizing by following the construction in Theorem 2.9. ◇
Exercise 2.7*. If you are familiar with Grundy numbers, construct an automaton that computes the Grundy number of each word in WordSubtraction(S) for a finite subtraction set . The basic idea was mentioned at the end of Section 2.4. ◇
Open Problems
Problem 2.1 (Can we construct a polynomial-size DFA for ?). Fix an alphabet . For a nonempty finite subtraction set , let
The construction in Theorem 2.9 uses
states, which grows exponentially with . How much can this bound be improved? In particular, is there a polynomial , independent of , such that every such language can be recognized by a DFA with at most states? A related question is whether a polynomial bound is possible in terms of the total length
of the subtraction words.
The construction can contain both unreachable states and states that can be merged without changing the recognized language. For example, when , states such as are not needed, as shown in Figure 1. Moreover, even the DFA in Figure 1 contains redundant information and can be reduced to the equivalent DFA with only three states:

The unary case, corresponding to ordinary subtraction games, is a natural starting point. We have not yet investigated whether existing results on subtraction games settle this question. ◇
3 Regular Subtraction Sets
3.1 Motivation
In the previous section, we have seen that, when the subtraction set is finite, the - and -position languages of WordSubtraction() are regular. Recall that every finite language is itself regular. In other words, the subtraction set can be described by a finite automaton. This naturally leads to the next question: what happens when is an arbitrary regular language?
The answer is perhaps surprising: even when is an arbitrary regular language, the -position language is still regular. However, the construction in the previous section does not directly apply. That construction remembers a final portion of the pattern whose length depends on the maximum length of a word in . When is infinite, there is no such maximum, so we need a different way to record the relevant information. The key idea is to keep track of several possible states of an automaton recognizing . This leads us to the notion of nondeterminism. The approach developed in this section was originally suggested by Professor Yoshiaki Takata of Kochi University of Technology.
Before going into the general construction, let us first develop some intuition through a concrete example. Consider the subtraction set
with , that is, the language of words that either start with and have even length, or start with and have odd length.
As we saw in Example 2.2, this language is recognized by the following DFA:

Figure 2: A DFA recognizing .
Let us think about what the - and -position languages look like in this case. First, every word in is an -position because the player to move can remove the entire word and leave . Thus, every word accepted by the original DFA is an -position.
There is another source of -positions. Suppose that is a -position and . Then the concatenation is necessarily an -position because we can remove the suffix and reach the -position . How can we reproduce this behavior using an automaton? Consider, for example, . Neither of its nonempty suffixes, and , belongs to , so is a terminal position and hence a -position. In the original DFA, reaches the rejecting state with the run
To detect words obtained by appending an element of to , we would like to start reading again from after reaching this -position. As a first attempt, let us replace the transition by . The modified automaton then returns to after reading . We call this return a reset:

For example, on input , the modified automaton follows the run
and accepts . This agrees with the game: removing the suffix leaves the -position . Moreover, , so this modification detects an -position that the original DFA does not accept.
However, replacing the transition also loses information. The word belongs to and is therefore an -position, but the modified automaton follows
and rejects it. Thus, we want to retain both the original transition and the reset transition . The original transition allows the automaton to continue checking the word being read, while the reset transition starts a new check from the -prefix . This suggests allowing more than one possible run for the same input word, and accepting the word if at least one run ends in an accepting state. This is the basic idea of a nondeterministic finite automaton.
One difficulty remains: a reset should be allowed only after a -position. So far, we have identified as such a position by analyzing the game directly. In general, how can the automaton determine when a reset is appropriate? We will return to this question after introducing nondeterministic finite automata and the idea of keeping track of all possible current states.
3.2 Nondeterminism
We now introduce the nondeterministic finite automaton (NFA) as a variant of the DFA. In a DFA, the current state and the next input letter uniquely determine the next state. In an NFA, there can be several possible next states, or none at all. We therefore use a transition function
where denotes the set of all subsets of . Here, is the set of possible next states after reading in state . As a result, an NFA can have more than one run on the same input word.
Definition 3.1 (Nondeterministic Finite Automata). A nondeterministic finite automaton (NFA for short) is a 5-tuple
where
-
is a finite set of states,
-
is an alphabet,
• is the transition function,
• is the initial state, and
• is the set of accepting states.
A sequence of states
is a run of a word if
for each . We say that accepts if there exists a run of such that . The language
is called the language recognized by N.
In other words, an NFA can have several possible next states for a given state and input letter. If there are several possible runs of an input word, the word is accepted as long as at least one of them ends in an accepting state. Note that can also be empty, so there can be no possible transition for a given state and input letter. A run must read the entire input word; reaching an accepting state before the input ends does not by itself imply acceptance.
Example 3.2. Let . The following NFA recognizes the language :

For example, consider the word . As in a DFA, the automaton starts in the initial state . There are two valid runs of :
and
The second run ends in the accepting state , so aba is accepted.
On the other hand, consider the word . There are two valid runs of :
and
Neither of them ends in , and hence aab is rejected.
Finally, consider the word abaa. After reading aba, the possible states are and , as shown above. On the final , the run ending at continues to , but the run ending at cannot continue because . Thus, the only run of the entire word is
so abaa is rejected.
An NFA is a generalization of a DFA because every DFA can be regarded as a special kind of NFA in which there is exactly one possible transition for every state and input letter. At first sight, this may suggest that NFAs are more powerful than DFAs. However, this is not the case. NFAs have exactly the same expressive power as DFAs: they still recognize only regular languages.
Theorem 3.3. A language is regular if and only if it is recognized by some NFA.
Proof. Recall that a language is regular if it is recognized by some DFA. Because every DFA is a special kind of NFA, the only if direction is immediate.
For the converse, let us start with an arbitrary NFA and construct a DFA that recognizes the same language. This construction is well known as the subset construction. The basic idea is to remember all possible current states at the same time. For example, consider the NFA in Example 3.2 and suppose that it is currently in state and reads the input letter b. There are then two possible next states, and . Thus, we simply remember the set
as a single state of the new automaton. More generally, each state of the new DFA represents a subset of . Because is finite, there are only possible subsets, so the new automaton still has only finitely many states. A subset should be an accepting state of the new automaton whenever contains an accepting state of the original NFA. Thus, a subset is accepting if and only if .
We now give the formal construction. Let be a given NFA. Define the DFA
by
for each and , and
Initially, the DFA records the singleton set . If it records all states reachable in the NFA after reading a word , then the union above records exactly all states reachable after reading . Thus, by induction on the input length, the DFA always records exactly the set of states reachable in the NFA. By the definition of , the two automata accept the same words.
Example 3.4. Applying the subset construction to the NFA in Example 3.2 yields the following DFA :

Note that, apart from the three states , , and in the upper left, all other states are unreachable from the initial state and can therefore be omitted. ■
Let us briefly return to the connection with word subtraction games. The acceptance condition of an NFA is closely related to the notion of an -position. Recall that a position is an -position if at least one of its options is a -position. This is analogous to an NFA accepting a word when at least one of its possible runs ends in an accepting state: in both cases, it is enough for one possible choice to succeed.
In fact, we will not use NFAs directly in our analysis of word subtraction games. What matters is the idea behind the subset construction: instead of choosing one possibility, we can keep track of all possible states at the same time. This idea will be the key to our construction for regular subtraction sets.
3.3 Universal and Alternating Automata
There is a natural variant of an NFA in which the existential acceptance condition is replaced by a universal one. A universal finite automaton (UFA) has the same structure as an NFA, but a word is accepted if and only if every run on that word ends in an accepting state. Thus, while an NFA requires at least one accepting run, a UFA requires every run to be accepting.
UFAs also recognize exactly the regular languages. Indeed, the subset construction works here as well. After reading a word , the constructed DFA records the set of all states that the UFA can reach by reading . For a UFA with accepting states , we simply declare a subset to be accepting when
In other words, all possible current states must be accepting. Thus, the same basic idea that turns an NFA into a DFA also shows that UFAs recognize only regular languages.
This gives a useful logical perspective on these automata. The acceptance condition of an NFA has an existential flavor:
The acceptance condition of a UFA has a universal flavor:
This leads to more general models known as Boolean automata [4] and alternating finite automata [6]. Informally, these models combine existential and universal choices during a computation: at some steps, the remaining input must be accepted from at least one of the possible next states; at others, it must be accepted from all of them. Despite this additional flexibility, alternating finite automata still recognize exactly the regular languages. We will not discuss these models further here.
The same distinction between existential and universal conditions appears in word subtraction games. A position is an -position if at least one of its options is a -position, whereas it is a -position if all of its options are -positions. These conditions are applied recursively, in a way similar to alternating computation. These viewpoints help to explain the construction in the next subsection, where we build a DFA for the position languages of a word subtraction game with a regular subtraction set.
3.4 Back to Word Subtraction
We now apply these ideas to word subtraction games with a regular subtraction set . Recall the two complementary ways to determine the outcome of a position: it is an -position if some option is a -position, and a -position if all options are -positions. These are the existential and universal viewpoints discussed above. Because every move removes a nonempty suffix, all options are shorter prefixes, so we can determine their outcomes before determining the outcome of the current word.
To implement this idea, take a DFA recognizing and read the input from left to right. At every prefix already identified as a -position, start a new run of this DFA, while retaining all existing runs. This includes the empty prefix, which is a -position. An accepting run then identifies a suffix in whose removal leaves a -position. Thus, if at least one run is accepting, the current word is an -position. If none is accepting, no move leads to a -position, so the current word is a -position. Figure 3 illustrates this process using the DFA from Section 3.1.

The newest run accepts . Removing from leaves the -position .
Figure 3: Tracking runs on input for .
Each row follows one run, with accepting states shown in blue. After reading , the only existing run is rejecting, so we start a second run. After reading , both existing runs are rejecting, so we start a third. These resets are marked by red dashed lines. At the end of , only the third run is accepting. It has read from the prefix , so removing this suffix leaves a -position. Thus is an -position.
We do not need to keep track of these runs separately: it is enough to record their current states, just as in the subset construction. Let be the set of current states of all the runs started so far, where is the state set of the DFA recognizing . For example, after reading and starting the third run, we have . Whenever contains no accepting state, we add the initial state to and start a new run. Otherwise, the current word is an -position, so no new run is started.
We first arrange that no transition of the original DFA returns to its initial state. This will allow us to identify resets in the construction below.
Lemma 3.5 (Non-Returning DFA). For every DFA , there is an equivalent DFA whose transitions never return to the initial state. More precisely, there is a DFA such that
and
for every and .
Proof. Let with a new distinct initial state . In addition, let
for each and , and let
No transition enters because every value of lies in . By the definition of , the two automata either both accept or both reject the empty word. For a nonempty word , where and , we have
Here, the middle equality holds because for every and . Because , the two automata accept exactly the same nonempty words. Therefore, .
In this note, we call a DFA with no transition returning to its initial state non-returning.
We now turn to the main result of this section. We will show that if is regular, then the -position language is also regular. To prove this, we start with a DFA recognizing and construct a new DFA recognizing . We first give the construction of .
Let
be a DFA recognizing . By Lemma 3.5, we can assume without loss of generality that is non-returning. Since , we have . We now define
as follows:
• ,
• for each and ,
and
• .
The construction is similar in spirit to the subset construction: the states of keep track of the information needed to detect both - and -positions simultaneously. In particular, the part highlighted in red is crucial. When the automaton detects a -position, that is, a word for which none of the possible runs reaches an accepting state, we apply the reset rule by adding to the state set.
The following two lemmas describe the key properties of this construction. The first lemma shows that an accepting run of can be traced through individual states of , using original transitions and occasional resets.
Lemma 3.6. Let be a non-returning DFA, and let denote the DFA obtained from by the construction above. If
is an accepting run of with and , then there is a sequence
such that
• for each ,
• for each , and
• .
Proof. Let us construct the sequence backwards. All the sets are nonempty because and the transition rule maps every nonempty set to a nonempty set. In addition, is an accepting state, that is, holds. Therefore, we can choose a state .
Now suppose that we have chosen satisfying the required conditions, and consider how to choose . If , we can choose arbitrarily from . Indeed, by the assumption that is non-returning, implies that the reset rule was used in the transition from to . Thus, for every , we have and .
On the other hand, suppose that . Because the reset rule adds only , the state must come from an original transition. Thus, we can choose such that
The definition of then gives
Repeating these steps backwards until we reach gives the desired sequence .
The second lemma concerns the role of the initial state . Recall that the original automaton A is non-returning. Thus, in the construction of , the current state set contains only if the reset rule has been applied. The following lemma shows that this happens precisely when the input word is rejected.
Lemma 3.7. Let be a non-returning DFA with , and let denote the DFA obtained from by the construction above. Then, it holds that
for each .
Proof. The case is clear because and . Let with and , and let .
Suppose that . By the assumption that is non-returning, the only way to have is for the reset rule to have been applied. That is, for all . Therefore,
holds, and thus, . This implies that .
Conversely, suppose that . Then, there exists such that by the definition of . Therefore,
holds, and thus, . This means that is accepted by .
We are now ready to prove the main theorem.
Theorem 3.8 (Regularity for Regular Subtraction Sets). Let be an alphabet and be a regular language. Then, the -position language of WordSubtraction() is regular.
Proof. Let be a non-returning DFA recognizing , and let be the DFA constructed above. We show that
holds with .
We use induction on the length of . For , the claim is immediate because and is a -position. Now let , and assume as the induction hypothesis that
for every proper prefix of .
If is an -position, then for some -position and some . Because , the word is a proper prefix of . By the induction hypothesis and Lemma 3.7,
The transition rule always retains the original transition: if , then
Applying this observation successively along , we obtain
Because , we have . Therefore, .
Conversely, assume that and consider its run
with . By Lemma 3.6, there are states and such that and for each . Let be the largest index such that . Since and , we have . Then, the sequence
is an accepting run of the original DFA . Indeed, for each , we have by the choice of . Because the only state that the reset rule can add is , the relation implies
for each . This implies that . In addition, by and Lemma 3.7. This means that is a -position by the induction hypothesis. Therefore, their concatenation is indeed an -position. Consequently, we can conclude that and is regular.
Example 3.9. Let us illustrate the construction for . That is, we construct from the non-returning DFA shown in Figure 2. In principle, the subset construction gives possible states. However, several of these states are unreachable from the initial state. We therefore restrict our attention to the four states that actually occur:
The initial state of is . Suppose that we read from . As in the usual subset construction, we move to because . Moreover, is an accepting state of , so is detected as an -position.
Now consider reading from . In this case, we move to . The original transition leads to the rejecting state , so the reset rule is applied and is added to the set of possible states. In terms of the game, this means that is detected as a -position.
Similarly, the reset rule is applied when we read or from . That is, . Thus, for example, both and are detected as -positions.
For the remaining transitions, no reset is needed. For example, . Indeed, although the transition from leads to the rejecting state , the transition from leads to the accepting state . Hence there is a possible run that reaches an accepting state, and the word is detected as an -position.
Continuing in this way, we obtain the following DFA :

This automaton shows that
and is its complement. In other words, a -position consists of an optional initial , followed by zero or more two-letter blocks, each beginning with .
Taking complements gives the corresponding result for -position languages.
Corollary 3.10. Let be an alphabet and be a regular language. Then, the -position language of WordSubtraction() is regular.
This result also has a direct consequence for ordinary subtraction games. If the subtraction set is ultimately periodic, then the sets of - and -positions are ultimately periodic as well. Indeed, under the identification of with , unary regular languages correspond exactly to ultimately periodic subsets of the nonnegative integers. This includes, in particular, finite and cofinite subtraction sets.
For readers familiar with Grundy numbers, we briefly explain how the same idea extends to them. This discussion is not needed for the later sections. Let denote the Grundy number of a position . For every fixed integer , we can construct a DFA recognizing
Starting with the DFA recognizing , we use tuples
as states. The set tracks runs of started at prefixes with Grundy number . Because the empty word has Grundy number 0, the initial state is
Suppose that the next input letter is . First, advance all tracked runs by setting
with . Then means that the current position has an option with Grundy number . By the mex rule, the Grundy number is the smallest nonnegative integer that does not occur among the Grundy numbers of its options. If there is an index with , let be the smallest such index; then the current Grundy number is . Otherwise, the current Grundy number exceeds , and we set . The next state is , where
Thus, we start a new run in the component corresponding to the current Grundy number, provided that this number is at most .
A tuple is declared accepting exactly when
for every . Because , adding does not change whether a component contains an accepting state. Therefore, the acceptance condition expresses precisely that the mex is . The interpretation of each is preserved after every letter, so induction on the input length shows that this DFA recognizes . Values larger than need not be distinguished, and the state space is finite. Hence, is regular.
Exercises
Exercise 3.1. Let . Construct an NFA with the specified number of states that recognizes each of the following languages:
-
with five states
-
with three states
-
with two states
-
with one state
◇
Exercise 3.2. The class of regular languages is closed under union. This fact can be proved using NFAs.
Let be regular languages. For each , let be a DFA recognizing , where and are disjoint. Construct an NFA with an initial state as follows:
and, for each ,
On states in and , let have the same transitions as and , respectively. Make every state in accepting, and make accepting if and only if or . Write down the construction of precisely, and prove that
holds.
◇
Exercise 3.3*. In Section 1, we claimed that there is little difference between defining word subtraction games by removing suffixes and defining them by removing prefixes. One reason is that many language classes, including the class of regular languages, are closed under reversal.
For a regular language , let . Prove that is also regular by the following steps: Let be a DFA recognizing . Construct an automaton by reversing the direction of every transition of , making the original initial state an accepting state, and making the original accepting states initial states. Finally, show that
Strictly speaking, need not be an NFA as defined above because its set of initial states need not contain exactly one state. Adapt the construction in the previous exercise to obtain an NFA with a single initial state that recognizes the same language.
Exercise 3.4. Choose a regular subtraction set . Construct a DFA recognizing by following the construction in Theorem 3.8, and remove its unreachable states. Check its answers on several short words directly from the game rules.
Open Problems
Problem 3.1 (When is the -position language a group language?). For ordinary subtraction games, one can ask which subtraction sets give a purely periodic sequence or Grundy sequence. Here, a sequence is called purely periodic if it is periodic from the beginning, that is, if it has no preperiod.
We omit the details here, but this question has a natural analogue for word subtraction games: for which subtraction sets is the -position language a group language? Here, a regular language is called a group language if its syntactic monoid is a group. Equivalently, in the minimal DFA for , the map
is a bijection for every . Over a unary alphabet, a regular language is a group language exactly when its membership sequence is purely periodic.
4 Beyond Regular Languages
4.1 Motivation
Theorem 3.8 shows that regular languages are, in a sense, closed under the operation of taking the -position language of a word subtraction game: starting from a regular subtraction set, we obtain a regular language again. Therefore, if we want to go beyond regular languages, we must first allow the subtraction set itself to go beyond regular languages.
But how far should we go? Although the definition of WordSubtraction() allows any language as a subtraction set, we would like to study rules that have finite descriptions. A natural next step is the class of context-free languages, which extends the regular languages and can be described by finite grammars.
Context-free languages can express some conditions that finite automata cannot. For example, the language
which requires the two blocks of 's to have the same length, is context-free but not regular. They also share some useful properties with regular languages. In particular, Parikh's theorem states that the Parikh image of every context-free language is semilinear [15].
Therefore, we can ask whether the regularity result from Section 3 extends to context-free languages: if is context-free, must also be context-free? In contrast to the case that is regular, the answer is no. In this section, we will study a context-free subtraction set whose -position language is not context-free.
The first concrete example of this phenomenon was discovered for the subtraction set
Thus, the game allows us to remove a nonempty suffix consisting only of 's, a nonempty suffix consisting only of 's, or a suffix containing the same number of 's and 's. Yushin Kusajima and Shunya Oguchi, both at Nagoya University, discovered that the set of -positions of this game is not context-free. They later found that the same phenomenon also occurs when
Of these two examples, we focus on the palindrome example, for which the proof is simpler. This example also shows that the -position language is not context-free. At the end of the section, we give a simpler example in which only the -position language is not context-free. Before analyzing these games, we introduce context-free grammars and develop the tools needed for the proofs: a pumping lemma and several closure properties.
4.2 Context-Free Grammars
Let us begin by introducing context-free languages. As regular languages can be described by finite automata, context-free languages can be described by context-free grammars (CFGs). To see how context-free languages extend the class of regular languages, we begin with three special classes of CFGs: regular grammars, right-linear grammars, and linear grammars.
Regular grammars provide a third way of looking at regular languages, alongside DFAs and NFAs. In fact, their underlying structure is essentially the same as that of NFAs. Let us first give the definition.
Definition 4.1 (Regular Grammars). A regular grammar is a 4-tuple where
-
is a finite set of nonterminal symbols. We usually write nonterminals using uppercase letters such as
-
is an alphabet disjoint from . Its elements are also called terminal symbols, or simply terminals. As before, we usually write terminals using lowercase letters such as
-
is a finite set of production rules, each of one of the following two forms:
where and .
- is the initial symbol.
We now explain how a grammar generates words. If is a production rule, we can replace an occurrence of by , leaving the surrounding symbols unchanged. More precisely, for , we write
and call this a one-step derivation. A sequence of zero or more one-step derivations
with is called a derivation. We sometimes also write when such a derivation exists.
A word is said to be generated by if there is a derivation
In other words, starting from the initial symbol , we repeatedly apply production rules until we obtain the terminal word . The set
is called the language generated by .
Example 4.2. The regular grammar with
generates the language
For example,
and
are derivations of this grammar.
As mentioned earlier, regular grammars are essentially the same as NFAs. For example, in the grammar above, replace the nonterminals by states , respectively. Then interpret a production such as as the transition . Under this correspondence, the second derivation in Example 4.2 corresponds directly to the run
In addition, the production means that a derivation is allowed to stop at . Therefore, we can declare the corresponding state to be accepting. By this construction, we obtain exactly the same NFA as in Example 3.2.
More generally, for a given regular grammar , we can construct an equivalent NFA by letting
for each and , and
Conversely, every NFA can be translated into an equivalent regular grammar by reversing this construction. Therefore, a language is generated by a regular grammar if and only if it is a regular language.
We can generalize the definition slightly by allowing production rules of the form
where and . Such a grammar is called a right-linear grammar. For example, the grammar has derivations such as
This grammar generates the language consisting of all words of even length.
Despite this more general form of the production rules, right-linear grammars still generate only regular languages. Intuitively, a rule that produces several letters at once can be replaced by a sequence of rules that produces them one letter at a time. For example, a rule can be simulated by introducing a new nonterminal and replacing the original rule with
Repeating this construction allows every right-linear grammar to be converted into an equivalent regular grammar. Strictly speaking, one must also deal with rules of the form , which are called unit rules. This requires a small additional argument, but nothing fundamentally new is involved, so we will not go into the details here.
So far, regular grammars and right-linear grammars generate words by successively producing terminal symbols to the left of the remaining nonterminal. Suppose that we also allow terminals to be produced on its right. Then, we obtain a more general class of grammars that can generate nonregular languages.
Definition 4.3 (Linear Grammars). A linear grammar (or linear context-free grammar) is a 4-tuple where
-
is a finite set of nonterminal symbols.
-
is an alphabet disjoint from .
-
is a finite set of production rules, each of one of the following two forms:
where and .
- is the initial symbol.
Example 4.4. The linear grammar with
generates the language
For example,
and
are derivations of this grammar.
Example 4.5. The linear grammar with
generates . The rules and give odd-length palindromes, while and give even-length palindromes. For example,
and
are derivations of this grammar.
Recall from Propositions 2.6 and 2.7 that these languages are not regular. Therefore, the class of languages generated by linear grammars is strictly larger than the class of regular languages.
We now allow a production rule to create several nonterminals at once. This gives a context-free grammar, in which the right-hand side of a rule can be any word over . For example, a rule creates two nonterminals that can be rewritten independently.
Definition 4.6 (Context-Free Grammars). A context-free grammar (CFG for short) is a 4-tuple where
-
is a finite set of nonterminal symbols.
-
is an alphabet disjoint from .
-
is a finite set of production rules of the form where and .
-
is the initial symbol.
The name “context-free” means that a rule can be applied to any occurrence of , regardless of the symbols surrounding it.
Example 4.7. The CFG with
generates the language
For example,
and
For readers familiar with disjunctive sums of games, the independent rewriting of different nonterminals is similar to making a move in one component while leaving the others unchanged.
are derivations of this grammar. In these examples, we always rewrite the leftmost nonterminal, but this is not required. For example, we can change the rewriting order in the second derivation as follows:
The original derivation and this one are represented by the same derivation tree, as we will see in the next subsection.
Definition 4.8 (Context-Free Languages). A language is called a context-free language (CFL for short) if there exists a context-free grammar such that .
It is known that the context-free language cannot be generated by any linear grammar, although we omit the proof here. Thus, the class of context-free languages is strictly larger than the class of linear context-free languages.
Combining this observation with the results above, we obtain the following hierarchy:
regular languages linear context-free languages context-free languages.
4.3 Pumping Lemma for Context-Free Languages
Our goal is to find an example in which the subtraction set is context-free, while the corresponding - or -position language is not context-free. To establish that a language is not context-free, we need a suitable tool for proving non-context-freeness. Just as for regular languages, context-free languages admit a pumping lemma. To introduce the lemma, we first describe derivations using trees.
Earlier, we represented the derivation
as a sequence of rewriting steps (see Example 4.7). This describes the process of rewriting one nonterminal at each step until a word consisting only of terminal symbols is obtained. However, the derivation can also be viewed as a tree:

Each application of a production rule is represented by a node labeled with children labeled , in that order. Reading the terminal symbols at the leaves from left to right, with contributing nothing, gives the generated word. We call this a derivation tree.
The part of the tree highlighted in red is responsible for making the tree deep. For comparison, we can derive by first using to produce eight occurrences of , and then deriving from each one. The resulting tree spreads out more widely, without requiring a long chain of nested nonterminals:

Here, we define the depth of a derivation tree as the maximum number of nonterminal occurrences on a path from the root to a leaf. Because the number of children of each node is bounded for this fixed grammar, a bound on the depth of the tree gives a bound on the number of leaves, and hence on the length of the generated word. Therefore, for every positive integer , there is a bound on the length of words generated by trees of depth at most .
The pumping lemma for context-free languages, like the one for regular languages, ultimately comes from finiteness and the pigeonhole principle. For regular languages, we use the finiteness of the set of states. For context-free languages, we instead use the fact that the set of nonterminal symbols of the corresponding CFG is finite. Let
As we have just seen, a derivation tree of depth can generate only words of length at most . In other words, any word longer than must have a derivation tree of depth at least . Thus, if we consider a derivation tree generating a word such that , there must be a path on which at least nonterminals appear. By the pigeonhole principle, some nonterminal must appear at least twice on this path:

Then, the part of the tree between the two occurrences of can be contracted to obtain a smaller tree:

Conversely, we can repeat this part any number of times and obtain another tree:

Because the two subtrees have roots labeled by the same nonterminal , the modified trees still follow the production rules of the grammar. Therefore, their leaves give words generated by the same grammar.
Now, let be the word generated on the left side of the path from to the first occurrence of , and let be the word generated on the right side. Similarly, let and be the words generated on the left and right sides, respectively, between the two occurrences of . Finally, let be the word generated by the second occurrence of . Then, the original derivation tree corresponds to a derivation of the form
Also, the derivations obtained by contracting and repeating this part can be written as
and
respectively. Thus, for every , the word is also generated by the grammar. This is the basic intuition behind the pumping lemma for context-free languages.
Theorem 4.9 (Pumping Lemma for Context-Free Languages). Let be a context-free language. Then there exists a positive integer such that, for every such that , there exist satisfying
Proof sketch. Because is context-free, there is a CFG with . Let and let .
For a word with , choose a derivation tree with the fewest nodes among all derivation trees generating . The depth of the tree exceeds , so some nonterminal occurs twice on a root-to-leaf path. The construction above gives
and shows that for every .
It remains to check that . If both and were empty, replacing the subtree rooted at the upper occurrence by the subtree rooted at the lower occurrence would give a smaller derivation tree for the same word . This contradicts our choice of the tree. Therefore, . For a more detailed treatment, see, e.g., Chapter 2 of [21].
Stronger versions of this pumping lemma give more control over the lengths and locations of the pumped factors. The version above suffices for the next proposition. We return to stronger versions in the exercises at the end of this section.
Proposition 4.10. The language
is not context-free.
Proof. Suppose, for contradiction, that
is context-free. Let N be the pumping length given by the pumping lemma, and consider
By the pumping lemma, we can write
such that and
for every .
If either or contains some , then pumping it twice introduces at least one additional . Thus
contains at least three b's and hence does not belong to L.
Therefore, both and consist only of 's. By , at least one of them is nonempty. Moreover, each of them lies entirely within one of the three blocks of 's. Thus, taking increases the lengths of at least one and at most two of the three blocks of 's. At least one block remains of length , so the three lengths can no longer be equal.
For example, if lies in the first block of 's and lies in the second block of 's, then
which is not in . The other possible cases are analogous. This contradicts the pumping lemma.
Compare this with the context-free language
from Example 4.4. In this example, the two blocks of a's can be kept in balance by the recursive rule
Each application of this rule adds one a to each side, increasing the lengths of both blocks by one. In contrast, the language
requires all three separated blocks of a's to have the same length. The pumping lemma above shows why this extra requirement cannot be maintained.
4.4 Closure Properties of Context-Free Languages
When working with context-free languages, it is useful to keep some of their closure properties in mind. We begin with two basic properties: the class of context-free languages is closed under finite union and concatenation.
Proposition 4.11. Let be context-free languages. Then, the union and the concatenation are context-free.
Proof. Let and be CFGs such that and . By renaming nonterminals if necessary, we can assume that . Let be a new nonterminal symbol. Then, the CFG with
generates . Similarly, let be a new nonterminal symbol. Then, the CFG with
generates .
On the other hand, the class of context-free languages is not closed under intersection.
Proposition 4.12. There exist context-free languages such that is not context-free.
Proof. Let
and
with . Note that the language is context-free by Example 4.4. Moreover, and are regular, and hence context-free. Therefore, both and are context-free by Proposition 4.11. On the other hand,
which is not context-free by Proposition 4.10.
Although context-free languages are not closed under intersection, they are closed under intersection with regular languages. Thus, restricting a context-free language to words accepted by a given DFA still gives a context-free language. We omit the proof.
Proposition 4.13. Let be a context-free language and be a regular language. Then, is context-free.
Finally, the failure of closure under complement follows from the properties above. Indeed, the class of context-free languages is closed under union. If it were also closed under complement, then De Morgan's laws would imply that it is closed under intersection. This contradicts Proposition 4.12.
Proposition 4.14. There exists a context-free language whose complement is not context-free.
Let us illustrate this fact with an important example. We have already seen in Proposition 4.10 that
is not context-free. On the other hand, its complement is context-free:
Proposition 4.15. The complement of the language
is context-free.
Proof. Take complements relative to , where . Let
This language is generated by the grammar with initial symbol A and rules
Indeed, makes the first block longer, while makes the second block longer. The rule adds one to each block. Together, these rules generate exactly the words in .
Now a word belongs to if it is not of the form , or if two adjacent blocks have different lengths. Therefore,
The first language is regular, and the other two are context-free by closure under concatenation. Because context-free languages are closed under finite union, is context-free. (In fact, the same decomposition shows that is linear context-free.)
4.5 Back to Word Subtraction
We are now ready to return to word subtraction games. We will show that, even when the subtraction set is linear context-free, both position languages and can fail to be context-free. Our example is
Readers who only want a simple example with a non-context-free -position language can skip ahead to “A simpler example” on page 47.
Theorem 4.16. The language is not context-free.
Proof. For integers , consider the word
We first show that
We will then use this characterization to obtain a contradiction to the pumping lemma. To determine the status of w, we compute the outcomes of its prefixes from left to right. Let
which is a prefix of w. The first part of the pattern is as follows:
For example, aabba is a -position because the only possible options are
and both are -positions:
Then, every word of the form with is an -position because it has the option . In addition, is also an -position because it has the option . On the other hand, is a -position because all of its possible options,
are -positions. In this way, we can compute the pattern of as described above.
Next, we have that is a -position if and only if . This is because if , has the option . On the other hand, if , then the only possible options are
and both are -positions. We next determine the status of , which has as an option, by considering the same two cases. Specifically, is a -position if and only if . On the other hand, regardless of the values of and , both and are -positions. Furthermore, with is a -position if and only if :
where
Now put
so that . It remains to determine the outcomes of , , and , in that order. At each step, we list all options and use the outcomes already determined. First, is a -position if and only if . This is because this word has options
-
,
-
,
-
if , and
-
if .
Thus, the word is an -position if and only if either , in which case the second option is a -position, or , in which case the fourth option exists.
Then, is a -position if and only if . This is because this word has options
• ,
• ,
• if , and
• if .
Thus, the word is an -position if and only if either , in which case the first option is a -position, or , in which case the fourth option exists.
Finally, is a -position if and only if . This is because has options
• ,
• ,
• ,
• , and
• if .
Thus, if , the fourth option is a -position. In addition, if but , then the first option is a -position. Therefore, implies that is an -position. Conversely, if , then all options are -positions, and hence is a -position.
Suppose, for contradiction, that is context-free. By Proposition 4.13, its intersection
with this regular language is also context-free. (It is easily shown that is regular.) Let be an integer greater than the pumping length given by the pumping lemma, and consider
Indeed, belongs to because this word corresponds to with . By the pumping lemma, we can write
such that and
for every . Neither nor can contain the letter because taking would increase the number of 's and take the word outside . In addition, neither can contain a letter from the fixed initial block because pumping that letter would change the required prefix . Thus, every nonempty lies entirely within one of the three -blocks.
Taking increases the lengths of at least one and at most two of these blocks. Therefore, the three lengths are no longer all equal, and each is still at least 5. By the characterization proved above, the resulting word is not a -position. This contradicts .
Note that, already at the stage where we obtained the condition
characterizing when is a -position, one can show that the corresponding language is not context-free. However, we used the condition to simplify the proof.
Corollary 4.17 (Non-Context-Freeness for Context-Free Subtraction Sets). Even when the subtraction set is context-free, the corresponding -position language need not be context-free.
Because context-free languages are not closed under complement, Theorem 4.16 does not settle whether is context-free. Moreover, the same family of words does not give a contradiction: among words of the form
with , the -positions are exactly those for which the three exponents are not all equal. The language described by this condition is context-free, by an argument similar to Proposition 4.15.
To prove non-context-freeness for -positions, we instead use the words ending in , whose outcomes were also determined in the proof above.
Theorem 4.18. The language is not context-free.
Proof sketch. In the proof of Theorem 4.16, we showed that, for , the word
is an -position if and only if
Using this characterization, we can show that
is not context-free.
To prove this, we use a refined pumping lemma that gives more control over the positions of the pumped factors. This allows us to analyze how pumping changes the comparisons between , , and . The details are developed in Exercises 4.5 and 4.6.
Because PAL is generated by a linear grammar, the two non-context-freeness results already hold for linear context-free subtraction sets. The following table summarizes the results obtained so far:
| Subtraction set | ||
|---|---|---|
| Finite | Regular | Regular |
| Regular | ||
| Linear context-free | Not necessarily context-free | Not necessarily context-free |
| Context-free |
Table 1: The relationship between subtraction sets and position languages.
A simpler example. There is also a much simpler example in which the subtraction set is linear context-free but the -position language is not context-free. Let and set
We claim that
The argument in Proposition 4.15 shows that is linear context-free. Every word in is an -position because the whole word can be removed, leaving . On the other hand, no word in is a proper prefix of another word in . Therefore, every legal move from a word in leaves a nonempty prefix in , which is an -position. This proves the claim.
Because is not context-free, neither is . However, in this example, is context-free. Thus, the palindrome example establishes a stronger conclusion: both the - and -position languages can fail to be context-free, even when the subtraction set is linear context-free.
Interestingly, the reverse situation cannot occur when is context-free. Indeed, the identity
and closure under concatenation imply that, if both and are context-free, then is context-free as well.
The same construction applies more generally to any prefix-free language : if , then
Here, prefix-free means that no word in is a proper prefix of another word in . Hiyu Inoue of Hiroshima University also independently discovered an example of a context-free subtraction set for which is not context-free but is context-free, together with the general observation above for prefix-free languages . This gives a simple way to construct further examples.
For instance, consider
The language is prefix-free because different initial blocks of 's are followed by . Moreover, is context-free. To see this, first consider words of the form
with and . Such a word belongs to exactly when its final block has length 1 and each block is one letter shorter than the previous block. A failure of the latter condition can be described by a context-free grammar that generates two adjacent blocks of lengths with , adding matching 's on either side of the between them. The blocks before and after this pair are unrestricted. Nonempty words of the wrong form, or with a final block of length other than 1, form regular languages. Together, these observations show that is context-free. Nevertheless, it is easily shown that the Parikh image
of is not semilinear. Thus, a context-free subtraction set can give rise to a -position language whose Parikh image is not semilinear.
The position languages of several other context-free subtraction sets have also been studied, revealing different relationships between the language classes of subtraction sets and their position languages. We leave these other examples for another occasion.
Exercises
Exercise 4.1. Let . Give a context-free grammar generating each of the following languages:
◇
Exercise 4.2. Prove that the class of context-free languages is closed under reversal. In particular, given a CFG generating a language , construct a CFG generating .
Exercise 4.3 . Show that Theorem 4.9 can be strengthened by requiring the decomposition
to satisfy
in addition to the conditions stated in the theorem.
◇
Exercise 4.4. Let . Using the strengthened pumping lemma from Exercise 4.3, prove that
• and
•
are not context-free.
◇
Exercise 4.5 . Exercise 4.3 strengthens Theorem 4.9 by bounding the length of . Another useful strengthening allows us to specify a sufficiently long factor of the input word and guarantees that at least one nonempty pumping part lies entirely within that factor:
Proposition 4.19 (Lemma 2 of [8]). Let be a context-free language. Then there exists a positive integer such that, whenever for some with , there exist satisfying:
• ,
either
-
and the occurrence of in w is contained in the occurrence of in w, or
-
and the occurrence of in w is contained in the occurrence of in w, and
• for every .
Here, an occurrence is said to be contained in another occurrence if it lies entirely within the latter.
Intuitively, this lemma allows us to constrain the location of the pumping pair by specifying in advance a sufficiently long factor . However, unlike in the case of regular languages, we can only guarantee that one of the occurrences of and is contained in the occurrence of .
Now, show that the language
is not context-free. The proof strategy is as follows: Let N be the pumping length, and consider the word
with , , and .
Exercise 4.6 . Use the ideas from Exercise 4.5 to complete the proof of Theorem 4.18.
Open Problems
Problem 4.1 (Which subclasses of context-free languages preserve context-freeness?). We have seen that a context-free subtraction set can give rise to a position language that is not context-free. Can we restrict to a natural subclass of context-free languages so that is always context-free? We are interested in classes that include nonregular languages, extending the result of Theorem 3.8.
Two familiar candidates are linear context-free languages and deterministic context-free languages (DCFLs). The former are generated by linear grammars, as discussed in the main text. The latter are recognized by deterministic pushdown automata: roughly speaking, finite automata that use a stack and operate without nondeterministic choices.
However, neither class has the desired property. The language PAL is linear context-free, but is not context-free, as shown above. Similarly, as mentioned earlier, the subtraction set
is deterministic context-free, but is not context-free.
Are there other natural candidates? Yushin Kusajima and the first author have discussed this question, but so far have obtained positive results only under very restrictive assumptions. ◇
Problem 4.2 (What is a natural upper bound?). We have seen that, when is a context-free language, need not be context-free. Is there a natural class of languages that contains for every context-free subtraction set ?
One natural candidate is the class of multiple context-free languages (MCFLs) [19], which properly contains the class of context-free languages. Roughly speaking, a multiple context-free grammar generates tuples of words and uses rules that combine their components without copying them. This allows dependencies between several parts of a word to be maintained during a derivation. MCFLs retain many useful properties of context-free languages; in particular, their Parikh images are semilinear.
However, the example in Section 4.5 shows that a context-free subtraction set can have a -position language whose Parikh image is not semilinear. Thus, MCFLs are not sufficient. More generally, any language class containing for every context-free subtraction set must include languages with non-semilinear Parikh images. What natural language class can provide such an upper bound?
5 Variants
5.1 Prefix and Suffix Removal
So far, we have considered word subtraction games in which a move consists of removing a suffix from the current word. A natural variant is to allow moves from both ends of the word. More precisely, let be languages. In the two-sided word subtraction game WordSubtraction, a player can either remove a prefix belonging to , or remove a suffix belonging to . Thus, from a position , a move consists of replacing by whenever either
or
As before, the player who cannot make a move loses. We expect that general results can also be obtained for the two-sided version. However, we currently understand only a few special cases, which we discuss here.
As our first case study, consider , , and . In other words, a player can remove either a prefix ending in or a suffix beginning with . Interestingly, this game is equivalent to a combinatorial game known as the Timber game [14]. In the Timber game, a position is represented by a row of dominoes, each of which is tilted either to the left or to the right. On each turn, a player chooses one domino and knocks it down. If the chosen domino is tilted to the left, then all dominoes to its left are also knocked down, regardless of their directions. Similarly, if it is tilted to the right, then all dominoes to its right are knocked down. The player who knocks down all the remaining dominoes wins. Indeed, if we regard a domino tilted to the left as the letter and a domino tilted to the right as the letter , then the Timber game is exactly the same as WordSubtraction.
The -position language of WordSubtraction is the context-free language known as the Dyck language, which is generated by the CFG with
For example,
-
-
, and
-
are derivations of this grammar. In fact, the Dyck language consists of all well-formed sequences of parentheses, where is regarded as an opening parenthesis and as a closing parenthesis. We call such a word a Dyck word. (Dyck words can also be represented as lattice paths, called Dyck paths.) For example, the derived words , , and abaabbab correspond to the parenthesis sequences (), (), and ()(), respectively, and hence are Dyck words. On the other hand, , , , and are not Dyck words.
But why are Dyck words -positions in WordSubtraction? To understand this, it is useful to consider a characterization of Dyck words in terms of their balance. For a word , define its balance by
Then a word is a Dyck word if and only if it satisfies the following two conditions:
-
for every prefix of , and
-
for every suffix of .
Intuitively, when reading the word from left to right, we can never close more parentheses than we have opened. Similarly, when reading it from right to left, we can never open more parentheses than we have closed. In particular, every Dyck word has balance 0.
We can now see why the Dyck words are exactly the -positions. First, suppose that w is a Dyck word, and consider a move that removes a suffix beginning with b, leaving a word . Then is a prefix of w, and hence
Therefore, . Because a Dyck word has balance 0, cannot be a Dyck word. The same argument shows that removing a prefix ending in a also leaves a word that is not a Dyck word. Thus, no move from a Dyck word leads to another Dyck word.
Conversely, suppose that is not a Dyck word. By the characterization above, either some prefix of has negative balance or some suffix of has positive balance. In the first case, let be the shortest prefix of having negative balance. Then by . In addition, for every decomposition of has a non-positive balance because . This implies that is a Dyck word. Thus, by removing the suffix beginning with the immediately following we can move to the Dyck word . The second case is analogous. Hence, from every non-Dyck word, there is a move to a Dyck word. Summarizing, by the Partition Theorem, a word is a Dyck word if and only if is a -position.
Both and in this example are regular languages. In contrast, the -position language of WordSubtraction, while context-free, is not regular. (This can be easily shown using the pumping lemma.) Thus, at least the closure property stated in Theorem 3.8 does not extend to the two-sided setting.
One might still expect that, if both and are regular, then is context-free. The next example shows that this does not hold in general.
The example we consider next is obtained by reformulating a combinatorial game known as End-Nim [1] as a word subtraction game. In End-Nim, a position is a sequence of heaps of stones, such as . On each turn, a player chooses either the leftmost or the rightmost heap and removes any positive number of stones from it. The player who makes the last move wins. The -positions of End-Nim can be characterized as follows. For a position
let be the largest integer i such that
and let be the largest integer j such that
When , we define .
Proposition 5.1 (Theorem 2.1 of [5]). For a position of End-Nim such that , is a -position if and only if either
• and is even, or
• , is odd, and is even.
For example, is a -position because and .
Now, End-Nim behaves in the same way as WordSubtraction . To see this correspondence, represent each heap by a nonempty block of 's, with one or more 's separating consecutive heaps. For example, the position can be represented by a word such as
The precise number of b's used as separators is irrelevant; they merely serve to separate consecutive heaps. Removing a prefix or suffix in corresponds to removing a positive number of stones from the leftmost or rightmost heap. If the whole heap is removed, some or all of the adjacent b's can also be removed. Thus, words with different numbers of b's between the blocks of a's or at either end can represent the same End-Nim position. Therefore, for a word
with , let be the corresponding End-Nim position. By Proposition 5.1 and symmetry, is a -position if and only if one of the following holds:
• and is even.
• , is odd, and is even.
• , is even, and is odd.
Theorem 5.2. The -position language with is not context-free.
Proof sketch. We prove that is not context-free by using the pumping lemma from Proposition 4.19. Suppose that this language is context-free, and let be a pumping length. Consider
The corresponding End-Nim position is . Because and , this is a -position.
Apply the lemma with the first block as the specified factor . We obtain a decomposition
in which at least one nonempty pumping factor lies entirely within the first block. Now consider
The first heap of has size at least . Unless contains an from the last block, the last heap still has size . In that case, the two end heaps differ by at least 2, so cannot be a -position. Moreover, if contains the letter , then contains more than three 's and is not of the form . Therefore, for some , and its occurrence lies entirely within the last block.
It remains to consider the case where lies in the first block and lies in the last block, with . The end heaps have sizes and . For their difference to be at most 1, we must have . But the resulting position is then
for which . Because the last heap is one larger than the first, the characterization requires to be even. Thus, is not a -position, contradicting the pumping lemma.
Corollary 5.3. There exist regular languages such that the -position language of WordSubtraction is not context-free.
5.2 Infix Removal and Merging
Another variant is to remove an arbitrary infix, rather than a prefix or suffix, and merge the remaining parts into a single word. More precisely, if a position can be written as for some and , then one can replace by . Here we give two examples showing that simple subtraction sets can lead to -position languages that are not context-free.
A familiar example is Wythoff's game [23]. Let
and consider the infix-removal game on words in . A word represents two heaps of sizes m and n. A move either reduces one heap by a positive amount or reduces both heaps by the same positive amount. Thus, this restricted game is exactly Wythoff's game.
The -positions of Wythoff's game are described by Beatty sequences involving the golden ratio (see, e.g., Theorem 3.4 in Chapter IV of [20]). The resulting set of pairs is not semilinear. By Parikh's theorem, the language of -positions within is therefore not context-free. Because context-free languages are closed under intersection with regular languages, the full -position language is not context-free either.
Even restricting the subtraction set to a regular language does not guarantee a context-free -position language. For example, take and
This infix-removal game is known as StrNim, and its -position language is not context-free [12]. Thus, the regularity result of Theorem 3.8 does not extend to infix removal.
We leave a more general study of infix-removal games for future work.
Exercises
Exercise 5.1. Let and be languages over . Show that the -position language of WordSubtraction is not regular. (Hint: If is regular, then is also regular.)
Exercise 5.2*. Let be finite subtraction sets, and let \ \notin \Sigma(S, T)\Sigma \cup {$$. Show that
is regular. (Hint: No move can remove the symbol uv$ as a disjunctive sum and use Grundy numbers.)
Exercise 5.3*. As a slight generalization of the Timber game, consider WordSubtraction( ), where . Thus, in each move, a player can remove either a prefix ending in a letter from or a suffix beginning with a letter from . Characterize the -positions in each of the following cases:
-
and ,
-
,
-
the general case.
◇
Exercise 5.4*. Let be the golden ratio. It is well known that, in Wythoff's game, a position with is a -position if and only if
for some integer .
54
{a^{\lfloor k\cdot\varphi\rfloor}b^{\lfloor k\cdot\varphi^{2}\rfloor}:k\geq 0}\cup{a^{\lfloor k\cdot\varphi^{2}\rfloor}b^{\lfloor k\cdot\varphi\rfloor}:k\geq 0}
over $\Sigma=\{a,b\}$ is not context-free. You can use the fact that a Beatty sequence{\lfloor \alpha k \rfloor \mid k\geq 0},
where $\alpha>1$ is irrational, does not contain an infinite arithmetic progression. 2. Prove that the set of $\mathcal{P}$-positions of the infix-removal word subtraction game with subtraction setS=a^{+}\cup b^{+}\cup{a^{n}b^{n}:n\geq 1}\subseteq \Sigma^{+}
is not context-free. ## Open Problems Problem 5.1 (Can the Dyck-word characterization be generalized?). Exercise 5.3 considers a generalization of Timber in which moves are determined by individual letters. More generally, let $U,V\subseteq \Sigma^{+}$ be languages and consider\mathrm{WordSubtraction}(\Sigma^{}U,V\Sigma^{}).
Can the characterization by Dyck words be extended to this setting? In particular, how should such a characterization account for overlapping occurrences of words in $U\cup V$? Problem 5.2 (Can Beatty sequences arise in suffix-removal games?). In the infix-removal version, a context-free subtraction set can realize a $\mathcal{P}$-position language whose restriction to $a^{*}b^{*}$ has a Parikh image described by irrational Beatty sequences, as in Wythoff's game. This suggests a related question for the ordinary suffix-removal version: can a context-free subtraction set $S$ yield a $\mathcal{P}$-position language $L_{\mathcal{P}}(S)$ whose Parikh image is described by irrational Beatty sequences? The example in Section 4.5 shows that, even in the suffix-removal version, a context-free subtraction set can realize a $\mathcal{P}$-position language with a non-semilinear Parikh image. This suggests that context-free subtraction sets can give rise to a broad range of structures in their $\mathcal{P}$-positions. The question here is whether the particular structure of irrational Beatty sequences can also arise. # 6 Advanced Topics ## 6.1 Misère Play So far, we have considered combinatorial games under the normal-play convention, in which the player who makes the last move wins. Another important convention is misère play, in which the player who makes the last move loses. Equivalently, a player who has no legal move wins. For a subtraction set $S \subseteq \Sigma^+$, we write $\text{WordSubtraction}^-(S)$ for the word subtraction game played under the misère convention. The legal moves are exactly the same as those in $\text{WordSubtraction}(S)$; only the winning condition is changed. We denote its $\mathcal{P}$- and $\mathcal{N}$-position languages by $L_{\mathcal{P}}^-(S)$ and $L_{\mathcal{N}}^-(S)$, respectively. Although this change may appear minor, it changes the starting point of the recursive classification: Under normal play, every terminal position is a $\mathcal{P}$-position, whereas under misère play, every terminal position is an $\mathcal{N}$-position. For nonterminal positions, the recursive characterization remains unchanged. Theorem 6.1 (Partition Theorem for Misère Play). For an impartial short misère-play game, * a position is a $\mathcal{P}$-position if and only if it has at least one option and all of its options are $\mathcal{N}$-positions, and * a position is an $\mathcal{N}$-position if and only if it has no option or it has an option that is a $\mathcal{P}$-position. In particular, the set of positions is partitioned into $\mathcal{P}$-positions and $\mathcal{N}$-positions. Based on this characterization, we will show that even in the misère-play setting, the $\mathcal{N}$-position language $L_{\mathcal{N}}^-(S)$ is regular if $S$ is regular. Let us begin with the following lemma: Lemma 6.2. If the subtraction set $S \subseteq \Sigma^+$ is regular, then the set of nonterminal positions $\Sigma^*S$ is also regular. Proof. Let $\mathbf{A}_S = (Q_S, \Sigma, \delta_S, q_S, F_S)$ be a DFA recognizing $S$. Note that $q_S \notin F_S$ holds by $\varepsilon \notin S$. We can construct an NFA $\mathbf{N}_{\mathrm{NT}}$ recognizing $\Sigma^*S$ in the following way: For each $a \in \Sigma$, add a transitionq_S \xrightarrow{a} q_S
to $\mathbf{A}_S$. More precisely, let $\mathbf{N}_{\mathrm{NT}} = (Q_S, \Sigma, \delta'_S, q_S, F_S)$ where\delta'_S(q,a) = \begin{cases} {\delta_S(q,a)} \cup {q_S} & \text{if } q = q_S, \ {\delta_S(q,a)} & \text{otherwise.} \end{cases}
Indeed, $w \in \Sigma^*S$ if and only if there exists a run of the formq_S \xrightarrow{a_1} q_S \xrightarrow{a_2} \cdots q_S \xrightarrow{a_m} q_S \xrightarrow{b_1} q_1 \xrightarrow{b_2} \cdots \xrightarrow{b_n} q_n \in F_S
on $\mathbf{N}_{\mathrm{NT}}$ where $w = a_1a_2\cdots a_m b_1 b_2 \cdots b_n$ with $a_1a_2\cdots a_m \in \Sigma^*$ and $b_1b_2\cdots b_n \in S$. Thus, $L(\mathbf{N}_{\mathrm{NT}}) = \Sigma^*S$ holds and $\Sigma^*S$ is regular. $\square$ More generally, regular languages are closed under concatenation; that is, if $L_1$ and $L_2$ are regular, then $L_1L_2$ is also regular. We now construct a DFA recognizing the $\mathcal{N}$-position language $L_{\mathcal{N}}^-(S)$ of $\text{WordSubtraction}^-(S)$. The strategy is very similar to that used for the normal-play setting in Theorem 3.8. We first identify a set of base $\mathcal{N}$-positions. We then identify the nonterminal positions that can move only to these base $\mathcal{N}$-positions as $\mathcal{P}$-positions. At each such $\mathcal{P}$-position, we apply the reset rule. From each reset point, positions for which the suffix read from that point belongs to $S$ are then identified as $\mathcal{N}$-positions. We repeat this process to obtain a DFA recognizing $L_{\mathcal{N}}^{-}(S)$. The only difference is how the base $\mathcal{N}$-positions are obtained. In the normal-play case, the base $\mathcal{N}$-positions are precisely the elements of the subtraction set $S$. On the other hand, in the misère-play case, the terminal positions are the base $\mathcal{N}$-positions. Thus, we begin by identifying the terminal positions and then identify the nonterminal positions that can move only to terminal positions as $\mathcal{P}$-positions. At each such $\mathcal{P}$-position, we apply the reset rule and proceed in the same way as in the normal-play case. **Theorem 6.3.** Let $\Sigma$ be an alphabet and $S \subseteq \Sigma^+$ be a regular language. Then, the $\mathcal{N}$-position language $L_{\mathcal{N}}^{-}(S)$ of WordSubtraction$^{-}(S)$ is regular. Proof. Let $\mathbf{A}_S = (Q_S, \Sigma, \delta_S, q_S, F_S)$ be a non-returning DFA recognizing the subtraction set $S$. Also, let $\mathbf{A}_T = (Q_T, \Sigma, \delta_T, q_T, F_T)$ be a DFA recognizing the set of terminal positions $(\Sigma^* S)^c$. Such a DFA $\mathbf{A}_T$ indeed exists because $\Sigma^* S$ is regular by Lemma 6.2, and hence its complement $(\Sigma^* S)^c$ is also regular. Note that $q_T \in F_T$ because $\varepsilon$ is a terminal position. By renaming states if necessary, assume that $Q_S \cap Q_T = \emptyset$. Let $\mathbf{A} = (Q, \Sigma, \delta, q_T, F)$ be the DFA defined as * $Q = Q_S \cup Q_T$, * for each $q \in Q$ and $a \in \Sigma$,\delta(q,a)=\begin{cases}\delta_S(q,a)&\text{if } q \in Q_S,\\delta_T(q,a)&\text{if } q \in Q_T,\end{cases}
and * $F = F_S \cup F_T$. Finally, let $\mathbf{A}_{\mathcal{N}} = (Q_{\mathcal{N}}, \Sigma, \delta_{\mathcal{N}}, \{q_T\}, F_{\mathcal{N}})$ be the DFA defined as * $Q_{\mathcal{N}} = 2^Q$, * for each $R \subseteq Q$ and $a \in \Sigma$,\delta_{\mathcal{N}}(R,a)=\begin{cases}{\delta(q,a):q\in R}\cup{qs}&\text{if }\delta(q,a)\notin F\text{ for all }q\in R,\{\delta(q,a):q\in R}&\text{otherwise},\end{cases}
and * $F_{\mathcal{N}} = \{R \subseteq Q: R \cap F \neq \emptyset\}$. The construction always keeps track of the run of $\mathbf{A}_T$ from $q_T$. In addition, each reset starts a new run of $\mathbf{A}_S$ from $q_S$. We prove correctness by induction on the length of the input, showing that a word is accepted exactly when it is an $\mathcal{N}$-position, and that a reset occurs exactly at each nonempty $\mathcal{P}$-position. For the empty word, the initial state $\{q_T\}$ is accepting, as required because $\varepsilon$ is a terminal $\mathcal{N}$-position. Now, let $w \neq \varepsilon$, and assume the claim for every proper prefix of $w$. Suppose that, after reading $w$, the current set of states contains an accepting state $q_f \in F$. There are two cases: * If $q_f \in F_T$, then $\mathbf{A}_T$ accepts $w$, so $w$ is a terminal position. * If $q_f \in F_S$, then a run of $\mathbf{A}_S$ started by a reset at some proper prefix $w'$ accepts the remaining suffix $s \in S$, where $w = w's$. By the induction hypothesis, $w'$ is a $\mathcal{P}$-position. In either case, $w$ is an $\mathcal{N}$-position by Theorem 6.1. Conversely, suppose that $w$ is an $\mathcal{N}$-position. By Theorem 6.1, either $w$ is terminal or $w = w's$ for some $\mathcal{P}$-position $w'$ and $s \in S$. In the first case, the run of $\mathbf{A}_T$ reaches an accepting state. In the second case, the induction hypothesis ensures that a reset occurs at $w'$. The run of $\mathbf{A}_S$ started there accepts $s$, so the current set again contains an accepting state. Thus, $w$ is accepted if and only if it is an $\mathcal{N}$-position. $\square$ As an example, let us consider $\text{WordSubtraction}^-(S)$ for the subtraction set $S = a\Sigma(\Sigma\Sigma)^* \cup b(\Sigma\Sigma)^*$, which we considered in Section 3. It is clear that the set of terminal positions is $(\Sigma^*S)^c = (ba)^* \cup a(ba)^*$. Thus, for example, $\mathbf{A}_T$ is given by the following automaton:  Combining this with the DFA $\mathbf{A}_S$ recognizing $S$ given in Example 2.2, we obtain the following automaton $\mathbf{A}$.  Although the two DFAs appear to be disconnected in the figure, they together form a single DFA $\mathbf{A}$. Now, applying the construction of $\mathbf{A}_N$ to this DFA $\mathbf{A}$, we obtain a DFA recognizing $L_{\mathcal{N}}^{-}(S)$. However, writing down all of its states would be inconvenient. Instead, let us illustrate the construction by considering the run of the word $baab$:{q_{T}} \xrightarrow{b} {q_{b}, q_{S}} \xrightarrow{a} {q_{a}, q_{1}} \xrightarrow{a} {q_{\perp}, q_{2}} \xrightarrow{b} {q_{\perp}, q_{S}, q_{1}} \notin F_{\mathcal{N}}.
We start from the initial state $\{q_T\}$. Following the transition of $\mathbf{A}_T$, we move to the state $\{q_b\}$. However, because $q_b$ is not an accepting state of $\mathbf{A}$, the reset rule is applied, and the actual state in $\mathbf{A}_N$ is $\{q_b, q_S\}$. Next, the respective transitions from $q_b$ and $q_S$ on $a$ lead to $q_a$ and $q_1$. Because $q_a$ is an accepting state, the transition in $\mathbf{A}_N$ leads to $\{q_a, q_1\}$. Indeed, $ba$ is a terminal position and hence an $\mathcal{N}$-position. On reading the next $a$, the respective transitions lead to $q_\perp$ and $q_2$. Because $q_2$ is an accepting state, the resulting state in $\mathbf{A}_N$ is $\{q_\perp, q_2\}$. In fact, $baa$ is not a terminal position, but it is an $\mathcal{N}$-position: the first player can remove $aa$, leaving $b$ to the second player, who is then forced to remove it. Finally, on reading $b$, the respective transitions lead to the rejecting states $q_\perp$ and $q_1$. Thus, the reset rule is applied, and the resulting state is $\{q_\perp, q_S, q_1\}$. Therefore, $baab$ is a $\mathcal{P}$-position. An important special case is when $\Sigma \subseteq S$, that is, when the only terminal position is $\varepsilon$. In this case, we have the following result. **Theorem 6.4.** Let $S \subseteq \Sigma^+$ be a regular subtraction set such that $\Sigma \subseteq S$. Then, $L_{\mathcal{N}}^{-}(S) = \Sigma \cdot L_{\mathcal{N}}(S) \cup \{\varepsilon\}$ holds. In other words, an $\mathcal{N}$-position in misère play is precisely either the empty word $\varepsilon$ or a word obtained by adding a single letter to the left end of a normal-play $\mathcal{N}$-position. Proof sketch. When the only terminal position is $\varepsilon$, $\mathbf{A}_T$ is given by the following two-state DFA:  Then, the DFA $\mathbf{A}_{\mathcal{N}}$ constructed in the proof of Theorem 6.3 is isomorphic to the corresponding DFA for the normal-play version with the following transitions added at the beginning:  The only difference is that each state additionally contains $q_\perp$. However, this does not affect the behavior of the automaton because no accepting state can be reached from $q_\perp$. $\square$ We discuss a generalization of this fact in Exercise 6.2. ## 6.2 Reflexivity In ordinary subtraction games, a subtraction set $S \subseteq \mathbb{N}_+$ is called reflexive if the $\mathcal{P}$-position set of the game with subtraction set $L_{\mathcal{P}}(S) \setminus \{0\} \subseteq \mathbb{N}$ coincides with $S$ after removing 0; that is,L_{\mathcal{P}}(L_{\mathcal{P}}(S) \setminus {0}) \setminus {0} = S.
This property can be used to study other properties of subtraction sets. Takuto Maki of Kagoshima University observed that reflexivity and related properties should have natural analogues for word subtraction games, and suggested that they should be investigated in this setting. The results presented in this section were developed with his advice. We first introduce a notion of reflexivity for word subtraction games. Several results on reflexivity for ordinary subtraction games were proved in [10]. To follow the same line of argument for word subtraction games, we use both prefix and suffix removal for technical reasons. Unlike addition of integers, concatenation of words is not commutative, so we must distinguish between the two kinds of removal. Therefore, we write $\text{WordSubtraction}^{\text{suf}}(S)$ and $\text{WordSubtraction}^{\text{pre}}(S)$ for the suffix-removal and prefix-removal versions, respectively. We use the corresponding notation $L_{\mathcal{P}}^{\text{suf}}(S)$, $L_{\mathcal{N}}^{\text{suf}}(S)$, $L_{\mathcal{P}}^{\text{pre}}(S)$, and $L_{\mathcal{N}}^{\text{pre}}(S)$ for their $\mathcal{P}$-position and $\mathcal{N}$-position languages, respectively. A subtraction set $S \subseteq \Sigma^+$ is said to be reflexive ifS = L_{\mathcal{P}}^{\text{pre}}(L_{\mathcal{P}}^{\text{suf}}(S) \setminus {\varepsilon}) \setminus {\varepsilon}.
In other words, consider the word subtraction game $\text{WordSubtraction}^{\text{pre}}(L_{\mathcal{P}}^{\text{suf}}(S) \setminus \{\varepsilon\})$, whose subtraction set consists of the nonempty $\mathcal{P}$-positions of $\text{WordSubtraction}^{\text{suf}}(S)$. Then the set of nonempty $\mathcal{P}$-positions in this new game coincides with the original subtraction set $S$. For example, the subtraction set $S = a^+b^* \cup a^*b^+$ with $\Sigma = \{a, b\}$ is reflexive. This is because $L_{\mathcal{P}}^{\text{suf}}(S) = \Sigma^*ba \cup \{\varepsilon\}$, as discussed in Exercise 1.3. The $\mathcal{N}$-positions in $\text{WordSubtraction}^{\text{pre}}(\Sigma^*ba)$ are exactly the words containing $ba$. Indeed, from any such word, the first player can remove the prefix ending at the last occurrence of $ba$, immediately reaching a terminal position. Thus, the set of nonempty $\mathcal{P}$-positions is precisely(\Sigma^ba\Sigma^)^c \setminus {\varepsilon} = a^+b^* \cup a^*b^+ = S.
We next give a characterization of reflexivity. In [10], it was shown that, for an ordinary subtraction set $S \subseteq \mathbb{N}_+$, $S$ is reflexive if and only if every element of $\mathcal{D}(S)$ is an $\mathcal{N}$-position, where $\mathcal{D}(S)$ is defined as\mathcal{D}(S)={x-x^{\prime}\in\mathbb{N}_{+}:x,x^{\prime}\in S}.
To obtain a language-theoretic counterpart of this characterization, we introduce the notion of derivatives of languages. For a language $L \subseteq \Sigma^*$ and a word $v \in \Sigma^*$, the right derivative (or right quotient) of $L$ with respect to $v$ is the languageL v^{-1}={w\in\Sigma^{*}:w v\in L}.
Thus, $Lv^{-1}$ consists of the prefixes that remain after removing the suffix $v$ from words in $L$. More generally, for languages $L, V \subseteq \Sigma^*$, we define the right derivative of $L$ by $V$ asL V^{-1}=\bigcup_{v\in V}L v^{-1}={w\in\Sigma^{*}:w v\in L\mathrm{f o r~s o m e}v\in V}.
For a subtraction set $S \subseteq \Sigma^+$, define\mathcal{D}(S)=(S S^{-1})\setminus{\varepsilon}={u\in\Sigma^{+}:u s^{\prime}\in S\mathrm{f o r~s o m e}s^{\prime}\in S}.
The following can be proved using the same approach as Theorem 2 in [10]. Theorem 6.5. A subtraction set $S \subseteq \Sigma^+$ is reflexive if and only if $\mathcal{D}(S) \subseteq L_{\mathcal{N}}^{\mathrm{suf}}(S)$. Proof. Let $S^{\mathrm{ref}} = L_{\mathcal{P}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\}) \setminus \{\varepsilon\}$. We first prove the only-if direction by showing its contrapositive. If $\mathcal{D}(S) \not\subseteq L_{\mathcal{N}}^{\mathrm{suf}}(S)$, there exists a nonempty $\mathcal{P}$-position $p \in \Sigma^+$ in WordSubtraction$^{\mathrm{suf}}(S)$ such that $ps' = s$ with some $s, s' \in S$. Thus, the move from $s$ to $s'$ is legal in WordSubtraction$^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$, and therefore, $s' \in L_{\mathcal{P}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$ implies $s \notin L_{\mathcal{P}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$. Thus, $s$ and $s'$ cannot both belong to $S^{\mathrm{ref}}$. Because both belong to $S$, we conclude that $S \neq S^{\mathrm{ref}}$. We next prove the if direction. Suppose that $S$ is not reflexive. Then there exists $w \in \Sigma^+$ such thatw\in S\setminus S^{\mathrm{r e f}}\quad\mathrm{o r}\quad w\in S^{\mathrm{r e f}}\setminus S.
w\in S\setminus S^{\mathrm{r e f}}.
Indeed, suppose that $w \in S^{\text{ref}} \setminus S$. If $w \in L_{\mathcal{P}}^{\text{suf}}(S)$, then $w$ itself belongs to the subtraction set of the new prefix-removal game. Removing the whole word would make $w$ an $\mathcal{N}$-position in that game, contradicting $w \in S^{\text{ref}}$. Thus,w\in L_{\mathcal{N}}^{\mathrm{s u f}}(S).
By $w \notin S$, there must be a move from $w$ to a nonempty $\mathcal{P}$-position $p$ in WordSubtraction$^{\mathrm{suf}}(S)$ obtained by removing some suffix $s \in S$. By the minimality of $w$, we have $s \in S^{\mathrm{ref}}$ because $s \in S \setminus S^{\mathrm{ref}}$ does not hold. Here, $p$ belongs to the subtraction set $L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\}$ and $s \in S^{\mathrm{ref}}$ is a $\mathcal{P}$-position in WordSubtraction$^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$. This implies that $w = ps$ is an $\mathcal{N}$-position in WordSubtraction$^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$, and this contradicts $w \in S^{\mathrm{ref}}$. Consequently, we have $w \in S \setminus S^{\mathrm{ref}}$. Now, $w \notin S^{\mathrm{ref}}$ implies $w \in L_{\mathcal{N}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$. Therefore, there exists $p \in L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\}$ and $w' \in L_{\mathcal{P}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\})$ such that $w = pw'$. In addition, $w \neq p$, that is, $w' \neq \varepsilon$ because $w \in S$ implies $w \notin L_{\mathcal{P}}^{\mathrm{suf}}(S)$. Thus, we have $w' \in L_{\mathcal{P}}^{\mathrm{pre}}(L_{\mathcal{P}}^{\mathrm{suf}}(S) \setminus \{\varepsilon\}) \setminus \{\varepsilon\} = S^{\mathrm{ref}}$ and $w' \in S$ by the minimality of $w$. Finally,p=w\left(w^{\prime}\right)^{-1}\in S S^{-1}=\mathcal{D}(S)\cup{\varepsilon}
with $p \in L_{\mathcal{P}}^{\mathrm{suf}}(S)$, and hence $\mathcal{D}(S) \not\subseteq L_{\mathcal{N}}^{\mathrm{suf}}(S)$. For example, $\mathcal{D}(a^+b^* \cup a^*b^+) = a^+b^* \cup a^*b^+ \subseteq L_{\mathcal{N}}^{\text{sup}}(a^+b^* \cup a^*b^+)$ holds, and indeed $a^+b^* \cup a^*b^+$ is reflexive. In this subsection, we have defined reflexivity using both suffix and prefix removal. As noted above, we used this setting for technical reasons in order to follow the argument in [10]. Hiyu Inoue of Hiroshima University has pointed out that a useful characterization can also be obtained when reflexivity is defined using suffix removal alone, that is, byS=L_{\mathcal{P}}^{\mathsf{s u f}}\big(L_{\mathcal{P}}^{\mathsf{s u f}}(S)\setminus{\varepsilon}\big)\setminus{\varepsilon}.
We leave this discussion for another occasion. ### 6.3 Realizability In Section 3, we showed that if the subtraction set $S \subseteq \Sigma^+$ is regular, then the $\mathcal{P}$-position language $L_{\mathcal{P}}(S)$ is also regular. This naturally raises the converse question: can every regular language $W \subseteq \Sigma^*$ be realized as the $\mathcal{P}$-position language of some WordSubtraction(S) with a regular subtraction set $S \subseteq \Sigma^+$? The answer is no. In fact, a simple counterexample can already be found in the setting of ordinary subtraction games. ConsiderW={\varepsilon,a a,a a a}
over the alphabet $\Sigma = \{a\}$. In this case, $W$ cannot be the $\mathcal{P}$-position language $L_{\mathcal{P}}(S)$ for any subtraction set $S \subseteq \Sigma^+$, even without requiring $S$ to be regular. To see this, suppose that $L_{\mathcal{P}}(S) = W$. Because $a \notin W$, the position $a$ is an $\mathcal{N}$-position. This implies $a \in S$. On the other hand, $aaa$ must be an $\mathcal{N}$-position because $aa$ is a $\mathcal{P}$-position and $aaa$ can be moved to $aa$ by removing $a \in S$. This contradicts $aaa \in L_{\mathcal{P}}(S) = W$. Takuto Maki previously established necessary and sufficient conditions for a set $W$ to be realizable as the set of $\mathcal{P}$-positions of an ordinary subtraction game. He also suggested that these results can be extended to word subtraction games. This subsection summarizes these results and their extensions, and was completed with his advice and collaboration. For a language $W \subseteq \Sigma^*$, let\mathcal{S}(W)={S\subseteq\Sigma^{+}:L_{\mathcal{P}}(S)=W}.
In other words, $\mathcal{S}(W)$ is the collection of all subtraction sets that realize $W$. In the previous subsection, we considered right derivatives of languages. Left derivatives are defined similarly. For languages $L, U \subseteq \Sigma^*$, we define the left derivative of $L$ by $U$ asU^{-1}L={w\in\Sigma^{*}:u w\in L\mathrm{f o r~s o m e}u\in U}.
In particular, when $L = U = W$, we haveW^{-1}W={s\in\Sigma^{*}:w=w^{\prime}s\mathrm{w i t h s o m e}w,w^{\prime}\in W}.
If $W$ is the $\mathcal{P}$-position language, no legal move can take a word $w \in W$ to a shorter word $w' \in W$; such a move would make $w$ an $\mathcal{N}$-position because $w$ has an option $w' \in W$ that is a $\mathcal{P}$-position. Thus, every word in $W^{-1}W$ must be excluded from the subtraction set. The following theorem shows that, whenever $W$ is realizable, all remaining nonempty words can be allowed as members of a subtraction set. Theorem 6.6. Let $W \subseteq \Sigma^*$ be a language. If $\mathcal{S}(W) \neq \emptyset$, then the language $S_{\max} \subseteq \Sigma^+$ defined asS_{max}=(W^{-1}W)^{c}
is the maximum element of $\mathcal{S}(W)$ with respect to set inclusion. Proof. Assume that $\mathcal{S}(W)$ is nonempty, and let $S \in \mathcal{S}(W)$ be a subtraction set realizing $W$. Because no legal move in WordSubtraction($S$) can take a word in $W$ to another word in $W$, we have $S \cap W^{-1}W = \emptyset$, that is, $S \subseteq (W^{-1}W)^c = S_{\max}$. Therefore, it suffices to show that $L_{\mathcal{P}}(S) = L_{\mathcal{P}}(S_{\max})$. Let us show that for every $w \in \Sigma^*$, $w \in L_{\mathcal{P}}(S) \iff w \in L_{\mathcal{P}}(S_{\max})$ by induction on $|w|$. First, it is clear that $w \in L_{\mathcal{P}}(S) \cap L_{\mathcal{P}}(S_{\max})$ if $w = \varepsilon$. Next let $w \neq \varepsilon$, and assume as the induction hypothesis thatw^{\prime}\in L_{\mathcal{P}}(S)\quad\Longleftrightarrow\quad w^{\prime}\in L_{\mathcal{P}}(S_{\max})
for every proper prefix $w'$ of w. Suppose that $w \in L_{\mathcal{P}}(S)$ but $w \notin L_{\mathcal{P}}(S_{\max})$, and derive a contradiction. By $w \in L_{\mathcal{N}}(S_{\max})$, there are a $\mathcal{P}$-position $w' \in L_{\mathcal{P}}(S_{\max})$ and a word $s \in S_{\max}$ such that $w = w's$. Note that $w'$ is also a $\mathcal{P}$-position in WordSubtraction($S$) by the induction hypothesis. Now, $w \in L_{\mathcal{P}}(S) = W$ and $w' \in L_{\mathcal{P}}(S) = W$ imply that $s = (w')^{-1}w \in W^{-1}W$. This contradicts $s \in S_{\max} = (W^{-1}W)^c$. Therefore, $w \in L_{\mathcal{P}}(S_{\max})$. Conversely, suppose that $w \in L_{\mathcal{P}}(S_{\max})$. Then, every option $w'$ of $w$ is an $\mathcal{N}$-position in WordSubtraction($S_{\max}$). Because $S \subseteq S_{\max}$ by the first paragraph, every legal move in WordSubtraction($S$) is also legal in WordSubtraction($S_{\max}$). Thus, every option of $w$ in WordSubtraction($S$) must also belong to $L_{\mathcal{N}}(S_{\max})$. By the induction hypothesis, every option of $w$ belongs to $L_{\mathcal{N}}(S)$, and hence $w \in L_{\mathcal{P}}(S)$. This completes the induction and proves that $L_{\mathcal{P}}(S) = L_{\mathcal{P}}(S_{\max})$. Applying this result, we obtain a characterization of when a language W is realizable. Theorem 6.7. Let $W \subseteq \Sigma^*$ be a language. Then $\mathcal{S}(W) \neq \emptyset$ if and only ifW(W^{-1}W)^{c}=W^{c}.
Proof. Suppose first that $\mathcal{S}(W) \neq \emptyset$. By Theorem 6.6, the subtraction set $S_{\max} = (W^{-1}W)^c$ realizes W. Therefore,W^{c}=L_{\mathcal{N}}(S_{\max})=L_{\mathcal{P}}(S_{\max})S_{\max}=W(W^{-1}W)^{c}.
Conversely, suppose that $W(W^{-1}W)^c = W^c$. It suffices to show that $W = L_{\mathcal{P}}(S_{\max})$. By the Partition Theorem, we need to show that every option of a word in $W$ lies outside $W$, and that every word outside $W$ has an option in $W$. First, suppose that $w \in W$. If a legal move from $w$ led to another word $w' \in W$, we would have $w = w's$ for some $s \in S_{\max}$. But $w', w \in W$ would imply $s \in W^{-1}W$, contradicting the definition of $S_{\max}$. Therefore, every option of a word in $W$ lies outside $W$. Next, suppose that $w \notin W$. By the assumed equality $W(W^{-1}W)^c = W^c$, we can write $w = w's$ with $w' \in W$ and $s \in S_{\max}$. Removing the suffix $s$ is therefore a legal move from $w$ to a word in $W$. Hence $W = L_{\mathcal{P}}(S_{\max})$ and $\mathcal{S}(W) \neq \emptyset$. Thus, realizability can be characterized using only concatenation, left derivatives, and complement. For a regular language $W$, these operations preserve regularity. Corollary 6.8. Let $W \subseteq \Sigma^*$ be a regular language. If $\mathcal{S}(W) \neq \emptyset$, then there exists a regular subtraction set $S \subseteq \Sigma^+$ such that $W = L_{\mathcal{P}}(S)$. Proof. Let $S = (W^{-1}W)^c$. Note that $S$ is regular because the class of regular languages is closed under taking derivatives and complements. By Theorem 6.6, $\mathcal{S}(W) \neq \emptyset$ implies that the regular language $S$ belongs to $\mathcal{S}(W)$. $\square$ Exercise 6.5 strengthens this result: if $W$ is recognized by a monoid $M$ and is realizable, then there exists a subtraction set recognized by $M$ that realizes $W$. We have focused on the maximum subtraction set $S_{max}$ realizing W. It is natural to ask whether there is also a minimum subtraction set with respect to set inclusion. The situation is more complicated: even when W is realizable, such a minimum element need not exist. In such cases, we can instead ask how to find minimal subtraction sets realizing W. For ordinary subtraction games, Takuto Maki has established a method for finding such minimal sets using reflexivity, the notion discussed in the previous subsection. Maki and the first author expect that this method extends naturally to word subtraction games, but this remains to be investigated. ### 6.4 Decidability So far, we have studied the languages of winning and losing positions. We now ask whether properties of these languages can be decided algorithmically. When $S$ is given by a DFA or a CFG, the outcome of any particular position can be computed by examining its finitely many possible moves recursively. But deciding a property of all positions at once is a different question. For example, can we decide whether every nonterminal position is an $\mathcal{N}$-position? Checking positions one by one does not by itself give an algorithm that always terminates. In this subsection, we consider the following two decision problems: • Are all positions in WordSubtraction(S) P-positions? • Are all nonterminal positions in WordSubtraction(S) N-positions? The first problem is, in fact, rather simple: it asks only whether $S$ is empty. When $S$ is given by a DFA or a CFG, there is an algorithm for determining whether $S = \emptyset$. In other words, the problem is decidable. The second problem leads to a more interesting phenomenon. When $S$ is a regular language given by a DFA, the problem is also decidable. In contrast, when $S$ is a context-free language given by a CFG, the problem is undecidable. This means that no algorithm can always terminate with the correct answer for every valid input CFG. We first recall two basic facts from formal language theory. Proposition 6.9. Given a regular language $L \subseteq \Sigma^*$, for example by a DFA, it is decidable whether $L = \emptyset$. Proof. Let $\mathbf{A} = (Q, \Sigma, \delta, q_0, F)$ be a DFA. It is clear that $L(\mathbf{A}) \neq \emptyset$ if and only if there is an accepting state that is reachable from the initial state $q_0$. Here, we say that a state $q' \in Q$ is reachable from a state $q \in Q$ if there is a word $w \in \Sigma^*$ such that $\delta^*(q, w) = q'$. We can decide whether $L(\mathbf{A}) \neq \emptyset$ by computing the set $X \subseteq Q$ of states that can reach an accepting state. Initially, set $X := F$. Indeed, every accepting state can reach itself by reading the empty word $\varepsilon$. We then repeatedly apply the following rule: for each $q \in Q$ and $a \in \Sigma$, if\delta(q,a)\in X,
then add $q$ to $X$. We repeat this process until no new state is added. Because $X$ contains at most $\#(Q)$ states, this process must terminate. After the process terminates, we haveq_{0}\in X\quad\Longleftrightarrow\quad L(A)\neq\emptyset.
Thus, the problem is decidable. Proposition 6.10. Given a context-free language $L \subseteq \Sigma^*$, for example by a CFG, it is decidable whether $L = \emptyset$. Proof. Let $\mathbf{G} = (\Gamma, \Sigma, R, I)$ be a CFG. We can decide whether $L(\mathbf{G}) = \emptyset$ by a procedure similar to the one used in Proposition 6.9. We compute the set $X \subseteq \Gamma$ of productive nonterminals. Here, a nonterminal $A \in \Gamma$ is called *productive* if $A$ can derive a word consisting entirely of terminal symbols; that is, if there exists some $w \in \Sigma^*$ such that $A \Rightarrow^* w$. We start with $X := \emptyset$. For each terminal rule $A \to u \in R$ with $u \in \Sigma^*$, we add $A$ to $X$. We then repeatedly apply the following rule until $X$ is no longer updated: for each nonterminal ruleA \to u_0 A_1 u_1 \cdots A_n u_n \in R,
where $u_0, u_1, \ldots, u_n \in \Sigma^*$ and $A_1, \ldots, A_n \in \Gamma$, ifA_1, \ldots, A_n \in X,
then we add $A$ to $X$. Because $X$ contains at most $\#(\Gamma)$ nonterminals, this procedure must terminate. After the process terminates, $X$ consists exactly of the productive nonterminals. Therefore, we haveI \in X \quad \Longleftrightarrow \quad L(\mathbf{G}) \neq \emptyset,
and the problem is decidable. It follows that the first problem is decidable: **Theorem 6.11.** Given a DFA or a CFG representing $S \subseteq \Sigma^+$, it is decidable whether every position in WordSubtraction($S$) is a $\mathcal{P}$-position. Proof. Every position in WordSubtraction($S$) is a $\mathcal{P}$-position if and only if $S = \emptyset$. Indeed, if $S = \emptyset$, then no move is possible, so every position is a $\mathcal{P}$-position. Conversely, if there exists some $s \in S$, then $s$ itself is an $\mathcal{N}$-position because the first player can remove $s$ and reach the empty word. Therefore, by Propositions 6.9 and 6.10, the problem is decidable. $\square$ We next consider the second problem: whether every nonterminal position is an $\mathcal{N}$-position. This problem is slightly less trivial than the first one. For example, consider the case $S = a\Sigma^*$ with $\Sigma = \{a, b\}$. The terminal positions are precisely the words in $b^*$, while every nonterminal position contains at least one occurrence of $a$. Therefore, from any nonterminal position, the first player can win by removing the suffix beginning at the leftmost occurrence of $a$. Hence, every nonterminal position is an $\mathcal{N}$-position. First, we show that the problem is decidable when $S$ is regular. **Theorem 6.12.** Given a DFA representing $S \subseteq \Sigma^+$, it is decidable whether every nonterminal position in WordSubtraction($S$) is an $\mathcal{N}$-position. Proof. The set of nonterminal positions is $\Sigma^*S$. Thus, it suffices to decide whetherL_{\mathcal{P}}(S) \cap \Sigma^*S = \emptyset.
For this purpose, we construct a DFA recognizing $L_{\mathcal{P}}(S) \cap \Sigma^*S$ and apply Proposition 6.9. First, given a DFA $\mathbf{A}_S = (Q_S, \Sigma, \delta_S, q_S, F_S)$ such that $L(\mathbf{A}_S) = S$, we can construct a DFA recognizing $L_{\mathcal{N}}(S)$ using the method described in Section 3. By interchanging its accepting and rejecting states, we obtain a DFA $\mathbf{A}_{\mathcal{P}}$ recognizing $L_{\mathcal{P}}(S)$. Moreover, we can also construct a DFA $\mathbf{A}_{\mathrm{NT}}$ recognizing $\Sigma^*S$ by applying the subset construction to $\mathbf{N}_{\mathrm{NT}}$ constructed in Lemma 6.2. We now have a DFA $\mathbf{A}_{\mathcal{P}}$ recognizing the $\mathcal{P}$-position language $L_{\mathcal{P}}(S)$ and a DFA $\mathbf{A}_{\mathrm{NT}}$ recognizing the set of nonterminal positions $\Sigma^*S$. We can construct a DFA recognizing $L_{\mathcal{P}}(S) \cap \Sigma^*S$ using a standard construction called the product automaton. For two DFAs\mathbf{A}1 = (Q_1, \Sigma, \delta_1, q{01}, F_1) \quad \text{and} \quad \mathbf{A}2 = (Q_2, \Sigma, \delta_2, q{02}, F_2),
\mathbf{A}{1}\times\mathbf{A}{2}=(Q_{1}\times Q_{2},\Sigma,\delta,(q_{01},q_{02}),F_{1}\times F_{2}),
\delta((q_{1},q_{2}),a)=(\delta_{1}(q_{1},a),\delta_{2}(q_{2},a))
for each $(q_1, q_2) \in Q_1 \times Q_2$ and $a \in \Sigma$. The two components simulate $\mathbf{A}_1$ and $\mathbf{A}_2$ on the same input. The product accepts exactly when both components accept, soL(\mathbf{A}{1}\times\mathbf{A}{2})=L(\mathbf{A}{1})\cap L(\mathbf{A}{2}).
We apply this construction to $\mathbf{A}_{\mathcal{P}}$ and $\mathbf{A}_{\mathrm{NT}}$, and then use Proposition 6.9 to test emptiness. This determines whetherL_{\mathcal{P}}(S)\cap\Sigma^{*}S=\emptyset
and gives the desired answer. For context-free subtraction sets, the same automata construction is no longer available. However, the failure of this method alone does not imply undecidability. The next theorem shows that no algorithm can solve the problem for all context-free subtraction sets. Theorem 6.13. Given a CFG representing $S \subseteq \Sigma^+$, it is undecidable whether every nonterminal position in WordSubtraction(S) is an $\mathcal{N}$-position. Proof. We give a reduction from the universality problem for CFGs, which is undecidable. That is, given a CFG $\mathbf{G}$ over an alphabet $\Delta$, it is undecidable whether $L(\mathbf{G}) = \Delta^*$. (See, e.g., Theorem 5.13 of [21] for details.) Let $L = L(\mathbf{G}) \subseteq \Delta^*$. Choose a fresh symbol $\notin \Delta$, let $\Sigma = \Delta \cup \{\}$, and defineS=(L\mathbb{)}^{+}\cup{\mathbb{}}\cup\Sigma^{*}\Delta.
A CFG generating $S$ can be effectively constructed from $\mathbf{G}$ using the standard constructions for union, concatenation, and positive closure. Moreover, $S \subseteq \Sigma^+$. Because $\Sigma \subseteq S$, the only terminal position is $\varepsilon$. We show that every nonterminal position is an $\mathcal{N}$-position if and only if $L = \Delta^*$. Suppose first that $L = \Delta^*$. Every nonempty word ending in a letter of $\Delta$ belongs to $\Sigma^* \Delta$. Also, every word ending in $\$ can be written asu_{1}$u_{2}$ \cdots u_{k}$
with $u_i \in \Delta^*$, $k \geq 1$, and hence belongs to $(L\mathbb{)}^+$. Thus $S = \Sigma^+$, so every nonempty position can move directly to $\varepsilon$ and is an $\mathcal{N}$-position. Conversely, suppose that $L \neq \Delta^*$, and choose $w \in \Delta^* \setminus L$. If $w = \varepsilon$, then $\$$ $\notin S$. Its only option is $\$, which is an $\mathcal{N}$-position. Thus $\$$ is a nonterminal $\mathcal{P}$-position. If $w \neq \varepsilon$, consider $w\$. Because it contains exactly one $\$ and$ $w \notin L$, we have $w\$$ $\notin S$. Thus no move removes the whole word. Every option of $w\$ is a nonempty prefix of $w$ and therefore belongs to $\Delta^+ \subseteq S$. Every such option is an $\mathcal{N}$-position because it can move directly to $\varepsilon$. Hence, $w\$ is a $\mathcal{P}$-position, which is nonterminal. Therefore, the required property holds exactly when $L(\mathbf{G}) = \Delta^*$. An algorithm deciding this property from a CFG for $S$ would decide universality for CFGs, which is impossible. These examples show that the answer depends on how the subtraction set is specified: the same question is decidable for regular subtraction sets but undecidable for context-free subtraction sets. Many other decision problems remain to be explored. 65Exercises
Exercise 6.1. Consider WordSubtraction (S) for
with . Let us compute its -position language.
-
Construct a DFA recognizing .
-
Determine the set of terminal positions and construct a DFA recognizing it.
-
Following the construction in Theorem 6.3, construct a DFA recognizing .
-
Verify that
holds.
◇
Exercise 6.2*. The result of Theorem 6.4 can be extended to regular subtraction sets such that is prefix-closed. Here, we say that a language is prefix-closed if every prefix of every word in also belongs to . For example, is prefix-closed.
-
Let be a regular language and be a DFA recognizing in which every state is reachable from the initial state. Prove that is prefix-closed if and only if no rejecting state can reach an accepting state in .
-
Prove that for a regular language , if is prefix-closed and nonempty, then
holds.
- Let be a regular subtraction set, and let be the set of terminal positions. Suppose that is prefix-closed. Following the proof of Theorem 6.4, show that
holds.
◇
Exercise 6.3. Show that the subtraction set with is not reflexive.
◇
Exercise 6.4. Let and . Let be the language defined as
Show that .
◇
Exercise 6.5*. A language is said to be recognized by a monoid if there are a monoid homomorphism and a subset such that . For example, the language of even length words is recognized by the cyclic group of order 2. Indeed, holds with the homomorphism defined as for each .
-
Show that if a language is recognized by a monoid , then the complement is also recognized by .
-
Show that if a language is recognized by a monoid , then is also recognized by . (Hint: Put and consider .)
-
Based on Theorem 6.6, show that if a language is recognized by a monoid and , then there is a language such that is also recognized by .
It is well known that a language is regular if and only if it is recognized by some finite monoid. By item 3, if is recognized by a finite monoid and , then some is recognized by the same monoid . This gives another proof of Corollary 6.8.
Studying languages through recognition by monoids is a central approach in algebraic language theory. For an introduction, see [11]; for a comprehensive reference, see [16].
Exercise 6.6*. For an ordinary subtraction game, the set of nonnegative multiples of any integer can be realized as the set of -positions by taking its complement as the subtraction set. We consider a natural generalization to word subtraction games.
A regular language is called an identity group language if there exist a finite group and a monoid homomorphism such that
where denotes the identity element of .
Let be an identity group language.
- Show that and
- Put . Show that no legal move can take a word in to another word in , while every word outside has a legal move to . Use the Partition Theorem to conclude that
- Apply Theorem 6.6 to show that is the maximum element of with respect to set inclusion.
Thus, every identity group language can be realized as the -position language of a word subtraction game, with its complement as the maximum subtraction set.
Exercise 6.7*. Let be a regular language given by a DFA .
- Let be the set of accepting states reachable from . For each , let be the DFA obtained from by changing only the initial state to . Show that
-
Using item 1 and closure under complement and concatenation, describe how to construct a DFA recognizing .
-
Show that it is decidable whether there exists a subtraction set such that .
Exercise 6.8. Let and be regular languages given by DFAs. For each of the following problems, describe an algorithm that decides whether the answer is yes or no.
-
Does contain at least one word that is an -position in WordSubtraction()?
-
Is every word in an -position in WordSubtraction()?
Open Problems
Problem 6.1 (Can the problem in Theorem 6.12 be solved in polynomial time?). As stated in Theorem 6.12, given a DFA representing a subtraction set , it is decidable whether every nonterminal position is an -position. However, the decision procedure constructs a DFA recognizing . As discussed in Section 3, this construction is essentially an instance of the subset construction, and the resulting product
can have exponentially many states.
Can this property be decided in time polynomial in the size of the input DFA, without explicitly constructing a DFA for ? Even if recognizing the full position language requires many states, deciding this particular property could be easier. ◇
7 Research Background and Further Directions
This project began when Yuji Komatsu of Nagoya University, who introduced the first author to combinatorial game theory, encouraged him to explore connections between combinatorial games and formal language theory. Around the same time, Professor Ryuya Hora of ZEN University, who has contributed extensively to both formal language theory and combinatorial game theory, pointed out several connections between the two fields and helped bridge the communities working in them. In particular, he drew attention within these communities to the analogy between game quotients and syntactic monoids, which we discuss below.
The idea of word subtraction games emerged from a more general framework of derivation games. Around the end of 2025, the first author noticed that the computation of Grundy numbers using mex and nim-sum in normal-play games has a structural resemblance to weight computation in weighted context-free grammars. The first author formulated this analogy in terms of derivation games in [9]. In our work, word subtraction games first appeared there as a concrete example of this framework. In fact, the prefix-removal version of Example 1.6 in this note already appeared in [9]. Its interesting behavior was investigated by Hiyu Inoue and Professor Shun-ichi Kimura, together with other members of the research group at Hiroshima University, including the second author, Hiroki Inazu, Takahiro Yamashita, and Kosaku Watanabe.
It is worth noting that word subtraction games are not an entirely new idea. The suffix-removal version considered here already appears in Hetyei's work [7] under the name truncation game, in connection with Bernoulli games and enumeration problems. Our emphasis here is different: we focus on the relationship between the language class of the subtraction set and those of the corresponding position languages.
Over the following months, several interesting results on word subtraction emerged through discussions in different communities. In particular, Professor Hiroyuki Seki of Mukogawa Women's University and Professor Yoshiaki Takata of Kochi University of Technology studied derivation games restricted to right-linear grammars in detail [22]. This special class is closely related to word subtraction. Their work was the first to give an explicit proof of the fact stated in Theorem 2.9 although the techniques are quite different from those used here. Moreover, many of the ideas underlying Section 3 are due to Yoshiaki Takata.
Around the same time, Yushin Kusajima and Shunya Oguchi, students in the first author's research group, investigated the case where the subtraction set is context-free, which is the subject of Section 4. Their work showed that the general case is considerably more complicated, and raised several questions about where the boundary lies between the regular and context-free cases.
Since the summer of 2026, the first author has had several opportunities to present these results to researchers in combinatorial game theory. The discussions on these occasions have led to further observations and questions.
In particular, with the help of the second author, we obtained several interesting results concerning misère play, which are discussed in Section 6.1. He had already been in contact with the first author for some time and has a strong understanding of both formal language theory and combinatorial game theory. This naturally led to his joining the project.
We also benefited greatly from the advice and collaboration of Takuto Maki of Kagoshima University, who has extensive knowledge of reflexivity and realizability for ordinary subtraction sets. His insights and suggestions directly contributed to the material presented in Sections 6.2 and 6.3. These discussions also provided an answer to a question that had been of particular interest to the first author: which languages can arise as -position languages of word subtraction games?
Several specific open problems have already been stated throughout the note. We conclude with some broader topics for further study.
Grundy functions. This note has focused primarily on - and -positions, but the full
Grundy function
contains more information. Section 3 shows that, for a regular subtraction set and each fixed , the words with Grundy number form a regular language. This provides a starting point for further study. For example, when is the Grundy function bounded, and how efficiently can its values be computed? Understanding these functions is also important when several word subtraction games are combined by disjunctive sum.
Games with heap splitting. Subtraction games can be generalized to games in which a heap can be split as part of a move, giving rise to the well-known classes of octal games and code games; see, for example, [3, 20]. We would like to define corresponding games on words and find methods for analyzing them. For example, after removing an infix from a word , we could keep and as two independent components, rather than concatenate them as in Section 5.2. Positions would then consist of finite collections of words, and Grundy numbers would describe how the components combine.
A related construction appears in the derivation game introduced in [9], which was formulated as a special case of a word version of a code game. Its main purposes were to explore the connection between Grundy computation and context-free grammars and to prove an undecidability result. It was not introduced as a general framework for studying word versions of code games.
Partizan games. Throughout this note, both players have had the same legal moves. A natural extension is to allow Left and Right to use different subtraction sets. One can then ask how the language classes of these sets affect the languages of positions in the four outcome classes , and . Another possibility is to allow Left to remove prefixes and Right to remove suffixes. With the subtraction sets used for End-Nim in Section 5.1, this gives a word version of partizan End-Nim, which has already been studied (see Section 2.6 of [2]).
Computational complexity. Although computational complexity has been briefly mentioned in several open problems, it has not been a main focus of this note. The complexity of various problems concerning word subtraction games is another interesting direction for further study. For example, consider a word of length in the two-sided game of Section 5.1. Once membership in and has been recorded for every infix of , its outcome can be computed in time by dynamic programming over intervals: there are intervals, and each has possible moves. This resembles the interval-based computation used in the CYK algorithm. More generally, computational complexity questions for word subtraction games could provide an interesting meeting point for combinatorial game theory, formal language theory, and algorithms.
Concatenation sum and game quotients. In combinatorial game theory, one can compare positions by asking whether they have the same outcome when combined with other positions. In the theory of misère quotients, for example, one considers a set of positions closed under disjunctive sum and taking options, and identifies two positions when they have the same outcome after adding any other position in the set [17]. As Ryuya Hora pointed out in discussions between the two communities, this idea is closely related to the construction of syntactic monoids in formal language theory.
The second author recently proposed considering concatenation as a sum operation on word positions. For simplicity, fix a subtraction set and consider the suffix-removal version. For two positions , define their concatenation sum by
The resulting word is played as a single position, so a move can cross the boundary between and . For example, if and , then
is a legal move. Thus, the two original words do not remain independent components during play.
This operation gives a concrete connection between game outcomes and familiar constructions in language theory. Write . We compare two words and by appending the same word to both. The resulting positions and have the same outcome for every if and only if
This equivalence relation is the Myhill-Nerode right congruence of . When is regular, its equivalence classes form the state set of the minimal DFA recognizing . However, these classes do not in general form a monoid under concatenation: the proposed product can depend on the representatives chosen. The right congruence guarantees only that appending a fixed word gives a well-defined transition between classes.
To obtain a monoid quotient, we instead compare positions by placing words on both sides:
This gives the syntactic congruence of W. Because this relation is preserved by concatenation on both sides, its equivalence classes form a monoid, called the syntactic monoid. When W is regular, this monoid is isomorphic to the transition monoid of its minimal DFA.
Concatenation differs from the disjunctive sum used in misère quotients, but the underlying idea is shared: two objects are identified when no allowed context can distinguish their behavior. Here, membership in the position language is exactly the outcome of the game. Thus, the analogy between game quotients and syntactic monoids becomes a direct correspondence for word positions under concatenation.
This viewpoint also suggests a connection with algebraic language theory, which studies regular languages through finite monoids. Exercise 6.5 gives an example of how monoid recognition can be used in the study of word subtraction games. We hope that these connections will encourage further exchanges between combinatorial game theory and formal language theory.
References
[1] Michael Albert and Richard Nowakowski. The game of End-Nim. The Electronic Journal of Combinatorics, 8, 2001.
[2] Michael Albert, Richard Nowakowski, and David Wolfe. Lessons in Play: An Introduction to Combinatorial Game Theory. A K Peters/CRC Press, 2nd edition, 2019.
[3] Elwyn R. Berlekamp, John H. Conway, and Richard K. Guy. Winning Ways for Your Mathematical Plays, volume 1. A K Peters, Natick, MA, 2001.
[4] Janusz A. Brzozowski and Ernst L. Leiss. On equations for regular languages, finite automata, and sequential networks. Theor. Comput. Sci., 10:19–35, 1980.
[5] Grant Cairns and Nhan Bao Ho. Some remarks on End-Nim. International Journal of Combinatorics, 2011.
[6] Ashok K. Chandra, Dexter Kozen, and Larry J. Stockmeyer. Alternation. J. ACM, 28(1):114–133, 1981.
[7] Gábor Hetyei. Enumeration by kernel positions for strongly Bernoulli type truncation games on words. J. Comb. Theory A, 117(8):1107–1126, 2010.
[8] Yusuke Inoue, Kenji Hashimoto, and Hiroyuki Seki. An ambiguity hierarchy of weighted context-free grammars. Theor. Comput. Sci., 974:114112, 2023.
[9] Yusuke Inoue, Yuji Komatsu, Hiyu Inoue, and Shun-ichi Kimura. Impartial derivation games on context-free grammars. In 30th International Conference on Implementation and Application of Automata, volume 16695 of LNCS, pages 78–91, 2026.
[10] Urban Larsson. The *-operator and invariant subtraction games. Theor. Comput. Sci., 422:52–58, 2012.
[11] Mark V. Lawson. Finite automata. In Handbook of Networked and Embedded Control Systems, pages 117–144. Birkhäuser, 2005.
[12] Shota Mizuno, Ryo Yoshinaka, and Ayumi Shinohara. StrNim: a variant of Nim played on strings. arXiv preprint arXiv:2503.16781, 2025.
[13] Edward F. Moore. Gedanken-experiments on sequential machines. In Automata Studies, volume 34 of Annals of Mathematics Studies, pages 129–153. Princeton University Press, Princeton, NJ, 1956.
[14] Richard J. Nowakowski, Gabriel Renault, Emily Lamoureux, Stephanie Mellon, and Timothy Miller. The game of Timber! Journal of Combinatorial Mathematics and Combinatorial Computing, 85:213–225, 2013.
[15] Rohit Parikh. On context-free languages. J. ACM, 13(4):570–581, 1966.
[16] Jean-Éric Pin. Mathematical foundations of automata theory, 2025. Version of March 24, 2025.
[17] Thane E. Plambeck and Aaron N. Siegel. Misère quotients for impartial games. J. Comb. Theory A, 115(4):593–622, 2008.
[18] Arto Salomaa and Matti Soittola. Automata-Theoretic Aspects of Formal Power Series. Texts and Monographs in Computer Science. Springer, 1978.
[19] Hiroyuki Seki, Takashi Matsumura, Mamoru Fujii, and Tadao Kasami. On multiple context-free grammars. Theor. Comput. Sci., 88(2):191–229, 1991.
[20] Aaron N. Siegel. Combinatorial Game Theory, volume 146 of Graduate Studies in Mathematics. American Mathematical Society, Providence, RI, 2013.
[21] Michael Sipser. Introduction to the Theory of Computation. Cengage Learning, 3rd edition, 2013.
[22] Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki. Construction of a DFA for computing Grundy numbers in the successful derivation games on right-linear grammars. arXiv preprint arXiv:2609.00871, 2026.
[23] Willem A. Wythoff. A modification of the game of Nim. Nieuw Archief voor Wiskunde, 7:199–202, 1907.