Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE S. Tanimoto Turing Completeness

Similar presentations


Presentation on theme: "CSE S. Tanimoto Turing Completeness"— Presentation transcript:

1 CSE 341 -- S. Tanimoto Turing Completeness
Relevance to programming languages: How can we measure the generality of a language? (One answer: by determining whether or not the language is “Turing complete.”) Historical perspective. Examples of Turing Machines. Formal definition of Turing Machines. Formal definition of Turing Completeness. Applying Turing Completeness. CSE S. Tanimoto Turing Completeness

2 Historical Perspective
In the 1940s, Alan Turing and Emil Post were investigating the question of which mathematical functions are theoretically computable by mechanical devices. One question they faced: “What is a computable function?” Are all mathematical functions computable? (Answer: no) Formal models of computers and computation... CSE S. Tanimoto Turing Completeness

3 CSE 341 -- S. Tanimoto Turing Completeness
The Turing Machine Turing proposed an abstract model of a mechanical computing device, a sort of “tape automaton” with ability to read and write symbols on the tape and move the tape left and right. We now call it a Turing Machine in Turing’s honor. CSE S. Tanimoto Turing Completeness

4 Turing Machine Example 1
Task: compute the parity of a sequence of bits. Parity of a bit sequence: the exclusive-or of the bits. finite control read/write head 1 1 1 $ tape CSE S. Tanimoto Turing Completeness

5 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) Tape alphabet: { 0, 1, $, Blank } Actions: { Left, Right, Halt } Left = move tape head left, relative to the tape. Right = “ “ “ right, “ “ “ “ . Halt = stop the Turing machine. 1 1 1 $ CSE S. Tanimoto Turing Completeness

6 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) Set of possible states for the finite control: S0: initial state; parity so far is 0. S1: parity so far is 1. Transition function: “Whenever the current tape symbol is a 1, change state, leave the symbol as it is, and move the head to the right (relative to the tape). If the current symbol is $, move right without changing state. If the current symbol is Blank, and the state is S0, write 0 and halt, but if the current state is S1, write 1 and halt.” S0 1 1 1 $ CSE S. Tanimoto Turing Completeness

7 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ CSE S. Tanimoto Turing Completeness

8 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S0 1 1 1 $ CSE S. Tanimoto Turing Completeness

9 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S0 1 1 1 $ CSE S. Tanimoto Turing Completeness

10 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ CSE S. Tanimoto Turing Completeness

11 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ CSE S. Tanimoto Turing Completeness

12 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ CSE S. Tanimoto Turing Completeness

13 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ CSE S. Tanimoto Turing Completeness

14 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 1 (cont) S1 1 1 1 $ 1 Halt! CSE S. Tanimoto Turing Completeness

15 Turing Machine Example 2
Compute the function f(n) = n + 1. To make this easy, let’s assume that n is represented on the tape in unary notation. Tape alphabet = { 1, Blank }, States = { S0 }. Transition function: “If the current tape symbol is 1, move right, leaving the symbol unchanged. If the current tape symbol is Blank, write a 1 and halt.” S0 1 1 1 1 1 1 1 CSE S. Tanimoto Turing Completeness

16 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 2 (Cont) S0 1 1 1 1 1 1 1 CSE S. Tanimoto Turing Completeness

17 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 2 (Cont) . . . 1 1 1 1 1 1 1 CSE S. Tanimoto Turing Completeness

18 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 2 (Cont) S0 1 1 1 1 1 1 1 CSE S. Tanimoto Turing Completeness

19 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 2 (Cont) S0 Halt! 1 1 1 1 1 1 1 1 CSE S. Tanimoto Turing Completeness

20 Turing Machine Example 3
Task: Determine whether or not the input string is a palindrome. S0 ^ M A D A M $ CSE S. Tanimoto Turing Completeness

21 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) Tape alphabet: { A, D, M, ^, $, Blank } ^: left end marker, $: right end marker States: { S0, S1, S2, S3, S4, S5, S6, S7 } S0: initial state, S1: moving R to find A, S2: moving R to find D, S3: moving R to find M, S4: stepping left for A, S5: stepping left for D, S6: stepping left for M, S7: homing -- moving left to find ^ CSE S. Tanimoto Turing Completeness

22 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) Transition function: Cur. State Cur. Sym. New Sym. Next State Move S0 A ^ S R S0 D ^ S R S0 M ^ S R S0 ^ ^ S R S0 $ Accept S1 $ $ S L S1 * no-change S R S2 $ $ S L S2 * no-change S R S3 $ $ S L S3 * no-change S R CSE S. Tanimoto Turing Completeness

23 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) Transition function, continued: Cur. State Cur. Sym. New Sym. Next State Move S4 A $ S L S4 ^ Accept S4 * Reject S5 D $ S L S5 ^ Accept S5 * Reject S6 M $ S L S6 ^ Accept S6 * Reject S7 ^ ^ S R S7 * no-change S L CSE S. Tanimoto Turing Completeness

24 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S0 ^ M A D A M $ CSE S. Tanimoto Turing Completeness

25 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S3 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

26 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S3 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

