1 Introduction
Given two contextfree grammars (CFGs), the equivalence problem asks whether they represent the same language; this is well known to be undecidable in general [3]. In contrast, the equivalence problem is decidable within some families of CFGs, such as deterministic CFGs [14] and (pre)NTS grammars [13, 2]. Thus, a reasonable question to ask when studying a subclass of CFGs is whether equivalence is decidable for members of this class.
One subclass of CFGs of interest to grammatical inference consists of the CFGs considered in [9], which we refer to as Clarkcongruential (CC) grammars. There it is shown that, given an oracle called the “teacher”, an algorithm can infer a language known to the teacher by posing questions about the language in a fixed format. In particular, one type of question that the teacher can answer is an equivalence query, where the algorithm supplies a CFG and asks whether it represents the language that the teacher has in mind. A similar (if slightly less general) teacher can be used to infer regular languages [1].
In analogy to other classes of CFGs, one might ask whether the equivalence problem for CC grammars is decidable; in analogy to regular languages, one might ask whether it is in principle possible to implement a teacher that answers equivalence queries for a CC grammar. Motivated by these questions, we investigate decision problems surrounding CC grammars. Our main contribution is a proof that equivalence and congruence problems for these grammars are decidable, based on arguments of that ilk for preNTS grammars [2]. We also show that it is decidable whether a deterministic CFG is CC.
The remainder of this paper is organised as follows. In Section 2, we recall some preliminary notions. In Section 3, we discuss the congruence, equivalence and recognition problems for CC grammars. We list directions for further work in Section 4. To preserve the narrative, some proofs appear in the appendices.
2 Preliminaries
A relation is said to be Noetherian if it does not admit an infinite chain, i.e., there exist no infinite sequence such that for all it holds that and . is confluent on if it is transitive and when for all such that and , there exists a with and .
Words and languages
We fix a finite set , called the alphabet, and write for the language of words over . We write for another finite alphabet that contains , and the symbol , which is not in . The empty word is denoted by . We write for the length of . We also fix an (arbitrary) total order on , and extend to an order on by defining if and only if either , or and precedes lexicographically. A prefix (resp. suffix) of is a such that there exists a with (resp. ); overlaps with if a nonempty suffix of is a prefix of , or vice versa.
A function is a morphism when for it holds that . If we define a function , then uniquely extends to a morphism , by defining for that . If for all we have that , we say that is strictly alphabetic. When is a language, we write for the language given by .
A semiThue system [7] is a reflexive and transitive relation on such that if and , then . A reduction is a Noetherian semiThue system. We say that is irreducible by a reduction if implies that .
A congruence is an equivalence on such that when and , also . If is a congruence on , we write for the congruence class containing . A congruence is finitely generated if for some finite , is the smallest congruence containing ; the set is said to generate . Any language induces a syntactic congruence, denoted , which is the relation where holds precisely when, for all , we have if and only if . The language of contexts of w.r.t. a language , denoted , is (for a distinguished symbol ). It should be clear that if and only if .
A language is congruential [7] if there exists a finitelygenerated congruence and a finite set such that . We say that is regular if its syntactic congruence induces finitely many congruence classes [11].
Decidability of congruence and of equivalence are closely related for congruential languages, as witnessed by the following lemma from [13].
Let and be congruences generated by finite sets respectively, and let be finite. Let and be given by L_1 = ⋃_t ∈T_1 [t]_∼_1 L_2 = ⋃_t ∈T_2 [t]_∼_2 If we can decide and , as well as and , then we can decide whether . Observe that precisely when and , as well as and . The first two inclusions are decidable, since and are finite, and and are decidable. The latter two inclusions are also decidable, for they are equivalent to checking whether and . Thus, we can decide whether .
Contextfree grammars
A (contextfree) grammar (CFG) is a tuple where is a finite set of symbols called nonterminals with the initial nonterminals, and is a finite set of pairs called productions. We denote by . We use to denote an arbitrary CFG , implicitly quantifying over all CFGs.
We write for the set and define as the smallest relation on such that for all and , we have . For , the language of in , denoted is ; the language of , denoted , is . We say that is a contextfree language (CFL) if for some CFG .
As an example of a CFG, let us fix as a CFG over the alphabet , where , and contains the rules and and . The language of is the wellknown Dyck language, which consists of strings of wellnested parentheses, and which we shall use as a recurring example throughout this paper.
If is nonempty, we write for the minimum of . Now, if is nonempty, then . We define as the smallest semiThue system such that whenever and , also . As an example, for we see that , and hence is generated solely by the rule .
We observe that is a reduction (regardless of ), and that for all and it holds that . We write for the set of words irreducible by . Note that is regular: it is the complement of the regular language of words containing the lefthand side of a rule defining , and regular languages are closed under complementation. For instance, it is not hard to see that .
We say that is weakly reduced when for we have that is infinite, and for all productions where is finite, we have that .
Let be a CFG, let be a regular language and let be a strictly alphabetic morphism. All of the following hold:

