# Lambda cube

The lambda cube. Direction of each arrow is direction of inclusion.

In mathematical logic and type theory, the λ-cube is a framework introduced by Henk Barendregt [1] to investigate the different dimensions in which the calculus of constructions is a generalization of the simply typed λ-calculus. Each dimension of the cube corresponds to a new way of making objects depend on other objects, namely

The different ways to combine these three dimension yield the 8 vertices of the cube, each corresponding to a different kind of typed system.

## Examples of Systems

### Simply typed lambda calculus

The simplest system found in the λ-cube is the simply typed lambda calculus, also called λ→. In this system, the only way to construct an abstraction is by making a term depend on a term variable, with the rule

${\displaystyle {\frac {\Gamma ,x:\sigma \vdash t:\tau }{\Gamma \vdash \lambda x\cdot t:\sigma \to \tau }}}$

### System F

In System F, also named λ2, there is another type of abstraction, written with a ${\displaystyle \Lambda }$, that allows terms to depend on types, with the following rule:

${\displaystyle {\frac {\Gamma \vdash t:\sigma }{\Gamma \vdash \Lambda \alpha \cdot t:\Pi \alpha \cdot \sigma }}\alpha {\text{ not free in }}\Gamma }$

The terms beginning with a ${\displaystyle \Lambda }$ are called polymorphic, as they can be applied to different types to get different functions, similarly to polymorphic functions in ML-like languages. For instance, the polymorphic identity

fun x -> x


of OCaml has type

'a -> 'a


meaning it can take an argument of any type and return an element of that type. This type corresponds in λ2 to the type ${\displaystyle \Lambda \alpha \cdot \alpha \to \alpha }$.

### Lambda-P

In the λP system, also named ΛΠ, and closely related to the Logical Framework, one has so called dependent types. These are types that are allowed to depend on terms. The crucial induction rule of the system is

${\displaystyle {\frac {\Gamma ,x:A\vdash B:*}{\Gamma \vdash \Pi x:A\cdot B:*}}}$

where ${\displaystyle *}$represents valid types. The new type constructor ${\displaystyle \Pi }$corresponds via the Curry-Howard isomorphism to a universal quantifier, and the system λP as a whole corresponds to first order logic with implication as only connective. An example of these dependent types in concrete programming is the type of vectors on a certain length: the length is a term, on which the type depends.

### System Fω

In System Fω, one has the ${\displaystyle \Lambda }$ constructor of System F, but another construction is allowed: types can be constructed from other types. This is called type constructors, and an example would be ${\displaystyle TREE\ A\ B:=(A\to B)\to (B\to B\to B)\to B}$ with ${\displaystyle A}$ and ${\displaystyle B}$ free type variable. In concrete programming, this feature corresponds to the ability to define type constructors inside the language, rather than considering them as primitives. The previous type constructor roughly corresponds to the following definition of a trees with labeled leaves in OCaml:

type tree = | Leaf of a | Node of 'a tree * 'a tree


### Calculus of constructions

In the calculus of constructions, denoted as λC in the cube, these three features cohabit, so that both types and terms can depend on types and terms. The clear border that exists in λ→ between terms and types is somewhat abolished, as all types except the universal ${\displaystyle \square }$ are themselves terms with a type.

## Formal definition

As for all systems based upon the simply typed lambda calculus, all systems in the cube are given in two steps: first, raw terms, together with a notion of β-reduction, and then typing rules that allow to type those terms.

The set of sorts is defined as ${\displaystyle S:=\{*,\square \}}$, sorts are represented with the letter ${\displaystyle s}$. There is also a set ${\displaystyle V}$ of variables, represented by the letters ${\displaystyle x,y,\dots }$. The raw terms of the eight systems of the cube are given by the following syntax:

${\displaystyle A:=x\mid s\mid A~A\mid \lambda x:A\cdot A\mid \Pi x:A\cdot A}$

and ${\displaystyle A\to B}$ denoting ${\displaystyle \Pi x:A\cdot B}$ when ${\displaystyle x}$ does not occur free in ${\displaystyle B}$.

The environment, as is usual in typed systems, are given by ${\displaystyle \Gamma :=\emptyset \mid \Gamma ,x:T}$

The notion of β-reduction is common to all systems in the cube. It is written ${\displaystyle \to _{\beta }}$ and given by the rules

${\displaystyle {\frac {}{(\lambda x:A\cdot B)~C\to _{\beta }B[C/x]}}}$
${\displaystyle {\frac {B\to _{\beta }B'}{\lambda x:A\cdot B\to _{\beta }\lambda x:A\cdot B'}}}$
${\displaystyle {\frac {A\to _{\beta }A'}{\lambda x:A\cdot B\to _{\beta }\lambda x:A'\cdot B}}}$
${\displaystyle {\frac {B\to _{\beta }B'}{\Pi x:A\cdot B\to _{\beta }\Pi x:A\cdot B'}}}$
${\displaystyle {\frac {A\to _{\beta }A'}{\Pi x:A\cdot B\to _{\beta }\Pi x:A'\cdot B}}}$
Its reflexive, transitive closure is written ${\displaystyle =_{\beta }}$.

The following typing rules are also common to all systems in the cube:

${\displaystyle {\frac {}{\vdash *:\square }}\quad {\text{(Axiom)}}}$
${\displaystyle {\frac {\Gamma \vdash A:s\quad x{\text{ does not occur in }}\Gamma }{\Gamma \vdash x:A}}\quad {\text{(Start)}}}$
${\displaystyle {\frac {\Gamma \vdash A:B\quad \Gamma \vdash C:s}{\Gamma ,x:C\vdash A:B}}\quad {\text{(Weakening)}}}$
${\displaystyle {\frac {\Gamma \vdash C:\Pi x:A\cdot B\quad \Gamma \vdash a:A}{\Gamma \vdash Ca:B[a/x]}}\quad {\text{(Application)}}}$
${\displaystyle {\frac {\Gamma \vdash A:B\quad B=_{\beta }B'\quad \Gamma \vdash B':s}{\Gamma \vdash A:B'}}\quad {\text{(Conversion)}}}$
The difference between the systems is in the pairs of sorts ${\textstyle (s_{1},s_{2})}$ that are allowed in the following two typing rules:
${\displaystyle {\frac {\Gamma \vdash A:s_{1}\quad \Gamma ,x:A\vdash B:s_{2}}{\Gamma \vdash \Pi x:A\cdot B:s_{2}}}\quad {\text{(Product)}}}$
${\displaystyle {\frac {\Gamma \vdash A:s_{1}\quad \Gamma ,x:A\vdash b:B\quad \Gamma ,x:A\vdash B:s_{2}}{\Gamma \vdash \lambda x:A\cdot b:\Pi x:A\cdot B}}\quad {\text{(Abstraction)}}}$

The correspondence between the systems and the pairs ${\textstyle (s_{1},s_{2})}$ allowed in the rules is the following:

${\displaystyle (s_{1},s_{2})}$ ${\displaystyle (*,*)}$ ${\displaystyle (*,\square )}$ ${\displaystyle (\square ,*)}$ ${\displaystyle (\square ,\square )}$
λ→ x
λP x x
λ2 x x
λω x x
λP2 x x x
λPω x x x
λω x x x
λC x x x x

Each direction of the cube corresponds to one pair (excluding the pair ${\textstyle (*,*)}$ shared by all systems), and in turn each pair corresponds to one possibility of dependency between terms and types:

• ${\textstyle (*,*)}$ allows terms to depend on terms.
• ${\textstyle (*,\square )}$ allows types to depend on terms.
• ${\textstyle (\square ,*)}$ allows terms to depend on types.
• ${\textstyle (\square ,\square )}$ allows types to depend on types.

## Comparison between the systems

### λ→

A typical derivation that can be obtained is

${\displaystyle \alpha :*\vdash \lambda x:\alpha \cdot x:\Pi x:\alpha \cdot \alpha }$
or with the arrow shortcut
${\displaystyle \alpha :*\vdash \lambda x:\alpha \cdot x:\alpha \to \alpha }$
closely resembling the identity (of type ${\textstyle \alpha }$) of the usual λ→. Note that all types used must appear in the context, because the only derivation that can be done in an empty context is ${\textstyle \vdash *:\square }$.

The computing power is quite weak, it corresponds to the extended polynomials (polynomials together with a conditional operator) [2].

### λ2

In λ2, such terms can be obtained as

${\displaystyle \vdash (\lambda \beta :*\cdot \lambda x:\bot \cdot x\beta ):\Pi \beta :*\cdot \bot \to \beta }$
with ${\textstyle \bot =\Pi \alpha :*\cdot \alpha }$. If one reads ${\textstyle \Pi }$ as a universal quantification, via the Curry-Howard isomorphism, this can be seen as a proof of the principle of explosion. In general, λ2 adds the possibility to have impredicative types such as ${\textstyle \bot }$, that is terms quantifying over all types including themselves.
The polymorphism also allows the construction of functions that were not constructible in λ→. More precisely, the function definable in System F are those provably total in second order Peano arithmetic[3]. In particular, all primitive recursive functions are definable.

### λP

In λP, the ability to have types depending on terms means one can express logical predicates. For instance, the following is derivable:

${\displaystyle \alpha :*,a_{0}:\alpha ,p:\alpha \to *,q:*\vdash \lambda z:(\Pi x:\alpha \cdot px\to q)\cdot \lambda y:(\Pi x:\alpha \cdot px)\cdot (xa_{0})(ya_{0}):(\Pi x:\alpha \cdot px\to q)\to (\Pi x:\alpha \cdot px)\to q}$
which corresponds, via the Curry-Howard isomorphism, to a proof of ${\displaystyle (\forall x:A,Px\to Q)\to (\forall x:A,Px)\to Q}$.
From the computational point of view, however, having dependent types does not enhance computational power, only the possibility to express more precise type properties[4].

The conversion rule is strongly needed when dealing with dependent types, because it allows to perform computation on the terms in the type. For instance, if you have ${\displaystyle \Gamma \vdash A:P((\lambda x\cdot x)y)}$ and ${\displaystyle \Gamma \vdash B:\Pi x:P(y)\cdot C}$, you need to apply the conversion rule to obtain ${\displaystyle \Gamma \vdash A:P(y)}$ to be able to type ${\displaystyle \Gamma \vdash BA:C}$.

### λω

In λω, the following operator

${\displaystyle AND:=\lambda \alpha :*\cdot \lambda \beta :*\cdot \Pi \gamma :*\cdot (\alpha \to \beta \to \gamma )\to \gamma }$
is definable, that is ${\displaystyle \vdash AND:*\to *\to *}$. The derivation
${\displaystyle \alpha :*,\beta :*\vdash \Pi \gamma :*\cdot (\alpha \to \beta \to \gamma )\to \gamma :*}$
can be obtained already in λω, however the polymorphic ${\textstyle AND}$ can only be defined if the rule ${\textstyle (\square ,*)}$ is also present.

From a computing point of view, λω is extremely strong, and has been considered as a basis for programming languages [5].

### λC

The calculus of constructions has both the predicate expressiveness of λC and the computational power of λω, so it is very powerful, both on the logical side and on the computational side.

## Relation to other systems

The system Automath is similar to λ2 from a logical point of view. The ML-like languages, from a typing point of view, lie somewhere between λ→ and λ2, as they admit a restricted kind of polymorphic types, that is the types in prenex normal form. However, because they feature some recursion operators, their computing power is greater than that of λ2.[4] The Coq system is based on an extension of λC with a linear hierarchy of universes, rather than only one untypable ${\textstyle \square }$, and the ability to construct inductive types.

Pure Type Systems can be seen as a generalization of the cube, with an arbitrary set of sorts, axiom, product and abstraction rules. Conversely, the systems of the lambda cube can be expressed as Pure Type Systems with two sorts ${\displaystyle \{*,\square \}}$, the only axiom ${\textstyle \{*,\square \}}$, and a set of rules ${\textstyle R}$ such that ${\displaystyle \{(*,*,*)\}\subseteq R\subseteq \{(*,*,*),(*,\square ,\square ),(\square ,*,*),(\square ,\square ,\square )\}}$[1].

Via the Curry-Howard isomorphism, there is a one-to-one correspondence between the systems in the lambda cube and logical systems[1], namely:

System of the cube Logical System
λ→ (First Order) Propositional Calculus
λ2 Second Order Propositional Caculus
λω Weakly Higher Order Propositional Calculus
λω Higher Order Propositional Calculus
λP (First Order) Predicate Logic
λP2 Second Order Propositional Calculus
λPω Weak Higher Order Propositional Calculus
λC Calculus of Constructions

All the logics are implicative (i.e. the only connectives are ${\textstyle \to }$ and ${\textstyle \forall }$), however one can define other connectives such as ${\displaystyle \wedge }$ or ${\displaystyle \neg }$ in an impredicative way in second and higher order logics. In the weak higher order logics, there are variables for higher order predicates, but no quantification on those can be done.

## Common properties

All systems in the cube enjoy

• the Church-Rosser property: if ${\displaystyle M\to _{\beta }N}$ and ${\displaystyle M\to _{\beta }N'}$ then there exists ${\displaystyle N''}$ such that ${\displaystyle N\to _{\beta }^{*}N''}$ and ${\displaystyle N'\to _{\beta }^{*}N''}$;
• the subject reduction property: if ${\displaystyle \Gamma \vdash M:T}$ and ${\displaystyle M\to _{\beta }M'}$ then ${\displaystyle \Gamma \vdash M':T}$;
• the uniqueness of types: if ${\displaystyle \Gamma \vdash A:B}$ and ${\displaystyle \Gamma \vdash A:B'}$ then ${\displaystyle B=_{\beta }B'}$.

All of these can be proven on generic pure type systems[6].

Any term well-typed in a system of the cube is strongly normalizing[1], although this property is not common to all pure type systems. No system in the cube is Turing complete[4].

## Subtyping

Subtyping however is not represented in the cube, even though systems like ${\displaystyle F_{<:}^{\omega }}$, known as higher-order bounded quantification, which combines subtyping and polymorphism are of practical interest, and can be further generalized to bounded type operators. Further extensions to ${\displaystyle F_{<:}^{\omega }}$ allow the definition of purely functional objects; these systems were generally developed after the lambda cube paper was published.[7]

The idea of the cube is due to the mathematician Henk Barendregt (1991). The framework of pure type systems generalizes the lambda cube in the sense that all corners of the cube, as well as many other systems can be represented as instances of this general framework.[8] This framework predates the lambda cube by a couple of years. In his 1991 paper, Barendregt also defines the corners of the cube in this framework.

• In his Habilitation à diriger les recherches[9], Olivier Ridoux gives a cut-out template of the lambda cube and also a dual representation of the cube as an octahedron, where the 8 vertices are replaced by faces, as well as a dual representation as a dodecahedron, where the 12 edges are replaced by faces.
• Homotopy type theory

## Notes

1. ^ a b c d Barendregt, Henk (1991). "Introduction to generalized type systems". Journal of Functional Programming. 1 (2): 125–154. doi:10.1017/s0956796800020025. ISSN 0956-7968.
2. ^ Schwichtenberg, Helmut (1975). "Definierbare Funktionen imλ-Kalkül mit Typen". Archiv für Mathematische Logik und Grundlagenforschung. 17 (3–4): 113–114. doi:10.1007/bf02276799. ISSN 0933-5846.
3. ^ Jean-Yves., Girard (1989). Proofs and types. Cambridge University Press. OCLC 504959682.
4. ^ a b c Ridoux, Olivier (1998). Lambda-Prolog de A à Z ... ou presque. [s.n.] OCLC 494473554.
5. ^ C., Pierce, Benjamin (1989). Programming in higher-order typed lambda-calculi. Carnegie Mellon University, Computer Science Dept. OCLC 20442222.
6. ^ Sørensen, Morten Heine; Urzyczyin, Pawel (2006), "Pure type systems and the λ-cube", Lectures on the Curry-Howard Isomorphism, Elsevier, pp. 343–359, doi:10.1016/s0049-237x(06)80015-7, ISBN 9780444520777
7. ^ Pierce, Benjamin (2002). Types and programming languages. MIT Press. pp. 467–490. ISBN 978-0262162098. OCLC 300712077.
8. ^ Pierce, Benjamin (2002). Types and programming languages. MIT Press. p. 466. ISBN 978-0262162098. OCLC 300712077.
9. ^ Ridoux, Olivier (1998). Lambda-Prolog de A à Z ... ou presque. [s.n.] p. 70. OCLC 494473554.