Fundamentele Informatica 1 (I&E) najaar 2011 - - PowerPoint PPT Presentation

fundamentele informatica 1 i e
SMART_READER_LITE
LIVE PREVIEW

Fundamentele Informatica 1 (I&E) najaar 2011 - - PowerPoint PPT Presentation

Fundamentele Informatica 1 (I&E) najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 13, maandag 5 december 2011 (laatste college!) 7. Turing Machines 1 reg. languages reg. grammar FA reg.


slide-1
SLIDE 1

Fundamentele Informatica 1 (I&E)

najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 13, maandag 5 december 2011 (laatste college!)

  • 7. Turing Machines

1

slide-2
SLIDE 2
  • reg. languages
  • reg. grammar

FA

  • reg. expression
  • cf. languages
  • cf. grammar

PDA TM

2

slide-3
SLIDE 3
  • 7. Turing Machines

7.1. A General Model of Computation

3

slide-4
SLIDE 4

Assumptions about a human computer working with a pencil and paper:

  • 1. The only things written on the paper are symbols from some

fixed finite alphabet;

  • 2. Each step taken by the computer depends only on the symbol

he is currently examining and on his “state of mind” at the time;

  • 3. Although his state of mind may change as a result of his ex-

amining different symbols, only a finite number of distinct states

  • f mind are possible.

4

slide-5
SLIDE 5

Actions of a human computer on a sheet of paper:

  • 1. Examining an individual symbol on the paper;
  • 2. Erasing a symbol or replacing it by another;

3. Transferring attention from one symbol to another nearby symbol.

5

slide-6
SLIDE 6

Turing machine Turing machine has a finite alphabet of symbols. (actually two alphabets. . . ) Turing machine has a finite number of states. Turing machine has a tape for reading input, as workspace, and for writing output (if applicable). Tape is linear, instead of 2-dimensional. Tape has a left end and is potentially infinite to the right. Tape is marked off into squares, each of which can hold one symbol. Tape head is centered on one square of the tape for reading and writing.

6

slide-7
SLIDE 7

A move of a Turing machine consists of:

  • 1. Changing from the current state to another, possibly different

state;

  • 2. Replacing the symbol in the current square by another, pos-

sibly different symbol; 3. Leaving the tape head on the current square, or moving it

  • ne square to the right, or moving it one square to the left if it

is not already on the leftmost square.

7

slide-8
SLIDE 8

Just like FA and PDA, Turing machine

  • may be used to accept a language
  • has a finite number of states

Unlike FA and PDA, Turing machine

  • may also be used to compute a function ∗
  • is not restricted to reading input left-to-right ∗
  • does not have to read all input ∗
  • does not have a set of accepting states, but has two halt states:
  • ne for acceptance and one for rejection (in case of computing

a function, . . . )

  • may decide not to halt

∗ = just like human computer

8

slide-9
SLIDE 9

7.2. Turing Machines as Language Acceptors

Example 7.3. A TM Accepting a Regular Language L = {a, b}∗{ab}{a, b}∗ ∪ {a, b}∗{ba} First a finite automaton, then a Turing machine

9

slide-10
SLIDE 10

Example 7.3. A TM Accepting a Regular Language L = {a, b}∗{ab}{a, b}∗ ∪ {a, b}∗{ba} First a finite automaton, then a Turing machine This conversion works in general for FAs. As a result,

  • only moves to the right,
  • no modifications of symbols on tape,
  • no moves to the reject state, but . . .

In this case,

  • we could modify TM, so that it does not always read

entire input.

10

slide-11
SLIDE 11

Definition 7.1. Turing machines A Turing machine (TM) is a 5-tuple T = (Q, Σ, Γ, q0, δ), where Q is a finite set of states. The two halt states ha and hr are not elements of Q. Σ, the input alphabet, and Γ, the tape alphabet, are both finite sets, with Σ ⊆ Γ. The blank symbol ∆ is not an element of Γ. q0, the initial state, is an element of Q. δ is the transition function: . . .

11

slide-12
SLIDE 12

