Abstract 1 Introduction 2 Notation & Preliminaries 3 Minimal witnesses are NP-complete 4 Minimal Pumping Length 5 Minimal witnesses are primes 6 Separating words 7 Computing Witnesses in polynomial time 8 Related work 9 Conclusions References

Minimal DFAs Witnessing Language Inequivalence

Jan Martens ORCID Leiden Institute of Advanced Computer Science, Leiden University, The Netherlands
Abstract

We study small witnesses for the inequivalence of two regular languages. A natural witness is a distinguishing word, e.g. a word in exactly one of the two languages. We propose using more succinct witnesses in the form of witnessing DFAs. A witnessing DFA recognizes a subset of one of the languages and contains at least one distinguishing word. In this way the DFA expresses behaviour contained in the first language but not the second. We show witnessing DFAs can be used to present more concise witnesses for the inequivalence of two regular languages. We show that the decision problem for the existence of a witnessing DFA of certain size is NP-complete in general, and in P in the special case of unary DFAs. Besides these computational aspects, we study structural properties of witnessing DFAs. Not all languages can be a minimal witness. It turns out that minimal witnesses are exactly the languages that are not decomposable in the union of languages with smaller state-complexity, the so-called prime languages as studied earlier by Kupferman and Mosheiff.

Keywords and phrases:
Deterministic Finite Automata, Language Inequivalence, DFA decomposition, Prime languages
Copyright and License:
[Uncaptioned image] © Jan Martens; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Regular languages
Related Version:
Based on earlier note: https://arxiv.org/abs/2306.03533 [13]
Editors:
Stefano Guerrini and Barbara König

1 Introduction

We are motivated by computing witnesses that explain difference in behaviour of two Deterministic Finite Automata (DFAs). In the formal verification of complex systems it can be key to compute witnesses and explanations for certain properties. Rather than a computer telling two DFAs are inequivalent, we would like to compute a witness that explains why the DFAs differ. We focus on the smallest witnesses since simple explanations are usually the best explanations.

A straightforward approach to explain the inequivalence of two DFAs would be to provide a distinguishing word, i.e. a word that is accepted by one of the automata but not the other. The method of finding minimal length distinguishing words is well understood and decidable in polynomial time [15]. An efficient implementation is given in [19] that has the same runtime complexity as the best known algorithm for DFA minimization known as Hopcroft’s minimization [8].

A natural question is if more powerful properties could result in smaller witnesses explaining the inequivalence of languages. Given two DFAs A1 and A2, any property of the language recognized by A1 that is not satisfied by the language of A2 can be used to witness their inequivalence. We propose to use inclusion of a third language as property. In this way a DFA A contains the property Ap if the language of Ap is included in the language recognized by A. In this work we study DFAs that witness inequivalence of two regular languages. In particular, a minimal witnessing DFA can be much more succinct than a distinguishing word.

The state complexity, also called index, of a language L is the number of states of the minimal DFA recognizing L. This descriptive complexity measure is well studied in literature, and forms a natural notion of size of a regular language. In this way properties expressed by DFAs are smaller witnesses that provide shorter and more intuitive explanation.

For example, consider the DFAs 𝒜 and shown in Figure 1. The shortest distinguishing word for these DFAs is a7. Indeed, we confirm a7(𝒜) but a7(). A different explanation for the inequivalence of 𝒜 and could be: every odd length sequence of a’s is accepted. This property is satisfied by 𝒜 and is not true for .

We call a DFA a witness for two DFAs if the language recognized is a subset of exactly one of the two DFAs. It is then said to distinguish the two languages. In the example from Figure 1, we see that the minimal witnessing DFA contains only two states, i.e. the DFA Aodd such that (Aodd)={a2i+1i}. An automaton recognizing only the minimal distinguishing word a7 would contain at least eight states. Therefore, a witnessing DFA can be much more succinct than a distinguishing word.

In this paper we study witnessing DFAs. We show that there are families of DFAs for which there are witnessing DFAs of constant size, where the length of the minimal distinguishing word grows linearly in the size of the DFAs. Additionally, we prove that computing minimal witnessing DFAs is NP-complete. In the case of unary DFAs this problem is computable in polynomial time.

This last result is due to a connection of witnessing DFAs with so-called prime languages [12]. Prime languages are the languages for which there is no decomposition in languages of smaller DFAs. We show that a DFA is a minimal witness for inequivalence of regular languages if and only if it is prime.

Figure 1: The DFA 𝒜 on the left and the DFA on the right side.

The reduction from CNF-SAT that proves the NP-completeness of deciding witnessing DFAs encodes satisfying assignment in structure of concatenation instead of composition used in other hardness proofs [11]. To show that this construction is more widely useable we show how modify the construction to obtain a simpler proof of the coNP-hardness of deciding the minimal pumping constant.

Structure

This work is structured as follows. First in Section 2 we cover the notation we use and introduce the main concept of witnessing DFAs. In Section 3 we show that computing minimal witnesses is NP-complete. After that, in Section 4, we demonstrate that the proof of the previous section can be more widely used in DFA decision problems. In Section 5 we discuss the connection between minimal witnessing DFAs, language compositionality, and so-called prime languages. In Section 6 we relate our results to the problem of separating words [4]. Finally, in Section 7 we introduce two polynomial time algorithms. The first algorithm computes a witnessing DFA that is not necessarily minimal. The second algorithm computes a minimal DFA that witnesses the non-inclusion of two unary languages. We end with conclusions and related work.

