Welcome back to our exploration of computation. In the previous lesson, we introduced regular expressions as a declarative way to describe languages and stated Kleene's Theorem, which claims a profound equivalence between these descriptive expressions and the computational machines we studied earlier—finite automata.
Today, we will prove this theorem. This is a cornerstone of the theory, and the proofs themselves are not just abstract arguments; they are constructive algorithms that have significant practical applications. You will learn the systematic procedures to convert any regular expression into an equivalent NFA and, conversely, any finite automaton into an equivalent regular expression. This process perfectly aligns with your goal of understanding the fundamental "science" of computer science, as it involves establishing a deep equivalence between two powerful formalisms.
1. From Description to Machine: Regular Expression to NFA
The first half of our proof shows that for any regular expression, there exists a finite automaton that recognizes the same language. Since we know NFAs and DFAs are equivalent, we'll make our lives easier by constructing a Nondeterministic Finite Automaton with -transitions (NFA-). The flexibility of -transitions is ideal for piecing together smaller machines into a larger one.
The proof strategy is inductive, following the recursive definition of a regular expression:
- Base Cases: We'll show how to build simple NFAs for the atomic regular expressions: a single symbol , the empty string , and the empty set .
- Inductive Step: We'll show how to combine existing NFAs for regular expressions and to create new NFAs for their union (), concatenation (), and Kleene star ().
This construction is often called Thompson's Algorithm.
The following video provides a clear, step-by-step walkthrough of this constructive proof.
Kleene's Theorem (a): from regex to automaton (Discrete Mathematics: Formal Languages and Automata)
This video from Frank Stajano Explains introduces Kleene's Theorem and then meticulously builds the construction for converting a regular expression to an NFA.
Please watch the following segments carefully: Introduction: The video frames the theorem and explains that the proof will construct an NFA-\epsilon because it simplifies the process. Base Cases: Pay attention to the simple machines for a single symbol, the empty string, and the empty set. Union Construction: Observe how \epsilon-transitions are used to run two machines in parallel. Concatenation: See how the accepting states of the first machine are connected to the start state of the second. Kleene Star: This is the most subtle part. Focus on why a new start state is needed and why simply looping back from the final state to the original start state is incorrect.
To summarize the inductive step, the following diagram shows the rules for combining smaller machines into larger ones. This visual should serve as a helpful reference for Thompson's construction.

Caption: The rules for Thompson's construction. Each rule takes the NFA(s) for smaller expressions (R, S) and shows how to wire them together with new start/final states and -transitions to build the NFA for the compound expression.
Example: Building an NFA for (a∪b)*a
The video you just watched also includes a great example of applying these rules to a more complex expression. Working through this will solidify your understanding.
Kleene's Theorem (a): from regex to automaton (Discrete Mathematics: Formal Languages and Automata)
This segment applies the construction rules to a concrete example.
Watch the lecturer build the NFA for the regular expression (a|b)*a from the example. Try to pause and predict each step based on the rules we've just discussed. Notice how the final machine is built hierarchically from the inside out, starting with the NFAs for a and b.
2. From Machine to Description: Finite Automaton to Regular Expression
Now, we prove the other direction: for any finite automaton, there is a regular expression that describes its language. This direction is often considered less intuitive, but the algorithm is just as systematic.
The core idea is to start with a finite automaton and progressively remove its states. As we remove a state, we update the transitions between the remaining states with regular expressions that account for the paths that went through the removed state. We continue this process until only the start state and a single final state remain. The label on the transition connecting them will be our final regular expression.
To formalize this, we use the concept of a Generalized NFA (GNFA), which is an NFA where the transitions are labeled with regular expressions instead of single symbols.
The State Elimination Algorithm
The algorithm consists of three main stages:
- Preprocessing: Convert the given automaton (DFA or NFA) into a specific GNFA format. We add a new, unique start state with an -transition to the original start state, and a new, unique final state with -transitions from all original final states. This ensures our machine has exactly one start state with no incoming edges and one final state with no outgoing edges.

