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

What's hot (20)

PPTX
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
PPTX
Pumping lemma Theory Of Automata
hafizhamza0322
 
PPT
Theory of computing
Ranjan Kumar
 
PDF
Chapter1 Formal Language and Automata Theory
Tsegazeab Asgedom
 
PDF
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
 
PDF
Flat unit 1
VenkataRaoS1
 
PDF
Ch3 4 regular expression and grammar
meresie tesfay
 
PPT
Parsing
khush_boo31
 
PDF
Flat unit 3
VenkataRaoS1
 
PPT
Asymptotic notation
Dr Shashikant Athawale
 
PPTX
Asymptotic notations
Nikhil Sharma
 
PPT
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
PPTX
LR(1) and SLR(1) parsing
R Islam
 
PPT
Regular Languages
parmeet834
 
PDF
Automata theory
Pardeep Vats
 
PPT
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
PPTX
Introduction TO Finite Automata
Ratnakar Mikkili
 
PPT
NFA or Non deterministic finite automata
deepinderbedi
 
PPTX
NFA & DFA
Akhil Kaushik
 
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Pumping lemma Theory Of Automata
hafizhamza0322
 
Theory of computing
Ranjan Kumar
 
Chapter1 Formal Language and Automata Theory
Tsegazeab Asgedom
 
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
 
Flat unit 1
VenkataRaoS1
 
Ch3 4 regular expression and grammar
meresie tesfay
 
Parsing
khush_boo31
 
Flat unit 3
VenkataRaoS1
 
Asymptotic notation
Dr Shashikant Athawale
 
Asymptotic notations
Nikhil Sharma
 
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
LR(1) and SLR(1) parsing
R Islam
 
Regular Languages
parmeet834
 
Automata theory
Pardeep Vats
 
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
Introduction TO Finite Automata
Ratnakar Mikkili
 
NFA or Non deterministic finite automata
deepinderbedi
 
NFA & DFA
Akhil Kaushik
 

Viewers also liked (18)

PPTX
REGULAR EXPRESSION TO N.F.A
Dev Ashish
 
PPTX
Computation Theory Topic
Rehan Hattab
 
PDF
Quiz1 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Vivekananda Samiti
 
PDF
Pumping lemma (1)
Self-employed
 
PDF
RegExp20110305
tmiya
 
PDF
Differential evolution
ҚяậŧĭҚậ Jậĭn
 
PPT
Theory of computing pdf
Dilouar Hossain
 
PPT
Intro automata theory
Rajendran
 
PPT
Regular expression with DFA
Maulik Togadiya
 
PDF
NFA to DFA
Animesh Chaturvedi
 
PDF
Xin Yao: "What can evolutionary computation do for you?"
ieee_cis_cyprus
 
PPT
Evolution algorithms
Andrii Babii
 
PPT
Evolutionary computation and_applications
ddawar
 
PDF
Lecture: Regular Expressions and Regular Languages
Marina Santini
 
PPT
introduction to web technology
vikram singh
 
PDF
Genetic Algorithms Made Easy
Prakash Pimpale
 
PPT
Genetic algorithm
garima931
 
REGULAR EXPRESSION TO N.F.A
Dev Ashish
 
Computation Theory Topic
Rehan Hattab
 
Quiz1 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Vivekananda Samiti
 
Pumping lemma (1)
Self-employed
 
RegExp20110305
tmiya
 
Differential evolution
ҚяậŧĭҚậ Jậĭn
 
Theory of computing pdf
Dilouar Hossain
 
Intro automata theory
Rajendran
 
Regular expression with DFA
Maulik Togadiya
 
NFA to DFA
Animesh Chaturvedi
 
Xin Yao: "What can evolutionary computation do for you?"
ieee_cis_cyprus
 
Evolution algorithms
Andrii Babii
 
Evolutionary computation and_applications
ddawar
 
Lecture: Regular Expressions and Regular Languages
Marina Santini
 
introduction to web technology
vikram singh
 
Genetic Algorithms Made Easy
Prakash Pimpale
 
Genetic algorithm
garima931
 
Ad

Similar to Regular expressions-Theory of computation (20)

PPTX
Regular expression
MONIRUL ISLAM
 
PDF
Flat unit 2
VenkataRaoS1
 
PDF
Formal Languages and Automata Theory unit 2
Srimatre K
 
DOCX
UNIT_-_II.docx
karthikeyan Muthusamy
 
PPTX
Unit2 Toc.pptx
viswanath kani
 
PDF
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Rushabh2428
 
PDF
FLAT.pdf
AtharvaJoshi930911
 
PPTX
Finite automata-for-lexical-analysis
Dattatray Gandhmal
 
PPT
02. chapter 3 lexical analysis
raosir123
 
PPTX
AUTOMATA AUTOMATA Automata4Chapter3.pptx
ArjayBalberan1
 
PPT
regular expression smmlmmmmmmmmmmmmm.ppt
rishabhsrivastava518345
 
PDF
Unit ii
TPLatchoumi
 
PPT
re1.ppt
PEzhumalai
 
PPT
RegularExpressions-theory of computation and formal language
mohdfareeduddin5
 
PPT
re1.ppt
Sarvesh Warjurkar
 
PPT
Re1 (3)
pepe3059
 
DOCX
theory of computation notes for school of engineering
FIONACHATOLA
 
PPT
Ch3.ppt
MDSayem35
 
PPT
Chapter Three(2)
bolovv
 
Regular expression
MONIRUL ISLAM
 
Flat unit 2
VenkataRaoS1
 
Formal Languages and Automata Theory unit 2
Srimatre K
 
UNIT_-_II.docx
karthikeyan Muthusamy
 
Unit2 Toc.pptx
viswanath kani
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Rushabh2428
 
Finite automata-for-lexical-analysis
Dattatray Gandhmal
 
02. chapter 3 lexical analysis
raosir123
 
AUTOMATA AUTOMATA Automata4Chapter3.pptx
ArjayBalberan1
 
regular expression smmlmmmmmmmmmmmmm.ppt
rishabhsrivastava518345
 
Unit ii
TPLatchoumi
 
re1.ppt
PEzhumalai
 
RegularExpressions-theory of computation and formal language
mohdfareeduddin5
 
Re1 (3)
pepe3059
 
theory of computation notes for school of engineering
FIONACHATOLA
 
Ch3.ppt
MDSayem35
 
Chapter Three(2)
bolovv
 
Ad

More from Bipul Roy Bpl (8)

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

Recently uploaded (20)

PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Import Data Form Excel to Tally Services
Tally xperts
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 

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