Formalising Mathematics Through the Curry-Howard Correspondence

In this article, I will explore the Curry-Howard Isomorphism, the bridge which demonstrates that mathematical proofs are the same as programs. I will also cover the maths behind it, and explore modern proof assistants.

St Andrews 202612 min read · 4 reads

Introduction

It may seem that pure mathematics and computer science are two separate fields, where one considers abstract propositions and formal proof, and the other involves algorithms, data structures and execution. However, in the late 20th century, logicians uncovered the Curry-Howard Isomorphism (or the Curry-Howard Correspondence). This demonstrated that formal logic and computation are not merely related but are the exact same mathematical system, just expressed in two different syntaxes. Therefore, a proposition in logic is mathematically identical to a type in computer science, a proof of a proposition is identical to a program, and simplifying a proof corresponds directly to running a program. In this article, we will explore this correspondence in depth, whilst also exploring the foundations of functional programming, namely λ\lambda-calculus and type theory.


Lambda Calculus and Type Theory

Before tackling the Curry-Howard Correspondence, we will first establish the formal model by which mathematical logic can be modelled through computation. This model is called λ\lambda-calculus (lambda calculus).

λ\lambda-calculus was introduced by mathematician Alonzo Church in the 1930s. It serves as another foundational theory of maths rather than set theory, in that every mathematical object is a function. More precisely, this current model we look at is called untyped λ\lambda-calculus (more on this later). We can define three basic syntactic terms:

$\begin{aligned} e ::= & ; x & \text{(Variable: representing a value or parameter)} \

| & ; \lambda x. , e & \text{(Abstraction / Function definition: taking input } x \text{ and returning expression } e) \

| & ; e_1 , e_2 & \text{(Application / Function call: applying function } e_1 \text{ to argument } e_2)

\end{aligned}$

Although λ\lambda-calculus is Turing-complete (capable of computing any computable function), it is unconstrained, and as a result allows for paradoxes, such as the Y combinator or infinite loops. For example, we can define the self-application function:

ω=λx. (x x)\omega = \lambda x. \, (x \, x)

If we apply this function to itself, we construct the term known as Ω\Omega (Omega):

Ω=ω ω=(λx. x x) (λx. x x)\Omega = \omega \, \omega = (\lambda x. \, x \, x) \, (\lambda x. \, x \, x)

When we attempt to evaluate (or β\beta-reduce) Ω\Omega, we substitute the argument (λx. x x)(\lambda x. \, x \, x) into the body of the function for xx:

Ω  ⇝  (λx. x x) (λx. x x)=Ω\Omega \;\rightsquigarrow\; (\lambda x. \, x \, x) \, (\lambda x. \, x \, x) = \Omega

Evaluating Ω\Omega yields Ω\Omega once again. We have therefore created an infinite loop, and so it does not ever reduce to a final value. In fact, in logic, a program running infinitely corresponds to a proof that never terminates (through the C-H correspondence).

To avoid these paradoxes, we constrain the system by introducing the notion of types. This is called Simply Typed λ\lambda-Calculus (λ→\lambda^\to).

Types

In λ→\lambda^\to, every expression is given a corresponding type (τ\tau). We construct types through base types (such as A,BA, B, representing primitive propositions or data types) and the function type constructor (→\to):

τ::=A  ∣  τ1→τ2\tau ::= A \;\mid\; \tau_1 \to \tau_2

Here, τ1→τ2\tau_1 \to \tau_2 represents a function that takes an input of type τ1\tau_1 and evaluates to an output of type τ2\tau_2. So, we define a type as either a base type or a function type from one type to another.

To ensure this system works, every term in the system must be well-typed. We express this using typing judgments within a typing context Γ\Gamma (gamma). In simple terms, a typing context Γ\Gamma acts like a reference list of known facts (e.g., "we assume variable xx is an integer"), and a typing judgment is the official rule checking whether a program expression legally makes sense under those assumed facts.

Γ⊢e:τ\Gamma \vdash e : \tau

This expression is read as follows: "Under the assumptions laid out in context Γ\Gamma, the expression ee has type τ\tau." If an expression cannot be assigned a valid type under these rules, it is rejected (i.e, a logically unsound expression).

Simply Typed Lambda Calculus

λ→\lambda^\to relies on two main rules on how it functions, namely abstraction and application.

Abstraction (→\to-Intro)

Γ,x:A⊢e:BΓ⊢(λx. e):A→B\frac{\Gamma, x : A \vdash e : B}{\Gamma \vdash (\lambda x. \, e) : A \to B}

The expression above means that if, under the assumption that variable xx has type AA, we can successfully compute an expression ee of type BB, then by abstracting over xx (binding it with a λ\lambda), we have created a function of type A→BA \to B.

Application (→\to-Elim)

Γ⊢e1:A→BΓ⊢e2:AΓ⊢e1 e2:B\frac{\Gamma \vdash e_1 : A \to B \quad \Gamma \vdash e_2 : A}{\Gamma \vdash e_1 \, e_2 : B}

