Mathematics for Computer Science



Similar documents
CSCA0201 FUNDAMENTALS OF COMPUTING. Chapter 1 History of Computers

Turing Machines: An Introduction

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Regular Languages and Finite Automata

Clock Arithmetic and Modular Systems Clock Arithmetic The introduction to Chapter 4 described a mathematical system

Binary Adders: Half Adders and Full Adders

Science in History: From the Abacus to the Modern Computer Part 1: The Abacus

Kapitel 1 Multiplication of Long Integers (Faster than Long Multiplication)

Turing Machines, Part I

Computational Models Lecture 8, Spring 2009

Forward exchange rates

History of Informatics: Ada Lovelace

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

How To Understand The Theory Of Computer Science

Chapter 1. Computation theory

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

A Short Guide to Significant Figures

3515ICT Theory of Computation Turing Machines

1.7 Graphs of Functions

Financial Mathematics

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Lies My Calculator and Computer Told Me

8 Primes and Modular Arithmetic

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

Soroban. The Japanese Abacus By Kimie Markarian

Math Games For Skills and Concepts

4.3 TABLE 3 TABLE five

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

3 Some Integer Functions

I remember that when I

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

NUMBER SYSTEMS. William Stallings

Numeracy and mathematics Experiences and outcomes

Chapter 13: Fibonacci Numbers and the Golden Ratio

Session 7 Fractions and Decimals

Kenken For Teachers. Tom Davis June 27, Abstract

Chapter 31 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M.

APPENDIX. Interest Concepts of Future and Present Value. Concept of Interest TIME VALUE OF MONEY BASIC INTEREST CONCEPTS

=

Common sense, and the model that we have used, suggest that an increase in p means a decrease in demand, but this is not the only possibility.

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

5544 = = = Now we have to find a divisor of 693. We can try 3, and 693 = 3 231,and we keep dividing by 3 to get: 1

Working with whole numbers

Continued Fractions and the Euclidean Algorithm

What Is Singapore Math?

Chapter 11 Number Theory

Basic numerical skills: FRACTIONS, DECIMALS, PROPORTIONS, RATIOS AND PERCENTAGES

Playing with Numbers

Decimal Notations for Fractions Number and Operations Fractions /4.NF

Multiplying and Dividing Signed Numbers. Finding the Product of Two Signed Numbers. (a) (3)( 4) ( 4) ( 4) ( 4) 12 (b) (4)( 5) ( 5) ( 5) ( 5) ( 5) 20

Linear Programming Notes VII Sensitivity Analysis

Number Systems and Radix Conversion

Mathematical Induction

20-30 minutes, can be used within a longer activity

Base Conversion written by Cathy Saxton

PYTHAGOREAN TRIPLES KEITH CONRAD

The Crescent Primary School Calculation Policy

5 Homogeneous systems

Notes on Complexity Theory Last updated: August, Lecture 1

Lecture 8: Synchronous Digital Systems

NP-Completeness and Cook s Theorem

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

1. The Fly In The Ointment

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

0.8 Rational Expressions and Equations

Currency and Exchange Rates

SECTION 10-2 Mathematical Induction

The Binomial Distribution

POLYNOMIAL FUNCTIONS

1.6 The Order of Operations

Introduction to Turing Machines

Application. Outline. 3-1 Polynomial Functions 3-2 Finding Rational Zeros of. Polynomial. 3-3 Approximating Real Zeros of.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

TEACHER S GUIDE TO RUSH HOUR

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

3.1. RATIONAL EXPRESSIONS

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Decision Making under Uncertainty

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

SYMBOL AND MEANING IN MATHEMATICS

Negative Integral Exponents. If x is nonzero, the reciprocal of x is written as 1 x. For example, the reciprocal of 23 is written as 2

Multiplication and Division with Rational Numbers

CALCULATIONS & STATISTICS

Math 4310 Handout - Quotient Vector Spaces

Count the Dots Binary Numbers

Section 1.5 Exponents, Square Roots, and the Order of Operations

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Permutation Groups. Tom Davis April 2, 2003

Creating, Solving, and Graphing Systems of Linear Equations and Linear Inequalities

Radicals - Multiply and Divide Radicals

Factorizations: Searching for Factor Strings

Transcription:

Mathematics for Computer Science Lecture 3: Turing Machines Areces, Blackburn and Figueira TALARIS team INRIA Nancy Grand Est Contact: patrick.blackburn@loria.fr Course website: http://www.loria.fr/~blackbur/courses/math

