cdt314 faber formal languages, automata and models of computation lecture 2

53
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2 School of Innovation, Design and Engineering Mälardalen University 2011

Upload: alec-delaney

Post on 31-Dec-2015

39 views

Category:

Documents


2 download

DESCRIPTION

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2 School of Innovation, Design and Engineering Mälardalen University 2011. Content Languages, Alphabets and Strings Strings & String Operations Languages & Language Operations Regular Expressions - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

1

CDT314

FABER

Formal Languages, Automata and Models of Computation

Lecture 2

School of Innovation, Design and Engineering Mälardalen University

2011

Page 2: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

2

Content

Languages, Alphabets and Strings

Strings & String Operations

Languages & Language Operations

Regular Expressions

Finite Automata, FA

Deterministic Finite Automata, DFA

Page 3: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

3

Languages, Alphabets and Strings

Page 4: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

5

Alphabets and Strings

We will use small alphabets:

abbaw

bbbaaav

abu

baaabbbaaba

baba

abba

ab

aStrings

ba,

Page 6: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

6

Operations on Strings

Page 7: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

7

String Operations

m

n

bbbv

aaaw

21

21

y bbbaaax abba

mn bbbaaawv 2121

Concatenation (sammanfogning)

xy abbabbbaaa

Page 8: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

8

12aaaw nR

naaaw 21 ababaaabbb

Reverse (reversering)

bbbaaababa

Example:

Longest odd length palindrome in a natural language:

saippuakauppias

(Finnish: soap sailsman)

Page 9: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

9

String Length

naaaw 21

1

2

4

a

aa

abba

nw Length:

Examples:

Page 10: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

10

Recursive Definition of Length

For any letter:

For any string :

Example:

1a

1wwawa

41111

11111

1

aab

abbabba

Page 11: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

11

Length of Concatenation

vuuv

853

8

vuuv

aababaabuv

5,

3,

vabaabv

uaabuExample:

Page 12: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

13

Inductive hypothesis:

vuuv

nv

1nv

vuuv

Inductive step: we will prove

for

for

Page 14: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

14

Inductive Step

Write , where

From definition of length:

From inductive hypothesis:

Thus:

wav 1, anw

1

1

wwa

uwuwauv

wuuw

vuwauwuuv 1

END OF PROOF

Page 15: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

15

Empty String

A string with no letters: (Also denoted as )

Observations:

}{{}

0

abbaabbaabba

www

Page 16: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

16

Substring (delsträng)

Substring of a string:

a subsequence of consecutive characters

String Substring

bbab

b

abba

ab

abbab

abbab

abbab

abbab

Page 17: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

17

Prefix and Suffix

Suffixesabbab

abbab

abba

abb

ab

a

b

ab

bab

bbab

abbab uvw

prefix

suffix

Prefixes

Page 18: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

18

Repetition

Example:

Definition:

n

n www... w

abbaabbaabba 2

0w

0abba

}

(String repeated n times)w

Page 19: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

20

The + (Kleene plus) Operation

: the set of all possible strings from the

alphabet except

,ba

,,,,,,,,,* aabaaabbbaabaaba

*

,,,,,,,, aabaaabbbaabaaba

Page 21: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

21

Example

* , oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch

*

, fyoj , usch

oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch

Page 22: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

22

Operations on Languages

Page 23: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

23

Language

A language is any subset of

Example:

Languages:

*

,,,,,,,,*

,

aaabbbaabaaba

