cd5560 faber formal languages, automata and models of computation lecture 2 mälardalen university
DESCRIPTION
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010. Content Languages, Alphabets and Strings Strings & String Operations Languages & Language Operations Regular Expressions Finite Automata, FA Deterministic Finite Automata, DFA. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/1.jpg)
1
CD5560
FABER
Formal Languages, Automata and Models of Computation
Lecture 2
Mälardalen University2010
![Page 2: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/2.jpg)
2
ContentLanguages, Alphabets and Strings
Strings & String OperationsLanguages & Language Operations
Regular ExpressionsFinite Automata, FADeterministic Finite Automata, DFA
![Page 3: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/3.jpg)
3
Languages, Alphabets and
Strings
![Page 4: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/4.jpg)
4
defined over an alphabet:
Languages
zcba ,,,,
A language is a set of strings
A String is a sequence of letters
An alphabet is a set of symbols
![Page 5: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/5.jpg)
5
Alphabets and Strings
We will use small alphabets:
abbawbbbaaavabu
baaabbbaabababaabbaaba
Strings
ba,
![Page 6: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/6.jpg)
6
Operations on Strings
![Page 7: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/7.jpg)
7
String Operations
m
n
bbbvaaaw
21
21
y bbbaaax abba
mn bbbaaawv 2121
Concatenation (sammanfogning)
xy abbabbbaaa
![Page 8: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/8.jpg)
8
12aaaw nR
naaaw 21 ababaaabbb
Reverse (reversering)
bbbaaababa
Example:Longest odd length palindrome in a natural language:
saippuakauppias (Finnish: soap sailsman)
![Page 9: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/9.jpg)
9
String Length
naaaw 21
12
4
aaaabba
nw Length:
Examples:
![Page 10: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/10.jpg)
10
Recursive Definition of Length
For any letter:
For any string :
Example:
1a
1wwawa
41111
11111
1
aab
abbabba
![Page 11: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/11.jpg)
11
Length of Concatenation
vuuv
8538
vuuvaababaabuv
5,3,
vabaabvuaabuExample:
![Page 12: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/12.jpg)
12
Proof of Concatenation Length
Claim:
Proof: By induction on the length
Induction basis: From definition of length:
vuuv
v
1v
vuuuv 1
![Page 13: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/13.jpg)
13
Inductive hypothesis:
vuuv
nv
1nv
vuuv
Inductive step: we will prove
for
for
![Page 14: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/14.jpg)
14
Inductive StepWrite , where
From definition of length:
From inductive hypothesis:
Thus:
wav 1, anw
11
wwauwuwauv
wuuw
vuwauwuuv 1
END OF PROOF
![Page 15: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/15.jpg)
15
Empty String
A string with no letters: (Also denoted as )
Observations:
}{{}
0
abbaabbaabbawww
![Page 16: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/16.jpg)
16
Substring (delsträng)Substring of a string:
a subsequence of consecutive characters
String Substring
bbabbabbaab
abbababbababbababbab
![Page 17: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/17.jpg)
17
Prefix and Suffix
Suffixesabbab
abbababbaabbaba
babbabbbababbab uvw
prefix
suffix
Prefixes
![Page 18: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/18.jpg)
18
Repetition
Example:
Definition:
n
n www... w
abbaabbaabba 2
0w
0abba
}
(String repeated n times)w
![Page 19: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/19.jpg)
19
The (Kleene* star) Operation
the set of all possible strings from alphabet
*
,,,,,,,,,*
,aabaaabbbaabaaba
ba
[* Kleene is pronounced "clay-knee“]
http://en.wikipedia.org/wiki/Kleene_star
![Page 20: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/20.jpg)
20
The + (Kleene plus) Operation
: the set of all possible strings from the alphabet except
,ba ,,,,,,,,,* aabaaabbbaabaaba
*
,,,,,,,, aabaaabbbaabaaba
![Page 21: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/21.jpg)
21
Example
* , oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch
*
, fyoj , usch
oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch
![Page 22: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/22.jpg)
22
Operations on Languages
![Page 23: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/23.jpg)
23
Language
A language is any subset of
Example:
Languages:
*
,,,,,,,,*,
aaabbbaabaababa
},,,,,{,,
aaaaaaabaababaabbaaabaaa
![Page 24: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/24.jpg)
24
Example
An infinite language }0:{ nbaL nn
Labb
aaaaabbbbbaabbab
L
![Page 25: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/25.jpg)
25
Operations on Languages
The usual set operations
aaaaaabbbaaaaaba
ababbbaaaaabaaaaabbabaabbbaaaaaba
,,,,}{,,,
},,,{,,,
,,,,,,, aaabbabaabbaa ,,,,,,,,,* aabaaabbbaabaaba
LL *Complement:
![Page 26: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/26.jpg)
26
Reverse
}:{ LwwL RR
ababbaabababaaabab R ,,,,
}0:{
}0:{
nabL
nbaLnnR
nn
Examples:
Definition:
![Page 27: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/27.jpg)
27
Concatenation
Definition: 2121 ,: LyLxxyLL
baaabababaaabbaaaab
aabbaaba,,,,,
,,,
Example
![Page 28: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/28.jpg)
28
RepeatDefinition:
Special case:
n
n LLLL
bbbbbababbaaabbabaaabaaa
babababa,,,,,,,
,,,, 3
0
0
,, aaabbaa
L
![Page 29: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/29.jpg)
29
Example
}0:{ nbaL nn
}0,:{2 mnbabaL mmnn
2Laabbaaabbb
![Page 30: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/30.jpg)
30
Star-Closure (Kleene *)
Definition:
Example:
210* LLLL
,,,,,,,,
,,,
*,
abbbbabbaaabbaaabbbbbbaabbaa
bbabba
![Page 31: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/31.jpg)
31
Positive ClosureDefinition
*L 21 LLL
,,,,,,,,
,,,
abbbbabbaaabbaaabbbbbbaabbaa
bbabba
![Page 32: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/32.jpg)
32
Regular Expressions
![Page 33: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/33.jpg)
33
Regular Expressions: Recursive Definition
1
1
21
21
*r
rrrrr
are Regular Expressions
,,Primitive regular expressions:
2rGiven regular expressions and 1r
![Page 34: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/34.jpg)
34
Examples
)(* ccbaA regular expression:
baNot a regular expression:
![Page 35: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/35.jpg)
35
Zero or more. a* means "zero or more a's."
To say "zero or more ab's," that is,
{, ab, abab, ababab, ...}, you need to say (ab)*.
ab* denotes {a, ab, abb, abbb, abbbb, ...}.
cba ,,Building Regular Expressions
![Page 36: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/36.jpg)
36
One or more. Since a* means "zero or more a's", you can use aa* (or equivalently, a*a) to mean "one or more a's.“
Similarly, to describe "one or more ab's," that is, {ab, abab, ababab, ...}, you can use ab(ab)*.
cba ,,Building Regular Expressions
![Page 37: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/37.jpg)
37
Any string at all. To describe any string at all (with = {a, b, c}), you can use (a+b+c)*.
Any nonempty string. This can be written as any character from followed by any string at all: (a+b+c)(a+b+c)*.
cba ,,
Building Regular Expressions
![Page 38: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/38.jpg)
38
Any string not containing.... To describe any string at all that doesn't contain an a (with = {a, b, c}), you can use (b+c)*.
Any string containing exactly one... To describe any string that contains exactly one a, put "any string not containing an a," on either side of the a, like this: (b+c)*a(b+c)*.
cba ,,Building Regular Expressions
![Page 39: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/39.jpg)
39
Languages of Regular Expressions
,...,,,,,*)( bcaabcaabcacbaL
Example
rL rlanguage of regular expression
![Page 40: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/40.jpg)
40
Definition
For primitive regular expressions:
aaL
L
L
![Page 41: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/41.jpg)
41
Definition (continued)
For regular expressions and
1r 2r
2121 rLrLrrL
2121 rLrLrrL
** 11 rLrL
11 rLrL
![Page 42: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/42.jpg)
42
Example *aba
*abaL *aLbaL
*aLbaL
*aLbLaL
*aba
,...,,,, aaaaaaba
,...,,,...,,, baababaaaaaa
Regular expression:
![Page 43: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/43.jpg)
43
Example
Regular expression
bbabar *
,...,,,,, bbbbaabbaabbarL
![Page 44: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/44.jpg)
44
Example
Regular expression
bbbaar **
}0,:{ 22 mnbbarL mn
![Page 45: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/45.jpg)
45
Example
Regular expression
*)10(00*)10( r
)(rL { all strings with at least two consecutive 0 }
1,0
![Page 46: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/46.jpg)
46
Example
Regular expression
(consists of repeating 1’s and 01’s).
)0(*)011(1 r
)(rL = { all strings without two consecutive 0 }
1,0
![Page 47: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/47.jpg)
47
Example L = { all strings without
two consecutive 0 }
)0(*1)0(**)011*1(2 r
(In order not to get 00 in a string, after each 0 there must be an 1, which means that strings of the form 1....101....1are repeated. That is the first parenthesis. To take into account strings that end with 0, and those consisting of 1’s solely, the rest of the expression is added.)
Equivalent solution:
![Page 48: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/48.jpg)
48
Equivalent Regular Expressions
Regular expressions and
1r 2r
)()( 21 rLrL are equivalent if
Definition:
![Page 49: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/49.jpg)
49
Example L = { all strings without
two consecutive 0 }
)0(*1)0(**)011*1(2 r
LrLrL )()( 21 1r 2randare equivalentregular expressions.
)0(*)011(1 r
![Page 50: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University](https://reader035.vdocument.in/reader035/viewer/2022062521/5681388f550346895da03ff7/html5/thumbnails/50.jpg)
Additional Sourceshttp://www.math.uu.se/~salling/ Lennart Salling
http://www.math.uu.se/~salling/AUTOMATA_DV/index.htmlIntroduktion movie .movProgram, strings, integers and integer functions .movDifferent infinities and integer functions that can not be calculated
by a program .movStrings and languages .mov
Regular languages and regular expressions .mov
50