Today s lecture The main purpose of today s lecture is to introduce Turing machines, a simple, abstract and (as we shall see) general model of computation. But although Turing machines are abstract, they reflect certain very concrete ideas about what it is to compute. Indeed, such ideas have long inspired others to create machines of various kinds to compute, as we shall now see. One of the most important skills you will learn today is how to write simple Turing machines. This skill is important for at least two reasons. First, it will teach you some basic programming skills. Second, it will help you to understand and appreciate just how simple and general Turing s model of computation is.

Roman abacus It is unclear whether the Roman abacus influenced the Chinese abacus or vice-versa (Rome and China were in contact via trade at the time). What is clear is that the Roman abacus was far slower than the Chinese one and much faster than hand calculation with Roman numerals.

Chinese Abacus above (Japanese below) The Chinese abacus was first mentioned around 190 AD. They became widely used around 1200 AD. Note the two rows of count 5 beads.

Japanese Abacus (Soroban) The Japanese adopted the abacus from the Chinese around the fifteenth or sixteenth century. They dropped one of the row of the count 5 beads, yielding the modern Soroban abacus, still used in modern Japan.

Effectiveness of the abacus On November 12, 1946, a contest was held in Tokyo to compare the Japanese soroban with an electric calculator. The soroban was operated by Kiyoshi Matsuzaki, the calculator by US Army Private Thomas Nathan Wood. The contest compared speed and accuracy for all four basic arithmetic operations (that is, addition, subtraction, division and multiplication) and one problem combined all four operations. The soroban won 4 to 1 (the electric calculator won the multiplication context). This contest formed the basis for a science fiction short story by Arthur C. Clarke in which teams of abacus operators successfully take over the functions of a broken computer on a spacecraft!

Inca abacus Inca (1200 1532) calculator. There are several ideas about how it worked, but no real certainty.

Gottfried Leibniz Gottfried Leibniz (1646 1716), philosopher, inventor of calculus, pioneer of symbolic logic, and general all-round genius, was also interested in the idea of mechanical calculation. As he put it: It is unworthy of excellent men to lose hours like slaves in the labor of calculation, which could be safely relegated to anyone else if machines were used.

Stepped Reckoner (I) In 1671, Leibniz started working on a machine, the Stepped Reckoner, that could perform the four basic arithmetical operations. He gradually improved over the years. The idea attracted a lot of interest, and led to Leibniz being elected a member of the Royal Society in 1673.

Stepped Reckoner (II) A number of versions of the machine were constructed in Leibniz s lifetime by a Hanover-based craftsman. However the Leibniz s ideas pushed the technology of the time to its limits: the machine was prone to jamming and malfunctioning.

The Turk The idea of computing over other domains than numbers also seems to have been in the air. Chess was an obvious choice. Between 1770 1854, the Turk, a mechanical chess player, took on all comers. Famous victims include Napoleon Bonaparte and Benjamin Franklin. In later incarnations it had a voice box, and uttered the word Check!. The Turk was destroyed by fire in 1854. Sadly, three years later, it was revealed to have been a fake; a human being concealed inside operated it.

Charles Babbage English pioneer of computer science and sadly, too far in advance of his time to realise his ideas,

A forerunner of more than mere computer science...! Here s what he wrote to Tennyson (the English poet) about Tennyson s poem The vision of sin poem: In your otherwise beautiful poem, one verse reads, Every moment dies a man, Every moment one is born... If this was true, the population of the world would be at a standstill. In truth, the rate of birth is slightly in excess of that of death. I would suggest: Every moment dies a man, Every moment 1 1/16 is born. Strictly speaking, the actual figure is so long I cannot get it into a line, but I believe the figure 1 1/16 will be sufficiently accurate for poetry. Geeks rule!

The Difference Engine (I) Babbage s first project was the Difference Engine. He conceived of it as a special-purpose mechanical digital calculator, designed to tabulate polynomial functions; he proposed it in an 1822 paper to the Royal Astronomical Society, entitled Note on the application of machinery to the computation of very big mathematical tables. Such tables were of immense important at the time, for example for navigation and gunnery.

The Difference Engine (II) This Difference Engine was designed to use the ordinary base 10 number system (that is, ordinary decimal arithmetic) and to be powered by turning a handle. The British government initially financed the project, but stopped when Babbage repeatedly asked for more money when he had made no apparent progress. The Difference Engine was never finished, but was later reconstructed by the Science Museum in London (the picture on the previous slide is of this reconstruction). The reason for Babbage s failure to finish the machine was his all-consuming enthusiasm for a more general project (closer to a modern computer) that he called the Analytical Engine.

