1.3. Propositional Logic: Intuitionism and Natural Deduction

In the previous chapter we saw, informally, that certain Haskell types can be read as logical formulas and certain programs as proofs. To make this correspondence precise, we first need to understand carefully what a proof is. In this chapter we present the intuitionistic view of propositional logic, the system of natural deduction that formalizes it, a first introduction to the sequent calculus, and the concept of a cut, which, as we shall see, is essentially computational in nature.

1.3.1. Types and propositions

A central concept in this course is that of a type. But what is a type in a programming language? Different authors offer a wide variety of definitions. According to Benjamin Pierce:

A type system is a tractable syntactic method for proving the absence of

certain program behaviors by classifying phrases according to the kinds of

values they compute.

Implicit in this definition of a type system is a notion of type: a type is a classification of program fragments according to the values they compute. In this way, we can understand a type as a syntactic representation of the set of values it stands for. The type Bool, for example, corresponds to the set \mathbb{B} = \{F, T\}, and a function type A \to B can be interpreted as the set of functions between the sets denoted by A and by B.

This view goes back to the tradition of defining the meaning of programs using denotational semantics, which consists in defining the meaning of a language by means of a function that maps each element of the syntax to a well-known mathematical object.

1.3.1.1. Denotational semantics of propositional logic

In a first logic course, the denotational approach is commonly used to define the meaning of the formulas of propositional logic: truth tables. Each formula denotes a truth value, computed from the values of its variables. For implication, we have: \begin{array}{cc|c} A & B & A \supset B \\ \hline F & F & T \\ F & T & T \\ T & F & F \\ T & T & T \end{array}

Using truth tables we know, for instance, that A \supset A is a tautology: it is true for every value of A.In this chapter we use \supset for logical implication, reserving \to for the function type constructor.

1.3.1.2. Propositions as types

The main idea to be developed throughout this course is that propositions of logic correspond to types in a programming language. Logical connectives will be understood as different type constructors; for example, the implication A \supset B will be interpreted as the function type A \to B.

There is, however, a difficulty. In the classical view, propositions are understood as truth values, whereas types are understood as sets of values (not necessarily logical ones). How can these views be reconciled?

A first attempt is the Boolean interpretation: a type is "true" if it is non-empty and "false" if it is empty. Under this view, the type Int would be understood as a proposition (a true one, since integers exist) and the type Int -> Int as the implication \textrm{Int} \supset \textrm{Int}. Using a truth table, we can determine when the set \textrm{Int} \to \textrm{Int} is empty or not, representing "false" by \emptyset and "true" by a singleton set \{\bullet\}: \begin{array}{c|c} \textrm{Int} & \textrm{Int} \supset \textrm{Int} \\ \hline \emptyset & \{\bullet\} \\ \{\bullet\} & \{\bullet\} \end{array}

The first row says that, if the proposition \textrm{Int} is false (the type is empty), there is still a function \emptyset \to \emptyset: the empty function, whose graph is the set \emptyset itself. The second row says that, if \textrm{Int} is true, the set of functions \textrm{Int} \to \textrm{Int} is non-empty (it contains, for example, the identity).

This interpretation, however, is very limited: under it, types are essentially just empty or non-empty, and we cannot distinguish different functions of the same type. The Haskell type [Int] -> [Int], for example, contains countless functions with very different characteristics — just think of the many sorting algorithms, which differ in efficiency, stability and strategy. If we wish to establish a serious correspondence between logic and programming languages, we must take into account the computational characteristics of proofs, and not merely their existence.

1.3.1.3. Girard's three levels

Jean-Yves Girard, an important French logician, argues that there are three levels of interpretation of logic:

  • at the Boolean level, we interpret propositions as truth values and are interested only in whether proofs exist or not;

  • at the extensional level, we interpret propositions as sets and are interested in which functions can or cannot be defined;

  • at the intensional level, we are interested in proofs themselves and in how they behave computationally.

In this course we are interested in the intensional level: in proofs themselves, and not only in knowing whether a proposition is provable or not. For this reason, we will study formalisms that define logic in terms of what can be proved: natural deduction and the sequent calculus.

1.3.2. Intuitionism

In classical logic, every proposition is either true or false — this is the law of excluded middle, A \lor \neg A. The meaning of a proposition is given by the truth values it can take, and not by whether or not it is provable.