Application can be defined as: if we have a function e1e_1 of type A→BA \to B, and we have an argument e2e_2 of type AA, applying the function to the argument (e1 e2e_1 \, e_2) yields a result of type BB.

To see how this system avoid paradoxes, let us look at the example from earlier. When we consider Simply Typed λ\lambda-Calculus (λ→\lambda^\to), self-referential terms like Ω\Omega become impossible to construct due to the typing rules established. Let us attempt to assign a type to the self-application term ω=λx. (x x)\omega = \lambda x. \, (x \, x). Here, to type-check the abstraction λx. (x x)\lambda x. \, (x \, x), we must first assign a type τ\tau to the variable xx (x:τx : \tau). Inside the body (x x)(x \, x), the variable xx acts as a function being applied to an argument, which is also xx. By the application rule (→\to-Elim), if xx is used as a function taking an argument of type τ\tau, then xx's type must be of the form τ→σ\tau \to \sigma (a function expecting a τ\tau). However, xx is simultaneously the argument itself, which means its type must also be τ\tau.

This forces an impossible type equation:\n

τ=τ→σ\tau = \tau \to \sigma

A type cannot contain itself as a proper subtype, as doing so would require an infinitely nested type structure (τ=(τ→σ)→σ=((τ→σ)→σ)→σ…\tau = (\tau \to \sigma) \to \sigma = ((\tau \to \sigma) \to \sigma) \to \sigma \dots), which is disallowed in λ→\lambda^\to. Because no valid type τ\tau can satisfy this equation, the term λx. (x x)\lambda x. \, (x \, x) is ill-typed and rejected by the type checker. This can be explored in a foundational theorem of λ→\lambda^\to, known as strong normalisation, guarantees that every well-typed program will eventually terminate and evaluate to a final value. In logic, this guarantees that every valid proof is finite and conclusive.

These two core operations, namely introducing a function and applying it, lead to modelling computation. More importantly, as we will see next, they form an exact structural mirror to the rules of logical deduction.


Deriving the Isomorphism

The Curry-Howard Isomorphism/Correspondence is what allows us to equate this model of computation with mathematical logic. The simplest way to perceive the correspondence is through looking at the elements side by side. In order to prove it fully, however, we would require Category Theory, but this is outside the scope of this article. If you are curious, mathematician Joachim Lambek proved that Intuitionistic Propositional Logic forms a specific type of category called a Cartesian Closed Category, and that Simply Typed Lambda Calculus also forms it. Hence, because both systems map to the same category, they are structurally identical, so an isomorphism exists.

Now, let's place standard formal logic (specifically intuitionistic natural deduction) side by side with the typing rules.

The main connection is that in propositional logic, we work with propositions (A,BA, B) and implications (A  ⟹  BA \implies B), and in type theory, we work with types (A,BA, B) and function types (A→BA \to B).

Abstraction. In logic, to prove an implication like A  ⟹  BA \implies B, we assume AA is true and show that BB logically follows:

Γ,A⊢BΓ⊢A  ⟹  B\frac{\Gamma, A \vdash B}{\Gamma \vdash A \implies B}

In λ→\lambda^\to, to construct a function of type A→BA \to B, we assume a variable xx of type AA and construct an expression ee of type BB:

Γ,x:A⊢e:BΓ⊢(λx. e):A→B\frac{\Gamma, x : A \vdash e : B}{\Gamma \vdash (\lambda x. \, e) : A \to B}

If you strip away the program variables (xx and ee) from the typing rule, you are left with the exact deduction rule for logical implication. Introducing a function space (→\to-Intro) is introducing a logical implication (  ⟹  \implies-Intro).

Application. In logic, if we know that A  ⟹  BA \implies B is true, and we independently know that AA is true, we can deduce BB. This is known as Modus Ponens:

Γ⊢A  ⟹  BΓ⊢AΓ⊢B\frac{\Gamma \vdash A \implies B \quad \Gamma \vdash A}{\Gamma \vdash B}

Similarly, in λ→\lambda^\to, if we have a function e1e_1 of type A→BA \to B and an argument e2e_2 of type AA, applying the function to the argument (e1 e2e_1 \, e_2) produces a term of type BB:

Γ⊢e1:A→BΓ⊢e2:AΓ⊢e1 e2:B\frac{\Gamma \vdash e_1 : A \to B \quad \Gamma \vdash e_2 : A}{\Gamma \vdash e_1 \, e_2 : B}

Consuming a function space via application (→\to-Elim) is applying Modus Ponens in logic.

This alignment establishes a formal dictionary between the two fields, and suggests a correspondence exists:

| Logic | Computer Science / Type Theory |

| -------------------------------------------| --------------------------------------------- |

| Proposition AA | Type AA |

| Proof of proposition AA | Program / Term ee of type AA |

| Implication A  ⟹  BA \implies B | Function Type A→BA \to B |

| Conjunction (A∧BA \land B) | Product Type (A×BA \times B / Pairs) |

| Disjunction (A∨BA \lor B) | Sum Type (A+BA + B / Either) |

| Tautology (True Proposition) | Inhabited Type (A type with a valid term) |

