SlideShare una empresa de Scribd logo
1 de 33
UNIT-2
REGULAR EXPRESSION
K LAKSHMI SRVANI
ASST PROFESSOR
SYLLABUS
Regular Expressions: Finite Automata and Regular Expressions,
Applications of Regular Expressions, Algebraic Laws for Regular
Expressions, Conversion of Finite Automata to Regular Expressions.
Pumping Lemma for Regular Languages, Statement of the pumping
lemma, Applications of the Pumping Lemma.
Closure Properties of Regular Languages: Closure properties of
Regular languages, Decision Properties of Regular Languages,
Equivalence and Minimization of Automata.
Regular Expressions.
● Regular expressions are used for representing certain
sets of strings in algebraic fashion.
● Any terminal symbol belongs to Σ including ɸ,ɛ are
RE
● The union of 2 RE is also RE
● The Concatenation of 2 RE is also RE
● The iteration or closure of RE is also RE
Regular Expressions Regular Set
(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }
(0*10*) L = {1, 01, 10, 010, 0010, …}
(0 + ε)(1 + ε) L = {ε, 0, 1, 01}
(a+b)* Set of strings of a’s and b’s of any length
including the null string. So L = { ε, a, b, aa
, ab , bb , ba, aaa…….}
(11)* Set consisting of even number of 1’s
including empty string, So L= {ε, 11, 1111,
111111, ……….}
(0+1)*011(0+1)* Sub string 011
Operators of RE
Operators used in regular expressions include:
• Union: If R1 and R2 are regular expressions, then R1 | R2 (also written as R1 U R2 or R1 +
R2) is also a regular expression.
L(R1|R2) = L(R1) U L(R2) or L(R1+R2)



• Concatenation: If R1 and R2 are regular expressions, then R1R2 (also written as R1.R2) is
also a regular expression.
L(R1R2) = L(R1) concatenated with L(R2).



• Kleene closure: If R1 is a regular expression, then R1* (the Kleene closure of R1) is also a
regular expression.
L(R1*) = epsilon U L(R1) U L(R1R1) U L(R1R1R1) U ...