2 Notation & Preliminaries

For two natural numbers i,j we write [i,j]={i,i+1,,j} as the closed interval from i to j. Given a finite alphabet Σ, a finite sequence of elements of Σ is called a word. We write ε for the empty word and define Σi as the set of all words over Σ of length i, and Σ=iΣi for all words over Σ. We write Σ+=ΣΣ for all non-empty words over Σ. Given words u,vΣ, we write uv and uv for word concatenation. Additionally, given a number i and a word uΣ we write ui for the concatenation of i times the word u.

Definition 1.

A Deterministic Finite Automaton (DFA) A=(Q,Σ,δ,q0,F) is a five-tuple consisting of:

  • Q a finite set of states,

  • Σ a finite set of symbols called the alphabet,

  • δ:Q×ΣQ the transition function,

  • q0Q the initial state, and

  • FQ the set of final states.

The transition function δ extends naturally to a transition function for words δ:Q×ΣQ. This is done inductively as follows:

δ(q,ε) =q
δ(q,aw) =δ(δ(q,a),w).

The language recognized by a DFA A=(Q,Σ,δ,q0,F) is denoted by (A), and consists of all words wΣ such that δ(q0,w)F. A language LΣ is called regular iff there is a DFA A such that (A)=L. We write A¯ for the DFA A¯=(Q,Σ,δ,q0,QF), which recognizes the complement of A.

The Myhill-Nerode theorem is a useful tool to establish the number of states necessary to recognize a language. It is based on the equivalence relation between words that have the exact same accepting extensions.

Definition 2.

Let x,yΣ be words and LΣ a language, then xLy if and only if for all zΣ it holds that xzLyzL.

Theorem 3 (Myhill-Nerode [16, 17]).

Let LΣ be a language, then L is regular if and only if the relation L has a finite number of equivalence classes.

A more specific corollary of the theorem relates the number of equivalence classes of L to the smallest number of states a DFA needs in order to recognize L. We refer to this number as the index of a language and write it as 𝑖𝑛𝑑(L). For a DFA A we write 𝑖𝑛𝑑(A) for the index of the language accepted by A.

Corollary 4.

Let L be a regular language over an alphabet Σ, then the smallest DFA A that recognizes L has 𝑖𝑛𝑑(L)=k states where k is the number of equivalence classes of the relation L.

Now we introduce the notion of witnessing DFA for the inequivalence of languages.

Definition 5.

Given DFAs A1,A2 such that (A1)(A2), a DFA B is called to witness the language inequivalence iff:

(B)(A1)(B)(A2).

A minimal witness for the inequivalence of A1 and A2 is a witness that is minimal (in size) amongst all witnesses. Of course, for DFAs A1 and A2, such that (A1)(A2) the DFA A1 itself is already a witness DFA. We are interested in small witnesses for language inequivalence, since in general small DFAs express the most intuive properties.

The notion of minimal witnessing DFAs naturally leads to the following decision problem.

k-DFA-DIST:

Let A1 and A2 be DFAs such that (A1)(A2), and k a number. Decide if there is a DFA Adist with at most k states such that:

(Adist)(A1)(Adist)(A2).

3 Minimal witnesses are NP-complete

First, we observe that DFA witnesses for language inequivalence can be arbitrarily smaller than distinguishing words. We show this by generalizing the construction from the example in the introduction (Figure 1).

Example 6.

For a number n{0}, let 𝒜n, n be DFAs defined such that:

(𝒜n) ={aci and ci2n}
(n) ={a}{aci,i0 and c1+i(2n1)}.

The minimal automata recognizing (𝒜n) (resp. (n)) have 2n (resp. 2n+1) states. The smallest word accepted by 𝒜n and not by n has length 2n+11. In this case the DFA Aodd accepting all odd length sequences of a also acts as a witnessing DFA. Hence, a minimal witnessing DFA is Aodd, i.e. the DFA such that (Aodd)={a2i+1i}. The DFA Aodd contains only 2 states, and thus the minimal witnessing DFA is asymptotically smaller than the minimal witnessing word.

The shape of the example automata 𝒜3 and 3 are given in Figure 2.

Figure 2: Example automata 𝒜3 (left) and 3 (right). The minimal witnessing word is a15 whereas the minimal witnessing DFA contains 2 states.

Next, we show the NP-completeness of computing minimal witnessing DFAs for language inequivalence. We prove k-DFA-DIST is NP-hard by a reduction from CNF-SAT.

Theorem 7.

Deciding k-DFA-DIST is NP-complete.

Before we introduce the reduction we define some notation in which we encode truth values of propositions. In the reduction we represent truth assignments as words over the Boolean alphabet 𝔹={𝟶,𝟷}. Given a set of propositional variables 𝑃𝑟𝑜𝑝={p1,,pk}, a truth assignment ρ:𝑃𝑟𝑜𝑝𝔹 is represented by the word a1ak𝔹k, where ai=ρ(pi) for every i[1,k]. The set 𝒳=𝔹k defines all words that represent truth assignments.

Now we are ready to introduce our reduction from CNF-SAT in order to prove Theorem 7. Let ϕ=C1Cn be a CNF formula over the propositional variables 𝑃𝑟𝑜𝑝={p1,,pk}, we define two regular languages over the alphabet Σ=𝔹{}. The first language LϕΣ is the finite set of at most n concatenated truth assignments separated by a , i.e.

