5.2  Terms, Formulas, Free Variables and Substitution

Section 5.1 read quantified sentences by eye. That is enough to understand them, and not enough to reason with them: every quantifier rule of Sections 5.3 to 5.6, and the rule for using an equation in Section 5.7, has the form “put the term t in for the variable x in φ”, written φ[t/x], and a rule has to say exactly which symbols change. This section makes the language of Section 5.1 exact, in the way Section 4.1 made the propositional language exact, says exactly what φ[t/x] does, and names the one way it goes wrong, capture.

5.2.1. Which letters are holes

Three sentences, over the domain N:

  • “x>2” is not a statement. It is the open sentence of item (e) of Example (Statements and nonstatements), true for some values of x and false for others.
  • “∀x(x2≥0)” is a statement, and a true one. The letter x still appears, but the quantifier has closed its hole: the sentence does not ask which x we mean.
  • “∀x(x≥y)” is neither true nor false as it stands. It is true when y is 0 (every natural number is at least 0) and false when y is 1 (the number 0 is not at least 1). It is an open sentence in y, although it begins with a quantifier.

So the question “is this a statement?” is not answered by looking for quantifiers. It is answered by asking which letters are still holes. In the third sentence x is closed by ∀x and y is open. The open letters will be called free, and the closed ones bound.

Here is why the difference matters for reasoning. Over N, the sentence ∃y(y≠x) is an open sentence in x, and it is true for every x: given x, the number y=x+1 differs from it. Now suppose that we want to say the same thing about a particular number named by another letter, and we put y in for x without thinking. The result is ∃y(y≠y), “some number differs from itself”, which is false. Nothing about numbers went wrong. The y that we put in landed inside the scope of ∃y, and the quantifier took hold of it: the new y was meant to name a number from outside, and it has become the quantifier’s own placeholder. This is capture.

Capture is the one trap of substitution, and the rules of Sections 5.3 to 5.7 substitute at almost every step. So we need exact answers to three questions: what the expressions are that can be put in; which occurrences of x get replaced; and when putting t in for x is safe.

5.2.2. Terms and formulas

The first things to build are the names of objects.

A term is a name of an object, built from variables and constants by function symbols.

Definition 5.2.1 (Term)

The terms are the strings given by the following clauses.

  • (Tm1) Every variable is a term, and every constant symbol is a term.
  • (Tm2) If f is a function symbol of arity n and t1,…,tn are terms, then f(t1,…,tn) is a term.
  • (Tm3) Nothing else is a term: a string is a term only if it is the last entry of a finite list of strings in which every entry is a variable, a constant symbol, or f(s1,…,sn) for some function symbol f of arity n and earlier entries s1,…,sn.

In words: variables and constants are terms, a function symbol applied to as many terms as it has places is a term, and nothing else is.

A variable of a term t is a variable that occurs in t. A term with no variables, such as 2 or f(c), names one fixed object once the symbols are interpreted; a term with variables, such as x+1, names an object only once its variables have values.

Shorthand. We write terms in the familiar way: x+y for +(x,y), x2, |x|, an for a(n) (a sequence is a function symbol, as Section 5.1 said). School conventions about grouping say which term is meant.

Here are terms, simplest first.

  • x and 2: by (Tm1). The degenerate terms, built in no steps; every argument about all terms has to handle them.
  • x+1, officially +(x,1): by (Tm2) from the terms x and 1.
  • f(f(c)): by (Tm2) twice, from c, for a one-place f. Its only building blocks are constants, so it has no variables.
  • |an−L|, officially |⋅|(−(a(n),L)), with the two-place minus: by (Tm2) three times, from the variables n and L. Its variables are n and L. The letter a is a function symbol, not a variable.
Second readingThe symbols of the language, strings that are not terms, and two more shorthand rules

Section 4.1 described the propositional language by its alphabet and its formation rules. The language of predicate logic has more symbols, of more kinds.

  • Variables: x,y,z,u, with subscripts x0,x1,y0,…, and in analysis also ε,δ,N,n,k,L. There are infinitely many, so that a fresh one is always available. Each is one symbol.
  • Constant symbols, such as 0, 1, 2, a, b, c. (A letter may be a constant in one language and a function symbol in another: in a language with a sequence, a is the sequence’s one-place function symbol, as below, and not a constant.)
  • Function symbols, each with a number of places n≥1, its arity: f and g, the arithmetic symbols +, ⋅ and − (two places), and − in front of a number, halving ⋅/2, squaring and |⋅| (one place). The one-place and the two-place minus are different symbols written alike; the number of terms they are applied to shows which is meant.
  • Predicate symbols, each with an arity n≥1: P,Q,R,S, <, ≤, >, ≥, Prime, and ∈A for a fixed set A (one place, as in Section 5.1).
  • Equality =, which every language has.
  • The constant ⊥, the connectives ¬,∧,∨,→,↔ of Chapter 4, and the quantifier symbols ∀ and ∃.
  • Parentheses (, ), and the comma.

Which constant, function, and predicate symbols are available depends on the subject. For the argument of Section 5.1 we need the constant 2 and the one-place predicate symbols P and S. For arithmetic we need 0, 1, +, ⋅, and <. Every formula uses only finitely many symbols, and we never need to fix the whole list in advance.

Strings that are not terms, each by one clause:

  • x<1 is not a term. It does not name an object; it says something about one. It is built with a predicate symbol, and (Tm2) uses only function symbols. It will be a formula.
  • f(x,y), for a one-place f, is not a term: (Tm2) applies f to exactly one term.

Terms can be drawn as trees, exactly as formulas were in Section 4.1: a variable or a constant is a single node, and f(t1,…,tn) is a node labeled f with the trees of t1,…,tn below it, in order. And a term can be read in only one way. The proof is the proof of unique readability for formulas in Section 4.3 (Theorem 4.3.3), with the parentheses and commas of (Tm2) doing the work that the parentheses of (F3) did there. We do not repeat it.

Shorthand rules 1 and 3.

Rule 1. Two-place predicate symbols such as <,≤ are written between their terms: x<y is shorthand for <(x,y). The one-place symbol ∈A is written after its term: t∈A is shorthand for (∈A)(t). (When sets are themselves objects of the domain, ∈ is a two-place predicate symbol and x∈A is ∈(x,A); in this chapter A is a fixed set, except in one example of Section 5.7 where sets are the objects, so we treat ∈A as one-place.) We write t1≠t2 for ¬(t1=t2). Rule 3. The bounded quantifiers of Definition 5.1.1, ∀x∈Aφ and the rest, stand for the formulas given there.

