For a mathematician, the line

$$x = x + 1$$

is an equation with no solution: subtracting $x$ from both sides leaves $0 = 1$. For a programmer, it is one of the most common lines there is, and it means “take the value of $x$, add one and store the result in $x$”. The same sign, in the two communities, does opposite jobs: there it asserts an equality; here it orders an assignment.

Fortran chose the equals sign

The one responsible was Fortran, the first widely used high-level programming language, created at IBM by a team led by John Backus and released in 1957. Programs were punched on cards, one statement per card, and the keyboards of the card punches had few signs. To say “store the value $27$ in $N$”, Fortran wrote N=27, as in an engineer’s formula.

Punched cards with Fortran statements. On the second card, `N=27` does not assert that N equals 27: it orders 27 to be stored in N.
Punched cards with Fortran statements. On the second card, N=27 does not assert that N equals 27: it orders 27 to be stored in N.Tangopaso · Wikimedia Commons · public domain

The choice was practical and it stuck. But it bothered those who thought of programming as mathematics. The Algol language, created by an international committee between 1958 and 1960, used another sign for assignment, :=, and kept = for comparison. The Swiss Niklaus Wirth kept := in Pascal (1970), and Donald Knuth, in The Art of Computer Programming, writes assignment with an arrow: $x \leftarrow x + 1$. Iverson’s APL also used the arrow, and the statistical language R inherited it as <-.

The == of the C language

The C language, created in 1972, followed Fortran: = assigns. To compare, it needed another sign and doubled the equals: ==. The consequence is one of the most famous bugs in programming:

if (x = 0) { ... }

The programmer wanted to ask whether $x$ is zero. They wrote a single equals sign and ordered zero to be put in $x$. Since the value of the assignment is $0$, which C reads as “false”, the block is never executed, and the previous value of $x$ is silently lost. Many modern compilers warn when they meet this line, precisely because the sign has two meanings for anyone coming from mathematics.

What mathematics gained

Assignment is not an equality, but it brought into writing an idea that traditional mathematics hardly wrote down: time. In x = x + 1, the $x$ on the left and the one on the right are the same name at two moments. Mathematics expresses this with indices, $x_{n+1} = x_n + 1$, as in sequences and in Newton’s iterative methods. Programming showed that whole algorithms can be written by thinking of a name as a box whose contents change, and this way of thinking came back to mathematics through books on algorithms.

For learners, the two readings sit badly together. Chapter 4 showed that the school equals sign already had many jobs; the computer’s equals sign added one more, that of an order. Telling “I assert that” from “make it so that” is one of the things learned when passing from one community to the other.

Exercise: follow the program

A program executes, in order: x = 3, x = x + 1, x = 2 * x. What is the final value of $x$? And if the three lines were equations?

As a program: $x$ is $3$, then $4$, then $8$. As equations, the system $x = 3$, $x = x + 1$, $x = 2x$ has no solution (the second is impossible, and the third only holds for $x = 0$). Rewritten with indices, $x_0 = 3$, $x_1 = x_0 + 1 = 4$, $x_2 = 2x_1 = 8$, the three lines become true equalities again.

Exercise: the if bug

Why does if (x == 0) work and if (x = 0) not, in C? What would a mathematician write?

x == 0 compares and is true or false depending on $x$. x = 0 assigns zero to $x$ and has the value $0$, which counts as false: the condition is never met, and $x$ is wiped. A mathematician would simply write “if $x = 0$”, because in mathematical writing an equals sign inside a condition can only be a comparison.


Chapter index · ← Notation as a tool of thought: Iverson · The names on theorems: Stigler’s law →