38
Lecture # 1 Lecture # 1 (Automata Theory) (Automata Theory)

Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Embed Size (px)

Citation preview

Page 1: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Lecture # 1Lecture # 1

(Automata Theory)(Automata Theory)

Page 2: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Material / ResourcesMaterial / Resources

Text BooksText Books1.1. Introduction to Computer TheoryIntroduction to Computer Theory, by , by

Daniel I. Cohen, John Wiley and Sons, Inc., Daniel I. Cohen, John Wiley and Sons, Inc., 2005, Second Edition 2005, Second Edition

2.2. Introduction to Languages and Theory of Introduction to Languages and Theory of ComputationComputation, by J. C. Martin, McGraw Hill , by J. C. Martin, McGraw Hill Book Co., 2003, Third Edition.Book Co., 2003, Third Edition.

wwwwww Any other good book on Automata TheoryAny other good book on Automata Theory

Page 3: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

GradingGrading

Assignments ……………..…..…………… 10%Assignments ……………..…..…………… 10% Quizzes ………..…………..…..…………… 10%Quizzes ………..…………..…..…………… 10% Mid Term….…………………………………. 20%Mid Term….…………………………………. 20% Presentation…………………………………. 10%Presentation…………………………………. 10% Final Exam..…………………………………. 50%Final Exam..…………………………………. 50%

Page 4: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Theory of AutomataTheory of Automata

Page 5: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

What does Automata mean? What does Automata mean?

It is the plural of It is the plural of automatonautomaton, and it , and it means “means “something that works something that works automaticallyautomatically”.”.

Automata theory is the study of Automata theory is the study of abstract computational devices and the abstract computational devices and the computational problems that can be computational problems that can be solved using them.solved using them.

Abstract devices are (simplified) models Abstract devices are (simplified) models of real computations.of real computations.

Page 6: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

1- Automata and formal language.1- Automata and formal language. Which answers - What are computers (Or Which answers - What are computers (Or

what are models of computers)what are models of computers) 2- Compatibility.2- Compatibility. Which answers - What can be computed Which answers - What can be computed

by computers?by computers? 3- Complexity.3- Complexity. Which answers - What can be efficiently Which answers - What can be efficiently

computed?computed?

In automata we will simulates parts of In automata we will simulates parts of computers.computers.

Page 7: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Helps in design and construction of Helps in design and construction of different software's and what we can different software's and what we can expect from our software's.expect from our software's.

Automata play a major role in theory Automata play a major role in theory of computation, compiler design, of computation, compiler design, artificial intelligence.artificial intelligence.

Page 8: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

A simple computerA simple computer

BATTERY

SWITCH

input: switch

output: light bulb

actions: flip switch

states: on, off

Page 9: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

A simple “computer”A simple “computer”

BATTERY

SWITCH

off onstart

f

f

input: switch

output: light bulb

actions: f for “flip switch”

states: on, off

bulb is on if and only if there was an odd number of flips

Page 10: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Another “computer”Another “computer”

BATTERY

off offstart

1

inputs: switches 1 and 2

actions: 1 for “flip switch 1”actions: 2 for “flip switch 2”

states: on, off

bulb is on if and only if both switches were flipped an odd number of times

1

2

1

off on

1

1

2 2 2 2

Page 11: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Introduction to languages Introduction to languages

Kinds of languages:Kinds of languages:

Talking languageTalking language Programming languageProgramming language Formal Languages (Syntactic languages) Formal Languages (Syntactic languages)

Page 12: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Alphabets Alphabets Definition:Definition: A finite non-empty set of symbols (letters), A finite non-empty set of symbols (letters),

is called an alphabet. It is denoted by is called an alphabet. It is denoted by ΣΣ ( Greek letter sigma).( Greek letter sigma).

Example: Example: ΣΣ={a,b} ={a,b}

ΣΣ={0,1} // important as this is the ={0,1} // important as this is the language language //which the computer //which the computer understands. understands. ΣΣ={i,j,k}={i,j,k}

A certain version of language ALGOL has A certain version of language ALGOL has 113 letters.113 letters.

