cd5560 faber formal languages, automata and models of computation lecture 0 - intro

52
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 0 - Intro Mälardalen University 2005

Upload: saad

Post on 22-Feb-2016

68 views

Category:

Documents


0 download

DESCRIPTION

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 0 - Intro Mälardalen University 2005. Content Adminstrivia Mathematical Preliminaries Countable Sets (Uppräkneliga mängder) Uncountable sets (Överuppräkneliga mängder). Lecturer & E xami ner - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

1

CD5560

FABER

Formal Languages, Automata and Models of Computation

Lecture 0 - Intro

Mälardalen University

2005

Page 2: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

2

Content

AdminstriviaMathematical PreliminariesCountable Sets (Uppräkneliga mängder)

Uncountable sets (Överuppräkneliga mängder)

Page 3: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

3

Lecturer & Examiner

Gordana Dodig-Crnkovic

Page 4: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

4

Teaching Assistent

Andreas Ermedahl

Page 5: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

5

http://www.idt.mdh.se/kurser/cd5560/05_04

visit home page regularly!

Course Home Page

Page 6: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

6

How Much Work?

20 hours a week for this type of course (norm)

4 hours lectures2 hours exercises

14 hours own work a week!

Page 7: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

7

Mathematical Preliminaries

Page 8: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

8

• Sets

• Functions

• Relations

• Proof Techniques

• Languages, Alphabets and Strings

• Strings & String Operations

• Languages & Language Operations

Page 9: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

9

}3,2,1{AA set is a collection of elements

SETS

},,,{ airplanebicyclebustrainB

We write

A1

Bship

Page 10: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

10

Set Representations

C = { a, b, c, d, e, f, g, h, i, j, k }

C = { a, b, …, k }

S = { 2, 4, 6, … }

S = { j : j > 0, and j = 2k for some k>0 }

S = { j : j is nonnegative and even }

finite set

infinite set

Page 11: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

11

A = { 1, 2, 3, 4, 5 }

Universal Set: All possible elements

U = { 1 , … , 10 }

1 2 34 5

A

U

6

78

910

Page 12: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

12

Set OperationsA = { 1, 2, 3 } B = { 2, 3, 4, 5}

• Union

A U B = { 1, 2, 3, 4, 5 }

• Intersection

A B = { 2, 3 }

• Difference

A - B = { 1 }

B - A = { 4, 5 }

U

A B

A-B

Page 13: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

13

• Complement

Universal set = {1, …, 7}

A = { 1, 2, 3 } A = { 4, 5, 6, 7}

12

3

4

5

6

7

A A

A = A

Page 14: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

14

{ even integers } = { odd integers }

024

6

1

3

5

7

even

odd

Integers

Page 15: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

15

DeMorgan’s Laws

A U B = A BU

A B = A U B

U

Page 16: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

16

Empty, Null Set:

= { }

S U = S

S =

S - = S

- S =

U = Universal Set

Page 17: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

17

SubsetA = { 1, 2, 3} B = { 1, 2, 3, 4, 5 }

A B

U

Proper Subset: A B

U

A

B

Page 18: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

18

Disjoint Sets

A = { 1, 2, 3 } B = { 5, 6} A B =

U

A B

Page 19: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

19

Set Cardinality

For finite sets

A = { 2, 5, 7 }

|A| = 3

Page 20: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

20

Powersets

A powerset is a set of sets

Powerset of S = the set of all the subsets of S

S = { a, b, c }

2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }

Observation: | 2S | = 2|S| ( 8 = 23 )

Page 21: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

21

Cartesian Product

A = { 2, 4 } B = { 2, 3, 5 }

A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 5) }

|A X B| = |A| |B|

Generalizes to more than two sets

A X B X … X Z

Page 22: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

22

PROOF TECHNIQUES

• Proof by construction

• Proof by induction

• Proof by contradiction

Page 23: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

23

Construction

We define a graph to be k-regular

if every node in the graph has degree k.

Theorem. For each even number n > 2 there exists

3-regular graph with n nodes.

1

2

4

3

0

5

1 2

0

3n = 4 n = 6

Page 24: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

24

Construct a graph G = (V, E) with n > 2 nodes.

V= { 0, 1, …, n-1 }

E = { {i, i+1} for 0 i n-2} {{n-1,0}} (*)