Lϕ={w1wjj[1,n] and w1,,wj𝒳}.

The second language Lϕ+Σ is a superset of Lϕ. In addition to all the words of Lϕ, the language Lϕ+ contains words of more than n concatenated truth assignments. Specifically, Lϕ+ includes all words consisting of n or more concatenated truth assignments of which the first consecutively satisfy the clauses C1,,Cn. More precisely,

Lϕ+=Lϕ{w1wjjn,w1,wj𝒳 and for all i[1,n]:wi satisfies Ci}.

We sketch the shape of the languages with an example using an unsatisfiable formula.

Example 8.

Consider the CNF-formula 𝒞=p1¬p1 over the propositional letters 𝑃𝑟𝑜𝑝={p1}. The language L𝒞 is the language containing the words:

  • b for b{𝟶,𝟷}, and

  • bb for b,b{𝟶,𝟷}.

The language L𝒞+ contains:

  • w if wL𝒞, and

  • 𝟷𝟶w for every w(𝒳)+.

Since 𝟷 is the only truth-assignment for p1 that satisfies C1=p1 and only 𝟶 satisfies C2=¬p2. The only words that witness the inequivalence L𝒞+L𝒞 are of the shape 𝟷𝟶w, for w(𝒳)+.

The languages Lϕ and Lϕ+ are regular, and hence there are automata that recognize these languages. In particular, there are automata recognizing these languages that are polynomial in size. One way of observing this fact is by inspecting the number of Myhill–Nerode equivalence classes of Lϕ+ and Lϕ.

Lemma 9.

Given a CNF formula ϕ, the languages Lϕ+ and Lϕ are recognizable by an automaton that is polynomial in the size of ϕ.

The next lemma proves the key fact of our reduction. Given a CNF formula ϕ that is satisfiable on the propositional letters 𝑃𝑟𝑜𝑝={p1,,pk}, the language {(wρ)ii} formed by a satisfying truth assignment ρ represented as the word wρ{𝟶,𝟷}k iterated arbitrary often is a small distinguishing automaton for the languages Lϕ+ and Lϕ. Conversely, a distinguishing automaton smaller than a certain size necessarily implies the existence of a satisfying truth assignment for ϕ.

Lemma 10.

Let ϕ=C1Cn be a CNF formula over k propositional letters 𝑃𝑟𝑜𝑝={p1,,pk}. Then ϕ is satisfiable if and only if there is a DFA Adist with at most k+2 states such that (Adist)Lϕ+ and (Adist)Lϕ.

Proof.

We prove both directions of the implication separately.

()

Assume ϕ is satisfiable, then there is a satisfying truth assignment ρ that is mapped to the word wρ=ρ(p1)ρ(pk)𝒳. We define the language Ldist={(wρ)ii}, and show that Ldist witnesses this implication.

First we show that LdistLϕ+. Assume i, if in then by definition (wρ)iLϕ and hence also (wρ)iLϕ+. If i>n, since ρ is a satisfying assignment, it holds for any w{ww𝒳} that (wρ)nwLϕ+, and thus also (wρ)n(wρ)inLϕ+. By covering both cases this means LdistLϕ+.

Next, we observe that (wρ)n+1Lϕ, and thus LdistLϕ. Hence, since LdistLϕ+ any DFA that recognizes Ldist is a distinguishing automaton.

The minimal DFA Adist such that (Adist)=Ldist contains one loop with k+1 states containing all positions of the word wρ and a sink state to reject all other words. Thus, if ϕ is satisfiable we can construct Adist with k+2 states that distinguishes Lϕ+ and Lϕ, which was to be showed.

()

We assume Adist is a DFA with at most k+2 states such that for the language accepted L^=(Adist) it holds that L^Lϕ+ and L^Lϕ. We show that this means ϕ is satisfiable.

Since L^Lϕ and LϕLϕ+ there is a word wLϕ+Lϕ accepted by Adist. By definition w is of shape w=w1wnw where wΣ+ and w1,,wn𝒳 and for every i[1,n] the word wi represents a satisfying truth assignment for the clause Ci. Next we show that w1 represents a satisfying truth assignment for ϕ by counting the number of equivalence classes of L^ for the prefixes of w1, together with the postfix wpost=w2wnw that witnesses an accepting postfix for w1.

We define the set U as the set containing all prefixes of w1=a1ak, i.e.

U={ε}{a1ajj[1,k]}.

If v,uU and vu then vL^u, since there is a σΣ such that vσ=w and wL^ and uσL^. This means there are |U|=k+1 distinct classes of L^. Lastly, since zL^ for any zΣ we can also conclude that L^u for all uU.

Since we assumed that Adist has at most k+2 states, by Corollary 4 there are at most k+2 equivalence classes of L^. Since trivially w1L^, by the pigeonhole principle there is a prefix uU such that at w1L^u.

It can not be the case that u=a1ai for some i[1,k], since

a1ai ai+1akwpostL^
w1 ai+1akwpostL^.

By eliminating all alternatives we conclude u=ε. Using this equivalence and since εw1wpostLdist we derive that w1w1wpostLdist. In particular, this means that (w1)nwpostLdist. By definition of Lϕ+ this means that the truth assignment w1 satisfies all clauses C1,,Cn and hence it is a satisfying assignment for ϕ. This witnesses that ϕ is a satisfiable formula.