The Analytical Engine The analytical engine was to have been powered by a steam engine; if it had been built, would have been over 30 metres long and 10 metres wide. The input was to have been via punched cards (such cards were already being used in mechanical looms). There were to be a variety of possible outputs: a printer, a curve plotter, a bell(!) and a card punch. It was designed for ordinary base 10 arithmetic. It could be programmed. Indeed, the Analytical Engine seems to have been comparable in power with the programmable calculators marketed by Texas Instruments and Hewlett Packard in the 1980s.

The Mill of the Analytical Engine This is the only part of the Analytical Engine which was ever built. Called the mill, which did the four basic arithmetic operations, comparisons, and square roots.

Ada Lovelace the first programmer Ada Lovelace (1815 1857), daughter of Lord Byron, was a was a passionate advocate for the analytical engine and the potential of computing. A mathematician, in 1842 she translated an Italian treatise on the Analytical Engine into English, and added a program for calculating Bernoulli numbers. Babbage called her The enchantress of numbers. The programming language Ada is named after her.

Practical computing Leibniz s Stepped Reckoner and Babbage s Analytical Engine were visionary and outstripped the technology of their time. But much existing technology (for example, the punched card) certainly was ready to be exploited for more down-to-earth computing tasks. One such task was tabulation counting and classifying large amounts of data for statistical purposes. The need for speedy methods of doing this was clear by the end of the 19th century. Hollerith designed and built a number of machines for this purposes, building on and extending existing technology.

Hollerith s fundamental patent The herein-described method of compiling statistics, which consists in recording separate statistical items pertaining to the individual by holes or combinations of holes punched in sheets of electrically non-conducting material, and bearing a specific relation to each other and to a standard, and then counting or tallying such statistical items separately or in combination by means of mechanical counters operated by electro-magnets the circuits through which are controlled by the perforated sheets, substantially as and for the purpose set forth.

The Hollerith Machine Hollerith s company, the Tabulating Machine Company, built and leased a number of such machines to the US Government. His company was one four that eventually merged to form IBM.

Columbia Machine Such work led eventually to other impressive technical developments. For example, the Columbia machine combined fast tabulation with the ability to perform arithmetic calculations.

Journalistic description of the Columbia Machine Indeed, the Columbia-machine seemed like science fiction to some writers at the time. But behind the journalistic exaggerations, it was clear that technology needed to exploit the theoretical work of Turing and his colleagues was almost in place.

How we calculate So what is a Turing machine, and how did the concept arise? Turing thought hard about what was involved in carrying out simple calculations, such as adding a column of numbers, or multiplying two large numbers together. He saw clearly that when performing such calculations, in essence we are carrying out simple algorithms. That is, we are following, step by step, a series of rules. For example, when adding two columns of numbers we learn to add them from the rightmost digit to leftmost, and to carry numbers. When multiplying two numbers greater than 10 we learn to do it digit by digit, to add in extra zeroes, and to obtain the final result by addition.

Algorithms are everywhere Following the steps in a recipe book, or following a knitting pattern, are two good examples of everyday algorithms. Indeed, much of the mathematics we learn in school isn t what a mathematician would regard as mathematics at all; rather, it s learning certain algorithms for certain tasks. Early in school we learn algorithms for carrying out addition, multiplication, division, or finding greatest common divisors (using the famous Euclidean algorithm); only much later, probably at university, do we learn the deeper concepts of number theory. Later in school we may learn simple calculus. But at school this is mostly about learning simple algorithms for differentiating and integrating simple functions such as polynomials; only later (at university) so we learn the underlying ideas of continuity, differentiability, and so on.

From algorithms to machines The idea of an algorithm, the step by step following of a sequence of precise rules, is one of the fundamental ideas of computer science. But how are algorithms actually realised in the physical world? How can we design machines to really carry them out? Turing answered this question by thinking carefully about what is involved when a person carries out calculations.

Turing s analysis Turing saw that performing an algorithm required some sort of workspace a place to write the input, the output, and the intermediate results. (For a human, such a workspace might be a sheet of paper.) He also saw that there needed to be clearly-defined finite number of simple operations that could be performed; for example, how to add two digits, or how to multiply two digits. Last but not least, he abstracted the notion of state. Internal states are the simple model of mind that lie behind Turing s design.