Page 13: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Strings Strings

Definition: Definition:

Concatenation of finite symbols from Concatenation of finite symbols from the alphabet is called a string. the alphabet is called a string.

Example: Example:

If If ΣΣ= {a,b} then = {a,b} then a, abab, aaabb, a, abab, aaabb, ababababababababab ababababababababab

Page 14: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

LanguageLanguage

Language is the set of all strings of Language is the set of all strings of terminal symbols derivable from terminal symbols derivable from alphabet.alphabet.

Page 15: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

NOTE: NOTE: EMPTYEMPTY STRING or STRING or NULLNULL STRING STRING

Sometimes a string with no symbol at all is Sometimes a string with no symbol at all is used, denoted by (used, denoted by (Small Greek letter Small Greek letter LambdaLambda) ) λλ or ( or (Capital Greek letterCapital Greek letter LambdaLambda) ) ΛΛ, is called an empty string or null string., is called an empty string or null string.

The capital lambda will mostly be used to The capital lambda will mostly be used to denote the empty string, in further denote the empty string, in further discussion.discussion.

Page 16: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Words Words Definition: Definition:

Words are strings belonging to some Words are strings belonging to some language. language.

Example: Example:

If If ΣΣ= {a} then a language L can be defined = {a} then a language L can be defined as L={aas L={ann : n=1,2,3,…..} or L={a,aa,aaa, : n=1,2,3,…..} or L={a,aa,aaa,….} ….}

Here a,aa,… are the Here a,aa,… are the wordswords of L of L

Page 17: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

NOTE: NOTE:

All All words are stringswords are strings, but , but not all not all strings are wordsstrings are words

Page 18: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Valid/In-valid alphabets Valid/In-valid alphabets

While defining an alphabet, an While defining an alphabet, an alphabet may contain letters alphabet may contain letters consisting of group of symbols for consisting of group of symbols for example example ΣΣ11= {B, aB, bab, d}= {B, aB, bab, d}..

Now consider an alphabet Now consider an alphabet

ΣΣ22= {B, Ba, bab, d}= {B, Ba, bab, d} and a string and a string BababBBababB

Page 19: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Valid/In-valid alphabetsValid/In-valid alphabets

This BababB (string) can be tokenized in This BababB (string) can be tokenized in two different ways two different ways (Ba), (bab), (B) (Ba), (bab), (B) (B), (abab), (B)(B), (abab), (B)

Which shows that the second group Which shows that the second group cannot be identified as a string, defined cannot be identified as a string, defined over over

ΣΣ22= {B, Ba, bab, d}= {B, Ba, bab, d}

Page 20: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Valid/In-valid alphabetsValid/In-valid alphabets

As when this string is scanned by the As when this string is scanned by the compiler (Lexical Analyzer),compiler (Lexical Analyzer), first symbol B first symbol B is identified as a letter belonging to is identified as a letter belonging to ΣΣ, , while for the second letter the lexical while for the second letter the lexical analyzer would not be able to identify, so analyzer would not be able to identify, so while defining an alphabet it should be while defining an alphabet it should be kept in mind that ambiguity should not be kept in mind that ambiguity should not be created.created.

Page 21: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Remarks: Remarks:

While defining an While defining an alphabetalphabet of of lettersletters consisting of more than one consisting of more than one symbolssymbols, no , no letter should be started with the letter of letter should be started with the letter of the same alphabet the same alphabet i.e. i.e. one letter should one letter should not be the prefixnot be the prefix of another. However, a of another. However, a letter may be ended in the letter of same letter may be ended in the letter of same alphabet alphabet i.e.i.e. one letter may be the one letter may be the suffix suffix of anotherof another. .

Page 22: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Conclusion Conclusion

ΣΣ11= {B, aB, bab, d}= {B, aB, bab, d} ΣΣ22= {= {BB, , BBa, bab, d} a, bab, d}

ΣΣ11 is a valid alphabet while is a valid alphabet while ΣΣ22 is an is an in-valid alphabetin-valid alphabet. .

Page 23: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Length of Strings Length of Strings

