In mathematics and theoretical computer science, a type theory is the formal presentation of a specific type system. [lower-alpha 1] Type theory is the academic study of type systems.
Some type theories serve as alternatives to set theory as a foundation of mathematics. Two influential type theories that have been proposed as foundations are:
Most computerized proof-writing systems use a type theory for their foundation. A common one is Thierry Coquand's Calculus of Inductive Constructions.
Type theory was created to avoid a paradox in a mathematical equation based on naive set theory and formal logic. Russell's paradox (first described in Gottlob Frege's The Foundations of Arithmetic) is that, without proper axioms, it is possible to define the set of all sets that are not members of themselves; this set both contains itself and does not contain itself. Between 1902 and 1908, Bertrand Russell proposed various solutions to this problem.
By 1908, Russell arrived at a ramified theory of types together with an axiom of reducibility, both of which appeared in Whitehead and Russell's Principia Mathematica published in 1910, 1912, and 1913. This system avoided contradictions suggested in Russell's paradox by creating a hierarchy of types and then assigning each concrete mathematical entity to a specific type. Entities of a given type were built exclusively of subtypes of that type, [lower-alpha 2] thus preventing an entity from being defined using itself. This resolution of Russell's paradox is similar to approaches taken in other formal systems, such as Zermelo-Fraenkel set theory. [3]
Type theory is particularly popular in conjunction with Alonzo Church's lambda calculus. One notable early example of type theory is Church's simply typed lambda calculus. Church's theory of types [4] helped the formal system avoid the Kleene–Rosser paradox that afflicted the original untyped lambda calculus. Church demonstrated [lower-alpha 3] that it could serve as a foundation of mathematics and it was referred to as a higher-order logic.
In the modern literature, "type theory" refers to a typed system based around lambda calculus. One influential system is Per Martin-Löf's intuitionistic type theory, which was proposed as a foundation for constructive mathematics. Another is Thierry Coquand's calculus of constructions, which is used as the foundation by Coq, Lean, and other computer proof assistants. Type theory is an active area of research, one direction being the development of homotopy type theory.
This section needs expansion. You can help by adding to it. (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 ongoing 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). [6] 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).
Much of the current research into type theory is driven by proof checkers, interactive proof assistants, and automated theorem provers. Most of these systems use a type theory as the mathematical foundation for encoding proofs, which is not surprising, given the close connection between type theory and programming languages:
Many type theories are supported by LEGO and Isabelle. Isabelle also supports foundations besides type theories, such as ZFC. Mizar is an example of a proof system that only supports set theory.
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, a programming language which uses UTT (Luo's Unified Theory of dependent Types) for its type system.
The programming language ML was developed for manipulating type theories (see LCF) and its own type system was heavily influenced by them.
Type theory is also widely used in formal theories of semantics of natural languages, [7] [8] especially Montague grammar [9] and its descendants. In particular, categorial grammars and pregroup grammars extensively use type constructors to define the types (noun, verb, etc.) of words.
The most common construction takes the basic types and for individuals and truth-values, respectively, and defines the set of types recursively as follows:
A complex type is the type of functions from entities of type to entities of type . Thus one has types like which are interpreted as elements of the set of functions from entities to truth-values, i.e. indicator functions of sets of entities. An expression of type 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 natural language quantifiers, like everybody or nobody (Montague 1973, Barwise and Cooper 1981). [10]
Type theory with records is a formal semantics representation framework, using records to express type theory types. It has been used in natural language processing, principally computational semantics and dialogue systems. [11] [12]
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.
A type theory is a mathematical logic, which is to say it is a collection of rules of inference that result in judgments. Most logics have judgments asserting "The proposition is true", or "The formula is a well-formed formula". [13] A type theory has judgments that define types and assign them to a collection of formal objects, known as terms. A term and its type are often written together as .
A term in logic is recursively defined as a constant symbol, variable, or a function application, where a term is applied to another term. Constant symbols could include the natural number , the Boolean value , and functions such as the successor function and conditional operator . Thus some terms could be , , , and .
Most type theories have 4 judgments:
Judgments may follow from assumptions. For example, one might say "assuming is a term of type and is a term of type , it follows that is a term of type ". Such judgments are formally written with the turnstile symbol .
If there are no assumptions, there will be nothing to the left of the turnstile.
The list of assumptions on the left is the context of the judgment. Capital greek letters, such as and , are common choices to represent some or all of the assumptions. The 4 different judgments are thus usually written as follows.
Formal notation for judgments | Description |
---|---|
Type | is a type (under assumptions ). |
is a term of type (under assumptions ). | |
Type is equal to type (under assumptions ). | |
Terms and are both of type and are equal (under assumptions ). |
Some textbooks use a triple equal sign to stress that this is judgmental equality and thus an extrinsic notion of equality. [14] The judgments enforce that every term has a type. The type will restrict which rules can be applied to a term.
A type theory's inference rules say what judgments can be made, based on the existence of other judgments. Rules are expressed as a Gentzen-style deduction using a horizontal line, with the required input judgments above the line and the resulting judgment below the line. [15] For example, the following inference rule states a substitution rule for judgmental equality.The rules are syntactic and work by rewriting. The metavariables , , , , and may actually consist of complex terms and types that contain many function applications, not just single symbols.
To generate a particular judgment in type theory, there must be a rule to generate it, as well as rules to generate all of that rule's required inputs, and so on. The applied rules form a proof tree, where the top-most rules need no assumptions. One example of a rule that does not require any inputs is one that states the type of a constant term. For example, to assert that there is a term of type , one would write the following.
Generally, the desired conclusion of a proof in type theory is one of type inhabitation. [16] The decision problem of type inhabitation (abbreviated by ) is:
Girard's paradox shows that type inhabitation is strongly related to the consistency of a type system with Curry–Howard correspondence. To be sound, such a system must have uninhabited types.
A type theory usually has several rules, including ones to:
Also, for each "by rule" type, there are 4 different kinds of rules
For examples of rules, an interested reader may follow Appendix A.2 of the Homotopy Type Theory book, [14] or read Martin-Löf's Intuitionistic Type Theory. [17]
The logical framework of a type theory bears a resemblance to intuitionistic, or constructive, logic. Formally, type theory is often cited as an implementation of the Brouwer–Heyting–Kolmogorov interpretation of intuitionistic logic. [17] Additionally, connections can be made to category theory and computer programs.
When used as a foundation, certain types are interpreted to be propositions (statements that can be proven), and terms inhabiting the type are interpreted to be proofs of that proposition. When some types are interpreted as propositions, there is a set of common types that can be used to connect them to make a Boolean algebra out of types. However, the logic is not classical logic but intuitionistic logic, which is to say it does not have the law of excluded middle nor double negation.
Under this intuitionistic interpretation, there are common types that act as the logical operators:
Logic Name | Logic Notation | Type Notation | Type Name |
---|---|---|---|
True | Unit Type | ||
False | Empty Type | ||
Implication | Function | ||
Not | Function to Empty Type | ||
And | Product Type | ||
Or | Sum Type | ||
For All | Dependent Product | ||
Exists | Dependent Sum |
Because the law of excluded middle does not hold, there is no term of type . Likewise, double negation does not hold, so there is no term of type .
It is possible to include the law of excluded middle and double negation into a type theory, by rule or assumption. However, terms may not compute down to canonical terms and it will interfere with the ability to determine if two terms are judgementally equal to each other.[ citation needed ]
Per Martin-Löf proposed his intuitionistic type theory as a foundation for constructive mathematics. [13] Constructive mathematics requires when proving "there exists an with property ", one must construct a particular and a proof that it has property . In type theory, existence is accomplished using the dependent product type, and its proof requires a term of that type.
An example of a non-constructive proof is proof by contradiction. The first step is assuming that does not exist and refuting it by contradiction. The conclusion from that step is "it is not the case that does not exist". The last step is, by double negation, concluding that exists. Constructive mathematics does not allow the last step of removing the double negation to conclude that exists. [18]
Most of the type theories proposed as foundations are constructive, and this includes most of the ones used by proof assistants.[ citation needed ] It is possible to add non-constructive features to a type theory, by rule or assumption. These include operators on continuations such as call with current continuation. However, these operators tend to break desirable properties such as canonicity and parametricity.
The Curry–Howard correspondence is the observed similarity between logics and programming languages. The implication in logic, "A B" resembles a function from type "A" to type "B". For a variety of logics, the rules are similar to expressions in a programming language's types. The similarity goes farther, as applications of the rules resemble programs in the programming languages. Thus, the correspondence is often summarized as "proofs as programs".
The opposition of terms and types can also be viewed as one of implementation and specification. By program synthesis, (the computational counterpart of) type inhabitation can be used to construct (all or parts of) programs from the specification given in the form of type information. [19]
Many programs that work with type theory (e.g., interactive theorem provers) also do type inferencing. It lets them select the rules that the user intends, with fewer actions by the user.
Main article: 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: [20]
The interplay, known as categorical logic, has been a subject of active research since then; see the monograph of Jacobs (1999) for instance.
Homotopy type theory attempts to combine type theory and category theory. It focuses on equalities, especially equalities between types. Homotopy type theory differs from intuitionistic type theory mostly by its handling of the equality type. In 2016, cubical type theory was proposed, which is a homotopy type theory with normalization. [21] [22]
The most basic types are called atoms, and a term whose type is an atom is known as an atomic term. Common atomic terms included in type theories are natural numbers, often notated with the type , Boolean logic values (/), notated with the type , and formal variables, whose type may vary. [16] For example, the following may be atomic terms.
In addition to atomic terms, most modern type theories also allow for functions. Function types introduce an arrow symbol, and are defined inductively: If and are types, then the notation is the type of a function which takes a parameter of type and returns a term of type . Types of this form are known as simple types. [16]
Some terms may be declared directly as having a simple type, such as the following term, , which takes in two natural numbers in sequence and returns one natural number.
Strictly speaking, a simple type only allows for one input and one output, so a more faithful reading of the above type is that is a function which takes in a natural number and returns a function of the form . The parentheses clarify that does not have the type , which would be a function which takes in a function of natural numbers and returns a natural number. The convention is that the arrow is right associative, so the parentheses may be dropped from 's type. [16]
New function terms may be constructed using lambda expressions, and are called lambda terms. These terms are also defined inductively: a lambda term has the form , where is a formal variable and is a term, and its type is notated , where is the type of , and is the type of . [16] The following lambda term represents a function which doubles an input natural number.
The variable is and (implicit from the lambda term's type) must have type . The term has type , which is seen by applying the function application inference rule twice. Thus, the lambda term has type , which means it is a function taking a natural number as an argument and returning a natural number.
A lambda term is often referred to [lower-alpha 4] as an anonymous function because it lacks a name. The concept of anonymous functions appears in many programming languages.
The power of type theories is in specifying how terms may be combined by way of inference rules. [4] Type theories which have functions also have the inference rule of function application: if is a term of type , and is a term of type , then the application of to , often written , has type . For example, if one knows the type notations , , and , then the following type notations can be deduced from function application. [16]
Parentheses indicate the order of operations; however, by convention, function application is left associative, so parentheses can be dropped where appropriate. [16] In the case of the three examples above, all parentheses could be omitted from the first two, and the third may simplified to .
Type theories that allow for lambda terms also include inference rules known as -reduction and -reduction. They generalize the notion of function application to lambda terms. Symbolically, they are written
The first reduction describes how to evaluate a lambda term: if a lambda expression is applied to a term , one replaces every occurrence of in with . The second reduction makes explicit the relationship between lambda expressions and function types: if is a lambda term, then it must be that is a function term because it is being applied to . Therefore, the lambda expression is equivalent to just , as both take in one argument and apply to it. [4]
For example, the following term may be -reduced.
In type theories that also establish notions of equality for types and terms, there are corresponding inference rules of -equality and -equality. [16]
The empty type has no terms. The type is usually written or . One use for the empty type is proofs of type inhabitation. If for a type , it is consistent to derive a function of type , then is uninhabited, which is to say it has no terms.
The unit type has exactly 1 canonical term. The type is written or and the single canonical term is written . The unit type is also used in proofs of type inhabitation. If for a type , it is consistent to derive a function of type , then is inhabited, which is to say it must have one or more terms.
The Boolean type has exactly 2 canonical terms. The type is usually written or or . The canonical terms are usually and .
Natural numbers are usually implemented in the style of Peano Arithmetic. There is a canonical term for zero. Canonical values larger than zero use iterated applications of a successor function .
Some type theories allow for types of complex terms, such as functions or lists, to depend on the types of its arguments. For example, a type theory could have the dependent type , which should correspond to lists of terms, where each term must have type . In this case, has the type , where denotes the universe of all types in the theory.
Some theories also permit types to be dependent on terms instead of types. For example, a theory could have the type , where is a term of type encoding the length of the vector. This allows for greater specificity and type safety: functions with vector length restrictions or length matching requirements, such as the dot product, can encode this requirement as part of the type. [24]
There are foundational issues that can arise from dependent types if a theory is not careful about what dependencies are allowed, such as Girard's Paradox. The logician Henk Barendegt introduced the lambda cube as a framework for studying various restrictions and levels of dependent typing. [25]
The product type depends on two types, and its terms are commonly written as ordered pairs or with the symbol . The pair has the product type , where is the type of and is the type of . The product type is usually defined with eliminator functions and .
Besides ordered pairs, this type is used for the concepts of logical conjunction and intersection.
The sum type depends on two types, and it is commonly written with the symbol or . In programming languages, sum types may be referred to as tagged unions. The type is usually defined with constructors and , which are injective, and an eliminator function such that
The sum type is used for the concepts of logical disjunction and union.
Two common type dependencies, dependent product and dependent sum types, allow for the theory to encode BHK intuitionistic logic by acting as equivalents to universal and existential quantification; this is formalized by Curry–Howard Correspondence. [24] As they also connect to products and sums in set theory, they are often written with the symbols and , respectively. [17] Dependent product and sum types commonly appear in function types and are frequently incorporated in programming languages. [26]
For example, consider a function , which takes in a and a term of type , and returns the list with the element at the end. The type annotation of such a function would be , which can be read as "for any type , pass in a and an , and return a ".
Sum types are seen in dependent pairs, where the second type depends on the value of the first term. This arises naturally in computer science where functions may return different types of outputs based on the input. For example, the Boolean type is usually defined with an eliminator function , which takes three arguments and behaves as follows.
The return type of this function depends on its input. If the type theory allows for dependent types, then it is possible to define a function such that
The type of may then be written as .
Following the notion of Curry-Howard Correspondence, the identity type is a type introduced to mirror propositional equivalence, as opposed to the judgmental (syntactic) equivalence that type theory already provides.
An identity type requires two terms of the same type and is written with the symbol . For example, if and are terms, then is a possible type. Canonical terms are created with a reflexivity function, . For a term , the call returns the canonical term inhabiting the type .
The complexities of equality in type theory make it an active research topic; homotopy type theory is a notable area of research that mainly deals with equality in type theory.
Inductive types are a general template for creating a large variety of types. In fact, all the types described above and more can be defined using the rules of inductive types. Two methods of generating inductive types are induction-recursion and induction-induction. A method that only uses lambda terms is Scott encoding.
Some proof assistants, such as Coq and Lean, are based on the calculus for inductive constructions, which is a calculus of constructions with inductive types.
The most commonly accepted foundation for mathematics is first-order logic with the language and axioms of Zermelo–Fraenkel set theory with the axiom of choice, abbreviated ZFC. Type theories having sufficient expressibility may also act as a foundation of mathematics. There are a number of differences between these two approaches.
Proponents of type theory will also point out its connection to constructive mathematics through the BHK interpretation, its connection to logic by the Curry–Howard isomorphism, and its connections to Category theory.
Terms usually belong to a single type. However, there are set theories that define "subtyping".
Computation takes place by repeated application of rules. Many types of theories are strongly normalizing, which means that any order of applying the rules will always end in the same result. However, some are not. In a normalizing type theory, the one-directional computation rules are called "reduction rules", and applying the rules "reduces" the term. If a rule is not one-directional, it is called a "conversion rule".
Some combinations of types are equivalent to other combinations of types. When functions are considered "exponentiation", the combinations of types can be written similarly to algebraic identities. [26] Thus, , , , , .
Most type theories do not have axioms. This is because a type theory is defined by its rules of inference. This is a source of confusion for people familiar with Set Theory, where a theory is defined by both the rules of inference for a logic (such as first-order logic) and axioms about sets.
Sometimes, a type theory will add a few axioms. An axiom is a judgment that is accepted without a derivation using the rules of inference. They are often added to ensure properties that cannot be added cleanly through the rules.
Axioms can cause problems if they introduce terms without a way to compute on those terms. That is, axioms can interfere with the normalizing property of the type theory. [27]
Some commonly encountered axioms are:
The Axiom of Choice does not need to be added to type theory, because in most type theories it can be derived from the rules of inference. This is because of the constructive nature of type theory, where proving that a value exists requires a method to compute the value. The Axiom of Choice is less powerful in type theory than most set theories, because type theory's functions must be computable and, being syntax-driven, the number of terms in a type must be countable. (See Axiom of choice § In constructive mathematics.)
(x,y) -> x^5+y
, as an anonymous function. [23] In logic and computer science, specifically automated reasoning, unification is an algorithmic process of solving equations between symbolic expressions, each of the form Left-hand side = Right-hand side. For example, using x,y,z as variables, and taking f to be an uninterpreted function, the singleton equation set { f(1,y) = f(x,2) } is a syntactic first-order unification problem that has the substitution { x ↦ 1, y ↦ 2 } as its only solution.
In programming language theory and proof theory, the Curry–Howard correspondence is the direct relationship between computer programs and mathematical proofs. It is also known as the Curry–Howard isomorphism or equivalence, or the proofs-as-programs and propositions- or formulae-as-types interpretation.
Intuitionistic type theory is a type theory and an alternative foundation of mathematics. Intuitionistic type theory was created by Per Martin-Löf, a Swedish mathematician and philosopher, who first published it in 1972. There are multiple versions of the type theory: Martin-Löf proposed both intensional and extensional variants of the theory and early impredicative versions, shown to be inconsistent by Girard's paradox, gave way to predicative versions. However, all versions keep the core design of constructive logic using dependent types.
A typed lambda calculus is a typed formalism that uses the lambda-symbol to denote anonymous function abstraction. In this context, types are usually objects of a syntactic nature that are assigned to lambda terms; the exact nature of a type depends on the calculus considered. From a certain point of view, typed lambda calculi can be seen as refinements of the untyped lambda calculus, but from another point of view, they can also be considered the more fundamental theory and untyped lambda calculus a special case with only one type.
In type theory, a typing rule is an inference rule that describes how a type system assigns a type to a syntactic construction. These rules may be applied by the type system to determine if a program is well-typed and what type expressions have. A prototypical example of the use of typing rules is in defining type inference in the simply typed lambda calculus, which is the internal language of Cartesian closed categories.
System F is a typed lambda calculus that introduces, to simply typed lambda calculus, a mechanism of universal quantification over types. System F formalizes parametric polymorphism in programming languages, thus forming a theoretical basis for languages such as Haskell and ML. It was discovered independently by logician Jean-Yves Girard (1972) and computer scientist John C. Reynolds.
In mathematical logic and type theory, the λ-cube is a framework introduced by Henk Barendregt 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:
In computer science and logic, a dependent type is a type whose definition depends on a value. It is an overlapping feature of type theory and type systems. In intuitionistic type theory, dependent types are used to encode logic's quantifiers like "for all" and "there exists". In functional programming languages like Agda, ATS, Coq, F*, Epigram, Idris, and Lean, dependent types help reduce bugs by enabling the programmer to assign types that further restrain the set of possible implementations.
The simply typed lambda calculus, a form of type theory, is a typed interpretation of the lambda calculus with only one type constructor that builds function types. It is the canonical and simplest example of a typed lambda calculus. The simply typed lambda calculus was originally introduced by Alonzo Church in 1940 as an attempt to avoid paradoxical use of the untyped lambda calculus.
In mathematical logic, Heyting arithmetic is an axiomatization of arithmetic in accordance with the philosophy of intuitionism. It is named after Arend Heyting, who first proposed it.
In computer science, Programming Computable Functions (PCF) is a typed functional language introduced by Gordon Plotkin in 1977, based on previous unpublished material by Dana Scott. It can be considered to be an extended version of the typed lambda calculus or a simplified version of modern typed functional languages such as ML or Haskell.
Axiomatic constructive set theory is an approach to mathematical constructivism following the program of axiomatic set theory. The same first-order language with "" and "" of classical set theory is usually used, so this is not to be confused with a constructive types approach. On the other hand, some constructive theories are indeed motivated by their interpretability in type theories.
In logic, a modal companion of a superintuitionistic (intermediate) logic L is a normal modal logic that interprets L by a certain canonical translation, described below. Modal companions share various properties of the original intermediate logic, which enables to study intermediate logics using tools developed for modal logic.
In constructive mathematics, Church's thesis is the principle stating that all total functions are computable functions.
In proof theory, ordinal analysis assigns ordinals to mathematical theories as a measure of their strength. If theories have the same proof-theoretic ordinal they are often equiconsistent, and if one theory has a larger proof-theoretic ordinal than another it can often prove the consistency of the second theory.
In type theory, a system has inductive types if it has facilities for creating a new type from constants and functions that create terms of that type. The feature serves a role similar to data structures in a programming language and allows a type theory to add concepts like numbers, relations, and trees. As the name suggests, inductive types can be self-referential, but usually only in a way that permits structural recursion.
Stokes' theorem, also known as the Kelvin–Stokes theorem after Lord Kelvin and George Stokes, the fundamental theorem for curls or simply the curl theorem, is a theorem in vector calculus on . Given a vector field, the theorem relates the integral of the curl of the vector field over some surface, to the line integral of the vector field around the boundary of the surface. The classical theorem of Stokes can be stated in one sentence:
A Hindley–Milner (HM) type system is a classical type system for the lambda calculus with parametric polymorphism. It is also known as Damas–Milner or Damas–Hindley–Milner. It was first described by J. Roger Hindley and later rediscovered by Robin Milner. Luis Damas contributed a close formal analysis and proof of the method in his PhD thesis.
In mathematical logic, the intersection type discipline is a branch of type theory encompassing type systems that use the intersection type constructor to assign multiple types to a single term. In particular, if a term can be assigned both the type and the type , then can be assigned the intersection type . Therefore, the intersection type constructor can be used to express finite heterogeneous ad hoc polymorphism . For example, the λ-term can be assigned the type in most intersection type systems, assuming for the term variable both the function type and the corresponding argument type .
In mathematics, especially mathematical logic, graph theory and number theory, the Buchholz hydra game is a type of hydra game, which is a single-player game based on the idea of chopping pieces off a mathematical tree. The hydra game can be used to generate a rapidly growing function, , which eventually dominates all recursive functions that are provably total in "", and the termination of all hydra games is not provably total in .
{{cite journal}}
: CS1 maint: DOI inactive as of November 2024 (link)