This lemma allows us to prove Theorem 7.

Proof of Theorem 7.

Membership of NP follows naturally. For two DFAs A1 and A2 we can, in polynomial time, check if (A1)(A2). This can be done by computing the emptiness of (A1)(A2)¯. Moreover, either A1 or A2 itself necessarily already is a distinguishing automaton, so the minimal distinguishing DFA is definitely polynomial in size.

NP-hardness is a direct consequence of Lemma 10 and of the fact that LϕLϕ+, so the language of any distinguishing automaton is a subset of Lϕ+ and not vice-versa.

4 Minimal Pumping Length

The pumping lemma is mostly famous for educational purposes in automata theory. The lemma asserts that in a regular language a word from a certain length can be pumped. A word in a language can be pumped if a non-empty part of it can be arbitrarily repeated while remaining in the language.

Definition 11 (Pumping lemma).

Let LΣ be a regular language. There is a p such that for all words wL if |w|p then there is a decomposition w=xyz such that |xy|p, |y|1 and for all i: xyizL.

Recently, the computational complexity of deciding the minimal pumping length was studied in [6]. The decision problem associated with the pumping lemma is to decide if the lemma holds for a certain pumping constant p.

𝒌-PUMPING:

Let A be a DFA, and k a number. Decide if the pumping lemma holds with constant p=k.

In [6] it was shown that computing the minimal pumping constant p of the lemma is coNP-hard.

Theorem 12 ([6, Cor. 15]).

k-PUMPING is coNP-complete.

The proof of the coNP-hardness of k-pumping goes by a reduction from Hamiltonian cycle. A slightly modified language based on Lϕ+ from Section 3 gives an alternative proof of this fact. The reduction is directly from the tautology of DNF formulas, which is the natural coNP-complete problem.

Let the language Lϕdnf be a language similar to the one previously mentioned, but for a propositional formula in Disjunctive Normal Form (DNF). Here, a formula ϕ is said to be in disjunctive normal formal if ϕ=C1Cn where each Ci is a conjunction of literals. The language contains all words w1wn{ww𝒳}, where there is an i[1,n] such that the truth assignment wi satisfies Ci,
Lϕdnf=Lϕ{w1wjjn,w1,,wj𝒳 and there is an i[1,n]:wi satisfies Ci}.

Lemma 13.

Given a DNF formula ϕ=C1Cn, the language Lϕdnf is (k+1)n-PUMPING if and only if ϕ is a tautology.

Proof.

()

Let w𝒳 be a word representing a truth assignment. Since Lϕdnf is (k+1)n-PUMPING, the pumping lemma holds for the word (w)nLϕLϕdnf. Let xyz=(w)n be the composition as mentioned in the pumping lemma. Since y is non-empty, and xy2zLϕdnf by the structure of Lϕdnf it has to hold that |y|=c(k+1) for some c. Observe that any such y is of the shape wpost(w)wpre, where w=wprewpost. From this we can conclude that xy2z=(w)n+c and thus, by definition of Lϕdnf, that w represents a satisfying assignment for ϕ. In particular, since w was arbitrarily chosen, any assignment is a valid truth assignment and thus ϕ is a tautology.

()

Assume ϕ is a tautology, and wLϕdnf such that |w|(k+1)n. By definition the word can be represented as w1wj for some jn and truth assignments w1,,wj𝒳. We distinguish on whether |w|=(k+1)n.

  • Assume |w|=(k+1)n, then since ϕ is a tautology, there is a clause C for which w1 is a satisfying truth assignment. We verify that w=xyz for the words x=ε, y=w1w1 and z=wwj, and that xyizLϕdnf for all i.

  • In the second case |w|>(k+1)n. By construction of the language w=w1wi for some i>n, and hence there is a word wn+1 that represents a truth assignment. Since ϕ is a tautology, there is a clause C such that the word wn+1 represents a satisfying assignment for C. We show that x=w1w1, y=wwn, z=wn+1wj verifies the pumping lemma. Indeed, in xy0z the word wn+1 satisfies C and thus xy0zLϕdnf. For any c1, the word xycz=w1wnwj, and since wLϕdnf also xyczLϕdnf.

This shows that in both cases, the language Lϕdnf is (k+1)n-PUMPING.

5 Minimal witnesses are primes

In this section we study the structure of minimal witnesses and show that minimal witnesses correspond to the prime languages [12]. Prime languages are those that cannot be decomposed into a union of languages with smaller state complexity. In other words, a language L can be k-decomposed if it is the union of languages of index k. This hierarchy on regular languages was first studied in [12].

Definition 14 (k-composable).

A regular language L is k-composable if and only if there are DFAs A1,,At, such that 𝑖𝑛𝑑(Ai)k for all i[1,t], and

L=i[1,t](Ai).

A DFA A is called prime iff it is minimal and not k-composable for any k<𝑖𝑛𝑑(A).

Formally in [12], instead of union decomposition, the focus is intersection decomposition. For our purpose it makes more sense to look at union decomposition. All results for intersection compositionality can be trivially dualized for union composition, this is already observed in [12]. Hence, this difference is only a matter of presentation. If a DFA A is union composite, e.g. (A)=i[1,n](Ai) for some DFAs A1,,An, then also (A)¯=i[1,n](Ai)¯.

We show how the concept of prime languages is related to minimal witnesses. We start by the observation that not all DFAs are a minimal witness. This is illustrated by the following example.

