Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Type theory

From Wikipedia, the free encyclopedia
Mathematical theory of data types
"Theory of types" redirects here. For an architectural term, seeForm (architecture) § Theories.

Inmathematics andtheoretical computer science, atype theory is theformal presentation of a specifictype system.[a] Type theory is the academic study of type systems.

Some type theories serve as alternatives toset theory as afoundation of mathematics. Two influential type theories that have been proposed as foundations are:

Mostcomputerized proof-writing systems use a type theory fortheir foundation. A common one isThierry Coquand'sCalculus of Inductive Constructions.

History

[edit]
Main article:History of type theory

Type theory was created to avoidparadoxes innaive set theory andformal logic[b], such asRussell's paradox which demonstrates 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 aramified theory of types together with anaxiom of reducibility, both of which appeared inWhitehead andRussell'sPrincipia 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 ofsubtypes of that type,[c] 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 asZermelo-Fraenkel set theory.[4]

Type theory is particularly popular in conjunction withAlonzo Church'slambda calculus. One notable early example of type theory is Church'ssimply typed lambda calculus. Church's theory of types[5] helped the formal system avoid theKleene–Rosser paradox that afflicted the original untyped lambda calculus. Church demonstrated[d] that it could serve as afoundation of mathematics and it was referred to as ahigher-order logic.

In the modern literature, "type theory" refers to a typed system based around lambda calculus. One influential system isPer Martin-Löf'sintuitionistic type theory, which was proposed as a foundation forconstructive mathematics. Another isThierry Coquand'scalculus of constructions, which is used as the foundation byRocq (previously known asCoq),Lean, and other computerproof assistants. Type theory is an active area of research, one direction being the development ofhomotopy type theory.

Applications

[edit]

Mathematical foundations

[edit]

The first computer proof assistant, calledAutomath, used type theory to encode mathematics on a computer. Martin-Löf specifically developedintuitionistic type theory to encodeall mathematics to serve as a new foundation for mathematics. There is ongoing research into mathematical foundations usinghomotopy type theory.

Mathematicians working incategory theory already had difficulty working with the widely accepted foundation ofZermelo–Fraenkel set theory. This led to proposals such as Lawvere'sElementary Theory of the Category of Sets (ETCS).[7] Homotopy type theory continues in this line using type theory. Researchers are exploring connections between dependent types (especially the identity type) andalgebraic topology (specificallyhomotopy).

Proof assistants

[edit]
Main article:Proof assistant

Much of the current research into type theory is driven byproof checkers, interactiveproof assistants, andautomated 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 byLEGO andIsabelle. Isabelle also supports foundations besides type theories, such asZFC.Mizar is an example of a proof system that only supports set theory.

Programming languages

[edit]