Next, the statements and open sentences. Atomic formulas say something about terms; everything else is built from them by connectives and quantifiers.

A first-order formula is built from predicates applied to terms, by the connectives and the two quantifiers.

Definition 5.2.2 (First-Order Formula)

The formulas (of predicate logic, or first-order formulas) are the strings given by the following clauses.

  • (Fm1) Atomic formulas. If R is a predicate symbol of arity n and t1,…,tn are terms, then R(t1,…,tn) is a formula. If t1 and t2 are terms, then t1=t2 is a formula. And ⊥ is a formula.
  • (Fm2) If φ is a formula, then ¬φ is a formula.
  • (Fm3) If φ and ψ are formulas, then (φ∧ψ), (φ∨ψ), (φ→ψ), and (φ↔ψ) are formulas.
  • (Fm4) If φ is a formula and x is a variable, then ∀xφ and ∃xφ are formulas.
  • (Fm5) Nothing else is a formula: a string is a formula only if it is the last entry of a finite list in which every entry is an atomic formula, or is built by (Fm2), (Fm3) or (Fm4) from earlier entries.
  • (Fm1): the atomic formulas, a predicate symbol with its terms, or an equation, or ⊥, take the place of Chapter 4’s atoms.
  • (Fm2), (Fm3): the connectives, as before.
  • (Fm4): puts ∀x or ∃x, with a variable x, in front of a formula, without parentheses, as ¬ is.

Structural induction and recursion (Theorem 4.3.1, Theorem 4.3.4) carry over to terms and first-order formulas, with the atomic formulas as base case and one new building step for each quantifier (the fold below says how).

Second readingInduction and recursion on formulas

The base case covers every atomic formula (and ⊥), and there are two new building steps, from φ to ∀xφ and to ∃xφ, for every variable x, each with one part, like the step to ¬φ. So, to prove that every formula has a property, prove it for the atomic formulas and ⊥, and prove that it passes from φ to ¬φ, ∀xφ, and ∃xφ, and from φ,ψ to (φ∘ψ). To define a function on formulas, give one clause for each of these cases. The proofs in Section 4.3 go through word for word with the new cases added, and unique readability holds for the same reason; we use all three without repeating them. The same two principles hold for terms, with (Tm1) as the base case and (Tm2) as the one building step.

Shorthand. The conventions of Section 4.1 for dropping parentheses stay, with three additions. Rules 1 and 3 (predicate symbols written between their terms, as in x<y; bounded quantifiers as abbreviations) are in the fold on the symbols of the language, above; rule 2 matters in every section:

Rule 2. A quantifier binds as tightly as ¬: it applies to the smallest formula that follows it. So ∀xP(x)→Q(c) stands for (∀xP(x)→Q(c)), an implication whose hypothesis is ∀xP(x). For the quantifier to govern the whole implication, write ∀x(P(x)→Q(x)), where the parentheses are the official ones around the implication.

Rule 2 matters in every rule section. The formula ∀xP(x)→Q(c) has main connective →, while ∀x(P(x)→Q(x)) has main symbol ∀x. The rule for using a “for every” (Section 5.3) applies only to the second.

Parse trees. A parse tree for a first-order formula is drawn as in Section 4.1, with one new kind of node: a quantifier node, labeled ∀x or ∃x, with the tree of the formula it governs as its only subtree. The leaves are atomic formulas (or ⊥); their terms have trees of their own, which we do not draw. Here is the tree of ∀x(P(x)→∃yR(x,y)).

Diagram. Labels: forall x, to, P(x), exists y, R(x, y)

The root is the quantifier node ∀x, so the formula’s main symbol is ∀x. Below it is the implication, with the atomic formula P(x) on the left and the quantifier node ∃y on the right, which governs the atomic formula R(x,y).

Quick check. Draw the parse tree of ∀xP(x)→∃y∀xR(x,y), written in shorthand. What is its main symbol?

Solution. By shorthand rule 2, each quantifier applies to the smallest formula after it, so the official formula is (∀xP(x)→∃y∀xR(x,y)) and its main symbol is →. The root is →. Its left subtree is the node ∀x above the leaf P(x). Its right subtree is the node ∃y, below it the node ∀x, and below that the leaf R(x,y). The two ∀x nodes are on different branches.

5.2.3. Free and bound: drawing the arrows

The parse tree shows which quantifier governs which part of a formula. That is exactly what decides whether a letter is a hole. Draw an arrow from each occurrence of a variable to the nearest quantifier on that variable above it in the parse tree. An occurrence with an arrow is bound; one with none is a hole still open.

Diagram. Labels: P(, x, ) wedge, forall x, \,(Q(, ) to, exists y, \,R(, ,\,, y, ))

Figure B. Each bound occurrence points to its quantifier. The first x points nowhere: it is free.

An occurrence of a variable is bound if a quantifier on that variable stands above it in the parse tree; otherwise it is free.

Definition 5.2.3 (Free and Bound Variables)

Let φ be a formula and x a variable. An occurrence of x in φ is an appearance of x inside one of the terms of an atomic formula of φ. (The x written just after a quantifier symbol, as in ∀x, is part of the quantifier node and is not an occurrence.)

  • An occurrence of x is bound if the path from its leaf up to the root of the parse tree passes through a quantifier node ∀x or ∃x, with the same variable x. The lowest such node binds the occurrence.
  • An occurrence that is not bound is free.
  • The scope of a quantifier node is the part of the tree below it: the formula it governs.
  • The variable x is a free variable of φ, or is free in φ, if at least one occurrence of x in φ is free.

A variable appears in φ if it is written anywhere in φ: inside a term, or just after a quantifier symbol. Every freshness condition of this chapter is stated with “appear”; in practice, a fresh letter is one written nowhere yet.

Definition 5.2.4 (Sentence)

A sentence is a formula with no free variables.

A sentence is what Chapter 1 called a statement, once the domain and the symbols are fixed: every hole is closed, so it is true or false. A formula with free variables is an open sentence, true or false only once values are given to its free variables.

Examples. The domain is irrelevant to all of them: being free or bound is a matter of the string, not of what it means.

  • ∀x(x≥y): the occurrence of x is bound by ∀x; the occurrence of y has no quantifier on y above it, so it is free. The free variables are y alone. Not a sentence.
  • P(x)∧∀xQ(x): the occurrence of x in P(x) is free (no quantifier stands above it: the ∀x governs only Q(x)), and the occurrence in Q(x) is bound. So x is a free variable of this formula, and it is not a sentence.
  • ∀x∃xP(x): the occurrence of x has two quantifiers on x above it, and the lower one, ∃x, binds it. The outer ∀x binds nothing. A sentence.