In intuitionistic logic, we consider a proposition to be true only if it is provable. The meaning of each connective is then given by describing what counts as a proof of a formula with that connective. This reading is known as the Brouwer-Heyting-Kolmogorov (BHK) interpretation:

  • a proof of A \land B consists of a pair of proofs: one of A and one of B;

  • a proof of A \lor B consists of a proof of A or of B, together with a tag indicating which of the two propositions was proved;

  • a proof of A \supset B consists of a procedure (a function) that transforms any proof of A into a proof of B;

  • a proof of \neg A consists of a procedure that produces an absurdity from a proof of A;

  • there is no proof of \bot (absurdity), and \top has a trivial proof.

Notice how computational this reading already is: pairs, tagged unions and functions are exactly the product, sum and function types of functional languages. Under this interpretation, the excluded middle is no longer self-evident: proving A \lor \neg A would require deciding, for an arbitrary proposition A, which of the two sides holds, and supplying the corresponding proof.

This informal interpretation is exactly the one captured by the formalism known as natural deduction, introduced by Gerhard Gentzen.

1.3.3. Natural deduction

1.3.3.1. Syntax

The formulas of propositional logic are generated by the following grammar, where A stands for a propositional variable: \begin{array}{lcll} \varphi & \to & \bot & \textrm{false} \\ & \mid & \top & \textrm{true} \\ & \mid & A & \textrm{variables} \\ & \mid & \varphi \supset \varphi & \textrm{implication} \\ & \mid & \varphi \land \varphi & \textrm{conjunction} \\ & \mid & \varphi \lor \varphi & \textrm{disjunction} \end{array}

To avoid parentheses, we adopt the precedence \neg, \land, \lor, \supset (from strongest to weakest) and take \supset to associate to the right: A \supset B \supset C means A \supset (B \supset C).

1.3.3.2. Contexts, sequents and rules

We call a context a list of formulas \Gamma = [\varphi_1, \ldots, \varphi_n], which represent the available hypotheses. A sequent is a pair consisting of a context and a formula, written \Gamma \vdash \varphi and read as "using the hypotheses in \Gamma it is possible to deduce \varphi".

The natural deduction system is presented as a set of inference rules of the form \frac{\Gamma \vdash \varphi_1 \quad \cdots \quad \Gamma \vdash \varphi_n}{\Gamma \vdash \varphi}

where the sequents \Gamma \vdash \varphi_i are the premises and \Gamma \vdash \varphi is the conclusion. The rules consist of an axiom and two kinds of rules for each connective:

  • introduction rules, which allow us to deduce a formula with a given connective;

  • elimination rules, which allow us to use a formula with a given connective. In these, the major premise (the one containing the eliminated connective) is the leftmost one.

