6.044J/18.423J: Computability, Programming, and Logic Handout 3 Massachusetts Institute of Technology September 6, 1996; corrected Sept. 10

Notes on Proving Arithmetic Equations

1 Expressions and Values

In these notes we describe a formal system for proving arithmetic equations. Our objective is to explain what it means to have a completely formal, automatically verifiable proof system, and to clarify the basic properties of such proof systems. Our objective is not to clarify the basic properties of numbers—we need to know these beforehand in order to understand and justify the proof system. For example, it will take some effort in our system to prove that e × 0 = 0; the formal proof certainly does not make this equation any more or less obvious.

Definition 1. Arithmetic expressions (ae’s) are defined inductively as follows:

• The numerals 0, 1 are ae’s.

• Any variable, x, is an ae.

• If e is an ae, then so is (-e).

• If e, f are ae’s, then so are (e + f) and (e * f).

• That’s all.

We use the symbol ℤ for the set of all integers {0, 1, −1, 2, −2, … }.

Definition 2. A valuation, V, is a mapping from the set, Var, of variable symbols which may appear in ae’s, into ℤ. The value, val(e, V), of an ae, e, at a valuation, V, is defined by structural induction on ae’s as follows:

• val(0, V) = 0 and val(1, V) = 1.

• val(x, V) = V (x) for any variable, x.

• val((-e), V) = −val(e, V).

• val((e + f), V) = val(e, V) + val(f, V), and

• val((e * f), V) = val(e, V) × val(f, V).

The meaning, ⟦e⟧, of an ae, e, is the function from valuations to ℤ defined by:

⟦e⟧(V) = val(e, V).

It is conventional to omit parentheses around the arguments of meaning functions, writing “⟦e⟧V ” instead of “⟦e⟧(V).”

Definition 3. An arithmetic equation (aeq) is an expression of the form (e = f) where e, f are ae’s. The aeq is true at valuation V, written

V ⊧ (e = f),

iff ⟦e⟧V = ⟦f⟧V. The equation is valid, written

                                  ⊧ (e = f)

iff it is true at all valuations, that is, iff ⟦e⟧ = ⟦f⟧.

Example. Let e_{0}, f_{0} be the ae’s

                   e_{0} ::= ((1 + (1 + 1)) * (x + y)),
                   f_{0} ::= ((y * (x * y)) + (-((1 + 1) + 1))).

Let V_{1} be a valuation such that V_{1}(x) = 2, and V_{1}(y) = 3. Then val(e_{0}, V_{1}) = 15 and val(f_{0}, V_{1}) = 15, so V_{1} ⊧ (e_{0} = f_{0}). Let V_{2} be the valuation such that V_{2}(v) = 0 for all variables v. Then val(e_{0}, V_{2}) = 0 ≠ −3 = val(f_{0}, V_{2}), so V_{2} |̸= (e_{0} = f_{0}). Thus, (e_{0} = f_{0}) is not valid.

As another example, note that equations of the following form are valid:

Lemma 1.

                  ⊧ ( (e * (f + g)) = ((e * f) + (e * g)) )

for all ae’s e, f, g.

Proof: Let V be any valuation and l, m, n be the values of e, f, g at V. Then

⟦(e * (f + g))⟧V = l(m + n)

by definition of the meaning of ae’s. Likewise,

⟦((e * f) + (e * g))⟧V = lm + ln.

But l(m + n) = lm + ln by the distributive law of arithmetic, so

                   ⟦(e * (f + g))⟧V = ⟦((e * f) + (e * g))⟧V.

But V was arbitrary, so this equation must hold for all V, i.e., the equation is valid.

2 Equational Proofs

We’ve been careful so far to use a special “teletype” font for the actual symbols “), *,” … occurring in ae’s, to distinguish them from the italic font mathematical symbols “), x, e, f” used to describe ae’s. To keep our notation uncluttered, from now on we stop being so careful when there is no danger of ambiguity. In particular, we often will omit parentheses and just use mathematical font throughout expressions. For example, the valid equations of Lemma 1 above will now be written as

e ∗ (f + g) = (e ∗ f) + (e ∗ g).

Definition 4. An aeq, C, is said to follow by the transitivity rule from the pair of aeq’s A_{1} and A_{2} iff A_{1} is of the form e = f, A_{2} is of the form f = g, and C is of the form e = g.

We use the notation

{e = f, f = g \atop e = g}

as a shorthand description of this rule. The aeq’s above the horizontal line are called the antecedents of the rule, and the aeq below the line is called its consequent.