Turing machines Putting all together, a Turing machine has three components: An unending tape divided into squares. The tape is the workspace. Input, output, and intermediate calculations are written on the tape. We think of the tape as infinite both to the right and to the left (if you prefer: imagine that we always have the possibility of adding more squares, at either end, should we need them). There is a read/write head (or simple, head) which moves along the tape. The head is restricted in its movement; it can only move one square left or right at a time. The head can read the symbol (if any) that is written on the tape, and write one of a finite number of symbols on the tape. A Turing machine can be in one of a fixed finite number of internal states. The ability of a Turing machine to enter different internal states is the real key to its power.

Writing Turing machines A Turing machine starts by scanning the input symbols which are written on the tape. We say a Turing machine is in standard configuration if it is scanning the leftmost symbol of all the input symbols. We write a Turing machine by saying what action the Turing machine is to perform when scanning a certain symbol in a certain state, and by saying what state it goes into after it has performed that action.

What actions can Turing machines perform? There are three basic things a Turing machine can do: it can move one square to the left, move one square to the right, or write a new symbol on the square it is reading (overwriting what is already there; note that we regard the blank square as a symbol). We also need to say what state the machine moves into after performing the action. This might be the state it was already in, or a new state. A Turing machine halts if no action is defined for the state it is in. Such a state is called a final state, or a halting state. If a Turing machine halts scanning the leftmost symbol of its answer, we say it halts in standard configuration.

An example Turing machine... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3 Here s an example machine. We see a blank tape, the read/write head (the red arrow), and the table which says what the machine is to do when in a given state scanning a given symbol. Note: to prevent ambiguity, in the table we represent the symbol blank square by #.

What does this machine do? This machine is designed to start in standard configuration scanning a tape containing a mixture of the symbols $ and x. The head moves along the tape from left to right, and changes every x it finds to a $ (that is, it overwrites every x with a $ symbol). When it reaches the first blank square to the right of the input, it moves left all the way back to the first blank to the left of the input. It then moves one square to the right (so it is scanning the left most dollar symbol) and halts in standard configuration. Fine but how exactly does it do this? Let s work through very carefully and see...

Turn Xs to Dollars!... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3 Here s the machine again...

Example input... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3 And here s some typical input. What happens next? Well, let s assume we start in State 1

Configuration 1... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 2... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ x $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There...!... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 3... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 4... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 5... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 6... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ x... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 7... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 8... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

What to do...?... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

There!... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 9... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 10... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 11... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 12... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 13... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 14... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3

Configuration 13... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3 Halt! No Action defined for State 3!

Configuration 13... $ $ $ $ $... 1 $ R 1 1 x $ 1 1 # L 2 2 $ L 2 2 # R 3 Halt! No Action defined for State 3!

Summing up As promised, the machine started in standard configuration, converted all x symbols to $ symbols, and halted in standard configuration. A simple machine, but one which demonstrated the basic symbol manipulation abilities of Turing machines. Study it well. But the best way to learn to write Turing machines is to study as many of them as possible. So lets look at another example.

Turing machines for arithmetic functions We have seen examples of the sort of devices (abacuses and so on) that people have devised during history to calculate arithmetic functions (that is, addition, multiplication, division and so on). Unsurprisingly, Turing machines can calculate such functions too. Let s look at an example: a Turing machine for addition.

Representing numbers The first thing to decide is how to represent numbers. Now we could use ordinary decimal notation, or we could use binary notation, but it will make things simpler if we start by using monadic notation. What is monadic notation? Simple! the numeral 1 is represented by 1, 2 is represented by 11, 3 is represented by 111, 4 by 1111, 5 by 11111, and so on (we won t bother to introduce a convention for handling 0, though it is easy to do so). This notation is makes it easy to do addition. For example, 2 + 3 is 11 + 111 which is just 11111. That is, we really just need to stick the two blocks of one representing the input together! How can we devise a Turing machine for doing this?

The basic idea We re going to present a Turing machine that will take as input two blocks of 1s (separated by a blank square). The machine will start in standard configuration. It will then stick the two blocks together (thus performing the monadic addition). Furthermore, we shall design the machine is such a way that it halts in standard configuration. Why bother starting and stopping in standard configuration? It may not seem like a very important concept. But is is. We shall see why in the following lecture.

The algorithm in more detail Begin by scanning the leftmost 1. Move right, and keep doing so until you get to the blank that divides the two blocks on input ones. When you find the blank separating the two blocks of input, write 1 in the blank, and switch into a new state. Keep moving right until you come to the blank at the right-hand-end of the (now continuous) block of 1s. Move one space left, switch state, and change the 1 to a blank (now the correct number of 1s are on the tape). Move left, change state and keep moving left until you come to the blank at the left-hand-end of the block of 1s. Move right one space and halt. And here s a machine that realizes this algorithm...