The axiom (or hypothesis rule) says that we can conclude any formula present in the context: \frac{}{\Gamma, \varphi, \Gamma' \vdash \varphi}\,(\textrm{Ax})

1.3.3.3. Conjunction

To deduce \varphi_1 \land \varphi_2, it suffices to deduce each of its parts — exactly the pair of proofs of the BHK interpretation: \frac{\Gamma \vdash \varphi_1 \quad \Gamma \vdash \varphi_2}{\Gamma \vdash \varphi_1 \land \varphi_2}\,(\land I)

Conversely, from a conjunction we can extract either of its components (the projections of the pair): \frac{\Gamma \vdash \varphi_1 \land \varphi_2}{\Gamma \vdash \varphi_1}\,(\land E_1) \qquad \frac{\Gamma \vdash \varphi_1 \land \varphi_2}{\Gamma \vdash \varphi_2}\,(\land E_2)

1.3.3.4. Implication

To deduce \varphi_1 \supset \varphi_2, we assume \varphi_1 (adding it to the context) and deduce \varphi_2: \frac{\Gamma, \varphi_1 \vdash \varphi_2}{\Gamma \vdash \varphi_1 \supset \varphi_2}\,(\supset I)

The elimination of implication is modus ponens: from \varphi_1 \supset \varphi_2 and \varphi_1, we conclude \varphi_2: \frac{\Gamma \vdash \varphi_1 \supset \varphi_2 \quad \Gamma \vdash \varphi_1}{\Gamma \vdash \varphi_2}\,(\supset E)

From a computational point of view, (\supset I) corresponds to defining a function (a \lambda abstraction) and (\supset E) to function application.

1.3.3.5. A first example

Let us deduce \{A \land B \supset C\} \vdash A \supset B \supset C. A derivation is built bottom-up: we start from the goal and, at each step, choose a rule whose conclusion has the desired form. The goal is an implication, so we use (\supset I) twice, adding A and B to the context; it remains to deduce C. The only way to obtain C is to use the hypothesis A \land B \supset C via (\supset E), which requires deducing A \land B, which we do with (\land I) from the hypotheses A and B. Omitting the contexts, the complete derivation is: \dfrac{\dfrac{\dfrac{\dfrac{}{A \land B \supset C} \quad \dfrac{\dfrac{}{A} \quad \dfrac{}{B}}{A \land B}}{C}}{B \supset C}}{A \supset B \supset C}

In Lean, logical connectives are types and proofs are terms. The derivation above corresponds to the following program, in which each rule becomes a language construct: (\supset I) is fun, (\supset E) is application and (\land I) is the pair construction ⟨a, b⟩:

namespace Ch02 variable (A B C : Prop) example : (A ∧ B → C) → A → B → C := fun h a b => h ⟨a, b⟩

This is a preview of the Curry-Howard isomorphism, which we will study in detail later on.

1.3.3.6. Disjunction

There are two introduction rules for disjunction, one for each side; the choice of rule is the "tag" of the BHK interpretation: \frac{\Gamma \vdash \varphi_1}{\Gamma \vdash \varphi_1 \lor \varphi_2}\,(\lor I_1) \qquad \frac{\Gamma \vdash \varphi_2}{\Gamma \vdash \varphi_1 \lor \varphi_2}\,(\lor I_2)

The elimination of disjunction is reasoning by cases: if we know \varphi_1 \lor \varphi_2 and can deduce \varphi both by assuming \varphi_1 and by assuming \varphi_2, then we deduce \varphi: \frac{\Gamma \vdash \varphi_1 \lor \varphi_2 \quad \Gamma, \varphi_1 \vdash \varphi \quad \Gamma, \varphi_2 \vdash \varphi}{\Gamma \vdash \varphi}\,(\lor E)

Computationally, (\lor E) corresponds to a case (or match) expression on a sum type. For example, the commutativity of disjunction:

example : A ∨ B → B ∨ A := fun h => match h with | Or.inl a => Or.inr a | Or.inr b => Or.inl b

1.3.3.7. True and false

The constant \top has only one introduction rule, with no premises. For \bot, on the other hand, there is only an elimination rule, known as ex falso quodlibet: from absurdity, anything follows. \frac{}{\Gamma \vdash \top}\,(\top I) \qquad \frac{\Gamma \vdash \bot}{\Gamma \vdash \varphi}\,(\bot E)

Are some rules missing? There is no introduction rule for \bot and no elimination rule for \top. This is intentional: it should not be possible to introduce absurdity (there is no proof of \bot), and there is nothing useful to extract from \top (its proof carries no information).

1.3.3.8. Negation

Negation needs no rules of its own: it is treated as an abbreviation for an implication, \neg \varphi \equiv \varphi \supset \bot.

Thus, proving \neg \varphi means showing that \varphi leads to an absurdity, and using \neg \varphi together with \varphi yields \bot by (\supset E).

As an example, let us deduce \{A \supset B\} \vdash \neg B \supset \neg A. By (\supset I), we assume \neg B and need \neg A, that is, A \supset \bot. Again by (\supset I), we assume A and need to deduce \bot. To do so, we apply \neg B = B \supset \bot to a deduction of B, which we obtain from A \supset B and A: \dfrac{\dfrac{\dfrac{\dfrac{}{\neg B} \quad \dfrac{\dfrac{}{A \supset B} \quad \dfrac{}{A}}{B}}{\bot}}{\neg A}}{\neg B \supset \neg A}

In Lean, ¬ A is defined exactly as A → False, and the derivation above becomes:

example : (A → B) → ¬ B → ¬ A := fun ab nb a => nb (ab a)

1.3.3.9. Structural rules

Besides the rules presented so far, natural deduction has structural rules, which do not mention connectives and deal only with the context of hypotheses. Weakening allows us to add unused hypotheses: \frac{\Gamma, \Gamma' \vdash \varphi}{\Gamma, \varphi', \Gamma' \vdash \varphi}\,(\textrm{W})

Exchange allows us to reorder hypotheses: \frac{\Gamma, \varphi_1, \varphi_2, \Gamma' \vdash \varphi}{\Gamma, \varphi_2, \varphi_1, \Gamma' \vdash \varphi}\,(\textrm{X})

Contraction allows us to remove duplicate hypotheses: \frac{\Gamma, \varphi', \varphi', \Gamma' \vdash \varphi}{\Gamma, \varphi', \Gamma' \vdash \varphi}\,(\textrm{C})

Structural rules are needed because we treat contexts as lists of formulas. If contexts are treated as sets of formulas, these rules need not be handled explicitly: order and repetition no longer matter. Logics that restrict these rules — for example, by forbidding contraction and weakening, so that each hypothesis must be used exactly once — are called substructural (such as linear logic) and have important applications in Computer Science, as we will see when we study separation logic.

1.3.4. Sequent calculus: a first look

In natural deduction, the elimination rules act on the formula to the right of the \vdash, and the context \Gamma plays a secondary role: it is modified only by the rules that introduce hypotheses, such as (\supset I) and (\lor E). The sequent calculus, also proposed by Gentzen, reorganizes the rules so that all manipulation is performed on the sequent as a whole: the introduction rules become rules acting on the right of the sequent, and the elimination rules become rules acting on the left, directly decomposing the hypotheses in the context. For example, instead of projecting a conjunction that has already been deduced, the sequent calculus decomposes a conjunction present in the context: \frac{\Gamma, \varphi_1, \varphi_2 \Longrightarrow \varphi}{\Gamma, \varphi_1 \land \varphi_2 \Longrightarrow \varphi}

One advantage of this presentation is that derivations always grow in the same direction, which makes it well suited to automated proof search. The sequent calculus will be studied in detail in the next chapter. Before that, we discuss a concept that appears especially clearly in this setting: the cut.

1.3.5. Cut

A very important concept in logic is that of a cut. Intuitively, cut allows the use of auxiliary results (lemmas) in proofs. Formally, cut is the following property of the logic: if we deduce \varphi' and, assuming \varphi', we deduce \varphi, then we can deduce \varphi directly: \frac{\Gamma \vdash \varphi' \quad \Gamma', \varphi' \vdash \varphi}{\Gamma, \Gamma' \vdash \varphi}\,(\textrm{Cut})

The formula \varphi' acts as a lemma: it is proved once and used as a hypothesis in the main proof. Removing a cut consists in replacing the references to the hypothesis \varphi' in \Gamma', \varphi' \vdash \varphi with the proof of \Gamma \vdash \varphi' itself.

1.3.5.1. Redundancies

To illustrate the computational structure of cut, let us consider an example of a redundancy in a proof. Suppose we have proofs \pi of \Gamma \vdash A and \pi' of \Gamma \vdash B. The derivation on the left introduces a conjunction only to eliminate it immediately afterwards; it can be simplified to the derivation on the right: \dfrac{\dfrac{\dfrac{\pi}{\Gamma \vdash A} \quad \dfrac{\pi'}{\Gamma \vdash B}}{\Gamma \vdash A \land B}}{\Gamma \vdash A} \quad \leadsto \quad \dfrac{\pi}{\Gamma \vdash A}

