Ladda ner presentationen
Presentation laddar. Vänta.
1
Formal Languages, Automata and Models of Computation
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2006
2
RECAPITULATION: REGULAR LANGUAGES - Languages, Alphabets and Strings - Operations on Strings - Operations on Languages - Regular Expressions - Finite Automata - Regular Grammars - Pumping lemma INTRODUCTION: CONTEXT FREE LANGUAGES
3
NEXT WEEK! Midterm Exam 1 Regular Languages
Place: U2114 Time: Tuesday , 10:15-12:00 It is OPEN BOOK. (This means you are allowed to bring in one book of your choice.) It will cover lectures 1 through 5 (Regular Languages).
4
Med det som vi har lärt oss hittills kan vi klara följande tentauppgifter…
5
Tenta 29 okt 1999; uppgift 2 (L Salling)
Konstruera (med motiveringar) a) Ett reguljärt uttryck över vars strängar innehåller samtliga tre tecken!
6
Lösning eller
7
Konstruera (med motiveringar)
b) En minimal DFA för ett språk L över vars strängar innehåller samtliga tre tecken!
9
Särskiljningsalgoritm
10
c) En reguljär grammatik för L
11
Tenta 24 okt 1994; uppgift 2 (L Salling)
Reguljära? a) Språket över vars strängar innehåller ett jämnt antal a:n! Ja, språket är reguljärt och beskrivs med ett reguljärt uttryck:
12
Tenta 24 okt 1994; uppgift 2 (L Salling)
b) De välformade aritmetiska uttrycken formade i alfabetet Nej, språket är inte reguljärt: Ta följande sträng: N stycken a adderas Om språket vore reguljärt skulle det kunna pumpas. Men de N avslutande tecknen består enbart av höger- parenteser och kan inte ändras utan att balansen med vänsterparenteserna förstörs.
13
Tenta 15 mars 1995; uppgift 3 (L Salling)
Reguljära? c) Ja, språket är reguljärt och beskrivs med ett reguljärt uttryck:
14
Tenta 15 mars 1995; uppgift 3 (L Salling)
Reguljära? d) Nej. Strängen vars enda palindromprefix längre än 2 är strängen själv, kan inte pumpas någonstans inuti b-block utan att falla ur språket.
15
Tenta 15 mars 1995; uppgift 3 (L Salling)
Reguljära? e) Nej. Om det vore reguljärt skulle även föregående språk vara det (eftersom det är komplementspråk, och regulariteten bevaras under komplementbildning).
16
Pumping Lemma is necessary but not sufficient for RL
OBS! The pumping lemma does not give a sufficient condition for a language to be regular! You can not use it to show that language is regular. For example, the language (strings over the alphabet {0,1} consisting of a nonempty even palindrome followed by another nonempty string) is not regular but can still be "pumped" with m = 4: Suppose w=uuRv has length at least 4. If u has length 1, then |v| ≥ 2 and we can take y to be the first character in v. Otherwise, take y to be the first character of u and note that yk for k ≥ 2 starts with the nonempty palindrome yy. For a practical test that exactly characterizes regular languages, see the Myhill-Nerode theorem. The typical method for proving that a language is regular is to construct either a Finite State Machine or a Regular Expression for the language.
17
By Partitioning (Delmängdskonstruktion)
Minimizing DFA’s By Partitioning (Delmängdskonstruktion)
18
Minimizing DFA Different methods
All involve finding equivalent states: States that go to equivalent states under all inputs We will use the Partitioning Method
19
Minimizing DFA’s by Partitioning
Consider the following DFA (from Forbes Louis): Accepting states are yellow Non-accepting states are blue Are any states really the same?
20
S2 and S7 are really the same: Both Final states
Both go to S6 under input b Both go to S3 under an a S0 and S5 really the same. Why? We say each pair is equivalent Are there any other equivalent states? We can merge equivalent states into 1 state
21
Partitioning Algorithm
First Divide the set of states into Final and Non-final states Partition I Partition II a b S0 S1 S4 S5 S2 S3 S6 S7 *S2 *S7
22
Partitioning Algorithm
Now See if states in each partition each go to the same partition S1 & S6 are different from the rest of the states in Partition I (but like each other) We will move them to their own partition a b S0 S1 I S4 I S1 S5 I S2 II S3 S3 I S3 I S4 S1 I S5 S6 S7 II *S2 S6 I *S7
23
Partitioning Algorithm
b S0 S1 S4 S5 S3 S2 S6 S7 *S2 *S7
24
Partitioning Algorithm
Now again See if states in each partition each go to the same partition In Partition I, S3 goes to a different partition from S0, S5 and S4 We’ll move S3 to its own partition a b S0 S1 III S4 I S5 S3 S3 I S4 S1 S5 I S2 II S6 S7 II *S2 S6 III *S7
25
Partitioning Algorithm
Note changes in S6, S2 and S7 a b S0 S1 III S4 I S5 S4 S3 S3 IV S1 S5 I S2 II S6 S7 II *S2 S6 III *S7
26
Partitioning Algorithm
Now S6 goes to a different partition on an a from S1 S6 gets its own partition. We now have 5 partitions Note changes in S2 and S7 a b S0 S1 III S4 I S5 S4 S3 S3 IV S1 S5 I S2 II S6 S7 II *S2 S6 V *S7
27
Partitioning Algorithm
All states within each of the 5 partitions are identical. We might as well call the states I, II III, IV and V. a b S0 S1 III S4 I S5 S4 S3 S3 IV S1 S5 I S2 II S6 S7 II *S2 S6 V *S7
28
Partitioning Algorithm
Here they are: a b I III *II IV V II V a b
Liknande presentationer
© 2024 SlidePlayer.se Inc.
All rights reserved.