We can construct a weakly reduced CFG such that and ; moreover, when it holds that .

We can construct a CFG such that and ; moreover, when it holds that .

We can construct a CFG such that ; moreover, when there exist and such that .
Pushdown automata
A pushdown automaton (PDA) is a tuple where is a finite set of states, is the initial state, are the accepting states and is the (finite) transition relation. When , we write . The set of configurations of , denoted , is . We define as the smallest relation on such that whenever and as well as , it holds that . The language of , denoted , is^{2}^{2}2This definition is nonstandard, in that upon acceptance the machine should be in an accepting state, and the stack contains exactly . A (D)PDA with this acceptance condition can easily be converted into an equivalent (D)PDA with the standard acceptance condition, provided that its transitions preserve the endofstack marker; this is the case for all DPDAs in this paper. We omit details for the sake of brevity.
is a deterministic PDA if, (i) for all , , and , there is at most one and at most one such that , and, (ii) for all and such that , there are no , and such that .
If is a PDA and a language such that , we say that accepts . It is wellknown that a language is a CFL if and only if it is accepted by a PDA [8]. A language accepted by a deterministic PDA is said to be a deterministic CFL (DCFL). A CFG whose language is a DCFL is said to be a deterministic CFG (DCFG).
As an example of a PDA, consider , where contains the rules , and . This PDA happens to be deterministic, and it is not hard to see that it accepts the Dyck language, ; this makes a DCFG.
3 Clarkcongruential languages
We now turn our attention to Clarkcongruential languages. These are contextfree languages that are defined by grammars where every nonterminal has a language that is contained in a congruence class of its grammar; more formally, we work with the following definition.
is Clarkcongruential (CC) if for all , there exists an s.t. is a subset of . A language is CC if for a CC grammar .
As an example of a CC grammar, consider . There, we find that if , then consists of a string of balanced parentheses; hence, if , then , and vice versa. Consequently, it holds that for we have .
CC grammars can be seen as a generalization of preNTS grammars [2], which are themselves a generalization of NTS grammars [5, 13, 6]. While the class of CC grammars strictly contains the class of preNTS grammars, and thus the class of preNTS languages is contained in the class of CC languages, it remains an open question whether this inclusion is strict on the level of languages; likewise, the class of NTS grammars is contained in the class of preNTS grammars, but the question of equal expressiveness remains open.
3.1 Congruence and equivalence
We now consider the question of deciding equivalence of CC grammars. Our strategy here will be to verify the preconditions of Lemma 2 w.r.t. CC languages. Thus, our first task is to show that all CC languages are congruential; this is indeed the case.
If is a CC language, then is congruential. Let be a CC grammar such that and choose as the smallest congruence containing . Obviously, is finitely generated. We now claim that
For the inclusion from left to right, note that if for an , then , and hence ; thus, . For the other inclusion, note that since is CC, . Hence, if with , then , and thus .
We use to denote an arbitrary CC grammar, and set out to validate the second assumption of Lemma 2, i.e., to show that if is CC, then is decidable. To this end, we observe the following; details are in Appendix B.
The grammar transformations from Lemma 2 preserve Clarkcongruentiality.
The algorithm that we describe to decide is essentially a generalization of the one found in [2]. Before we dive into formal details, it helps to sketch a highlevel roadmap of the steps required to establish the desired result, in analogy with the steps in op. cit. We proceed as follows:

