30
1 CD5560 FABER Formal Languages, Automata and Models of Computation Exercise 2 Mälardalen University 2007

CD5560 FABER Formal Languages, Automata and Models of Computation Exercise 2

Embed Size (px)

DESCRIPTION

CD5560 FABER Formal Languages, Automata and Models of Computation Exercise 2 Mälardalen University 2007. NEXT WEEK! Midterm Exam 1 Regular Languages. Place: U2-114 Time: Tuesday 2007-04-24, 10:15-12:00 It is OPEN BOOK . - PowerPoint PPT Presentation

Citation preview

1

CD5560

FABER

Formal Languages, Automata and Models of Computation

Exercise 2

Mälardalen University

2007

2

NEXT WEEK!Midterm Exam 1

Regular Languages

Place: U2-114

Time: Tuesday 2007-04-24, 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).

3

Tenta 29 okt 1999; uppgift 2 (L Salling)

Construct (and explain)

},,{ cbawich strings contain all three symbols!

),( LabbcbaLaba

a) A regular expression over

4

Solution bcacba

abcbac

acbcab

baccacabba )()(

abccbcbaab )()( acbbcbcaac )()(

or

5

Construct (and explain)

},,{ cbawich strings contain all three symbols!

b) A minimal DFA

for a language L over

6

ca,

1

43

7

5

2

6

8

a

b

ba,

c

cba ,,

b

c

bc

b c

bc,

c

b

a

a

a

a

7

ca,

1

43

7

5

2

6

8

a

b

ba,

c

cba ,,

b

c

bc

b c

bc,

c

b

a

a

a

a

}7,6,5,4,3,2,1{ }8{

}6,5,4,3,2,1{a

}7{ }8{

}1{ }2{ }4{ }6{ }3{ }5{ }7{ }8{

c

}6,4,2,1{b

}3{ }5{ }7{ }8{

Särskiljningsalgoritm

8

c) En reguljär grammatik för L

ca,

S

BC

F

D

A

E

G

a

b

ba,

c

cba ,,

b

c

bc

b c

bc,

c

b

a

a

a

a

cCbBaAS ||

cDbEaAA ||

aEcFbBB ||

bFaDcCC ||

bGcDaDD ||

cGbEaEE ||

aGcFbFF ||

cGbGaGG |||

9

Tenta 24 okt 1994; uppgift 2 (L Salling)

Reguljära?

},{ ba

vars strängar innehåller ett jämnt antal a:n!

a) Språket över

Ja, språket är reguljärt och beskrivs med ett reguljärt uttryck:

)( ababb

10

Tenta 24 okt 1994; uppgift 2 (L Salling)

}(,),,{ a

b) De välformade aritmetiska uttrycken formade i alfabetet

Nej, språket är inte reguljärt: Ta följande sträng:

))))(((( aaaaa 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.

11

Tenta 15 mars 1995; uppgift 3 (L Salling)

Reguljära?

}

3|},{{

trängpalindromsenärsom

längdavprefixettharwbaw a)

Ja, språket är reguljärt och beskrivs med ett reguljärt uttryck:

))(( babbbbababaaaa

12

Tenta 15 mars 1995; uppgift 3 (L Salling)

Reguljära?

b)

}

3|},{{

trängpalindromsenärsom

MINSTlängdavprefixettharwbaw

Nej. Strängen22 aabbaw NN

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.

13

Tenta 15 mars 1995; uppgift 3 (L Salling)

Reguljära?

c)

}

3|},{{

trängpalindromsenärsom

MINSTlängdavprefixingetwbaw

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).

14

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.

{ | , {0,1} } Ruu v u v

15

Minimizing DFA’s

By Partitioning(Delmängdskonstruktion)

16

Minimizing DFA’s

Different methods

All involve finding equivalent states:

States that go to equivalent states under all inputs

We will use the Partitioning Method

17

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?

18

• 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

19

Partitioning AlgorithmFirst

Divide the set of states into

Final and Non-final states

Partition I

Partition II

a b

S0 S1 S4

S1 S5 S2

S3 S3 S3

S4 S1 S4

S5 S1 S4

S6 S3 S7

*S2 S3 S6

*S7 S3 S6

20

Partitioning AlgorithmNow

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 S4 I

S5 S1 I S4 I

S6 S3 I S7 II

*S2 S3 I S6 I

*S7 S3 I S6 I

21

Partitioning Algorithm

a b

S0 S1 S4

S5 S1 S4

S3 S3 S3

S4 S1 S4

S1 S5 S2

S6 S3 S7

*S2 S3 S6

*S7 S3 S6

22

Partitioning AlgorithmNow 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 S1 III S4 I

S3 S3 I S3 I

S4 S1 III S4 I

S1 S5 I S2 II

S6 S3 I S7 II

*S2 S3 I S6 III

*S7 S3 I S6 III

23

Partitioning Algorithm Note changes in S6,

S2 and S7

a b

S0 S1 III S4 I

S5 S1 III S4 I

S4 S1 III S4 I

S3 S3 IV S3 IV

S1 S5 I S2 II

S6 S3 IV S7 II

*S2 S3 IV S6 III

*S7 S3 IV S6 III

24

Partitioning AlgorithmNow 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 S1 III S4 I

S4 S1 III S4 I

S3 S3 IV S3 IV

S1 S5 I S2 II

S6 S3 IV S7 II

*S2 S3 IV S6 V

*S7 S3 IV S6 V

25

Partitioning AlgorithmAll 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 S1 III S4 I

S4 S1 III S4 I

S3 S3 IV S3 IV

S1 S5 I S2 II

S6 S3 IV S7 II

*S2 S3 IV S6 V

*S7 S3 IV S6 V

26

Partitioning Algorithm

a b

I III I

*II IV V

III I II

IV IV IV

V IV II

Here they are:

Va

a

aa ab

b

b

bb

b

27

Chomsky Hierarchy

28

Automata theory: formal languages and formal grammars

Chomsky hierarchy

Grammars Languages Minimal automaton

Type-0 Unrestricted Recursively enumerable Turing machine

Type-1 Context-sensitive Context-sensitive Linear-bounded

Type-2 Context-free Context-free Pushdown

Type-3 Regular Regular Finite

29

Grammar Languages Automaton Production

rules

Type-0 Recursively enumerable

Turing machine No restrictions

Type-1 Context-sensitive Linear-bounded non-deterministic Turing machine

Type-2 Context-free Non-deterministic pushdown automaton

Type-3 Regular Finite state automaton and

Automata theory: formal languages and formal grammars

30

Regular Languages

}{ nnba }{ Rww

Context-Free Languages

Non-regular languages

}0:{ ! nan}0,:{ lncba lnln