Equivalence of regular expressions and regular languages Theory of Computation
πΌ The Big Idea (in simple words)
Think of a regular expression (RE) as a recipe.
It tells you how to build strings using symbols, choices, repetitions, etc.
Think of a regular language as the collection of all dishes made using that recipe.
Now imagine a DFA or NFA as a machine that checks whether a dish matches the recipe.
The amazing fact:
Whatever recipe (regular expression) you writeβ¦
there is always a matching machine (finite automaton) that understands it.
And whatever machine (DFA/NFA) you buildβ¦
you can always create a recipe (regular expression) that describes the exact same set of strings.
So they are two different representations of the same idea.
β Why is this equivalence important?
Because it gives us two ways to describe languages:
β REs are simple and compact
Good for writing patterns, specifying tokens, searching, etc.
β Automata are great for analysis
You can simulate them, minimize them, and prove things using them.
Since both express the same languages, you can switch from one to the other whenever needed.
π Part 1: From Regular Expression β NFA
Every regular expression can be turned step-by-step into an NFA.
This is commonly done using Thompsonβs construction.
Hereβs the idea:
For a single symbol
(a)
|
βββββ a βββββ
β S β -----> β F β
βββββ βββββ
For alternation (choice)
Expression: a | b
You branch:
Ξ΅ a Ξ΅
ββββ>β ----->β----------->βββββ
β β
β β
β Ξ΅ b Ξ΅
ββββ>β ----->β----------->βββββ
For concatenation
Expression: ab
S ββaβ β ββbβ F
For Kleene star
Expression: a*
βββββββββbβββββββββ
β β
β (S) --Ξ΅--> [a] --Ξ΅--> (F)
β β
β-------Ξ΅---------β
Every part of an RE has a small NFA structure.
By combining them, the whole regular expression becomes an NFA.
π Part 2: From DFA/NFA β Regular Expression
Going the other way is a bit like peeling onions.
We remove states one by one and update transitions with equivalent regular expressions.
This is called state elimination.
Simple idea:
- Pick a state to remove.
- Re-route all transitions around it by combining labels into regular expressions.
- Continue until only start and final states remain.
- The final label between them is the regular expression.
A rough sketch:
Before elimination:
(Start) --a--> [Q] --b--> (Final)
After removing Q:
(Start) --ab--> (Final)
The transition label becomes the regular expression describing paths through Q.
πΌ Why does equivalence hold?
Because both REs and finite automata describe patterns built from:
- sequences (concatenation)
- choices (union)
- repetitions (Kleene star)
These are exactly the tools needed for defining regular languages.
REs do it as written patterns.
Automata do it using states and transitions.
But the power is the same.
π Visual Summary Diagram
ββββββββββββββββββββββββββββ
β Regular Expressions (RE)β
β β patterns β β
ββββββββββββ¬βββββββββββββββ
β Convert (Thompson)
βΌ
ββββββββββββββ
β NFA β
β(Ξ΅-moves ok)β
ββββββββ¬ββββββ
β Subset Construction
βΌ
ββββββββββββββ
β DFA β
β(no Ξ΅-moves)β
ββββββββ¬ββββββ
β State Elimination
βΌ
ββββββββββββββββββββββββββββ
β Regular Expressions (RE)β
ββββββββββββββββββββββββββββ
The loop shows that you can always move between RE β Automata.