Definition:Definition:The length of string s, denoted by |s|, is The length of string s, denoted by |s|, is the number of letters in the string.the number of letters in the string.

Example: Example: ΣΣ={a,b}={a,b}

s=ababa s=ababa |s|=5|s|=5

Page 24: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Example: Example:

ΣΣ= {B, aB, bab, d}= {B, aB, bab, d}

s=BaBbabBd s=BaBbabBd

TokenizingTokenizing=(B), (aB), (bab), (B), (d) =(B), (aB), (bab), (B), (d) |s|=5|s|=5

Page 25: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Reverse of a String Reverse of a String

Definition: Definition: The reverse of a string s denoted by The reverse of a string s denoted by Rev(s) or Rev(s) or ssrr, is obtained by writing , is obtained by writing the letters of s in reverse order. the letters of s in reverse order.

Example: Example: If s = If s = abcabc is a string defined over is a string defined overΣΣ={a,b,c} ={a,b,c} then then Rev(s) or Rev(s) or ssrr = = cbacba

Page 26: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Reverse of a StringReverse of a String

Example: Example:

ΣΣ= {B, aB, bab, d} = {B, aB, bab, d}

s=BaBbabBd s=BaBbabBd

TokenizingTokenizing=(B) (=(B) (aBaB) (bab) (B) (d) ) (bab) (B) (d)

Rev(s)=dBbabRev(s)=dBbabaBaBBB

Page 27: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Defining Languages Defining Languages The languages can be defined in different The languages can be defined in different

ways , such as ways , such as 1.1. Descriptive definition, Descriptive definition, 2.2. Recursive definition, Recursive definition, 3.3. using Regular Expressions(RE) and using Regular Expressions(RE) and 4.4. using Finite Automaton(FA) etc. using Finite Automaton(FA) etc.

Descriptive definition of languageDescriptive definition of language: : The language is defined, The language is defined, describing the describing the conditions imposedconditions imposed on its on its wordswords. .

Page 28: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample: :

The language L of strings of The language L of strings of oddodd length, length, defined over defined over ΣΣ={a}, can be written as ={a}, can be written as

L={a, aaa, aaaaa,…..} L={a, aaa, aaaaa,…..} ExampleExample: :

The language L of strings that does not The language L of strings that does not start with a, defined over start with a, defined over ΣΣ={a,b,c}, can ={a,b,c}, can be written asbe written as

L={b, c, ba, bb, bc, ca, cb, cc, …}L={b, c, ba, bb, bc, ca, cb, cc, …}

Page 29: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::The language L of strings of The language L of strings of length 2length 2, , defined over defined over ΣΣ={0,1,2}, can be written as ={0,1,2}, can be written as

L={00, 01, 02,10, 11,12,20,21,22}L={00, 01, 02,10, 11,12,20,21,22}

ExampleExample::The language L of strings The language L of strings ending in 0ending in 0, , defined over defined over ΣΣ ={0,1}, can be written as ={0,1}, can be written as

L={0,00,10,000,010,100,110,…} L={0,00,10,000,010,100,110,…}

Page 30: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample: : The language The language EQUALEQUAL, of strings with , of strings with number of a’s equal to number of b’s, number of a’s equal to number of b’s, defined over defined over ΣΣ={a,b}, can be written as ={a,b}, can be written as

{{ΛΛ ,ab,aabb,abab,baba,abba,…} ,ab,aabb,abab,baba,abba,…} ExampleExample::

The language The language EVEN-EVENEVEN-EVEN, of strings with , of strings with even number of a’s and even number of b’s, even number of a’s and even number of b’s, defined over defined over ΣΣ={a,b}, can be written as ={a,b}, can be written as {{ΛΛ, aa, bb, aaaa,aabb,abab, abba, baab, , aa, bb, aaaa,aabb,abab, abba, baab, baba, bbaa, bbbb,…}baba, bbaa, bbbb,…}

Page 31: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::

The language The language INTEGERINTEGER, of strings defined , of strings defined over over ΣΣ={-,0,1,2,3,4,5,6,7,8,9}, can be ={-,0,1,2,3,4,5,6,7,8,9}, can be written as written as

