Workshop 3 Turing Machines In these exercises, you are given various Turing Machines described in tabular form. You are also given a starting tape. You must write out the computations made according to the table. Huge amounts of squared paper are available. There are also some “reflective” questions at the end. 2. A Machine which halts or does not Let’s work with the Turing Machine defined by the following table. I’ve constructed this machine to show you how the input data on the tape may cause the machine to halt or not. Here’s the machine table start 1 * State Read Write Move New State Q 1 1 R Q 2 Q 2 2 L A 3 Q 3 3 N Halt 4 A 1 1 R Q 5 A 2 2 L A 6 A 3 3 N Halt 2.1 Run the machine on paper, with the following input tape: 1 2 2 Does the machine halt or not? 2.2 Now run the machine on paper, with the following input tape 1 3 3 Does the machine halt or not? 2.3 Using the tabular description of the Turing Machine (above), construct the “state diagram” for this machine. Start by drawing circles for the states (and label them), then draw the arcs between the states. Label each arc as (symbol read, symbol written, movement) for example (1,1,R) which means that the symbol read is “1”, then the symbol written is “1” then the tape head moves “R” to the right. 3. A Bracket Checker As explained in class, brackets are fundamental in a symbolic notation to indicate what elements must be grouped together. For example “4 + ( 5 x 3) = 3 + 15 = 19”. Do the contents of the brackets first. Also in programming, you will find a “{“ which marks the start of a block of code, and a “}” which marks the end of the code block. In either case, the brackets must match: This means that for every bra“(“ there must be a –ket “)”. Otherwise the calculation fails, eg “4 + (5 x 3 ” is meaningless in maths, or “while(i<10) { i++;” will not compile. Bra-kets missing. Here are examples of “well-formed” bra-ket strings: ( ( ) ) ( )( ) ( ) ( ( ) ) And here’s some examples of “not-well-formed” strings ( ( ) ( )(( ) ) ( ( ) ) 3.1 Copy these “not-well-formed” bracket strings, and add a bracket (or more) to make them “wellformed”. 3.2 The Turing Machine defined in the following table performs a bracket checking operation. When complete, if the tape has a written symbol “0”, then the string is ill-formed. If a symbol “1” is written, then the string is well-formed, the bra-kets match. Run the Turing Machine (on paper) with the following tape (input data). E ( ( ) ) E Bracket Checker Turing Machine: start 1 * State Read Write Move New State A ) X L B 2 A ( ( R A 3 A E E L C 4 A X X R A 5 B ) ) L B 6 B ( X R A 7 B E 0 N Halt 8 B X X L B 9 C ) 10 C ( 0 N Halt 11 C E 1 N Halt 12 C X X L C Can’t happen 3.2 Now run the Turing Machine with the following tape, which is a “not-well-formed” string and see what happens. E ( ( ) E 3.3 Construct the state diagram associated with this Turing Machine 3.4 From your observation of the behavior of the Turing Machine, can you explain how it works, ie how it “pairs off” the brackets. Hint, what do states A and B actually do? 3.5 Explain the advantage of the Turing Machine over a Finite State Machine to solve the bracketchecking problem. 4. Binary Addition The Turing Machine defined here effects an addition to a binary number. The addition is “1”. So if the original binary number was “0 1 1 0” (denary 6) then after addition of 1, the result would be “0 1 1 1” (denary 7). If the original number was “0 1 1” (denary 3) then the result would be “1 0 0” (denary 4). The Turing Machine to perform this addition is defined below: start 1 State * Read Write Move New State A 0 0 R A 2 A 1 1 R A 3 A # # L B 4 B 0 1 L Halt 5 B 1 0 L B 6 B # 1 L Halt 4.1 Start with the tape containing the number “6” and run the Turing Machine to produce the number “7”. Check if it works! 0 1 1 0 # 4.2 Now take the tape with the number “3” (below) and compute it with the Turing Machine 0 1 1 # Parity Checker This Turing machine scans a string composed of the two binary digits 0 and 1 and determines the “parity” of the string. This is the odd-ness or even-ness of the number of 1’s in the string. If there are 1 or 3 or 5, 1’s in the string then the parity is odd, if there are 0,2,4,6 … 1’s in the string then the parity is even. Here’s a few examples: 0011 1110 01010101 111001 00000010 even odd even even odd Here’s the Turing Machine for the parity detector in tabular form. start 1 * State Read Write Move New State Even 0 0 R Even 2 Even 1 0 R Odd 3 Even @ 0 N Halt 4 Even # # R Even 5 Odd 0 0 R Odd 6 Odd 1 0 R Even 7 Odd @ 1 N Halt 8 Odd # # R Odd 5.1 Run the Turing Machine for the following tape. Check the resulting computation # 1 1 1 @ 5.2 And now for this tape and see what you get. # 1 1 0 0 @ 5.3 Can you describe in simple English how the Turing Machine works? 5.4 Do you see how to simplify the tabular representation of the Turing Machine? Finite State Machines 6.1 Construct a finite state machine which will test for three pairs of matched brackets, eg ( ( ( ) ) ). It should indicate if the brackets are matched, or if they are not, as ( ( ( ) ) 6.2 Reflect on the power of Turing Machines over Finite State Machines in solving the bracketmatching problem 6.3 In what sense can we say that Turing Machines extend Finite State Machines in that they are “Infinite State Machines”? In other words, what provides the “infinity”? Philosophical Issues 7.1 You may have realized that the crux of the demonstration of the Halting Problem involved the feeding of a description of a computer (as a programme) into the computer itself. This arrangement caused the fundamental problem. There are other examples of this in the literature. Research these and write up some notes on this. You may like to start with the Epimenides Paradox, or Russel’s Paradox. 7.2 Turing’s result for the “halting problem”, that it is impossible to know if a general computer programme will halt has enormous impact on our belief in computers. People often say that “a computer will only output rubbish if the input is rubbish”. Clearly Turing showed the situation may be not as clear-cut as this. Yet computers are used in “safety-critical” systems (such as aircraft control and enginemanagement systems) which if they go wrong, could be life threatening. 7.3 Can you write a short computer programme which is guaranteed to halt? (easy). Can you write a computer programme which may halt or may not? (very hard). 7.4 Can you identify situations in our contemporary world where it is absolutely necessary to know whether a computer programme will halt (ie work) or not (won’t work)? Think of aircraft control systems, hospital computers in intensive care, or your microwave. Or are there situations where it does not matter if a computer cannot compute? Perhaps in the banking industry, or in the media?