Second readingOccurrences, ‘appear’, and the recursive description of ‘free’

In words: an occurrence of x is bound when it lies in the scope of a quantifier on x; quantifiers on other variables do not bind it. If several quantifiers on x stand above it, the nearest one, the lowest in the tree, is the one that binds it. A free occurrence is a hole still open. A variable is free in a formula if it has at least one free occurrence, even if it has bound occurrences too.

So y appears in ∀yP(x), although it has no occurrence there. A variable that does not appear in φ has no occurrence in φ, and no quantifier of φ is on it; that is why the freshness conditions use “appear”.

Three more examples:

  • ⊥ and P(c) are sentences: they contain no variables at all. So is ∀xP(c). These are the degenerate cases.
  • ∀x(x2≥1): the single occurrence of x lies below the node ∀x, so it is bound. A sentence.
  • ∀x(P(x)→∃yR(x,y)), the parse tree drawn above: both occurrences of x are bound by the root; the occurrence of y in R(x,y) is bound by ∃y. A sentence.

The recursive description. In proofs about all formulas we need “x is free in φ” in the form that structural induction can use, one case per clause of Definition 5.2.2.

  • x is free in an atomic formula exactly when x occurs in one of its terms; x is never free in ⊥.
  • x is free in ¬φ exactly when x is free in φ.
  • x is free in (φ∘ψ) exactly when x is free in φ or in ψ.
  • x is free in ∀yφ, and in ∃yφ, exactly when x is a different variable from y and x is free in φ.

Each line is read off the tree. In an atomic formula there are no quantifier nodes, so every occurrence is free. The tree of ¬φ or (φ∘ψ) adds a root that is not a quantifier node, so it binds nothing. The tree of ∀yφ adds the root ∀y on top of the tree of φ: an occurrence of x inside φ keeps its path, with one more node at the top, so it is free in ∀yφ exactly when it was free in φ and the new node is not a quantifier on x, that is, when x and y are different variables.

Second readingThe free variables of a limit statement
Example (The free variables of a limit statement)

With the conventions of Section 5.1 (domain R, the sequence as a function symbol a), “the sequence (an) converges to L” is the formula ∀ε>0∃N∈N∀n∈N(n≥N→|an−L|<ε). Write it without bounded quantifiers, and find its free variables. Is it a sentence?

Solution. Unfolding the three bounded quantifiers by Definition 5.1.1 (→ under each ∀, ∧ under the ∃) gives ∀ε(ε>0→∃N(N∈N∧∀n(n∈N→(n≥N→|an−L|<ε)))). The variables that occur are ε, N, n, and L. Check each.

  • Every occurrence of ε lies below the root ∀ε: bound.
  • Every occurrence of N lies below ∃N: bound.
  • Every occurrence of n (in n∈N, in n≥N, and in the term an) lies below ∀n: bound.
  • The occurrence of L has no quantifier on L above it: free.

So L is the only free variable, and the formula is not a sentence. It is an open sentence in L, as it should be: until L is given a value, “(an) converges to L” is neither true nor false, and which values make it true depends on the sequence (for an=1/(n+1) the value L=0 does and L=1 does not; for an=(−1)n no value does). Putting ∃L in front gives the sentence “(an) converges”.

The other symbols in it are not variables, and “free” and “bound” do not apply to them. The letter a is a function symbol; the formula is certainly about the sequence a, but a is fixed by the language, like +, and cannot be quantified in this logic. The symbol ∈N is a one-place predicate symbol, 0 is a constant, and >, ≥, <, − and |⋅| are predicate and function symbols of the language.

Warning. The same letter can occur free and bound in one formula. In P(x)∧∀xQ(x), the first x is a hole and the second is the quantifier’s placeholder, and the two have nothing to do with each other. This is legal, and it is a trap for the reader: a proof that “uses x” from such a formula has to say which x it means. The book avoids it by renaming the bound variable (the last part of this section explains how): P(x)∧∀zQ(z) says the same thing, and the question does not arise.

Quick check. Is x free in ∀y(x<y)→∃x(x=0)? At which occurrences?

Solution. Yes. By shorthand rule 2 the formula is (∀y(x<y)→∃x(x=0)). The occurrence of x in x<y lies below ∀y only, which is a quantifier on y, so it is free. The occurrence of x in x=0 lies below ∃x, so it is bound. One free occurrence is enough: x is a free variable of the formula. The variable y, by contrast, is not free: its only occurrence lies below ∀y.

5.2.4. Substitution, by example first

We now come to the operation that every quantifier rule uses. The rule of Section 5.3 will take the premise ∀x(P(x)→S(x)) of Section 5.1’s argument and produce P(2)→S(2): it strips the quantifier and puts 2 in for x. The rule of Section 5.5 goes the other way. Both need to say exactly what “put 2 in for x” does. The answer has one principle: only the free occurrences are replaced, because only they are holes. A bound occurrence belongs to its quantifier, and the quantifier is not asking for a value.

φ[t/x] is φ with t put in for every free occurrence of x, and nothing else changed.

Example (Four substitutions)

Compute each substitution by the rule in the slogan above.

  • (a) (P(x)→S(x))[2/x].
  • (b) (x<y∧∀x(x≥0))[(y+1)/x].
  • (c) (∀yR(x,y))[f(z)/x].
  • (d) (∀xP(x))[c/x].

Solution. (a) The implication passes the substitution to both sides, and in each atomic formula the term x becomes 2: the result is P(2)→S(2). This is the step that Section 5.3’s rule makes in the argument of Section 5.1.

(b) The conjunction passes it to both parts. In x<y the x becomes y+1, giving y+1<y. In ∀x(x≥0) the quantifier is on x, so the substitution stops. The result is y+1<y ∧ ∀x(x≥0). Only the free occurrence of x changed. The bound one, in x≥0, was the quantifier’s placeholder, and replacing it would have turned the sentence “every x is at least 0” into a claim about y+1.

(c) The quantifier is on y, a variable different from x, so it passes the substitution on: the result is ∀yR(f(z),y).

(d) The quantifier is on x, so nothing changes: the result is ∀xP(x). There was no free x to replace.

Here are the clauses those computations followed.

Definition 5.2.5 (Substitution of a Term for a Variable)

