请输入您要查询的字词:

 

单词 14DependentFunctionTypes
释义

1.4 Dependent function types


In type theoryPlanetmathPlanetmath we often use a more general version of functiontypes, called a Π-type or dependent function type. The elements ofa Π-type are functionsMathworldPlanetmathwhose codomain type can vary depending on theelement of the domain to which the function is applied, called dependent functions. The name “Π-type”is used because this type can also be regarded as the cartesianproduct over a given type.

Given a type A:𝒰 and a family B:A𝒰, we may constructthe type of dependent functions (x:A)B(x):𝒰.There are many alternative notationsDlmfDlmfDlmfDlmfDlmf for this type, such as

(x:A)B(x)  (x:A)B(x)  (x:A),B(x).

If B is a constant family, then the dependent product type is the ordinary function type:

(x:A)B(AB).

Indeed, all the constructions of Π-types are generalizationsPlanetmathPlanetmath of the corresponding constructions on ordinary function types.

We can introduce dependent functions by explicit definitions: todefine f:(x:A)B(x), where f is the name of a dependent function to bedefined, we need an expression Φ:B(x) possibly involving the variable x:A,and we write

f(x)܃Φ  for x:A.

Alternatively, we can use λ-abstraction

λx:A:.Φ:(x:A)B(x).(1.4.1)

As with non-dependent functions, we can apply a dependent function f:(x:A)B(x) to an argument a:A to obtain an element f(a):B(a).The equalities are the same as for the ordinary function type, i.e. we have the computation rulegiven a:A we have f(a)Φ and(λx:A:.Φ)(a)Φ, where Φ is obtained by replacing alloccurrences of x in Φ by a (avoiding variable capture, as always).Similarly, we have the uniqueness principle f(λx.f(x)) for any f:(x:A)B(x).

As an example, recall from §1.3 (http://planetmath.org/13universesandfamilies) that there is a type family 𝖥𝗂𝗇:𝒰 whose values are the standard finite setsMathworldPlanetmath, with elements 0n,1n,,(n-1)n:𝖥𝗂𝗇(n).There is then a dependent function 𝖿𝗆𝖺𝗑:(n:)𝖥𝗂𝗇(n+1)which returns the “largest” element of each nonempty finite type, 𝖿𝗆𝖺𝗑(n)܃nn+1.As was the case for 𝖥𝗂𝗇 itself, we cannot define 𝖿𝗆𝖺𝗑 yet, but we will be able to soon; see http://planetmath.org/node/87562Exercise 1.9.

Another important class of dependent function types, which we can define now, are functions which are polymorphicover a given universePlanetmathPlanetmath.A polymorphic function is one which takes a type as one of its arguments, and then acts on elements of that type (or other types constructed from it).An example is the polymorphic identity functionMathworldPlanetmath 𝗂𝖽:(A:𝒰)AA, which we define by 𝗂𝖽܃λ(A:𝒰).x:Ax.

We sometimes write some arguments of a dependent function as subscripts.For instance, we might equivalently define the polymorphic identity function by 𝗂𝖽A(x)܃x.Moreover, if an argument can be inferred from context, we may omit it altogether.For instance, if a:A, then writing 𝗂𝖽(a) is unambiguous, since 𝗂𝖽 must mean 𝗂𝖽A in order for it to be applicable to a.

Another, less trivial, example of a polymorphic function is the “swap” operationMathworldPlanetmath that switches the order of the arguments of a (curried) two-argument function:

𝗌𝗐𝖺𝗉:(A:𝒰)B:𝒰C:𝒰(ABC)(BAC)

We can define this by

𝗌𝗐𝖺𝗉(A,B,C,g)܃λb.ag(a)(b).

We might also equivalently write the type arguments as subscripts:

𝗌𝗐𝖺𝗉A,B,C(g)(b,a)܃g(a,b).

Note that as we did for ordinary functions, we use currying to define dependent functions withseveral arguments (such as 𝗌𝗐𝖺𝗉). However, in the dependent case the second domain maydepend on the first one, and the codomain may depend on both. That is,given A:𝒰 and type families B:A𝒰 and C:(x:A)B(x)𝒰, we may constructthe type (x:A)y:B(x)C(x,y) of functions with twoarguments.(Like λ-abstractions, Πs automatically scope over the rest of the expression unless delimited; thus C:(x:A)B(x)𝒰 means C:(x:A)(B(x)𝒰).)In the case when B is constant and equal to A, we may condense the notation and write (x,y:A); for instance, the type of 𝗌𝗐𝖺𝗉 could also be written as

𝗌𝗐𝖺𝗉:(A,B,C:𝒰)(ABC)(BAC).

Finally, given f:(x:A)y:B(x)C(x,y) and arguments a:A and b:B(a), we have f(a)(b):C(a,b), which,as before, we write as f(a,b):C(a,b).

随便看

 

数学辞典收录了18232条数学词条,基本涵盖了常用数学知识及数学英语单词词组的翻译及用法,是数学学习的有利工具。

 

Copyright © 2000-2023 Newdu.com.com All Rights Reserved
更新时间:2025/5/4 22:24:27