Figure 3: Minimal automata recognizing L2 (from qbb), and the languages La (from pε), and Lb (from rε).
Example 15.

Consider the language L2={waσwΣ,σΣ} over the alphabet Σ={a,b}. The minimal automaton recognizing L2 is shown in Figure 3. Observe that 𝑖𝑛𝑑(L2)=4. Given a language LΣ such that L2L, then necessarily there is a word wΣ,σΣ such that the word waσL. Let the language Lσ be defined as Lσ={waσwΣ}. Then Lσ is a subset of L2 and witnesses the non-inclusion L2L. Since 𝑖𝑛𝑑(Lσ)=3, we see that for the non inclusion of L2 in any language there is a witness of index smaller than the index of L2.

In general for each k define the languages Lk={wauwΣ,uΣk}. The language Lk always has a witness for non-inclusion with index exponentially smaller than the index of Lk.

A natural question is when a DFA A is a minimal witness for the non-inclusion of some languages LL. In the example above, the language L2 is not prime. In fact, L2 is 3-decomposable in the automata recognizing the languages Lσ={waσwΣ} for each σΣ. Now we see the language L2=σΣLσ. Next, we prove that prime languages characterize exactly the languages that are minimal witnesses.

Theorem 16.

Given a DFA A, A is a minimal witness for the non-inclusion of some DFAs B1 in B2, i.e. (B1)(B2) if and only if A is prime.

Proof.

()

Given a prime DFA A, we will show that there are DFAs B1 and B2 such that A is a minimal witness for their non-inclusion. First we define α(A) the floor of A, by

α(A)={A𝑖𝑛𝑑(A)<𝑖𝑛𝑑(A) and (A)(A)}.

Now from [12, Theorem 2.2] it holds that since A is prime, there is a primality witness w(A) such that wAα(A)(A). Let (B2)=Σ{w}. Now, for all DFAs Aα(A), in other words all DFAs such that (A)(A) and 𝑖𝑛𝑑(A)<𝑖𝑛𝑑(A), necessarily w(A). Now it is easy to see there is no smaller DFA than A that witnesses (A)(B2), and hence A is a minimal witness for the non inclusion (A)(B).

()

Assume A is a minimal witness for the DFAs B1 and B2. Since A is minimal, it holds for all DFAs Aα(A) that A is no witness for the non-inclusion of B1 and B2. Hence, for all Aα(A) it holds that (A)(B2). Since (A)(B2) there is a primality witness w(A)(B2) such that wAα(A)(A), hence A is prime.

A direct consequence of this theorem is that for any DFA A and k it holds that if A is k-composable then any non-inclusion (A)(B) is witnessed by a DFA of index at most k. Unfortunately, the converse is not necessarily true. A witnessing DFA does not need to be part of a decomposition. For example, consider the minimal automaton A recognizing the language (A)={a3ii}. This DFA contains 3 states and is prime. However, in order to witness that (A)Σ{ε} we can use the minimal DFA B recognizing the language (B)={ε}, which only contains 2 states, but B is not part of the decomposition of A since A is prime.

6 Separating words

A special case of the minimal witness problem is the separating words problem. The problem is to find the smallest DFA that distinguishes two given words, in the sense that it accepts one and rejects the other. Given two words w1,w2Σ what is the minimal DFA A such that w1(A)w2(A). In our context this question is exactly to compute a witness for the inequivalence of L1=Σ{w1} and L2=Σ{w2}. We define Sep(w1,w2) as the minimal number of states in a DFA that distinguishes w1 from w2 – accepting one and rejecting the other.

The study of the separating words problem focuses on the asymptotic behavior of the maximum value of Sep(w1,w2), taken over all pairs of words w1 and w2 of length n over an alphabet of size . This is captured by the function Sep(n):

Sep(n)=maxw1,w2{a1,,ak}nSep(w1,w2).

Computing Sep(w1,w2) is NP-complete, which is a corollary from the study of identity checking in arbitrary finite semigroups [1]. Two words w1,w2Σ (often called terms in the context of algebras) form an identity for a finite semigroup S if, for every projection τ:ΣS, the equality τ(w1)=τ(w2) holds. Here, τ extends to words by applying the semigroup operation, that is,

τ(a1a2an)=τ(a1)τ(a2)τ(an)for a1,,anΣ.

The identity checking problem for a semigroup S is defined as deciding whether w1,w2 is an identity.

A particular semigroup is the transformation group Tn, which consists of all functions from 0,,n1 to itself, with function composition as operation.

Theorem 17 (([1, Thm. 2],[10, Thm. 1])).

The identity checking problem for the transformation group Tn is coNP-complete for n3.

In [2] it is noticed how this is closely related to the separating words problem.

Lemma 18.

Let n3 be a number. Given an alphabet Σ and words w1,w2Σ. The words w1,w2 are not an identity in Tn if and only if there is a DFA A with at most k states such that w1(A) and w2(A).

Proof.

If w1 and w2 are not an identity in Tn, then, by definition, there exists a projection τ:ΣTn such that τ(w1)τ(w2). Note that, since τ(w1)τ(w2), there is an i{0,,n1} such that τ(w1)(i)τ(w2)(i). Given this witnessing projection τ, and number i we define an n-state DFA A=({0,,n1},Σ,δ,q0,F), where q0=i, F={τ(w1)(i)}, and the transition function δ is defined as:

δ(q,a)=τ(a)(q)for each q{0,,n1} and aΣ.

This DFA operates by simulating the function of the projection τ on each input symbol. By construction w1(A) and since τ(w2)(i)τ(w1)(i), w2(A).

Conversely, assume that for words w1,w2Σ there is a DFA A with n states that distinguishes w1 and w2. We derive a projection τ:ΣTn from the DFA A=(Q,Σ,δ,q0,F). Without loss of generality, assume Q={0,,n1} and define the projection τ for every iQ,aΣ as τ(a)(i)=δ(i,a). Now we observe that τ witnesses that w1 and w2 are not an identity in Tn.

Corollary 19.

Given an alphabet Σ, and two words w1,w2Σ deciding whether there is a DFA A with at most k states such that w1(A) and w2(A) is NP-complete for any k3.

It is worth noting that the function Sep(n) remains equal regardless of the size of the alphabet when 2 [4].

Lemma 20 ([4, Proposition 2.]).

For all 2, Sep(n)=Sep2(n).

However, for any finite k, the existence of a k state DFA that distinguishes two binary words can be decided in constant time by trying all projections τ:{0,1}Tk. When the alphabet is part of the input and k2, then trying all the projections is not feasible, since there are |Tk||Σ| possible projections.

So, deciding whether Sep(w1,w2)=k is known to be NP-complete, for any fixed k and variable alphabet size. The complexity remains unresolved when k is part of the input and the alphabet is constant. This is particularly significant because the binary case fully determines the asymptotic behaviour of Sep(n) – making it an interesting question for future research.

Question 21.

Given w1,w2{0,1} is computation of Sep(w1,w2) possible in polynomial time?

7 Computing Witnesses in polynomial time

In this section we provide polynomial algorithms that compute not necessarily minimal witnesses for DFA inequivalence. First we compute witnessing DFAs greedily combining states until a fixed point is reached. Secondly, for unary DFAs we build a polynomial algorithm that computes a witness of index k or rejects if it does not exist. This algorithm uses the notion of clean quotients, which are used to show that deciding primality of unary DFAs is decidable in LOGSPACE [9].

Simple witnesses

In this section we introduce a naive polynomial time algorithm that computes a witnessing DFA that is not minimal, but can not become smaller by state merging.

Definition 22 (Irreducible witness).

Let A=(Q,Σ,δ,q0,F) be a DFA such that (A)(B) for some DFA B. A DFA Adist is called an irreducible witness w.r.t. A and B iff there is no DFA Aα(Adist) such that (A)(B), where α(Adist) is the floor of Adist defined as

α(Adist)={A𝑖𝑛𝑑(A)<𝑖𝑛𝑑(Adist) and (A)(Adist)}.

We obtain irreducible DFAs by iteratively combining states. In order to do so, we define an operation on DFAs that maps one state to another. Given a DFA A=(Q,Σ,δ,q0,F), and two states q,pQ, when we write A[qp], we mean the automaton where the transitions into q are relayed to p, i.e.