*Caption: An illustration of part of the preprocessing step. Original final states (`qf1`, `qf2`, `qf3`) are connected via $\epsilon$-transitions to a single new final state (`qf`).*
2. State Elimination: Repeatedly pick an intermediate state to "rip out." For any pair of states q_in and q_out with transitions passing through the state being removed, q_rip, we create a new direct transition from q_in to q_out. The label of this new transition is a regular expression that captures all possible paths from q_in to q_out via q_rip.
- Finalization: When only the start state and final state are left, the regular expression on the single transition connecting them is the result.
The following reading explains this state-ripping procedure in detail.
Note 1: How to convert DFA/NFA to a regular expression
This document from the University of Illinois provides a rigorous but clear walkthrough of the state elimination algorithm.
Please read the first three pages, focusing on these key sections: Section 1.1: Understand the definition of a Generalized NFA (GNFA) and the four simplifying conditions that are enforced. Section 1.2: Review the "Top-level outline" of the conversion process. Section 1.3: This is the most critical part. Study the subsection "Reworking connections for specific triple of states" carefully. The formula given is the heart of the algorithm: R_dir + R_in(R_rip)*R_out. Make sure you understand what each component represents in the diagram.
The formula you just read is key. If we are removing q_rip, the new regular expression for the transition from q_in to q_out is:
Here, is the label on the existing direct path from q_in to q_out (if any), and the second part captures all paths that go through q_rip one or more times.
The Algorithm in Action
To see how this abstract procedure works, let's turn back to Professor Stajano's lecture, where he introduces this method from a slightly different, more high-level perspective before diving into an example.
Kleene's Theorem (b): from automaton to regex (Discrete Mathematics: Formal Languages and Automata)
This video covers the automaton-to-regex conversion.
Please watch the following segments: The Core Lemma: The lecturer introduces a powerful lemma that underpins the algorithm. This formalizes the idea that we can find a regular expression for any path between two states that is restricted to a certain set of intermediate states. This abstract view should appeal to your interest in formal proofs. The Inductive Proof: He then sketches the proof by induction on the size of the set of allowed intermediate states. This is the state elimination process in disguise. The base case (empty set of intermediate states) corresponds to direct transitions. The inductive step (adding one more state q0 to the set) corresponds to the formula we just discussed. A Worked Example: Finally, he applies this method to a small automaton. Notice his commentary on how tedious the process is and how the resulting regular expressions can be complex and non-intuitive. This is an important practical takeaway.
As a final illustration, the document you read earlier also has a fantastic, clear, step-by-step graphical example.
Note 1: How to convert DFA/NFA to a regular expression
This section provides a visual trace of the state elimination algorithm.
Review Section 2.1. Follow the eight figures to see how the NFA is first normalized and then states A, B, and C are removed one by one, with the transition labels growing in complexity at each step until a single expression remains.
Conclusion
In this lesson, we have formally established the equivalence of regular expressions and finite automata by providing concrete algorithms for converting between them. This completes the proof of Kleene's Theorem.
Here are the main takeaways:
- Two Sides of the Same Coin: Regular languages can be defined either by a computational device (DFA/NFA) or by a descriptive text pattern (regular expression). These two formalisms are equivalent in power.
- Thompson's Construction (RE NFA): An elegant inductive algorithm that builds an NFA by mirroring the recursive structure of a regular expression.
- State Elimination (FA RE): A method that systematically removes states from an automaton, encoding the lost paths into increasingly complex regular expressions on the remaining transitions.
- Constructive Proof: Both conversions are algorithms, providing a constructive proof of equivalence. This has practical significance, as these algorithms (or variants of them) are used in compilers, text editors, and search tools.
We now have a complete picture of the world of regular languages. We know how to define them with machines and with expressions, and how to translate between these representations. But what are the boundaries of this world? What can't these simple models do? In our next lesson, we will introduce a powerful tool, the Pumping Lemma, to prove that certain languages are not regular, thereby exploring the limits of finite memory computation.