{{i, i+n/2 for 0 i n/2 –1} (**)

The nodes of this graph can be written consecutively around the circle.

(*) edges between adjacent pairs of nodes

(**) edges between nodes on opposite sides

Proof by Construction

END OF PROOF

Page 25: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

25

Induction

We have statements P1, P2, P3, …

If we know

• for some k that P1, P2, …, Pk are true

• for any n k that

P1, P2, …, Pn imply Pn+1

Then

Every Pi is true

Page 26: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

26

Proof by Induction

• Inductive basis

Find P1, P2, …, Pk which are true

• Inductive hypothesis

Let’s assume P1, P2, …, Pn are true,

for any n k

• Inductive step

Show that Pn+1 is true

Page 27: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

27

Example

Theorem A binary tree of height n

has at most 2n leaves.

Proof

let L(i) be the number of leaves at level i

L(0) = 1

L(3) = 8

Page 28: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

28

We want to show: L(i) 2i

• Inductive basis

L(0) = 1 (the root node)

• Inductive hypothesis

Let’s assume L(i) 2i for all i = 0, 1, …, n

• Induction step

we need to show that L(n + 1) 2n+1

Page 29: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

29

Induction Step

hypothesis: L(n) 2n

Leveln

n+1

Page 30: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

30

hypothesis: L(n) 2n

Leveln

n+1

L(n+1) 2 * L(n) 2 * 2n = 2n+1

Induction Step

END OF PROOF

Page 31: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

31

Inductionsbevis: Potensmängdens kardinalitet

Påstående: En mängd med n element har 2n delmängder

Kontroll

• Tomma mängden {} (med noll element) har bara en delmängd: {}.

• Mängden {a} (med ett element) har två delmängder: {} och {a}

Page 32: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

32

Påstående: En mängd med n element har 2n delmängder

Kontroll (forts.)

• Mängden {a, b} (med två element) har fyra delmängder:

{}, {a}, {b} och {a,b}

• Mängden {a, b, c} (med tre element) har åtta delmängder: {}, {a}, {b}, {c} och {a,b}, {a,c}, {b,c}, {a,b,c}

Påstående stämmer så här långt.

Page 33: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

33

Bassteg

Enklaste fallet är en mängd med noll element (det finns bara en sådan), som har 20 = 1 delmängder.

Page 34: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

34

Induktionssteg

Antag att påståendet gäller för alla mängder med k element, dvs antag att varje mängd med k element har 2k delmängder.

Visa att påståendet i så fall också gäller för alla mängder med k+1 element, dvs visa att varje mängd med k+1 element har 2k+1 delmängder.

Page 35: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

35

Vi betraktar en godtycklig mängd med k+1 element. Delmängderna till mängden kan delas upp i två sorter:

Delmängder som inte innehåller element nr k+1: En sådan delmängd är en delmängd till mängden med de k första elementen, och delmängder till en mängd med k element finns det (enligt antagandet) 2k stycken.

Page 36: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

36

Delmängder som innehåller element nr k+1: En sådan delmängd kan man skapa genom att ta en delmängd som inte innehåller element nr k+1 och lägga till detta element. Eftersom det finns 2k delmängder utan element nr k+1 kan man även skapa 2k

delmängder med detta element.

Totalt har man 2k + 2k = 2. 2k= 2k+1 delmängder till den betraktade mängden.

END OF PROOF

(Exempel från boken: Diskret matematik och diskreta modeller, K Eriksson, H. Gavel)

Page 37: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

37

Proof by Contradiction

We want to prove that a statement P is true

• we assume that P is false

• then we arrive at a conclusion that contradicts our assumptions

• therefore, statement P must be true

Page 38: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

38

Example

Theorem is not rational

Proof

Assume by contradiction that it is rational

= n/m

n and m have no common factors

We will show that this is impossible

2

2

Page 39: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

39

Therefore, n2 is evenn is even

n = 2 k

2 m2 = 4k2 m2 = 2k2m is even

m = 2 p

Thus, m and n have common factor 2

Contradiction!

= n/m 2 m2 = n2 2

END OF PROOF

Page 40: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

40

Languages, Alphabets and

Strings

Page 41: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

41

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 42: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

42

Alphabets and Strings

We will use small alphabets:

abbawbbbaaavabu

baaabbbaabababaabbaaba

Strings

ba,

Page 43: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

43

Operations on Strings

Page 44: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

44

String Operations

m

n

bbbvaaaw

21

21

y bbbaaax abba

mn bbbaaawv 2121

Concatenation (sammanfogning)

xy abbabbbaaa

Page 45: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

45

12aaaw nR

naaaw 21 ababaaabbb

Reverse (reversering)

bbbaaababa

Example:Longest odd length palindrome in a natural language:

saippuakauppias (Finnish: soap sailsman)

Page 46: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

46

String Length

naaaw 21

12

4

aaaabba

nw Length:

Examples:

Page 47: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

47

Empty String

A string with no letters: (Also denoted as )

Observations:

}{{}

0

abbaabbaabbawww

Page 48: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

48

Substring (delsträng)Substring of string:

a subsequence of consecutive characters

String Substring

bbabbabbaab

abbababbababbababbab

Page 49: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

49

Prefix and Suffix

Suffixesabbab

abbababbaabbaba

babbabbbababbab uvw

prefix

suffix

Prefixes

Page 50: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

50

Repetition

Example:

Definition:

n

n www... w

abbaabbaabba 2

0w

0abba

}

(String repeated n times)w

Page 51: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

51

The * (Kleene star) Operation

the set of all possible strings from alphabet

*

,,,,,,,,,*

,aabaaabbbaabaaba

ba

[Kleene is pronounced "clay-knee“]

Page 52: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 0 - Intro

52

The + Operation

: the set of all possible strings from alphabet except

,ba ,,,,,,,,,* aabaaabbbaabaaba

*

,,,,,,,, aabaaabbbaabaaba