Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lambda cube
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|A framework}} [[File:Lambda_Cube_img.svg|alt=|frame|The lambda cube. Direction of each arrow is direction of inclusion.]] In [[mathematical logic]] and [[type theory]], the '''λ-cube''' (also written '''lambda cube''') is a framework introduced by [[Henk Barendregt]]<ref name=":0">{{Cite journal|last=Barendregt|first=Henk|date=1991|title=Introduction to generalized type systems|journal=[[Journal of Functional Programming]]|volume=1|issue=2|pages=125–154|doi=10.1017/s0956796800020025|issn=0956-7968|hdl=2066/17240|s2cid=44757552 |hdl-access=free}}</ref> 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 [[Free variables and bound variables|bind]] a term or type. The respective dimensions of the λ-cube correspond to: * x-axis (<math>\rightarrow</math>): types that can depend on terms, corresponding to [[dependent type]]s. * y-axis (<math>\uparrow</math>): terms that can depend on types, corresponding to [[Parametric polymorphism|polymorphism]]. * z-axis (<math>\nearrow</math>): types that can depend on other types, corresponding to (binding) [[type operator]]s. 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>\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")<ref>{{cite book |last1=Nederpelt |first1=Rob |last2=Geuvers |first2=Herman |title=Type Theory and Formal Proof |date=2014 |publisher=Cambridge University Press |isbn=9781107036505 |page=69 |url=https://www.cambridge.org/vi/academic/subjects/computer-science/programming-languages-and-applied-logic/type-theory-and-formal-proof-introduction?format=HB }}</ref> there is another type of abstraction, written with a <math>\Lambda</math>, that allows ''terms to depend on types'', with the following rule: <math>\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>\Lambda</math> are called [[Parametric polymorphism|polymorphic]], as they can be applied to different types to get different functions, similarly to polymorphic functions in [[ML (programming language)|ML-like languages]]. For instance, the polymorphic identity <syntaxhighlight lang="ocaml"> fun x -> x </syntaxhighlight>of [[OCaml]] has type <syntaxhighlight lang="ocaml"> 'a -> 'a </syntaxhighlight>meaning it can take an argument of any type <code>'a</code> and return an element of that type. This type corresponds in λ2 to the type <math>\Pi \alpha . \alpha \to \alpha</math>. === (λ<u>ω</u>) System F<u>ω</u> === In System F<math>\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''".<ref>{{harvnb|Nederpelt|Geuvers|2014|p=85}}</ref> An example of such a type constructor is the type of binary trees with leaves labeled by data of a given type <math>A</math>: <math>\mathsf{TREE} := \lambda A : * . \Pi B . (A \to B) \to (B \to B \to B) \to B</math>, where "<math>A:*</math>" informally means "<math>A</math> is a type". This is a function that takes a type parameter <math>A</math> as an argument and returns the type of <math>\mathsf{TREE}</math>s of values of type <math>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:<syntaxhighlight lang="ocaml"> type 'a tree = | Leaf of 'a | Node of 'a tree * 'a tree </syntaxhighlight> This type constructor can be applied to other types to obtain new types. E.g., to obtain type of trees of integers:<syntaxhighlight lang="ocaml">type int_tree = int tree</syntaxhighlight> System F<math>\underline{\omega}</math> is generally not used on its own, but is useful to isolate the independent feature of type constructors.<ref>{{harvnb|Nederpelt|Geuvers|2014|p=100}}</ref> === (λP) Lambda-P === In the [[λΠ-calculus|λP]] system, also named λΠ, and closely related to the [[Logical framework#LF|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>\frac{\Gamma, x : A \;\vdash\; B : *}{\Gamma \;\vdash\; (\Pi x : A . B) : *}</math> where <math>*</math> represents valid types. The new type constructor <math>\Pi</math> corresponds via the [[Curry Howard isomorphism|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-omega|System Fω]] combines both the <math>\Lambda</math> constructor of System F and the type constructors from System F<math>\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ω,<ref name=:0/>{{rp|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>\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>S := \{*, \square \}</math>, sorts are represented with the letter <math>s</math>. There is also a set <math>V</math> of variables, represented by the letters <math>x,y,\dots</math>. The raw terms of the eight systems of the cube are given by the following syntax: <math>A := x \mid s \mid A~A \mid \lambda x : A . A \mid \Pi x : A . A</math> and <math>A \to B</math> denoting <math>\Pi x : A . B</math> when <math>x</math> does not occur free in <math>B</math>. The environments, as is usual in typed systems, are given by <math>\Gamma := \emptyset \mid \Gamma, x : A</math> The notion of β-reduction is common to all systems in the cube. It is written <math>\to_{\beta}</math> and given by the rules<math display="block">\frac{}{(\lambda x : A . B)~C \to_{\beta} B[C/x]}</math><math display="block">\frac{B \to_{\beta} B'}{\lambda x : A . B \to_{\beta} \lambda x : A . B'}</math><math display="block">\frac{A \to_{\beta} A'}{\lambda x : A . B \to_{\beta} \lambda x : A' . B}</math><math display="block">\frac{B \to_{\beta} B'}{\Pi x : A . B \to_{\beta} \Pi x : A . B'}</math><math display="block">\frac{A \to_{\beta} A'}{\Pi x : A . B \to_{\beta} \Pi x : A' . B}</math>Its [[Reflexive transitive closure|reflexive, transitive closure]] is written <math>=_\beta</math>. The following typing rules are also common to all systems in the cube:<math display="block">\frac{}{\vdash * : \square}\quad \text{(Axiom)}</math><math display="block">\frac{\Gamma \vdash A : s}{\Gamma, x : A \vdash x : A } x \not\in \Gamma \quad \text{(Start)}</math><math display="block">\frac{\Gamma \vdash A : B \quad \Gamma \vdash C : s}{\Gamma, x : C \vdash A : B} x \not\in \Gamma \quad \text{(Weakening)}</math><math display="block">\frac{\Gamma \vdash C : \Pi x : A . B \quad \Gamma \vdash D : A}{\Gamma \vdash CD : B[D/x]}\quad\text{(Application)}</math><math display="block">\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 display="inline">(s_1,s_2)</math> that are allowed in the following two typing rules:<math display="block">\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>\frac{\Gamma \vdash A : s_1 \quad \Gamma, x : A \vdash B : C \quad \Gamma, x : A \vdash C : s_2}{\Gamma \vdash \lambda x : A . B : \Pi x : A . C}\quad\text{(Abstraction)}</math> The correspondence between the systems and the pairs <math display="inline">(s_1,s_2)</math> allowed in the rules is the following: {| class="wikitable" !<math>(s_1, s_2)</math> !<math>(*,*)</math> !<math>(*,\square)</math> !<math>(\square,*)</math> !<math>(\square,\square)</math> |- |λ→ |{{ya}} |{{na}} |{{na}} |{{na}} |- |λP |{{ya}} |{{ya}} |{{na}} |{{na}} |- |λ2 |{{ya}} |{{na}} |{{ya}} |{{na}} |- |λ<u>ω</u> |{{ya}} |{{na}} |{{na}} |{{ya}} |- |λP2 |{{ya}} |{{ya}} |{{ya}} |{{na}} |- |λP<u>ω</u> |{{ya}} |{{ya}} |{{na}} |{{ya}} |- |λω |{{ya}} |{{na}} |{{ya}} |{{ya}} |- |λC |{{ya}} |{{ya}} |{{ya}} |{{ya}} |} Each direction of the cube corresponds to one pair (excluding the pair <math display="inline">(*,*)</math> shared by all systems), and in turn each pair corresponds to one possibility of dependency between terms and types: * <math display="inline">(*,*)</math> allows terms to depend on terms. * <math display="inline">(*,\square)</math> allows types to depend on terms. * <math display="inline">(\square, *)</math> allows terms to depend on types. * <math display="inline">(\square, \square)</math> allows types to depend on types. ==Comparison between the systems== ===λ→=== A typical derivation that can be obtained is<math display="block">\alpha : * \vdash \lambda x : \alpha . x : \Pi x : \alpha . \alpha</math>or with the arrow shortcut<math display="block">\alpha : * \vdash \lambda x : \alpha . x : \alpha \to \alpha</math>closely resembling the identity (of type <math display="inline">\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 display="inline">\vdash * : \square</math>. The computing power is quite weak, it corresponds to the extended polynomials (polynomials together with a conditional operator).<ref>{{Cite journal |last=Schwichtenberg |first=Helmut |author-link=Helmut Schwichtenberg |date=1975 |title=Definierbare Funktionen imλ-Kalkül mit Typen |journal=[[Archiv für Mathematische Logik und Grundlagenforschung]] |volume=17 |issue=3–4 |pages=113–114 |doi=10.1007/bf02276799 |s2cid=11598130 |issn=0933-5846 |language=DE}}</ref> ===λ2=== In λ2, such terms can be obtained as<math display="block">\vdash (\lambda \beta : * . \lambda x : \bot . x \beta) : \Pi \beta : * . \bot \to \beta</math>with <math display="inline">\bot = \Pi \alpha : * . \alpha</math>. If one reads <math display="inline">\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 [[Impredicativity|impredicative]] types such as <math display="inline">\bot</math>, that is terms quantifying over all types including themselves.<br />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]].<ref>{{cite book |first1=Jean-Yves |last1=Girard |first2=Yves |last2=Lafont |first3=Paul |last3=Taylor |title=Proofs and Types |publisher=Cambridge University Press |year=1989 |isbn=9780521371810 |volume=7 |series=Cambridge Tracts in Theoretical Computer Science }}</ref> 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 display="block">\begin{array}{l}\alpha : *, a_0 : \alpha, p : \alpha \to *, q : * \vdash \\ \quad \lambda z : (\Pi x : \alpha . p x \to q) . \\ \quad \lambda y : (\Pi x : \alpha . p x) . \\ \quad (z a_0) (y a_0) : (\Pi x : \alpha . p x \to q) \to (\Pi x : \alpha . p x) \to q \end{array}</math>which corresponds, via the Curry-Howard isomorphism, to a proof of <math>(\forall x : A, P x \to Q) \to (\forall x : A, P x) \to Q</math>.<br />From the computational point of view, however, having dependent types does not enhance computational power, only the possibility to express more precise type properties.<ref name=":1">{{Cite book|title=Lambda-Prolog de A à Z ... ou presque|last=Ridoux|first=Olivier|date=1998|publisher=[s.n.]|oclc=494473554|url=ftp://ftp.irisa.fr/techreports/habilitations/ridoux.pdf }}</ref> 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 <math>\Gamma \vdash A : P((\lambda x . x)y)</math> and <math>\Gamma \vdash B : \Pi x : P(y) . C</math>, one needs to apply the conversion rule{{efn|name= dependentTypeConvent|1= The assumption <math>\Gamma \vdash B' : s</math> in the Conversion rule is a convenience; one could prove a meta-theorem that <math>\Gamma \vdash A : B \land B =_{\beta} B' \Rightarrow \Gamma \vdash B' : s</math> instead.<ref>{{cite book | last1 = Angiuli | first1 = Carlo | last2 = Gratzer | first2 = Daniel | title = Principles of Dependent Type Theory | publisher = Indiana University and Aarhus University | year = 2024 | url = https://www.danielgratzer.com/courses/type-theory-s-2024/lecture-notes.pdf | chapter = 2.1.3 Who type-checks the typing rules? and 2.2 Towards the syntax of dependent type theory | access-date = 7 September 2024 }}</ref><ref>{{cite web | last = Favier | first = Naïm | title = In the Conversion inference rule of the lambda cube, why is Γ ⊢ B′:s necessary? | website = Computer Science Stack Exchange | date = August 17, 2023 | url = https://cs.stackexchange.com/a/169633/174020 | access-date = September 7, 2024 }}</ref>}} to obtain <math>\Gamma \vdash A : P(y)</math> to be able to type <math>\Gamma \vdash B A : C</math>. ===λω=== In λω, the following operator<math display="block">AND := \lambda \alpha : * . \lambda \beta : * . \Pi \gamma : * . (\alpha \to \beta \to \gamma) \to \gamma</math>is definable, that is <math>\vdash AND : * \to * \to *</math>. The derivation<math display="block">\alpha : *, \beta : * \vdash \Pi \gamma : * . (\alpha \to \beta \to \gamma) \to \gamma : *</math>can be obtained already in λ2, however the polymorphic <math display="inline">AND</math> can only be defined if the rule <math display="inline">(\square, *)</math> is also present. From a computing point of view, λω is extremely strong, and has been considered as a basis for programming languages.<ref>{{Cite book|title=Programming in higher-order typed lambda-calculi |last1=Pierce |first1=Benjamin |first2=Scott |last2=Dietzen |first3=Spiro |last3=Michaylov |date=1989 |publisher=Computer Science Department, Carnegie Mellon University |id=CMU-CS-89-111 ERGO-89-075 |oclc=20442222}}</ref> ===λC=== The calculus of constructions has both the predicate expressiveness of λP and the computational power of λω, hence why λC is also called λPω,<ref name=:0/>{{rp|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 (programming language)|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.<ref name=":1" /> The Coq system is based on an extension of λC with a linear hierarchy of universes, rather than only one untypable <math display="inline">\square</math>, and the ability to construct inductive types. [[Pure type system]]s 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>\{*, \square\}</math>, the only axiom <math display="inline">\{*,\square\}</math>, and a set of rules <math display="inline">R</math> such that <math>\{(*,*,*)\} \subseteq R \subseteq \{(*,*,*), (*,\square, \square), (\square, *, *), (\square, \square, \square) \}</math>.<ref name=":0" /> Via the Curry-Howard isomorphism, there is a one-to-one correspondence between the systems in the lambda cube and logical systems,<ref name=":0" /> namely: {| class="wikitable" !System of the cube !Logical System |- |λ→ |(Zeroth-order) [[Propositional calculus|Propositional Calculus]] |- |λ2 |[[Second-order propositional logic|Second-order Propositional Calculus]] |- |λ{{Underline|ω}} |Weakly Higher Order Propositional Calculus |- |λω |Higher Order Propositional Calculus |- |λP |(First order) [[Predicate Logic]] |- |λP2 |[[Second order predicate calculus|Second-order Predicate Calculus]] |- |λP{{Underline|ω}} |Weak [[Higher-order logic|Higher Order Predicate Calculus]] |- |λC |[[Calculus of constructions|Calculus of Constructions]] |} All the logics are implicative (i.e. the only connectives are <math display="inline">\to</math> and <math display="inline">\forall</math>), however one can define other connectives such as <math>\wedge</math> or <math>\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>M \to_\beta N</math> and <math>M \to_\beta N'</math> then there exists <math>N''</math> such that <math>N \to^*_\beta N''</math> and <math>N' \to^*_\beta N''</math>; * the [[Subject reduction|subject reduction property]]: if <math>\Gamma \vdash M : T</math> and <math>M \to_\beta M'</math> then <math>\Gamma \vdash M' : T</math>; * the uniqueness of types: if <math>\Gamma \vdash A : B</math> and <math>\Gamma \vdash A : B'</math> then <math>B =_\beta B'</math>. All of these can be proven on generic pure type systems.<ref>{{Cite book |last1=Sørensen|first1=Morten Heine|chapter=Pure type systems and the λ-cube|date=2006|title=Lectures on the Curry-Howard Isomorphism|pages=343–359|publisher=Elsevier|isbn=9780444520777|last2=Urzyczyin|first2=Pawel|doi=10.1016/s0049-237x(06)80015-7}}</ref> Any term well-typed in a system of the cube is strongly normalizing,<ref name=":0" /> although this property is not common to all pure type systems. No system in the cube is Turing complete.<ref name=":1" /> == Subtyping == [[Subtyping]] however is not represented in the cube, even though systems like <math>F^\omega_{<:}</math>, known as [[higher-order bounded quantification]], which combines subtyping and polymorphism are of practical interest, and can be further generalized to [[bounded type operator]]s. Further extensions to <math>F^\omega_{<:}</math> allow the definition of [[purely functional objects]]; these systems were generally developed after the lambda cube paper was published.<ref>{{Cite book|title=Types and programming languages|last=Pierce|first=Benjamin|date=2002|publisher=MIT Press|isbn=978-0262162098|pages=467–490|oclc=300712077 }}</ref> The idea of the cube is due to the mathematician [[Henk Barendregt]] (1991). The framework of [[pure type system]]s 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.<ref>{{harvnb|Pierce|2002|p=466}}</ref> 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'',<ref>{{harvnb|Ridoux|1998|p=70}}</ref> 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. * [[Logical cube]] * [[Logical hexagon]] * [[Square of opposition]] * [[Triangle of opposition]] == Notes == {{reflist}} {{notelist}} == Further reading == * {{cite web |first1=Simon |last1=Peyton Jones |first2=Erik |last2=Meijer |year=1997 |url=https://www.microsoft.com/en-us/research/wp-content/uploads/1997/01/henk.pdf |title=Henk: A Typed Intermediate Language |website=[[Microsoft]] |quote=''Henk'' is based directly on the lambda cube, an expressive family of typed lambda calculi. }} == External links == * [http://www.rbjones.com/rbjpub/logic/cl/tlc001.htm Barendregt's Lambda Cube] in the context of [[pure type systems]] by Roger Bishop Jones [[Category:Lambda calculus]] [[Category:Type theory]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Efn
(
edit
)
Template:Harvnb
(
edit
)
Template:Na
(
edit
)
Template:Notelist
(
edit
)
Template:Reflist
(
edit
)
Template:Rp
(
edit
)
Template:Short description
(
edit
)
Template:Underline
(
edit
)
Template:Ya
(
edit
)