✕ Close

Week 15 · 15.2 · Tue, Nov 10 · The Bigger Picture: ACT-style reading

Checking a Routine by Hand: From Turing's Table to Java's Boxes

1 This section explains how a person can check what a program's boxes hold without running it, from a short paper Alan Turing gave in 1949 to the trace tables used with Java today.

A Table in 1949

2 On June 24, 1949, the mathematician Alan Turing presented a short paper at a conference at the Mathematical Laboratory in Cambridge, England. The conference marked the start of the laboratory's new computer, the EDSAC. Turing's paper was called "Checking a Large Routine," and in those years a program was often called a routine. The three-page paper asks how a person can check that a routine is right.

3 Turing began with an everyday comparison: checking a long addition. When five numbers are added and only the final total is written down, a checker has to check the whole sum at once, because of the carries. When the total of each column is written down too, the work splits into small checks that are each easy to make. Turing argued that a routine could be checked the same way, and he wrote that "the programmer should make assertions about the various states that the machine can reach." An assertion is a statement about what is stored at one moment in a run.

4 His example routine worked out a factorial, the product of every whole number from 1 up to some number, such as 4 × 3 × 2 × 1. The routine had to work "without the use of a multiplier," so it carried out multiplication by repeated addition. Beside the routine's flow diagram, Turing drew a table. Each row stood for one storage location, numbered 27 to 31, and each column stood for one moment in the run, from the start to the stop. A checker could test the columns "in any order and quite independently."

5 The paper drew little notice at the time, and at the conference the physicist Douglas Hartree objected to some of its words. In 1984, two computer scientists named Morris and Jones published a corrected version, "An Early Program Proof by Alan Turing." Computer scientists now count it among the earliest attempts to show that a program is correct.

Boxes That Change

6 A Java variable is a named box. The line int count = 0; declares a box: it gives the box's type, int, its name, count, and its first value, 0. The type decides what the box can hold: int for whole numbers, double for numbers with a decimal point, boolean for true or false, and String for text in double quotation marks.

7 The = sign is the assignment operator. In the words of Oracle's Java tutorial, it "assigns the value on its right to the operand on its left." Java works out the whole right side first, using the value each box holds at that moment, which is its current value, and only then stores the result in the box on the left. For that reason, count = count + 1; makes sense in Java, even though it could never be true in math. The right side uses the current value of count, and the result replaces it. Oracle's tutorial notes that x = x + 1; and x += 1; both increase the value of x by 1.

8 A box holds one value at a time. When a line stores a new value, the old value is gone. A line that changes one box leaves every other box alone, so a box keeps its last value, even when the boxes it was worked out from change later.

A Trace Table for Java

9 A trace table follows the same idea as Turing's table. It has one column for each box and one row for each line that runs. Each row records every box's value right after that line runs, and an Output column records what the line prints. Figure 1 sets Turing's table beside a Java trace table.

1int score = 10;
2int bonus = 3;
3score = score + bonus;
4bonus = bonus * 2;
5System.out.println(score + bonus);

10 After line 3, score holds 13 and bonus still holds 3. After line 4, bonus holds 6 and score still holds 13. Line 5 adds the current values and prints 19.

19

11 Today's question asks what x = x + 1; does to the box called x. The line is an assignment, so Java works out x + 1 with the current value of x, then stores the result back in x, replacing the old value. A trace table keeps track of what x holds after every line. On today's bench, each Java program is traced line by line, with a column for every box.

Summary

12 In 1949, Alan Turing showed that a routine could be checked by recording what each storage location held at each moment. In Java, an assignment works out the right side with current values and then stores the result, so x = x + 1; adds 1 to x. A box keeps its last value until a line stores a new one, and a trace table records every box after every line.

Sources: King's College, Cambridge, The Turing Digital Archive, AMT/B/8; X. Leroy, Program Logics, Collège de France, 2021 (reproducing Morris and Jones, "An Early Program Proof by Alan Turing," 1984); F. Wiedijk, A Large Routine, 2016; Oracle, The Java Tutorials: Variables, Primitive Data Types and Assignment, Arithmetic, and Unary Operators; Oracle, The Java Language Specification, Java SE 21 Edition, §15.26.1.

Figure 1. In 1949 Turing's table recorded what each storage location held at each moment of a run; today a trace table records every Java box after every line, and = always stores the newest value.
ACT-style reading · 9 questions

Read the passage on the left. Answer each question by clicking a choice: the right answer turns green, and a wrong one tells you why. Questions point to paragraph numbers, as on the ACT.

1. Main idea

The main purpose of the passage is to:

2. Detail

According to paragraph 2, where and when did Turing present "Checking a Large Routine"?

3. Purpose

The author describes checking a long addition (paragraph 3) mainly to:

4. Words in context

As it is used in paragraph 3, the word assertion most nearly means:

5. Detail

According to paragraph 4, what did each row and each column of Turing's table stand for?

6. Inference

Based on paragraph 5, how did people's view of Turing's paper change over time?

7. Cause and effect

According to paragraph 7, why does count = count + 1; make sense in Java even though it could never be true in math?

8. Detail

According to paragraph 8, what happens to a box when a line changes a different box?

9. Author's claim

Which sentence from the passage best answers what x = x + 1; does to the box called x?