Along with transitivity, the reflexivity, symmetry, and congruence rules together are called the standard equational inference rules. They are described in Table ??. Note that the reflexive rule has no antecedents. Such rules without antecedents are usually called axioms and are just written as equations, omitting the horizontal line.

Table 1: Standard Equational Inference Rules.

(reflexivity) e = e

e = f ; (symmetry) ; f = e

e = f, f = g

(transitivity)

e = g

e_{1} = e_{2}, f_{1} = f_{2}

(+-congruence)

e_{1} + f_{1} = e_{2} + f_{2}

e_{1} = e_{2}, f_{1} = f_{2}

(∗-congruence)

e_{1} ∗ f_{1} = e_{2} ∗ f_{2}

e = f

(−-congruence)

−e = −f

To capture the properties of arithmetic, we will need some additional axioms. These equational axioms for arithmetic are all the aeq’s of the forms given in Table ??.

Table 2: Equational Axioms for Arithmetic

(e + f) + g = e + (f + g) (associativity of +) (e ∗ f) ∗ g = e ∗ (f ∗ g) (associativity of ∗)

e + f = f + e (commutativity of +) e ∗ f = f ∗ e (commutativity of ∗) 0 + e = e (identity for +) 1 ∗ e = e (identity for ∗) e + (−e) = 0 (inverse for +) e ∗ (f + g) = (e ∗ f) + (e ∗ g) (distributivity)

Definition 5. An arithmetic equational proof is a finite sequence of aeq’s such that every aeq in the sequence follows from aeq’s earlier in the sequence by one of the standard equational inference rules or axioms of arithmetic. An aeq, e = f, is equationally provable, written

⊢ e = f,

iff it is the last equation of some proof.

A crucial property of formal proofs is that they can be checked automatically, i.e., by a program, without any need for “understanding” of the subject matter by the checker. Adding comments to an equational proof can make proof checking easier, but it is not strictly necessary, since it is not hard to program a checker for uncommented proofs.

Figure ?? contains a formal proof of the equation (f+g)+−g = f. For the reader’s convenience, the names of the rules from which each equation follows have been included as a comment after the equation.

Figure 1: An arithmetic equational proof.

g + −g = 0 (inverse for +) f = f (reflexivity)

f + (g + −g) = f + 0 (congruence)

(f + g) + −g = f + (g + −g) (associativity of +) (f + g) + −g = f + 0 (transitivity)

f + 0 = 0 + f (symmetry)

(f + g) + −g = 0 + f (transitivity)

0 + f = f (identity for +) (f + g) + −g = f (transitivity)

Using this formal proof, we can show:

6.044J/18.423J Handout 3: Notes on Proving Arithmetic Equations 5 Lemma 2. For all ae’s e,

⊢ 0 = 0 ∗ e.

Proof: Figure ?? exhibits a formal proof with rule names as comments.

Figure 2: A proof of 0 = e ∗ 0.

0 + 1  =  1  (identity for +)
e  =  e  (reflexivity)
e ∗ (0 + 1)  =  e ∗ 1  (congruence)
e ∗ 1  =  e ∗ (0 + 1)  (symmetry)
e ∗ (0 + 1)  =  (e ∗ 0) + (e ∗ 1)  (distributivity)
e ∗ 1  =  (e ∗ 0) + (e ∗ 1)  (transitivity)
−(e ∗ 1)  =  −(e ∗ 1)  (reflexivity)
(e ∗ 1) + −(e ∗ 1)  =  ((e ∗ 0) + (e ∗ 1)) + −(e ∗ 1)  (congruence)
⋮

(Insert proof from Fig. ??

with f, g replaced by e ∗ 0, e ∗ 1, respectively).

⋮

(e ∗ 1) + −(e ∗ 1)  =  e ∗ 0  (transitivity)
(e ∗ 1) + −(e ∗ 1)  =  0  (inverse for +)
0  =  (e ∗ 1) + −(e ∗ 1)  (symmetry)
0  =  e ∗ 0  (transitivity)

The axioms of Table ?? are so fundamental that they have a special mathematical name: the commutative ring axioms. Any set of elements with +, ∗, − operations satisfying these axioms is called a commutative ring. In addition to ℤ, other examples of commutative rings are the real numbers, ℝ, the complex numbers, ℂ, and the integers modulo n (for n > 1). Problem 1. 1(a) Show that ⊢ −e = −1 ∗ e. 1(b) Show that ⊢ 1 = −1 ∗ −1. Problem 2. Define the set of Arithmetic Equational Theorems (aet’s) inductively as follows:

• every equational axiom of arithmetic is an aet.

• if all the antecedents of a standard equational inference rule are aet’s, then so is the consequent.

Prove that the set of equationally provable aeq’s equals the set of aet’s.

Problem 3. For arithmetic expressions e, f and variable x, the substitution, e[x := f], of f for x in e is defined by induction on e:

x[x := f] = f,
c[x := f] = c for any constant or variable, c, distinct from x,
(−e_{0})[x := f] = −(e_{0}[x := f]),
(e_{0} op e_{1})[x := f] = e_{0}[x := f] op e_{1}[x := f], where op ∈ {+, ∗} .

3(a) Prove that

⊢ f = g implies ⊢ e[x := f] = e[x := g].

3(b) Prove that

⊢ e = g implies ⊢ e[x := f] = g[x := f].

Problem 4. Repeat Problem ??, using the results of the previous two problems to simplify the argument.

The validity of the distributivity axiom—Lemma 1—followed directly from the distributivity of the integers and definition of the value of an ae. It is equally easy to see that all the other equational axioms of arithmetic of Table ?? are valid as well.

A rule of inference is validity-preserving if the consequent of the rule is valid whenever all its antecedents are valid. For example, it follows directly from the symmetry of mathematical equality, that the (symmetry) inference rule of our formal equational proof system is validitypreserving. Clearly all the standard equational inference rules of Table ?? are also validitypreserving. As a consequence, we have:

Theorem 1. (Soundness)

⊢ e = f implies ⊧ e = f.

Proof: Immediate by induction on the definition of arithmetic equational theorems given in Problem ??, using the fact that the inference rules are validity-preserving.

6.044J/18.423J Handout 3: Notes on Proving Arithmetic Equations 7

3 Canonical Forms

The only numerals defined to occur in aeq’s are 0 and 1—not 2, 3, …. We don’t need these other numerals since there are expressions for them, e.g., (1 + 1) is an expression whose meaning is the integer two. It is useful to have a standard expression, or canonical form, for every integer: Definition 6. For integers n ≥ 0 define ae’s n̂ and ˆ−n inductively:

• ˆ0 = 0,

• { \atop n + 1} = (1 + n̂),

• { \atop −(n + 1)} = ((-1) + ˆ−n)

For example,

                            ˆ3 is (1 + (1 + (1 + 0))),
                           ˆ−2 is ((-1) + ((-1) + 0)).

Problem 5. Prove that \left⟦{ \atop n̂}\right⟧V = n for all n ∈ ℤ and valuations V. Problem 6. 6(a) Show that ⊢ (1 + n̂) = { \atop n + 1} for all n ∈ ℤ. 6(b) Show that ⊢ ((-1) + n̂) = { \atop n − 1} for all n ∈ ℤ. 6(c) Show that ⊢ (n̂ + m̂) = { \atop n + m} for all m, n ∈ ℤ. (hint: Induction on magnitude of n.) 6(d) Show that ⊢ (n̂ * m̂) = { \atop n × m} for all m, n ∈ ℤ. 6(e) Show that ⊢ (-n̂) = ˆ−n for all n. ∈ ℤ.

6(f) Let e be an arbitrary ae in which there are no occurrences of variables. Conclude that for all valuations V,

⊢ e = { \atop ⟦e⟧V}.

(hint: Structural induction on e.)

Lemma 3. (Completeness for Constant Expressions) Let e, f be ae’s in which there are no occurrences of variables. Then

⊧ e = f implies ⊢ e = f.

Proof: Choose some fixed valuation V. From ⊧ e = f, we have ⟦e⟧V = ⟦f⟧V = n for some n ∈ ℤ. By ??, part (f), ⊢ e = n̂ and ⊢ f = n̂, so ⊢ e = f by symmetry and transitivity.

The usual canonical form for a polynomial in x is

c_{n}x^{n} + c_{n−1}x^{n−1} + … + c_{0}

where the leading coefficient c_{n} is nonzero. We use instead the “sparse” canonical form

c_{n_{1}}x^{n_{1}} + c_{n_{2}}x^{n_{2}} + … + c_{n_{k}}x^{n_{k}}

where n_{1} > n_{2} > … and all coefficients are nonzero. We generalize to more than one variable by treating, for example, a polynomial in variables y and x as a polynomial in y with coefficients which are polynomials in x. Here is the precise definition:

Definition 7. For any ae e and integer n ≥ 1, let e^{1} ::= e and e^{n+1} ::= (e * e^{n}).

Let L be a sequence of distinct variables. An L-canonical arithmetic expression of degree d ≥ 0 is defined by induction on the length of L:

• if L is empty, then the L-canonical ae’s of degree 0 are precisely the ae’s of the form n̂ for n ∈ ℤ. In this case, there are no L-canonical ae’s of positive degree.

• if L begins with the variable x and L′ is the rest of L, then the L-canonical ae’s of degree d are defined by induction on d:

– the L-canonical ae’s of degree 0 are the L′-canonical ae’s (no matter what their degrees).

– The L-canonical ae’s of degree d + 1 are those ae’s of the form

                                    ((a * x^{d+1}) + c)

where a ≠ 0 is an L′-canonical form (of any degree) and c is an L-canonical form of degree ≤ d.

Problem 7. Describe an x, y, z-canonical form with the same meaning as ((x + ( ˆ−3 ∗ y^{2})) + z^{3})^{2}.

Theorem 2. Let e be an arithmetic expression and L a sequence of distinct variables including all the variables occurring in e. Then there is an L-canonical form c such that ⊢ e = c.

Proof: (Sketch) First prove by induction on d that the sum of an L-canonical form of degree d and any L-canonical form is provably equal to an L-canonical form. Use this to prove that a product of two L-canonical forms, as well as the negative of an L-canonical form, is provably equal to an L-canonical form. Then proceed by structural induction on e.

Lemma 4. If c and d are syntactically distinct L-canonical forms for some L, then ⟦c⟧ ≠ ⟦d⟧.

Proof: (Sketch) By induction on the length of L. The induction step uses the fact that if p, q are polynomials in the same variable, x, with real number coefficients, then if the degree of p is greater than that of q, or they have the same degree and the absolute value of the leading coefficient of p is greater than that of q, then the absolute value of p is greater that the absolute value of q for all large enough values of x.

Theorem 3. (Completeness) For all ae’s e, f,

⊧ e = f implies ⊢ e = f.

Proof: Let L be a sequence of distinct variables including all the variables occurring in either of e or f. By Theorem ??, ⊢ e = c and ⊢ f = d for some L-canonical forms c, d. By Soundness, we have ⟦e⟧ = ⟦c⟧ and ⟦f⟧ = ⟦d⟧. Now if ⊧ e = f, then ⟦e⟧ = ⟦f⟧, so ⟦c⟧ = ⟦d⟧. Then by Lemma ??, c and d must be syntactically identical, so we really have ⊢ e = c and ⊢ f = c, from which ⊢ e = f follows by symmetry and transitivity.

Problem 8. Let e be an ae and L a sequence of distinct variables including all the variables in e. Show that there is a unique L-canonical form c such that ⊢ e = c.

The development above extends easily to arithmetic expressions over the real numbers simply by allowing valuations in which the values of variables may be real numbers. (For uniformity, we keep the syntax unaltered, so the only numbers definable by variable-free ae’s are still the integers.) We say an aeq e = f is valid over the reals,

⊧_{ℝ} e = f,

iff it holds for all real-valued valuations. Since we are now considering two notions of validity— over the reals and over the integers—we’ll use the notation ⊧_{ℤ} for ⊧ when it is helpful to emphasize our original notion of validity.

Problem 9. Prove that

⊧_{ℝ} e = f iff ⊧_{ℤ} e = f.

4 Arithmetic Inequalities

We can extend our formal proof system to include arithmetic inequalities.

Definition 8. An arithmetic inequality (aineq) is an expression of the form (e <= f) where e, f are ae’s. The aineq is true at valuation V, written

                                 V ⊧ (e <= f)

iff ⟦e⟧V ≤ ⟦e⟧V. The equation is valid, written

                                  ⊧ (e <= f)

iff it is true at all valuations, that is, iff ⟦e⟧ ≤ ⟦f⟧.

As we did with equations, we will stop using teletype font for formal symbols like <= which appear in aineq’s, writing them instead as ordinary mathematical symbols, e.g., “≤.” Some additional formal inference rules for proving inequalities are given in Table ??.

Table 3: Inference Rules for Inequalities.

e = f

(≤-reflexivity) e ≤ f

e ≤ f, f ≤ e

(≤-antisymmetry)

f = e

e ≤ f, f ≤ g

(≤-transitivity)

