In mathematical logic and type theory, the λ-cube (also written lambda 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 kind of dependency between terms and types. Here, "dependency" refers to the capacity of a term or type to bind a term or type. The respective dimensions of the λ-cube correspond to:
→
\uparrow
\nearrow
The different ways to combine these three dimensions yield the 8 vertices of the cube, each corresponding to a different kind of typed system. The λ-cube can be generalized into the concept of a pure type system.
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, with the typing rule:
\Gamma,x:\sigma \vdash t:\tau | |
\Gamma \vdash λx.t:\sigma\to\tau |
In System F (also named λ2 for the "second-order typed lambda calculus")[2] there is another type of abstraction, written with a
Λ
\Gamma \vdash t:\sigma | |
\Gamma \vdash Λ\alpha.t:\Pi\alpha.\sigma |
if\alphadoesnotoccurfreein\Gamma
The terms beginning with a
Λ
'a
and return an element of that type. This type corresponds in λ2 to the type \Pi\alpha.\alpha\to\alpha
In System F
\underline{\omega}
A
TREE:=λA:*.\PiB.(A\toB)\to(B\toB\toB)\toB
A:*
A
A
TREE
A
This type constructor can be applied to other types to obtain new types. E.g., to obtain type of trees of integers:
System F
\underline{\omega}
In the λP system, also named λΠ, and closely related to the LF Logical Framework, one has so called dependent types. These are types that are allowed to depend on terms. The crucial introduction rule of the system is
\Gamma,x:A \vdash B:* | |
\Gamma \vdash (\Pix:A.B):* |
where
*
\Pi
System Fω combines both the
Λ
\underline{\omega}
In the calculus of constructions, denoted as λC in the cube or as λPω,[1] these four 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
\square
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
S:=\{*,\square\}
s
V
x,y,...
A:=x\mids\midA~A\midλx:A.A\mid\Pix:A.A
and
A\toB
\Pix:A.B
x
B
The environments, as is usual in typed systems, are given by
\Gamma:=\emptyset\mid\Gamma,x:A
The notion of β-reduction is common to all systems in the cube. It is written
\to\beta
=\beta
The following typing rules are also common to all systems in the cube:
The difference between the systems is in the pairs of sorts that are allowed in the following two typing rules:
\Gamma\vdashA:s1 \Gamma,x:A\vdashB:C \Gamma,x:A\vdashC:s2 | |
\Gamma\vdashλx:A.B:\Pix:A.C |
(Abstraction)
The correspondence between the systems and the pairs allowed in the rules is the following:
(s1,s2) | (*,*) | (*,\square) | (\square,*) | (\square,\square) | |
---|---|---|---|---|---|
λ→ | |||||
λP | |||||
λ2 | |||||
λω | |||||
λP2 | |||||
λPω | |||||
λω | |||||
λC |
Each direction of the cube corresponds to one pair (excluding the pair shared by all systems), and in turn each pair corresponds to one possibility of dependency between terms and types:
A typical derivation that can be obtained isor with the arrow shortcutclosely resembling the identity (of type ) 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 .
The computing power is quite weak, it corresponds to the extended polynomials (polynomials together with a conditional operator).[3]
In λ2, such terms can be obtained aswith . If one reads 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 , 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 functions definable in λ2 are those provably total in second-order Peano arithmetic.[4] In particular, all primitive recursive functions are definable.
In λP, the ability to have types depending on terms means one can express logical predicates. For instance, the following is derivable:which corresponds, via the Curry-Howard isomorphism, to a proof of
(\forallx:A,Px\toQ)\to(\forallx:A,Px)\toQ
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 one has
\Gamma\vdashA:P((λx.x)y)
\Gamma\vdashB:\Pix:P(y).C
\Gamma\vdashA:P(y)
\Gamma\vdashBA:C
In λω, the following operatoris definable, that is
\vdashAND:*\to*\to*
From a computing point of view, λω is extremely strong, and has been considered as a basis for programming languages.[6]
The calculus of constructions has both the predicate expressiveness of λP and the computational power of λω, hence why λC is also called λPω,[1] so it is very powerful, both on the logical side and on the computational side.
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. The Coq system is based on an extension of λC with a linear hierarchy of universes, rather than only one untypable , 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
\{*,\square\}
\{(*,*,*)\}\subseteqR\subseteq\{(*,*,*),(*,\square,\square),(\square,*,*),(\square,\square,\square)\}
Via the Curry-Howard isomorphism, there is a one-to-one correspondence between the systems in the lambda cube and logical systems, namely:
System of the cube | Logical System | |
---|---|---|
λ→ | (Zeroth-order) Propositional Calculus | |
λ2 | Second-order Propositional Calculus | |
λ | Weakly Higher Order Propositional Calculus | |
λω | Higher Order Propositional Calculus | |
λP | (First order) Predicate Logic | |
λP2 | Second-order Predicate Calculus | |
λP | Weak Higher Order Predicate Calculus | |
λC | Calculus of Constructions |
\wedge
\neg
All systems in the cube enjoy
M\to\betaN
M\to\betaN'
N''
N
* | |
\to | |
\beta |
N''
N'
* | |
\to | |
\beta |
N''
\Gamma\vdashM:T
M\to\betaM'
\Gamma\vdashM':T
\Gamma\vdashA:B
\Gamma\vdashA:B'
B=\betaB'
All of these can be proven on generic pure type systems.[7]
Any term well-typed in a system of the cube is strongly normalizing, although this property is not common to all pure type systems. No system in the cube is Turing complete.
Subtyping however is not represented in the cube, even though systems like
\omega | |
F | |
<: |
\omega | |
F | |
<: |
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. 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.