But why would anyone use this structure in proofs? Simple: modularity. By proving a general lemma (here, A \land B) and then specializing it, we are structuring the proof into reusable parts. Formally, a redundancy (or cut, in natural deduction) is the use of an introduction rule immediately followed by an elimination rule for the same connective, and cut elimination consists in removing these redundancies.

From a computational point of view, the example above is just the evaluation of a projection applied to a pair: fst (a, b) reduces to a. Likewise, introducing an implication and immediately eliminating it corresponds to applying an anonymous function to an argument, and eliminating that cut is the \beta-reduction of the \lambda-calculus. Eliminating cuts is running programs.

1.3.5.2. An example of cut elimination

Consider the following proof of \{A \land B, A \supset B \supset C\} \vdash C, in which the hypothesis A \land B is used twice: \dfrac{\dfrac{\dfrac{}{A \supset B \supset C} \quad \dfrac{\dfrac{}{A \land B}}{A}}{B \supset C} \quad \dfrac{\dfrac{}{A \land B}}{B}}{C}

Consider also the trivial proof of \{A, B\} \vdash A \land B: \dfrac{\dfrac{}{A} \quad \dfrac{}{B}}{A \land B}

By cut, we can combine them to obtain a proof of \{A, B, A \supset B \supset C\} \vdash C, replacing each use of the hypothesis A \land B with its proof: \dfrac{\dfrac{\dfrac{}{A \supset B \supset C} \quad \dfrac{\dfrac{\dfrac{}{A} \quad \dfrac{}{B}}{A \land B}}{A}}{B \supset C} \quad \dfrac{\dfrac{\dfrac{}{A} \quad \dfrac{}{B}}{A \land B}}{B}}{C}

