SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Theory of Computation - RegularRegular
ExpressionsExpressions
Notation to specify a language
Declarative
Sort of like a programming language.
Fundamental in some languages like perl and
applications like grep or lex
Capable of describing the same thing as a NFA
The two are actually equivalent, so RE =
NFA = DFA
We can define an algebra for regular
expressions
Algebra for LanguagesAlgebra for Languages
 Previously we discussed these operators:
 Union (+)
 Concatenation (.)
 Kleene Star/Closure (*)
Definition of a Regular
Expression
 R is a regular expression if it is:
1. a for some a in the alphabet ∑, standing for the
language {a}
2. , standing for the language { }ε ε
3. Ø, standing for the empty language
4. R1+R2where R1 and R2 are regular expressions, and
+ signifies union (sometimes | is used)
5. R1R2 where R1 and R2 are regular expressions and
this signifies concatenation
6. R* where R is a regular expression and signifies
closure
7. (R) where R is a regular expression, then a
parenthesized R is also a regular expression
RE Examples:RE Examples:
 L(001) = {001}
 L(0+10*) = { 0, 1, 10, 100, 1000, 10000, … }
 L(0*10*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has
exactly a single 1}
 L(∑∑)* = {w | w is a string of even length}
 L((0(0+1))*) = { , 00, 01, 0000, 0001, 0100, 0101, …}ε
 L((0+ )(1+ε ε)) = { , 0, 1, 01}ε
 L(1Ø) = Ø ; concatenating the empty set to any set
yields the empty set.
 R = Rε
 R+Ø = R
Equivalence of FA andEquivalence of FA and
RERE
 Finite Automata and Regular Expressions are
equivalent. To show this:
Show we can express a DFA as an equivalent
RE
Show we can express a RE as an NFA.
Turning a DFA into a RETurning a DFA into a RE
Theorem: If L=L(A) for some DFA , then there
is a regular expression R such that L=L(R).
State Elimination
We’ll see how to do this next, easier than
inductive construction, there is no
exponential number of expressions
DFA to RE: StateDFA to RE: State
EliminationElimination
Eliminates states of the automaton and
replaces the edges with regular expressions
that includes the behavior of the eliminated
states.
Eventually we get down to the situation
with just a start and final node, and this is
easy to express as a RE
DFA to RE via StateDFA to RE via State
Elimination (1)Elimination (1)
1. Starting with intermediate states and then
moving to accepting states, apply the state
elimination process to produce an
equivalent automaton with regular
expression labels on the edges.
• The result will be a one or two state
automaton with a start state and
accepting state.
DFA to RE StateDFA to RE State
Elimination (2):Elimination (2):
2. If the two states are different, we will have an
automaton that looks like the following:
Start
S
R
T
U
We can describe this automaton as:
(R+SU*T)*SU*
DFA to RE StateDFA to RE State
Elimination (3)Elimination (3)
3. If the start state is also an accepting state, then
we must also perform a state elimination from
the original automaton that gets rid of every
state but the start state. This leaves the
following:
Start
R
We can describe this automaton as simply R*.
DFA to RE State EliminationDFA to RE State Elimination
(4)(4)
4. If there are n accepting states, we must repeat
the above steps for each accepting states to get
n different regular expressions, R1, R2, … Rn.
For each repeat we turn any other accepting
state to non-accepting. The desired regular
expression for the automaton is then the union
of each of the n regular expressions: R1∪ R2…
∪ RN
DFARE Example
Convert the following to a RE
First convert the edges to RE’s:
3Start 1 2
1 1
0
0
0,1
3Start 1 2
1 1
0
0
0+1
DFADFA  RE Example (2)RE Example (2)
Eliminate State 1:
3Start 1 2
1 1
0
0
0+1
3Start 2
11
0+10 0+1
Answer: (0+10)*11(0+1)*
Converting a RE to anConverting a RE to an
AutomataAutomata
We have shown we can convert an automata to a
RE. To show equivalence we must also go the
other direction, convert a RE to an automaton.
We can do this easiest by converting a RE to an
NFA
Inductive construction
Start with a simple basis, use that to build
more complex parts of the NFA
RE toRE to NFA:NFA:
Basis:
R=a
R=ε
a
ε
R=Ø
R=S+T
S
T
ε
ε
ε
ε
R=ST
S T
ε
R=S*
S
ε
ε
ε
ε
RE to NFA Example
 Convert R= (ab+a)* to an NFA