A[qp] =(Q{q},Σ,δ,q0,F),where for all r,aQ×Σ
δ(r,a) ={p if δ(r,a)=qδ(r,a) otherwise.
q0 ={p if q0=qq0 otherwise.

The algorithm follows the following procedure.

1. Pick a distinguishing word.

First we compute a distinguishing word w(A1)(A2). This can be done in quasi-linear time [19]. It can be noted that a shortest distinguishing word does not necessarily result in the smallest witnessing automaton. However, by lack of better heuristics it seems best to pick a smallest distinguishing word w, since this will guarantee an upper bound on the distinguishing DFA found.

2. Greedily combine states.

We compute the path w takes in the automaton A1. We try to combine states on this path, and check whether the DFA still accepts a subset of A1. By construction the DFA still accepts w and thus is a witnessing DFA for (A1)(A2).

Algorithm 1 Computing a irreducible distinguishing DFA.

This procedure results in a DFA which is not larger than that of a minimal distinguishing word, and potentially is a minimal witnessing DFA. We prove that the resulting DFA is so-called irreducible, which is, for any smaller DFA A, which is a subset of A1 it holds that w(A).

Theorem 23.

Given two DFAs A1 and A2, such that (A1)(A2), and a word w(A1)(A2) the output DFA SimpleWitness(A1,A2) from Algorithm 1 is irreducible.

An interesting question is whether we can compute the minimal witnessing DFA if we compute the correct word w in Line 2. In other words, given DFA A can we compute a minimal DFA which recognizes a subset of A while still containing a word w(A). More formally we are interested in the computational complexity of the following decision problem.

𝒘,𝒌-DFA-DIST:

Given a DFA A1, a number k, and a word w(A1) is there a DFA Ad of index k such that (Ad)(A1) and w(Ad).

If w,k-DFA-DIST is in P, then also Question 21 is answered affirmitively, e.g. we can compute the smallest DFA that separates two words in polynomial time.

Unary DFAs

When the alphabet Σ of the input DFAs is only a singleton |Σ|=1, the problem of deciding minimal witnesses becomes easier. This is due to the specific shapes of these automata.

A unary DFA is a DFA where the alphabet Σ is a singleton, usually we pick Σ={a}. The language of unary DFA is a set of words in the form ai for some natural number i. It is natural to see the language of a unary DFA as a subset of . For a unary DFA B we define the unary-language is (B)={iai(B)}.

A minimal unary DFA has a specific shape. Since each state has exactly one outgoing transition, it contains exactly one cycle. The initial state might not be on the cycle. In this case the state is the start of a path leading up to the cycle. For the analysis of unary DFAs it is very convenient to distinguish these states.

Figure 4: The (2,1)-DFA A1 on the left and the (0,1)-DFA A2 on the right side.

For two integers d1 and 0 a unary (,d)-DFA is a unary DFA with prefix states s0,,s1 and a cycle containing d states q0,,qd1. The path leading into the cycle we call the prefix. Examples of these automata are given in Figure 4.The language of a unary (,d)-DFA A=({s0,s1}{q0,qd1},{a},δ,s1,F) is given by

(A)={ii< and siF}{+i+cdc,0i<d and qiF}.

For unary DFAs computing minimal DFA witnesses is similar to deciding primality of unary DFAs. Deciding primality for unary DFAs is computable in deterministic logarithmic space [9]. An algorithm is proposed that carefully inspects so-called clean quotients. A clean quotient of a unary DFA is a unary DFA in which the cycle is folded into a smaller cycle.

Although our setting differs from primality testing, a similar technique can be used to compute minimal witnesses for non-inclusion. We inspect all possible covers of the cycle of the unary DFA. For each possible folding this procedure takes only polynomial time and there is only a linear number of possible covers.

In particular there is a unary DFA with a single accepting state that witnesses this non-inclusion. Hence, finding minimal witnesses for the language non-inclusion of two unary DFAs boils down to finding the smallest numbers k1,k2 such that the language Lk1,k2={ak1aik2i} distinguishes A1 and A2.

We define the family of unary DFAs A,d=(Q,{a},δ,s0,F) for each ,d, where

  • the set of states is defined as:

    Q={s0,,s1}{q0,,qd1},
  • the transition function is given as:

    δ(p,a)={sj+1if p=sj, for some j{0,,1}q0if p=sqjotherwise, if p=qi and ji+1modd,
  • and, one accepting state at the start of the cycle F={q0}.

Observe that there is always a minimal distinguishing DFA in the shape of A,d.

Lemma 24.

Given unary DFAs A1,A2 such that (A1)(A2), then if a unary DFA B witnesses the non-inclusion, then there is a DFA A,d such that 𝑖𝑛𝑑(A,d)𝑖𝑛𝑑(B) and A,d witnesses (A1)(A2).

Proof.

Let B=(Q,{a},δ,q0,F) be a distinguishing DFA such that (B)(A1) and (B)(A2). Then, by definition there is a word w(B) such that w(A2). Now we define the DFA B=(Q,{a},δ,q0,{δ(q0,w)}) such that the only accepting state is the one accepting w. Since B still accepts w, it is still a distinguishing DFA for (A1)(A2) and by construction 𝑖𝑛𝑑(B)𝑖𝑛𝑑(B).

We complete the proof by showing that (B)=(A,d) for some ,d. If δ(w,q0) is part of the prefix siQ, then the DFA (A|w|,0)=(B). In the other case when δ(q0,w)=qi is some state qiQ on a cycle, and let that cycle have length d. Then it holds that (A|w|,d)=(B).

Algorithm 2 Computing a minimal witnessing DFA for two unary DFAs.

There are only polynomially many of these automata of smaller index, e.g. 𝑖𝑛𝑑(A,d)k. A polynomial time algorithm can simply enumerate them all. Our algorithm is slightly less naive and checks for each accepting state that accepts a distinguishing word, the possible languages A,d that accept that distinguishing word.

Lemma 25.

Let A1,A2 be two unary DFAs such that (A1)(A2). Then the DFA B= UnaryMinWitness(A1,A2), by Algorithm 2 is a minimal witness for the non-inclusion.

Since all loops of Algorithm 2 have a linear bound, the algorithm runs in polynomial time.

Theorem 26.

The decision problem k-DFA-DIST for unary DFAs is in P.

8 Related work

There are some decision problems on DFAs that show some similarities, but are different from the work here. For instance the early work of Gold [5] and Pfleeger [18] in which it is shown that learning minimal DFAs from (partial) observations is NP-complete. In this line of work by Gold, so-called separating languages are widely studied in the literature. Here the separating problem is, given languages L1 and L2, to find a separating language Lsep such that LsepL1 and LsepL2=. Although this resembles our witnessing problem, a direct relation is not obvious.

The framework of distinguishing words roughly corresponds to that of Hennessy–Milner theorems for non-deterministic structures [7]. Two non-deterministic structures are not bisimilar if and only if there is a distinguishing formula (within the Hennessy–Milner logic). These formulas are used as counter-examples in the field of model checking. Despite the fact that computing minimal formulas is NP-hard, a similar method as computing distinguishing words results in succinct witnesses [3, 14]. This work can contribute towards witnesses with invariants in the non-deterministic setting.

9 Conclusions

We showed how to use DFAs to witness language inequivalence. In this way it is possible more concisely represent witnesses that explain why the language of input DFAs are not equivalent. These witnesses correspond with prime languages that are previously studied [12, 9]. We show with a reduction from CNF-SAT that deciding minimal distinguishing witnesses is NP-complete. This reduction exploits structure in the language in a non-trivial way. This structure also provides a simpler proof of the coNP-hardness of the minimal pumping length. This indicates that it might be a useful tool in the DFA workbench. In particular, we conjecture that it can be used to closen the complexity gap of deciding primality [12].

To contrast this NP-hardness result we provide a greedy algorithm that in polynomial time computes a witnessing DFA that is never larger than a distinguishing word. In addition, we show that deciding minimal witnesses is in P for unary language non-inclusion.

We leave open two complexity questions that seem interesting. First the complexity of deciding w,k-DFA-DIST and the separating words problem for a binary alphabet. Additionally, it would be interesting to extend the hardness result primality of DFAs. We sketched a connection between prime DFA and minimal witnesses for DFA inequivalence, however, translating this hardness result seems not trivial.

References

  • [1] J. Almeida, M. V. Volkov, and S. V. Goldberg. Complexity of the identity checking problem for finite semigroups. Journal of Mathematical Sciences, 158(5):605–614, 2009. doi:10.1007/s10958-009-9397-z.
  • [2] Andrei A. Bulatov, Olga Karpova, Arseny M. Shur, and Konstantin Startsev. Lower bounds on words separation: Are there short identities in transformation semigroups?, August 2017. doi:10.37236/6450.
  • [3] Rance Cleaveland. On automatically explaining bisimulation inequivalence. In Edmund M. Clarke and Robert P. Kurshan, editors, Proc. Computer-Aided Verification (CAV 1990), pages 364–372, Berlin, Heidelberg, 1991. Springer Berlin Heidelberg. doi:10.1007/BFb0023750.
  • [4] Erik D Demaine, Sarah Eisenstat, Jeffrey Shallit, and David A Wilson. Remarks on separating words. In Markus Holzer, Martin Kutrib, and Giovanni Pighizzini, editors, Proc. of DCFS 2011, volume 6808 of LNCS, pages 147–157. Springer, 2011. doi:10.1007/978-3-642-22600-7_12.
  • [5] Mark E. Gold. Complexity of automaton identification from given data. Information and Control, 37(3):302–320, 1978. doi:10.1016/S0019-9958(78)90562-4.
  • [6] Hermann Gruber, Markus Holzer, and Christian Rauch. The pumping lemma for regular languages is hard. In International Conference on Implementation and Application of Automata, pages 128–140. Springer, 2023. doi:10.1007/978-3-031-40247-0_9.
  • [7] Matthew Hennessy and Robin Milner. On observing nondeterminism and concurrency. In Jaco de Bakker and Jan van Leeuwen, editors, Automata, Languages and Programming (ICALP ‘1980), pages 299–309, Berlin, Heidelberg, 1980. Springer-Verlag. doi:10.5555/646234.758793.
  • [8] John Hopcroft. An n log n algorithm for minimizing states in a finite automaton. In Zvi Kohavi and Azaria Paz, editors, Theory of Machines and Computations, pages 189–196. Academic Press, 1971. doi:10.1016/B978-0-12-417750-5.50022-1.
  • [9] Ismaël Jecker, Orna Kupferman, and Nicolas Mazzocchi. Unary Prime Languages. In Javier Esparza and Daniel Král’, editors, Proc. of MFCS 2020, volume 170 of Leibniz International Proceedings in Informatics (LIPIcs), pages 51:1–51:12, Dagstuhl, Germany, 2020. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.MFCS.2020.51.
  • [10] Ondřej Klíma. Identity checking problem for transformation monoids. Semigroup Forum, 84(3):487–498, 2012. doi:10.1007/s00233-012-9401-7.
  • [11] Dexter Kozen. Lower bounds for natural proof systems. In Proc. of SFCS 1977, pages 254–266. IEEE, 1977. doi:10.1109/SFCS.1977.16.
  • [12] Orna Kupferman and Jonathan Mosheiff. Prime languages. Information and Computation, 240:90–107, 2015. doi:10.1016/j.ic.2014.09.010.
  • [13] Jan Martens. Deciding minimal distinguishing DFAs is NP-complete. arXiv preprint arXiv:2306.03533, 2023. doi:10.48550/arXiv.2306.03533.
  • [14] Jan Martens and Jan Friso Groote. Computing minimal distinguishing Hennessy-Milner formulas is NP-hard, but variants are tractable. In G.A. Pérez and J.-F. Raskin, editors, Proc. of CONCUR 2023, volume 279 of LIPIcs, pages 32:1–32:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPIcs.CONCUR.2023.32.
  • [15] Tyler Moore. Gedanken-experiments on sequential machines. In C. E. Shannon and J. McCarthy, editors, Automata Studies, Annals of Mathematical Studies, no. 34. Citeseer, 1956.
  • [16] John R. Myhill. Finite automata and the representation of events. WADD Technical Report, 57-624:112–137, 1957.
  • [17] Anil Nerode. Linear automaton transformations. Proceedings of the American Mathematical Society, 9(4):541–544, 1958. doi:10.1090/S0002-9939-1958-0135681-9.
  • [18] Charles P. Pfleeger. State reduction in incompletely specified finite-state machines. IEEE Transactions on Computers, 100(12):1099–1102, 1973. doi:10.1109/T-C.1973.223655.
  • [19] Rick Smetsers, Joshua Moerman, and David N Jansen. Minimal separating sequences for all pairs of states. In Adrian-Horia Dediu, Jan Janoušek, Carlos Martín-Vide, and Bianca Truthe, editors, Proc. of (LATA 2016), volume 9618 of LNCS, pages 181–193. Springer, 2016. doi:10.1007/978-3-319-30000-9_14.