Top Banner
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 1 - Intro Mälardalen University 2010
139

Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Sep 06, 2018

Download

Documents

dinhdien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

1

CDT314

FABER

Formal Languages, Automata

and Models of Computation

Lecture 1 - Intro

Mälardalen University

2010

Page 2: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

2

Content

Adminstrivia

Mathematical Preliminaries

Countable Sets (Uppräkneliga mängder)

Uncountable sets (Överuppräkneliga mängder)

Page 3: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

3

Examiner

Gordana Dodig-Crnkovic

Lecturer

Stefan Bygde

Page 4: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

4

http://www.idt.mdh.se/kurser/cd5560/11_10

visit home page regularly!

Course Home Page

Page 5: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

5

How Much Work?

20 hours a week for this type of course

(norm)

4 hours lectures

2 hours exercises

14 hours own work a week!

Page 6: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

6

Why Theory of Computation?

1. A real computer can be modelled by a

mathematical object: a theoretical computer.

2. A formal language is a set of strings, and

can represent a computational problem.

3. A formal language can be described in many

different ways that ultimately prove to be

identical.

4. Simulation: the relative power of computing

models can be based on the ease with

which one model can simulate another.

Page 7: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

7

5. Robustness of a computational model.

6. The Church-Turing thesis: anything that can

be computed can be computed by a Turing

machine.

7. Nondeterminism: languages can be

described by the existence or nonexistence

of computational paths.

8. Unsolvability: for some computational

problems there is no corresponding

algorithm that will unerringly solve them.

Page 8: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

8

Practical Applications

1. Efficient compilation of computer languages

2. String searching

3. Identifying the limits; Recognizing difficult problems

4. Applications to other areas:

– circuit verification

– economics and game theory (finite automata as

strategy models in decision-making);

– theoretical biology (L-systems as models of

organism growth)

– computer graphics (L-systems)

– linguistics (modeling by grammars)

Page 9: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

9

History

• Euclid's attempt to axiomatize geometry

(Archimedes realized, during his own efforts to

define the area of a planar figure, that Euclid's

attempt had failed and that additional postulates

were needed. )

• Leibniz's dream of a symbolic logic

• de Morgan, Boole, Frege, Russell, Whitehead:

Mathematics as branch of symbolic logic!

Page 10: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

10

1900 Hilberts program

1880 -1936 first programming languages

1931 Gödels incompleteness theorem

1936 Turing machine (showed to be equivalent with recursive functions). Commonly accepted: TM as ultimate computer

1950 automata

1956 language/automata hierarchy

Page 11: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

11

Every mathematical truth expressed in a formal

language is consisting of

• a fixed alphabet of admissible symbols, and

• explicit rules of syntax for combining those symbols

into meaningful words and sentences

Page 12: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

12

Turing used a Universal Turing machine (UTM) to prove an even more powerful incompleteness theorem because it destroyed not one but two of Hilbert's dreams:

1. Finding a finite list of axioms from which all

mathematical truths can be deduced

2. Solving the entscheidungsproblem, ("decision

problem“) by producing a "fully automatic procedure"

for deciding whether a given proposition (sentence) is

true or false.

Page 13: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Examination

• Three midterms

• Regular Languages

• Context Free Languages

• Restriction Free Languages

• OR:

• Final Exam in three parts

• If you have finished the midterm of one

time of language you don’t have to do

corresponding part of the final exam

13

Page 14: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Form and Resources

• Lectures

• Exercises

• Labs (optional)

• Midterms

• Webpage (many links, news etc)

• Literature:

• Swe: Lennart Salling. Formella språk,

automater och beräkningar

• Eng: Linz, An Introduction to Formal

Languages and Automata

14

Page 15: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

15

Mathematical Preliminaries

Page 16: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

16

• Sets

• Functions

• Relations

• Proof Techniques

• Languages, Alphabets and Strings

• Strings & String Operations

• Languages & Language Operations

Page 17: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

17

}3,2,1{A

A set is a collection of elements

SETS

},,,{ airplanebicyclebustrainB

We write

A1

Bship

Page 18: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

18

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 19: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

19

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

Universal Set: All possible elements

U = { 1 , … , 10 }

1 2 3

4 5

A

U

6

7

8

910

Page 20: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

20

Set Operations

A = { 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 21: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

21

• Complement

Universal set = {1, …, 7}

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

12

3

4

5

6

7

AA

A = A

Page 22: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

22

{ even integers } = { odd integers }

02

4

6

1

3

5

7

even

odd

Integers

Page 23: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

23

DeMorgan’s Laws

A U B = A BU

A B = A U B

U

Page 24: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

24

Empty, Null Set:

= { }

S U = S

S =

S - = S

- S =

U = Universal Set

Page 25: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

25

Subset

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

A B

U

Proper Subset: A B

U

A

B

Page 26: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

26

Disjoint Sets

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

A B = U

A B

Page 27: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

27

Set Cardinality

For finite sets

A = { 2, 5, 7 }

|A| = 3

Page 28: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

28

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 29: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

29

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 30: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

30

PROOF TECHNIQUES

• Proof by construction

• Proof by induction

• Proof by contradiction

Page 31: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

31

Proof by 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 32: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

32

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 33: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

33

Inductive Proof

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 34: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

34

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 35: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

35

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 36: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

36

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 37: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

37

Induction Step

hypothesis: L(n) 2n

Level

n

n+1

Page 38: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

38

hypothesis: L(n) 2n

Level

n

n+1

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

Induction Step

END OF PROOF

Page 39: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

39

Proof of induction: The cardinality of the powerset

Claim: A set of n elements

has 2n subsets

Check:

• The empty set {} has only one subset: {}.

• The set {a} (a set with exactly one element) has two

subsets: {} och {a}

Page 40: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

40

Påstående: En mängd med n element

har 2n delmängder

Check (cont.)

• The set of two elements {a, b} has four subsets:

{}, {a}, {b} and {a,b}

• The set {a, b, c} has eight subsets:

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

The claim holds for these basic cases.

Page 41: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

41

Base Case

The simplest case is a set with no elements

(there is just one such set), which has 20 = 1

subsets.

Page 42: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

42

Induction step

Suppose that the claim holds for all sets with k

elements, i.e., suppose that every set with k

elements has 2k subsets.

Show that the claim in this case holds also for all

sets with k+1 elements, i.e., show that every

set with k+1 elements has 2k+1 subsets.

Page 43: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

43

Consider an arbitrary set with k+1 elements. The subsets

of this set can be divided into two groups:

Subsets which does not contain the k+1:th element: Such

a subset is a subset to the set of the k original elements,

and the cardinality of subsets to a set of k elements is

(according to the inductive hypothesis) 2k.

Page 44: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

44

Subsets containing the k+1:th element: Such a subset can be

constructed by taking any set not containing the k+1th element and

add the k+1th element. Since there are 2k subsets without the

k+1th element (by hypothesis), it is also possible to create 2k

subsets including this element.

In total there are 2k + 2k = 2. 2k= 2k+1 subsets to the considered set.

END OF PROOF

(Exemple taken from the book: Diskret matematik och diskreta modeller,

K Eriksson, H. Gavel)

Page 45: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

45

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 46: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

46

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 47: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

47

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 = n22

END OF PROOF

Page 48: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

48

Countable Sets

Page 49: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

49

Infinite sets are either

Countable or Uncountable

Page 50: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

50

Countable set

There is a one to one correspondence

between elements of the set

and natural numbers

Page 51: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

51

We started with the natural numbers, then

• add infinitely many negative whole numbers to

get the integers,

• then add infinitely many rational fractions to get

the rationals,

• then added infinitely many irrational fractions to

get the reals.

Each infinite addition seem to increase

cardinality: |N| < |Z| < |Q| < |R|

But is this true? NO!

Page 52: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

52

Example

Integers: ,2,2,1,1,0

The set of integers is countable

Correspondence:

Natural numbers: ,4,3,2,1,0

oddnnevennnnf 2/)1(;2/)( {

Page 53: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

53

ExampleThe set of rational numbers

is countable

Positive

Rational numbers:,

8

7,

4

3,

2

1

Page 54: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

54

Naive Idea

Rational numbers: ,3

1,

2

1,

1

1

Natural numbers:

Correspondence:

,3,2,1

Doesn’t work!

we will never count

numbers with nominator 2:,

3

2,

2

2,

1

2

Page 55: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

55

Better Approach

1

1

2

1

3

1

4

1

1

2

2

2

3

2

1

3

2

3

1

4

...

...

...

...

Rows: constant numerator (täljare)

Columns: constant denominator

Page 56: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

56

1

1

2

1

3

1

4

1

1

2

2

2

3

2

1

3

2

3

1

4

...

...

...

...

Page 57: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

57

We proved:

the set of rational numbers is countable

by describing an enumeration procedure

Page 58: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

58

Definition

An enumeration procedure for is an

algorithm that generates

all strings of one by one

Let be a set of strings S

S

S

Page 59: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

59

A set is countable if there is an

enumeration procedure for it

Observation

Page 60: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

60

Example

The set of all finite strings

is countable

},,{ cba

We will describe the enumeration procedure

Proof

Page 61: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

61

Naive procedure:

Produce the strings in lexicographic order:

a

aaaaa

......

Doesn’t work!

Strings starting with will never be produced b

aaaa

Page 62: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

62

Better procedure

1. Produce all strings of length 1

2. Produce all strings of length 2

3. Produce all strings of length 3

4. Produce all strings of length 4

..........

Proper Order

Page 63: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

63

Produce strings in

Proper Order

aa

abacba

bb

bcca

cbcc

aaaaabaac......

length 2

length 3

length 1abc

Page 64: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

64

Theorem

The set of all finite strings is countable

Proof

Find an enumeration procedure

for the set of finite strings

Any finite string can be encoded

with a binary string of 0’s and 1’s

Page 65: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

65

Produce strings in Proper Order

length 2

length 3

length 10

1

00

01

10

11

000

001

….

0

1

2

3

4

5

6

7

….

String = program Natural number

Page 66: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

66

PROGRAM = STRING (syntactic way)

PROGRAM = FUNCTION (semantic way)

PROGRAMstring string

PROGRAM

natural

number

n

natural

number

n

Page 67: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

67

Uncountable Sets

Page 68: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

68

A set is uncountable if it is not countable

Definition

Page 69: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

69

Theorem

The set of all infinite strings is

uncountable

We assume we have

an enumeration procedure

for the set of infinite strings

Proof (by contradiction)

Page 70: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

70

Infinite string Encoding

0w

1w

2w

...

...

...

...

00b

10b

20b

01b

11b

21b

02b

12b

22b

=

=

=

Cantor’s diagonal argument

... ... ... ...

Page 71: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

71

Cantor’s diagonal argument

We can construct a new string

that is missing in our enumeration!w

The set of all infinite strings is

uncountable!

Conclusion

Page 72: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

72

There are some integer functions that

that cannot be described by finite strings

(programs/algorithms).

Conclusion

An infinite string can be seen as FUNCTION (n:th

output is n:th bit in the string)

Page 73: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

73

Theorem

Let be an infinite countable set

The powerset of is uncountableS2 S

S

Example of uncountable infinite sets

Page 74: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

74

Proof

Since is countable, we can write S

},,,{ 321 sssS

Page 75: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

75

Elements of the powerset have the form:

},{ 31 ss

},,,{ 10975 ssss

……

Page 76: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

76

We encode each element of the power set

with a binary string of 0’s and 1’s

1s 2s 3s 4s

1 0 0 0}{ 1s

Powerset

element

Encoding

0 1 1 0},{ 32 ss

1 0 1 1},,{ 431 sss

...

...

...

...

Page 77: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

77

Let’s assume (by contradiction)

that the powerset is countable.

we can enumerate

the elements of the powerset

Then:

Page 78: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

78

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

Powerset

elementEncoding

1p

2p

3p

4p

...

...

...

...

...

Page 79: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

79

Take the powerset element

whose bits are the complements

in the diagonal

Page 80: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

80

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

New element: 0011

(binary complement of diagonal)

...

...

...

...

1p

2p

3p

4p

Page 81: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

81

The new element must be some

of the powerset

ip

However, that’s impossible:

the i-th bit of must be

the complement of itself

from definition of

Contradiction!

ip

ip

Page 82: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

82

Since we have a contradiction:

The powerset of is uncountable S2 S

END OF PROOF

Page 83: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

83

Example Alphabet : },{ ba

The set of all finite strings:

},,,,,,,,,{},{ * aabaaabbbaabaababaS

infinite and countable

uncountable infinite

}},,,}{,{},{},{{2 aababaabaaS

1L 2L 3L 4L

The powerset of contains all languages:S

An Application: Languages

Page 84: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

84

Finite strings (algorithms): countable

Languages (power set of strings): uncountable

There are infinitely many more languages

than finite strings.

Page 85: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

85

There are some languages

that cannot be described by finite strings

(algorithms).

Conclusion

Page 86: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

86

Cardinality - Kardinaltal

A Cardinal number is a measure of the size of a set. The cardinality for a finite set is simply the number of elements in the set.

Two sets has equal size if it is possible to pair the elements one by one in the two sets. That is, if there exists a bijection between the two sets.

This concept can be generalised to infinite sets. For instance, the set of positive integers and the set of integers have equal size.

On the contrary, it is not possible to pair the real numbers with the integers in this fashion. The set of real numbers is larger than the set of integers.

Cardinal numbers can be defined as in the following way: two sets have the same cardinal number if and only if they have the same size (i.e., can be paired together one and one). As an example, the cardinal number for the integers is 0 (alef-0, alef is the first letter in the hebrew alphabet).

These infinite cardinal numbers are called transfinite cardinal numbers.

Page 87: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

87

Georg Cantor developed, in the end of the 19th century, the logical

foundation of mathematics: set theory.

Cantor introduced the notion transfinite cardinal numbers.

The simplest, ”smallest", infinity, he named 0.

This is the countable infinite sets’ (for instance, the integers) cardinal

number.

The cardinality of the set of points on a line, or the points in a plane or

field, Cantor named 1.

Are there ”larger” infinities?

More about Infinty

Page 88: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

88

Yes! Cantor showed that the set of functions on a line

was ”even more infinite” than the points on the line,

and he called that cardinality 2.

Cantor discovered that it was possible to use

artithmetic on cardinal numbers just as with finite

numbers. But the arithmetic rules became quite

simplistic:

0 + 1= 0 0 + 0 = 0 0 · 0 = 0.

Page 89: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

89

However, with powers something happened:

0 0 ( 0 to the power of 0) = 1.

In general:

2 n (2 to the power of n) = n+1

This implies that there are infinitly many infinities, in

strictly increasing order.

Page 90: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

90

But is it really certain that there is no cardinality in between the countable infinity and the points on the line? Cantor tried to prove the so-called continuum hypothesis.

Cantor: two different infinities 0 and 1

http://www.ii.com/math/ch/#cardinals

Continuum Hypothesis: 0 < 1 = 2 0

See also:

http://www.nyteknik.se/pub/ipsart.asp?art_id=26484

Page 91: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

CD5560CD5560

FABER

Formal Languages, Automata and Models of Computationand Models of Computation

Lecture 2

Mälardalen University2010

1

Page 92: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

ContentLanguages, Alphabets and Stringsg g , p g

Strings & String OperationsLanguages & Language OperationsLanguages & Language Operations

Regular ExpressionsFinite Automata, FADeterministic Finite Automata, DFA

2

Page 93: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Languages,Languages, Alphabets and

Strings

3

Page 94: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Languages

A language is a set of strings

d fi d l h bA String is a sequence of letters

defined over an alphabet:

{ }{ }zcba ,,,, K=Σ

An alphabet is a set of symbols

4

Page 95: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Alphabets and Strings

We will use small alphabets: { }ba,=Σp

Strings

{ },

ba

Strings

bbbaaavabu =ab

abbawbbbaaav==

b babba

abbaw =

baaabbbaabababa

5baaabbbaaba

Page 96: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Operations on StringsOperations on Strings

6

Page 97: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

String Operations

naaaw L21= x = abbam

nbbbv L21

21= y = bbbaaa

x abba

Concatenation (sammanfogning)

bbbaaawv =

Concatenation (sammanfogning)

mn bbbaaawv LL 2121=

bb bbbxy = abbabbbaaa

7

Page 98: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Reverse (reversering)Reverse (reversering)

naaaw L21= ababaaabbb

12aaaw nR L= bbbaaababa12n bbbaaababa

Example:Longest odd length palindrome in a natural language:g g p g g

saippuakauppias (Finnish: soap sailsman)

8

(Finnish: soap sailsman)

Page 99: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

String LengthString Length

naaaw L21=nw =Length: nw =Length:

Examples:

4=abbaExamples:

2=aa1=a

9

Page 100: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Recursive Definition of LengthRecursive Definition of Length

F l tt 1For any letter: 1=a

For any string : 1+= wwawa

Example: 1+= abbabba

11111 +++=++= aab41111 =+++=

10

Page 101: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Length of Concatenation

vuuv +=

3== uaabuExample:

53,== vabaabv

uaabuExample:

5, vabaabv

8538== aababaabuv

853 =+=+= vuuv

11

Page 102: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Proof of Concatenation Length

Claim: vuuv +=Claim: vuuv +=

Proof: By induction on the length v

Induction basis: 1=vFrom definition of length:

vuuuv +=+= 1 vuuuv +=+= 1

12

Page 103: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

I d i h h i +Inductive hypothesis:

vuuv +=

f nv ≤for

Inductive step: we will prove

vuuv +=

1+= nvfor

13

Page 104: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Inductive StepWrite , wherewav = 1, == anw

From definition of length: 1+== uwuwauv1+= wwa

From inductive hypothesis: wuuw +=

1Thus: vuwauwuuv +=+=++= 1

14END OF PROOF

Page 105: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Empty StringEmpty String

A string with no letters: (Also denoted as ε)

λ( )

Observations: 0λObservations: 0

λλ

λ

==

=

wwwλλ

∅== abbaabbaabba

}{{} λ≠=∅

15

Page 106: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Substring (delsträng)Substring of a string:

a subsequence of consecutive charactersa subsequence of consecutive characters

String SubstringString Substring

ababbab

babbaabbab

bbabb

bb babbab

16bbababbab

Page 107: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Prefix and Suffix

Suffixesabbab

Prefixes Suffixes

λ abbab uvw =Prefixes

bbabfi

ab babprefix

suffixabb ab

suffix

abbaλb

17abbab λ

Page 108: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Repetitionn www... w =

n (String repeated n times)w

Example: ( ) abbaabbaabba =2p

Definition:

( )

λ0Definition: λ=0w

( )0( ) λ=0abba

18

Page 109: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Th (Kl * t ) O tiThe (Kleene* star) Operation

the set of all possible strings from alphabet *Σ Σ

{ }bΣ { }{ }*

,aabaaabbbaabaaba

baλ=Σ

=Σ{ }K,,,,,,,,,* aabaaabbbaabaabaλ=Σ

[* Kleene is pronounced "clay-knee“]

19http://en.wikipedia.org/wiki/Kleene_star

Page 110: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

The + (Kleene plus) Operation( p ) p

: the set of all possible strings from the+Σ galphabet except Σ λ

{ },ba=Σ{ }K,,,,,,,,,* aabaaabbbaabaabaλ=Σ

λ−Σ=Σ+ *

{ }K,,,,,,,, aabaaabbbaabaaba=Σ+

20

Page 111: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

{ }, fyoj=Σ , usch

{}

* λ, oj, fy, usch, ojoj, =Σ}Kfyfy,uschusch, ojfy, ojusch

λ−Σ=Σ+ *{

}oj, fy, usch, ojoj, fyfy,uschusch,

f h=Σ+

}Kojfy, ojusch

21

Page 112: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Operations on LanguagesOperations on Languages

22

Page 113: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

LanguageA language is any subset of *Σ

Example: { },ba=Σ { }{ }K,,,,,,,,*

,aaabbbaabaabaλ=Σ

Languages:{ }λ{ }{ }aabaaaλ{ }

}{,,

aaaaaaabaababaabbaaabaaa

λ23

},,,,,{ aaaaaaabaababaabbaλ

Page 114: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

An infinite language }0:{ ≥= nbaL nnAn infinite language }0:{ ≥= nbaL

λ

Labb∉ab L∈

bbbbbaabbaaaaabbbbb

24

Page 115: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Operations on LanguagesThe usual set operations

{ } { }{ } { } bbbbb

aaaabbabaabbbaaaaaba}{

},,,{,,, =∪{ } { }{ } { } { }aaaaaabbbaaaaaba

ababbbaaaaaba,,,,

}{,,,=−=∩

{ } { } { },,,,

LL −Σ= *Complement:

{ }K,,,,,,,,,* aabaaabbbaabaabaλ=ΣLL Σp

{ } { }K,,,,,,, aaabbabaabbaa λ=25

Page 116: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Reverse

}:{ LwwL RR ∈=Definition:

}:{ LwwL ∈=

Examples:

{ } { }ababbaabababaaabab R ,,,, =Examples:

{ } { }

}0:{ ≥= nbaL nn

}0:{}{

≥= nabL nnR }0:{ ≥nabL

26

Page 117: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

ConcatenationCo cate at o

Definition: { }2121 ,: LyLxxyLL ∈∈=

Example

{ }{ }aabbaaba ,,,Example

{ }{ }{ }baaabababaaabbaaaab

aabbaaba,,,,,

,,,= { },,,,,

27

Page 118: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

RepeatDefinition: 321Ln LLLL =

n

{ } { }{ }{ }bbbb 3{ } { }{ }{ }{ }bbbbbababbaaabbabaaabaaa

babababa ,,,, 3 ==

Special case:

{ }bbbbbababbaaabbabaaabaaa ,,,,,,,Special case: { }λ=0L

{ } { }λ=0,, aaabbaa28

Page 119: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

nn }0:{ ≥= nbaL nn

}0{2 bb mmnn }0,:{2 ≥= mnbabaL mmnn

2Lbb bbb 2Laabbaaabbb∈

29

Page 120: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Star-Closure (Kleene *)

Definition:Definition:L210* LLLL ∪∪=

Example:Example:

⎪⎫

⎪⎧ ,λ

{ } ⎪⎪⎬

⎪⎪⎨=

,,*,

bbbbbbbbbba

bba{ }

⎪⎪⎭

⎪⎪⎩

⎨ ,,,,abbbbabbaaabbaaa

bbbbbbaabbaa

30

⎪⎭⎪⎩ K,,,, abbbbabbaaabbaaa

Page 121: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Positive ClosureDefinition

+ 21

{ }λ−= *LL=+ 21 LLL UU

{ }λ= *L

⎪⎫

⎪⎧ ,,bba

{ }⎪

⎪⎬

⎪⎨=

+ ,,,,, bbbbbbaabbaabba⎪⎭⎪⎩ K,,,, abbbbabbaaabbaaa

31

Page 122: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Regular ExpressionsRegular Expressions

32

Page 123: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Regular Expressions: R i D fi itiRecursive Definition

λ∅ αλ,,∅Primitive regular expressions:

2rGiven regular expressions and1r

21 rr +2rGiven regular expressions and 1r

21

21rrrr

⋅+

1

21*r

are Regular Expressions

( )1r33

Page 124: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Examples

( ) )(* ∅+⋅⋅+ ccbaA regular expression: ( ) )( ∅+⋅⋅+ ccbaA regular expression:

( )++ baNot a regular expression:

34

Page 125: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Building Regular Expressions

{ }cba=ΣBuilding Regular Expressions

Zero or more

{ }cba ,,=Σ

Zero or more. a* means "zero or more a's."

To say "zero or more ab's," that is, y , ,{, ab, abab, ababab, ...}, you need to say (ab)*.

ab* denotes {a, ab, abb, abbb, abbbb, ...}.

35

Page 126: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Building Regular Expressions{ }cba ,,=Σ

Building Regular Expressions

One or more

{ },,

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)*{ab, abab, ababab, ...}, you can use ab(ab) .

36

Page 127: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Building Regular Expressions

{ }cba ,,=Σ

Any string at all. To describe any string at all (with = {a b c}) you canTo 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)*.