Anystatic program analysis, such as the type checking algorithms in thesemantic analysis phase ofcompiler, has a connection to type theory. A prime example isAgda, a programming language which uses UTT (Luo's Unified Theory of dependent Types) for its type system.

The programming languageML was developed for manipulating type theories (seeLCF) and its own type system was heavily influenced by them.

Linguistics

[edit]

Type theory is also widely used informal theories of semantics ofnatural languages,[8][9] especiallyMontague grammar[10] and its descendants. In particular,categorial grammars andpregroup grammars extensively use type constructors to define the types (noun,verb, etc.) of words.

The most common construction takes the basic typese{\displaystyle e} andt{\displaystyle t} for individuals andtruth-values, respectively, and defines the set of types recursively as follows:

A complex typea,b{\displaystyle \langle a,b\rangle } is the type offunctions from entities of typea{\displaystyle a} to entities of typeb{\displaystyle b}. Thus one has types likee,t{\displaystyle \langle e,t\rangle } 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 typee,t,t{\displaystyle \langle \langle e,t\rangle ,t\rangle } 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 ofnatural language quantifiers, like everybody ornobody (Montague 1973,Barwise and Cooper 1981).[11]

Type theory with records is aformal semantics representation framework, usingrecords to expresstype theory types. It has been used innatural language processing, principallycomputational semantics anddialogue systems.[12][13]

Social sciences

[edit]

Gregory Bateson introduced a theory of logical types into the social sciences; his notions ofdouble bind and logical levels are based on Russell's theory of types.

Logic

[edit]

A type theory is amathematical logic, which is to say it is a collection ofrules of inference that result injudgments. Most logics have judgments asserting "Thepropositionφ{\displaystyle \varphi } is true", or "Theformulaφ{\displaystyle \varphi } is awell-formed formula".[14] 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 asterm:type{\displaystyle \mathrm {term} :{\mathsf {type}}}.

Terms

[edit]

Aterm in logic isrecursively defined as aconstant symbol,variable, or afunction application, where a term is applied to another term. Constant symbols could include the natural number0{\displaystyle 0}, the Boolean valuetrue{\displaystyle \mathrm {true} }, and functions such as thesuccessor functionS{\displaystyle \mathrm {S} } andconditional operatorif{\displaystyle \mathrm {if} }. Thus some terms could be0{\displaystyle 0},(S0){\displaystyle (\mathrm {S} \,0)},(S(S0)){\displaystyle (\mathrm {S} \,(\mathrm {S} \,0))}, and(iftrue0(S0)){\displaystyle (\mathrm {if} \,\mathrm {true} \,0\,(\mathrm {S} \,0))}.

Judgments

[edit]

Most type theories have 4 judgments:

Judgments may follow from assumptions. For example, one might say "assumingx{\displaystyle x} is a term of typebool{\displaystyle {\mathsf {bool}}} andy{\displaystyle y} is a term of typenat{\displaystyle {\mathsf {nat}}}, it follows that(ifxyy){\displaystyle (\mathrm {if} \,x\,y\,y)} is a term of typenat{\displaystyle {\mathsf {nat}}}". Such judgments are formally written with theturnstile symbol{\displaystyle \vdash }.

x:bool,y:nat(ifxyy):nat{\displaystyle x:{\mathsf {bool}},y:{\mathsf {nat}}\vdash ({\textrm {if}}\,x\,y\,y):{\mathsf {nat}}}

If there are no assumptions, there will be nothing to the left of the turnstile.

S:natnat{\displaystyle \vdash \mathrm {S} :{\mathsf {nat}}\to {\mathsf {nat}}}

The list of assumptions on the left is thecontext of the judgment. Capital greek letters, such asΓ{\displaystyle \Gamma } andΔ{\displaystyle \Delta }, are common choices to represent some or all of the assumptions. The 4 different judgments are thus usually written as follows.

Formal notation for judgmentsDescription
ΓT{\displaystyle \Gamma \vdash T} TypeT{\displaystyle T} is a type (under assumptionsΓ{\displaystyle \Gamma }).
Γt:T{\displaystyle \Gamma \vdash t:T}t{\displaystyle t} is a term of typeT{\displaystyle T} (under assumptionsΓ{\displaystyle \Gamma }).
ΓT1=T2{\displaystyle \Gamma \vdash T_{1}=T_{2}}TypeT1{\displaystyle T_{1}} is equal to typeT2{\displaystyle T_{2}} (under assumptionsΓ{\displaystyle \Gamma }).
Γt1=t2:T{\displaystyle \Gamma \vdash t_{1}=t_{2}:T}Termst1{\displaystyle t_{1}} andt2{\displaystyle t_{2}} are both of typeT{\displaystyle T} and are equal (under assumptionsΓ{\displaystyle \Gamma }).

Some textbooks use a triple equal sign{\displaystyle \equiv } to stress that this isjudgmental equality and thus anextrinsic notion of equality.[15] The judgments enforce that every term has a type. The type will restrict which rules can be applied to a term.

Rules of Inference

[edit]

A type theory'sinference rules say what judgments can be made, based on the existence of other judgments. Rules are expressed as aGentzen-stylededuction using a horizontal line, with the required input judgments above the line and the resulting judgment below the line.[16] For example, the following inference rule states asubstitution rule for judgmental equality.Γt:T1ΔT1=T2Γ,Δt:T2{\displaystyle {\begin{array}{c}\Gamma \vdash t:T_{1}\qquad \Delta \vdash T_{1}=T_{2}\\\hline \Gamma ,\Delta \vdash t:T_{2}\end{array}}}The rules are syntactic and work byrewriting. ThemetavariablesΓ{\displaystyle \Gamma },Δ{\displaystyle \Delta },t{\displaystyle t},T1{\displaystyle T_{1}}, andT2{\displaystyle T_{2}} 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 aproof 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 term0{\displaystyle 0} of typenat{\displaystyle {\mathsf {nat}}}, one would write the following.0:nat{\displaystyle {\begin{array}{c}\hline \vdash 0:nat\\\end{array}}}

Type inhabitation

[edit]
Main article:Type inhabitation

Generally, the desired conclusion of a proof in type theory is one oftype inhabitation.[17] The decision problem of type inhabitation (abbreviated byt.Γt:τ?{\displaystyle \exists t.\Gamma \vdash t:\tau ?}) is:

Given a contextΓ{\displaystyle \Gamma } and a typeτ{\displaystyle \tau }, decide whether there exists a termt{\displaystyle t} that can be assigned the typeτ{\displaystyle \tau } in the type environmentΓ{\displaystyle \Gamma }.

Girard's paradox shows that type inhabitation is strongly related to theconsistency 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:

  • create a judgment (known as acontext in this case)
  • add an assumption to the context (contextweakening)
  • rearrange the assumptions
  • use an assumption to create a variable
  • definereflexivity,symmetry andtransitivity for judgmental equality
  • define substitution for application of lambda terms
  • list all the interactions of equality, such as substitution
  • define a hierarchy of type universes
  • assert the existence of new types

Also, for each "by rule" type, there are 4 different kinds of rules

  • "type formation" rules say how to create the type
  • "term introduction" rules define the canonical terms and constructor functions, like "pair" and "S".
  • "term elimination" rules define the other functions like "first", "second", and "R".
  • "computation" rules specify how computation is performed with the type-specific functions.

For examples of rules, an interested reader may follow Appendix A.2 of theHomotopy Type Theory book,[15] or read Martin-Löf's Intuitionistic Type Theory.[18]

Connections to foundations

[edit]

The logical framework of a type theory bears a resemblance tointuitionistic, or constructive, logic. Formally, type theory is often cited as an implementation of theBrouwer–Heyting–Kolmogorov interpretation of intuitionistic logic.[18] Additionally, connections can be made tocategory theory andcomputer programs.

Intuitionistic logic

[edit]

When used as a foundation, certain types are interpreted to bepropositions (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 aBoolean algebra out of types. However, the logic is notclassical logic butintuitionistic logic, which is to say it does not have thelaw of excluded middle nordouble negation.

Under this intuitionistic interpretation, there are common types that act as the logical operators:

Logic NameLogic NotationType NotationType Name
True{\displaystyle \top }{\displaystyle \top }Unit Type
False{\displaystyle \bot }{\displaystyle \bot }Empty Type
ImplicationAB{\displaystyle A\to B}AB{\displaystyle A\to B}Function
Not¬A{\displaystyle \neg A}A{\displaystyle A\to \bot }Function to Empty Type
AndAB{\displaystyle A\land B}A×B{\displaystyle A\times B}Product Type
OrAB{\displaystyle A\lor B}A+B{\displaystyle A+B}Sum Type
For AllaA,P(a){\displaystyle \forall a\in A,P(a)}Πa:A.P(a){\displaystyle \Pi a:A.P(a)}Dependent Product
ExistsaA,P(a){\displaystyle \exists a\in A,P(a)}Σa:A.P(a){\displaystyle \Sigma a:A.P(a)}Dependent Sum

Because the law of excluded middle does not hold, there is no term of typeΠa.A+(A){\displaystyle \Pi a.A+(A\to \bot )}. Likewise, double negation does not hold, so there is no term of typeΠA.((A))A{\displaystyle \Pi A.((A\to \bot )\to \bot )\to A}.

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]

Constructive mathematics

[edit]

Per Martin-Löf proposed his intuitionistic type theory as a foundation forconstructive mathematics.[14] Constructive mathematics requires when proving "there exists anx{\displaystyle x} with propertyP(x){\displaystyle P(x)}", one must construct a particularx{\displaystyle x} and a proof that it has propertyP{\displaystyle P}. 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 isproof by contradiction. The first step is assuming thatx{\displaystyle x} does not exist and refuting it by contradiction. The conclusion from that step is "it is not the case thatx{\displaystyle x} does not exist". The last step is, by double negation, concluding thatx{\displaystyle x} exists. Constructive mathematics does not allow the last step of removing the double negation to conclude thatx{\displaystyle x} exists.[19]

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 ascall with current continuation. However, these operators tend to break desirable properties such ascanonicity andparametricity.

Curry-Howard correspondence

[edit]

TheCurry–Howard correspondence is the observed similarity between logics and programming languages. The implication in logic, "A{\displaystyle \to } 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 ofimplementation andspecification. Byprogram 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.[20]

Type inference

[edit]
Main article:Type inference

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.

Research areas

[edit]

Category theory

[edit]

Although the initial motivation forcategory theory was far removed from foundationalism, the two fields turned out to have deep connections. AsJohn Lane Bell writes: "In fact categories canthemselves 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 (orsorts[21]), 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:[22]

The interplay, known ascategorical logic, has been a subject of active research since then; see the monograph of Jacobs (1999) for instance.

Homotopy type theory

[edit]

Homotopy type theory attempts to combine type theory and category theory. It focuses on equalities, especially equalities between types.Homotopy type theory differs fromintuitionistic 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.[23][24]

Definitions

[edit]

Terms and types

[edit]

Atomic terms

[edit]

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 arenatural numbers, often notated with the typenat{\displaystyle {\mathsf {nat}}},Boolean logic values (true{\displaystyle \mathrm {true} }/false{\displaystyle \mathrm {false} }), notated with the typebool{\displaystyle {\mathsf {bool}}}, andformal variables, whose type may vary.[17] For example, the following may be atomic terms.

Function terms

[edit]

In addition to atomic terms, most modern type theories also allow forfunctions. Function types introduce an arrow symbol, and aredefined inductively: Ifσ{\displaystyle \sigma } andτ{\displaystyle \tau } are types, then the notationστ{\displaystyle \sigma \to \tau } is the type of a function which takes aparameter of typeσ{\displaystyle \sigma } and returns a term of typeτ{\displaystyle \tau }. Types of this form are known assimple types.[17]

Some terms may be declared directly as having a simple type, such as the following term,add{\displaystyle \mathrm {add} }, which takes in two natural numbers in sequence and returns one natural number.

add:nat(natnat){\displaystyle \mathrm {add} :{\mathsf {nat}}\to ({\mathsf {nat}}\to {\mathsf {nat}})}

Strictly speaking, a simple type only allows for one input and one output, so a more faithful reading of the above type is thatadd{\displaystyle \mathrm {add} } is a function which takes in a natural number and returns a function of the formnatnat{\displaystyle {\mathsf {nat}}\to {\mathsf {nat}}}. The parentheses clarify thatadd{\displaystyle \mathrm {add} } does not have the type(natnat)nat{\displaystyle ({\mathsf {nat}}\to {\mathsf {nat}})\to {\mathsf {nat}}}, which would be a function which takes in a function of natural numbers and returns a natural number. The convention is that the arrow isright associative, so the parentheses may be dropped fromadd{\displaystyle \mathrm {add} }'s type.[17]

Lambda terms

[edit]

New function terms may be constructed usinglambda expressions, and are called lambda terms. These terms are also defined inductively: a lambda term has the form(λv.t){\displaystyle (\lambda v.t)}, wherev{\displaystyle v} is a formal variable andt{\displaystyle t} is a term, and its type is notatedστ{\displaystyle \sigma \to \tau }, whereσ{\displaystyle \sigma } is the type ofv{\displaystyle v}, andτ{\displaystyle \tau } is the type oft{\displaystyle t}.[17] The following lambda term represents a function which doubles an input natural number.

(λx.addxx):natnat{\displaystyle (\lambda x.\mathrm {add} \,x\,x):{\mathsf {nat}}\to {\mathsf {nat}}}

The variable isx{\displaystyle x} and (implicit from the lambda term's type) must have typenat{\displaystyle {\mathsf {nat}}}. The termaddxx{\displaystyle \mathrm {add} \,x\,x} has typenat{\displaystyle {\mathsf {nat}}}, which is seen by applying the function application inference rule twice. Thus, the lambda term has typenatnat{\displaystyle {\mathsf {nat}}\to {\mathsf {nat}}}, which means it is a function taking a natural number as anargument and returning a natural number.

A lambda term is often referred to[e] as ananonymous function because it lacks a name. The concept of anonymous functions appears in many programming languages.

Inference Rules

[edit]

Function application

[edit]

The power of type theories is in specifying how terms may be combined by way ofinference rules.[5] Type theories which have functions also have the inference rule offunction application: ift{\displaystyle t} is a term of typeστ{\displaystyle \sigma \to \tau }, ands{\displaystyle s} is a term of typeσ{\displaystyle \sigma }, then the application oft{\displaystyle t} tos{\displaystyle s}, often written(ts){\displaystyle (t\,s)}, has typeτ{\displaystyle \tau }. For example, if one knows the type notations0:nat{\displaystyle 0:{\textsf {nat}}},1:nat{\displaystyle 1:{\textsf {nat}}}, and2:nat{\displaystyle 2:{\textsf {nat}}}, then the following type notations can bededuced from function application.[17]

Parentheses indicate theorder of operations; however, by convention, function application isleft associative, so parentheses can be dropped where appropriate.[17] In the case of the three examples above, all parentheses could be omitted from the first two, and the third may simplified toadd1(add20):nat{\displaystyle \mathrm {add} \,1\,(\mathrm {add} \,2\,0):{\textsf {nat}}}.

Reductions

[edit]

Type theories that allow for lambda terms also include inference rules known asβ{\displaystyle \beta }-reduction andη{\displaystyle \eta }-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(λv.t){\displaystyle (\lambda v.t)} is applied to a terms{\displaystyle s}, one replaces every occurrence ofv{\displaystyle v} int{\displaystyle t} withs{\displaystyle s}. The second reduction makes explicit the relationship between lambda expressions and function types: if(λv.tv){\displaystyle (\lambda v.t\,v)} is a lambda term, then it must be thatt{\displaystyle t} is a function term because it is being applied tov{\displaystyle v}. Therefore, the lambda expression is equivalent to justt{\displaystyle t}, as both take in one argument and applyt{\displaystyle t} to it.[5]

For example, the following term may beβ{\displaystyle \beta }-reduced.

(λx.addxx)2add22{\displaystyle (\lambda x.\mathrm {add} \,x\,x)\,2\rightarrow \mathrm {add} \,2\,2}

In type theories that also establish notions ofequality for types and terms, there are corresponding inference rules ofβ{\displaystyle \beta }-equality andη{\displaystyle \eta }-equality.[17]

Common terms and types

[edit]

Empty type

[edit]

Theempty type has no terms. The type is usually written{\displaystyle \bot } or0{\displaystyle \mathbb {0} }. One use for the empty type is proofs oftype inhabitation. If for a typea{\displaystyle a}, it is consistent to derive a function of typea{\displaystyle a\to \bot }, thena{\displaystyle a} isuninhabited, which is to say it has no terms.

Unit type

[edit]

Theunit type has exactly 1 canonical term. The type is written{\displaystyle \top } or1{\displaystyle \mathbb {1} } and the single canonical term is written{\displaystyle \ast }. The unit type is also used in proofs of type inhabitation. If for a typea{\displaystyle a}, it is consistent to derive a function of typea{\displaystyle \top \to a}, thena{\displaystyle a} isinhabited, which is to say it must have one or more terms.

Boolean type

[edit]

The Boolean type has exactly 2 canonical terms. The type is usually writtenbool{\displaystyle {\textsf {bool}}} orB{\displaystyle \mathbb {B} } or2{\displaystyle \mathbb {2} }. The canonical terms are usuallytrue{\displaystyle \mathrm {true} } andfalse{\displaystyle \mathrm {false} }.

Natural numbers

[edit]

Natural numbers are usually implemented in the style ofPeano Arithmetic. There is a canonical term0:nat{\displaystyle 0:{\mathsf {nat}}} for zero. Canonical values larger than zero use iterated applications of asuccessor functionS:natnat{\displaystyle \mathrm {S} :{\mathsf {nat}}\to {\mathsf {nat}}}.

Type constructors

[edit]

Some type theories allow for types of complex terms, such as functions or lists, to depend on the types of its arguments; these are calledtype constructors. For example, a type theory could have the dependent typelista{\displaystyle {\mathsf {list}}\,a}, which should correspond tolists of terms, where each term must have typea{\displaystyle a}. In this case,list{\displaystyle {\mathsf {list}}} has the kindUU{\displaystyle U\to U}, whereU{\displaystyle U} denotes theuniverse of all types in the theory.

Product type

[edit]

The product type,×{\displaystyle \times }, depends on two types, and its terms are commonly written asordered pairs(s,t){\displaystyle (s,t)}. The pair(s,t){\displaystyle (s,t)} has the product typeσ×τ{\displaystyle \sigma \times \tau }, whereσ{\displaystyle \sigma } is the type ofs{\displaystyle s} andτ{\displaystyle \tau } is the type oft{\displaystyle t}. Each product type is then usually defined with eliminator functionsfirst:σ×τσ{\displaystyle \mathrm {first} :\sigma \times \tau \to \sigma } andsecond:σ×ττ{\displaystyle \mathrm {second} :\sigma \times \tau \to \tau }.

Besides ordered pairs, this type is used for the concepts oflogical conjunction andintersection.

Sum type

[edit]

The sum type is written as either+{\displaystyle +} or{\displaystyle \sqcup }. In programming languages, sum types may be referred to astagged unions. Each typeστ{\displaystyle \sigma \sqcup \tau } is usually defined withconstructorsleft:σ(στ){\displaystyle \mathrm {left} :\sigma \to (\sigma \sqcup \tau )} andright:τ(στ){\displaystyle \mathrm {right} :\tau \to (\sigma \sqcup \tau )}, which areinjective, and an eliminator functionmatch:(σρ)(τρ)(στ)ρ{\displaystyle \mathrm {match} :(\sigma \to \rho )\to (\tau \to \rho )\to (\sigma \sqcup \tau )\to \rho } such that

The sum type is used for the concepts oflogical disjunction andunion.

Polymorphic types

[edit]

Some theories also allow terms to have their definitions depend on types. For instance, an identity function of any type could be written asλx.x:α.αα{\displaystyle \lambda x.x:\forall \alpha .\alpha \to \alpha }. The function is said to be polymorphic inα{\displaystyle \alpha }, or generic inx{\displaystyle x}.

As another example, consider a functionappend{\displaystyle \mathrm {append} }, which takes in alista{\displaystyle {\mathsf {list}}\,a} and a term of typea{\displaystyle a}, and returns the list with the element at the end. The type annotation of such a function would beappend:a.listaalista{\displaystyle \mathrm {append} :\forall \,a.{\mathsf {list}}\,a\to a\to {\mathsf {list}}\,a}, which can be read as "for any typea{\displaystyle a}, pass in alista{\displaystyle {\mathsf {list}}\,a} and ana{\displaystyle a}, and return alista{\displaystyle {\mathsf {list}}\,a}". Hereappend{\displaystyle \mathrm {append} } is polymorphic ina{\displaystyle a}.

Products and sums

[edit]

With polymorphism, the eliminator functions can be defined generically forall product types asfirst:στ.σ×τσ{\displaystyle \mathrm {first} :\forall \,\sigma \,\tau .\sigma \times \tau \to \sigma } andsecond:στ.σ×ττ{\displaystyle \mathrm {second} :\forall \,\sigma \,\tau .\sigma \times \tau \to \tau }.

Likewise, the sum type constructors can be defined for all valid types of sum members asleft:στ.σ(στ){\displaystyle \mathrm {left} :\forall \,\sigma \,\tau .\sigma \to (\sigma \sqcup \tau )} andright:στ.τ(στ){\displaystyle \mathrm {right} :\forall \,\sigma \,\tau .\tau \to (\sigma \sqcup \tau )}, which areinjective, and the eliminator function can be given asmatch:στρ.(σρ)(τρ)(στ)ρ{\displaystyle \mathrm {match} :\forall \,\sigma \,\tau \,\rho .(\sigma \to \rho )\to (\tau \to \rho )\to (\sigma \sqcup \tau )\to \rho } such that

Dependent typing

[edit]

Some theories also permit types to be dependent on terms instead of types. For example, a theory could have the typevectorn{\displaystyle {\mathsf {vector}}\,n}, wheren{\displaystyle n} is a term of typenat{\displaystyle {\mathsf {nat}}} encoding the length of thevector. This allows for greater specificity andtype safety: functions with vector length restrictions or length matching requirements, such as thedot product, can encode this requirement as part of the type.[26]

There are foundational issues that can arise from dependent types if a theory is not careful about what dependencies are allowed, such asGirard's Paradox. The logicianHenk Barendegt introduced thelambda cube as a framework for studying various restrictions and levels of dependent typing.[27]

Dependent products and sums

[edit]

Two commontype dependencies, dependent product and dependent sum types, allow for the theory to encodeBHK intuitionistic logic by acting as equivalents touniversal and existential quantification; this is formalized byCurry–Howard Correspondence.[26] As they also connect toproducts andsums inset theory, they are often written with the symbolsΠ{\displaystyle \Pi } andΣ{\displaystyle \Sigma }, respectively.

Sum types are seen independent 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 functionif{\displaystyle \mathrm {if} }, which takes three arguments and behaves as follows.

Ordinary definitions ofif{\displaystyle \mathrm {if} } requirex{\displaystyle x} andy{\displaystyle y} to have the same type. If the type theory allows for dependent types, then it is possible to define a dependent typex:boolTFx:UUU{\displaystyle x:{\mathsf {bool}}\,\vdash \,\mathrm {TF} \,x:U\to U\to U} such that

The type ofif{\displaystyle \mathrm {if} } may then be written asστ.Πx:bool.στTFxστ{\displaystyle \forall \,\sigma \,\tau .\Pi _{x:{\mathsf {bool}}}.\sigma \to \tau \to \mathrm {TF} \,x\,\sigma \,\tau }.

Identity type

[edit]

Following the notion of Curry-Howard Correspondence, theidentity type is a type introduced to mirrorpropositional equivalence, as opposed to thejudgmental (syntactic) equivalence that type theory already provides.

An identity type requires two terms of the same type and is written with the symbol={\displaystyle =}. For example, ifx+1{\displaystyle x+1} and1+x{\displaystyle 1+x} are terms, thenx+1=1+x{\displaystyle x+1=1+x} is a possible type. Canonical terms are created with a reflexivity function,refl{\displaystyle \mathrm {refl} }. For a termt{\displaystyle t}, the callreflt{\displaystyle \mathrm {refl} \,t} returns the canonical term inhabiting the typet=t{\displaystyle t=t}.

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

[edit]

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 areinduction-recursion andinduction-induction. A method that only uses lambda terms isScott encoding.

Someproof assistants, such asRocq (previously known asCoq) andLean, are based on the calculus for inductive constructions, which is acalculus of constructions with inductive types.

Differences from set theory

[edit]

The most commonly acceptedfoundation for mathematics isfirst-order logic with thelanguage andaxioms ofZermelo–Fraenkel set theory with theaxiom of choice, abbreviated ZFC. Type theories having sufficientexpressibility may also act as a foundation of mathematics. There are a number of differences between these two approaches.

  • Set theory has bothrules andaxioms, while type theories only have rules. Type theories, in general, do not have axioms and are defined by their rules of inference.[15]
  • Classical set theory and logic have thelaw of excluded middle. When a type theory encodes the concepts of "and" and "or" as types, it leads tointuitionistic logic, and does not necessarily have the law of excluded middle.[18]
  • In set theory, an element is not restricted to one set. The element can appear in subsets and unions with other sets. In type theory, terms (generally) belong to only one type. Where a subset would be used, type theory can use apredicate function or use a dependently-typed product type, where each elementx{\displaystyle x} is paired with a proof that the subset's property holds forx{\displaystyle x}. Where a union would be used, type theory uses the sum type, which contains new canonical terms.
  • Type theory has a built-in notion of computation. Thus, "1+1" and "2" are different terms in type theory, but they compute to the same value. Moreover, functions are defined computationally as lambda terms. In set theory, "1+1=2" means that "1+1" is just another way to refer the value "2". Type theory's computation does require a complicated concept of equality.
  • Set theoryencodes numbers as sets. Type theory can encode numbers as functions usingChurch encoding, or more naturally asinductive types, and the construction closely resemblesPeano's axioms.
  • In type theory, proofs are types whereas in set theory, proofs are part of the underlying first-order logic.[15]

Proponents of type theory will also point out its connection to constructive mathematics through theBHK interpretation, its connection to logic by theCurry–Howard isomorphism, and its connections toCategory theory.

Properties of type theories

[edit]

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 arestrongly 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.[28] Thus,0+AA{\displaystyle {\mathbb {0} }+A\cong A},1×AA{\displaystyle {\mathbb {1} }\times A\cong A},1+12{\displaystyle {\mathbb {1} }+{\mathbb {1} }\cong {\mathbb {2} }},AB+CAB×AC{\displaystyle A^{B+C}\cong A^{B}\times A^{C}},AB×C(AB)C{\displaystyle A^{B\times C}\cong (A^{B})^{C}}.

Axioms

[edit]

Most type theories do not haveaxioms. 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 asfirst-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 thenormalizing property of the type theory.[29]

Some commonly encountered axioms are:

  • "Axiom K" ensures "uniqueness of identity proofs". That is, that every term of an identity type is equal to reflexivity.[30]
  • "Univalence Axiom" holds that equivalence of types is equality of types. The research into this property led tocubical type theory, where the property holds without needing an axiom.[24]
  • "Law of Excluded Middle" is often added to satisfy users who wantclassical logic, instead of intuitionistic logic.

TheAxiom 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 theconstructive 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. (SeeAxiom of choice § In constructive mathematics.)

List of type theories

[edit]

Major

[edit]

Minor

[edit]

Active research

[edit]

See also

[edit]

Further reading

[edit]

Notes

[edit]
  1. ^See§ Terms and types
  2. ^TheKleene–Rosser paradox "The Inconsistency of Certain Formal Logics" on page 636Annals of Mathematics36 number 3 (July 1935), showed that1=2{\displaystyle 1=2}.[1]
  3. ^InJulia's type system, for example, abstract types have no instances, but can have subtype,[2]: 110  whereas concrete types do not have subtypes but can have instances, for "documentation, optimization, and dispatch".[3]
  4. ^Church demonstrated hislogistic method with his simple theory of types,[5] and explained his method in 1956,[6] pages 47-68.
  5. ^InJulia, for example, a function with no name, but with two parameters in some tuple (x,y) can be denoted by say,(x,y) -> x^5+y, as an anonymous function.[25]

References

[edit]
  1. ^Kleene, S. C. & Rosser, J. B. (1935). "The inconsistency of certain formal logics".Annals of Mathematics.36 (3):630–636.doi:10.2307/1968646.JSTOR 1968646.
  2. ^Balbaert, Ivo (2015)Getting Started With Julia Programming ISBN 978-1-78328-479-5
  3. ^docs.julialang.orgv.1 TypesArchived 2022-03-24 at theWayback Machine
  4. ^Stanford Encyclopedia of Philosophy(rev. Mon Oct 12, 2020) Russell’s ParadoxArchived December 18, 2021, at theWayback Machine 3. Early Responses to the Paradox
  5. ^abcdChurch, Alonzo (1940). "A formulation of the simple theory of types".The Journal of Symbolic Logic.5 (2):56–68.doi:10.2307/2266170.JSTOR 2266170.S2CID 15889861.
  6. ^Alonzo Church (1956)Introduction To Mathematical Logic Vol 1
  7. ^ETCS at thenLab
  8. ^Chatzikyriakidis, Stergios; Luo, Zhaohui (2017-02-07).Modern Perspectives in Type-Theoretical Semantics. Springer.ISBN 978-3-319-50422-3.Archived from the original on 2023-08-10. Retrieved2022-07-29.
  9. ^Winter, Yoad (2016-04-08).Elements of Formal Semantics: An Introduction to the Mathematical Theory of Meaning in Natural Language. Edinburgh University Press.ISBN 978-0-7486-7777-1.Archived from the original on 2023-08-10. Retrieved2022-07-29.
  10. ^Cooper, Robin. "Type theory and semantics in fluxArchived 2022-05-10 at theWayback Machine." Handbook of the Philosophy of Science 14 (2012): 271-323.
  11. ^Barwise, Jon; Cooper, Robin (1981)Generalized quantifiers and natural languageLinguistics and Philosophy4 (2):159--219 (1981)
  12. ^Cooper, Robin (2005). "Records and Record Types in Semantic Theory".Journal of Logic and Computation.15 (2):99–112.doi:10.1093/logcom/exi004.
  13. ^Cooper, Robin (2010).Type theory and semantics in flux.Handbook of the Philosophy of Science. Volume 14: Philosophy of Linguistics. Elsevier.
  14. ^abMartin-Löf, Per (1987-12-01)."Truth of a proposition, evidence of a judgement, validity of a proof".Synthese.73 (3):407–420.doi:10.1007/BF00484985.ISSN 1573-0964.
  15. ^abcdThe Univalent Foundations Program (2013).Homotopy Type Theory: Univalent Foundations of Mathematics. Homotopy Type Theory.
  16. ^Smith, Peter."Types of proof system"(PDF).logicmatters.net.Archived(PDF) from the original on 2022-10-09. Retrieved29 December 2021.
  17. ^abcdefghHenk Barendregt; Wil Dekkers; Richard Statman (20 June 2013).Lambda Calculus with Types. Cambridge University Press. pp. 1–66.ISBN 978-0-521-76614-2.
  18. ^abc"Rules to Martin-Löf's Intuitionistic Type Theory"(PDF).Archived(PDF) from the original on 2021-10-21. Retrieved2022-01-22.
  19. ^"proof by contradiction".nlab.Archived from the original on 13 August 2023. Retrieved29 December 2021.
  20. ^Heineman, George T.; Bessai, Jan; Düdder, Boris; Rehof, Jakob (2016). "A long and winding road towards modular synthesis".Leveraging Applications of Formal Methods, Verification and Validation: Foundational Techniques. ISoLA 2016. Lecture Notes in Computer Science. Vol. 9952. Springer. pp. 303–317.doi:10.1007/978-3-319-47166-2_21.ISBN 978-3-319-47165-5.
  21. ^Barendregt, Henk (1991). "Introduction to generalized type systems".Journal of Functional Programming.1 (2):125–154.doi:10.1017/s0956796800020025.hdl:2066/17240.ISSN 0956-7968.S2CID 44757552.
  22. ^Bell, John L. (2012)."Types, Sets and Categories"(PDF). In Kanamory, Akihiro (ed.).Sets and Extensions in the Twentieth Century. Handbook of the History of Logic. Vol. 6. Elsevier.ISBN 978-0-08-093066-4.Archived(PDF) from the original on 2018-04-17. Retrieved2012-11-03.
  23. ^Sterling, Jonathan; Angiuli, Carlo (2021-06-29). "Normalization for Cubical Type Theory".2021 36th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS). Rome, Italy: IEEE. pp. 1–15.arXiv:2101.11479.doi:10.1109/LICS52264.2021.9470719.ISBN 978-1-6654-4895-6.S2CID 231719089.
  24. ^abCohen, Cyril; Coquand, Thierry; Huber, Simon; Mörtberg, Anders (2016)."Cubical Type Theory: A constructive interpretation of the univalence axiom"(PDF).21st International Conference on Types for Proofs and Programs (TYPES 2015).arXiv:1611.02108.doi:10.4230/LIPIcs.CVIT.2016.23 (inactive 2 July 2025).Archived(PDF) from the original on 2022-10-09.{{cite journal}}: CS1 maint: DOI inactive as of July 2025 (link)
  25. ^ Balbaert,Ivo(2015) Getting Started with Julia
  26. ^abBove, Ana; Dybjer, Peter (2009), Bove, Ana; Barbosa, Luís Soares; Pardo, Alberto; Pinto, Jorge Sousa (eds.),"Dependent Types at Work",Language Engineering and Rigorous Software Development: International LerNet ALFA Summer School 2008, Piriapolis, Uruguay, February 24 - March 1, 2008, Revised Tutorial Lectures, Lecture Notes in Computer Science, Berlin, Heidelberg: Springer, pp. 57–99,doi:10.1007/978-3-642-03153-3_2,ISBN 978-3-642-03153-3, retrieved2024-01-18
  27. ^Barendegt, Henk (April 1991)."Introduction to generalized type systems".Journal of Functional Programming.1 (2):125–154.doi:10.1017/S0956796800020025.hdl:2066/17240 – via Cambridge Core.
  28. ^Milewski, Bartosz."Programming with Math (Exploring Type Theory)".YouTube.Archived from the original on 2022-01-22. Retrieved2022-01-22.
  29. ^"Axioms and Computation".Theorem Proving in Lean.Archived from the original on 22 December 2021. Retrieved21 January 2022.
  30. ^"Axiom K".nLab.Archived from the original on 2022-01-19. Retrieved2022-01-21.

External links

[edit]

Introductory material

[edit]

Advanced material

[edit]
Note: This template roughly follows the 2012ACM Computing Classification System.
Hardware
Computer systems organization
Networks
Software organization
Software notations andtools
Software development
Theory of computation
Algorithms
Mathematics ofcomputing
Information systems
Security
Human–centered computing
Concurrency
Artificial intelligence
Machine learning
Graphics
Applied computing
General
Theorems (list)
 and paradoxes
Logics
Traditional
Propositional
Predicate
Set theory
Types ofsets
Maps and cardinality
Set theories
Formal systems (list),
language and syntax
Example axiomatic
systems
 (list)
Proof theory
Model theory
Computability theory
Related
Central concepts
Topics
Areas
Phenomena
Formalism
Formal systems
Concepts
See also
Retrieved from "https://en.wikipedia.org/w/index.php?title=Type_theory&oldid=1300149787"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp