# McNaughton's theorem

In automata theory, McNaughton's theorem refers to a theorem that asserts that the set of ω-regular languages is identical to the set of languages recognizable by deterministic Muller automata. This theorem is proven by supplying an algorithm to construct a deterministic Muller automaton for any ω-regular language and vice versa.
This theorem has many important consequences. Since (non-deterministic) Büchi automata and ω-regular languages are equally expressive, the theorem implies that Büchi automata and deterministic Muller automata are equally expressive. Since complementation of deterministic Muller automata is trivial, the theorem implies that Büchi automata/ω-regular languages are closed under complementation.

## Original statement

In McNaughton's original paper, the theorem was stated as:
   "An ω-event is regular if and only if it is finite-state."
In modern terminology, ω-events are commonly referred to as ω-languages. Following McNaughton's definition, an ω-event is a finite-state event if there exists a deterministic Muller automaton that recognizes it.

## Constructing an ω-regular language from a deterministic Muller automaton

One direction of the theorem can be proven by showing that any given Muller automaton recognizes an ω-regular language.
Suppose A = (Q,Σ,δ,q$_0$,F) is a deterministic Muller automaton. The union of finitely many ω-regular languages produces an ω-regular language; therefore it can be assumed without loss of generality that the Muller acceptance condition F contains exactly one set of states {q$_1$, ... ,q$_n$}. Let α be the regular language whose elements will take A from q$_0$ to q$_1$. For 1≤i≤n, let β$_i$ be a regular language whose elements take A from q$_i$ to q$_{(imodn)+1}$ without passing through any state outside of {q$_1$, ... ,q$_n$}. It is claimed that α(β$_1$ ... β$_n$)$^ω$ is the ω-regular language recognized by the Muller automaton A. It is proved as follows.
Suppose w is a word accepted by A. Let ρ be the run that led to the acceptance of w. For a time instant t, let ρ(t) be the state visited by ρ at time t. We create an infinite and strictly increasing sequence of time instants t$_1$, t$_2$, ... such that only states in {q$_1$, ... ,q$_n$'} appear after time t$_1$, and for each a and b, ρ(t$_{na+b}$) = q$_b$. Such a sequence exists because all and only the states of {q$_1$, ... ,q$_n$} appear in ρ infinitely often. By the above definitions of α and β's, it can be easily shown that the existence of such a sequence implies that w is an element of α(β$_1$ ... β$_n$)$^ω$.
Conversely, suppose w ∈ α(β$_1$ ... β$_n$)$^ω$. Due to definition of α, there is an initial segment of w that is an element of α and thus leads A to the state q$_1$. From there on, the run never assumes a state outside of {q$_1$, ... ,q$_n$}, due to the definitions of the β's, and all the states in the set are repeated infinitely often. Therefore, A accepts the word w.

## Constructing a deterministic Muller automaton from a given ω-regular language

The other direction of the theorem can be proven by showing that there exists a deterministic Muller automaton that recognizes a given ω-regular language.
The union of finitely many deterministic Muller automata can be easily constructed; therefore without loss of generality we assume that the given ω-regular language is of the form αβ$^ω$. Consider an ω-word w=a$_1$a$_2$... ∈ αβ$^ω$. Let w(i,j) be the finite segment a$_{i+1}$,...,a$_{j-1}$a$_j$ of w. For building a Muller automaton for αβ$^ω$, we introduce the following two concepts with respect to w.

### Favor

    A time j favors time i if j > i, w(0,i) ∈ αβ*, and w(i,j) ∈ β*.

### Equivalence

    E(i,j,k), or i is equivalent to j as judged at time k, if i,j ≤ k, w(0,i) ∈ αβ*,w(0,j) ∈ αβ*, and for every word x in Σ*, w(i,k)x ∈ β* if and only if w(j,k)x ∈ β*. It is easy to note that if E(i,j,k) then for all k < l, E(i,j,l). In other words, if i and j are ever judged to be equivalent then they will stay equivalent thereafter. And also for the same l, l favors i if and only if l favors j. Let E(i,j) if there exists a k such that E(i,j,k).
Let p be the number of states in the minimum deterministic finite automaton A$^{β*}$ to recognize language β*. Now we prove two lemmas about the above two concepts.

### Lemma 1

    For any time k, among the times i,j < k such that w(0,i) and w(0,j) ∈ αβ*, the number of equivalence classes induced by E(i,j,k) is bounded by p. Also the number of equivalence classes induced by E(i,j) is bounded by p.
    Proof: The finite automaton A$^{β*}$ is minimum; therefore it does not contain equivalent states. Let i and j be such that w(0,i) and w(0,j) ∈ αβ* and E(i,j,k). Then, words w(i,k) and w(j,k) will have to take A$^{β*}$ to the same state starting from the initial state. Hence, first part of lemma is true. The second part is proved by contradiction. Let's suppose there are p+1 times i$_1$,...,i$_{p+1}$ such that no two of them are equivalent. For l > max(i$_1$,...,i$_{p+1}$), we would have, for each m and n, not E(i$_m$,i$_n$,l). Therefore there would be p+1 equivalence classes, as judged at l, contradicting the first part of the lemma.

### Lemma 2

    w ∈ αβ$^ω$ if and only if there exists a time i such that there are infinitely many times equivalent to i and favoring i.
    Proof: Let's suppose w ∈ αβ$^ω$ then there exists a strictly increasing sequence of times i$_0$,i$_1$,i$_2$,... such that w(0,i$_0$) ∈ α and w(i$_n$,i$_{n+1}$) ∈ β. Therefore, for all n > m, w(i$_m$,i$_n$) ∈ β* and i$_n$ favors i$_m$. So, all the i's are members of one of the finitely many equivalence classes (shown in Lemma 1). So, there must be an infinite subset of all i's that belongs to same class. The smallest member of this subset satisfies the right hand side of this lemma.
    Conversely, suppose in w, there are infinitely many times that are equivalent to i and favoring i. From those times, we will construct a strictly increasing and infinite sequence of times i$_0$,i$_1$,i$_2$,... such that w(0,i$_0$) ∈ αβ* and w(i$_n$,i$_{n+1}$) ∈ β*. Therefore w would be in αβ$^ω$. We define this sequence by induction:
    Base case: w(0,i) ∈ αβ* because i is in a equivalence class. So, we set i$_0$=i. We set i$_1$ such that i$_1$ favors i$_0$ and E(i$_0$,i$_1$). So, w(i$_0$,i$_1$) ∈ β*.
    Induction step: Suppose E(i$_0$,i$_n$). So, there exists a time i' such that E(i$_0$,i$_n$,i'). We set i$_{n+1}$ such that i$_{n+1}$ > i', i$_{n+1}$ favors i$_0$, and E(i$_0$,i$_{n+1}$). So, w(i$_0$,i$_{n+1}$) ∈ β* and, since i$_{n+1}$ > i' we have by definition of E(i$_0$,i$_n$,i'), w(i$_n$,i$_{n+1}$) ∈ β*.

### Muller automaton construction

We have used both the concepts of "favor" and "equivalence" in Lemma 2. Now, we are going to use the lemma to construct a Muller automaton for language αβ$^ω$. The proposed automaton will accept a word if and only if a time i exists such that it will satisfy the right hand side of Lemma 2. The machine below is described informally. Note that this machine will be a deterministic Muller automaton.
The machine contains p+2 deterministic finite automaton and a master controller, where p is the size of A$^{β*}$. One of the p+2 machine can recognize αβ* and this machine gets input in every cycle. And, it communicates at any time i to the master controller whether or not w(0,i) ∈ αβ*. The rest of p+1 machines are copies of A$^{β*}$. The master can set the A$^{β*}$ machines dormant or active. If master sets a A$^{β*}$ machine to be dormant then it remains in its initial state and oblivious to the input. If master activates a A$^{β*}$ machine then it reads the input and moves, until master makes it dormant and force it back to the initial state. Master can make a A$^{β*}$ machine active and dormant as many times as it wants. The master stores the following information about the A$^{β*}$ machines at each time instant.
* Current states of A$^{β*}$ machines.
* List of the active A$^{β*}$ machines in the order of their activation time.
* For each active A$^{β*}$ machine M, the set of other active A$^{β*}$ machines that were in an accepting state at the time of activation of M. In other words, if a machine is made active at time i and some other machine was last made active at j < i and continue to be active till i then the master keeps the record whether or not i favors j. This record is dropped if the other machine goes dormant before M.
Initially, the master may behave 2 different ways depending on α. If α contains empty word then only one of the A$^{β*}$ is active otherwise none of the A$^{β*}$ machines are active at the start. Later at some time i, if w(0,i) ∈ αβ* and none of A$^{β*}$ machines are in initial state then master activates one of the dormant machines and the just activated A$^{β*}$ machine start receiving input from time i+1. At some time, if two A$^{β*}$ machines reach to the same state then master makes the machine dormant that was activated later than the other. Note that the master can make the above decisions using the information it stores.
For the output, the master also have a pair of red and green lights corresponding to each A$^{β*}$ machine. If a A$^{β*}$ machine goes from active state to dormant state then corresponding red light flashes. The green light for some A$^{β*}$ machine M, which was activated at j, flashes at time i in the following two situations:
* M is in initial state, thus E(j,i,i) and i favors j ( the initial state has to be accepting state).
* For some other active A$^{β*}$ machine M' activated at k, where j< k <i, k favors j (the master has record of this) and i is the earliest time at which E(j,k,i) ( M' goes dormant at time i ).
Note that the green light for M does not flash every time when a machine goes dormant due to M.

#### Lemma 3

    If there exist a time equivalent to infinitely many times that favor it and i is the earliest such time, then a A$^{β*}$ machine M is activated at i, remained active forever (no corresponding red light flash thereafter), and flashes the green light infinitely many times.
    Proof: Let's suppose a A$^{β*}$ machine was activated at time j such that j < i and this machine goes to initial state at time i. Therefore, if any time is equivalent and favors i then the time must be in the same relation with j. This contradicts the hypothesis that i is the earliest time such that infinitely many times equivalent to i and favoring i. So at time i, no active machine can be in the initial state. Hence, the master has to activate a new A$^{β*}$ machine at time i, which is our M. This machine will never go dormant because if some other machine, which was activated at time l, makes it dormant at time k then E(l,i,k). Again, the same contradiction is implied. By construction and due to infinitely many times are equivalent to i and favor i, the green light will flash infinitely often.

#### Lemma 4

    Conversely, if there is a A$^{β*}$ machine M whose green light flashed infinitely often and red light only finitely often then there are infinitely many times equivalent to and favoring the last time at which M became active.
    Proof: True by construction.

#### Lemma 5

    w ∈ αβ$^ω$ if and only if, for some A$^{β*}$ machine, the green light flashes infinitely often and the red light flashes only finitely often.
    Proof: Due to Lemmas 2-4.