Let t be a term and x a variable. For a term s, the term s[t/x] is s with every occurrence of x replaced by t; by recursion on terms, x[t/x]=t,y[t/x]=y  for a variable y≠x,c[t/x]=c,f(s1,…,sn)[t/x]=f(s1[t/x],…,sn[t/x]). For a formula φ, the formula φ[t/x], read “φ with t for x”, is defined by recursion on φ: R(s1,…,sn)[t/x]=R(s1[t/x],…,sn[t/x]),(s1=s2)[t/x]=(s1[t/x]=s2[t/x]),⊥[t/x]=⊥,(¬φ)[t/x]=¬(φ[t/x]),(φ∘ψ)[t/x]=(φ[t/x]∘ψ[t/x]),(∀xφ)[t/x]=∀xφ,(∀yφ)[t/x]=∀y(φ[t/x])  for a variable y≠x, and the last two lines likewise with ∃ in place of ∀.

A compound term is written in parentheses: φ[(y+1)/x] puts y+1 in for x.

Two facts follow from the definition at once, and both are used again and again.

First, φ[x/x]=φ: putting x in for itself changes nothing. In each clause the replaced symbol is x again.

Second, and more useful: if x is not free in φ, then φ[t/x]=φ, for every term t. Example (d) was one instance. Later sections use it; its proof, a structural induction, is in the fold below.

Second readingThe clauses in words, why the definition defines, and the claim proved

In words, clause by clause: in a term, every x is replaced, since a term has no quantifiers. In an atomic formula, the replacement happens inside its terms. The connectives pass the substitution to their parts. A quantifier on x stops it: below ∀x there is no free occurrence of x to replace. A quantifier on another variable y passes it on.

Well defined. The clauses give one value for each case of Definition 5.2.2, so structural recursion (carried over as above) says that they define exactly one formula φ[t/x] for each φ. And the result is a formula: each clause builds its value by the clauses of Definition 5.2.1 and Definition 5.2.2 from values already known to be terms and formulas.

This is a different operation from the substitution σ of Section 4.5 (the one in Lemma 4.5.3). There, formulas were put in for atoms, at every occurrence. Here a term is put in for a variable, and bound occurrences are left alone.

Claim. Let x be a variable and t a term. For every formula φ: if x is not free in φ, then φ[t/x]=φ.

Idea. Substitution changes only free occurrences of x, and there are none. Formally, structural induction on φ, using the recursive description of “free” case by case. The only case with any content is a quantifier on a variable other than x, where the substitution is passed on, and the induction hypothesis applies because x is still not free inside.

Proof. For terms first: if x does not occur in a term s, then s[t/x]=s, by induction on s (a variable other than x and a constant are unchanged by the clauses, and f(s1,…,sn)[t/x]=f(s1,…,sn) when each si[t/x]=si). Now we prove the claim by structural induction on φ.

Atomic formulas and ⊥. If x is not free in R(s1,…,sn), then x occurs in none of the si (the recursive description), so each si[t/x]=si, and the clause for atomic formulas returns R(s1,…,sn). The same holds for s1=s2, and ⊥[t/x]=⊥.

Connectives. If x is not free in ¬φ, it is not free in φ, so (¬φ)[t/x]=¬(φ[t/x])=¬φ by the induction hypothesis. If x is not free in (φ∘ψ), it is free in neither part, and the same argument applies to both.

Quantifiers. Consider ∀yφ. If y is x, then (∀xφ)[t/x]=∀xφ by the definition, whatever φ is. If y is a different variable and x is not free in ∀yφ, then x is not free in φ (the recursive description), so (∀yφ)[t/x]=∀y(φ[t/x])=∀yφ by the induction hypothesis. The case of ∃yφ is the same.

This proves the claim for every formula φ.

One substitution at a time. φ[t/x] replaces one variable. Two substitutions in a row are made one after the other, and the second acts on the result of the first. So R(x,y)[y/x] is R(y,y), and then [x/y] turns it into R(x,x), not into the swapped R(y,x): the first step has already lost track of which y was which. To swap two variables, go through a letter that appears nowhere: [z/x], [x/y], [y/z] give R(z,y), R(z,x), R(y,x).

Quick check. Compute ((P(x)∧Q(y))[y/x])[x/y]. Which formula would swapping x and y give?

Solution. The first step gives P(y)∧Q(y), and the second P(x)∧Q(x). The swap is P(y)∧Q(x), reached by [z/x], [x/y], [y/z] with a new letter z.

5.2.5. Capture, and the practical rule

The definition of substitution never refuses. Given any φ, t and x, it returns a formula. Sometimes that formula does not say what we meant.

Take φ=∃y(y≠x), the example at the start of the section, and t=y. The quantifier ∃y is on a variable different from x, so the definition passes the substitution through, and (∃y(y≠x))[y/x]=∃y(y≠y). The definition was followed correctly. The meaning is wrong. The formula ∃y(y≠x) says something about the number x: some number differs from it, which over N is true whatever x is. We wanted to say the same thing about the number y, and we got “some number differs from itself”, which is false. The y we put in was supposed to name a number from outside, and it landed in the scope of ∃y and was captured.

Compare a substitution that is safe. Over R, ∀z(x<z) says that x is smaller than every number (false, as it happens, for every x; but what matters is what it says). Put y+1 in for x: the quantifier ∀z passes the substitution on, and (∀z(x<z))[(y+1)/x]=∀z(y+1<z), which says exactly that y+1 is smaller than every number. Nothing was captured, because the term y+1 does not contain z, the only variable quantified above the occurrence of x.

The difference between the safe case and the unsafe one is exactly this: whether a variable of t is quantified somewhere above a free occurrence of x.

A term is free for x when putting it in for x lets none of its variables be captured.

Definition 5.2.6 (Free For)

Let t be a term, x a variable, and φ a formula. The term t is free for x in φ if no free occurrence of x in φ lies in the scope of a quantifier ∀y or ∃y such that y is a variable of t.

In words: look at each place where t will go, that is, at each free occurrence of x. Look at the quantifiers above it in the tree. If none of them is on a variable of t, the substitution is safe there. The term is free for x when it is safe at every such place. Informally: no variable of t becomes bound when t is put in.

Four special cases, each immediate from the definition, cover most uses.

  • A term with no variables (2, c, f(c)) is free for every variable in every formula: there is no y to capture.
  • The variable x is free for x in every formula. A free occurrence of x never lies in the scope of a quantifier on x; if it did, it would be bound.
  • A variable z that does not appear in φ is free for every variable in φ: no quantifier of φ is on z.
  • If x is not free in φ, every term is free for x in φ: there are no free occurrences to check. (And then φ[t/x]=φ by the claim above.)

In our examples: y is not free for x in ∃y(y≠x), because the free occurrence of x lies in the scope of ∃y and y is a variable of the term y. Likewise y+1 is not free for x in ∃y(y>x). And y+1 is free for x in ∀z(x<z): the only quantifier above the free occurrence of x is on z, which is not a variable of y+1.