27 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S3 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

28 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S3 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

29 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S3 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

30 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S6 ^ ^ A D A M $ CSE S. Tanimoto Turing Completeness

31 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ A D A $ $ CSE S. Tanimoto Turing Completeness

32 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ A D A $ $ CSE S. Tanimoto Turing Completeness

33 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ A D A $ $ CSE S. Tanimoto Turing Completeness

34 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ A D A $ $ CSE S. Tanimoto Turing Completeness

35 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S0 ^ ^ A D A $ $ CSE S. Tanimoto Turing Completeness

36 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S1 ^ ^ ^ D A $ $ CSE S. Tanimoto Turing Completeness

37 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S1 ^ ^ ^ D A $ $ CSE S. Tanimoto Turing Completeness

38 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S1 ^ ^ ^ D A $ $ CSE S. Tanimoto Turing Completeness

39 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S1 ^ ^ ^ D A $ $ CSE S. Tanimoto Turing Completeness

40 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S4 ^ ^ ^ D A $ $ CSE S. Tanimoto Turing Completeness

41 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ ^ D $ $ $ CSE S. Tanimoto Turing Completeness

42 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S7 ^ ^ ^ D $ $ $ CSE S. Tanimoto Turing Completeness

43 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S0 ^ ^ ^ D $ $ $ CSE S. Tanimoto Turing Completeness

44 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) S2 ^ ^ ^ ^ $ $ $ CSE S. Tanimoto Turing Completeness

45 CSE 341 -- S. Tanimoto Turing Completeness
TM Example 3 (Cont) Accept! S2 ^ ^ ^ ^ $ $ $ CSE S. Tanimoto Turing Completeness

46 CSE 341 -- S. Tanimoto Turing Completeness
Formal Definition A Turing Machine is a 3-tuple, T = { , ,  }, where  is a finite set of states,  is a finite tape alphabet, and  is a transition function that specifies, for each    and   , a new tape symbol ', a new state ', and an action (one of Left, Right, Halt, Accept, or Reject). CSE S. Tanimoto Turing Completeness

47 CSE 341 -- S. Tanimoto Turing Completeness

48 CSE 341 -- S. Tanimoto Turing Completeness
A programming language L is said to be Turing complete provided that any function that can be computed by some Turing machine can also be computed by some program expressed in L. CSE S. Tanimoto Turing Completeness

49 Applying Turing Completeness
In order to show that a language is Turing complete, it suffices to show that the language provides: 1. a way to represent the current state of a TM computation, no matter how many states the TM may have, 2. a way to represent an a tape of whatever size may be needed by the computation, and to represent on each square of the tape, any tape symbol from a finite set (no matter how many symbols may be in TM’s finite set), 3. a way to implement any TM’s transition function, and 4. a way to repeat the execution of the transition function without limit. CSE S. Tanimoto Turing Completeness

50 Applying Turing Completeness (Cont)
1. a way to represent the current state of a TM computation, no matter how many states the TM may have: An integer variable. If there are n states in , then the variable must be able to handle any number in the range {0, …, n-1}. (For large numbers of states, we could use several integer variables. In principle we may need either one “bignum” or an arbitrary finite number of fixed-precision integer variables.) CSE S. Tanimoto Turing Completeness

51 Applying Turing Completeness (Cont)
2. a way to represent an a tape of whatever size may be needed by the computation, and to represent on each square of the tape, any tape symbol from a finite set (no matter how many symbols may be in TM’s finite set): a dynamically growable array or a linked-list construction capability. Each element of the array or list must be able to represent an integer in the range {0, …, m-1} where m is the size of . It must be possible to read and write any element of the array or list and to simulate moving the tape head left or right. CSE S. Tanimoto Turing Completeness

52 Applying Turing Completeness (Cont)
There must also be a way to keep track of the current tape head position. This could be done with a “bignum” or using a pointer if the tape is represented by a linked list. If the tape is represented by an actual serial I/O device (a real magnetic tape), then the position may be implicit and not require a program variable at all. CSE S. Tanimoto Turing Completeness

53 Applying Turing Completeness (Cont)
3. a way to implement any TM’s transition function: Either: nestable conditionals (IF constructs) or conditionals with compound conditions, and the ability to compare the current state with an arbitrary state, and compare the current tape symbol with an arbitrary symbol. Changing the state would presumably be done by assignment, but there may be other ways of doing it (e.g., creating new bindings in an ML style). CSE S. Tanimoto Turing Completeness

54 Applying Turing Completeness (Cont)
4. a way to repeat the execution of the transition function without limit: Either a means of explicit looping, a means of recursion, or an implicit repetition mechanism, as in some simulation systems such as cellular automata or microworlds like Stagecast Creator. CSE S. Tanimoto Turing Completeness

55 CSE 341 -- S. Tanimoto Turing Completeness
Most real programming languages are Turing complete. If a language is not Turing complete, it may or may not qualify as a “programming language.” However, “programming language” is a subjective term. CSE S. Tanimoto Turing Completeness


Download ppt "CSE S. Tanimoto Turing Completeness"

Similar presentations


Ads by Google