1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?

59
1 Turing Machines
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    219
  • download

    0

Transcript of 1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?

1

Turing Machines

2

The Language Hierarchy

*aRegular Languages

Context-Free Languagesnnba Rww

nnn cba ww?

**ba

?

3

*aRegular Languages

Context-Free Languagesnnba Rww

nnn cba ww

**ba

Languages accepted byTuring Machines

4

A Turing Machine

............Tape

Read-Write headControl Unit

5

The Tape

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

Read-Write head

No boundaries (infinite length)

• The head moves Left or Right

6

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

Read-Write head

The head at each time step:

1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right

7

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

Example:Time 0

............Time 1

1. Reads

2. Writes

a a cb

a b k c

a

k

3. Moves Left

8

............Time 1

a b k c

............Time 2

a k cf

1. Reads

2. Writes

b

f

3. Moves Right

9

The Input String

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

Blank symbol

head

a b ca

10

The States

1q 2qLba ,

read write move Left

1q 2qRba ,

move Right

11

Example:

1q 2qRba ,

............ a b ca

Time 1

1qcurrent state

12

............ a b caTime 1

1q 2qRba ,

............ a b cbTime 2

1q

2q

13

............ a b caTime 1

1q 2qLba ,

............ a b cbTime 2

1q

2q

Example:

14

............ a b caTime 1

1q 2qRg,

............ ga b cbTime 2

1q

2q

Example:

15

Determinism

1q

2qRba ,

OK NOT ALLOWED

3qLdb ,

1q

2qRba ,

3qLda ,

•For a read symbol only one transition is allowed

•No lambda transitions allowed

16

Partial Transition Function

1q

2qRba ,

3qLdb ,

............ a b ca

1q

Example:

No transitionfor input symbol c

OK

17

Halting

The machine halts if there are no possible transitionsto take

18

Example:

............ a b ca

1q

1q

2qRba ,

3qLdb ,

No possible transition

HALT!!!

19

Final States

1q 2q OK

1q 2q NOT ALLOWED

• Final states have no outgoing transitions

• In a final state the machine halts

20

Acceptance

Accept Input If machine halts in a final state

Reject Input • If machine halts in a non-final state

• If machine enters an infinite loop

21

Turing Machine Example

A turing machine for the language *aa

0q

Raa ,

L,1q

22

0q

Raa ,

L,1q

aaTime 0

0q

a

230q

Raa ,

L,1q

aaTime 0

0q

a

aaTime 1

0q

a

240q

Raa ,

L,1q

aaTime 1

0q

a

aaTime 2

0q

a

250q

Raa ,

L,1q

aaTime 2

0q

a

aaTime 3

0q

a

260q

Raa ,

L,1q

aaTime 3

0q

a

aaTime 4

1q

a

HALT & accept

27

Rejection Example

0q

Raa ,

L,1q

baTime 0

0q

a

280q

Raa ,

L,1q

baTime 0

0q

a

baTime 1

0q

a

HALT & reject

29

Infinite Loop Example

0q

Raa ,

L,1q

Lbb ,

Turing machine for the language *aa

30

0q

Raa ,

L,1q

baTime 0

0q

a

Lbb ,

310q

Raa ,

L,1q

baTime 0

0q

a

baTime 1

0q

a

Lbb ,

320q

Raa ,

L,1q

baTime 1

0q

a

baTime 2

0q

a

Lbb ,

33

baTime 2

0q

a

baTime 3

0q

a

baTime 4

0q

a

baTime 5

0q

a

...Infinite Loop

34

Because of the infinite loopthe final state cannot be reachedand the input is not accepted

35

Another Turing Machine Example

0q

Turing machine for the language }{ nnba

1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

R,

36

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

ba

0q

a b

Time 0

bx

1q

a b

Time 1

37

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b

Time 1

bx

1q

a b

Time 2

38

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b

Time 2

yx

2q

a b

Time 3

39

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b

Time 3

yx

2q

a b

Time 4

40

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b

Time 4

yx

0q

a b

Time 5

41

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

a b

Time 5

yx

1q

x b

Time 6

42

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b

Time 6

yx

1q

x b

Time 7

43

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b

Time 7

yx

2q

x yTime 8

44

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

x yTime 8

yx

2q

x yTime 9

45

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

x yTime 9

yx

2q

x yTime 10

46

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

x yTime 10

yx

3q

x yTime 11

47

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x yTime 11

yx

3q

x yTime 12

48

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x yTime 12

yx

4q

x yTime 13

HALT & accept

49

By modifying the machine for the language }{ nnba

we can easily construct a machine for language }{ nnn cba

50

Formal Definitionsfor

Turing Machines

51

Transition Function:

1q 2qRba ,

),,(),( 21 Rbqaq

1q 2qLdc ,

),,(),( 21 Ldqcq

52

Turing Machine:

),,,,,,( 0 FqQM

states

Inputalphabet

Tapealphabet

Transitionfunction

Initialstate

blank

Finalstates

53

Configuration

ba

1q

a

Instantaneous description:

c

baqca 1

54

yx

2q

a b

Time 4

yx

0q

a b

Time 5

A move: aybqxxaybq 02

55

yx

2q

a b

Time 4

yx

0q

a b

Time 5

bqxxyybqxxaybqxxaybq 1102

yx

1q

x b

Time 6

yx

1q

x b

Time 7

56

bqxxyybqxxaybqxxaybq 1102

bqxxyxaybq 12

Equivalent notation:

57

Initial configuration: wq0

ba

0q

a b

w

Input string

58

The Accepted Language

For any Turing Machine M

}:{)( 210 xqxwqwML f

Initial state Final state

59

Standard Turing Machine

• Deterministic

• Infinite tape in both directions

•Tape is the input/output file

The machine we described is the standard: