SlideShare a Scribd company logo
1 of 37
Lecture # 3
Automata Theory and formal languages
(CSC-307)
Muhammad Shahzeb
Defining Languages Continued…
 Recursive definition of languages:
 The following three steps are used in recursive
definition
1. Some basic words are specified in the language.
2. Rules for constructing more words are defined
in the language.
3. No strings except those constructed in above,
are allowed to be in the language.
Example
Defining language of INTEGER
Step 1: 1 is in INTEGER.
Step 2: If x is in INTEGER then x+1 and x-1
are also in INTEGER.
Step 3: No strings except those constructed in
above, are allowed to be in INTEGER.
Example
Defining language of EVEN
Step 1: 2 is in EVEN.
Step 2: If x is in EVEN then x+2 and x-2 are
also in EVEN.
Step 3: No strings except those constructed in
above, are allowed to be in EVEN.
Example
Defining the language factorial
Step 1: As 0!=1, so 1 is in factorial.
Step 2: n!=n*(n-1)! is in factorial.
Step 3: No strings except those constructed in
above, are allowed to be in factorial.
Defining the language PALINDROME, defined over Σ
= {a,b}
Step 1: a and b are in PALINDROME
Step 2: if x is palindrome, then s(x)Rev(s) and
xx will also be palindrome, where s belongs to Σ*
Step 3: No strings except those constructed in
above, are allowed to be in palindrome
Defining the language {an
bn
}, n=1,2,3,… , of strings
defined over Σ={a,b}
Step 1: ab is in {an
bn
}
Step 2: if x is in {an
bn
}, then axb is in {an
bn
}
Step 3: No strings except those
constructed in above, are allowed to be in {an
bn
}
Defining the language L, of strings ending in a ,
defined over Σ={a,b}
Step 1: a is in L
Step 2: if x is in L then s(x) is also in L, where s
belongs to Σ*
Step 3: No strings except those constructed in
above, are allowed to be in L
Defining the language L, of strings beginning and
ending in same letters , defined over Σ={a, b}
Step 1: a and b are in L
Step 2: (a)s(a) and (b)s(b) are also in L, where
s belongs to Σ*
Step 3: No strings except those constructed in
above, are allowed to be in L
Defining the language L, of strings containing aa or
bb , defined over Σ={a, b}
Step 1: aa and bb are in L
Step 2: s(aa)s and s(bb)s are also in L, where s
belongs to Σ*
Step 3: No strings except those constructed in
above, are allowed to be in L
Defining the language L, of strings containing exactly
aa, defined over Σ={a, b}
Step 1: aa is in L
Step 2: s(aa)s is also in L, where s belongs to
b*
Step 3: No strings except those constructed in
above, are allowed to be in L
Q2) Prove that for any set of strings S
(S+
)*=(S*)*
Solution: In general Λ is not in S+ , while Λ does
belong to S*. Obviously Λ will now be in (S+
)*,
while (S*)* and S* generate the same set of
strings. Hence (S+
)*=(S*)*.
ii) (S+
)+
=S+
Solution: since S+ generates all possible strings
that can be obtained by concatenating the strings
of S, so (S+)+ generates all possible strings that
can be obtained by concatenating the strings of
S+ , will not generate any new string. Hence (S+)
+=S+
Is (S*)+
=(S+
)*
Solution: since Λ belongs to S* ,so Λ will belong
to (S*)+
as member of S* .Moreover Λ may not
belong to S+
, in general, while Λ will automatically
belong to (S+
)*. Hence
(S*)+
=(S+
)*
Lecture # 4
Automata Theory and formal languages
(CSC-307)
Date: 26 August 2015
Regular Expression
Regular Expression
As discussed earlier that
a* generates Λ, a, aa, aaa, … and
a+
generates a, aa, aaa, aaaa, …, so the language
L1 = {Λ, a, aa, aaa, …} and
L2 = {a, aa, aaa, aaaa, …}
can simply be expressed by a* and a+
, respectively.
a* and a+
are called the regular expressions (RE) for
L1 and L2 respectively.
Note: a+
, aa* and a*a also generate L2.
Recursive definition of Regular Expression(RE)
 Step 1: Every letter of Σ including Λ is a regular expression
 Step 2: If r1 and r2 are regular expressions then
 (r1)
 r1r2
 r1 + r2 and
 r1*
