4.6.5 · HinglishTheory of Computation

Regular expressions — equivalence with finite automata

2,091 words10 min readRead in English

4.6.5 · Coding › Theory of Computation


Hum kya prove kar rahe hain?

Yeh ek iff hai, isliye humein do directions chahiye:

  1. Regex → NFA (har pattern ek machine ki tarah banaya ja sakta hai) — Thompson's construction.
  2. FA → Regex (har machine ka behavior ek pattern ki tarah express kiya ja sakta hai) — state elimination.

Kyunki NFA ≡ DFA (subset construction, alag jagah prove kiya gaya), regex ↔ NFA prove karna kaafi hai.


Regex syntax (pehle, taaki hum jaanein hum kya convert kar rahe hain)


Direction 1: Regex → NFA (Thompson's construction)

Figure — Regular expressions — equivalence with finite automata

Direction 2: FA → Regex (state elimination / GNFA)


Dono directions ko saath mein rakhna

Recall Feynman: 12 saal ke bacche ko explain karo

Socho ek regex ek recipe likhi in words hai ("pehle ek apple, phir koi bhi number of bananas"). Ek finite automaton ek chhota robot hai jo rooms mein chalta hai jaise woh har fruit khata hai aur green light karta hai agar meal match kare. Kleene's theorem kehta hai: koi bhi recipe jo tum likh sako, uske liye ek robot banaya ja sakta hai jo ise check kare — aur kisi bhi robot ka behavior wapas ek recipe ki tarah likha ja sakta hai. Yeh dono ek hi idea ki do languages hain, toh tum hamesha ek ko doosre mein translate kar sakte ho.


Active recall

Kleene's Theorem kehta hai
Ek language regular (regex-describable) hai iff woh ek finite automaton (DFA/NFA) se accept hoti hai.
Equivalence prove karne wali do constructions
Regex→NFA via Thompson's construction; FA→Regex via state elimination (GNFA).
Union ka Thompson gadget
Naya start ε-branches aur mein; naya accept dono purane accepts se ε ke through reach hota hai.
Concatenation ka Thompson gadget
ke accept se ke start tak ε-edge; accept = ka accept.
Star ka Thompson gadget
Naya start ε se naye accept tak (zero) aur ke start tak; ka accept ε se wapas uske start pe (loop) aur naye accept pe (stop).
State-elimination relabeling rule
.
Elimination mein ka matlab
Jis state ko delete kiya ja raha hai us pe zero ya zyada baar loop karo jaane se pehle.
Elimination se pehle fresh start/accept kyun add karo
Taaki start mein koi incoming aur accept mein koi outgoing edges na hon, jisse rip rule hamesha applicable ho.
ki value
— "kuch bhi nahi ka zero ya zyada baar" empty string hai.
NFA proof kaafi kyun hai (directly DFA nahi)
NFA ≡ DFA by subset construction, toh regex↔NFA se regex↔DFA free mein mil jaata hai.
Kya elimination order language change karta hai
Nahi — alag orders equivalent regexes dete hain (same language), sirf form mein alag.
FA ka Regex: , loop, accept 2
.

Connections

Concept Map

connects

connects

describes

accepts

needs direction

needs direction

method

method

glues gadgets via

mirror

built from

so regex vs NFA suffices

Kleene Theorem iff

Regular expression pattern

Finite automaton machine

Regular languages

Regex to NFA

FA to Regex

Thompson construction

State elimination

Epsilon transitions

Operators union concat star

NFA equiv DFA