e ≤ g

e ≤ f

(+-≤-congruence)

e + g ≤ f + g

e ≤ f, 0 ≤ g

(∗-≤-congruence)

e ∗ g ≤ f ∗ g

e ≤ f

(−-≤-congruence)

−f ≤ −e

0 ≤ 1 (01-axiom)

We now have two proof systems, the original one for equality with the rules in Tables ?? and ??, and the extension of this system by the rules for inequalities in Table ??. We’ll use the notations ⊢ _{=} and ⊢ _{≤} when it’s useful to emphasize the relevant proof system.

Problem 10. Completeness for constant inequalities.

10(a) Show that n ≤ m iff ⊢ _{≤} (n̂ <= m̂).

10(b) Conclude that if e, f are ae’s with no occurrences of variables, then

⊧ e ≤ f implies ⊢ _{≤} e ≤ f.

By Problem ??, we know that ⊢ _{≤} is complete for inequalities between aeq’s without variables. Given our success in finding a complete proof system for arithmetic equalities over the integers even if variables do occur, we might hope to achieve the same thing for inequalities.

However, there are some notable contrasts between equations and inequations. For example, Problem ?? reveals that the same equations are valid whether we consider meanings over the integers, ℤ, or the real numbers, ℝ. In fact, exactly the same equations are valid over the complex numbers, ℂ. Not so for inequations. For example, let ℝ^{+} denote the positive real numbers. The complex numbers can be partially ordered by the relation, ⊑, where c⊑d iff d − c ∈ ℝ^{+} ∪ {0}. If we interpret the symbol ≤ to mean the relation ⊑, then we have:

⊧_{ℤ} 0 ≤ e ∗ e,
⊧_{ℝ} 0 ≤ e ∗ e, but
|̸=_{ℂ} 0 ≤ e ∗ e.

This remark implies a limitation of the proof rules for ⊢ _{≤}, namely:

Lemma 5. (Incompleteness for ⊢ _{≤}) There is an arithmetic inequality which is valid over the integers but not ⊢ _{≤}-provable, namely,

⊧_{ℤ} 0 ≤ x ∗ x,
⊬_{≤} 0 ≤ x ∗ x.

Proof: All the rules of ⊢ _{≤} are validity-preserving over the complex numbers with ≤ interpreted as ⊑, so an inequality which is not valid over the complexes cannot be provable.

This particular discrepancy between validity and provability can be regarded an oversight in the design of our proof system. We could repair it simply by adding the “missing” inequality as an axiom. That is, if we define ⊢ _{2} to have the rules of ⊢ _{≤} along with the axiom 0 ≤ e ∗ e, then the resulting proof system remains sound over the integers (though not any more over the complexes partially ordered by ⊑). Now, of course, the formerly missing inequality is immediately ⊢ _{2}-provable.

But ⊢ _{2} is also incomplete over the integers.

Lemma 6. (Incompleteness for ⊢ _{2}) There is an arithmetic inequality which is valid over the integers but not ⊢ _{2} provable, namely,

⊧_{ℤ} e ≤ e ∗ e,
⊬_{2} x ≤ x ∗ x.

Proof: All the rules of ⊢ _{2} are validity-preserving over the real numbers, so the inequality x ≤ x ∗ x, which is not valid over the reals, cannot be provable.

Now we might similarly define ⊢ _{3} to have the rules of ⊢ _{2} along with the further rule e ≤ e∗e. At this point, it is no longer so easy to show incompleteness for ⊢ _{3}. On the other hand, neither is there an apparent reason to expect ⊢ _{3} to be complete for integer inequalities.

Nevertheless, we can be sure that ⊢ _{3} is not complete. One of the great mathematical results of the Twentieth Century implies that there is no sound, complete proof system for arithmetic inequalities over the integers. In fact, given a proof checking program for any sound proof system for integer inequalities, it is possible to construct, from the text of the checking program, a valid inequality which has no proof recognizable by the checker! This is one of the consequences of Gödel’s Incompleteness Theorem and Matiyasevich’s negative solution to Hilbert’s Tenth Problem^{1}, topics which we take up later.

Problem 11. For discussion: We have explained that, given any proof checking program for a sound proof system for arithmetic inequalities over the integers, we can construct a valid inequality which has no proof in the system. But if the inequality has no proof, how can we possibly know it is valid?

1cf. Hilbert’s Tenth Problem, Yuri V. Matiyasevich, MIT Press, c. 1993, 264 pp.