Lambda cube
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:
- x-axis ([math]\displaystyle{ \rightarrow }[/math]): types that can bind terms, corresponding to dependent types.
- y-axis ([math]\displaystyle{ \uparrow }[/math]): terms that can bind types, corresponding to polymorphism.
- z-axis ([math]\displaystyle{ \nearrow }[/math]): types that can bind types, corresponding to (binding) type operators.
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.
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, with the typing rule:
[math]\displaystyle{ \frac{\Gamma, x : \sigma \;\vdash\; t : \tau}{\Gamma \;\vdash\; \lambda x . t : \sigma \to \tau} }[/math]
(λ2) System F
In System F (also named λ2 for the "second-order typed lambda calculus")[2] there is another type of abstraction, written with a [math]\displaystyle{ \Lambda }[/math], that allows terms to depend on types, with the following rule:
[math]\displaystyle{ \frac{\Gamma \;\vdash\; t : \sigma}{\Gamma \;\vdash\; \Lambda \alpha . t : \Pi \alpha . \sigma} \;\text{ if } \alpha\text{ does not occur free in }\Gamma }[/math]
The terms beginning with a [math]\displaystyle{ \Lambda }[/math] 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 'a
and return an element of that type. This type corresponds in λ2 to the type [math]\displaystyle{ \Pi \alpha . \alpha \to \alpha }[/math].
(λω) System Fω
In System F[math]\displaystyle{ \underline{\omega} }[/math] a construction is introduced to supply types that depend on other types. This is called a type constructor and provides a way to build "a function with a type as a value".[3] An example of such a type constructor is the type of binary trees with leaves labeled by data of a given type [math]\displaystyle{ A }[/math]: [math]\displaystyle{ \mathsf{TREE} := \lambda A : * . \Pi B . (A \to B) \to (B \to B \to B) \to B }[/math], where "[math]\displaystyle{ A:* }[/math]" informally means "[math]\displaystyle{ A }[/math] is a type". This is a function that takes a type parameter [math]\displaystyle{ A }[/math] as an argument and returns the type of [math]\displaystyle{ \mathsf{TREE} }[/math]s of values of type [math]\displaystyle{ A }[/math]. 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 tree with labeled leaves in OCaml:
type 'a tree = | Leaf of 'a | Node of 'a tree * 'a tree
This type constructor can be applied to other types to obtain new types. E.g., to obtain type of trees of integers:
type int_tree = int tree
System F[math]\displaystyle{ \underline{\omega} }[/math] is generally not used on its own, but is useful to isolate the independent feature of type constructors.[4]
(λP) Lambda-P
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
[math]\displaystyle{ \frac{\Gamma, x : A \;\vdash\; B : *}{\Gamma \;\vdash\; (\Pi x : A . B) : *} }[/math]
where [math]\displaystyle{ * }[/math] represents valid types. The new type constructor [math]\displaystyle{ \Pi }[/math] 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ω
System Fω combines both the [math]\displaystyle{ \Lambda }[/math] constructor of System F and the type constructors from System F[math]\displaystyle{ \underline{\omega} }[/math]. Thus System Fω provides both terms that depend on types and types that depend on types.
(λC) Calculus of constructions
In the calculus of constructions, denoted as λC in the cube or as λPω,[1]:130 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 [math]\displaystyle{ \square }[/math] 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 [math]\displaystyle{ S := \{*, \square \} }[/math], sorts are represented with the letter [math]\displaystyle{ s }[/math]. There is also a set [math]\displaystyle{ V }[/math] of variables, represented by the letters [math]\displaystyle{ x,y,\dots }[/math]. The raw terms of the eight systems of the cube are given by the following syntax:
[math]\displaystyle{ A := x \mid s \mid A~A \mid \lambda x : A . A \mid \Pi x : A . A }[/math]
and [math]\displaystyle{ A \to B }[/math] denoting [math]\displaystyle{ \Pi x : A . B }[/math] when [math]\displaystyle{ x }[/math] does not occur free in [math]\displaystyle{ B }[/math].
The environments, as is usual in typed systems, are given by [math]\displaystyle{ \Gamma := \emptyset \mid \Gamma, x : A }[/math]
The notion of β-reduction is common to all systems in the cube. It is written [math]\displaystyle{ \to_{\beta} }[/math] and given by the rules[math]\displaystyle{ \frac{}{(\lambda x : A . B)~C \to_{\beta} B[C/x]} }[/math][math]\displaystyle{ \frac{B \to_{\beta} B'}{\lambda x : A . B \to_{\beta} \lambda x : A . B'} }[/math][math]\displaystyle{ \frac{A \to_{\beta} A'}{\lambda x : A . B \to_{\beta} \lambda x : A' . B} }[/math][math]\displaystyle{ \frac{B \to_{\beta} B'}{\Pi x : A . B \to_{\beta} \Pi x : A . B'} }[/math][math]\displaystyle{ \frac{A \to_{\beta} A'}{\Pi x : A . B \to_{\beta} \Pi x : A' . B} }[/math]Its reflexive, transitive closure is written [math]\displaystyle{ =_\beta }[/math].
The following typing rules are also common to all systems in the cube:[math]\displaystyle{ \frac{}{\vdash * : \square}\quad \text{(Axiom)} }[/math][math]\displaystyle{ \frac{\Gamma \vdash A : s \quad x\text{ does not occur in }\Gamma}{\Gamma, x : A \vdash x : A }\quad \text{(Start)} }[/math][math]\displaystyle{ \frac{\Gamma \vdash A : B \quad \Gamma \vdash C : s}{\Gamma, x : C \vdash A : B}\quad \text{(Weakening)} }[/math][math]\displaystyle{ \frac{\Gamma \vdash C : \Pi x : A . B \quad \Gamma \vdash a : A}{\Gamma \vdash Ca : B[a/x]}\quad\text{(Application)} }[/math][math]\displaystyle{ \frac{\Gamma \vdash A : B \quad B =_{\beta} B' \quad \Gamma \vdash B' : s}{\Gamma \vdash A : B'}\quad\text{(Conversion)} }[/math]The difference between the systems is in the pairs of sorts [math]\displaystyle{ (s_1,s_2) }[/math] that are allowed in the following two typing rules:[math]\displaystyle{ \frac{\Gamma \vdash A : s_1 \quad \Gamma, x : A \vdash B : s_2}{\Gamma \vdash \Pi x : A . B : s_2}\quad\text{(Product)} }[/math][math]\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 . b : \Pi x : A . B}\quad\text{(Abstraction)} }[/math]
The correspondence between the systems and the pairs [math]\displaystyle{ (s_1,s_2) }[/math] allowed in the rules is the following:
[math]\displaystyle{ (s_1, s_2) }[/math] | [math]\displaystyle{ (*,*) }[/math] | [math]\displaystyle{ (*,\square) }[/math] | [math]\displaystyle{ (\square,*) }[/math] | [math]\displaystyle{ (\square,\square) }[/math] |
---|---|---|---|---|
λ→ | ![]() |
![]() |
![]() |
![]() |
λP | ![]() |
![]() |
![]() |
![]() |
λ2 | ![]() |
![]() |
![]() |
![]() |
λω | ![]() |
![]() |
![]() |
![]() |
λP2 | ![]() |
![]() |
![]() |
![]() |
λPω | ![]() |
![]() |
![]() |
![]() |
λω | ![]() |
![]() |
![]() |
![]() |
λC | ![]() |
![]() |
![]() |
![]() |
Each direction of the cube corresponds to one pair (excluding the pair [math]\displaystyle{ (*,*) }[/math] shared by all systems), and in turn each pair corresponds to one possibility of dependency between terms and types:
- [math]\displaystyle{ (*,*) }[/math] allows terms to depend on terms.
- [math]\displaystyle{ (*,\square) }[/math] allows types to depend on terms.
- [math]\displaystyle{ (\square, *) }[/math] allows terms to depend on types.
- [math]\displaystyle{ (\square, \square) }[/math] allows types to depend on types.
Comparison between the systems
λ→
A typical derivation that can be obtained is[math]\displaystyle{ \alpha : * \vdash \lambda x : \alpha . x : \Pi x : \alpha . \alpha }[/math]or with the arrow shortcut[math]\displaystyle{ \alpha : * \vdash \lambda x : \alpha . x : \alpha \to \alpha }[/math]closely resembling the identity (of type [math]\displaystyle{ \alpha }[/math]) 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 [math]\displaystyle{ \vdash * : \square }[/math].
The computing power is quite weak, it corresponds to the extended polynomials (polynomials together with a conditional operator).[5]
λ2
In λ2, such terms can be obtained as[math]\displaystyle{ \vdash (\lambda \beta : * . \lambda x : \bot . x \beta) : \Pi \beta : * . \bot \to \beta }[/math]with [math]\displaystyle{ \bot = \Pi \alpha : * . \alpha }[/math]. If one reads [math]\displaystyle{ \Pi }[/math] 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 [math]\displaystyle{ \bot }[/math], 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.[6] 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:[math]\displaystyle{ \alpha : *, a_0 : \alpha, p : \alpha \to *, q : * \vdash \lambda z : (\Pi x : \alpha . p x \to q) . \lambda y : (\Pi x : \alpha . p x) . (z a_0) (y a_0) : (\Pi x : \alpha . p x \to q) \to (\Pi x : \alpha . p x) \to q }[/math]which corresponds, via the Curry-Howard isomorphism, to a proof of [math]\displaystyle{ (\forall x : A, P x \to Q) \to (\forall x : A, P x) \to Q }[/math].
From the computational point of view, however, having dependent types does not enhance computational power, only the possibility to express more precise type properties.[7]
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 [math]\displaystyle{ \Gamma \vdash A : P((\lambda x . x)y) }[/math] and [math]\displaystyle{ \Gamma \vdash B : \Pi x : P(y) . C }[/math], you need to apply the conversion rule to obtain [math]\displaystyle{ \Gamma \vdash A : P(y) }[/math] to be able to type [math]\displaystyle{ \Gamma \vdash B A : C }[/math].
λω
In λω, the following operator[math]\displaystyle{ AND := \lambda \alpha : * . \lambda \beta : * . \Pi \gamma : * . (\alpha \to \beta \to \gamma) \to \gamma }[/math]is definable, that is [math]\displaystyle{ \vdash AND : * \to * \to * }[/math]. The derivation[math]\displaystyle{ \alpha : *, \beta : * \vdash \Pi \gamma : * . (\alpha \to \beta \to \gamma) \to \gamma : * }[/math]can be obtained already in λ2, however the polymorphic [math]\displaystyle{ AND }[/math] can only be defined if the rule [math]\displaystyle{ (\square, *) }[/math] is also present.
From a computing point of view, λω is extremely strong, and has been considered as a basis for programming languages.[8]
λC
The calculus of constructions has both the predicate expressiveness of λP and the computational power of λω, hence why λC is also called λPω,[1]:130 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.[7] The Coq system is based on an extension of λC with a linear hierarchy of universes, rather than only one untypable [math]\displaystyle{ \square }[/math], 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 [math]\displaystyle{ \{*, \square\} }[/math], the only axiom [math]\displaystyle{ \{*,\square\} }[/math], and a set of rules [math]\displaystyle{ R }[/math] such that [math]\displaystyle{ \{(*,*,*)\} \subseteq R \subseteq \{(*,*,*), (*,\square, \square), (\square, *, *), (\square, \square, \square) \} }[/math].[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 |
---|---|
λ→ | (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 |
All the logics are implicative (i.e. the only connectives are [math]\displaystyle{ \to }[/math] and [math]\displaystyle{ \forall }[/math]), however one can define other connectives such as [math]\displaystyle{ \wedge }[/math] or [math]\displaystyle{ \neg }[/math] 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 [math]\displaystyle{ M \to_\beta N }[/math] and [math]\displaystyle{ M \to_\beta N' }[/math] then there exists [math]\displaystyle{ N'' }[/math] such that [math]\displaystyle{ N \to^*_\beta N'' }[/math] and [math]\displaystyle{ N' \to^*_\beta N'' }[/math];
- the subject reduction property: if [math]\displaystyle{ \Gamma \vdash M : T }[/math] and [math]\displaystyle{ M \to_\beta M' }[/math] then [math]\displaystyle{ \Gamma \vdash M' : T }[/math];
- the uniqueness of types: if [math]\displaystyle{ \Gamma \vdash A : B }[/math] and [math]\displaystyle{ \Gamma \vdash A : B' }[/math] then [math]\displaystyle{ B =_\beta B' }[/math].
All of these can be proven on generic pure type systems.[9]
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.[7]
Subtyping
Subtyping however is not represented in the cube, even though systems like [math]\displaystyle{ F^\omega_{\lt :} }[/math], 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 [math]\displaystyle{ F^\omega_{\lt :} }[/math] allow the definition of purely functional objects; these systems were generally developed after the lambda cube paper was published.[10]
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.[11] 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.
See also
- In his Habilitation à diriger les recherches,[12] 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.
Notes
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 Barendregt, Henk (1991). "Introduction to generalized type systems". Journal of Functional Programming 1 (2): 125–154. doi:10.1017/s0956796800020025. ISSN 0956-7968.
- ↑ Nederpelt, Rob; Geuvers, Herman (2014). Type Theory and Formal Proof. Cambridge University Press. p. 69. ISBN 9781107036505. https://www.cambridge.org/vi/academic/subjects/computer-science/programming-languages-and-applied-logic/type-theory-and-formal-proof-introduction?format=HB.
- ↑ Nederpelt & Geuvers 2014, p. 85
- ↑ Nederpelt & Geuvers 2014, p. 100
- ↑ Schwichtenberg, Helmut (1975). "Definierbare Funktionen imλ-Kalkül mit Typen" (in DE). Archiv für Mathematische Logik und Grundlagenforschung 17 (3–4): 113–114. doi:10.1007/bf02276799. ISSN 0933-5846.
- ↑ Girard, Jean-Yves; Lafont, Yves; Taylor, Paul (1989). Proofs and Types. Cambridge Tracts in Theoretical Computer Science. 7. Cambridge University Press. ISBN 9780521371810.
- ↑ 7.0 7.1 7.2 Ridoux, Olivier (1998). Lambda-Prolog de A à Z ... ou presque. [s.n.]. OCLC 494473554. ftp://ftp.irisa.fr/techreports/habilitations/ridoux.pdf.
- ↑ Pierce, Benjamin; Dietzen, Scott; Michaylov, Spiro (1989). Programming in higher-order typed lambda-calculi. Computer Science Department, Carnegie Mellon University. CMU-CS-89-111 ERGO-89-075. OCLC 20442222.
- ↑ 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.
- ↑ Pierce, Benjamin (2002). Types and programming languages. MIT Press. pp. 467–490. ISBN 978-0262162098. OCLC 300712077.
- ↑ Pierce 2002, p. 466
- ↑ Ridoux 1998, p. 70
Further reading
- Peyton Jones, Simon; Meijer, Erik (1997). "Henk: A Typed Intermediate Language". https://www.microsoft.com/en-us/research/wp-content/uploads/1997/01/henk.pdf. "Henk is based directly on the lambda cube, an expressive family of typed lambda calculi."
External links
- Barendregt's Lambda Cube in the context of pure type systems by Roger Bishop Jones
![]() | Original source: https://en.wikipedia.org/wiki/Lambda cube.
Read more |