are also regular expressions.
 Step 3: Nothing else is a regular expression
Method 3 (Regular Expressions)
Consider the language L={Λ, a, aa, aaa,…} of
strings, defined over Σ = {a}. We can write this
language as the Kleene star closure of alphabet Σ
or L=Σ*={a}* this language can also be expressed
by the regular expression a*.
Similarly the language L={a, aa, aaa,…}, defined
over Σ = {a}, can be expressed by the regular
expression a+
.
Example
Now consider another language L, consisting of all
possible strings, defined over Σ = {a, b}. This
language can also be expressed by the regular
expression (a + b)*
Example
Now consider another language L, consisting of all
possible strings, defined over Σ = {a, b}. This
language can also be expressed by the regular
expression (a + b)*
Now consider another language L, of strings
having exactly double a, having any number of b’s
defined over Σ = {a, b}, then it’s regular
expression may be
b*aab*
Example
Now consider another language L, of even length,
defined over Σ = {a, b}, then it’s regular
expression may be
((a+b)(a+b))*
Now consider another language L, of odd length,
defined over Σ = {a, b}, then it’s regular
expression may be
(a+b)((a+b)(a+b))* or
((a+b)(a+b))*(a+b)
Remark
It may be noted that a language may be
expressed by more than one regular expressions,
while given a regular expression there exist a
unique language generated by that regular
expression.
Example
Consider the language, defined over Σ={a, b} of
words having at least one a, may be expressed by
a regular expression
(a+b)*a(a+b)*
Consider the language, defined over Σ = {a, b} of
words having at least one a and one b, may be
expressed by a regular expression
(a+b)*a(a+b)*b(a+b)* + (a+b)*b(a+b)*a(a+b)*
Example
Consider the language, defined over Σ={a, b}, of
words starting with double a and ending in
double b then its regular expression may be
aa(a+b)*bb
Consider the language, defined over Σ={a, b} of
words starting with a and ending in b OR
starting with b and ending in a, then its regular
expression may be
a(a+b)*b+b(a+b)*a
Practice – Regular Expression ?
Consider the language, defined over Σ={a, b} of
words beginning with a
Consider the language, defined over Σ={a, b} of
words beginning and ending in same letter
Practice – Regular Expression ?
Consider the language, defined over Σ={a, b} of
words ending in b
Consider the language, defined over Σ={a, b} of
words not ending in a
An important Example
The Language EVEN-EVEN :
Language of strings, defined over Σ={a, b} having
even number of a’s and even number of b’s.
i.e.
EVEN-EVEN = {Λ, aa, bb, aaaa,aabb,abab, abba,
baab, baba, bbaa, bbbb,…},
Its regular expression can be written as
( aa + bb + (ab+ba)(aa+bb)*(ab+ba) )*
Note
It is important to be clear about the difference of
the following regular expressions
r1=a*+b*
r2=(a+b)*
Here r1 does not generate any string of
concatenation of a and b, while r2 generates such
strings.
Equivalent Regular Expressions
Definition: Two regular expressions are said to
be equivalent if they generate the same language.
Example: Consider the following regular
expressions
r1= (a + b)* (aa + bb)
r2= (a + b)*aa + ( a + b)*bb then
both regular expressions define the language of
strings ending in aa or bb.
Note
 If r1 =(aa + bb) and r2 =( a + b) then
1. r1 + r2 =(aa + bb) + (a + b)
2. r1 r2 = (aa + bb) (a + b) = (aaa + aab + bba + bbb)
3. (r1)* =(aa + bb)*
Regular Languages
Definition:
The language generated by any regular
expression is called a regular language.
It is to be noted that if r1, r2 are regular
expressions, corresponding to the languages L1
and L2then the languages generated by r1 + r2 , r1r2
( or r2r1) and r1*( or r2*) are also regular
languages.
Note
 It is to be noted that if L1 and L2 are expressed by