We proceed in stages, starting from simple elements
and working our way up
a
a
b
b
ab
a bε
RE toRE to NFANFA Example (2):Example (2):
ab+a
a bε
a
ε
ε
ε
ε
(ab+a)*
a bε
a
ε
ε
ε
ε
εε
ε
ε
Algebraic Laws for RE’s
Just like we have an algebra for arithmetic, we
also have an algebra for regular expressions.
While there are some similarities to arithmetic
algebra, it is a bit different with regular
expressions.
Algebra for RE’s:Algebra for RE’s:
Commutative law for union:
L + M = M + L
Associative law for union:
(L + M) + N = L + (M + N)
Associative law for concatenation:
(LM)N = L(MN)
Note that there is no commutative law for
concatenation, i.e. LM ≠ ML
Algebra for RE’s (2):Algebra for RE’s (2):
The identity for union is:
L + Ø = Ø + L = L
The identity for concatenation is:
L = L = Lε ε
The annihilator for concatenation is:
ØL = LØ = Ø
Left distributive law:
L(M + N) = LM + LN
Right distributive law:
(M + N)L = LM + LN
Idempotent law:
L + L = L
Laws Involving Closure:Laws Involving Closure:
(L*)* = L*
i.e. closing an already closed expression does
not change the language
Ø* = ε
 *ε = ε
L+
= LL* = L*L
L* = L+
+ ε
23
End of SlidesEnd of Slides

More Related Content

PPT
Basics of C programming
PPT
unit-1.ppt
PDF
Automata theory
PDF
Regular language and Regular expression
PDF
Theory of Computation Lecture Notes
PPT
Solar power system
PDF
Morris mano digital logic design
PPTX
Regular expressions
Basics of C programming
unit-1.ppt
Automata theory
Regular language and Regular expression
Theory of Computation Lecture Notes
Solar power system
Morris mano digital logic design
Regular expressions

What's hot (20)

PPTX
Regular expressions
PPTX
Pumping lemma Theory Of Automata
PPTX
Context free grammar
PDF
Daa notes 1
PDF
Deterministic Finite Automata (DFA)
PPT
Regular Languages
PPTX
Specification-of-tokens
PDF
Parse Tree
PPT
Context free grammars
PPT
NFA or Non deterministic finite automata
PPT
Regular expression with DFA
PPTX
Lecture optimal binary search tree
PDF
Flat unit 3
PDF
Algorithms Lecture 1: Introduction to Algorithms
PPTX
Simplification of cfg ppt
PPT
context free language
PPTX
Regular Expression to Finite Automata
PPTX
serializability in dbms
PPTX
Deadlock ppt
PDF
Flat unit 2
Regular expressions
Pumping lemma Theory Of Automata
Context free grammar
Daa notes 1
Deterministic Finite Automata (DFA)
Regular Languages
Specification-of-tokens
Parse Tree
Context free grammars
NFA or Non deterministic finite automata
Regular expression with DFA
Lecture optimal binary search tree
Flat unit 3
Algorithms Lecture 1: Introduction to Algorithms
Simplification of cfg ppt
context free language
Regular Expression to Finite Automata
serializability in dbms
Deadlock ppt
Flat unit 2
Ad

Viewers also liked (17)

PPTX
REGULAR EXPRESSION TO N.F.A
PPTX
Computation Theory Topic
PDF
Quiz1 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
PDF
Pumping lemma (1)
PDF
RegExp20110305
PDF
Differential evolution
PPT
Theory of computing pdf
PPT
Intro automata theory
PDF
NFA to DFA
PDF
Xin Yao: "What can evolutionary computation do for you?"
PPT
Evolution algorithms
PPT
Evolutionary computation and_applications
PDF
Lecture: Regular Expressions and Regular Languages
PPT
introduction to web technology
PDF
Genetic Algorithms Made Easy
PPT
Genetic algorithm
REGULAR EXPRESSION TO N.F.A
Computation Theory Topic
Quiz1 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Pumping lemma (1)
RegExp20110305
Differential evolution
Theory of computing pdf
Intro automata theory
NFA to DFA
Xin Yao: "What can evolutionary computation do for you?"
Evolution algorithms
Evolutionary computation and_applications
Lecture: Regular Expressions and Regular Languages
introduction to web technology
Genetic Algorithms Made Easy
Genetic algorithm
Ad