ba

},,,,,{

,,

aaaaaaabaababaabba

aabaaa

Page 24: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

24

Example

An infinite language }0:{ nbaL nn

Labb

aaaaabbbbb

aabb

ab

L

Page 25: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

25

Operations on Languages

The usual set operations

aaaaaabbbaaaaaba

ababbbaaaaaba

aaaabbabaabbbaaaaaba

,,,,

}{,,,

},,,{,,,

,,,,,,, aaabbabaabbaa ,,,,,,,,,* aabaaabbbaabaaba

LL *Complement:

Page 26: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

26

Reverse

}:{ LwwL RR

ababbaabababaaabab R ,,,,

}0:{

}0:{

nabL

nbaLnnR

nn

Examples:

Definition:

Page 27: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

27

Concatenation

Definition: 2121 ,: LyLxxyLL

baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

Example

Page 28: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

28

Repeat

Definition:

Special case:

n

n LLLL

bbbbbababbaaabbabaaabaaa

babababa

,,,,,,,

,,,, 3

0

0

,, aaabbaa

L

Page 29: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

29

Example

}0:{ nbaL nn

}0,:{2 mnbabaL mmnn

2Laabbaaabbb

Page 30: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

30

Star-Closure (Kleene *)

Definition:

Example:

210* LLLL

,,,,

,,,,

,,

,

*,

abbbbabbaaabbaaa

bbbbbbaabbaa

bbabba

Page 31: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

31

Positive Closure

Definition

*L 21

LLL

,,,,

,,,,

,,

,

abbbbabbaaabbaaa

bbbbbbaabbaa

bba

bba

Page 32: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

32

Regular Expressions

Page 33: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

33

Regular Expressions: Recursive Definition

1

1

21

21

*

r

r

rr

rr

are Regular Expressions

,,Primitive regular expressions:

2rGiven regular expressions and 1r

Page 34: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

34

Examples

)(* ccbaA regular expression:

baNot a regular expression:

Page 35: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

39

Languages of Regular Expressions

,...,,,,,*)( bcaabcaabcacbaL

Example

rL rlanguage of regular expression

Page 40: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

40

Definition

For primitive regular expressions:

aaL

L

L

Page 41: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

41

Definition (continued)

For regular expressions and

1r 2r

2121 rLrLrrL

2121 rLrLrrL

** 11 rLrL

11 rLrL

Page 42: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

42

Example *aba

*abaL *aLbaL

*aLbaL

*aLbLaL

*aba

,...,,,, aaaaaaba

,...,,,...,,, baababaaaaaa

Regular expression:

Page 43: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

43

Example

Regular expression

bbabar *

,...,,,,, bbbbaabbaabbarL

Page 44: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

44

Example

Regular expression

bbbaar **

}0,:{ 22 mnbbarL mn

Page 45: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

45

Example

Regular expression

*)10(00*)10( r

)(rL { all strings with at least

two consecutive 0 }

1,0

Page 46: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

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: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

48

Equivalent Regular Expressions

Regular expressions and

1r 2r

)()( 21 rLrL are equivalent if

Definition:

Page 49: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

49

Example L = { all strings without

two consecutive 0 }

)0(*1)0(**)011*1(2 r

LrLrL )()( 21 1r 2randare equivalent

regular expressions.

)0(*)011(1 r

Page 50: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

Lennart Salling’s Video Resourceshttp://www.math.uu.se/~salling/ Lennart Salling

http://www.math.uu.se/~salling/AUTOMATA_DV/index.html

Introduktion: http://www2.math.uu.se/~salling/Movies/Intro%20to%20Automata.mov

Program, strings, integers and integer functions

http://www2.math.uu.se/~salling/Movies/StringsNumbersAndFunctions.mov

http://www.youtube.com/embed/EuhbL0MPryU Vad handlar kursen om?

http://www.youtube.com/embed/VM5SUcyY4sI?hl=en&fs=1 Kan alla problem lösas av program?

http://www.youtube.com/embed/acsUNSkzUgg?hl=en&fs=1 Vad har stora och små oändligheter med saken att göra?

http://www.youtube.com/embed/eQoP_kuNgXU?hl=sv&fs=1 Vad har språk och beräkningar med varandra att göra?

http://www.youtube.com/embed/-4K72wsQmPI?hl=sv&fs=1 Reguljära språk, vad är det?

http://www.youtube.com/embed/R2bHYnBXWFs?hl=sv&fs=1 Vilka automater är specialiserade på reguljära språk?

http://www.youtube.com/embed/2PNyEWl1AI0?hl=sv&fs=1 Varför icke-determinism?

http://www.youtube.com/embed/2abHjjS8Tqc?hl=sv&fs=1 Hur ser problem ut som inte kan lösas av program?

http://www.youtube.com/embed/WMN_wz-b3K0?hl=sv&fs=1

http://www.youtube.com/embed/y-zMnV3G9pg?hl=sv&fs=1 Hur kan man visa att ett problem inte kan lösas av program?

50

Page 51: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

Lennart Salling’s Video Video Resources

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Closure_properties/Closure_properties.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/FA_to_RegExpression/FA_to_RegExpression.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Famous_undecidable_and_decidable_problems/Famous_undecidable_and_decidable_problems.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Universal_Turing_machines/Universal_Turing_machines.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Turing_machines/Turing_machines.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Unrestricted_grammar/Unrestricted_grammar.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Pumping%20CFL/Pumping%20CFL.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/PDA/PDA.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/CFG/CFG.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Nonregularity/Nonregularity.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Reduction_of_number_of_states/Reduction_of_number_of_states.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/Closure_properties/Closure_properties.mov

http://www2.math.uu.se/~salling/AUTOMATA_DV/media/2011/FA_to_RegExpression/FA_to_RegExpression.mov

51

Page 52: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

More Video’s 1

www.youtube.com/watch?v=MzDG34w0LLA&feature=player_embedded SubsetConstruction

http://www.youtube.com/watch?v=acsUNSkzUgg&feature=related Infinities

http://www.youtube.com/watch?v=y-zMnV3G9pg&feature=related Rice'sTheorem

http://www.youtube.com/watch?v=R2bHYnBXWFs&feature=related Finite Automata

http://www.youtube.com/watch?v=eQoP_kuNgXU&feature=related Strings and Languages

http://www.youtube.com/watch?v=-4K72wsQmPI&feature=related Regular Languages

http://www.youtube.com/watch?v=WMN_wz-b3K0&feature=related Accept and decide (TM)

 

52

Page 53: CDT314  FABER Formal Languages, Automata  and Models of Computation Lecture 2

More Video’s 2

http://www.youtube.com/watch?v=RYNN-tb9WxI&feature=related

Regular Expression to NFA

http://www.youtube.com/watch?v=shN_kHBFOUE&feature=related 2 - Convert Regular Expression to Finite-State Automaton

http://www.youtube.com/watch?v=dlH2pIndNrU&feature=related Convert Regular Expression to DFA

http://www.youtube.com/watch?v=5a_pO3NYJl0 Great Principles of Computing - Peter J. Denning

http://www.youtube.com/watch?v=60P7717-XOQ&feature=related Stephen Wolfram: Computing a theory of everything

http://www.youtube.com/watch?v=cCdbZqI1r7I&feature=related Computing Beyond Turing - Jeff Hawkins

53