37

Page 128: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Building Regular Expressions{ }cba ,,=Σ

g g p

Any string not containing....To describe any string at all that doesn't contain an aTo 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 y g y , p"any string not containing an a," on either side of the a, like this: (b+c)*a(b+c)*. , ( ) ( )

38

Page 129: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Languages of Regular Expressions

( )( )rL rlanguage of regular expression

Example

( ) { },...,,,,,*)( bcaabcaabcacbaL λ=⋅+

39

Page 130: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

DefinitionDefinition

For primitive regular expressions:

( )L ∅∅( )L ∅=∅

( ) { }L = λλ( ) { }

( ) { }aaL =

40

Page 131: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Definition (continued)e t o (co t ued)

For regular expressions and1r 2r

( ) ( ) ( )2121 rLrLrrL ∪=+

( ) ( ) ( )( ) ( ) ( )2121 rLrLrrL =⋅

( ) ( )( )( ) ( )( )** 11 rLrL =

( )( ) ( )( )( ) ( )11 rLrL =

41

Page 132: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example( ) *b+( ) *aba ⋅+Regular expression:

( )( )*abaL ⋅+ ( )( ) ( )*aLbaL +=

( ) ( )( ) ( )*aLbaL +=

( ) ( )( ) ( )( )*LbLL( ) ( )( ) ( )( )*aLbLaL ∪=

{ } { }( ) { }( )*b∪{ } { }( ) { }( )*aba ∪=

{ }{ }aaaaaaba λ= { }{ },...,,,, aaaaaaba λ=

{ }baababaaaaaa=42

{ },...,,,...,,, baababaaaaaa=

Page 133: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

Regular expression

( ) ( )bbabar ++= *

( ) { }bbbbaabbaabbarL =( ) { },...,,,,, bbbbaabbaabbarL =

43

Page 134: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

Regular expressionRegular expression

( ) ( ) bbbaar **= ( ) ( ) bbbaar =

( ) }0,:{ 22 ≥= mnbbarL mn( ) },{

44

Page 135: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Examplep

{ }1,0=Σ { },

)(rL = { all strings with at leasttwo consecutive 0 }two consecutive 0 }

