请输入您要查询的字词:

 

单词 53Wtypes
释义

5.3 W-types


Inductive types are very general, which is excellent for their usefulness and applicability, but makes them difficult to study as a whole.Fortunately, they can all be formally reduced to a few special cases.It is beyond the scope of this book to discuss this reductionPlanetmathPlanetmath — which is anyway irrelevant to the mathematician using type theoryPlanetmathPlanetmath in practice — but we will take a little time to discuss the one of the basic special cases that we have not yet met.These are Martin-Löf’s W-types, also known as the types of well-founded trees.𝖶-types are a generalizationPlanetmathPlanetmath of such types as natural numbersMathworldPlanetmath, lists, and binary treesMathworldPlanetmath, which are sufficiently general to encapsulate the “recursion” aspect of any inductive type.

A particular 𝖶-type is specified by giving two parameters A:𝒰 and B:A𝒰, in which case the resulting 𝖶-type is written 𝖶(a:A)B(a).The type A represents the type of labels for 𝖶(a:A)B(a), which function as constructors (however, we reserve that word for the actual functions which arise in inductive definitions). For instance, when defining natural numbers as a 𝖶-type,the type A would be the type 𝟐 inhabited by the two elements 0𝟐 and 1𝟐, since there are precisely two ways to obtain a natural number — either it will be zero or a successorMathworldPlanetmathPlanetmathPlanetmath of another natural number.

The type family B:A𝒰 is used to record the arity of labels: a label a:A will take a family of inductive arguments, indexed over B(a). We can therefore think of the “B(a)-many” arguments of a. These arguments are represented by a function f:B(a)𝖶(a:A)B(a), with the understanding that for any b:B(a), f(b) is the “b-th” argument to the label a. The 𝖶-type 𝖶(a:A)B(a) can thus be thought of as the type of well-founded trees, where nodes are labeled by elements of A and each node labeled by a:A has B(a)-many branches.

In the case of natural numbers, the label 0𝟐 has arity 0, since it constructs the constant zero; the label 1𝟐 has arity 1, since it constructs the successor of its argument. We can capture this by using simple elimination on 𝟐 to define a function 𝗋𝖾𝖼𝟐(𝒰,𝟎,𝟏) into a universePlanetmathPlanetmath of types; this function returns the empty type 𝟎 for 0𝟐 and the unit type 𝟏 for 1𝟐. We can thus define

𝐍𝐰:𝖶(b:𝟐)𝗋𝖾𝖼𝟐(𝒰,𝟎,𝟏)

where the superscript 𝐰 serves to distinguish this version of natural numbers from the previously used one.Similarly, we can define the type of lists over A as a 𝖶-type with 𝟏+A many labels: one nullary label for the empty list, plus one unary label for each a:A, corresponding to appending a to the head of a list:

𝖫𝗂𝗌𝗍(A):𝖶(x:𝟏+A)𝗋𝖾𝖼𝟏+A(𝒰, 0,λa. 1).

In general, the 𝖶-type 𝖶(x:A)B(x) specified by A:𝒰 and B:A𝒰 is the inductive type generated by the following constructor:

  • 𝗌𝗎𝗉:(a:A)(B(a)𝖶(x:A)B(x))𝖶(x:A)B(x).

The constructor 𝗌𝗎𝗉 (short for supremum) takes a label a:A and a function f:B(a)𝖶(x:A)B(x) representing the arguments to a, and constructs a new element of 𝖶(x:A)B(x). Using our previous encoding of natural numbers as 𝖶-types, we can for instance define

0𝐰:𝗌𝗎𝗉(0𝟐,λx.𝗋𝖾𝖼𝟎(𝐍𝐰,x)).

Put differently, we use the label 0𝟐 to construct 0𝐰. Then, 𝗋𝖾𝖼𝟐(𝒰,𝟎,𝟏,0𝟐) evaluates to 𝟎, as it should since 0𝟐 is a nullary label. Thus, we need to construct a function f:𝟎𝐍𝐰, which represents the (zero) arguments supplied to 0𝟐. This is of course trivial, using simple elimination on 𝟎 as shown. Similarly, we can define

1𝐰:𝗌𝗎𝗉(1𝟐,λx. 0𝐰)
2𝐰:𝗌𝗎𝗉(1𝟐,λx. 1𝐰)

and so on.

We have the following inductionMathworldPlanetmath principle for 𝖶-types:

  • When proving a statement E:(𝖶(x:A)B(x))𝒰 about all elements of the 𝖶-type 𝖶(x:A)B(x), it suffices to prove it for 𝗌𝗎𝗉(a,f), assuming it holds for all f(b) with b:B(a).In other words, it suffices to give a proof

    e:(a:A)(f:B(a)𝖶(x:A)B(x))(g:(b:B(a))E(f(b)))E(𝗌𝗎𝗉(a,f))

The variable g represents our inductive hypothesis, namely that all arguments of a satisfy E. To state this, we quantify over all elements of type B(a), since each b:B(a) corresponds to one argument f(b) of a.