The above description of a full machine can be viewed as a large deterministic automaton. Now, it is left to define the Muller acceptance condition. In this large automaton, we define μ$_n$ to be the set of states in which the green light flashes and the red light does not flash corresponding to nth A$^{β*}$ machine. Let ν$_n$ be the set of states in which the red light does not flash corresponding to nth A$^{β*}$ machine. So, Muller acceptance condition F = { S | ∃n μ$_n$ ⊆ S ⊆ ν$_n$ }. This finishes the construction of the desired Muller automaton. Q.E.D.

## Other proofs

Since McNaughton's proof, many other proofs have been proposed. The following are some of them.
* ω-regular languages can be shown equiv-expressive to Büchi automata. Büchi automata can be shown to equiv-expressive to semi-deterministic Büchi automata. Semi-deterministic Büchi automata can be shown to be equiv-expressive to deterministic Muller automata. This proof follows the same lines as the above proof.
* Safra's construction transforms a non-deterministic Büchi automaton to a deterministic Rabin automaton. This construction is known to be optimal.
* There is a purely algebraic proof of McNaughton's theorem.

## Reference list

* ↑ McNaughton, R.: "Testing and generating infinite sequences by a finite automaton", Information and Control 9, pp. 521–530, 1966.
* ↑ Safra, S. (1988), "On the complexity of ω-automata", Proceedings of the 29th Annual Symposium on Foundations of Computer Science (FOCS '88), Washington, DC, USA: IEEE Computer Society, pp. 319–327, doi:10.1109/SFCS.1988.21948.
* ↑ B. Le Saëc, J.-É. Pin, P. Weil, A purely algebraic proof of McNaughton's theorem on infinite words, Foundations of Software Technology and Theoretical Computer Science, p. 141–151, 1991