Similar to Regular expressions-Theory of computation (20)

PPTX
Regular expression
PPTX
Unit-2. Regular Expressions and Languages.pptx
PDF
Formal Languages and Automata Theory unit 2
DOCX
UNIT_-_II.docx
DOCX
Regular Expression .docx
PPTX
Unit2 Toc.pptx
PDF
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
PDF
PPTX
Finite automata-for-lexical-analysis
PPT
02. chapter 3 lexical analysis
PPTX
AUTOMATA AUTOMATA Automata4Chapter3.pptx
PPT
regular expression smmlmmmmmmmmmmmmm.ppt
PPT
regular expression to automata toc flat,
PDF
Unit ii
PPT
RegularExpressions-theory of computation and formal language
PPT
PPT
re1.ppt
PPT
Re1 (3)
DOCX
theory of computation notes for school of engineering
Regular expression
Unit-2. Regular Expressions and Languages.pptx
Formal Languages and Automata Theory unit 2
UNIT_-_II.docx
Regular Expression .docx
Unit2 Toc.pptx
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Finite automata-for-lexical-analysis
02. chapter 3 lexical analysis
AUTOMATA AUTOMATA Automata4Chapter3.pptx
regular expression smmlmmmmmmmmmmmmm.ppt
regular expression to automata toc flat,
Unit ii
RegularExpressions-theory of computation and formal language
re1.ppt
Re1 (3)
theory of computation notes for school of engineering

More from Bipul Roy Bpl (8)

PPT
Specification and complexity - algorithm
PPT
Sequential circuit-Digital Electronics
PPTX
Test design techniques
PPTX
Software engineering quality assurance and testing
PPT
DFD level-0 to 1
PPTX
Garment management system
PPT
Finite automata
PPT
Theory of computing
Specification and complexity - algorithm
Sequential circuit-Digital Electronics
Test design techniques
Software engineering quality assurance and testing
DFD level-0 to 1
Garment management system
Finite automata
Theory of computing

Recently uploaded (20)