“Free for” is the precise condition under which φ[t/x] says about t what φ says about x. The rules ∀E (Section 5.3), ∃I (Section 5.5) and =E (Section 5.7) carry it as a side condition.

Second readingA second capture, the recursive description of ‘free for’, and why it asks no more than it needs

Here is a second example, with a compound term. Over R, ∃y(y>x) is true for every x: there is a number larger than x. Put y+1 in for x: (∃y(y>x))[(y+1)/x]=∃y(y>y+1). The result says that some number is larger than its own successor, which is false. It should have said that some number is larger than y+1, which is true.

The recursive description. For induction proofs, “free for” can be read off case by case, like “free”:

  • t is free for x in every atomic formula and in ⊥;
  • t is free for x in ¬φ exactly when it is free for x in φ, and in (φ∘ψ) exactly when it is free for x in both φ and ψ;
  • t is free for x in ∀yφ (and in ∃yφ) exactly when either x is not free in ∀yφ, or y is not a variable of t and t is free for x in φ.

The first two lines hold because an atomic formula has no quantifiers and a connective node is not a quantifier. For the third: if x is not free in ∀yφ, there is nothing to check. If it is free, then y is a different variable and the free occurrences of x in ∀yφ are those in φ; each lies in the scope of the new root ∀y and of the quantifiers inside φ above it. The root is harmless exactly when y is not a variable of t, and the quantifiers inside are harmless exactly when t is free for x in φ.

Section 5.3 shows the capture example of this section turning a true premise into a false conclusion when the side condition is ignored. The definition asks for no more than it needs: a variable of t may be quantified elsewhere in φ, as long as no free occurrence of x lies in its scope. For instance, y is free for x in P(x)∧∃yQ(y), and the result P(y)∧∃yQ(y) says of y what the original said of x.

Before you substitute. Look at each free occurrence of x and at the quantifiers above it. If none of them is on a letter of t, go ahead. If one is, rename that quantifier’s letter to a brand-new letter first (next subsection), and then substitute. Nothing else can go wrong.

Quick check. Is y free for x in ∃y(x<y)∧P(y)? Is x+1?

Solution. By shorthand rule 2 the formula is (∃y(x<y)∧P(y)). The term y is not free for x: the free x of x<y lies under ∃y, and y is a letter of the term. Rename first, ∃z(x<z)∧P(y), and then substitute to get ∃z(y<z)∧P(y). The term x+1 is free for x: the only quantifier above the free x is on y, which is not a letter of x+1.

Warning. Capture changes meaning, and it gives no warning: the definition of φ[t/x] returns a formula either way. Over R, ∃y(y>x) is true for every x, and (∃y(y>x))[(y+1)/x] is ∃y(y>y+1), which is false. Before putting t in for x, check that no variable of t is quantified above a free occurrence of x.

Quick check. Is y+1 free for x in ∀z(x<z)? Is it free for x in ∀y(x<y)? Compute both substitutions and say what each result claims.

Solution. In ∀z(x<z): yes. The only quantifier above the occurrence of x is on z, and z is not a variable of y+1. The result is ∀z(y+1<z), “y+1 is smaller than every number”, which is what the original said about x.

In ∀y(x<y): no. The occurrence of x lies in the scope of ∀y, and y is a variable of y+1. The definition gives ∀y(y+1<y): “every number is larger than its own successor”. That is a sentence about no particular number at all, and a false one; the original said something about x, and the result should have said the same about y+1. The y of y+1 was captured.

5.2.6. Renaming bound variables

What should we do when t is not free for x in φ? A bound variable is a placeholder, and the name of a placeholder does not matter. “Some number differs from x” can be written ∃y(y≠x) or ∃z(z≠x), just as ∫01s2ds and ∫01u2du are the same integral. So the way out is: rename the bound variable first, then substitute.

Renaming. Let φ be a formula and y,z variables, with z not appearing in φ. The formula ∀zφ[z/y] is obtained from ∀yφ by renaming the bound variable y to z; likewise ∃zφ[z/y] from ∃yφ. The same may be done to a quantifier anywhere inside a larger formula.

In words: change the variable after the quantifier, and change the occurrences it binds, to a letter that appears nowhere in the formula. The condition that z does not appear in φ does two jobs. It makes z free for y in φ (the third special case above), so no new z is captured by a quantifier inside φ. And it ensures that no free z already in φ is captured by the new quantifier ∀z. Without it, renaming can change the meaning: ∀y(y≥z) says something about z (over N, that z=0), and “renaming” y to z would give ∀z(z≥z), a sentence that is simply true.

Renaming a bound letter is treated as never changing what a formula says; Sections 5.4 and 5.6 derive it at the front of a formula, and the fold says where the rest stands.

Second readingThe status of renaming

Its status. Renaming is not a rule of the calculus, and we have not proved that it keeps meaning. Here is where it stands. For a renaming at the front of a formula, ∀yφ and ∀zφ[z/y] can each be derived from the other in three lines, once the rules of Section 5.4 are available; that section does it, and Section 5.6 does the same for ∃. A renaming inside a larger formula we take as a convention of this book: formulas that differ only by renaming bound variables are treated as saying the same thing. Its justification in terms of meaning is the one the Looking-ahead box at the end of this section points to.

The recipe. To put t in for x in φ when t is not free for x: rename each quantifier of φ that is on a variable of t and has a free occurrence of x in its scope, each to a different variable that appears neither in φ nor in t (each such step is a renaming in the sense above); then substitute. After the renaming, t is free for x.

  • ∃y(y≠x) with y for x: rename y to z, giving ∃z(z≠x); then substitute, giving ∃z(z≠y), “some number differs from y”. True over N for every y, as intended.
  • ∃y(y>x) with y+1 for x: rename to ∃z(z>x); substitute, giving ∃z(z>y+1). True over R, as intended.

Which fresh letter we choose does not matter: two choices give formulas that differ only by a renaming. From now on, whenever a rule writes φ[t/x], it will require t to be free for x in φ, and if we want a t that is not, we rename first.

5.2.7. How substitution looks in a mathematical proof

Mathematicians substitute constantly and never write [t/x]. Two examples show the operation, and its trap, in their natural habitat.