r1 and r2, respectively then the language expressed
by
1. r1+ r2, is the language L1+ L2 or L1U L2
2. r1 r2, , is the language L1L2, of strings obtained by
prefixing every string of L1 with every string of L2
3. r1*, is the language L1*, of strings obtained by
concatenating the strings of L, including the null
string.
Example
If r1=(aa+bb) and r2=(a+b) then the language of
strings generated by r1+ r2, is also a regular
language, expressed by (aa+bb)+(a+b)
If r1=(aa+bb) and r2=(a+b) then the language of
strings generated by r1r2, is also a regular
language, expressed by (aa+bb)(a+b)
If r=(aa+bb) then the language of strings
generated by r*, is also a regular language,
expressed by (aa+bb)*
All finite languages are regular
Example:
Consider the language L, defined over Σ={a,b}, of
strings of length 2, starting with a, then
L={aa, ab}, may be expressed by the regular
expression aa+ab.
Hence L, by definition, is a regular language.
Note
It may be noted that if a language contains even
thousand words, its RE may be expressed, placing
‘ + ’ between all the words.
Here the special structure of RE is not important.
Consider the language L={aaa, aab, aba, abb, baa,
bab, bba, bbb}, that may be expressed by a RE
aaa+aab+aba+abb+baa+bab+bba+bbb, which is
equivalent to (a+b)(a+b)(a+b).
Thank You…

More Related Content

What's hot

Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02hamzamughal39
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsAshu
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsShiraz316
 
Context free grammars
Context free grammarsContext free grammars
Context free grammarsRonak Thakkar
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automatahafizhamza0322
 
Regular Expression Examples.pptx
Regular Expression Examples.pptxRegular Expression Examples.pptx
Regular Expression Examples.pptxGhulamRabani9
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFAMaulik Togadiya
 

What's hot (20)

Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 2 Solutions
Introduction to Computer theory Daniel Cohen Chapter 2 Solutions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Pumping lemma Theory Of Automata
Pumping lemma Theory Of AutomataPumping lemma Theory Of Automata
Pumping lemma Theory Of Automata
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
Regular Expression Examples.pptx
Regular Expression Examples.pptxRegular Expression Examples.pptx
Regular Expression Examples.pptx
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Lesson 05
Lesson 05Lesson 05
Lesson 05
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
 

Similar to Lecture 3,4

Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture mariajan8
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 028threspecter
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01 hamzamughal39
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptashja1
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxRaviAr5
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........NaumanAli215439
 
Final formal languages
Final formal languagesFinal formal languages
Final formal languagesMegha Khanna
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdfTariqSaeed80
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler designRiazul Islam
 
theory of computation notes. introduction and mcq points
theory of computation notes. introduction and mcq pointstheory of computation notes. introduction and mcq points
theory of computation notes. introduction and mcq pointsbushraphd2022
 

Similar to Lecture 3,4 (20)

Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 04
Lesson 04Lesson 04
Lesson 04
 
To lec 03
To lec 03To lec 03
To lec 03
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 02
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.ppt
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........
 
Final formal languages
Final formal languagesFinal formal languages
Final formal languages
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdf
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
 
Ch2 automata.pptx
Ch2 automata.pptxCh2 automata.pptx
Ch2 automata.pptx
 
theory of computation notes. introduction and mcq points
theory of computation notes. introduction and mcq pointstheory of computation notes. introduction and mcq points
theory of computation notes. introduction and mcq points
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Lecture 3,4

  • 1. Lecture # 3 Automata Theory and formal languages (CSC-307) Muhammad Shahzeb
  • 2. Defining Languages Continued…  Recursive definition of languages:  The following three steps are used in recursive definition 1. Some basic words are specified in the language. 2. Rules for constructing more words are defined in the language. 3. No strings except those constructed in above, are allowed to be in the language.
  • 3. Example Defining language of INTEGER Step 1: 1 is in INTEGER. Step 2: If x is in INTEGER then x+1 and x-1 are also in INTEGER. Step 3: No strings except those constructed in above, are allowed to be in INTEGER.
  • 4. Example Defining language of EVEN Step 1: 2 is in EVEN. Step 2: If x is in EVEN then x+2 and x-2 are also in EVEN. Step 3: No strings except those constructed in above, are allowed to be in EVEN.
  • 5. Example Defining the language factorial Step 1: As 0!=1, so 1 is in factorial. Step 2: n!=n*(n-1)! is in factorial. Step 3: No strings except those constructed in above, are allowed to be in factorial.
  • 6. Defining the language PALINDROME, defined over Σ = {a,b} Step 1: a and b are in PALINDROME Step 2: if x is palindrome, then s(x)Rev(s) and xx will also be palindrome, where s belongs to Σ* Step 3: No strings except those constructed in above, are allowed to be in palindrome
  • 7. Defining the language {an bn }, n=1,2,3,… , of strings defined over Σ={a,b} Step 1: ab is in {an bn } Step 2: if x is in {an bn }, then axb is in {an bn } Step 3: No strings except those constructed in above, are allowed to be in {an bn }
  • 8. Defining the language L, of strings ending in a , defined over Σ={a,b} Step 1: a is in L Step 2: if x is in L then s(x) is also in L, where s belongs to Σ* Step 3: No strings except those constructed in above, are allowed to be in L
  • 9. Defining the language L, of strings beginning and ending in same letters , defined over Σ={a, b} Step 1: a and b are in L Step 2: (a)s(a) and (b)s(b) are also in L, where s belongs to Σ* Step 3: No strings except those constructed in above, are allowed to be in L
  • 10. Defining the language L, of strings containing aa or bb , defined over Σ={a, b} Step 1: aa and bb are in L Step 2: s(aa)s and s(bb)s are also in L, where s belongs to Σ* Step 3: No strings except those constructed in above, are allowed to be in L
  • 11. Defining the language L, of strings containing exactly aa, defined over Σ={a, b} Step 1: aa is in L Step 2: s(aa)s is also in L, where s belongs to b* Step 3: No strings except those constructed in above, are allowed to be in L
  • 12. Q2) Prove that for any set of strings S (S+ )*=(S*)* Solution: In general Λ is not in S+ , while Λ does belong to S*. Obviously Λ will now be in (S+ )*, while (S*)* and S* generate the same set of strings. Hence (S+ )*=(S*)*.
  • 13. ii) (S+ )+ =S+ Solution: since S+ generates all possible strings that can be obtained by concatenating the strings of S, so (S+)+ generates all possible strings that can be obtained by concatenating the strings of S+ , will not generate any new string. Hence (S+) +=S+
  • 14. Is (S*)+ =(S+ )* Solution: since Λ belongs to S* ,so Λ will belong to (S*)+ as member of S* .Moreover Λ may not belong to S+ , in general, while Λ will automatically belong to (S+ )*. Hence (S*)+ =(S+ )*
  • 15. Lecture # 4 Automata Theory and formal languages (CSC-307) Date: 26 August 2015
  • 17. Regular Expression As discussed earlier that a* generates Λ, a, aa, aaa, … and a+ generates a, aa, aaa, aaaa, …, so the language L1 = {Λ, a, aa, aaa, …} and L2 = {a, aa, aaa, aaaa, …} can simply be expressed by a* and a+ , respectively. a* and a+ are called the regular expressions (RE) for L1 and L2 respectively. Note: a+ , aa* and a*a also generate L2.
  • 18. Recursive definition of Regular Expression(RE)  Step 1: Every letter of Σ including Λ is a regular expression  Step 2: If r1 and r2 are regular expressions then  (r1)  r1r2  r1 + r2 and  r1* are also regular expressions.  Step 3: Nothing else is a regular expression
  • 19. Method 3 (Regular Expressions) Consider the language L={Λ, a, aa, aaa,…} of strings, defined over Σ = {a}. We can write this language as the Kleene star closure of alphabet Σ or L=Σ*={a}* this language can also be expressed by the regular expression a*. Similarly the language L={a, aa, aaa,…}, defined over Σ = {a}, can be expressed by the regular expression a+ .
  • 20. Example Now consider another language L, consisting of all possible strings, defined over Σ = {a, b}. This language can also be expressed by the regular expression (a + b)*
  • 21. Example Now consider another language L, consisting of all possible strings, defined over Σ = {a, b}. This language can also be expressed by the regular expression (a + b)* Now consider another language L, of strings having exactly double a, having any number of b’s defined over Σ = {a, b}, then it’s regular expression may be b*aab*
  • 22. Example Now consider another language L, of even length, defined over Σ = {a, b}, then it’s regular expression may be ((a+b)(a+b))* Now consider another language L, of odd length, defined over Σ = {a, b}, then it’s regular expression may be (a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b)
  • 23. Remark It may be noted that a language may be expressed by more than one regular expressions, while given a regular expression there exist a unique language generated by that regular expression.
  • 24. Example Consider the language, defined over Σ={a, b} of words having at least one a, may be expressed by a regular expression (a+b)*a(a+b)* Consider the language, defined over Σ = {a, b} of words having at least one a and one b, may be expressed by a regular expression (a+b)*a(a+b)*b(a+b)* + (a+b)*b(a+b)*a(a+b)*
  • 25. Example Consider the language, defined over Σ={a, b}, of words starting with double a and ending in double b then its regular expression may be aa(a+b)*bb Consider the language, defined over Σ={a, b} of words starting with a and ending in b OR starting with b and ending in a, then its regular expression may be a(a+b)*b+b(a+b)*a
  • 26. Practice – Regular Expression ? Consider the language, defined over Σ={a, b} of words beginning with a Consider the language, defined over Σ={a, b} of words beginning and ending in same letter
  • 27. Practice – Regular Expression ? Consider the language, defined over Σ={a, b} of words ending in b Consider the language, defined over Σ={a, b} of words not ending in a
  • 28. An important Example The Language EVEN-EVEN : Language of strings, defined over Σ={a, b} having even number of a’s and even number of b’s. i.e. EVEN-EVEN = {Λ, aa, bb, aaaa,aabb,abab, abba, baab, baba, bbaa, bbbb,…}, Its regular expression can be written as ( aa + bb + (ab+ba)(aa+bb)*(ab+ba) )*
  • 29. Note It is important to be clear about the difference of the following regular expressions r1=a*+b* r2=(a+b)* Here r1 does not generate any string of concatenation of a and b, while r2 generates such strings.
  • 30. Equivalent Regular Expressions Definition: Two regular expressions are said to be equivalent if they generate the same language. Example: Consider the following regular expressions r1= (a + b)* (aa + bb) r2= (a + b)*aa + ( a + b)*bb then both regular expressions define the language of strings ending in aa or bb.
  • 31. Note  If r1 =(aa + bb) and r2 =( a + b) then 1. r1 + r2 =(aa + bb) + (a + b) 2. r1 r2 = (aa + bb) (a + b) = (aaa + aab + bba + bbb) 3. (r1)* =(aa + bb)*
  • 32. Regular Languages Definition: The language generated by any regular expression is called a regular language. It is to be noted that if r1, r2 are regular expressions, corresponding to the languages L1 and L2then the languages generated by r1 + r2 , r1r2 ( or r2r1) and r1*( or r2*) are also regular languages.
  • 33. Note  It is to be noted that if L1 and L2 are expressed by r1 and r2, respectively then the language expressed by 1. r1+ r2, is the language L1+ L2 or L1U L2 2. r1 r2, , is the language L1L2, of strings obtained by prefixing every string of L1 with every string of L2 3. r1*, is the language L1*, of strings obtained by concatenating the strings of L, including the null string.
  • 34. Example If r1=(aa+bb) and r2=(a+b) then the language of strings generated by r1+ r2, is also a regular language, expressed by (aa+bb)+(a+b) If r1=(aa+bb) and r2=(a+b) then the language of strings generated by r1r2, is also a regular language, expressed by (aa+bb)(a+b) If r=(aa+bb) then the language of strings generated by r*, is also a regular language, expressed by (aa+bb)*
  • 35. All finite languages are regular Example: Consider the language L, defined over Σ={a,b}, of strings of length 2, starting with a, then L={aa, ab}, may be expressed by the regular expression aa+ab. Hence L, by definition, is a regular language.
  • 36. Note It may be noted that if a language contains even thousand words, its RE may be expressed, placing ‘ + ’ between all the words. Here the special structure of RE is not important. Consider the language L={aaa, aab, aba, abb, baa, bab, bba, bbb}, that may be expressed by a RE aaa+aab+aba+abb+baa+bab+bba+bbb, which is equivalent to (a+b)(a+b)(a+b).