4.1  Formulas as Objects

Chapter 3 ended on a question that no derivation can answer. We show that a sequent holds by writing a derivation of it; but how could we show that one does not hold, that no derivation of Q→P from P→Q exists, however long and however clever? This chapter’s answer is a theorem about every derivation of every formula, and such a theorem needs, first of all, an exact description of what a formula is. This section gives it.

4.1.1. Why formulas must become objects

Here is the theorem that Section 4.7 proves, stated loosely:

If ψ can be derived from premises Γ, then ψ is true in every situation in which all the premises are true.

Read it as a mathematician reads a statement about all integers. “For every integer n, n2−n is even” can be proved only by someone who knows what an integer is: every integer is even or odd, and each kind can be handled. A proof needs a way to take hold of an arbitrary object of the kind the statement is about. The loose theorem above is about arbitrary derivations, and a derivation is a list of formulas, so the proof will need a way to take hold of an arbitrary formula.

Chapters 1–3 never needed one. There we read statements by eye: we found the main connective of ¬(P∧Q)→R (Definition 1.1.2) by looking, and we drew its tree by hand. That is fine for one statement at a time. It is useless for a claim about all statements, because “all the strings we would recognize as statements” is not a description anyone can reason from. So we now say exactly which objects we mean, in a form that later proofs can use.

The description has three parts. First, the alphabet, the symbols formulas are written with. Second, the formation rules, which say how formulas are built. Third, a closing clause saying that nothing else is a formula. The third is the one that is easy to forget and that makes everything else work.

4.1.2. The alphabet

Formulas are strings of symbols. A string is a finite list of symbols written one after another, and its length is the number of symbols in it. The symbols are these.

  • Atoms: p,q,r,p1,p2,p3,…, infinitely many of them. Each atom is one symbol: p1 is a single symbol whose name happens to carry a subscript, not the two symbols p and 1.
  • The constant ⊥, read “contradiction”, as in Chapter 1.
  • The connectives: ¬ (the only one that takes one part) and ∧,∨,→,↔ (the binary connectives, which take two).
  • The parentheses ( and ).

An atom plays the part that a letter played in Chapters 1–3: a statement whose inner structure we ignore. In those chapters the letters were capitals, P,Q,R, and they stood for arbitrary statements, atomic or compound. From now on we keep two kinds of letter apart, because the theorems of this chapter need the difference.

Remark. Who is who: the letters of this chapter.

Letter Stands for Inside a formula? Example
p,q,r,p1,p2,… an atom, one symbol of the language yes (p∧¬q)
φ,ψ,χ (phi, psi, chi) any formula: a metavariable, a name we use when talking about formulas never “if φ is a formula, so is ¬φ”
Γ,Δ (capital gamma, delta) a finite list of formulas, as in the sequents of Chapter 1 (Definition 1.2.3) never Γ⊢ψ
P,Q,R of Chapters 1–3 arbitrary statements; read from now on as atoms, or as any formulas (the last part of this section) they are replaced P→Q read as p→q

Chapter 1 already used the three letters φ,ψ,χ in exactly this way, in the schemas of its rules (Definition 1.2.1).

Quick check. Which of these is a formula, and which is a name for formulas or for a list: (p→q); (φ→q); Γ?

Solution. (p→q) is a formula. (φ→q) is not a formula, since φ is no symbol of the language; it is a pattern, and each formula put in for φ gives a formula. Γ names a list of formulas.

Two languages. Everything in this chapter is said in two languages at once. The object language is the language of formulas: its expressions are strings over the alphabet above, such as (p→q). The metalanguage is the language in which we talk about those strings: English with ordinary mathematics, together with names for formulas (φ,ψ) and for lists (Γ), and claims such as Γ⊢ψ and, from Section 4.5 on, Γ⊨ψ. Neither ⊢ nor ⊨ is a symbol of the alphabet. The sentence “(p→q) has length 5” belongs to the metalanguage and speaks about a string of the object language; (p→q) on its own is a string, not a claim. The theorems of this chapter, unique readability, soundness and completeness, are theorems about the object language, proved in the metalanguage by ordinary mathematics: induction, cases, counting. To speak about a symbol we name it, as we name a word. “p is an atom” mentions the symbol p, in the way that “‘seven’ has five letters” mentions a word.

Quick check. Sort into strings of the object language, claims of the metalanguage, and neither:

  • (a) ((p∧q)→p)
  • (b) p∧q⊢p
  • (c) the main connective of ((p∧q)→p) is →
  • (d) (φ∧q)
  • (e) ¬⊥ is a formula