“Apply the hypothesis with ε/2 in place of ε.” Suppose we know that (an) converges to L, and we have fixed an ε>0 for some other purpose. A proof says: “applying the hypothesis with ε/2, there is an N∈N with |an−L|<ε/2 for all n≥N”. The hypothesis is ∀εφ, with φ = (ε>0→∃N∈N∀n∈N(n≥N→|an−L|<ε)), and the proof uses the instance φ[t/ε] with the term t=ε/2: ε/2>0→∃N∈N∀n∈N(n≥N→|an−L|<ε/2). The term ε/2 contains the variable ε: the fixed ε of the proof, not the bound one of the hypothesis. It is free for ε in φ, because the only quantifiers above the free occurrences of ε in φ are on N and n. Section 5.3’s rule makes this step, and “ε/2>0” then comes from ε>0 by arithmetic.

“Take N=n.” Now suppose the proof has chosen N, so it knows ψ = ∀n∈N(n≥N→|an−L|<ε), with N free. A tempting step is to “apply this with n in place of N”. No rule allows this: N has been chosen, not quantified, so no term may be put in for it. Writing the step out shows how badly it goes wrong, because n is not even free for N in ψ: the occurrence of N lies in the scope of ∀n. The substitution produces ∀n∈N(n≥n→|an−L|<ε), which says that every term of the sequence is within ε of L, a far stronger claim that does not follow. In words, the error is to let the threshold N be “the n we are looking at”, when n is the placeholder of “for all n≥N”. A proof that needs a statement about a particular index names it with a new letter, say m≥N, and substitutes m, which is free for n.

Second readingInduction, as a formula

Induction, as a formula. The display after Axiom 4.2.1 in Section 4.2 used a property P(n). With substitution it can be written for any formula φ in which the variable n is free, as the formula (φ[0/n] ∧ ∀n∈N(φ→φ[(n+1)/n])) → ∀n∈Nφ, where φ[0/n] plays the part of P(0) and φ[(n+1)/n] the part of P(n+1). The term n+1 is free for n in φ: its only variable is n, and a free occurrence of n never lies in the scope of a quantifier on n. This is how the principle of induction reads in the language of this chapter; its status (a basic property of N) is unchanged.

Second readingPartial terms

Mathematics writes 1/x and liman, which name nothing for some values: x=0, or a sequence with no limit. In the language of this chapter every term names an object, because every function symbol is defined everywhere on the domain. Mathematics keeps partial operations out of trouble with hypotheses: 1/x is written only under x≠0, as in ∀x(x≠0→x⋅(1/x)=1), where the value at 0 is never used; and “the limit” is written only after it has been proved that there is exactly one (Section 5.8). Some logics allow terms that name nothing; this book does not need them.

Remark (Looking ahead). Chapter 7 proves, in an optional section, that renaming a bound letter never changes the meaning of a formula.

5.2.8. Exercises

A. Check your understanding

Exercise (A1)
  • (a) For each formula, mark each occurrence of each variable as free or bound, list the free variables, and say whether it is a sentence: (i) ∀x(P(x)→Q(y)); (ii) ∃x∀yR(x,y); (iii) ∀x(x<y)∧∃y(y<x); (iv) ∀ε(ε>0→∃δ(δ>0∧δ<ε)).
  • (b) Which of the following are terms, and which are formulas, for one-place f, two-place g and two-place predicate R? (i) g(f(x),c); (ii) R(f(x),c); (iii) f(R(x,c)); (iv) ∀cR(c,c).
  • (c) True or false, with a reason: if t is a variable, then t is free for x in every formula.
  • (d) True or false, with a reason: (∀xP(x)∧Q(x))[c/x] is ∀xP(x)∧Q(c).

Solution. (a) (i) The single occurrence of x, in P(x), is bound by ∀x (the x after ∀ belongs to the quantifier node and is not an occurrence); the occurrence of y in Q(y) is free (no quantifier on y). Free variables: y. Not a sentence.

  • (ii) The occurrence of x is bound by ∃x, that of y by ∀y. No free variables: a sentence.

  • (iii) By shorthand rule 2 this is (∀x(x<y)∧∃y(y<x)). In the left part, x is bound by ∀x and y is free. In the right part, y is bound by ∃y and x is free (the ∀x governs only the left part). Free variables: x and y, each with one free and one bound occurrence. Not a sentence.

  • (iv) Every occurrence of ε lies below ∀ε, and both occurrences of δ lie below ∃δ; 0 is a constant. A sentence.

(b) (i) A term, by (Tm2) twice. (ii) A formula, atomic by (Fm1): the predicate R applied to the terms f(x) and c. (iii) Neither: R(x,c) is a formula, not a term, and (Tm2) applies f only to a term. (iv) Neither: (Fm4) puts a variable after ∀, and c is a constant symbol.

(c) False. The variable y is not free for x in ∃y(y≠x), since the free occurrence of x lies in the scope of ∃y. (A variable t is free for x when t is x itself, or when t does not appear in the formula.)

(d) True. The formula is (∀xP(x)∧Q(x)) by shorthand rule 2. The ∧ passes the substitution to both parts; ∀xP(x) is unchanged because its quantifier is on x, and Q(x) becomes Q(c).

Exercise (A2: Drill)

Answer each part in a line or two.

  • (a) In ∀y(x<y)∧∃x(x=y), which occurrences are free, and what are the free variables?
  • (b) Is ∀x∃y(x+y=0) a sentence?
  • (c) Someone writes ∀xP(x)→Q(x) for “every P is a Q”. Which occurrence of x is free, and what is the repair?
  • (d) Repair ∀ε>0∃δ>0(|x−a|<δ→|f(x)−f(a)|<ε), meant as “f is continuous at a”, with a a variable here (not a constant symbol), so that a is its only free variable.
  • (e) Compute (x≤y∧∃y(y<x))[3/x].
  • (f) Compute (∀x(x≥y))[0/y].
  • (g) Compute (∀xP(x)→P(x))[c/x].
  • (h) Compute ((x+y=y+x)[y/x])[x/y]. Is the result the formula with x and y swapped?
  • (i) Compute (P(x,y)[f(y)/x])[c/y].
  • (j) Is x free for y in ∃x(x>y)?
  • (k) Is z+1 free for y in ∃x(x>y)? Compute.
  • (l) Put x in for y in ∃x(x>y), renaming first.