We argue that, when is CC, is almost confluent: it can be used to decide by reducing using any strategy, until we reach an irreducible word.

We show that, for a given , we can use the transformations discussed earlier to construct a particular CC grammar , which has a number of useful properties.

From , we create a DPDA accepting a language very close to ; this DPDA exploits the almostconfluent nature of and the properties of .

We argue that if and only if . Since the latter is decidable [14], we can decide the former.
Step (I): reduction is (almost) confluent
If is preNTS, then is confluent on , but not necessarily on [2]. For CC languages, this property is lost. As an example, consider the CC grammar with the rules , , and , and both and initial. We find that and , and hence as well as , but both and are irreducible in .
On the positive side, is still useful in deciding membership of : There exists an with if and only if . For the direction from left to right, note that if , then , and therefore . Since , also . For the other direction, note that if , then for some , and therefore .
Using Lemma 3.1, we can simply apply reductions (using any strategy) to from , until we reach an irreducible word . This process terminates, since is Noetherian. At that point, either for some , in which case , or for all , in which case (since ), and since , also .
As an example, consider the word [[][]], which can be reduced using as follows:
And hence . On the other hand, the word [[] can be reduced to [ only, and therefore Lemma 3.1 allows us to conclude that .
The (implicit) precondition that is CC is necessary to establish Lemma 3.1. As an example, consider the grammar with rules , and , with both and initial. This grammar is not CC. If we assume that , then is generated by the rule . We then find that and , while .
Step (Ii): construct
We now proceed to construct a CC grammar from . This is done by progressively applying the CCpreserving transformations described in Lemma 2.
First, we augment by adding for the (unique) letter , i.e., every letter gains a “primed” version; this does not change , or the fact that is CC. We write for the original alphabet, and for the set of newly added letters. Moreover, let be the morphism that removes the primes from , i.e., the morphism defined by setting for and for . We write for the “primed copy” of , i.e., the unique element of such that . We proceed to define in steps, as follows:

Let be such that .

Let be such that , where .

Let be such that , and is weakly reduced.
By Lemma 2, these grammars are CC. Without trying to get ahead of ourselves, we note that is already somewhat close to . After all, we know that . The difference between and comes down to having or separate the parts of the words, and whether those parts need to be in .
Some analysis of now gives us the following.
Let . If and , then . Suppose that . First note that we can (without loss of generality) find such that . Consequently, there exist such that . Since , this means that is a substring of or , and thus . For the remainder, it suffices to show that , and .
First, note that , and so ; thus, . Since , we have . Also, suppose towards a contradiction that . Then contains at least one primed letter. By choice of and , we find that . Now contains strictly more primed letters than ; since all words in contain exactly primed letters, we have reached a contradiction. We conclude that .
Since is the weakly reduced version of , we can show the following:
Let with . Then and either contain or share an overlap with ; more formally, one of the following holds:

and , for and a nonempty prefix of

and , for and a nonempty suffix of

and , for .
If is finite, then (since is weakly reduced), and therefore ; thus, and satisfy the third condition.
Otherwise, suppose that is infinite. First, note that there exist such that . Thus, there exist such that . Suppose, towards a contradiction, that neither contains nor overlaps with . In that case, , and ; then, since , also . By Lemma 3.1, we have that is finite. But since and the latter is infinite, we have a contradiction. Therefore must contain or overlap with .
Suppose for and a nonempty prefix of ; other cases are similar. Write and . By choice of and , we have . Therefore, for some .
This lemma tells us something about : all of its generating rules overlap with , and moreover each rule preserves . Thus, to decide whether , we can apply the rules of as described above; since every step involves (and preserves) part of , we also know that reductions must be clustered around the locus of .
Step (Iii): creating a DPDA
The above analysis allows us to construct a DPDA that accepts , by going through the following phases:

Read symbols and push them on the stack, until we encounter .

From that point on, read from the stack or the input and apply reductions whenever possible, but with standing in for the part of .

When no reductions are possible (i.e., we have reached an element if ), check whether the buffer corresponds to a for some .
In the second step, the state of the DPDA holds a buffer to the left and the right of , large enough to detect any possible reductions. Since is Noetherian, this phase must end after finitely many reductions; furthermore, since is lengthdecreasing, we can choose the size of the buffer appropriately. Formally, this DPDA is defined as follows:
We build the PDA as follows.
First, let be the maximum length of for in .
Also, and are the smallest sets satisfying
q_0 ∈Q
u, v ∈Σ_0^*
—u—, —v— ≤N
u♯v ∈Q
A ∈I_w
ϑ_G_w(A) = uw’v
u♯v ∈F
Furthermore, is the smallest transition relation satisfying
a ≠♯q_0 b, a/ba→ q_0
q_0 ♯, a/a→ ♯
u♯v ∈Q
—u— ¡ N
uw’v ∈I_G_w
a ≠$
u♯v ϵ, a/ϵ→ au♯v
u♯v ∈Q
—v— ¡ N
uw’v ∈I_G_w
a = $ ∨—u— = N
u♯v b, a/a→ u♯vb
u♯v ∈Q
uw’v ／∈I_G_w
uw’v ↝_G_w xw’y such that is minimal
u♯v ϵ, a/a→ x♯y
The first two rules take care of the first phase, where input is read onto the stack until we reach . The third and fourth rule are responsible for reading symbols from the stack and from the input buffer respectively; the last rule applies reductions. The set of accepting states makes sure that, upon acceptance, the buffer represents for an .
We note that is deterministic: if is in state , then the input is either equal to (in which case the first rule applies) or not (in which case the second rule applies); otherwise, we are in some state , then either (and so the last rule applies), or the (mutually exclusive) third or fourth rule apply.
We can then show that indeed accepts . We give a sketch of the proof below; details are in Appendix A.
[] .
Proof sketch For the inclusion from left to right, show that every change in configuration of corresponds to a step in the reduction of the input according to , and that a configuration where accepts corresponds to this reduction reaching for .
For the other inclusion, first note that if is such that , we can let read up to and including , putting on the stack. Subsequently, inspect the halting configuration reached by from that point on (which exists uniquely, for is Noetherian), and show that it is a state where can accept — i.e., that the remaining input and stack is empty, and that the buffer corresponds to an accepting state of .
Step (Iv): wrapping up
Now we can show the following. if and only if . For the direction from left to right, suppose that , and that . We can then find such that and . Now, since is CC and and , we know that . Consequently, , and therefore , meaning that . By symmetry, also implies ; this allows us to conclude that .
For the other direction, suppose that . Then such that , and . Since , it then follows that , and thus . This shows that ; the other inclusion follows symmetrically.
The above characterises the syntactic congruence of in terms of the equivalence of two DPDAs, constructible from , and . Since equivalence of DPDAs is decidable [14], it follows that we can decide . The main result then follows. It is decidable, given a CFG that is CC and , whether . It is furthermore decidable, given CFGs and that are CC, whether .
Like in [2], is oneturn, i.e., it processes input first in a phase where the stack does not shrink (when it is still in ), and subsequently in a phase where the stack does not grow (in all other states). Thus, an algorithm to test equivalence of finiteturn DPDAs [17, 4] suffices. Complexitywise, this also helps: the equivalence problem for oneturn DPDAs is known to be in conp [15], while the problem for general DPDAs is known only to be primitive recursive [16].
3.2 Recognition
The recognition problem for a class of CFGs asks, given a CFG , whether is in . This problem is decidable for NTS grammars [13], yet undecidable for a proper subclass of preNTS grammars [19].^{3}^{3}3We note that the class of CFGs considered in [19] was originally claimed to coincide with preNTS grammars [6], but this is not strictly true: Zhang’s class is a strict subclass of the preNTS grammars, although the languages that they can express are the same.
Given that our earlier decidability proofs were based on proofs of the same statement for preNTS grammars, one might ask whether we could extend the result from [19]
to CC grammars. This turns out not to be the case. The proof in op. cit. constructs, given a Turing machine
and an input , a CFG which is in the studied class if and only if does not halt on input ; this construction relies heavily on adding nonterminals with an empty language. However, we can easily adapt the first construction from Lemma 2 to show that we can remove all such nonterminals from a CFG to obtain an (equivalent) CFG ; furthermore, is CC if and only if is CC. Thus, to decide whether a given CFG is CC, we can assume without loss of generality that no nonterminal has an empty language. Hence, the undecidability proof from [19] does not generalize to CC grammars.We therefore turn our attention to finding a novel approach to the recognition problem for CC grammars, independent of (un)decidability proofs of the recognition problem for its subclasses. To this end, it is useful to introduce the following notion. Let be a congruence. is aligned if, for every , there exists a such that .
Note that, by definition, is CC if and only if it is aligned. As it turns out, alignment is decidable, provided that is decidable. Given a decidable congruence , it is decidable whether a CFG is aligned. Without loss of generality, assume that all nonterminals of have a nonempty language; if this is not the case, we can create a CFG that does have this property, and which is aligned if and only if is. Since is computable, it now suffices to prove that is aligned if and only if for all , it holds that .
For the direction from left to right, we know that if , then for some ; hence, . For the direction from right to left, a straightforward inductive argument shows that for all such that , we have that . Hence, if , then we know that , and thus it suffices to choose .
As an application of the above, let be the smallest congruence on such that . Without too much effort, we can then show that we can uniquely compute such that . Therefore, we can conclude that is decidable: to decide whether , check whether the and computed for are the same as the and computed for . Thus, by Lemma 3.2, we find that we can decide whether a given grammar over the alphabet is aligned. Indeed, turns out to be exactly .
Lemma 3.2 would also show that the recognition problem for CC grammars is decidable, provided that the congruence problem were decidable for arbitrary CFGs. Unsurprisingly, this is not the case, as witnessed by the following lemma. It is undecidable, given a CFG and words , whether . We claim that if and only if , and for all it holds that . First, suppose ; then immediately. Furthermore, for and , we have that , and thus . For the other direction, let . An argument by induction on then shows that , and hence .
Since it is decidable whether , the above equivalence tells us that we can decide if we can decide the congruence problem for . Because the former is undecidable for CFGs in general [3], the claim follows.
Fortunately, some classes of CFGs do have a decidable congruence problem. This leads us to formulate our main result regarding the recognition problem, as follows.
It is decidable, given a DCFG , whether is CC. Let us write . By Lemma 3.2, it suffices to show that we can effectively obtain a decision procedure for . We employ a technique similar to the method we used to decide when is CC: we reduce the problem to checking equivalence of DCFLs.
Without loss of generality, let , with , such that . For , we define the morphism by setting and for .
We now claim that . To see this, suppose that ; then, since and , we find that . For the other inclusion, suppose that . Since , we can write for . Since , we find that .
4 Further work
With regard to implementing a teacher for a given CC language, one detail remains to be settled. The algorithm to learn CC languages from [9] assumes the presence of an extended MAT, in which the representation of the language in the equivalence query need not guarantee that the hypothesis language is in the class of languages being learned. More concretely, this means that the algorithm might query the teacher with grammars that are not CC, and thus the decision procedure outlined in this paper need not apply. Consequently, we wonder whether the learning algorithm can be adapted to work with a (proper) MAT, or alternatively, whether the decision procedure of this paper can be extended to accommodate the class of grammars that can be produced by the learning algorithm.
One possible direction for generalization of the decision procedure is the setting of multiple contextfree grammars (MCFGs) [12]. A notion corresponding to Clarkcongruentiality for MCFGs is already known, and the class of languages generated by such MCFGs is also known to be learnable [18]. We conjecture that the decidability results can be lifted to Clarkcongruential MCFGs, and that such a lifting would employ turn DPDAs instead of oneturn DPDAs.
Equivalence and congruence are decidable for both DCFLs and CC languages. To see if the case for CC languages follows from the case for DCFLs, one would have to investigate whether all CC grammars define a DCFL. For what it’s worth, the fact that we can decide whether a DCFG is CC appears to at least not contradict this possibility, and we have been unsuccessful in finding a counterexample thus far.
The question about the connection between CC languages and DCFLs can be seen as analogous to the (open) question of whether all preNTS grammars define a DCFL [2]. Since all NTS grammars are preNTS, and all preNTS grammars are in turn CC, it follows that every NTS language is a preNTS language, and in turn every preNTS language is a CC language; whether this inclusion is strict remains an open question. It has been conjectured that these families of languages coincide [9].
Acknowledgements
We would like to thank the anonymous referees of LearnAut and ICGI for their comments, which helped improve this paper.
References
 [1] Dana Angluin. Learning regular sets from queries and counterexamples. Inf. Comput., 75(2):87–106, 1987. doi:10.1016/08905401(87)900526.
 [2] JeanMichel Autebert and Luc Boasson. The equivalence of preNTS grammars is decidable. Mathematical Systems Theory, 25(1):61–74, 1992. doi:10.1007/BF01368784.
 [3] Yehoshua BarHillel, Micha Perles, and Eli Shamir. On formal properties of simple phrase structure grammars. Sprachtypologie und Universalienforschung, 14:143–172, 1961.
 [4] Catriel Beeri. An improvement of Valiant’s decision procedure for equivalence of deterministic finiteturn pushdown automata. In Proc. Foundations of Computer Science (FOCS), pages 128–134, 1975. doi:10.1109/SFCS.1975.4.
 [5] Luc Boasson. Derivations et redutions dans les grammaires algebriques. In Proc. Automata, Languages and Programming, pages 109–118, 1980. doi:10.1007/3540100032_64.
 [6] Luc Boasson and Géraud Sénizergues. NTS languages are deterministic and congruential. J. Comput. Syst. Sci., 31(3):332–342, 1985. doi:10.1016/00220000(85)90056X.
 [7] Ronald V. Book and Friedrich Otto. StringRewriting Systems. Texts and Monographs in Computer Science. Springer, 1993. doi:10.1007/9781461397717.
 [8] Noam Chomsky. Contextfree grammars and pushdown storage. MIT. Res. Lab. Electron. Quart. Prog. Report, 65:187–194, 1962.
 [9] Alexander Clark. Distributional learning of some contextfree languages with a minimally adequate teacher. In Proc. Grammatical Inference (ICGI), pages 24–37, 2010. doi:10.1007/9783642154881_4.
 [10] Seymour Ginsburg and Sheila A. Greibach. Deterministic context free languages. Information and Control, 9(6):620–648, 1966. doi:10.1016/S00199958(66)800190.
 [11] Anil Nerode. Linear automaton transformations. Proc. American Mathematical Society, 9(4):541–544, 1958. doi:doi:10.2307/2033204.
 [12] Hiroyuki Seki, Takashi Matsumura, Mamoru Fujii, and Tadao Kasami. On multiple contextfree grammars. Theor. Comput. Sci., 88(2):191–229, 1991. doi:10.1016/03043975(91)90374B.
 [13] Géraud Sénizergues. The equivalence and inclusion problems for NTS languages. J. Comput. Syst. Sci., 31(3):303–331, 1985. doi:10.1016/00220000(85)900558.
 [14] Géraud Sénizergues. ? Decidability results from complete formal systems. Theor. Comput. Sci., 251(12):1–166, 2001. doi:10.1016/S03043975(00)002851.
 [15] Géraud Sénizergues. The equivalence problem for turn DPDA is coNP. In Proc. Automata, Languages and Programming (ICALP), pages 478–489, 2003. doi:10.1007/3540450610_39.
 [16] Colin Stirling. Deciding DPDA equivalence is primitive recursive. In Proc. Automata, Languages and Programming (ICALP), pages 821–832, 2002. doi:10.1007/3540454659_70.
 [17] Leslie G. Valiant. The equivalence problem for deterministic finiteturn pushdown automata. Information and Control, 25(2):123–133, 1974. doi:10.1016/S00199958(74)908390.
 [18] Ryo Yoshinaka and Alexander Clark. Polynomial time learning of some multiple contextfree languages with a minimally adequate teacher. In Proc. Formal Grammar (FG), pages 192–207, 2010. doi:10.1007/9783642320248_13.
 [19] Louxin Zhang. The preNTS property is undecidable for CFGs. Inf. Process. Lett., 44(4):181–184, 1992. doi:10.1016/00200190(92)900827.
Appendix A The language of
To analyze the behavior of , we first note that if it is in a configuration with a state of the form , then all reachable configurations are related to that configuration by . In effect, this shows that proceeds according to .
If s.t. then it follows that
Comments
There are no comments yet.