Notice that the resulting proof contains two redundancies (introduction of \land followed by elimination), which can be removed as described above, yielding a cut-free proof. In Lean, cut corresponds to a local definition (have), and the substitution corresponds to "unfolding" that definition:

-- With cut: the lemma `ab` is proved once -- and used twice. example : A → B → (A → B → C) → C := fun a b h => have ab : A ∧ B := ⟨a, b⟩ h ab.1 ab.2 -- Without cut: `⟨a, b⟩.1` simplifies to `a`, -- and `⟨a, b⟩.2` to `b`. example : A → B → (A → B → C) → C := fun a b h => h a b

1.3.5.3. Consistency

Cut elimination is a crucial property of the logic, because it implies its consistency. We say that the logic is consistent if it is not possible to deduce \bot from an empty context of hypotheses, that is, if the sequent \vdash \bot is not provable.

Why does this matter? Consistency implies that the logic is useful. This is due to the elimination rule for falsity: \frac{\Gamma \vdash \bot}{\Gamma \vdash \varphi}

If it were possible to prove \vdash \bot, then every formula \varphi would be provable using this rule, and the logic would not distinguish true formulas from false ones.

Two facts are central to establishing consistency:

  1. (Cut elimination) If \varphi is provable, then there is a cut-free proof of \varphi; it is obtained by eliminating the redundancies one by one.

  2. If \vdash \varphi has a cut-free deduction with an empty context, then that deduction ends with an introduction rule. (Intuitively, with no hypotheses available, an elimination at the root would need a major premise which, in turn, would have to end with an introduction of the same connective — which would form a cut.)

Theorem. The natural deduction system is consistent.

Proof. Suppose, for the sake of contradiction, that natural deduction is not consistent. Then there is a deduction \pi of \vdash \bot. By cut elimination, there is also a cut-free deduction \pi' of \vdash \bot. By the second fact above, \pi' must end with an introduction rule. But there is no introduction rule for \bot. Contradiction! \square

This argument is the first manifestation of an idea that will reappear throughout the course: the consistency of a logic is tied to the fact that every program (proof) can be run until it reaches a value (normal form). This is why proof assistants such as Lean require every function to terminate: a non-terminating program could "prove" \bot, as we saw with the Haskell function loop in the previous chapter.

1.3.5.4. Intuitionism in Lean

Lean's logic is intuitionistic by default: all the proofs above were built without any classical principle. The excluded middle is available as an additional axiom, Classical.em, whose use is recorded and can be inspected:

Classical.em : ∀ (p : Prop), p ∨ ¬p#check (Classical.em : ∀ (p : Prop), p ∨ ¬ p)
Classical.em : ∀ (p : Prop), p ∨ ¬p

Some consequences of the excluded middle, however, are already valid intuitionistically. For example, its double negation is provable without any additional axioms:

example : ¬¬(A ∨ ¬A) := fun h => h (Or.inr (fun a => h (Or.inl a))) end Ch02

1.3.5.5. References

  • MIMRAM, Samuel. Program = Proof. 2020.

  • GIRARD, Jean-Yves; LAFONT, Yves; TAYLOR, Paul. Proofs and Types. Cambridge University Press, 1989.

1.3.6. Exercises

  1. Build natural deduction derivations for the sequents below: (a) \vdash A \supset B \supset A; (b) \vdash (A \supset B \supset C) \supset (A \supset B) \supset A \supset C; (c) \{A \land B\} \vdash B \land A; (d) \{A \lor B, \neg A\} \vdash B; (e) \vdash A \supset \neg\neg A.

  2. Write Lean terms (without using tactics) corresponding to the derivations of the previous exercise.

  3. Show that, if the context is treated as a set, the exchange and contraction rules are unnecessary. Does the same hold for weakening?

  4. Describe the redundancy corresponding to the introduction of an implication followed by its elimination. Which operation of the \lambda-calculus removes it?

  5. Do the same for disjunction: write a derivation in which (\lor I_1) is immediately followed by (\lor E) and show how to simplify it.

  6. Using the BHK interpretation, explain why it is not reasonable to expect an intuitionistic proof of \neg\neg A \supset A. Then prove the formula A \supset \neg\neg A in Lean.

  7. Eliminate the redundancies from the proof of \{A, B, A \supset B \supset C\} \vdash C obtained by cut in the section on cut, and check that the result is a cut-free proof.