lesson 1uaf
TRANSCRIPT
-
8/9/2019 Lesson 1UAF
1/38
Welcome to ! Lecture # 1
Theory Of Automata
-
8/9/2019 Lesson 1UAF
2/38
Text and Reference Material
1. Introductionto Computer Theory, by DanielI. Cohen, John Wiley and Sons, Inc., 1991,Second Edition
2. Introduction to Languages and Theory ofComputation, by J. C. Martin, McGraw HillBook Co., 1997, Second Edition
-
8/9/2019 Lesson 1UAF
3/38
Grading
There will be One mid exam and one final
exam. The final exam will be comprehensive.These will contribute the followingpercentages to the final grade:
Mid-Term Exams. (12 Marks)
Assignments (04 Marks)
Final Exams. (24 Marks)
Practical Exam (20 Marks)
-
8/9/2019 Lesson 1UAF
4/38
What does automata mean?
It is the plural of automaton, and itmeanssomethingthatworks automatically
-
8/9/2019 Lesson 1UAF
5/38
Introduction to languages
There aretwotypes of languages
Formal Languages (Syntactic languages)
Informal Languages (Semantic
languages)
-
8/9/2019 Lesson 1UAF
6/38
Alphabets
Definition:
A finitenon-empty setofsymbols (letters), is
called an alphabet. Itis denoted by ( Greekletter sigma).
Example:
={a,b}
={0,1} //importantas this is the language//whichthecomputerunderstands.
={i,j,k}
-
8/9/2019 Lesson 1UAF
7/38
Strings
Definition:
Concatenationoffinite symbols fromthe
alphabetis called a string. Example:
If={a,b} then
a, abab, aaabb, ababababababababab
-
8/9/2019 Lesson 1UAF
8/38
NOTE:
EMPTYSTRING orNULL STRING
Sometimes a string withno symbol atall is
used, denoted by (Small Greek letterLambda) or (Capital Greek letterLambda) , is calledan empty stringornull string.
Thecap
ital lambda w
ill mostly beusedtodenotethe empty string, infurtherdiscussion.
-
8/9/2019 Lesson 1UAF
9/38
Words
Definition:
Words are strings belongingto some
language.Example:
If={x} then a languageLcan bedefined as
L={xn: n=1,2,3,..} orL={x,xx,xxx,.}
Here x,xx, arethe words ofL
-
8/9/2019 Lesson 1UAF
10/38
NOTE:
All words are strings, butnotall stringsare words.
-
8/9/2019 Lesson 1UAF
11/38
Valid/In-valid alphabets
Whiledefining an alphabet, an alphabetmaycontain letters consistingofgroupofsymbols
for example1={B, aB, bab, d}.
Now consider an alphabet2={B, Ba, bab, d} and a string BababB.
-
8/9/2019 Lesson 1UAF
12/38
This stringcan betokenizedintwodifferentways
(Ba), (bab), (B) (B), (abab), (B)
Which shows thatthe secondgroupcannot
beidentified as a string, definedover ={a, b}.
-
8/9/2019 Lesson 1UAF
13/38
As whenthis stringis scanned bythecompiler (Lexical Analyzer), firstsymbol B is
identified as a letter belongingto, whileforthe second letterthe lexical analyzer wouldnotbe abletoidentify, so whiledefining analphabetitshould be keptinmindthat
ambiguity shouldnotbecreated.
-
8/9/2019 Lesson 1UAF
14/38
Remarks:
Whiledefining an alphabetof lettersconsistingofmorethanone symbols, no
letter should be started withthe letterofthesame alphabeti.e. one letter shouldnotbetheprefix ofanother. However, a lettermaybe endedinthe letterofsame alphabeti.e.
one lettermay bethe suffix ofanother.
-
8/9/2019 Lesson 1UAF
15/38
Conclusion
1={B, aB, bab, d}
2={B, Ba, bab, d}
1is a valid alphabetwhile2is anin-validalphabet.
-
8/9/2019 Lesson 1UAF
16/38
Length ofStrings
Definition:
The lengthofstring s, denoted by |s|, is the
numberof letters inthe string. Example:
={a,b}
s=ababa|s|=5
-
8/9/2019 Lesson 1UAF
17/38
Example:
={B, aB, bab, d}
s=BaBbabBd
Tokenizing=(B), (aB), (bab), (B), (d)
|s|=5
-
8/9/2019 Lesson 1UAF
18/38
Reverse of a String
Definition:
Thereverseofa string s denoted byRev(s)
or sr, is obtained by writingthe letters ofsinreverseorder.
Example:
Ifs=abcis a stringdefinedover={a,b,c}thenRev(s) or sr=cba
-
8/9/2019 Lesson 1UAF
19/38
Example:
={B, aB, bab, d}
s=BaBbabBd
Rev(s)=dBbabaBB
-
8/9/2019 Lesson 1UAF
20/38
Defining Languages
The languages can bedefinedindifferentways , such as Descriptivedefinition,Recurs
ivedef
inition, us
ing
RegularExpressions(RE) andusing Finite
Automaton(FA) etc.
Descriptive definition of language:The languageis defined, describingtheconditions imposedonits words.
-
8/9/2019 Lesson 1UAF
21/38
Example:
The language Lofstrings ofodd length,
definedover
={a},
can be wr
itten asL={a, aaa, aaaaa,..}
Example:
The languageLofstrings thatdoes notstart
with a, definedover={a,b,c}, can be writtenas
L={b, c, ba, bb, bc, ca, cb, cc, }
-
8/9/2019 Lesson 1UAF
22/38
Example:
The languageLofstrings of length2,
definedover={0,1,2}, can be written asL={00, 01, 02,10, 11,12,20,21,22}
Example:
The languageLofstrings endingin 0,definedover ={0,1}, can be written as
L={0,00,10,000,010,100,110,}
-
8/9/2019 Lesson 1UAF
23/38
Example: The languageEQUAL, ofstrings withnumberofas equal tonumberofbs, definedover={a,b}, can be written as
{ ,ab,aabb,abab,baba,abba,}
Example: The languageEVEN-EVEN, ofstringswith evennumberofas and evennumberof
bs, defi
nedover={
a,b},c
an be wri
tten as{, aa, bb, aaaa,aabb,abab, abba, baab, baba,bbaa, bbbb,}
-
8/9/2019 Lesson 1UAF
24/38
Example: The languageINTEGER, ofstringsdefinedover={-,0,1,2,3,4,5,6,7,8,9}, can
be written asINTEGER={,-2,-1,0,1,2,}
Example: The languageEVEN, ofstingsdefin
edove
r={
-,0,1,2,3,4,
5,6,7,8,9},
c
anbe written as
EVEN={ ,-4,-2,0,2,4,}
-
8/9/2019 Lesson 1UAF
25/38
Example: The language{anbn}, ofstringsdefinedover={a,b}, as
{a
n
b
n
: n=1,2,3,},can be wr
itten as{ab, aabb, aaabbb,aaaabbbb,}
Example: The language{anbnan}, ofstringsdefinedover={a,b}, as
{anbnan: n=1,2,3,}, can be written as
{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,}
-
8/9/2019 Lesson 1UAF
26/38
Example: The languagefactorial, ofstringsdefinedover={1,2,3,4,5,6,7,8,9} i.e.
{1,2,6,24,120,} Example: The languageFACTORIAL, of
strings definedover={a}, as
{an!: n=1,2,3,}, can be written as
{a,aa,aaaaaa,}. Itis to benotedthatthelanguage FACTORIALcan bedefinedoverany single letter alphabet.
-
8/9/2019 Lesson 1UAF
27/38
Example: The languageDOUBLEFACTORIAL,ofstrings definedover={a, b}, as
{an!
bn!
: n=1,2,3,}, can be written as{ab, aabb, aaaaaabbbbbb,}
Example: The languageSQUARE, ofstringsdefinedover={a}, as
{an2
: n=1,2,3,}, can be written as
{a, aaaa, aaaaaaaaa,}
-
8/9/2019 Lesson 1UAF
28/38
Example: The languageDOUBLESQUARE, ofstrings defined
over={a,b}, as{an
2
bn2
: n=1,2,3,}, can be written as
{ab, aaaabbbb, aaaaaaaaabbbbbbbbb,}
-
8/9/2019 Lesson 1UAF
29/38
Example: The languagePRIME, ofstringsdefinedover={a}, as
{ap: pis prime}, can be written as
{aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa}
-
8/9/2019 Lesson 1UAF
30/38
An Important language
PALINDROME:
The languageconsistingof andthe
strings s definedover suchthatRev(s)=s.
Itis to bedenotedthatthe words ofPALINDROME arecalledpalindromes.
Example:For={a,b},PALINDROME={ , a, b, aa, bb, aaa, aba,bab, bbb, ...}
-
8/9/2019 Lesson 1UAF
31/38
Remark
There are as manypalindromes of length2nas there areof length2n-1.
Toprovethe aboveremark, thefollowingis
to benoted:
-
8/9/2019 Lesson 1UAF
32/38
Note
Numberofstrings of length mdefinedoveralphabetof n letters is nm.
Examples: The languageofstrings of length2, definedover={a,b} is L={aa, ab, ba, bb} i.e.numberofstrings =22
The languageofstrings of length 3, definedover={a,b} is L={aaa, aab, aba, baa, abb,bab, bba, bbb} i.e. numberofstrings =23
-
8/9/2019 Lesson 1UAF
33/38
Tocalculatethenumberofpalindromes oflength(2n), considerthefollowingdiagram,
-
8/9/2019 Lesson 1UAF
34/38
which shows thatthere are as manypalindromes of length2n as there arethe
strings of lengt
hn
i.e. t
herequ
irednumberofpalindromes are2n.
-
8/9/2019 Lesson 1UAF
35/38
Tocalculatethenumberofpalindromes oflength (2n-1) with a as themiddle letter,
considerthefollowingdiagram,
-
8/9/2019 Lesson 1UAF
36/38
which shows thatthere are as manypalindromes of length2n-1 as there arethe
strings of lengt
hn-1
i.e. t
herequ
irednumberofpalindromes are2n-1.
Similarlythenumberofpalindromes of length2n-1, with b as middle letter, will be2n-1as
well. Hencethetotal numberofpalindromes oflength2n-1 will be2n-1+ 2n-1=2 (2n-1)=2n.
-
8/9/2019 Lesson 1UAF
37/38
Exercise
Q) Provethatthere are as manypalindromes
of length2n, definedover ={a,b,c}, asthere areof length2n-1. Determinethenumberofpalindromes of length2ndefinedoverthe same alphabetas well.
-
8/9/2019 Lesson 1UAF
38/38
SummingUp Lecture-1
Introductiontothecoursetitle, Formal andIn-
formal languages, Alphabets, Str
ings, Null str
ing,Words, Valid andIn-valid alphabets, lengthofa
string, Reverseofa string, Defining languages,Descriptivedefinitionof languages, EQUAL,EVEN-EVEN, INTEGER, EVEN, { anbn}, { anbnan
}, factorial, FACTORIAL, DOUBLEFACTORIAL,SQUARE, DOUBLESQUARE, PRIME,PALINDROME.