PDF
Nekopoi APK 2025 free lastest update
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PPT
Introduction Database Management System for Course Database
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Online Work Permit System for Fast Permit Processing
PDF
top salesforce developer skills in 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
medical staffing services at VALiNTRY
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Introduction to Artificial Intelligence
PPTX
ai tools demonstartion for schools and inter college
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Nekopoi APK 2025 free lastest update
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Choose the Right IT Partner for Your Business in Malaysia
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ISO 45001 Occupational Health and Safety Management System
Introduction Database Management System for Course Database
2025 Textile ERP Trends: SAP, Odoo & Oracle
Online Work Permit System for Fast Permit Processing
top salesforce developer skills in 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
medical staffing services at VALiNTRY
L1 - Introduction to python Backend.pptx
Introduction to Artificial Intelligence
ai tools demonstartion for schools and inter college
Wondershare Filmora 15 Crack With Activation Key [2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Transform Your Business with a Software ERP System
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf

Regular expressions-Theory of computation

  • 1. Theory of Computation - RegularRegular ExpressionsExpressions Notation to specify a language Declarative Sort of like a programming language. Fundamental in some languages like perl and applications like grep or lex Capable of describing the same thing as a NFA The two are actually equivalent, so RE = NFA = DFA We can define an algebra for regular expressions
  • 2. Algebra for LanguagesAlgebra for Languages  Previously we discussed these operators:  Union (+)  Concatenation (.)  Kleene Star/Closure (*)
  • 3. Definition of a Regular Expression  R is a regular expression if it is: 1. a for some a in the alphabet ∑, standing for the language {a} 2. , standing for the language { }ε ε 3. Ø, standing for the empty language 4. R1+R2where R1 and R2 are regular expressions, and + signifies union (sometimes | is used) 5. R1R2 where R1 and R2 are regular expressions and this signifies concatenation 6. R* where R is a regular expression and signifies closure 7. (R) where R is a regular expression, then a parenthesized R is also a regular expression
  • 4. RE Examples:RE Examples:  L(001) = {001}  L(0+10*) = { 0, 1, 10, 100, 1000, 10000, … }  L(0*10*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has exactly a single 1}  L(∑∑)* = {w | w is a string of even length}  L((0(0+1))*) = { , 00, 01, 0000, 0001, 0100, 0101, …}ε  L((0+ )(1+ε ε)) = { , 0, 1, 01}ε  L(1Ø) = Ø ; concatenating the empty set to any set yields the empty set.  R = Rε  R+Ø = R
  • 5. Equivalence of FA andEquivalence of FA and RERE  Finite Automata and Regular Expressions are equivalent. To show this: Show we can express a DFA as an equivalent RE Show we can express a RE as an NFA.
  • 6. Turning a DFA into a RETurning a DFA into a RE Theorem: If L=L(A) for some DFA , then there is a regular expression R such that L=L(R). State Elimination We’ll see how to do this next, easier than inductive construction, there is no exponential number of expressions
  • 7. DFA to RE: StateDFA to RE: State EliminationElimination Eliminates states of the automaton and replaces the edges with regular expressions that includes the behavior of the eliminated states. Eventually we get down to the situation with just a start and final node, and this is easy to express as a RE
  • 8. DFA to RE via StateDFA to RE via State Elimination (1)Elimination (1) 1. Starting with intermediate states and then moving to accepting states, apply the state elimination process to produce an equivalent automaton with regular expression labels on the edges. • The result will be a one or two state automaton with a start state and accepting state.
  • 9. DFA to RE StateDFA to RE State Elimination (2):Elimination (2): 2. If the two states are different, we will have an automaton that looks like the following: Start S R T U We can describe this automaton as: (R+SU*T)*SU*
  • 10. DFA to RE StateDFA to RE State Elimination (3)Elimination (3) 3. If the start state is also an accepting state, then we must also perform a state elimination from the original automaton that gets rid of every state but the start state. This leaves the following: Start R We can describe this automaton as simply R*.
  • 11. DFA to RE State EliminationDFA to RE State Elimination (4)(4) 4. If there are n accepting states, we must repeat the above steps for each accepting states to get n different regular expressions, R1, R2, … Rn. For each repeat we turn any other accepting state to non-accepting. The desired regular expression for the automaton is then the union of each of the n regular expressions: R1∪ R2… ∪ RN
  • 12. DFARE Example Convert the following to a RE First convert the edges to RE’s: 3Start 1 2 1 1 0 0 0,1 3Start 1 2 1 1 0 0 0+1
  • 13. DFADFA  RE Example (2)RE Example (2) Eliminate State 1: 3Start 1 2 1 1 0 0 0+1 3Start 2 11 0+10 0+1 Answer: (0+10)*11(0+1)*
  • 14. Converting a RE to anConverting a RE to an AutomataAutomata We have shown we can convert an automata to a RE. To show equivalence we must also go the other direction, convert a RE to an automaton. We can do this easiest by converting a RE to an NFA Inductive construction Start with a simple basis, use that to build more complex parts of the NFA
  • 15. RE toRE to NFA:NFA: Basis: R=a R=ε a ε R=Ø
  • 17. RE to NFA Example  Convert R= (ab+a)* to an NFA We proceed in stages, starting from simple elements and working our way up a a b b ab a bε
  • 18. RE toRE to NFANFA Example (2):Example (2): ab+a a bε a ε ε ε ε (ab+a)* a bε a ε ε ε ε εε ε ε
  • 19. Algebraic Laws for RE’s Just like we have an algebra for arithmetic, we also have an algebra for regular expressions. While there are some similarities to arithmetic algebra, it is a bit different with regular expressions.
  • 20. Algebra for RE’s:Algebra for RE’s: Commutative law for union: L + M = M + L Associative law for union: (L + M) + N = L + (M + N) Associative law for concatenation: (LM)N = L(MN) Note that there is no commutative law for concatenation, i.e. LM ≠ ML
  • 21. Algebra for RE’s (2):Algebra for RE’s (2): The identity for union is: L + Ø = Ø + L = L The identity for concatenation is: L = L = Lε ε The annihilator for concatenation is: ØL = LØ = Ø Left distributive law: L(M + N) = LM + LN Right distributive law: (M + N)L = LM + LN Idempotent law: L + L = L
  • 22. Laws Involving Closure:Laws Involving Closure: (L*)* = L* i.e. closing an already closed expression does not change the language Ø* = ε  *ε = ε L+ = LL* = L*L L* = L+ + ε
  • 23. 23 End of SlidesEnd of Slides