|
|
Line 1: |
Line 1: |
| In [[mathematics]], [[logic]], and [[computer science]], a '''type theory''' is any of a class of [[formal system]]s, some of which can serve as alternatives to [[set theory]] as a foundation for all mathematics. In type theory, every "term" has a "type" and operations are restricted to terms of a certain type.
| | My hobby is mainly Herpetoculture. Appears boring? Not at all!<br>I to learn Chinese in my spare time.<br><br>Also visit my blog; [http://tinyurl.com/m2okfad cheap ugg Australia] |
| | |
| Type theory is closely related to (and in some cases overlaps with) [[type systems]], which are a [[programming language]] feature used to reduce [[bug (computer programming)|bug]]s. The types of type theory were created to avoid paradoxes in a variety of formal [[mathematical logic|logic]]s and [[rewrite system]]s and sometimes "type theory" is used to refer to this broader application.
| |
| | |
| Two well-known type theories that can serve as mathematical foundations are [[Alonzo Church]]'s [[typed lambda calculus|typed λ-calculi]] and [[Per Martin-Löf]]'s [[intuitionistic type theory]]. Type theories are often the mathematical foundation used by computer [[proof assistant]]s because of the [[Curry–Howard correspondence]] which relates programs to proofs.
| |
| | |
| == History ==
| |
| {{Main|History of type theory}}
| |
| | |
| The types of type theory were invented by [[Bertrand Russell]] in response to his discovery that [[Gottlob Frege]]'s version of [[naive set theory]] was afflicted with [[Russell's paradox]]. This theory of types features prominently in [[Alfred North Whitehead|Whitehead]] and [[Bertrand Russell|Russell]]'s ''[[Principia Mathematica]]''. It avoids Russell's paradox by first creating a hierarchy of types, then assigning each mathematical (and possibly other) entity to a type. Objects of a given type are built exclusively from objects of preceding types (those lower in the hierarchy), thus preventing loops.
| |
| | |
| The common usage of "type theory" is when those types are used with a [[term rewrite system]]. The most famous early example is [[Alonzo Church]]'s [[lambda calculus]]. ''Church's Theory of Types''<ref name="church">[[Alonzo Church]], [http://www.jstor.org/stable/2266170 ''A formulation of the simple theory of types''], The Journal of Symbolic Logic 5(2):56–68 (1940)</ref> helped the formal system avoid the [[Kleene–Rosser paradox]] that afflicted the original untyped lambda calculus. Church demonstrated that it could serve as a foundation of mathematics and it was referred to as a [[higher-order logic]].
| |
| | |
| Some other type theories include [[Per Martin-Löf]]'s [[intuitionistic type theory]] which has been the foundation used in some areas of [[Constructivism (mathematics)|constructive mathematics]] and for the proof assistant [[Agda (programming language)|Agda]]. [[Thierry Coquand]]'s [[calculus of constructions]] and its derivatives are the foundation used by [[Coq]] and others. The field is an area of active research, as demonstrated by [[homotopy type theory]].
| |
| | |
| == Basic concepts ==
| |
| | |
| In a system of type theory, each '''[[term (logic)|term]]''' has a '''type''' and operations are restricted to terms of a certain type. A [[Judgment (mathematical logic)|typing judgment]] <math>M : A</math> describes that the term <math>M</math> has type <math>A</math>. For example, <math>nat</math> may be a type representing the natural numbers and <math>0, 1, 2, ...</math> may be inhabitants of that type. The judgement that <math>2</math> has type <math>nat</math> is written as <math>2 : nat</math>.
| |
| | |
| A function in type theory is denoted with an arrow <math>\to</math>. The function <math>addOne</math> (commonly called [[Successor function|successor]]), has the judgement <math>addOne : nat \to nat</math>. Calling or "[[apply]]ing" a function to an argument is usually written without parentheses, so <math>addOne\ 2</math> instead of <math>addOne(2)</math>. (See [[currying]] for why.)
| |
| | |
| Type theories also contain rules for rewriting terms. These are called '''conversion rules''' or, if the rule only works in one direction, a '''reduction rule'''. For example, <math>2 + 1</math> and <math>3</math> are syntactically different terms, but the first reduces to the latter. This reduction is denoted as <math>2 + 1 \twoheadrightarrow 3</math>.
| |
| | |
| == Difference from set theory ==
| |
| | |
| There are many different set theories and many different systems of type theory, so what follows are generalizations.
| |
| | |
| * Set theory is built on top of logic. It requires a separate system like Frege's underneath it. In type theory, concepts like "and" and "or" can be encoded as types in the type theory itself.
| |
| * In set theory, an element can belong to multiple sets, either to a subset or superset. In type theory, terms (generally) belong to only one type. (Where a subset would be used, type theory creates a new type, called a [[Intuitionistic type theory#.CE.A3-types|dependent sum type]], with new terms. Union is similarly achieved by a new [[Tagged union|sum type]] and new terms.)
| |
| * In set theory, sets can contain unrelated elements, e.g., apples and real numbers. In type theory, types that combine unrelated types do so by creating new terms.
| |
| * Set theory usually encodes numbers as sets. (0 is the empty set, 1 is a set containing the empty set, etc.) Type theory can encode numbers as functions using [[Church encoding]] or more naturally as [[Intuitionistic type theory#Inductive types|inductive types]], which are a type with well-behaved constant terms.
| |
| * Set theory allows [[Set-builder notation|Set builder notation]].
| |
| * Type theory has a simple connection to constructive mathematics through the [[BHK interpretation]].
| |
| | |
| == Optional features ==
| |
| | |
| === Normalization ===
| |
| | |
| | |
| The term <math>2 + 1</math> reduces to <math>3</math>. Since <math>3</math> cannot be reduced further, it is called a '''normal form'''. A system of type theory is said to be '''[[Normalization property (abstract rewriting)|strongly normalizing]]''' if all terms have a normal form and any order of reductions reaches it. '''Weakly normalizing''' systems have a normal form but some orders of reductions may loop forever and never reach it.
| |
| | |
| For a normalizing system, some borrow the word '''element''' from set theory and use it to refer to all closed terms that can reduce to the same normal form. A '''closed term''' is one without parameters. (A term like <math>x + 1</math> with its parameter <math>x</math> is called an '''open term'''.) Thus, <math>2 + 1</math> and <math>3 + 0</math> may be different terms but they're both from the element <math>3</math>.
| |
| | |
| A similar idea that works for open and closed terms is convertibility. Two terms are '''convertible''' if there exists a term that they both reduce to. For example, <math>2 + 1</math> and <math>1 + 2</math> are convertible. As are <math>x + (1 + 1)</math> and <math>x + 2</math>. However, <math>x + 1</math> and <math>1 + x</math> (where <math>x</math> is a free variable) are not because both are in normal form and they are not the same. [[Confluence (abstract rewriting)|Confluent]] and weakly normalizing systems can test if two terms are convertible by checking if they both reduce to the same normal form.
| |
| | |
| === Dependent types ===
| |
| {{Main|dependent types}}
| |
| A '''dependent type''' is a type that depends on a term or on another type. Thus, the type returned by a function may depend upon the argument to the function.
| |
| | |
| For example, a list of <math>nat</math>s of length 4 may be a different type than a list of <math>nat</math>s of length 5. In a type theory with dependent types, it is possible to define a function that take a parameter "n" and returns a list containing "n" zeros. Calling the function with 4 would produce a term with a different type than if the function was called with 5.
| |
| | |
| Dependent types play a central role in [[intuitionistic type theory]] and in the design of [[functional programming languages]] like [[ATS (programming language)|ATS]], [[Agda (theorem prover)|Agda]] and [[Epigram (programming language)|Epigram]].
| |
| | |
| === Equality types (or "identity types") ===
| |
| | |
| Many systems of type theory have a type that represents equality of types and terms. This type is different from convertibility, and is often denoted '''propositional equality'''.
| |
| | |
| In intuitionistic type theory, the dependent type is known as <math>I</math> for identity. There is a type <math>I\ A\ a\ b</math> when <math>A</math> is a type and <math>a</math> and <math>b</math> are both terms of type <math>A</math>. A term of type <math>I\ A\ a\ b</math> is interpreted as meaning that <math>a</math> is equal to <math>b</math>.
| |
| | |
| In practice, it is possible to build a type <math>I\ nat\ 3\ 4</math> but there will not exist a term of that type. In intuitionistic type theory, new terms of equality start with reflexivity. If <math>3</math> is a term of type <math>nat</math>, then there exists a term of type <math>I\ nat\ 3\ 3</math>. More complicated equalities can be created by creating a reflexive term and then doing a reduction on one side. So if <math>2+1</math> is a term of type <math>nat</math>, then there is a term of type <math>I\ nat\ (2+1)\ (2+1)</math> and, by reduction, generate a term of type <math>I\ nat\ (2+1)\ 3</math>. Thus, in this system, the equality type denotes that two values of the same type are convertible by reductions.
| |
| | |
| Having a type for equality is important because it can be manipulated inside the system. There is usually no judgement to say two terms are ''not'' equal; instead, as in the [[Brouwer–Heyting–Kolmogorov interpretation]], we map <math>\neg(a = b)</math> to <math>(a = b) \to \bot</math>, where <math>\bot</math> is the [[bottom type]] having no values. There exists a term with type <math>(I\ nat\ 3\ 4) \to \bot</math>, but not one of type <math>(I\ nat\ 3\ 3) \to \bot</math>.
| |
| | |
| [[Homotopy type theory]] differs from [[intuitionistic type theory]] mostly by its handling of the equality type.
| |
| | |
| === Inductive types ===
| |
| {{main|Inductive type}}
| |
| | |
| A system of type theory requires some basic terms and types to operate on. Some systems build them out of functions using [[Church encoding]]. Other systems have '''inductive types''': a set of base types and a set of [[type constructor]]s that generate types with well-behaved properties. For example, [[Structural induction|certain recursive functions]] called on inductive types are guaranteed to terminate.
| |
| | |
| '''Coinductive type''' are infinite data types created by giving a function that generates the next element(s). See [[Coinduction]] and [[Corecursion]].
| |
| | |
| '''[[Induction-Induction (type theory)|Induction induction]] ''' is a feature for declaring an inductive type and a family of types that depends on the inductive type.
| |
| | |
| '''[[Induction-recursion (type theory)|Induction recursion]]''' allows a wider range of well-behaved types but requires that the type and the recursive functions that operate on them be defined at the same time.
| |
| | |
| === Universe types ===
| |
| | |
| Types were created to prevent paradoxes, such as [[Russell's paradox]]. However, the motives that lead to those paradoxes – being able to say things about all types – still exist. So many type theories have a "universe type", which contains all other types.
| |
| | |
| In systems where you might want to say something about universe types, there is a hierarchy of universe types, each containing the one below it in the hierarchy. The hierarchy is defined as being infinite, but statements must only refer to a finite number of universe levels.
| |
| | |
| Type universes are particularly tricky in type theory. The initial proposal of intuitionistic type theory suffered from [[Girard's paradox]].
| |
| | |
| === Computational component ===
| |
| | |
| Many systems of type theory, such as the [[simply-typed lambda calculus]], [[intuitionistic type theory]], and the [[calculus of constructions]], are also programming languages. That is, they are said to have a "computational component". The computation is the reduction of terms of the language using [[rewriting|rewriting rules]].
| |
| | |
| A system of type theory that has a well-behaved computational component also has a simple connection to constructive mathematics through the [[BHK interpretation]].
| |
| | |
| Non-constructive mathematics in these systems is possible by adding operators on continuations such as [[Call/cc#Relation to non-constructive logic|call with current continuation]]. However, these operators tend to break desirable properties such as [[canonicity (type theory)|canonicity]] and [[parametricity]].
| |
| | |
| == Systems of type theory ==
| |
| | |
| === Major ===
| |
| * [[Simply typed lambda calculus]] which is a [[higher-order logic]]
| |
| * [[Intuitionistic type theory]]
| |
| * [[System F]]
| |
| * [[Logical framework|LF]] is often used to define other type theories
| |
| * [[Calculus of constructions]] and its derivatives
| |
| | |
| === Minor ===
| |
| * [[Automath]]
| |
| * some forms of [[combinatory logic]]
| |
| * [[ST type theory]]
| |
| * others defined in the [[lambda cube]]
| |
| * others under the name [[typed lambda calculus]]
| |
| * others under the name [[pure type system]]
| |
| | |
| === Active ===
| |
| * [[Homotopy type theory]] is being researched
| |
| | |
| == Practical impact ==
| |
| | |
| === Programming languages ===
| |
| {{Main|Type system}}
| |
| There is extensive overlap and interaction between the fields of type theory and type systems. Type systems are a programming language feature designed to identify bugs. Any static program analysis, such as the type checking algorithms in the semantic analysis phase of [[compiler]], has a connection to type theory.
| |
| | |
| A prime example is [[Agda (programming language)|Agda]], a programming language which uses [[intuitionistic type theory]] for its type system. The programming language [[ML (programming language)|ML]] was developed for manipulating type theories (see [[Logic for Computable Functions|LCF]]) and its own type system was heavily influenced by them.
| |
| | |
| === Mathematical foundations ===
| |
| {{Expand section|date=May 2008}}
| |
| | |
| The first computer proof assistant, called [[Automath]], used type theory to encode mathematics on a computer. Martin-Löf specifically developed [[intuitionistic type theory]] to encode ''all'' mathematics - to serve as a new foundation for mathematics. There is current research into mathematical foundations using [[homotopy type theory]].
| |
| | |
| Mathematicians working in [[category theory]] already had difficulty working with the widely accepted foundation of [[Zermelo–Fraenkel set theory]]. This led to proposals such as Lawvere’s [[Elementary Theory of the Category of Sets]] (ETCS).<ref>{{nlab|id=ETCS}}</ref> Homotopy type theory continues in this line using type theory. Researchers are exploring connections between dependent types (especially the identity type) and [[algebraic topology]] (specifically [[homotopy]]).
| |
| | |
| === Proof assistants ===
| |
| {{main|Proof assistant}}
| |
| | |
| Much of the current research into type theory is driven by [[Automated proof checking|proof checkers]], interactive [[proof assistant]]s, and [[Automated theorem proving|automated theorem provers]]. Most of these systems use a type theory as the mathematical foundation for encoding proofs. This is not surprising, given the close connection between type theory and programming languages.
| |
| | |
| * [[Logical framework|LF]] is used by [[Twelf]], often to define other type theories
| |
| * Multiple type theories falling under [[higher-order logic]] are used by the [[HOL (proof assistant)|HOL family of provers]] and [[Prototype Verification System|PVS]]
| |
| * [[Intuitionistic type theory]] is used by [[Agda (programming language)|Agda]] which is both a programming language and proof assistant.
| |
| * Computational Type Theory is used by [[NuPRL]]
| |
| * The [[calculus of constructions]] and its derivatives are used by [[Coq]] and [[Matita]].
| |
| | |
| Multiple type theories are supported by [[LEGO (proof assistant)|LEGO]] and [[Isabelle (proof assistant)|Isabelle]]. Isabelle also supports foundations besides type theories, such as [[Zermelo–Fraenkel set theory|ZFC]]. [[Mizar system|Mizar]] is an example of a proof system that only supports set theory.
| |
| | |
| === Linguistics ===
| |
| Type theory is also widely in use in [[formal semantics (linguistics)|formal theories of semantics]] of [[natural language]]s, especially [[Montague grammar]] and its descendants. In particular, [[categorial grammar]]s and [[pregroup grammar]]s make extensive use of type constructors to define the types (''noun'', ''verb'', etc.) of words.
| |
| | |
| The most common construction takes the basic types <math>e</math> and <math>t</math> for individuals and [[truth-value]]s, respectively, and defines the set of types recursively as follows:
| |
| | |
| * if <math>a</math> and <math>b</math> are types, then so is <math>\langle a,b\rangle</math>.
| |
| * Nothing except the basic types, and what can be constructed from them by means of the previous clause are types.
| |
| | |
| A complex type <math>\langle a,b\rangle</math> is the type of [[Function (mathematics)|functions]] from entities of type <math>a</math> to entities of type <math>b</math>. Thus one has types like <math>\langle e,t\rangle</math> which are interpreted as elements of the set of functions from entities to truth-values, i.e. [[indicator function]]s of sets of entities. An expression of type <math>\langle\langle e,t\rangle,t\rangle</math> is a function from sets of entities to truth-values, i.e. a (indicator function of a) set of sets. This latter type is standardly taken to be the type of [[Generalized quantifier|natural language quantifiers]], like '' everybody'' or '' nobody'' (Montague 1973, Barwise and Cooper 1981).
| |
| | |
| === Social sciences ===
| |
| [[Gregory Bateson]] introduced a theory of logical types into the social sciences; his notions of [[double bind]] and [[logical levels]] are based on Russell's theory of types.
| |
| | |
| == Relation to category theory ==
| |
| | |
| Although the initial motivation for [[category theory]] was far removed from foundationalism, the two fields turned out to have deep connections. As [[John Lane Bell]] writes: "In fact categories can ''themselves'' be viewed as type theories of a certain kind; this fact alone indicates that type theory is much more closely related to category theory than it is to set theory." In brief, a category can be viewed as a type theory by regarding its objects as types (or sorts), i.e. "Roughly speaking, a category may be thought of as a type theory shorn of its syntax." A number of significant results follow in this way:<ref name="Sets and Extensions in the Twentieth Century">{{cite book|title=Handbook of the History of Logic. Volume 6. Sets and Extensions in the Twentieth Century|year=2012|publisher=Elsevier|isbn=978-0-08-093066-4| author=John L. Bell|chapter=Types, Sets and Categories | url = http://publish.uwo.ca/~jbell/types.pdf |editor=Akihiro Kanamory}}</ref>
| |
| * [[Cartesian closed category|cartesian closed categories]] correspond to the typed λ-calculus ([[Lambek]], 1970)
| |
| * [[C-monoid]]s (categories with products and exponentials and a single, nonterminal object) correspond to the untyped λ-calculus (observed independently by Lambek and [[Dana Scott]] around 1980)
| |
| * [[Locally cartesian closed category|locally cartesian closed categories]] correspond to [[Martin-Löf type theory|Martin-Löf type theories]] (Seely, 1984)
| |
| | |
| The interplay, known as [[categorical logic]], has been a subject of active research since then; see the monograph of Jacobs (1999) for instance.
| |
| | |
| == See also ==
| |
| * [[Data type]] for concrete types of data in programming
| |
| * [[Domain theory]]
| |
| * [[Type (model theory)]]
| |
| * [[Type system]] for a more practical discussion of type systems for programming languages
| |
| | |
| == References ==
| |
| {{refbegin}}
| |
| *W. Farmer, ''The seven virtues of simple type theory'', Journal of Applied Logic, Vol. 6, No. 3. (September 2008), pp. 267–286.
| |
| {{refend}}
| |
| {{reflist|colwidth=30em}}
| |
| | |
| == Further reading ==
| |
| * [[Robert Lee Constable|Constable, Robert L.]], 2002, "[http://www.nuprl.org/documents/Constable/naive.pdf Naïve Computational Type Theory,]" in H. Schwichtenberg and R. Steinbruggen (eds.), ''Proof and System-Reliability'': 213–259. Intended as an type theory counterpart of [[Paul Halmos]]'s (1960) ''[[Naive Set Theory (book)|Naïve Set Theory]]''
| |
| * {{cite book
| |
| | first = Peter
| |
| | last = Andrews B.
| |
| | year = 2002
| |
| | isbn = 978-1-4020-0763-7
| |
| | title = An Introduction to Mathematical Logic and Type Theory: To Truth Through Proof, 2nd ed.
| |
| | publisher = Kluwer Academic Publishers.
| |
| }}
| |
| *{{cite book
| |
| | first = Bart
| |
| | last = Jacobs
| |
| | title = Categorical Logic and Type Theory
| |
| | year = 1999
| |
| | publisher = North Holland, Elsevier
| |
| | isbn = 0-444-50170-3
| |
| | series = Studies in Logic and the Foundations of Mathematics 141
| |
| | url = http://www.cs.ru.nl/B.Jacobs/CLT/bookinfo.html }} Covers type theory in depth, including polymorphic and dependent type extensions. Gives [[categorical semantics]].
| |
| * {{cite book
| |
| | first = Jordan E.
| |
| | last = Collins
| |
| | year = 2012
| |
| | isbn = 978-3-8473-2963-3
| |
| | title = A History of the Theory of Types: Developments After the Second Edition of 'Principia Mathematica'
| |
| | publisher = LAP Lambert Academic Publishing
| |
| }} Provides a historical survey of the developments of the theory of types with a focus on the decline of the theory as a foundation of mathematics over the four decades following the publication of the second edition of 'Principia Mathematica'.
| |
| * Cardelli, Luca, 1997, "[http://citeseer.ist.psu.edu/cardelli97type.html Type Systems,]" in Allen B. Tucker, ed., ''The Computer Science and Engineering Handbook''. CRC Press: 2208–2236.
| |
| * Thompson, Simon, 1991. ''[http://www.cs.kent.ac.uk/people/staff/sjt/TTFP/ Type Theory and Functional Programming]''. Addison–Wesley. ISBN 0-201-41667-0.
| |
| * [[J. Roger Hindley]], ''Basic Simple Type Theory'', Cambridge University Press, 2008, ISBN 0-521-05422-2 (also 1995, 1997).<!-- no idea why these get different ISBNs, they don't appear to be different editions--> A good introduction to simple type theory for computer scientists; the system described is not exactly Church's STT though. [http://www.iwu.edu/~htiede/papers/pdf/jolli-review.pdf Book review]
| |
| * [[Stanford Encyclopedia of Philosophy]]: [http://plato.stanford.edu/entries/type-theory/ Type Theory]" – by [[Thierry Coquand]].
| |
| * Fairouz D. Kamareddine, Twan Laan, Rob P. Nederpelt, ''A modern perspective on type theory: from its origins until today'', Springer, 2004, ISBN 1-4020-2334-0
| |
| * José Ferreirós, José Ferreirós Domínguez, ''Labyrinth of thought: a history of set theory and its role in modern mathematics'', Edition 2, Springer, 2007, ISBN 3-7643-8349-6, chapter X "Logic and Type Theory in the Interwar Period"
| |
| | |
| == External links ==
| |
| * {{scholarpedia|title=Computational type theory|urlname=Computational_type_theory|curator=Robert L. Constable}}
| |
| * [http://lists.seas.upenn.edu/mailman/listinfo/types-list The TYPES Forum] — moderated e-mail forum focusing on type theory in computer science, operating since 1987.
| |
| * [ftp://ftp.cs.cornell.edu/pub/nuprl/doc/book.ps.gz The Nuprl Book]: "[http://www.cs.cornell.edu/Info/Projects/NuPrl/book/node31.html Introduction to Type Theory.]"
| |
| * [http://www.cs.chalmers.se/Cs/Research/Logic/Types/tutorials.html Types Project lecture notes] of summer schools 2005–2008
| |
| ** The [http://www.cs.chalmers.se/Cs/Research/Logic/TypesSS05/program.html 2005 summer school] has introductory lectures
| |
| | |
| {{Logic}}
| |
| {{Computer science}}
| |
| | |
| {{DEFAULTSORT:Type Theory}}
| |
| [[Category:Type theory| ]]
| |
| [[Category:Systems of formal logic]]
| |