Solution.

  • (a) The x of x<y and the y of x=y are free; the y of x<y is bound by ∀y and the x of x=y by ∃x. Free variables: x, y.

  • (b) Yes: every occurrence is bound.

  • (c) By shorthand rule 2 the ∀x governs only P(x), so the formula is (∀xP(x))→Q(x) and the x of Q(x) is free. Repair: ∀x(P(x)→Q(x)).

  • (d) As written, x is free, so the formula speaks of one fixed x. Repair: ∀ε>0∃δ>0∀x(|x−a|<δ→|f(x)−f(a)|<ε); f is a function symbol, not a variable.

  • (e) 3≤y∧∃y(y<3).

  • (f) ∀x(x≥0).

  • (g) ∀xP(x)→P(c) (shorthand rule 2: the ∀x governs only the first P(x)).

  • (h) y+y=y+y, then x+x=x+x. No: the swap is y+x=x+y.

  • (i) P(f(y),y), then P(f(c),c): the second substitution also reaches the y inside the term put in by the first.

  • (j) No: the free y lies in the scope of ∃x, and x is the variable of the term.

  • (k) Yes: ∃x(x>z+1).

  • (l) Rename x to z: ∃z(z>y); then ∃z(z>x).

B. Practice

Exercise (B1: Computing substitutions)

Compute each substitution. Where the term is not free for the variable, say which quantifier would capture it, rename first, and then substitute.

  • (a) (P(x)∧R(x,y))[f(y)/x].
  • (b) (∀xR(x,y)→P(x))[c/x].
  • (c) (∀y(x<y))[(y+1)/x].
  • (d) (∃x(x=2⋅y))[x/y].
  • (e) (∃y(y>x)∧Q(y))[(x+1)/y].

Solution. (a) No quantifiers, so f(y) is free for x. Every occurrence of x is replaced: P(f(y))∧R(f(y),y). The y inside f(y) and the y already in R(x,y) now stand side by side; with no quantifier around, both are the same free y, as intended.

(b) By shorthand rule 2 the formula is (∀xR(x,y)→P(x)). The constant c has no variables, so it is free for x. The left part is unchanged (quantifier on x); the free x in P(x) becomes c: ∀xR(x,y)→P(c).

(c) Not free for: the free occurrence of x lies in the scope of ∀y, and y is a variable of y+1. Rename y to z, which appears nowhere: ∀z(x<z). Then substitute: ∀z(y+1<z). (Without renaming, the definition would give ∀y(y+1<y), which says nothing about y+1.)

(d) Not free for: the free occurrence of y lies in the scope of ∃x, and the term is x. Rename x to z: ∃z(z=2⋅y), “y doubled is something”, then substitute: ∃z(z=2⋅x). (Without renaming, the result would be ∃x(x=2⋅x), “some number is its own double”, a claim about no particular number.)

(e) By shorthand rule 2 the formula is (∃y(y>x)∧Q(y)). The occurrence of y in y>x is bound, and the one in Q(y) is free and not in the scope of any quantifier; so x+1 is free for y (the ∃y above the bound y is irrelevant, since that occurrence is not replaced). The result is ∃y(y>x)∧Q(x+1).

Exercise (B2: The set of free variables)

For a term t, let Var(t) be the set of variables of t, and for a formula φ, let FV(φ) be the set of its free variables. (Here ∪ is the union of two sets, ∖ removes elements, and ∅ is the empty set, all in the everyday sense.)

  • (a) Write down clauses that define Var(t) by recursion on terms and FV(φ) by recursion on formulas, one clause for each case of Definition 5.2.1 and of Definition 5.2.2.
  • (b) Use your clauses to compute FV of ∀x(x<y)∧∃y(y<x) and of ∀x∃y(x+y=z), showing each step.

Solution. (a) For terms: Var(x)={x}  for a variable x,Var(c)=∅,Var(f(t1,…,tn))=Var(t1)∪⋯∪Var(tn). For formulas: FV(R(t1,…,tn))=Var(t1)∪⋯∪Var(tn),FV(t1=t2)=Var(t1)∪Var(t2),FV(⊥)=∅,FV(¬φ)=FV(φ),FV((φ∘ψ))=FV(φ)∪FV(ψ),FV(∀xφ)=FV(∃xφ)=FV(φ)∖{x}. These are the four lines of the recursive description of “free” (in the fold after the examples of free and bound occurrences), rewritten as sets: x∈FV(φ) exactly when x is free in φ. By structural recursion (carried over to terms and to first-order formulas), each set of clauses defines exactly one function.

(b) First formula. FV(x<y)={x,y}, so FV(∀x(x<y))={x,y}∖{x}={y}. FV(y<x)={x,y}, so FV(∃y(y<x))={x}. The conjunction gives {y}∪{x}={x,y}, which agrees with A1(a)(iii).

Second formula. FV(x+y=z)=Var(x+y)∪Var(z)={x,y,z}. Then FV(∃y(x+y=z))={x,z}, and FV(∀x∃y(x+y=z))={z}. So the formula is an open sentence in z alone (over R it is true for every z: given x, take y=z−x).

Exercise (B3: Swapping two letters)

Let φ=∃z(R(x,z)∧R(z,y)).

  • (a) Compute (φ[y/x])[x/y], and say whether it is φ with x and y swapped.
  • (b) Swap x and y in φ with three substitutions through a letter u that appears nowhere, checking at each step that the term is free for the variable.
  • (c) Why would z not do as the go-between?

Solution. (a) φ[y/x]=∃z(R(y,z)∧R(z,y)), and then [x/y] gives ∃z(R(x,z)∧R(z,x)). The swap is ∃z(R(y,z)∧R(z,x)), a different formula, and it says something different: over N with R read as < and x,y naming 2,0, the swap is true (z=1), while the computed formula, “some z is above 2 and below 2”, is false.

(b) φ[u/x]=∃z(R(u,z)∧R(z,y)); then [x/y] gives ∃z(R(u,z)∧R(z,x)); then [y/u] gives ∃z(R(y,z)∧R(z,x)), the swap. At each step the only quantifier above the replaced occurrence is ∃z, and the term (u, x, y) is not z, so it is free.

(c) z is not free for x in φ: the x of R(x,z) lies inside ∃z, so φ[z/x] would be captured and say ∃z(R(z,z)∧R(z,y)). The go-between must appear nowhere in φ, bound letters included (“appear”, in “Free and bound: drawing the arrows”).

Worked examples of these types: “One substitution at a time”; the practical rule “Before you substitute”.

Marking scheme. (10 points)

  • 3: (a), both steps computed and the swap written, with the difference shown (by the strings, or by one reading in which they differ).
  • 4: (b), the three substitutions in the right order, each result correct, and the free-for check stated once for each step.
  • 3: (c), capture named, with the captured formula written.

Fatal error (0 for the part): treating [y/x] and [x/y] as happening at the same time.

C. Going deeper

Exercise (C1: Challenge: What substitution does to the free variables)

