SlideShare a Scribd company logo
© 2020 Wael Badawy
1
Regular Expressions
1
DISCLAIMER:
This video is optimized for HD large display using
patented and patent-pending “Nile Codec”, the first
Egyptian Video Codec for more information,
PLEASE check https://NileCodec.com
Also available as a PodCast
© 2020 Wael Badawy
Copyright © 2020 Wael Badawy. All rights reserved
n This video is subject to copyright owned by Wael Badawy “WB”. Any
reproduction or republication of all or part of this video is expressly prohibited
unless WB has explicitly granted its prior written consent. All other rights
reserved.
n This video is intended for education and information only and is offered AS IS,
without any warranty of the accuracy or the quality of the content. Any other
use is strictly prohibited. The viewer is fully responsible to verify the accuracy
of the contents received without any claims of costs or liability arising .
n The names, trademarks service marked as logos of WB or the sponsors
appearing in this video may not be used in any any product or service,
without prior express written permission from WB and the video sponsors
n Neither WB nor any party involved in creating, producing or delivering
information and material via this video shall be liable for any direction,
incidental, consequential, indirect of punitive damages arising out of access
to, use or inability to use this content or any errors or omissions in the
content thereof.
n If you will continue to watch this video, you agree to the terms above and
other terms that may be available on http://nu.edu.eg & https://caiwave.net
2
© 2020 Wael Badawy
© 2020 Wael Badawy
Regular Expressions
Regular expressions
describe regular languages
Example:
describes the language
4
*
)( cba ×+
{ } { },...,,,,,,
*
bcaabcaabcabca e=
© 2020 Wael Badawy
Recursive Definition
5
ae,,Æ
( )1
*
1
21
21
r
r
rr
rr
×
+
Are regular expressions
Primitive regular expressions:
2r1rGiven regular expressions and
© 2020 Wael Badawy
Examples
6
( ) )(
*
Æ+××+ ccbaA regular expression:
( )++ baNot a regular expression:
© 2020 Wael Badawy
Languages of Regular
Expressions
: language of regular expression
Example
7
( )rL r
( ) { },...,,,,,)( *
bcaabcaabcacbaL e=×+
© 2020 Wael Badawy
Definition
For primitive regular expressions:
8
( )
( ) { }
( ) { }aaL
L
L
=
=
Æ=Æ
ee
© 2020 Wael Badawy
Definition (continued)
For regular expressions and
9
1r 2r
( ) ( ) ( )2121 rLrLrrL È=+
( ) ( ) ( )2121 rLrLrrL =×
( ) ( )( )*
1
*
1 rLrL =
( )( ) ( )11 rLrL =
© 2020 Wael Badawy
Example
Regular expression:
10
( ) *
aba ×+
( )( )*abaL ×+ ( )( ) ( )*
aLbaL +=
( ) ( )*
aLbaL +=
( ) ( )( ) ( )( )*
aLbLaL È=
{ } { }( ) { }( )*
aba È=
{ }{ },...,,,, aaaaaaba e=
{ },...,,,...,,, baababaaaaaa=
© 2020 Wael Badawy
Example
Regular expression
11
( ) ( )bbabar ++=
*
( ) { },...,,,,, bbbbaabbaabbarL =
© 2020 Wael Badawy
Example
Regular expression
12
( ) ( ) bbbaar
**
=
( ) }0,:{ 22
³= mnbbarL mn
© 2020 Wael Badawy
Example
Regular expression
13
**
)10(00)10( ++=r
)(rL = { all strings containing substring 00 }
© 2020 Wael Badawy
Example
Regular expression
14
)0()011( *
e++=r
)(rL = { all strings without substring 00 }
© 2020 Wael Badawy
Equivalent Regular Expressions
Definition:
Regular expressions and
are equivalent if
15
1r 2r
)()( 21 rLrL =
© 2020 Wael Badawy
Example
16
L = { all strings without substring 00 }
)0()011( *
1 e++=r
)0(1)0()0111( ****
2 ee +++=r
LrLrL == )()( 21
1r 2rand
are equivalent
regular expressions
17
Regular Expressions
and
Regular Languages
17
© 2020 Wael Badawy
Theorem
18
Languages
Generated by
Regular Expressions
Regular
Languages=
© 2020 Wael Badawy
19
Languages
Generated by
Regular Expressions
Regular
Languages
Í
Languages
Generated by
Regular Expressions
Regular
Languages
Ê
Proof:
© 2020 Wael Badawy
20
Proof - Part 1
r
)(rL
For any regular expression
the language is regular
Languages
Generated by
Regular Expressions
Regular
Languages
Í
Proof by induction on the size of r
© 2020 Wael Badawy
Induction Basis
Primitive Regular Expressions:
21
ae,,Æ
Corresponding
NFAs
)()( 1 Æ=Æ= LML
)(}{)( 2 ee LML ==
)(}{)( 3 aLaML ==
regular
languages
a
© 2020 Wael Badawy
Inductive Hypothesis
Suppose
that for regular expressions and ,
and are regular languages
22
1r 2r
)( 1rL )( 2rL
© 2020 Wael Badawy
Inductive Step
We will prove:
23
( )
( )
( )
( )( )1
*
1
21
21
rL
rL
rrL
rrL
×
+
Are regular
Languages
© 2020 Wael Badawy
By definition of regular expressions:
24
( ) ( ) ( )
( ) ( ) ( )
( ) ( )( )
( )( ) ( )11
*
1
*
1
2121
2121
rLrL
rLrL
rLrLrrL
rLrLrrL
=
=
=×
È=+
© 2020 Wael Badawy
25
)( 1rL )( 2rL
By inductive hypothesis we know:
and are regular languages
Regular languages are closed under:
( ) ( )
( ) ( )
( )( )*
1
21
21
rL
rLrL
rLrL ÈUnion
Concatenation
Star
We also know:
© 2020 Wael Badawy
Therefore:
26
( ) ( ) ( )
( ) ( ) ( )
( ) ( )( )*
1
*
1
2121
2121
rLrL
rLrLrrL
rLrLrrL
=
=×
È=+
Are regular
languages
)())(( 11 rLrL = is trivially a regular language
(by induction hypothesis)
End of Proof-Part 1
© 2020 Wael Badawy
27
Using the regular closure of operations,
we can construct recursively the NFA
that accepts
M
)()( rLML =
Example: 21 rrr +=
)()( 11 rLML =
)()( 22 rLML =
)()( rLML =
e
e
© 2020 Wael Badawy
28
For any regular language there is
a regular expression with
Proof - Part 2
Languages
Generated by
Regular Expressions
Regular
Languages
Ê
L
r LrL =)(
We will convert an NFA that accepts
to a regular expression
L
© 2020 Wael Badawy
Since is regular, there is a
NFA that accepts it
29
L
M
LML =)(
Take it with a single accept state
© 2020 Wael Badawy
From construct the equivalent
Generalized Transition Graph
in which transition labels are regular expressions
30
M
Example:
a
ba,
c
M
a
ba +
c
Corresponding
Generalized transition graph
© 2020 Wael Badawy
Another Example:
31
ba +
a
b
b
0q 1q 2q
ba,
a
b
b
0q 1q 2q
b
bTransition labels
are regular
expressions
© 2020 Wael Badawy
Reducing the states:
32
ba +
a
b
b
0q 1q 2q
b
0q 2q
babb*
)(*
babb +
Transition labels
are regular
expressions
© 2020 Wael Badawy
Resulting Regular Expression:
33
0q 2q
babb*
)(*
babb +
****
)()( bbabbabbr +=
LMLrL == )()(
© 2020 Wael Badawy
In General
Removing a state:
34
iq q jq
a b
cd
e
iq jq
dae*
bce*
dce*
bae*
2-neighbors
© 2020 Wael Badawy
35
iq jq
dae*
bce*
dce*
bae*
iq q jq
a b
cd
e
kq
f g
kq
fge*
dge*
fae*
bge*
fce*
This can be generalized
to arbitrary number
of neighbors to q
3-neighbors
© 2020 Wael Badawy
36
0q fq
1r
2r
3r
4r
*
2
*
1342
*
1 )( rrrrrrr +=
LMLrL == )()(
The resulting regular expression:
By repeating the process until
two states are left, the resulting graph is
Initial graph Resulting graph
End of Proof-Part 2
© 2020 Wael Badawy
Standard Representations
of Regular Languages
37
Regular Languages
DFAs
NFAs
Regular
Expressions
© 2020 Wael Badawy
38
When we say: We are given
a Regular Language
We mean:
L
Language is in a standard
representation
L
(DFA, NFA, or Regular Expression)

More Related Content

Similar to Regular expressions

Turing Machine
Turing MachineTuring Machine
Turing Machine
Wael Badawy
 
Turing variations
Turing variations Turing variations
Turing variations
Wael Badawy
 
Computer Vision panoramas
Computer Vision panoramas Computer Vision panoramas
Computer Vision panoramas
Wael Badawy
 
Computer Vision RANSAC
Computer Vision RANSACComputer Vision RANSAC
Computer Vision RANSAC
Wael Badawy
 
Computer Vision single view Modelling
Computer Vision single view ModellingComputer Vision single view Modelling
Computer Vision single view Modelling
Wael Badawy
 
Computer Vision Cameras
Computer Vision CamerasComputer Vision Cameras
Computer Vision Cameras
Wael Badawy
 

Similar to Regular expressions (6)

Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Turing variations
Turing variations Turing variations
Turing variations
 
Computer Vision panoramas
Computer Vision panoramas Computer Vision panoramas
Computer Vision panoramas
 
Computer Vision RANSAC
Computer Vision RANSACComputer Vision RANSAC
Computer Vision RANSAC
 
Computer Vision single view Modelling
Computer Vision single view ModellingComputer Vision single view Modelling
Computer Vision single view Modelling
 
Computer Vision Cameras
Computer Vision CamerasComputer Vision Cameras
Computer Vision Cameras
 

More from Wael Badawy

HTML introduction
HTML introduction HTML introduction
HTML introduction
Wael Badawy
 
Parsers -
Parsers -Parsers -
Parsers -
Wael Badawy
 
Computer Vision Gans
Computer Vision GansComputer Vision Gans
Computer Vision Gans
Wael Badawy
 
Computer Vision image classification
Computer Vision image classificationComputer Vision image classification
Computer Vision image classification
Wael Badawy
 
Computer Vision Structure from motion
Computer Vision Structure from motionComputer Vision Structure from motion
Computer Vision Structure from motion
Wael Badawy
 
Pushdown Automota
Pushdown Automota Pushdown Automota
Pushdown Automota
Wael Badawy
 
Computer Vision sfm
Computer Vision sfmComputer Vision sfm
Computer Vision sfm
Wael Badawy
 
Computer vision - photometric
Computer vision - photometricComputer vision - photometric
Computer vision - photometric
Wael Badawy
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - light
Wael Badawy
 
Computer vision - two view geometry
Computer vision -  two view geometryComputer vision -  two view geometry
Computer vision - two view geometry
Wael Badawy
 
Computer Vision - Stereo Vision
Computer Vision - Stereo VisionComputer Vision - Stereo Vision
Computer Vision - Stereo Vision
Wael Badawy
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single View
Wael Badawy
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramas
Wael Badawy
 
Computer Vision - cameras
Computer Vision - camerasComputer Vision - cameras
Computer Vision - cameras
Wael Badawy
 
Computer Vision - RANSAC
Computer Vision - RANSACComputer Vision - RANSAC
Computer Vision - RANSAC
Wael Badawy
 
Computer Vision alignment
Computer Vision alignmentComputer Vision alignment
Computer Vision alignment
Wael Badawy
 

More from Wael Badawy (16)

HTML introduction
HTML introduction HTML introduction
HTML introduction
 
Parsers -
Parsers -Parsers -
Parsers -
 
Computer Vision Gans
Computer Vision GansComputer Vision Gans
Computer Vision Gans
 
Computer Vision image classification
Computer Vision image classificationComputer Vision image classification
Computer Vision image classification
 
Computer Vision Structure from motion
Computer Vision Structure from motionComputer Vision Structure from motion
Computer Vision Structure from motion
 
Pushdown Automota
Pushdown Automota Pushdown Automota
Pushdown Automota
 
Computer Vision sfm
Computer Vision sfmComputer Vision sfm
Computer Vision sfm
 
Computer vision - photometric
Computer vision - photometricComputer vision - photometric
Computer vision - photometric
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - light
 
Computer vision - two view geometry
Computer vision -  two view geometryComputer vision -  two view geometry
Computer vision - two view geometry
 
Computer Vision - Stereo Vision
Computer Vision - Stereo VisionComputer Vision - Stereo Vision
Computer Vision - Stereo Vision
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single View
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramas
 
Computer Vision - cameras
Computer Vision - camerasComputer Vision - cameras
Computer Vision - cameras
 
Computer Vision - RANSAC
Computer Vision - RANSACComputer Vision - RANSAC
Computer Vision - RANSAC
 
Computer Vision alignment
Computer Vision alignmentComputer Vision alignment
Computer Vision alignment
 

Recently uploaded

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

Regular expressions

  • 1. © 2020 Wael Badawy 1 Regular Expressions 1 DISCLAIMER: This video is optimized for HD large display using patented and patent-pending “Nile Codec”, the first Egyptian Video Codec for more information, PLEASE check https://NileCodec.com Also available as a PodCast
  • 2. © 2020 Wael Badawy Copyright © 2020 Wael Badawy. All rights reserved n This video is subject to copyright owned by Wael Badawy “WB”. Any reproduction or republication of all or part of this video is expressly prohibited unless WB has explicitly granted its prior written consent. All other rights reserved. n This video is intended for education and information only and is offered AS IS, without any warranty of the accuracy or the quality of the content. Any other use is strictly prohibited. The viewer is fully responsible to verify the accuracy of the contents received without any claims of costs or liability arising . n The names, trademarks service marked as logos of WB or the sponsors appearing in this video may not be used in any any product or service, without prior express written permission from WB and the video sponsors n Neither WB nor any party involved in creating, producing or delivering information and material via this video shall be liable for any direction, incidental, consequential, indirect of punitive damages arising out of access to, use or inability to use this content or any errors or omissions in the content thereof. n If you will continue to watch this video, you agree to the terms above and other terms that may be available on http://nu.edu.eg & https://caiwave.net 2
  • 3. © 2020 Wael Badawy
  • 4. © 2020 Wael Badawy Regular Expressions Regular expressions describe regular languages Example: describes the language 4 * )( cba ×+ { } { },...,,,,,, * bcaabcaabcabca e=
  • 5. © 2020 Wael Badawy Recursive Definition 5 ae,,Æ ( )1 * 1 21 21 r r rr rr × + Are regular expressions Primitive regular expressions: 2r1rGiven regular expressions and
  • 6. © 2020 Wael Badawy Examples 6 ( ) )( * Æ+××+ ccbaA regular expression: ( )++ baNot a regular expression:
  • 7. © 2020 Wael Badawy Languages of Regular Expressions : language of regular expression Example 7 ( )rL r ( ) { },...,,,,,)( * bcaabcaabcacbaL e=×+
  • 8. © 2020 Wael Badawy Definition For primitive regular expressions: 8 ( ) ( ) { } ( ) { }aaL L L = = Æ=Æ ee
  • 9. © 2020 Wael Badawy Definition (continued) For regular expressions and 9 1r 2r ( ) ( ) ( )2121 rLrLrrL È=+ ( ) ( ) ( )2121 rLrLrrL =× ( ) ( )( )* 1 * 1 rLrL = ( )( ) ( )11 rLrL =
  • 10. © 2020 Wael Badawy Example Regular expression: 10 ( ) * aba ×+ ( )( )*abaL ×+ ( )( ) ( )* aLbaL += ( ) ( )* aLbaL += ( ) ( )( ) ( )( )* aLbLaL È= { } { }( ) { }( )* aba È= { }{ },...,,,, aaaaaaba e= { },...,,,...,,, baababaaaaaa=
  • 11. © 2020 Wael Badawy Example Regular expression 11 ( ) ( )bbabar ++= * ( ) { },...,,,,, bbbbaabbaabbarL =
  • 12. © 2020 Wael Badawy Example Regular expression 12 ( ) ( ) bbbaar ** = ( ) }0,:{ 22 ³= mnbbarL mn
  • 13. © 2020 Wael Badawy Example Regular expression 13 ** )10(00)10( ++=r )(rL = { all strings containing substring 00 }
  • 14. © 2020 Wael Badawy Example Regular expression 14 )0()011( * e++=r )(rL = { all strings without substring 00 }
  • 15. © 2020 Wael Badawy Equivalent Regular Expressions Definition: Regular expressions and are equivalent if 15 1r 2r )()( 21 rLrL =
  • 16. © 2020 Wael Badawy Example 16 L = { all strings without substring 00 } )0()011( * 1 e++=r )0(1)0()0111( **** 2 ee +++=r LrLrL == )()( 21 1r 2rand are equivalent regular expressions
  • 18. © 2020 Wael Badawy Theorem 18 Languages Generated by Regular Expressions Regular Languages=
  • 19. © 2020 Wael Badawy 19 Languages Generated by Regular Expressions Regular Languages Í Languages Generated by Regular Expressions Regular Languages Ê Proof:
  • 20. © 2020 Wael Badawy 20 Proof - Part 1 r )(rL For any regular expression the language is regular Languages Generated by Regular Expressions Regular Languages Í Proof by induction on the size of r
  • 21. © 2020 Wael Badawy Induction Basis Primitive Regular Expressions: 21 ae,,Æ Corresponding NFAs )()( 1 Æ=Æ= LML )(}{)( 2 ee LML == )(}{)( 3 aLaML == regular languages a
  • 22. © 2020 Wael Badawy Inductive Hypothesis Suppose that for regular expressions and , and are regular languages 22 1r 2r )( 1rL )( 2rL
  • 23. © 2020 Wael Badawy Inductive Step We will prove: 23 ( ) ( ) ( ) ( )( )1 * 1 21 21 rL rL rrL rrL × + Are regular Languages
  • 24. © 2020 Wael Badawy By definition of regular expressions: 24 ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )( ) ( )( ) ( )11 * 1 * 1 2121 2121 rLrL rLrL rLrLrrL rLrLrrL = = =× È=+
  • 25. © 2020 Wael Badawy 25 )( 1rL )( 2rL By inductive hypothesis we know: and are regular languages Regular languages are closed under: ( ) ( ) ( ) ( ) ( )( )* 1 21 21 rL rLrL rLrL ÈUnion Concatenation Star We also know:
  • 26. © 2020 Wael Badawy Therefore: 26 ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )( )* 1 * 1 2121 2121 rLrL rLrLrrL rLrLrrL = =× È=+ Are regular languages )())(( 11 rLrL = is trivially a regular language (by induction hypothesis) End of Proof-Part 1
  • 27. © 2020 Wael Badawy 27 Using the regular closure of operations, we can construct recursively the NFA that accepts M )()( rLML = Example: 21 rrr += )()( 11 rLML = )()( 22 rLML = )()( rLML = e e
  • 28. © 2020 Wael Badawy 28 For any regular language there is a regular expression with Proof - Part 2 Languages Generated by Regular Expressions Regular Languages Ê L r LrL =)( We will convert an NFA that accepts to a regular expression L
  • 29. © 2020 Wael Badawy Since is regular, there is a NFA that accepts it 29 L M LML =)( Take it with a single accept state
  • 30. © 2020 Wael Badawy From construct the equivalent Generalized Transition Graph in which transition labels are regular expressions 30 M Example: a ba, c M a ba + c Corresponding Generalized transition graph
  • 31. © 2020 Wael Badawy Another Example: 31 ba + a b b 0q 1q 2q ba, a b b 0q 1q 2q b bTransition labels are regular expressions
  • 32. © 2020 Wael Badawy Reducing the states: 32 ba + a b b 0q 1q 2q b 0q 2q babb* )(* babb + Transition labels are regular expressions
  • 33. © 2020 Wael Badawy Resulting Regular Expression: 33 0q 2q babb* )(* babb + **** )()( bbabbabbr += LMLrL == )()(
  • 34. © 2020 Wael Badawy In General Removing a state: 34 iq q jq a b cd e iq jq dae* bce* dce* bae* 2-neighbors
  • 35. © 2020 Wael Badawy 35 iq jq dae* bce* dce* bae* iq q jq a b cd e kq f g kq fge* dge* fae* bge* fce* This can be generalized to arbitrary number of neighbors to q 3-neighbors
  • 36. © 2020 Wael Badawy 36 0q fq 1r 2r 3r 4r * 2 * 1342 * 1 )( rrrrrrr += LMLrL == )()( The resulting regular expression: By repeating the process until two states are left, the resulting graph is Initial graph Resulting graph End of Proof-Part 2
  • 37. © 2020 Wael Badawy Standard Representations of Regular Languages 37 Regular Languages DFAs NFAs Regular Expressions
  • 38. © 2020 Wael Badawy 38 When we say: We are given a Regular Language We mean: L Language is in a standard representation L (DFA, NFA, or Regular Expression)