How would we define the function 𝖽𝗈𝗎𝖻𝗅𝖾 on natural numbers encoded as a 𝖶-type? We would like to use the recursion principle of 𝐍𝐰 with a codomain of 𝐍𝐰 itself. We thus need to construct a suitable function

e:(a:𝟐)(f:B(a)𝐍𝐰)(g:B(a)𝐍𝐰)𝐍𝐰

which will represent the recurrence for the 𝖽𝗈𝗎𝖻𝗅𝖾 function; for simplicity we denote the type family 𝗋𝖾𝖼𝟐(𝒰,𝟎,𝟏) by B.

Clearly, e will be a function taking a:𝟐 as its first argument. The next step is to perform case analysis on a and proceed based on whether it is 0𝟐 or 1𝟐. This suggests the following form

e:λa.𝗋𝖾𝖼𝟐(C,e0,e1,a)

where

C:(f:B(a)𝐍𝐰)(g:B(a)𝐍𝐰)𝐍𝐰

If a is 0𝟐, the type B(a) becomes 𝟎. Thus, given f:𝟎𝐍𝐰 and g:𝟎𝐍𝐰, we want to construct an element of 𝐍𝐰. Since the label 0𝟐 represents 𝟎, it needs zero inductive arguments and the variables f and g are irrelevant. We return 0𝐰 as a result:

e0:λf.λg. 0𝐰

Analogously, if a is 1𝟐, the type B(a) becomes 𝟏.Since the label 1𝟐 represents the successor operator, it needs one inductive argument — the predecessor — which is represented by the variable f:𝟏𝐍𝐰.The value of the recursive call on the predecessor is represented by the variable g:𝟏𝐍𝐰.Thus, taking this value (namely g()) and applying the successor operator twice thus yields the desired result:

e1:λf.λg.𝗌𝗎𝗉(1𝟐,(λx.𝗌𝗎𝗉(1𝟐,(λy.g())))).

Putting this together, we thus have

𝖽𝗈𝗎𝖻𝗅𝖾:𝗋𝖾𝖼𝐍𝐰(𝐍𝐰,e)

with e as defined above.

The associated computation rule for the function 𝗋𝖾𝖼𝖶(x:A)B(x)(E,e):(w:𝖶(x:A)B(x))E(w) is as follows.

  • For any a:A and f:B(a)𝖶(x:A)B(x) we have

    𝗋𝖾𝖼𝖶(x:A)B(x)(E,e,𝗌𝗎𝗉(a,f))e(a,f,(λb.𝗋𝖾𝖼𝖶(x:A)B(x)(E,f(b)))).

In other words, the function 𝗋𝖾𝖼𝖶(x:A)B(x)(E,e) satisfies the recurrence e.

By the above computation rule, the function 𝖽𝗈𝗎𝖻𝗅𝖾 behaves as expected:

𝖽𝗈𝗎𝖻𝗅𝖾(0𝐰)𝗋𝖾𝖼𝐍𝐰(𝐍𝐰,e,𝗌𝗎𝗉(0𝟐,λx.𝗋𝖾𝖼𝟎(𝐍𝐰,x)))
e(0𝟐,(λx.𝗋𝖾𝖼𝟎(𝐍𝐰,x)),(λx.𝖽𝗈𝗎𝖻𝗅𝖾(𝗋𝖾𝖼𝟎(𝐍𝐰,x))))
et((λx.𝗋𝖾𝖼𝟎(𝐍𝐰,x)),(λx.𝖽𝗈𝗎𝖻𝗅𝖾(𝗋𝖾𝖼𝟎(𝐍𝐰,x))))
0𝐰
and
𝖽𝗈𝗎𝖻𝗅𝖾(1𝐰)𝗋𝖾𝖼𝐍𝐰(𝐍𝐰,e,𝗌𝗎𝗉(1𝟐,λx. 0𝐰))
e(1𝟐,(λx. 0𝐰),(λx.𝖽𝗈𝗎𝖻𝗅𝖾(0𝐰)))
ef((λx. 0𝐰),(λx.𝖽𝗈𝗎𝖻𝗅𝖾(0𝐰)))
𝗌𝗎𝗉(1𝟐,(λx.𝗌𝗎𝗉(1𝟐,(λy.𝖽𝗈𝗎𝖻𝗅𝖾(0𝐰)))))
𝗌𝗎𝗉(1𝟐,(λx.𝗌𝗎𝗉(1𝟐,(λy. 0𝐰))))
2𝐰

and so on.

Just as for natural numbers, we can prove a uniqueness theorem for𝖶-types:

Theorem 5.3.1.

Let g,h:(w:W(x:A)B(x))E(w) be two functions which satisfy the recurrence

e:a,f(b:B(a)E(f(b)))E(𝗌𝗎𝗉(a,f)),

i.e., such that

a,fg(𝗌𝗎𝗉(a,f))=e(a,f,λb.g(f(b))),
a,fh(𝗌𝗎𝗉(a,f))=e(a,f,λb.h(f(b))).

Then g and h are equal.

随便看

 

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

 

Copyright © 2000-2023 Newdu.com.com All Rights Reserved
更新时间:2025/5/25 2:46:24