| Proof Simplification (β\beta-reduction) | Program Execution (Evaluation) |

Under the correspondence, a proposition is considered true if and only if its corresponding type is inhabited by a valid, well-typed program. In other words, this shows that writing a program that compiles is mathematically identical to writing a formal proof.


Computation and Proof Simplification

We have established in the previous sections that a type is a proposition and a term (program) is a proof. Now, let us consider the execution a program. In computation, running a program means performing β\beta-reduction. This is the idea of substituting arguments into functions until the code simplifies down to a final value. Under the Curry-Howard correspondence, this idea has a direct pair, namely proof normalisation.

Let us consider how β\beta-reduction works. Consider this simple function application where we feed an argument into an abstraction:

(λx. x+2) 3  ⇝  3+2  ⇝  5(\lambda x. \, x + 2) \, 3 \;\rightsquigarrow\; 3 + 2 \;\rightsquigarrow\; 5

During execution, the reducible expression is evaluated by plugging 33 in for xx. In logic, a proof can be simplified / normalised. When performing β\beta-reduction on a program, it is the equivalent of simplifying a mathematical proof.

Moreover, a program that has finished evaluating to a value corresponds to a normal form proof, a proof that cannot be simplified any further.


Dependent Type Theory & Quantifiers

Up to this point, Simply Typed λ\lambda-Calculus (λ→\lambda^\to) has allowed us to model basic logic, namely connecting statements with implications (A→BA \to B), conjunctions (A×BA \times B), and disjunctions (A+BA + B). However, standard mathematics requires more than these, such as the following quantifiers:

  • Universal Quantification (∀\forall): "For all integers xx, x+0=xx + 0 = x."
  • Existential Quantification (∃\exists): "There exists an integer xx such that x>5x > 5."

Simple types cannot express these statements, as a simple type (like Int→Int\text{Int} \to \text{Int}) cannot inspect or depend on the actual value being passed into it. To solve this, we consider Dependent Type Theory.

In Dependent Type Theory, a type can depend on a term (a value). A classic example is the type of fixed-length vectors:

  • List Int is a standard simple type (a list of integers of unknown length).
  • Vect n Int is a dependent type, where the type itself is parametrized by the integer value n (the exact length of the vector).

Here, the type changes based on the value of nn:

Vect 3  Int≠Vect 5  Int\text{Vect } 3 \; \text{Int} \quad \neq \quad \text{Vect } 5 \; \text{Int}

By allowing types to depend on values, two new fundamental type constructors emerge that directly correspond to logical quantifiers:

Π\Pi-Types (Dependent Product Types). A Π\Pi-type is a function type where the type of the output depends on the value of the input:

∏x:AB(x)\prod_{x : A} B(x)

This represents universal quantification (∀x∈A,B(x)\forall x \in A, B(x)), as proving a statement for all xx means providing a program (function) that can accept any input xx and successfully produce a valid proof of B(x)B(x) for that specific value.

Σ\Sigma-Types (Dependent Sum Types). A Σ\Sigma-type (or Sigma-type) is a pair where the type of the second element depends on the value of the first element:

∑x:AB(x)\sum_{x : A} B(x)

This represents existential quantification (∃x∈A,B(x)\exists x \in A, B(x)), as proving that something exists means providing a value xx, along with a proof yy that B(x)B(x) holds.

Dependent Type Theory is a very powerful form of type theory, and has many modern applications. For instance, it forms the foundation of all modern proof assistants, such as Lean, Coq, or Agda.

In Practice

Languages like Lean 4 turn the isomorphism into a functional working environment. In Lean, mathematicians and software engineers write mathematical theorems as type signatures, and construct proofs by writing code that inhabits those types:

-- A simple theorem in Lean: P → Q → P
theorem const_proof (P Q : Prop) : P → Q → P :=
  fun hp : P => fun hq : Q => hp

Here, the proof is a lambda abstraction (fun hp => fun hq => hp), returning the original evidence hp. When Lean compiles this code, the type checker verifies the proof automatically, as if the code type-checks, the proof is guaranteed to be mathematically sound.


Conclusion

In conclusion, we have explored the basics of lambda calculus and type theory, and showed how we can equate programs to proofs through types. The Curry-Howard Isomorphism demonstrates that logic and computation are not merely analogous but in fact mathematically identical. Moreover, by extending this correspondence from Simply Typed λ\lambda-Calculus to Dependent Type Theory, we can create programming languages which verify proofs for us, such as LEAN.

If you are curious and seek to learn more about type theory or the Curry-Howard Isomorphism, I recommend Lectures on the Curry-Howard Isomorphism by Morten Heine Sørensen and Pawel Urzyczyn, or, if you would like to learn how to write proofs in LEAN, Theorem Proving in Lean 4 is worth a read. If you have any questions, please do contact me via email (solecki-servi.m25@etoncollege.org.uk).

Reader discussion

Join the conversation.

0 contributions

No comments yet. Start the discussion.

Deep Dive

Written by students at Eton.
Read by anyone curious.

Your cookie preferences

We use essential cookies to run this website. With your permission, we also use analytics cookies to understand how visitors use the site.