Notebook 8: Regex to Automaton (Kleene)
Regex to Automaton & Kleene’s Theorem
This notebook walks through Kleene’s Theorem interactively in three steps:
- Write a regex → the notebook builds the corresponding NFA via Thompson’s construction.
- Choose states \(i\), \(j\) and frontier \(k\) → the notebook highlights which states are “allowed” as intermediates.
- Read off \(R_{i,j}^k\) → the regular expression for all words that go from \(q_i\) to \(q_j\) using only \(q_1, \ldots, q_k\) as intermediate stops.
The key recurrence is: \[ R_{i,j}^k = R_{i,j}^{k-1} + R_{i,k}^{k-1}(R_{k,k}^{k-1})^*R_{k,j}^{k-1} \]
+ for union, concatenation is implicit, * for Kleene star, () for grouping.Resulting expression R?,??
Recurrence breakdown (how this R was built)
Short words in R?,??
Test your own word
What to notice
When k = 0: \(R_{i,j}^0\) contains only \(\varepsilon\) (if \(i = j\)) and the labels of any direct edges from \(q_i\) to \(q_j\). No intermediate stops allowed.
When k increases by 1: the recurrence adds exactly the paths that use the newly unlocked state \(q_k\) as an intermediate. The star \((R_{k,k}^{k-1})^*\) covers paths that loop back through \(q_k\) zero or more times before leaving.
When k = n: \(R_{i,j}^n\) is unrestricted — any path is allowed — and \(R_{q_0,f}^n\) for each accepting state \(f\) gives one of the summands of the final regular expression.