Solution. (a) A string of the object language: a formula.

(b) A claim of the metalanguage, since ⊢ is not a symbol of the alphabet. It is true, by ∧E.

(c) A claim of the metalanguage, and true.

(d) Neither. The letter φ is a metavariable, not a symbol, so the expression is a pattern; each formula put in for φ gives a formula.

(e) A claim of the metalanguage, and true: ⊥ is a formula, and ¬ in front of a formula gives a formula (clauses (F1) and (F2) of the definition below).

4.1.3. Formulas

Chapter 1 described a statement as something “built from smaller ones by a connective”. The definition below says exactly how the building goes. It is an inductive definition: it names the starting pieces, names the ways of building new formulas from old, and then closes the door on everything else.

Building one formula. Here is the formula ((p∧¬q)→p) built one step at a time.

Diagram. Labels: i, p, q, neg q, (p wedge neg q), ((p wedge neg q) to p), neg on 2, 1 wedge 3, 4 to 1

Each entry is an atom, or is built from earlier entries by one connective. The atom p is used twice and listed once.

A list like this is called a formation sequence. The definition below has one more clause than the building steps. Its clause (F4) says that the formulas are exactly the last entries of such lists: the list you just saw, in general.

In clause (F4) below, ∘ stands for any one of the four binary connectives, as φ stands for any formula: (χj∘χl) means any one of (χj∧χl), (χj∨χl), (χj→χl), (χj↔χl).

A formula is a string built from atoms and ⊥ by the connectives, one step at a time, with a pair of parentheses around every binary step.

Definition 4.1.1 (Formula)

The formulas are the strings given by the following clauses.

  • (F1) Every atom is a formula, and ⊥ is a formula.
  • (F2) If φ is a formula, then ¬φ is a formula.
  • (F3) If φ and ψ are formulas, then (φ∧ψ), (φ∨ψ), (φ→ψ) and (φ↔ψ) are formulas.
  • (F4) Nothing else is a formula: a string is a formula only if it is the last entry of a formation sequence. A formation sequence is a finite list of strings χ1,…,χm, with m≥1, in which every entry χi is an atom or ⊥, or is ¬χj for some earlier entry χj (so j<i), or is (χj∘χl) for some earlier entries χj and χl (so j,l<i; j=l is allowed) and some binary connective ∘.

In words, clause by clause.

  • (F1), the starting pieces. A single atom is a formula, and so is ⊥. These are the only formulas of length one.
  • (F2), negation. Writing ¬ in front of a formula gives a formula. No parentheses are added: ¬p and ¬¬p are formulas, and ¬¬p is ¬ in front of the formula ¬p.
  • (F3), the binary connectives. Writing a binary connective between two formulas and wrapping the result in one pair of parentheses gives a formula. The two formulas may be the same: (p∧p) is a formula.
  • (F4), nothing else. Clauses (F1)–(F3) say which strings are formulas. They do not say that other strings are not. Clause (F4) does: a formula is exactly something we can reach from atoms and ⊥ by finitely many uses of (F2) and (F3), and the formation sequence is the written record of such a reaching. Think of building blocks: (F1) lists the blocks, (F2) and (F3) the two ways of joining them, and (F4) says that only what is built in this way counts.

Two facts about formation sequences are used constantly, and both are immediate from the definition.

First, every entry of a formation sequence is a formula. Walk along the list. The first entry χ1 is an atom or ⊥, so it is a formula by (F1). Each later entry is an atom or ⊥, a formula by (F1), or it is ¬χj or (χj∘χl) for earlier entries that are already formulas, and so it is a formula by (F2) or (F3). (Section 4.3 makes this walk exact with strong induction, in the fold “Sets built from a base”.)

Second, every formula was made by one of the clauses from formulas. Take a formula χ and a formation sequence ending in it. Its last entry χ is an atom or ⊥, or it is ¬χj, or it is (χj∘χl), where the earlier entries χj,χl are formulas by the first fact. So every formula is an atom, or ⊥, or ¬φ for a formula φ, or (φ∘ψ) for formulas φ,ψ. We will call this looking at the last step of a formula.

Looking at the last step already tells us something about the first symbol. A formula of the form ¬φ begins with ¬, and one of the form (φ∘ψ) begins with ( and ends with ). So:

The first-symbol test. A formula of length one is an atom or ⊥. A longer formula begins with ¬ or with (, and if it begins with (, it is (φ∘ψ) for formulas φ,ψ and ends with ).

(A formula of the form ¬φ has length at least 2, and one of the form (φ∘ψ) has length at least 5, since φ and ψ each have at least one symbol. So a formula of length one is made by (F1).)

Quick check. Write a formation sequence for ¬(p∨⊥), and say which earlier entries each entry uses.

Solution. p, ⊥, (p∨⊥), ¬(p∨⊥). Entry 3 uses entries 1 and 2, and entry 4 uses entry 3; entries 1 and 2 use none.

Example (Formation sequences)

Write down a formation sequence for each of the strings p, ⊥, ¬¬q and (¬p∨(q→⊥)), which shows that each is a formula.

Solution. For p, the one-entry list p is a formation sequence: its only entry is an atom. Likewise the list ⊥. These are the degenerate cases, and they matter: a formula need not have been built at all. Every structural argument in Section 4.3 has to deal with them.

For ¬¬q: q,¬q,¬¬q. The first entry is an atom; the second is ¬ in front of the first; the third is ¬ in front of the second.

For (¬p∨(q→⊥)): p,¬p,q,⊥,(q→⊥),(¬p∨(q→⊥)). Entries 1, 3 and 4 are atoms or ⊥. Entry 2 is ¬ in front of entry 1. Entry 5 is (χ3→χ4), and entry 6 is (χ2∨χ5).

Second readingMany formation sequences

A formula has many formation sequences. In Example (Formation sequences) we could have listed q before p in the last list, or added entries that are never used, such as r or ¬r. The definition asks only that some formation sequence ends in the string, and nothing in this chapter depends on which one we take.

To show that a string is a formula, we exhibit a formation sequence, just as we show that a sequent holds by exhibiting a derivation. To show that a string is not a formula, exhibiting is not enough; we need a property that every formula has and the string lacks. The first-symbol test supplies such properties.

Example (Strings that are not formulas)

Show that none of the strings p∧→q, (p∧q, (¬p) and p∧q is a formula.

Solution. p∧→q: it has length 4, so by the first-symbol test a formula would begin with ¬ or (. It begins with p. Not a formula.

(p∧q: it begins with (, so by the first-symbol test a formula would end with ). It ends with q. Not a formula. (The missing parenthesis is the whole problem: (p∧q) is a formula.)

(¬p): it begins with (, so a formula would have to be (φ∘ψ), with the two symbols ¬p between the parentheses equal to φ∘ψ, and so containing a binary connective. The string ¬p contains none. Not a formula. The official language puts no parentheses around a negation; (F2) adds none.

p∧q: it has length 3 and begins with p. Not a formula. This one is a surprise at first, since we have written p∧q all along. It is shorthand for the formula (p∧q), in the way explained later in this section.

The last two strings are ones Chapter 1 wrote freely, and that is no mistake in Chapter 1. Chapter 1 used a convenient shorthand; the official formulas carry every parenthesis that (F3) puts in and none that it does not. We come back to the shorthand below.

Quick check. Which of the following strings are formulas? For each, give a formation sequence or name the test it fails.

  • (a) ¬(p→⊥)
  • (b) (p→¬)
  • (c) ⊥⊥

Solution. (a) A formula: p, ⊥, (p→⊥), ¬(p→⊥) is a formation sequence.

(b) Not a formula. It begins with (, so it would be (φ→ψ) with φ the string p and ψ the string ¬ (the only binary connective is the →). But ¬ is a string of length one that is neither an atom nor ⊥, so by the first-symbol test it is not a formula.

(c) Not a formula. It has length 2, so it would begin with ¬ or (; it begins with ⊥.

4.1.4. Why this definition

Each feature of the definition is there because something breaks without it.

Without (F4), clauses (F1)–(F3) would be satisfied by far too many collections of strings. The collection of all strings contains every atom and ⊥, and is closed under writing ¬ in front and under wrapping two strings with a connective in parentheses; so (F1)–(F3) alone cannot tell us that p∧→q is excluded. Clause (F4) says the formulas are only those strings that the building steps reach. In other words, the formulas are the smallest collection of strings closed under (F1)–(F3).

Without the parentheses in (F3), a string could be read in two ways. Take p∧q∨r. Built one way, it is “p∧q” joined to r by ∨; built the other way, it is p joined to “q∨r” by ∧. The two constructions have different parse trees (defined below), and they say different things (the everyday reading of Chapter 1 is enough here): if p is false and r is true, then “p and q, or r” is true, because r is, while “p, and q or r” is false, because p is. With the parentheses of (F3) the two constructions give two different strings, ((p∧q)∨r)and(p∧(q∨r)), and the ambiguity disappears. Section 4.3 proves that it disappears for every formula: a formula can be built in only one way (the unique readability theorem).

Second readingTwo smaller points

Why not parentheses around a negation too? Nothing would break, but nothing would be gained. The symbol ¬ always stands in front of what it negates, so ¬φ can be read in only one way without help. Keeping the official language as lean as possible makes the proofs about it shorter.

Why atoms, and not sentences like “x>0”? Because the theorems of this chapter are about forms, and the form of an argument is what remains when the content of its atomic statements is forgotten (Chapter 1’s slogan: logic studies the forms of arguments). An atom is a statement reduced to a name.

Warning. A formula is a string of symbols, and questions about formulas are questions about strings. “Is (p∧p) the same formula as p?” has the answer no: the first has length 5 and the second length 1, even though they always have the same truth value (Section 4.4 gives the means to check this). Sameness of formulas is letter-for-letter identity; sameness of meaning is a different relation, which Section 4.5 names.

4.1.5. Parse trees

A formation sequence records how a formula was built, but it is a list, and a list hides the shape of the building. Chapter 1 drew the shape as a tree, with the main connective at the top (the tree after Definition 1.1.2). We now make that drawing official.

A parse tree is a formula’s construction drawn upside down: the last step at the root, the atoms at the leaves.

Definition 4.1.2 (Parse Tree)

A parse tree for a formula is defined along the clauses of Definition 4.1.1.

  • (T1) For an atom or ⊥: a single node, labeled by that atom or by ⊥.
  • (T2) If T is a parse tree for φ, then the tree whose root is labeled ¬ and has T hanging below it as its only subtree is a parse tree for ¬φ.
  • (T3) If T and T′ are parse trees for φ and ψ, then the tree whose root is labeled ∘, with T hanging below it on the left and T′ on the right, is a parse tree for (φ∘ψ).
  • (T4) Nothing else is a parse tree: a tree is a parse tree for a formula φ only if that follows from finitely many uses of (T1)–(T3). In particular, a parse tree for ¬φ is made by (T2), and a parse tree for (φ∘ψ) by (T3).

The leaves are the nodes with nothing below them; a branch is a path from the root down to a leaf.

In words: (T1) is the tree of a formula that was not built at all, a single node. (T2) puts a new root ¬ on top of an existing tree. (T3) joins two existing trees under a new root carrying the connective, keeping left and right apart, because (p→q) and (q→p) are different formulas. (T4), as (F4) did for formulas, says that only trees built this way count; Section 4.3 uses it when it asks how a given tree could have been made. Parentheses do not appear in a parse tree: their only job in the string was to show the grouping, and the tree shows the grouping by its shape.

Every formula has a parse tree. Take a formation sequence of the formula and build a tree for each entry in turn: an atom or ⊥ gets (T1), and an entry ¬χj or (χj∘χl) gets (T2) or (T3) from the trees already built for the earlier entries. The tree built for the last entry is a parse tree for the formula.

Could a formula have two different parse trees? That would happen if one string could be built in two different ways, as p∧q∨r could if parentheses were not written. Section 4.3 proves that it never happens (the unique readability theorem); until then we say “a parse tree”. After that section, every formula has exactly one, and we speak of the parse tree.

Example (Three parse trees)

Draw a parse tree for each formula: (a) p; (b) ¬(p∧¬q); (c) ((p↔¬q)∨(r∧(⊥→p))), which uses every connective and ⊥.

Solution. (a) A single node labeled p, by (T1). This is the degenerate tree: its root is also its only leaf, and its only branch has one node.

(b) By (T1) the atoms p and q get one-node trees; (T2) puts ¬ above q; (T3) joins p and ¬q under ∧; (T2) puts ¬ on top.

Diagram. Labels: p, q

(c) The main connective is the ∨: it is the last step, joining (p↔¬q) on the left to (r∧(⊥→p)) on the right. Each side is taken apart in the same way.

Diagram. Labels: p, q, r, to

The leaves are p, q, r, ⊥ and p again: the atom p occurs twice in the formula, and each occurrence is its own leaf.

To draw a parse tree from a string, find the last step, draw it as the root, and repeat on the parts. For a formula (φ∘ψ), the last step is the binary connective that sits inside exactly one pair of parentheses; in (c), it is the ∨, and every other binary connective sits inside at least two pairs. Section 4.3 proves that this recipe always finds the main connective, and only it.

4.1.6. Subformulas

Each node of a parse tree is the root of the part of the tree below it, and that part is itself a parse tree, built by the same clauses, for a formula. The formulas that arise in this way are the pieces a formula is built from.

Definition 4.1.3 (Subformula)

The subformulas of a formula φ are the formulas whose parse trees hang from the nodes of a parse tree for φ: for each node, the formula of which the part of the tree from that node downwards is a parse tree. The formulas at the children of the root are the immediate subformulas of φ.

Until Section 4.3 this depends, as far as we know, on the parse tree chosen; Section 4.3 shows there is only one, so the subformulas of φ are determined by φ.

So the subformulas of φ include φ itself (at the root) and each atom that occurs in φ (at the leaves). A formula of the form ¬φ has one immediate subformula, φ; a formula (φ∘ψ) has the two immediate subformulas φ and ψ (one, if φ and ψ are the same formula); an atom or ⊥ has none. When we list the subformulas, a formula that sits at several nodes is listed once.

For the formula (c) of Example (Three parse trees), the subformulas are ((p↔¬q)∨(r∧(⊥→p))),(p↔¬q),(r∧(⊥→p)),¬q,(⊥→p),p,q,r,⊥, nine in all. The tree has ten nodes, ∨, ↔, p, ¬, q, ∧, r, →, ⊥ and p again, and only p sits at two of them; so ten nodes give nine distinct subformulas. Counting by eye is easy to get wrong, and the safe method is to walk the tree node by node, as we just did.

A string that merely appears inside a formula need not be a subformula. The formula ((p∧q)∨r) contains the string q)∨r, which is not a formula at all, and it contains the string p∧q, which is only the shorthand of a formula. Its subformulas are the formulas at the nodes: ((p∧q)∨r), (p∧q), p, q and r.

Quick check. Draw the parse tree of (¬p∨q)↔¬(r∧p) (in official form, ((¬p∨q)↔¬(r∧p))) and list its subformulas.

Solution. The root is ↔. Its left subtree is ∨ over ¬p and q, where ¬p is ¬ over the leaf p. Its right subtree is ¬ over ∧, and ∧ has the leaves r and p.

The subformulas are the formula itself, (¬p∨q), ¬(r∧p), ¬p, q, (r∧p), p and r: eight, with p listed once although it sits at two leaves.

Warning. A parse tree is not a truth table. The tree records how a formula is built, and it is the same whatever the atoms stand for; nothing in it is true or false. Values come in Section 4.4, where they are computed along the tree, from the leaves up. Mixing the two, for instance writing “T” beside a node while drawing the tree, is a habit worth not forming: the same tree carries different values under different assignments.

4.1.7. Shorthand and official formulas

Nobody wants to write (((p∧q)→r)↔(p→(q→r))). Chapter 1 used conventions that let us drop parentheses (Section 1.1, the conventions before Definition 1.1.2), and we keep using them. What changes is their status: they are not part of the definition of a formula. A string written with the conventions is shorthand, and it stands for exactly one official formula, the one obtained by putting the dropped parentheses back.

The translation, from shorthand to official form, goes as follows.

  1. Put back the outer pair of parentheses of a formula whose main connective is binary: p∧q stands for (p∧q).
  2. ¬ binds most tightly: it applies to the smallest formula that follows it. So ¬p∧q stands for (¬p∧q), not for ¬(p∧q).
  3. ∧ and ∨ bind more tightly than → and ↔: p∧q→r stands for ((p∧q)→r).
  4. → groups to the right: p→q→r stands for (p→(q→r)).
  5. Chapter 1 sometimes wrote a negation in parentheses for emphasis, as in (¬P)→Q; such parentheses are simply removed.

In a mixture of ∧ with ∨, or of → with ↔, the shorthand keeps the parentheses (Chapter 1’s rule for such mixtures), so no rule is needed for those.

Example (Two groupings of three implications)

Write the official formula for the shorthand p→q→r, draw its parse tree beside that of ((p→q)→r), and find a situation in which the two formulas say different things.

Solution. By rule 4, p→q→r stands for (p→(q→r)): the first → is the main connective, and its conclusion is (q→r). The other grouping, ((p→q)→r), has the second → as main connective, and its hypothesis is (p→q). Left, (p→(q→r)); right, ((p→q)→r).

Diagram. Labels: to, p, q, r

The two trees are mirror images in shape, and they say different things. Suppose p, q and r are all false. The left formula is an implication whose hypothesis p is false, so it is true (vacuous truth, Section 2.1). The right formula has the true hypothesis p→q (again vacuous, since p is false) and the false conclusion r, so it is false. The everyday reading of Chapters 1 and 2 is enough to see this; Section 4.4 makes it a computation.

This is why the grouping convention matters. Grouping to the right is the useful choice, because statements of the form “if P, then if Q, then R” are common and (P→Q)→R is rare.

Going the other way, from official to shorthand, we drop every pair of parentheses the rules would put back. (¬(p∨q)↔(¬p∧¬q)) becomes ¬(p∨q)↔¬p∧¬q: the outer pair goes by rule 1, the pair around ¬p∧¬q by rule 3, and the pair after the first ¬ must stay, since without it rule 2 would read ¬p∨q.

From now on we write formulas in shorthand whenever that is clearer, and every statement about “the formula p∧q” is about the official formula (p∧q). Where the official form matters, as in counting parentheses or symbols, we write it out.

4.1.8. Letters, metavariables and substitution

We can now say exactly what the letters of Chapters 1–3 were.

Every rule was stated as a schema (Definition 1.2.1), with metavariables: ∧I writes φ∧ψ from φ and ψ, for any formulas φ and ψ. The derivations of those chapters were written with capital letters, as in the derivation of Proposition 1.4.1:

1P→Q
2Q→R
3Pasm, for →I
4Q→E 1, 3
5R→E 2, 4
6P→R→I 3–5

In the language of this chapter, read the letters P,Q,R as three atoms. Then this is a derivation of p→q, q→r⊢p→r in the official sense, written in shorthand. But Chapter 1 meant more: the derivation was a pattern, good for any statements put in for the letters. Here is that promise made exact.

A derivation written with letters is a template.

Substitution. Replace each atom of a derivation by a formula, the same formula at every occurrence of the same atom, and all such replacements at once. The result is again a derivation.

The fold below checks that every line stays a formula and stays justified.

Second readingWhy the result is again a derivation

Here is why. First, each line becomes a formula. Replacing atoms by formulas in a formula χ gives a formula: take a formation sequence of χ, write in front of it a formation sequence of each formula put in for an atom, and replace the atoms inside the old entries. Each old entry that was an atom has become the last entry of one of the sequences written in front; each old entry built by (F2) or (F3) is now built by the same clause from the replaced versions of the same earlier entries. So the new list is a formation sequence, and its last entry is the replaced χ.

Second, each line is still justified. Each line of the old derivation was a premise, an assumption, a repetition, or an instance of a rule’s schema (Definition 1.4.2, clauses (D1)–(D4)). Being an instance means: the line and the lines it cites are the schema with its metavariables replaced by certain formulas. The schema’s own symbols are connectives, ⊥ and parentheses, never atoms, so replacing atoms in the lines is the same as replacing atoms inside those certain formulas. The new lines are therefore the same schema with its metavariables replaced by the new formulas: an instance of the same rule.

Third, nothing about citations changes. The line numbers, the boxes, and which line cites which are untouched, and whether a line or a box is available depends on nothing else (Definition 1.4.2, the scope rule). So the result is a derivation, with the replaced premises and the replaced last line.

For instance, put (p1∧p2) for P, ¬p1 for Q, and (p2∨p1) for R in the derivation above:

1(p1∧p2)→¬p1
2¬p1→(p2∨p1)
3p1∧p2asm, for →I
4¬p1→E 1, 3
5p2∨p1→E 2, 4
6(p1∧p2)→(p2∨p1)→I 3–5

Line 4 is still →E: lines 1 and 3 are φ→ψ and φ with φ the formula p1∧p2 and ψ the formula ¬p1. Line 6 is still →I with the same box.

The fact is immediate rule by rule, because every rule was stated for arbitrary formulas from the start. It is what the phrase “the letters stand for arbitrary statements” (Chapter 1, Section 1.2) and the clause “replace each letter … the same statement for every occurrence” of Definition 2.3.1 were relying on. We use it twice later in the chapter, in the soundness proof of Section 4.7 and in the completeness proof of Section 4.8.

Remark. The replacement must be uniform. Replacing only the first P of the derivation above by p1∧p2, and leaving the P on line 3 alone, would break line 4, which needs the hypothesis of line 1 to be literally the formula on line 3.

Remark (Looking ahead). Section 4.3 proves that every formula is built in only one way. Then “the parse tree” of a formula makes sense, and with it the height of a formula.

4.1.9. Exercises

A. Check your understanding

Exercise (A1)
  • (a) Decide which of the following strings are formulas. Give a formation sequence for each formula, and for each nonformula name the test or clause it fails: (i) (p∨⊥); (ii) ¬¬p; (iii) (p¬q); (iv) ((p→q)); (v) (p∧q∧r).
  • (b) List the subformulas of (¬(p→q)∨q).
  • (c) Write a formation sequence of ((p∨q)∧¬(p∨q)) in which (p∨q) is listed once.
  • (d) Why does clause (F3) of Definition 4.1.1 put parentheses around its result, while (F2) does not?
  • (e) Explain why clauses (F1)–(F3) alone do not show that →p is not a formula, and which clause does.

Solution. (a) (i) A formula: p, ⊥, (p∨⊥).

  • (ii) A formula: p, ¬p, ¬¬p.

  • (iii) Not a formula. It begins with (, so by the first-symbol test it would be (φ∘ψ), and the string p¬q between the parentheses would contain a binary connective. It contains none.

  • (iv) Not a formula. It begins with (, so it would be (φ∘ψ) with φ∘ψ the string (p→q). The only binary connective in that string is the →, so φ would be the string (p, of length 2. A formula of length 2 begins with ¬, by the first-symbol test (one beginning with ( has length at least 5). So (p is not a formula, and neither is the string. So here the doubled outer pair is not official.

  • (v) Not a formula. It would be (φ∧ψ) with the ∧ one of the two. If it is the first, ψ is the string q∧r; if the second, φ is p∧q. Each has length 3 and begins with an atom, so by the first-symbol test neither is a formula. (Chapter 1’s conventions give no reading of the shorthand p∧q∧r; Section 4.5 introduces it for the right-grouped (p∧(q∧r)) and explains why either grouping would do.)

(b) The formula is (¬(p→q)∨q). Its subformulas are (¬(p→q)∨q), ¬(p→q), (p→q), p and q: five, with q listed once although it sits at two leaves.

(c) p, q, (p∨q), ¬(p∨q), ((p∨q)∧¬(p∨q)). Entry 4 uses entry 3, and entry 5 uses entries 3 and 4: (p∨q) is built once and used twice.

(d) A binary connective joins two formulas, and without parentheses a string such as p∧q∨r could be built in two ways, with different meanings (see “Why this definition”). A negation stands in front of the one formula it negates, so there is nothing to group.

(e) Clauses (F1)–(F3) say which strings are formulas and never which are not: the collection of all strings satisfies them. Clause (F4) says a formula is the last entry of a formation sequence, and from it follows the first-symbol test: →p has length 2 and does not begin with ¬ or (.

Exercise (A2: Drill)

Answer each part in a line or two.

  • (a) Is ¬¬¬p a formula?
  • (b) Is (p∧(q)) a formula?
  • (c) How many symbols has ((p→q)∨¬r)?
  • (d) Is p∧q⊢p a formula?
  • (e) What is the main connective of ¬(p∧q)→r?
  • (f) Which of these are subformulas of ((p∧q)→r): (p∧q); the string q)→r; (q→r); r?
  • (g) Add one symbol to (p∧¬q to make a formula.
  • (h) Delete as few symbols as possible from ((¬p)) to make a formula.
  • (i) Insert one pair of parentheses into (p∨q∨r) to make a formula, in two different ways.
  • (j) Write the official formula for ¬p∨q→r.
  • (k) Draw the parse tree of (p→(q→p)) and list its leaves.
  • (l) In the derivation of Proposition 1.4.1 printed in this section, put q for P, q for Q and p for R. Is the result a derivation?

Solution.

  • (a) Yes: p, ¬p, ¬¬p, ¬¬¬p is a formation sequence.

  • (b) No. It would be (φ∧ψ) with ψ the string (q). That string begins with ( and has length 3, and a formula beginning with ( has length at least 5.

  • (c) Ten: ( ( p → q ) ∨ ¬ r ).

  • (d) No. It is a claim of the metalanguage about two formulas; ⊢ is not a symbol of the alphabet.

  • (e) →; officially the formula is (¬(p∧q)→r).

  • (f) (p∧q) and r. The string q)→r is not a formula. (q→r) is a formula, but no node of the tree carries it.

  • (g) (p∧¬q): the string begins with (, so by the first-symbol test it must end with ).

  • (h) Delete all four parentheses, leaving ¬p. The string has no binary connective, and a pair of parentheses is official only around a binary step; so the only formulas made of its symbols are ¬p and p.

  • (i) ((p∨q)∨r) and (p∨(q∨r)).

  • (j) ((¬p∨q)→r).

  • (k) Root →; on the left the leaf p, on the right → over q and p. The leaves are p, q, p.

  • (l) Yes. Lines 1–6 become q→q, q→p, q, q, p, q→p, and lines 4, 5, 6 are still instances of →E, →E, →I. A substitution may put the same formula for two letters.

B. Practice

Exercise (B1: Trees from Chapter 1)

Each formula below appears, with capital letters, in a result of Chapter 1 (Proposition 1.4.2 and Proposition 1.6.1); here the letters are atoms. For each, write the official formula, draw its parse tree, and list its subformulas.

  • (a) (p∧q)→r
  • (b) p→(q→r)
  • (c) (p∧q)∨(p∧r)

Solution. (a) Official form ((p∧q)→r). Root →; left subtree ∧ with leaves p, q; right subtree the leaf r. Subformulas: ((p∧q)→r), (p∧q), p, q, r.

(b) Official form (p→(q→r)). Root →; left the leaf p; right subtree → with leaves q, r. Subformulas: (p→(q→r)), (q→r), p, q, r. (This is the left tree of Example (Two groupings of three implications). The formulas of (a) and (b) have different trees; Proposition 1.4.2 says that each can be derived from the other.)

(c) Official form ((p∧q)∨(p∧r)). Root ∨; left subtree ∧ with leaves p, q; right subtree ∧ with leaves p, r.

Diagram. Labels: p, q, r

Subformulas: ((p∧q)∨(p∧r)), (p∧q), (p∧r), p, q, r: six, with p listed once although it sits at two leaves.

Exercise (B2: Shorthand and back)
  • (a) Write in shorthand, dropping every pair of parentheses the conventions allow: ((p∧q)→(r→p)) and (¬(p∨q)→(¬p∧¬q)).
  • (b) Write the official formula for: p→q∨r→¬p and ¬p∧q↔r.

Solution. (a) p∧q→r→p. The outer pair goes by rule 1; (p∧q) loses its pair because ∧ binds more tightly than → (rule 3); (r→p) loses its pair because → groups to the right (rule 4).

¬(p∨q)→¬p∧¬q. The outer pair goes; the pair around ¬p∧¬q goes by rule 3. The pair after the first ¬ stays: without it, rule 2 would make the ¬ apply to p alone.

(b) (p→((q∨r)→¬p)). Rule 3 groups q∨r first; rule 4 then makes the first → the main connective, with conclusion ((q∨r)→¬p).

((¬p∧q)↔r). Rule 2 makes ¬ apply to p alone; rule 3 groups ¬p∧q before ↔.

C. Going deeper

Exercise (C1: Forgetting the grouping convention)

Suppose we forgot rule 4 of the shorthand, so that p→q→r→s could stand for any official formula obtained by inserting parentheses into it.

  • (a) List every official formula it could stand for, and draw the shape of each parse tree.
  • (b) How many are there? Say how the count is found, by splitting at the main connective.
  • (c) Which of them is the one rule 4 chooses?

Solution (Hint 1). The main connective is one of the three arrows. Choose it first.

Solution (Hint 2). Write cn for the number of groupings of a chain of n atoms, and find c1, c2 and c3 first.

Solution. (a) The main connective is one of the three arrows; what lies on each side is then grouped in every possible way.

  • Main connective the first arrow: p on the left, and q→r→s on the right, grouped in one of two ways. This gives (p→(q→(r→s))) and (p→((q→r)→s)).
  • Main connective the second arrow: (p→q) on the left and (r→s) on the right, each grouped in one way. This gives ((p→q)→(r→s)).
  • Main connective the third arrow: p→q→r on the left, grouped in one of two ways, and s on the right. This gives ((p→(q→r))→s) and (((p→q)→r)→s).

Their parse trees have the root → in each case: in the first two, the leaf p on the left and a chain of two arrows on the right (leaning right, or leaning left); in the third, two one-arrow trees side by side; in the last two, a chain of two arrows on the left and the leaf s on the right.

(b) There are 5. Write cn for the number of groupings of a chain of n atoms joined by one binary connective. A chain of one or two atoms has one grouping: c1=c2=1. For three atoms the main connective is the first or the second arrow, and the side with two atoms has one grouping: c3=c1c2+c2c1=2. For four atoms, choosing the main connective splits the chain into a left part of k atoms and a right part of 4−k atoms, for k=1,2,3, and the two parts are grouped independently: c4=c1c3+c2c2+c3c1=2+1+2=5. The three terms are the three bullets of (a).

(c) Rule 4 groups to the right, so the main connective is the first arrow and its right side is grouped to the right again: (p→(q→(r→s))), the first formula of the list.

The numbers 1,1,2,5,14,42,… produced by this splitting are the Catalan numbers; they grow quickly: a chain of eleven atoms joined by ten connectives already has 16,796 readings. Parentheses, or a fixed convention, are not pedantry.