For a word x, let xR denote the reverse of x; i.e., if x=a1a2…ak, then xR=ak…a2a1. For a language L, let LR={xR∣x∈L}. For a word x and a suffix y of x, let x/y denote the right quotient of x with respect to y; i.e., x/y equals the word z such that x=zy. For a word y and a prefix x of y, x\y denotes the left quotient of y with respect to x; i.e., x\y equals the word z such that y=xz.
For positions Q,Q′ of a combinatorial game, we write Q⇝Q′ if there exists a legal move from Q to Q′. The game graph of a game is the directed graph where the nodes are the positions and each edge represents a legal move.
Definition 1 (context-free grammar). A context-free grammar (or CFG) is a 4-tuple G=(Γ,Σ,R,I) where
-
Γ is a finite set of nonterminal symbols,
-
Σ is a finite set of terminal symbols,
-
I∈Γ is the initial symbol, and
-
R⊆Γ×(Γ∪Σ)+ is a finite set of rules.
A rule A→β is called a terminal rule if β∈Σ+. A rule A→B is called a unit rule if B∈Γ. In this paper, we consider only CFGs without a cycle of unit rules; i.e., if CFG G has a unit rule A→B∈R, then there is no derivation of the form B⇒∗A. This condition is imposed to ensure that derivations are of finite length. A derivation α⇒∗β with α,β∈(Γ∪Σ)+ is defined in the usual way.
A CFG G is linear if the right-hand side of each rule of G contains at most one nonterminal. A linear CFG G is right-linear if the right-hand side of each rule is an element of Σ+∪Σ∗Γ.
For each nonterminal A∈Γ, let L(G,A) be the language defined as
L(G,A)={w∈Σ+∣there is a derivation of the form A⇒∗w}.
The language generated by G=(Γ,Σ,R,I) is defined as L(G)=L(G,I).
Definition 2 (successful derivation game [4]). For a CFG G=(Γ,Σ,R,I) and a word w∈L(G), the successful derivation game (G,w) is the two-player combinatorial game defined as follows.
– A position is a finite multiset of the form
{(A1,w1),(A2,w2),…,(Aℓ,wℓ)}
where (Ai,wi)∈Γ×Σ+ and wi∈L(G,Ai) for each 1≤i≤ℓ.
– A legal move from a position Q is defined as follows. First, the current player chooses an element (A,w) of Q. Next, the player chooses a sequence (A1,w1),…,(Aℓ,wℓ)∈Γ×Σ+ with ℓ≥0 such that
• wi∈L(G,Ai) for each i, and
• A→u0A1u1…uℓ−1Aℓuℓ∈R where w=u0w1u1…uℓ−1wℓuℓ.
Finally, the position Q is updated to
Q′=(Q−{(A,w)})∪{(A1,w1),…,(Aℓ,wℓ)}.
– The game starts from the initial position Q0={(I,w)}, and the players alternate making legal moves Qi⇝Qi+1 for each i≥0. The player who is unable to move loses.
Let mex:Pfin(N)→N be the function defined as mex(X)=min(N−X), which means “the minimum excluded value.”
Definition 3 (Grundy number). For a position Q of an impartial, loop-free combinatorial game G, the Grundy number GG(Q)∈N is defined as
GG(Q)=mex({GG(Q′)∣Q⇝Q′}).
Note that if Q has no successive position, then GG(Q)=0 by definition.
It is well known that if G is a normal-play game, then GG(Q)=0 iff the next player has a winning strategy at Q (Sprague-Grundy theorem) [3,6].
Since we assume that a given CFG G has no cycle of unit rules, the SDG on G is loop-free and we can define the Grundy numbers of positions in the game as the same as Definition 3.
Example 1 (Subtraction game with colored stones). Consider an RLG G=({A},Σ,R,A) where Σ={a,b} and R={A→aA∣aaA∣bA∣a∣aa∣b}, which equals the grammar CSub described in Examples 4 and 7 in [4]. The SDG on
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki

Fig. 1. A partial game graph of the successful derivation game in Example 1.
G represents a game in which each player can remove one a, two a's, or one b from left to right.
Figure 1 shows a partial game graph of the SDG on G. In the graph, each singleton position {(A,w)} is written as (A,w) for simplicity. The graph contains every position (A,w) such that ∣w∣≤3. The graph also shows the Grundy number of each position. For example, GG({(A,a)})=1 since {(A,a)} has only one successor position ∅ whose Grundy number is zero, and GG({(A,aa)})=2 since {(A,aa)} has two successor positions {(A,a)} and ∅ whose Grundy numbers are one and zero, respectively.
In the following, we consider Grundy numbers of positions of a successful derivation game on a CFG G=(Γ,Σ,R,I). For a position Q of a successful derivation game (G,w) on G, let GG(Q) denote the Grundy number of Q, because w is irrelevant to the value of Q's Grundy number.
For each nonterminal A∈Γ, define the function GG,A:Σ+→N∪{⊥} as
GG,A(w)={GG({(A,w)})⊥if w∈L(G,A)otherwise
for each w∈Σ+.
Inoue et al. have shown the following propositions [4].
Proposition 1 (computability of GG,A). For a CFG G=(Γ,Σ,R,I), a nonterminal A∈Γ, and a word w∈Σ+, GG,A(w) can be computed in polynomial time with respect to the length of w.
Proposition 2 (boundedness of GG,A). For a linear CFG G=(Γ,Σ,R,I) and a nonterminal A∈Γ, there is an upper bound mA∈N such that GG,A(w)≤mA for each w∈L(G,A).
Proposition 3 (undecidability of maxGG,A). The problem to compute the least upper bound of Grundy numbers in the SDG, defined below, is undecidable even if the input CFG G is restricted to be linear.
MAX-GRUNDY-NUMBER-IN-SDG
-
Instance: a CFG G=(Γ,Σ,R,I), a nonterminal A∈Γ, and k∈N.
-
Question: maxw∈L(G,A)(GG,A(w))=k ?
In this paper, we show that the problem MAX-GRUNDY-NUMBER-IN-SDG described in Proposition 3 becomes decidable if we restrict the input CFG G to be right-linear. More generally, we show that we can construct a DFA representing the set of positions with a given Grundy number c, and the above problem can be reduced to the emptiness problem for these DFAs.
3 DFA Representing the Set of Positions With a Given Grundy Number
From here, we concentrate on the SDG on a given right-linear grammar (RLG) G. In this section, we describe an algorithm for constructing a DFA MA,i for each pair of a nonterminal A of G and a number i≤mA (mA is an upper bound of GG,A(w) described in Proposition 2) that satisfies
wR∈L(MA,i)⟺GG,A(w)=i.
We can compute maxw∈L(G,A)GG,A(w) by checking the emptiness of L(MA,i) for each i≤mA, because
w∈L(G,A)maxGG,A(w)=m⟺L(MA,m)=∅ and ∀i>m.L(MA,i)=∅.
Every MA,i shares the same state set Q, start state q0, and transition function δ, differing only in the set of final states.
Before showing the algorithm for constructing MA,i, we describe a concrete method to define an upper bound mA of GG,A(w).
3.1 Defining an Upper Bound mA
Let a given RLG be G=(Γ,Σ,R,I). For each A∈Γ and a∈Σ, define the following sets:
TA,a={x∈Σ∗∣A→ax∈R},
NA,a={xB∈Σ∗Γ∣A→axB∈R},
UA={C∈Γ∣A→C∈R}.
Then, define an upper bound mA of GG,A(w) as
mA=a∈Σmax(⌊NA,a⌋+sign∣TA,a∣)+∣UA∣,
where signx=1 if x>0 and signx=0 otherwise, because GG,A(w) is never greater than the number of legal moves from a position {(A,w)}.
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki
3.2 Construction of MA,i
Let a given RLG be G=(Γ,Σ,R,I) and let the constructed DFA be MA,i=(Q,Σ,δ,q0,FA,i) for each A∈Γ and i≤mA. Note that the Grundy number of a position is determined by the ones of the successor positions of it, and in the SDG on an RLG, the word w′ in a successor position {(B,w′)} of position {(A,w)} should be a suffix of w. Hence, we design MA,i as a DFA that reads a word w from right to left and keeps track of the Grundy number of position {(B,w′)} for each nonterminal B and each suffix w′ of w.
The construction of MA,i is performed through the following five steps.
- Divide the rule set R into the following three sets RN, RU, and RT. Moreover, introduce a new symbol E and define a set RT′ of modified terminal rules as follows. We consider E as a nonterminal and let mE=0.
RU={A→B∈R∣B∈Γ}, the set of unit rules,
RT={A→x∈R∣x∈Σ+}, the set of terminal rules,
RN={A→xB∈R∣x∈Σ+, B∈Γ}=R−(RU∪RT).
RT′={A→xE∣A→x∈RT}.
Define a total order <Γ over Γ that satisfies B<ΓA whenever A→B∈RU. (Such ordering can be obtained by topological sorting of the directed graph (Γ,RU). Since unit rules of G do not form a cycle, (Γ,RU) is acyclic.)
- Define the following Γ′ and ΓN, and let Q=P(Γ′∪ΓN) and q0={E0}.
Γ′={Ai∣A∈Γ∪{E}, 0≤i≤mA},
ΓN={xBi∣A→yxB∈RN∪RT′, y,x∈Σ+, Bi∈Γ′}.
- For q∈Q, a∈Σ, and A∈Γ, define the following JA,q,a and δA′(q,a). We apply this step to A∈Γ in the order according to <Γ; thus, the value of δB′(q,a) for every B satisfying A→B∈RU has already been determined.
JA,q,a={j∣A→axB∈RN∪RT′,x∈Σ∗,xBj∈q}∪{j∣A→B∈RU,Bj∈δB′(q,a)}.
δA′(q,a)={∅{Amex(JA,q,a)}if JA,q,a=∅otherwise.
- For q∈Q and a∈Σ, define δ(q,a) as follows.
δ(q,a)=A∈Γ⋃δA′(q,a)∪{axBj∈ΓN∣x∈Σ∗,xBj∈q}.
- Let FA,i={q∈Q∣Ai∈q} for A∈Γ and i≤mA.

Fig. 2. The state of MX,i just after reading (aw′)R.
The above DFA MX,i is designed based on the following idea: Assume that MX,i has just read a suffix w′ of some word from right to left (or equivalently read (w′)R from left to right) and reached a state q, and then it is reading a symbol a (Fig. 2). Let w=aw′. Then, JA,q,a in Step 3 represents the set of the Grundy numbers of the successor positions of position {(A,w)}. MX,i has already read every suffix of w′ and keeps information on the Grundy numbers of the successor positions of {(A,w)} inside the state q. JA,q,a can be computed using the information in q and the rules in RN∪RT′∪RU. Set δA′(q,a), which is either a singleton set or the empty set, represents the Grundy number of {(A,w)} determined by JA,q,a. (JA,q,a and δA′(q,a) become empty iff {(A,w)} is not a position, i.e., w∈/L(G,A).) In Step 4, the information in δA′(q,a) for every A∈Γ is gathered into δ(q,a), with some elements of ΓN each of which represents an intermediate state of a single production rule and is possibly used later for computing J.
4 Correctness of the Construction of DFAs
We fix a given RLG G=(Γ,Σ,R,I) in this section. Let MA,i=(Q,Σ,δ,q0,FA,i) for A∈Γ and i≤mA be the DFA constructed from G by the algorithm in Section 3. Let δ∗:Q×Σ∗→Q be the extension of δ to strings; i.e., δ∗(q,ε)=q and δ∗(q,xa)=δ(δ∗(q,x),a) for q∈Q, x∈Σ∗, and a∈Σ.
For convenience of proof, we consider {(E,ε)} is a position and is equivalent to the final empty position; i.e., {(A,w)}⇝{(E,ε)} if and only if A→w∈RT. Moreover, GG,E(ε)=0 and GG,E(w)=⊥ for any w∈Σ+.
Lemma 1. For w∈Σ∗, B∈Γ∪{E}, j≤mB, x∈Σ+ such that xBj∈ΓN,
xBj∈δ∗(q0,w)⟺Bj∈δ∗(q0,w/(xR)).
Proof. Let k=∣x∣ and x=x1…xk where xi∈Σ for 1≤i≤k. Assume that xBj∈ΓN. By the definition of ΓN, xBj∈ΓN implies x2…xkBj∈ΓN, …, xkBj∈ΓN.
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki
(Only-if part) Assume that xBj∈δ∗(q0,w). Since q0={E0} and x∈Σ+, w=ε holds. Let w=w′a where w′∈Σ∗ and a∈Σ. Since δ∗(q0,w)=δ(δ∗(q0,w′),a) and by the definition of δ, the following equivalence holds.
xBj∈δ∗(q0,w)⟺x1=a∧x2…xkBj∈δ∗(q0,w′).
Applying the same expansion to x2…xkBj∈δ∗(q0,w′) repeatedly, we obtain the following equivalence.
xBj∈δ∗(q0,w)⟺∃w′′. w=w′′xR∧Bj∈δ∗(q0,w′′).
The right-hand side implies Bj∈δ∗(q0,w/(xR)).
(If-part) Assume that Bj∈δ∗(q0,w/(xR)). This means that w=w′′xR for some w′′∈Σ∗. Therefore, by traversing the above equivalence in the only-if part conversely, we obtain xBj∈δ∗(q0,w).
Lemma 2. For w∈Σ∗, A∈Γ∪{E}, i≤mA,
Ai∈δ∗(q0,w)⟺GG,A(wR)=i.
Proof. We prove this lemma by induction on the length of w.
(Base case) Since δ∗(q0,ε)=q0={E0}, Ai∈δ∗(q0,ε) implies A=E and i=0, and hence GG,A(wR)=GG,E(ε)=i holds. For the converse, GG,A(ε)=⊥ implies A=E and GG,A(ε)=0, and hence Ai=E0∈δ∗(q0,ε) holds.
(Inductive step) Assume ∣w∣>0. As the induction hypothesis, we assume that for every y∈Σ∗ with ∣y∣<∣w∣, B∈Γ∪{E}, and j≤mB,
Bj∈δ∗(q0,y)⟺GG,B(yR)=j.(1)
When ∣w∣>0, Ai∈δ∗(q0,w) implies A=E and so does GG,A(wR)=⊥. Hence, we assume A=E in the following.
Let w=w′a for w′∈Σ∗ and a∈Σ. Also let q=δ∗(q0,w′). Note that δ∗(q0,w)=δ(q,a). We define S as the set of the successor positions of {(A,wR)}; i.e., S={s∣{(A,wR)}⇝s}. We show Ai∈δ∗(q0,w)⟺GG,A(wR)=i by induction on the order of A according to <Γ. A key point is to show that JA,q,a={GG(s)∣s∈S} and thus GG({(A,wR)})=mex(JA,q,a).
(Base case of the inner induction) Assume that there is no B∈Γ such that A→B∈RU. Hence, JA,q,a={j∣A→axB∈RN∪RT′,x∈Σ∗,xBj∈q}.
Assume that {(B,y)}∈S for B∈Γ∪{E} and y∈Σ∗. By the definition of the game, {(B,y)}∈S if and only if A→axB∈RN∪RT′ for some x∈Σ∗ such that wR=axy and GG,B(y)=⊥. Let j=GG,B(y). By the induction hypothesis (1), GG,B(y)=⊥ implies that Bj∈δ∗(q0,yR). If x=ε, then A→axB∈RN∪RT′ implies xBj∈ΓN, which is followed by xBj∈δ∗(q0,w′) by Lemma 1. If x=ε, then w′=yR and thus xBj∈δ∗(q0,w′) holds. Therefore, GG,B(y)∈JA,q,a holds in any case, and hence {GG(s)∣s∈S}⊆JA,q,a.
For the converse, assume that j∈JA,q,a. Then, A→axB∈RN∪RT′ for some B∈Γ∪{E} and x∈Σ∗ and xBj∈q=δ∗(q0,w′). If x=ε, then GG,B((w′)R)=
j holds by the induction hypothesis (1). If x=ε, then xBj∈ΓN, which is followed by Bj∈δ∗(q0,w′/(xR)) by Lemma 1. This implies GG,B(x\(w′)R)=j by (1). In any case, GG,B(y)=j=⊥ for y=(ax)\(wR), and thus {(B,y)}∈S. Therefore, JA,q,a⊆{GG(s)∣s∈S}. Since we have shown JA,q,a={GG(s)∣s∈S}, GG({(A,wR)})=max(JA,q,a) holds.
Assume that Ai∈δ∗(q0,w)=δ(q,a). By the definition of δ, Ai∈δA′(q,a) holds. By the definition of δA′, JA,q,a=∅ and mex(JA,q,a)=i, which is followed by GG,A(wR)=i. For the converse, assume that GG,A(wR)=i. Since GG,A(wR)=⊥, wR∈L(G,A) and thus S=∅. Hence, JA,q,a=∅ and δA′(q,a)={Ai}, which is followed by Ai∈δ(q,a).
(Inductive step of the inner induction) As the induction hypothesis, we assume that for every B∈Γ with B<ΓA and j≤mB,
Bj∈δ∗(q0,w)⟺GG,B(wR)=j.(2)
Note that by the definition of δ, Bj∈δ∗(q0,w) if and only if Bj∈δB′(q,a).
By definition, JA,q,a={j∣A→axB∈RN∪RT′,x∈Σ∗,xBj∈q}∪{j∣A→B∈RU,Bj∈δB′(q,a)}. In a similar way to the base case, we can show that JA,q,a={GG(s)∣s∈S}, and thus GG({(A,wR)})=mex(JA,q,a) holds. In the same way as the base case, we obtain Ai∈δ(q,a)⟺GG,A(wR)=i. □
Theorem 1. For w∈Σ+, A∈Γ, i≤mA,
wR∈L(MA,i)⟺GG,A(w)=i.
Proof. This follows directly from Lemma 2, since wR∈L(MA,i) if and only if Ai∈δ∗(q0,wR) by the construction of FA,i.
Corollary 1. For any A∈Γ and c≤mA, the set {w∈Σ+∣GG,A(w)=c}, which represents the set of positions whose nonterminal parts are A and Grundy numbers equal c, is regular.
Proof. This follows directly from Theorem 1, since the class of regular languages is closed under the reverse operation.
Corollary 2. MAX-GRUNDY-NUMBER-IN-SDG where the input CFG G is restricted to be right-linear, described below, is decidable.
-
Instance: an RLG G=(Γ,Σ,R,I), a nonterminal A∈Γ, and k∈N.
-
Question: maxw∈L(G,A)(GG,A(w))=k ?
Proof. We can answer this problem by checking whether L(MA,k)=∅ and L(MA,i)=∅ for each i with k<i≤mA.
5 PSPACE-Completeness of MAX-GRUNDY-NUMBER-IN-SDG on RLGs
Lemma 3. MAX-GRUNDY-NUMBER-IN-SDG is in PSPACE if the input CFG is restricted to be right-linear.
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki
Proof. By the proof of Corollary 2, it is sufficient to show the PSPACE-solvability of deciding L(MA,i)=∅ for each k≤i≤mA. Since PSPACE = NPSPACE, we show a non-deterministic polynomial-space algorithm for deciding L(MA,i)=∅.
Let G=(Γ,Σ,R,I) be a given RLG and MA,i=(Q,Σ,δ,q0,FA,i) be the constructed DFA for G, A∈Γ and i≤mA. Note that mA≤∣R∣ for each A∈Γ by the discussion in Section 3.1. Obviously, L(MA,i)=∅ if and only if there exists a path q0q1…qn of states following the transition function δ, starting from q0 and ending at qn∈FA,i, such that n<∣Q∣. Since Q=P(Γ′∪ΓN) and ∣Γ′∣+∣ΓN∣ is a polynomial of the description length of G, each q∈Q can be stored in polynomial space. The algorithm first writes q0 into the tape and repeatedly updates state q on the tape to δ(q,a) by non-deterministically choosing a∈Σ. If it reaches a state in FA,i within ∣Q∣ update steps, then accept; otherwise, reject. The counter for counting the number of repetition at most ∣Q∣ in binary also requires only polynomial space. Therefore, the algorithm is a non-deterministic polynomial-space one that decides whether L(MA,i)=∅. □
Theorem 2. MAX-GRUNDY-NUMBER-IN-SDG where the input CFG is restricted to be right-linear is PSPACE-complete.
Proof. By Lemma 3, it is sufficient to show the PSPACE-hardness of the problem. We show a polynomial-time reduction from the following PSPACE-complete problem [1,2].
REGULAR-GRAMMAR-NON-UNIVERSALITY
– Instance: a regular grammar G=(Γ,Σ,R,I) (without ε-rules).
– Question: L(G)=Σ+ ?
A regular grammar (RG) is a right-linear grammar where the right-hand side of each rule is an element of Σ∪ΣΓ∪Γ. Note that the definition of a CFG in this paper does not allow ε-rules, i.e., rules of the form A→ε. Because checking whether ε∈L(G) and eliminating ε-rules in an RG with ε-rules can be performed in polynomial time, the problem is still PSPACE-complete for RGs without ε-rules.
Let G=(Γ,Σ,R,I) be an input RG for REGULAR-GRAMMAR-NON-UNIVERSALITY. Let GALL=({IALL},Σ,RALL,IALL) be an RG such that L(GALL)=Σ+. The reduction to MAX-GRUNDY-NUMBER-IN-SDG on RLGs constructs an RLG G′=(Γ∪{IALL,I1,…,I9},Σ,R∪RALL∪R′,I1) where R′ consists of twelve unit rules shown in the following diagram.

The diagram also shows the possible Grundy numbers for some nonterminals. For example, I5 is labeled with “nonzero,” which means that GG′,I5(w)>0 for every w∈Σ+. This is implied by the fact that either GG′,I6(w)=0 or GG′,IALL(w)=0 holds for every w∈Σ+, because GG′,I6(w)=0 whenever GG′,IALL(w)>0. (This construction is based on Lemma 2 of [4].) The fact that GG′,I5(w)>0 for every w∈Σ+ implies GG′,I4(w)=0 and GG′,I3(w)=1 for every w∈Σ+. Similarly, GG′,I8(w)>0 and GG′,I7(w)=0 for every w∈L(G′,I)=L(G), and GG′,I7(w)=GG′,I8(w)=⊥ for every w∈/L(G). Since {(I2,w)} has two successors {(I3,w)} and {(I7,w)} if w∈L(G) and has only one successor {(I3,w)} if w∈/L(G),
GG′,I2(w)={20if w∈L(G)otherwise, and GG′,I1(w)={01if w∈L(G)otherwise.
Therefore, maxw∈Σ+(GG′,I1(w))=1 if and only if there exists w∈/L(G). □
6 Examples
Example 2. Consider the same RLG as Example 1: G=({A},Σ,R,A) where Σ={a,b} and R={A→aA∣aA∣bA∣a∣aa∣b}. Let mA=3. The construction of MA,i=(Q,Σ,δ,q0,FA,i) for i≤mA is performed as follows.
Step 1: Let RN={A→aA∣aaA∣bA}, RT′={A→aE∣aaE∣bE}, and RU=∅.
Step 2: Let Γ′={A0,…,A3,E0} and ΓN={aA0,…,aA3,aE0}. Moreover, let q0={E0}.
Steps 3 and 4: For simplicity, we restrict the state set Q to the set of states reachable from q0, and we define the transition function only on the restricted Q. Starting from q0, we iteratively apply Steps 3 and 4 to a newly found state q. We obtain the following JA,q,a, δA′(q,a), and δ(q,a) for state q reachable from q0 and a∈{a,b}.
JA,{E0},a={0},δA′({E0},a)={A1},δ({E0},a)={A1,aE0}.
JA,{E0},b={0},δA′({E0},b)={A1},δ({E0},b)={A1}.
JA,{A1,aE0},a={1,0},δA′({A1,aE0},a)={A2},δ({A1,aE0},a)={A2,aA1}.
JA,{A1,aE0},b={1},δA′({A1,aE0},b)={A0},δ({A1,aE0},b)={A0}.
JA,{A1},a={1},δA′({A1},a)={A0},δ({A1},a)={A0,aA1}.
JA,{A1},b={1},δA′({A1},b)={A0},δ({A1},b)={A0}.
JA,{A2,aA1},a={2,1},δA′({A2,aA1},a)={A0},δ({A2,aA1},a)={A0,aA2}.
JA,{A2,aA1},b={2},δA′({A2,aA1},b)={A0},δ({A2,aA1},b)={A0}.
JA,{A0},a={0},δA′({A0},a)={A1},δ({A0},a)={A1,aA0}.
JA,{A0},b={0},δA′({A0},b)={A1},δ({A0},b)={A1}.
JA,{A0,aA1},a={0,1},δA′({A0,aA1},a)={A2},δ({A0,aA1},a)={A2,aA0}.
JA,{A0,aA1},b={0},δA′({A0,aA1},b)={A1},δ({A0,aA1},b)={A1}.
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki

Fig. 3. DFA (Q,Σ,δ,q0,∅) in Example 2.
JA,{A0,aA2},a={0,2},δA′({A0,aA2},a)={A1},δ({A0,aA2},a)={A1,aA0}.
JA,{A0,aA2},b={0},δA′({A0,aA2},b)={A1},δ({A0,aA2},b)={A1}.
JA,{A1,aA0},a={1,0},δA′({A1,aA0},a)={A2},δ({A1,aA0},a)={A2,aA1}.
JA,{A1,aA0},b={1},δA′({A1,aA0},b)={A0},δ({A1,aA0},b)={A0}.
JA,{A2,aA0},a={2,0},δA′({A2,aA0},a)={A1},δ({A2,aA0},a)={A1,aA2}.
JA,{A2,aA0},b={2},δA′({A2,aA0},b)={A0},δ({A2,aA0},b)={A0}.
JA,{A1,aA2},a={1,2},δA′({A1,aA2},a)={A0},δ({A1,aA2},a)={A0,aA1}.
JA,{A1,aA2},b={1},δA′({A1,aA2},b)={A0},δ({A1,aA2},b)={A0}.
Step 5: Define FA,i for 0≤i≤3 as follows.
FA,0={{A0},{A0,aA1},{A0,aA2}},
FA,1={{A1},{A1,aE0},{A1,aA0},{A1,aA2}},
FA,2={{A2,aA0},{A2,aA1}},
FA,3=∅.
Figure 3 shows the constructed DFA (Q,Σ,δ,q0,∅) without final states. By simulating the behavior of this DFA on the words of length 4 or less, we obtain the following table of languages. We can confirm that every word w appearing in this table satisfies “w∈L(MA,i)⟺GG,A(wR)=i.”
L(MA,0)={ab,ba,bb,aaa,aab,abab,abba,abbb,baab,baba,babb,bbab,bbba,bbbb,…},
L(MA,1)={a,b,aba,abb,bab,bba,bbb,aaaa,aaab,aaba,aaab,baaa,…},
L(MA,2)={aa,baa,abaa,bbaa,…},
L(MA,3)=∅.

Fig. 4. The minimum DFA equivalent to MA,0 in Example 2.

Fig. 5. A DFA recognizing L(MA,0)R in Example 2.
Figure 4 shows the minimum DFA equivalent to MA,0, and Figure 5 shows the minimum DFA recognizing L(MA,0)R. In Example 7 of [4], Inoue et al. have shown a necessary and sufficient condition on a word w to satisfy GG,A(w)=0 for this grammar G: Let w=ad1be1ad2be2…adkbek with d2,…,dk,e1,…,ek−1>0 and d1,ek≥0, and let {0,1,2}∋di′≡dimod3. Then, GG,A(w)=0 if and only if (1) di′=2 for each 1≤i≤k and ∑i=1kdi′+∑i=1kei is even, or (2) there exists 1≤m≤k such that d1′,…,dm′−1=2, dm′=2, and ∑i=1m−1di′+∑i=1m−1ei is odd. We can confirm that L(MA,0)R represented by the DFA in Fig. 5 coincides with this condition.
Example 3. We modify the RLG in Example 2 as follows: G=({A,B},Σ,R,A) where Σ={a,b} and R={A→aA∣aaA∣B∣a∣aa,B→bA∣b}.
Let mA=4 and mB=2. The construction of MX,i=(Q,Σ,δ,q0,FX,i) for X∈{A,B} and i≤mX is performed as follows.
Step 1: Let RN={A→aA∣aaA,B→bB}, RU={A→B}, and RT′={A→aE∣aaE,B→bE}. Define <Γ as B<ΓA.
Step 2: Define Γ′ and ΓN in a similar way to Example 2. Let q0={E0}.
Steps 3 and 4: As in Example 2, we restrict Q to the set of states reachable from q0 and define δ only on the restricted Q. Since B<ΓA, we define JB,q,a and δB′(q,a) before defining JA,q,a for each q and a. We obtain the following JX,q,a, δX′(q,a), and δ(q,a) for X∈{A,B}, state q reachable from q0, and a∈{a,b}. Note that JB,q,a=δB′(q,a)=∅ for any q because the right-hand side of every rule for B starts with b.
JA,{E0},a={0},δA′({E0},a)={A1},δ({E0},a)={A1,aE0}.
JB,{E0},b={0},δB′({E0},b)={B1},
JA,{E0},b={1},δA′({E0},b)={A0},δ({E0},b)={A0,B1}.
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki
JA,{A1,aE0},a={1,0},δA′({A1,aE0},a)={A2},δ({A1,aE0},a)={A2,aA1}.
JB,{A1,aE0},b={1},δB′({A1,aE0},b)={B0},
JA,{A1,aE0},b={0},δA′({A1,aE0},b)={A1},δ({A1,aE0},b)={A1,B0}.
JA,{A0,B1},a={0},δA′({A0,B1},a)={A1},δ({A0,B1},a)={A1,aA0}.
JB,{A0,B1},b={0},δB′({A0,B1},b)={B1},
JA,{A0,B1},b={1},δA′({A0,B1},b)={A0},δ({A0,B1},b)={A0,B1}.
JA,{A2,aA1},a={2,1},δA′({A2,aA1},a)={A0},δ({A2,aA1},a)={A0,aA2}.
JB,{A2,aA1},b={2},δB′({A2,aA1},b)={B0},
JA,{A2,aA1},b={0},δA′({A2,aA1},b)={A1},δ({A2,aA1},b)={A1,B0}.
JA,{A1,B0},a={1},δA′({A1,B0},a)={A0},δ({A1,B0},a)={A0,aA1}.
JB,{A1,B0},b={1},δB′({A1,B0},b)={B0},
JA,{A1,B0},b={0},δA′({A1,B0},b)={A1},δ({A1,B0},b)={A1,B0}.
JA,{A1,aA0},a={1,0},δA′({A1,aA0},a)={A2},δ({A1,aA0},a)={A2,aA1}.
JB,{A1,aA0},b={1},δB′({A1,aA0},b)={B0},
JA,{A1,aA0},b={0},δA′({A1,aA0},b)={A1},δ({A1,aA0},b)={A1,B0}.
JA,{A0,aA2},a={0,2},δA′({A0,aA2},a)={A1},δ({A0,aA2},a)={A1,aA0}.
JB,{A0,aA2},b={0},δB′({A0,aA2},b)={B1},
JA,{A0,aA2},b={1},δA′({A0,aA2},b)={A0},δ({A0,aA2},b)={A0,B1}.
JA,{A0,aA1},a={0,1},δA′({A0,aA1},a)={A2},δ({A0,aA1},a)={A2,aA0}.
JB,{A0,aA1},b={0},δB′({A0,aA1},b)={B1},
JA,{A0,aA1},b={1},δA′({A0,aA1},b)={A0},δ({A0,aA1},b)={A0,B1}.
JA,{A2,aA0},a={2,0},δA′({A2,aA0},a)={A1},δ({A2,aA0},a)={A1,aA2}.
JB,{A2,aA0},b={2},δB′({A2,aA0},b)={B0},
JA,{A2,aA0},b={0},δA′({A2,aA0},b)={A1},δ({A2,aA0},b)={A1,B0}.
JA,{A1,aA2},a={1,2},δA′({A1,aA2},a)={A0},δ({A1,aA2},a)={A0,aA1}.
JB,{A1,aA2},b={1},δB′({A1,aA2},b)={B0},
JA,{A1,aA2},b={0},δA′({A1,aA2},b)={A1},δ({A1,aA2},b)={A1,B0}.
Step 5: Define FA,i and FB,j for 0≤i≤4 and 0≤j≤2 in a similar way to Example 2. Note that FA,3=FA,4=FB,2=∅.
Figure 6 shows the constructed DFA (Q,Σ,δ,q0,∅) without final states. By simulating the behavior of this DFA on the words of length 4 or less, we obtain the following table of languages.
L(MA,0)L(MA,1)={b,bb,aaa,aba,bbb,aaab,aaba,abab,abba,baaa,baba,bbbb,…},={a,ab,ba,aab,abb,bab,bba,aaaa,aabb,abbb,baab,babb,bbab,bbba,…},

Fig. 6. DFA (Q,Σ,δ,q0,∅) in Example 3.
L(MA,2)={aa,baa,abaa,bbaa,…},
L(MB,0)={ab,aab,abb,bab,aabb,abbb,baab,babb,bbab,…},
L(MB,1)={b,bb,bbb,aaab,abab,bbbb,…},
L(MA,3)=L(MA,4)=L(MB,2)=∅.

Fig. 7. A partial game graph of the successful derivation game in Example 3.
Figure 7 shows a partial game graph of the successful derivation game on G, which contains every position (X,w) such that ∣w∣≤3 and also shows the Grundy number of each position. Note that {(B,ax)} for x∈Σ∗ is not a position
Yoshiaki Takata, Yusuke Inoue, and Hiroyuki Seki
of this game because L(G,B)=bΣ∗. We can see that the Grundy numbers in Fig. 7 satisfy “wR∈L(MX,i)⟺GG,X(w)=i.”

Fig. 8. The minimum DFA equivalent to MA,0 in Example 3.

Fig. 9. A DFA recognizing L(MA,0)R in Example 3.
Figure 8 shows the minimum DFA equivalent to MA,0, and Figure 9 shows the minimum DFA recognizing L(MA,0)R.
7 Conclusion
In this paper, we studied the successful derivation game (SDG) on a right-linear grammar (RLG) and showed that we can construct a DFA for computing the Grundy number of a given position. This means that for this game, the set of positions with a given Grundy number c is regular. As a corollary, we showed that the least upper bound of the Grundy numbers in the SDG on a given RLG is decidable, which is known to be undecidable in general for the SDG on a linear CFG. We also showed that computing the least upper bound of the Grundy numbers in the SDG on an RLG is PSPACE-complete.
References
-
Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The Design and Analysis of Computer Algorithms. Addison-Wesley (1974)
-
Garey, M.R., Johnson, D.S.: Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman & Co. (1979)
-
Grundy, P.M.: Mathematics and games. Eureka 2, 6–8 (1939)
-
Inoue, Y., Komatsu, Y., Inoue, H., Kimura, S.: Impartial derivation games on context-free grammars. In: 30th International Conference on Implementation and Application of Automata (CIAA). Lecture Notes in Computer Science, vol. 16695, pp. 78-91. Springer (2026). https://doi.org/10.1007/978-3-032-31176-4_6
-
Siegel, A.N.: Combinatorial Game Theory, Graduate studies in mathematics, vol. 146. American Mathematical Society (2013)
-
Sprague, R.: Über mathematische kampfspiele. Tohoku Mathematical Journal 41, 438-444 (1935)