Precedence
● Closure > Concatenation > Union
● (01*+1)
Applications of RE
● RE in unix
• [ :digit:][0-9]
• [:alpha:]a-z A-Z
• [:Alnum:] [A-Z a-z 0-9]
● Lexical Analysis
● Finding Patterns in Text
● Grep utility in unix.
Algebraic Laws of RE
● COMMUTATIVITY
● ASSOCIATIVITY
● IDENTITIES
● ANNIHILATOR
● DISTRIBUTIVE
● IDEMPOTENT
COMMUTATIVITY
● For regular expressions, we have:
● L + M = M + L
● Commutative law for union: we may make the union of two
languages in either order
● Clearly the law L.M = M.L is FALSE (Commutative law for
concatenation)
ASSOCIATIVITY
● (L + M) + N = L + ( M + N) Associative law for union: we
may take the union of three languages either by taking the
union of the first two initially, or taking the union of the last
two initially. Together with the commutative law we can take
the union of any collection of languages with any order and
grouping, and the result will be the same. Intuitively, a string
is in L1 ∪ L2 . . . ∪ Lk iff it is in one or more of the Li s.
● (L.M).N = L.(M.N) Associative law for concatenation: we
can concatenate three-languages by concatenating either the
first two or the last two initially
IDENTITIES
● An identity for an operator is a value that when the
operator is applied to the identity and some other value, the
result is the other value.
● ∅ + L = L + ∅ = L
● e.L = L.e = L
ANNIHILATOR
● An annihilator for an operator is value that when the
operator is applied to the annihilator and some other
value, the result is the annihilator.
● ∅.L = L. ∅ = ∅
DISTRIBUTIVE
● For regular expressions we have:
● Left distributivity: L.(M + N) = LM + LN
● Right distributivity: (M + N).L = ML + NL
IDEMPOTENT
● An operator is idempotent if the result of applying it to two
of
● the same values as arguments is that value.
● Idempotent Law for union:
● L + L = L
● If we take the union of two identical expressions, we can
replace them by one copy of the expression.
Identities Related to Regular Expressions l={0,1}{l2}
Given R, P, L, Q as regular expressions, the following
identities hold −
• ∅* = ε
• ε* = ε
• RR* = R*R=R+
• R*R* = R*
• (R*)* = R*
• (PQ)*P =P(QP)*
• (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
• R + ∅ = ∅ + R = R (The identity for union)
• R ε = ε R = R (The identity for concatenation)
• ∅ L = L ∅ = ∅ (The annihilator for concatenation)
• R + R = R (Idempotent law)
• L (M + N) = LM + LN (Left distributive law)
• (M + N) L = ML + NL (Right distributive law)
• ε + RR* = ε + R*R = R*
Arden’s Theorem
In order to find out a regular expression of a Finite Automaton, we
use Arden’s Theorem along with the properties of regular
expressions.
Statement −
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique
solution that is R = QP*
Proof −
R = Q + (Q + RP)P [After putting the value R = Q + RP]
= Q + QP + RPP
When we put the value of R recursively again and again, we get the
following equation −
R = Q + QP + QP2 + QP3…..
R = Q (ε + P + P2 + P3 + …. )
R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
Hence, proved.
FA & RE
From DFA to RE
● Arden’s Theorem Steps:
● 1) Build RE for each state
● 2) Solve final states equations first
● State Elimination Method Steps
● 1) The start state of DFA must not have any incoming edges. If there exists any
incoming edge to start state ,then create a new state having no income edges.
● 2)There must be only one final state in DFA, If DFA contain more final states,
then create a new final state and all other final states to non final states
● 3) The final state of DFA doesn’t contain any out going edges, then create new
final state without any out going edges
● 4) Now start elimination intermediate states in any order. Finally we have
initial state going to final state.
● Question 1:
Question 2
RE to FA
Limitation of FA
● It have finite number of states.
● Finite amount of memory so doesn’t remember
previous state outcome.
● So in above scenarios we use pumping lemma.
Pumping Lemma
Theorem
Let L be a regular language. Then there exists a
constant ‘n’ such that for every string w in L −
|w| ≥ n
We can break w into three strings, w = xyz, such that −
• |y| = ε
• |xy| ≤ n
• For all k ≥ 0, the string xykz is also in L.
Applications of Pumping Lemma
Pumping Lemma is to be applied to show that certain
languages are not regular. It should never be used to show a
language is regular.
• If L is regular, it satisfies Pumping Lemma.

• If L does not satisfy Pumping Lemma, it is non-regular.

Applications of PL
Properties of Regular Sets/ Closure Properties
Property 1. The union of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(aa)* and RE2 = (aa)*
So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length
excluding Null)
and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even
length including Null)
L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
(Strings of all possible lengths including Null)
RE (L1 ∪ L2) = a* (which is a regular expression itself)
Hence, proved.
Property 2. The intersection of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(a*) and RE2 = (aa)*
So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths
excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length
including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length
excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.
Property 3. The complement of a regular set is regular.
Proof −
Let us take a regular expression −
RE = (aa)*
So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length
including Null)
Complement of L is all the strings that is not in L.
So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length
excluding Null)
RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.
Property 4. The difference of two regular set is regular.
Proof −
Let us take two regular expressions −
RE1 = a (a*) and RE2 = (aa)*
So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible
lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length
including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
(Strings of all odd lengths excluding Null)
RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.
Property 5. The reversal of a regular set is regular.
Proof −
We have to prove LR is also regular if L is a regular
set.
Let, L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10
LR = {10, 01, 11, 01}
RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.
Property 6. The closure of a regular set is regular.
Proof −
If L = {a, aaa, aaaaa, .......} (Strings of odd length
excluding Null)
i.e., RE (L) = a (aa)*
L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of
all lengths excluding Null)
RE (L*) = a (a)*
Hence, proved.
Property 7. The concatenation of two regular sets is
regular.
Proof −
Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings
ending in 0)
and L2 = {01, 010,011,.....} (Set of strings beginning
with 01)
Then, L1 L2 =
{001,0010,0011,0001,00010,00011,1001,10010,..........
...}
Set of strings containing 001 as a substring which can
be represented by an RE − (0 + 1)*001(0 + 1)*
Hence, proved.
Decision Properties of Regular Languages
● Membership
L={ends with 00|{0,1}}
w={1100,00,100,0100,00100….}
● Emptiness
● Equivalence
Equivalence and Minimisation of Automata
● Refer unit 1 ppt.
● Slides 42-50

Más contenido relacionado