Definition 7.1. Turing machines A Turing machine (TM) is a 5-tuple T = (Q, Σ, Γ, q0, δ), where Q is a finite set of states. The two halt states ha and hr are not elements of Q. Σ, the input alphabet, and Γ, the tape alphabet, are both finite sets, with Σ ⊆ Γ. The blank symbol ∆ is not an element of Γ. q0, the initial state, is an element of Q. δ is the transition function: δ : Q × (Γ ∪ {∆}) → (Q ∪ {ha, hr}) × (Γ ∪ {∆}) × {R, L, S}

12

slide-13
SLIDE 13

Interpretation of δ(p, X) = (q, Y, D) If q is ha or hr, the move causes T to halt What if D = L and T is on square 0?

13

slide-14
SLIDE 14

Normally, TM starts with

  • input string starting in square 1 and all other squares blank,
  • and its tape head on square 0.

Tape always contains finite number of non-blanks.

14

slide-15
SLIDE 15

Notation: configuration xqy = xqy∆ = xqy∆∆ if y = Λ, then xq∆ description of tape contents: xσy or xy if y = Λ, then x∆ move: xqy ⊢T zrw xqy ⊢∗

T zrw

xqy ⊢ zrw xqy ⊢∗ zrw example: configuration aabqa∆a and δ(q, a) = (r, ∆, L) initial configuration corresponding to input x: q0∆x This notation does not have to be used at the exam. This slide is meant only to understand Definition 7.2 and Definition 7.9.

15

slide-16
SLIDE 16

Definition 7.2. Acceptance by a TM If T = (Q, Σ, Γ, q0, δ) is a TM and x ∈ Σ∗, x is accepted by T if q0∆x ⊢∗

T whay

for some strings w, y ∈ (Γ ∪ {∆})∗ (i.e., if, starting in the initial configuration corresponding to input x, T eventually halts in the accepting state). A language L ⊆ Σ∗ is accepted by T if T = L(T), where L(T) = {x ∈ Σ∗ | x is accepted by T }

16

slide-17
SLIDE 17

Example 7.5. A TM Accepting XX = {xx | x ∈ {a, b}∗}

17

slide-18
SLIDE 18

Exercise 7.4. For each of the following languages, draw a transition diagram for a Turing machine that accepts that language.

  • a. AnBn = {aibi | i ≥ 0}

18

slide-19
SLIDE 19

Exercise 7.4. For each of the following languages, draw a transition diagram for a Turing machine that accepts that language.

  • a. AnBn = {aibi | i ≥ 0}

We could also use the portion of the tape to the right of the input, to simulate the stack of a deterministic pushdown au- tomaton (works for any deterministic PDA!)

19

slide-20
SLIDE 20
  • Exercise. Draw a transition diagram for a Turing machine that

accepts AnBnCn = {aibici | i ≥ 0}

20

slide-21
SLIDE 21

Example 7.7. Accepting L = {aibaj | 0 ≤ i < j} To illustrate that a Turing machine T may run forever for an input that is not in L(T). No problem!

21

slide-22
SLIDE 22

7.3. Turing Machines That Compute Partial Functions

Definition 7.9. A Turing Machine Computing a Function Let T = (Q, Σ, Γ, q0, δ) be a Turing machine, k a natural number, and f a partial function on (Σ∗)k with values in Γ∗. We say that T computes f if for every (x1, x2, . . . , xk) in the domain of f, q0∆x1∆x2∆ . . . ∆xk ⊢∗

T ha∆f(x1, x2, . . . , xk)

and no other input that is a k-tuple of strings is accepted by T. A partial function f : (Σ∗)k → Γ∗ is Turing-computable, or simply computable, if there is a TM that computes f.

22

slide-23
SLIDE 23

Example 7.10. The Reverse of a String Study this example yourself.

23

slide-24
SLIDE 24

Example 7.12. The Quotient and Remainder Mod 2

24

slide-25
SLIDE 25

Exercise. Draw a TM that computes the function f(x, y) = x + y where x, y are integers ≥ 0. Assume that the TM uses unary notation, both for its input and for its output.

25

slide-26
SLIDE 26

Exercise 7.17. For each case below, draw a TM that computes the indicated function. In the first five parts, the function is from N to N. In each of these parts, assume that the TM uses unary notation — i.e., the natural number n is represented by the string 1n.

  • b. f(x) = 2x
  • c. f(x) = x2

26