Regular expression

*)10(00*)10( *)10(00*)10( ++=r

45

Page 136: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

{ }1,0=Σ

)(rL = { all strings without

{ }1,0Σ

)(rL = { all strings withouttwo consecutive 0 }

Regular expression

)0(*)011(1 λ++=r(consists of repeating 1’s and 01’s).

46

Page 137: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

ExampleL = { all strings without

t ti 0 }two consecutive 0 }

Equivalent solution:

)0(*1)0(**)011*1(2 λλ +++=r

Equivalent solution:

)0(1)0()0111(2 λλ +++=r

( d 00 i i f h 0 h b 1(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 accountare 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.)

47

p )

Page 138: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Equivalent Regular Expressions

Definition:

Regular expressions andr rRegular expressions and1r 2r

)()( 21 rLrL =are equivalent if

48

Page 139: Formal Languages, Automata and Models of Computation · Formal Languages, Automata and Models of Computation ... 1950 automata 1956 language ... An Introduction to Formal Languages

Example

L = { all strings withouttwo consecutive 0 }

)(*)(**)*( λλ)0(*)011(1 λ++=r

)0(*1)0(**)011*1(2 λλ +++=r

LrLrL == )()( 21 1r 2randLrLrL )()( 21 1 2are equivalentregular expressions

49regular expressions.