La actualidad más candente

Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2shah zeb
 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
Theory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsTheory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsRushabh2428
 
Number theory and cryptography
Number theory and cryptographyNumber theory and cryptography
Number theory and cryptographyYasser Ali
 
Automata theory -- NFA and DFA construction
Automata theory -- NFA and DFA  constructionAutomata theory -- NFA and DFA  construction
Automata theory -- NFA and DFA constructionAkila Krishnamoorthy
 
Undecidability.pptx
Undecidability.pptxUndecidability.pptx
Undecidability.pptxPEzhumalai
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automatadeepinderbedi
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 

La actualidad más candente (20)

Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Turing machines
Turing machinesTuring machines
Turing machines
 
Theory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsTheory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and Problems
 
NLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit DistanceNLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit Distance
 
TOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal FormTOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal Form
 
Number theory and cryptography
Number theory and cryptographyNumber theory and cryptography
Number theory and cryptography
 
Automata theory -- NFA and DFA construction
Automata theory -- NFA and DFA  constructionAutomata theory -- NFA and DFA  construction
Automata theory -- NFA and DFA construction
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Undecidability.pptx
Undecidability.pptxUndecidability.pptx
Undecidability.pptx
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 

Similar a Formal Languages and Automata Theory unit 2

Similar a Formal Languages and Automata Theory unit 2 (20)

Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
FLAT.pdf
FLAT.pdfFLAT.pdf
FLAT.pdf
 
regular expression
regular expressionregular expression
regular expression
 
Unit ii
Unit iiUnit ii
Unit ii
 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
 
Regular expression
Regular expressionRegular expression
Regular expression
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdf
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Automata
AutomataAutomata
Automata
 
Automata
AutomataAutomata
Automata
 
unit 2 part b.docx
unit 2 part b.docxunit 2 part b.docx
unit 2 part b.docx
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
theoryofautomataandformallanguagesunit21-161231042659.pptx
theoryofautomataandformallanguagesunit21-161231042659.pptxtheoryofautomataandformallanguagesunit21-161231042659.pptx
theoryofautomataandformallanguagesunit21-161231042659.pptx
 

Más de Srimatre K

ML_ Unit 2_Part_B
ML_ Unit 2_Part_BML_ Unit 2_Part_B
ML_ Unit 2_Part_BSrimatre K
 
ML_Unit_2_Part_A
ML_Unit_2_Part_AML_Unit_2_Part_A
ML_Unit_2_Part_ASrimatre K
 
ML_Unit_1_Part_C
ML_Unit_1_Part_CML_Unit_1_Part_C
ML_Unit_1_Part_CSrimatre K
 
ML_Unit_1_Part_B
ML_Unit_1_Part_BML_Unit_1_Part_B
ML_Unit_1_Part_BSrimatre K
 
Internet of things unit-1
Internet of things unit-1Internet of things unit-1
Internet of things unit-1Srimatre K
 
ML_ Unit_1_PART_A
ML_ Unit_1_PART_AML_ Unit_1_PART_A
ML_ Unit_1_PART_ASrimatre K
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Srimatre K
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 

Más de Srimatre K (8)

ML_ Unit 2_Part_B
ML_ Unit 2_Part_BML_ Unit 2_Part_B
ML_ Unit 2_Part_B
 
ML_Unit_2_Part_A
ML_Unit_2_Part_AML_Unit_2_Part_A
ML_Unit_2_Part_A
 
ML_Unit_1_Part_C
ML_Unit_1_Part_CML_Unit_1_Part_C
ML_Unit_1_Part_C
 
ML_Unit_1_Part_B
ML_Unit_1_Part_BML_Unit_1_Part_B
ML_Unit_1_Part_B
 
Internet of things unit-1
Internet of things unit-1Internet of things unit-1
Internet of things unit-1
 