Let φ be a formula, x a variable and t a term, with t free for x in φ, and with x free in φ.

  • (a) Prove that the free variables of φ[t/x] are the free variables of φ other than x, together with the variables of t: FV(φ[t/x])=(FV(φ)∖{x})∪Var(t), with the notation of B2. Prove it in the following form, by structural induction on φ: for every φ in which t is free for x, if x∈FV(φ), then FV(φ[t/x])=(FV(φ)∖{x})∪Var(t); if x∉FV(φ), then φ[t/x]=φ. The term version, the atomic case and the connective cases are done below; prove the case of ∀yφ (the case of ∃yφ is the same).
  • (b) Show, with the capture example ∃y(y>x), t=y+1, that the conclusion can fail when t is not free for x. Show also, with an example of your own, that it can fail when x is not free in φ.

Given for (a). Terms. Let s be a term in which x occurs. Then Var(s[t/x])=(Var(s)∖{x})∪Var(t). By induction on s: if s is the variable x, then s[t/x]=t and both sides are Var(t). (A constant, or a variable other than x, does not contain x.) If s=f(s1,…,sn), then s[t/x]=f(s1[t/x],…,sn[t/x]); for each si containing x, the induction hypothesis gives Var(si[t/x])=(Var(si)∖{x})∪Var(t), and for each si not containing x, si[t/x]=si (as in the proof of the claim in the text). At least one si contains x, so the union over i is (Var(s)∖{x})∪Var(t).

Formulas. We prove, by structural induction on φ, the statement S(φ): if t is free for x in φ, then FV(φ[t/x])=(FV(φ)∖{x})∪Var(t) when x∈FV(φ), and φ[t/x]=φ when x∉FV(φ). The second half is the claim proved in the text, for every φ; so in each case below we assume x∈FV(φ) and prove the equation. Write E(χ) for the set (FV(χ)∖{x})∪Var(t).

Atomic. Let φ=R(s1,…,sn) with x occurring in some si. By the clause for atomic formulas, FV(φ[t/x]) is the union over i of the sets Var(si[t/x]). Exactly as in the term case for f(s1,…,sn) (the result for terms for each si containing x, si[t/x]=si for the others, and at least one si containing x), this union is E(φ). The same for s1=s2. (⊥ has no free variables.)

Negation. FV((¬φ)[t/x])=FV(φ[t/x])=E(φ)=E(¬φ), by the induction hypothesis (t is free for x in φ, and x is free in φ).

Binary connective. Let x be free in (φ∘ψ); then t is free for x in both parts, and x is free in at least one. If it is free in both, the induction hypothesis gives E(φ)∪E(ψ)=E((φ∘ψ)). If it is free in φ only, then ψ[t/x]=ψ, and E(φ)∪FV(ψ)=E((φ∘ψ)), because x∉FV(ψ). Symmetrically if it is free in ψ only.

Solution (Hint 1). When x is free in ∀yφ, what does “free for” tell you about y and t?

Solution (Hint 2). Start from FV((∀yφ)[t/x])=FV(φ[t/x])∖{y} and apply the induction hypothesis to φ. Then see where removing y from the resulting set needs something about y and Var(t).

Solution. (a) The term version and the atomic, negation and connective cases are given in the statement. It remains to treat the quantifiers.

Quantifier. If x is not free in ∀yφ, then (∀yφ)[t/x]=∀yφ by the claim of the text. Now let x be free in ∀yφ. Then y is not x and x is free in φ; and since t is free for x in ∀yφ while x is free there, y∉Var(t) and t is free for x in φ (the recursive description of “free for”). So FV((∀yφ)[t/x])=FV(φ[t/x])∖{y}=((FV(φ)∖{x})∪Var(t))∖{y}=(FV(φ)∖{x,y})∪Var(t)=E(∀yφ), where the third equality uses y∉Var(t), and the last uses FV(∀yφ)=FV(φ)∖{y}. The case of ∃y is the same.

This proves S(φ) for every formula, and (a) is its first half.

(b) With φ=∃y(y>x) and t=y+1: FV(φ)={x}, so the equation would give FV(φ[t/x])={y}. But φ[t/x]=∃y(y>y+1), whose set of free variables is ∅. The y of the term was captured, so it is not free in the result; the quantifier case of the proof fails because y∈Var(t).

For the second hypothesis, take φ=P(z) and t=y. Then x is not free in φ, and t is free for x (there are no quantifiers). Now φ[t/x]=P(z), with free variables {z}, while the equation would give {z}∪{y}={y,z}. Without a free x, nothing is put in, so the variables of t do not appear.

Marking scheme. (10 points)

  • 3: the quantifier case reduced to FV(φ[t/x])∖{y} by the definitions.
  • 3: the use of “free for” to get y∉Var(t) and t free for x in φ, naming where it is used.
  • 1: the case “x not free in ∀yφ” handled by the claim of the text.
  • 3: both counterexamples of (b), each checked by computing both sides.

Fatal errors (0 for the step): using the equation FV(χ[t/x])=(FV(χ)∖{x})∪Var(t) for a part χ in which x is not free (it fails there; see the second example in (b)); removing y from Var(t) without justification.

Exercise (C2: Renaming is not swapping)
  • (a) Show that ∀x∃y(x<y) and ∀y∃x(y<x) are the same sentence up to renaming bound variables: give a sequence of renamings, each allowed by the condition of the text, leading from the first to the second.
  • (b) Show that ∀x∃y(x<y) and ∃y∀x(x<y) are not the same up to renaming. Hint: what does a renaming leave unchanged?

Solution. (a) A renaming needs a variable that does not appear in the formula, so the two letters cannot be exchanged in one step; go through a third letter z.

  1. In ∀x∃y(x<y), rename the bound x to z, which does not appear: ∀z∃y(z<y).
  2. Rename the bound y to x, which no longer appears: ∀z∃x(z<x).
  3. Rename the bound z to y, which no longer appears: ∀y∃x(y<x).

Each step renames one quantifier and the occurrences it binds, to a letter absent from the formula at that moment. The result is the second sentence. (Over N both say “there is no largest natural number”, in two spellings.)

(b) A renaming changes only which letters are used. It does not change the parse tree’s shape, which quantifier symbol (∀ or ∃) sits at which node, or which quantifier node binds which occurrence. In ∀x∃y(x<y) the root is a ∀ node; in ∃y∀x(x<y) the root is an ∃ node. No sequence of renamings turns a ∀ node into an ∃ node, so no sequence of renamings leads from one sentence to the other.

The two sentences also say different things: over N, the first is true (take y=x+1) and the second false (for any y, take x=y). This is Example (Swapping two quantifiers) again. Renaming changes the names of the placeholders; swapping changes the order in which they are chosen, and the order is what carries the meaning.