INTEGER = {…,-2,-1,0,1,2,…}INTEGER = {…,-2,-1,0,1,2,…}

ExampleExample::

The language The language EVENEVEN, of, of stings defined over stings defined over

ΣΣ={-,0,1,2,3,4,5,6,7,8,9}, can be written as ={-,0,1,2,3,4,5,6,7,8,9}, can be written as EVEN = { …,-4,-2,0,2,4,…} EVEN = { …,-4,-2,0,2,4,…}

Page 32: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::

The language {aThe language {annbbnn}, of strings defined }, of strings defined over over ΣΣ={a,b}, as ={a,b}, as {a{annbbnn : n=1,2,3,…}, : n=1,2,3,…}, can be written as can be written as

{ab, aabb, aaabbb,aaaabbbb,…}{ab, aabb, aaabbb,aaaabbbb,…} ExampleExample::

The language {aThe language {annbbnn a ann}, of strings defined }, of strings defined over over ΣΣ={a,b}, as ={a,b}, as {a{annbbnn a ann : n=1,2,3,…}, : n=1,2,3,…}, can be written as can be written as

{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,……

Page 33: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::

The language The language factorialfactorial, of strings defined , of strings defined over over ΣΣ={1,2,3,4,5,6,7,8,9} ={1,2,3,4,5,6,7,8,9} i.e. i.e. {1,2,6,24,120,…} {1,2,6,24,120,…}

ExampleExample::

The language The language FACTORIALFACTORIAL, of strings defined , of strings defined over over ΣΣ={a}, as {={a}, as {aan!n! : n=1,2,3,…}, can be : n=1,2,3,…}, can be written as written as {a,aa,aaaaaa,…}. {a,aa,aaaaaa,…}.

It is to be noted that the language FACTORIAL It is to be noted that the language FACTORIAL can be defined over any single letter alphabet. can be defined over any single letter alphabet.

Page 34: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::The language The language DOUBLEFACTORIALDOUBLEFACTORIAL, of , of strings defined over strings defined over ΣΣ={a, b}, as ={a, b}, as {{aan!n! b bn!n! : n=1,2,3,…}, can be written as : n=1,2,3,…}, can be written as

{ab, aabb, aaaaaabbbbbb,…} {ab, aabb, aaaaaabbbbbb,…}

ExampleExample::The language The language SQUARESQUARE, of strings defined , of strings defined over over ΣΣ={a}, as ={a}, as

{a{ann22 : n=1,2,3,…}, can be written as : n=1,2,3,…}, can be written as {a, aaaa, aaaaaaaaa,…} {a, aaaa, aaaaaaaaa,…}

Page 35: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample::

The language The language DOUBLESQUAREDOUBLESQUARE, of strings , of strings defined over defined over ΣΣ={a,b}, as ={a,b}, as

{{aann22 b bnn22 : n=1,2,3,…}, can be written as : n=1,2,3,…}, can be written as

{ab, aaaabbbb, aaaaaaaaabbbbbbbbb,…} {ab, aaaabbbb, aaaaaaaaabbbbbbbbb,…}

Page 36: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

ExampleExample: :

The language The language PRIMEPRIME, of strings defined , of strings defined over over ΣΣ={a}, as ={a}, as

{a{app : p is prime}, can be written as : p is prime}, can be written as {aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa…} {aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa…}

Page 37: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

An Important language An Important language

PALINDROMEPALINDROME The language consisting of The language consisting of ΛΛ and the and the strings s defined over strings s defined over ΣΣ such that such that Rev(s)=s. Rev(s)=s. It is to be denoted that the It is to be denoted that the words of PALINDROME are called words of PALINDROME are called palindromes. palindromes.

ExampleExample::For For ΣΣ={a,b}, ={a,b}, PALINDROME={PALINDROME={ΛΛ , a, b, aa, , a, b, aa, bb, aaa, aba, bab, bbb, ...}bb, aaa, aba, bab, bbb, ...}

Page 38: Lecture # 1 (Automata Theory). Material / Resources Text Books Text Books 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons,

Thank You…Thank You…