ML_ Unit_1_PART_A
ML_ Unit_1_PART_AML_ Unit_1_PART_A
ML_ Unit_1_PART_A
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Formal Languages and Automata Theory unit 2

  • 1. UNIT-2 REGULAR EXPRESSION K LAKSHMI SRVANI ASST PROFESSOR
  • 2. SYLLABUS Regular Expressions: Finite Automata and Regular Expressions, Applications of Regular Expressions, Algebraic Laws for Regular Expressions, Conversion of Finite Automata to Regular Expressions. Pumping Lemma for Regular Languages, Statement of the pumping lemma, Applications of the Pumping Lemma. Closure Properties of Regular Languages: Closure properties of Regular languages, Decision Properties of Regular Languages, Equivalence and Minimization of Automata.
  • 3. Regular Expressions. ● Regular expressions are used for representing certain sets of strings in algebraic fashion. ● Any terminal symbol belongs to Σ including ɸ,ɛ are RE ● The union of 2 RE is also RE ● The Concatenation of 2 RE is also RE ● The iteration or closure of RE is also RE
  • 4. Regular Expressions Regular Set (0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … } (0*10*) L = {1, 01, 10, 010, 0010, …} (0 + ε)(1 + ε) L = {ε, 0, 1, 01} (a+b)* Set of strings of a’s and b’s of any length including the null string. So L = { ε, a, b, aa , ab , bb , ba, aaa…….} (11)* Set consisting of even number of 1’s including empty string, So L= {ε, 11, 1111, 111111, ……….} (0+1)*011(0+1)* Sub string 011
  • 5. Operators of RE Operators used in regular expressions include: • Union: If R1 and R2 are regular expressions, then R1 | R2 (also written as R1 U R2 or R1 + R2) is also a regular expression. L(R1|R2) = L(R1) U L(R2) or L(R1+R2)
 
 • Concatenation: If R1 and R2 are regular expressions, then R1R2 (also written as R1.R2) is also a regular expression. L(R1R2) = L(R1) concatenated with L(R2).
 
 • Kleene closure: If R1 is a regular expression, then R1* (the Kleene closure of R1) is also a regular expression. L(R1*) = epsilon U L(R1) U L(R1R1) U L(R1R1R1) U ...

  • 6. Precedence ● Closure > Concatenation > Union ● (01*+1)
  • 7. Applications of RE ● RE in unix • [ :digit:][0-9] • [:alpha:]a-z A-Z • [:Alnum:] [A-Z a-z 0-9] ● Lexical Analysis ● Finding Patterns in Text ● Grep utility in unix.
  • 8. Algebraic Laws of RE ● COMMUTATIVITY ● ASSOCIATIVITY ● IDENTITIES ● ANNIHILATOR ● DISTRIBUTIVE ● IDEMPOTENT
  • 9. COMMUTATIVITY ● For regular expressions, we have: ● L + M = M + L ● Commutative law for union: we may make the union of two languages in either order ● Clearly the law L.M = M.L is FALSE (Commutative law for concatenation)
  • 10. ASSOCIATIVITY ● (L + M) + N = L + ( M + N) Associative law for union: we may take the union of three languages either by taking the union of the first two initially, or taking the union of the last two initially. Together with the commutative law we can take the union of any collection of languages with any order and grouping, and the result will be the same. Intuitively, a string is in L1 ∪ L2 . . . ∪ Lk iff it is in one or more of the Li s. ● (L.M).N = L.(M.N) Associative law for concatenation: we can concatenate three-languages by concatenating either the first two or the last two initially
  • 11. IDENTITIES ● An identity for an operator is a value that when the operator is applied to the identity and some other value, the result is the other value. ● ∅ + L = L + ∅ = L ● e.L = L.e = L
  • 12. ANNIHILATOR ● An annihilator for an operator is value that when the operator is applied to the annihilator and some other value, the result is the annihilator. ● ∅.L = L. ∅ = ∅
  • 13. DISTRIBUTIVE ● For regular expressions we have: ● Left distributivity: L.(M + N) = LM + LN ● Right distributivity: (M + N).L = ML + NL
  • 14. IDEMPOTENT ● An operator is idempotent if the result of applying it to two of ● the same values as arguments is that value. ● Idempotent Law for union: ● L + L = L ● If we take the union of two identical expressions, we can replace them by one copy of the expression.
  • 15. Identities Related to Regular Expressions l={0,1}{l2} Given R, P, L, Q as regular expressions, the following identities hold − • ∅* = ε • ε* = ε • RR* = R*R=R+ • R*R* = R* • (R*)* = R* • (PQ)*P =P(QP)* • (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)* • R + ∅ = ∅ + R = R (The identity for union) • R ε = ε R = R (The identity for concatenation) • ∅ L = L ∅ = ∅ (The annihilator for concatenation) • R + R = R (Idempotent law) • L (M + N) = LM + LN (Left distributive law) • (M + N) L = ML + NL (Right distributive law) • ε + RR* = ε + R*R = R*
  • 16. Arden’s Theorem In order to find out a regular expression of a Finite Automaton, we use Arden’s Theorem along with the properties of regular expressions. Statement − Let P and Q be two regular expressions. If P does not contain null string, then R = Q + RP has a unique solution that is R = QP* Proof − R = Q + (Q + RP)P [After putting the value R = Q + RP] = Q + QP + RPP When we put the value of R recursively again and again, we get the following equation − R = Q + QP + QP2 + QP3….. R = Q (ε + P + P2 + P3 + …. ) R = QP* [As P* represents (ε + P + P2 + P3 + ….) ] Hence, proved.
  • 18. From DFA to RE ● Arden’s Theorem Steps: ● 1) Build RE for each state ● 2) Solve final states equations first ● State Elimination Method Steps ● 1) The start state of DFA must not have any incoming edges. If there exists any incoming edge to start state ,then create a new state having no income edges. ● 2)There must be only one final state in DFA, If DFA contain more final states, then create a new final state and all other final states to non final states ● 3) The final state of DFA doesn’t contain any out going edges, then create new final state without any out going edges ● 4) Now start elimination intermediate states in any order. Finally we have initial state going to final state.
  • 22. Limitation of FA ● It have finite number of states. ● Finite amount of memory so doesn’t remember previous state outcome. ● So in above scenarios we use pumping lemma.
  • 23. Pumping Lemma Theorem Let L be a regular language. Then there exists a constant ‘n’ such that for every string w in L − |w| ≥ n We can break w into three strings, w = xyz, such that − • |y| = ε • |xy| ≤ n • For all k ≥ 0, the string xykz is also in L. Applications of Pumping Lemma Pumping Lemma is to be applied to show that certain languages are not regular. It should never be used to show a language is regular. • If L is regular, it satisfies Pumping Lemma.
 • If L does not satisfy Pumping Lemma, it is non-regular.

  • 25. Properties of Regular Sets/ Closure Properties Property 1. The union of two regular set is regular. Proof − Let us take two regular expressions RE1 = a(aa)* and RE2 = (aa)* So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null) and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null) L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......} (Strings of all possible lengths including Null) RE (L1 ∪ L2) = a* (which is a regular expression itself) Hence, proved.
  • 26. Property 2. The intersection of two regular set is regular. Proof − Let us take two regular expressions RE1 = a(a*) and RE2 = (aa)* So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null) L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null) L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null) RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself. Hence, proved.
  • 27. Property 3. The complement of a regular set is regular. Proof − Let us take a regular expression − RE = (aa)* So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length including Null) Complement of L is all the strings that is not in L. So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding Null) RE (L’) = a(aa)* which is a regular expression itself. Hence, proved.
  • 28. Property 4. The difference of two regular set is regular. Proof − Let us take two regular expressions − RE1 = a (a*) and RE2 = (aa)* So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null) L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null) L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....} (Strings of all odd lengths excluding Null) RE (L1 – L2) = a (aa)* which is a regular expression. Hence, proved.
  • 29. Property 5. The reversal of a regular set is regular. Proof − We have to prove LR is also regular if L is a regular set. Let, L = {01, 10, 11, 10} RE (L) = 01 + 10 + 11 + 10 LR = {10, 01, 11, 01} RE (LR) = 01 + 10 + 11 + 10 which is regular Hence, proved.
  • 30. Property 6. The closure of a regular set is regular. Proof − If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null) i.e., RE (L) = a (aa)* L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths excluding Null) RE (L*) = a (a)* Hence, proved.
  • 31. Property 7. The concatenation of two regular sets is regular. Proof − Let RE1 = (0+1)*0 and RE2 = 01(0+1)* Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0) and L2 = {01, 010,011,.....} (Set of strings beginning with 01) Then, L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,.......... ...} Set of strings containing 001 as a substring which can be represented by an RE − (0 + 1)*001(0 + 1)* Hence, proved.
  • 32. Decision Properties of Regular Languages ● Membership L={ends with 00|{0,1}} w={1100,00,100,0100,00100….} ● Emptiness ● Equivalence
  • 33. Equivalence and Minimisation of Automata ● Refer unit 1 ppt. ● Slides 42-50