Monadic addition... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Example input... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 1... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 2... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 3... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 4... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5 We stick the blocks together by changing the blank between them to a 1. This means we have one 1 too many. So we will need to remember to delete rightmost 1.

Configuration 5... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 6... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 7... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 8... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 9... 1 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 10... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5 There! We changed the rightmost 1 to a blank. So we have the right number of symbols on the tape. The only thing left to do is get the head back to the leftmost 1 symbol.

Configuration 11... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 12... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 14... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 15... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 16... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 17... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 18... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5

Configuration 18... 1 1 1 1 1... 1 1 R 1 1 # 1 2 2 1 R 2 2 # L 3 3 1 # 3 3 # L 4 4 1 L 4 4 # R 5 Halt! State 5 is a final state!

Remarks This machine clearly does perform monadic addition. Thus we have seen our first example of a Turing machine which calculates an arithmetic function. Our use of monadic notation for number made addition easy but it makes other operations quite involved. For example, monadic multiplication takes a little more thought. Writing a Turing machine for monadic multiplication is one of the problems on Worksheet 3. It is perhaps worth emphasizing that we used monadic addition because it gave us a simple way to show how arithmetic functions could be implemented. But we weren t forced to do so! We could have defined addition in decimal or binary. And indeed, you ll find such exercises on Worksheet 3.

A decision problem Our first Turing machine (the x to $ converter) performed a typical computer science problem, namely converting one kind of symbol to another. Our second Turing machine, the monadic addition machine, carried out a typical mathematical task. Our third machine is going to carry out a typical logical task it is going to provide a yes/no answer to a question. That is, it is going to implement what logicians call a decision procedure. In particular, the machine is going to decide whether the input number (written in monadic) is odd or even.

The Algorithm We start in the initial state reading a 1. Assume that there are two other states: an even state and an odd state. Move right, go into the odd state, and then... Odd state: if you read a blank, write odd and halt. If you read a 1, move right, and go into the even state. Even state: if you read a blank, write even and halt. If you read a 1, move right, and go into the odd state. Just keep flipping between the previous two moves!

Odd or even?... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 Here s a machine for the algorithm just described. State 2 is the even state and State 3 is the odd state.

Example input... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 And here s some typical (even) input. Ready to go... blah blah blah

Configuration 1... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 We start in State 1. We re reading the first 1, so we have so far seen one 1, an odd number. So we go into the odd state (State 3).

Configuration 2... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 We re in the odd state. But we re reading a 1. So now we have seen an even number of 1s. So we go into the even state (State 2).

Configuration 3... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 We re in the even state. But we re reading a 1. So now we have seen an odd number of 1s. So we go into the odd state (State 3).

Configuration 4... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 We re in the odd state. But we re reading a 1. So now we have seen an even number of 1s. So we go into the even state (State 2).

Configuration 5... 1 1 1 1... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 We re in the even state. But now we are seeing a blank square. So we know that the input was an even number. So we write even on the tape and go into State 4

Configuration 6... 1 1 1 1 even... 1 1 R 3 2 # even 4 2 1 R 3 3 # odd 5 3 1 R 2 And this is where we halt, because State 4 is a final state. blah blah blah

Remarks So the machine really does implement the odd/even decision problem. Study this machine carefully, and then do the exercise on Worksheet 3 which asks you to modify it in a certain way.

Summary of Lecture 3 Key concepts: We introduced the key concept underlying this course, namely the concept of a Turing machine. Turing machines are abstract machines, nonetheless they are based on an analysis of concrete calculations. Indeed Turing machines are essentially a simple mechanism for realizing algorithms using three fundamental concepts: the tape, some basic operations operations (moving right, moving left, and writing symbols), and internal states.

Summary of Lecture 3 continued Key concepts: We examined three Turing machines in detail. The first performed a symbol conversion task: it took in a string of mixed xs and $s, changed all the xs to $s, and halted leaving a string of dollars on the tape. The second performed a typical mathematical task: it calculated values of the addition function. For this task we represented numbers using monadic notation, as this greatly simplified the task. Finally, we introduced the notion of a decision problem, and illustrated this with a machine that could decide whether an input number was odd or even. Note: all three machines are calculating functions think about it.

Summary of Lecture 3 continued Key concepts: We also mentioned several times the concept of standard configuration for input and output, though as yet we have not seen why this idea is so important. We will see why next week when we start to talk about to build Turing machines to perform more interesting tasks.