function type (changes) in nLab
Showing changes from revision #36 to #37: Added | Removed | Changed
Context
Type theory
natural deduction metalanguage, practical foundations
type theory (dependent, intensional, observational type theory, homotopy type theory)
computational trinitarianism = \linebreak propositions as types +programs as proofs +relation type theory/category theory
Mapping space
Contents
Idea
In type theory a function type X→YX \to Y for two types X,YX,Y is the type of functions from XX to YY.
In a model of the type theory in categorical semantics, this is an exponential object. In set theory, it is a function set. In dependent type theory, it is a special case of a dependent product type.
Function types are important because they allow the user to quantify over functions in type theory. In material set theory functions are sets and one could quantify over sets, while in structural set theory, while functions are different from sets, one could still quantify over the sort of functions. However, in type theory, one cannot quantify over families of elements x:A⊢b(x):Bx:A \vdash b(x):B, which are the analogue of functions in material and structural set theory, since families of elements are not elements of a single type, and quantification only occurs over a single type. Instead, one uses function types whose elements, called functions, represent families of elements, in the same way that the elements of type universes represent types.
Overview
type theory | category theory | |
---|---|---|
syntax | semantics | |
natural deduction | universal construction | |
function type | internal hom | |
type formation | ⊢X:Type⊢A:Type⊢(X→A):Type\frac{\vdash\: X \colon Type \;\;\;\;\; \vdash\; A\colon Type}{\vdash \; \left(X \to A\right) \colon Type} | |
term introduction | x:X⊢a(x):A⊢(x↦a(x)):(X→A)\frac{x \colon X \;\vdash\; a(x) \colon A}{\vdash (x \mapsto a\left(x\right)) \colon \left(X \to A\right) } | |
term elimination | ⊢f:(X→A)⊢x:X⊢f(x):A\frac{\vdash\; f \colon \left(X \to A\right)\;\;\;\; \vdash \; x \colon X}{\;\;\;\vdash\; f(x) \colon A} | |
computation rule | (y↦a(y))(x)=a(x)(y \mapsto a(y))(x) = a(x) |
Definition
Like any type constructor in type theory, a function type is specified by rules saying when we can introduce it as a type, how to construct terms of that type, how to use or “eliminate” terms of that type, and how to compute when we combine the constructors with the eliminators.
The type formation rule to build a function type is easy:
A:TypeB:TypeA→B:Type\frac{A\colon Type \qquad B \colon Type}{A\to B\colon Type}
As a negative type
Function types are almost always defined as a negative type. In this presentation, primacy is given to the eliminators. The natural eliminator of a function type says that we can apply it to any input:
f:A→Ba:Af(a):B\frac{f\colon A\to B \qquad a\colon A}{f(a) \colon B}
The constructor is then determined as usual for a negative type: to construct a term of A→BA\to B, we have to specify how it behaves when applied to any input. In other words, we should have a term of type BB containing a free variable of type AA. This yields the usual “λ\lambda-abstraction” constructor:
x:A⊢b:Bλx.b:A→B\frac{x\colon A\vdash b\colon B}{\lambda x.b\colon A\to B}
The ∞-reduction? rule is the obvious one (the ur-example of all β\beta-reductions), saying that when we evaluate a λ\lambda-abstraction, we do it by substituting for the bound variable.
(λx.b)(a)→ βb[a/x](\lambda x.b)(a) \;\to_\beta\; b[a/x]
If we want an ∞-conversion? rule, the natural one says that every function is a λ\lambda-abstraction:
λx.f(x)→ ηf \lambda x.f(x) \;\to_\eta\; f
As a positive type
It is also possible to present function types as a positive type. However, this requires a stronger metatheory, such as a logical framework. We use the same constructor (λ\lambda-abstraction), but now the eliminator says that to define an operation using a function, it suffices to say what to do in the case that that function is a lambda abstraction.
(x:A⊢b:B)⊢c:Cf:A→Bfunsplit(c,f):C\frac{(x\colon A \vdash b\colon B) \vdash c\colon C \qquad f\colon A\to B}{funsplit(c,f)\colon C}
This rule cannot be formulated in the usual presentation of type theory, since it involves a “higher-order judgment”: the context of the term c:Cc\colon C involves a “term of type BB containing a free variable of type AA”. However, it is possible to make sense of it. In dependent type theory, we need additionally to allow CC to depend on A→BA\to B.
The natural β\beta-reduction rule for this eliminator is
funsplit(c,λx.g)→ βc[g/b] funsplit(c, \lambda x.g) \;\to_\beta c[g/b]
and its η\eta-conversion rule looks something like
funsplit(c[λx.b/g],f)→ ηc[f/g]. funsplit(c[\lambda x.b / g], f) \;\to_\eta\; c[f/g].
Here g:A→B⊢c:Cg\colon A\to B \vdash c\colon C is a term containing a free variable of type A→BA\to B. By substituting λx.b\lambda x.b for gg, we obtain a term of type CC which depends on “a term b:Bb\colon B containing a free variable x:Ax\colon A”. We then apply the positive eliminator at f:A→Bf\colon A\to B, and the η\eta-rule says that this can be computed by just substituting ff for gg in cc.
Positive versus negative
As usual, the positive and negative formulations are equivalent in a suitable sense. They have the same constructor, while we can formulate the eliminators in terms of each other:
f(a) ≔funsplit(b[a/x],f) funsplit(c,f) ≔c[f(x)/b] \begin{aligned} f(a) &\coloneqq funsplit(b[a/x], f)\\ funsplit(c, f) &\coloneqq c[f(x)/b] \end{aligned}
The conversion rules also correspond.
In dependent type theory, this definition of funsplitfunsplit only gives us a properly typed dependent eliminator if the negative function type satisfies η\eta-conversion. As usual, if it satisfies propositional eta-conversion then we can transport along that instead—and conversely, the dependent eliminator allows us to prove propositional η\eta-conversion. This is the content of Propositions 3.5, 3.6, and 3.7 in (Garner).
Function types a la Russell and a la Tarski
In dependent type theory, there are two different ways to interpret the term f:A→Bf:A \to B:
-
ff is literally a family of terms in BB indexed by AA
-
ff is a term representation for a family of terms in BB indexed by AA
This situation is similar to how there are two notions of type universe where small types of a universe are interpreted a la Russell, literally as types, or a la Tarski, as a term representation of types. Thus, in analogy to type universes, we can refer to function types a la Russell and function types a la Tarski.
Function types a la Russell and a la Tarski are expressed respectively via the elimination rule of function types:
- given types AA and BB and a term f:A→Bf:A \to B, one could form the family of terms x:A⊢f(x):Bx:A \vdash f(x):B
Γ⊢AtypeΓ⊢BtypeΓ⊢f:A→BΓ,x:A⊢f(x):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma \vdash f:A \to B}{\Gamma, x:A \vdash f(x):B}
- given types AA and BB, one could form the family of terms f:A→B,x:A⊢eval(f,x):Bf:A \to B, x:A \vdash \mathrm{eval}(f, x):B
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A⊢eval(f,x):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A \vdash \mathrm{eval}(f, x):B}
Function types a la Tarski corresponds to the notion of exponential object in category theory where the exponential object B AB^A literally comes with a morphism eval:B A×A→B\mathrm{eval}:B^A \times A \to B, but function types a la Russell are the one most commonly used in dependent type theory.
The conversion rules for function types a la Russell are as follows:
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢b(x):BΓ,x:A⊢(λx:A.b(x))(x)≡b(x):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash b(x):B}{\Gamma, x:A \vdash (\lambda x:A.b(x))(x) \equiv b(x):B}
Γ⊢AtypeΓ⊢BtypeΓ⊢f:A→BΓ⊢f≡λx:A.f(x):A→B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma \vdash f:A \to B}{\Gamma \vdash f \equiv \lambda x:A.f(x):A \to B}
and the conversion rules for function types a la Tarski are as follows:
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢b(x):BΓ,x:A⊢eval(λx:A.b(x),x)≡b(x):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash b(x):B}{\Gamma, x:A \vdash \mathrm{eval}(\lambda x:A.b(x), x) \equiv b(x):B}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B⊢f≡λx:A.eval(f,x):A→B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B \vdash f \equiv \lambda x:A.\mathrm{eval}(f, x):A \to B}
For the rest of the article we shall assume the use of function types a la Russell.
Weak and strict function types
In dependent type theory, weak function types are function types for which the computation rules (β\beta-conversion) and uniqueness rules (η\eta-conversion) are propositional rather than judgmental:
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢b(x):BΓ,a:A⊢β A→B x:A.b(x)(a):(λ(x:A).b(x))(a)= Bb(a)\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash b(x):B}{\Gamma, a:A \vdash \beta_{A \to B}^{x:A.b(x)}(a):(\lambda(x:A).b(x))(a) =_{B} b(a)}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B⊢η A→B(f):f= A→Bλ(x:A).f(x)\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B \vdash \eta_{A \to B}(f):f =_{A \to B} \lambda(x:A).f(x)}
Weak function types appear in weak type theories.
This contrasts with strict function types which use judgmental computation and uniqueness rules:
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢b(x):BΓ,a:A⊢(λ(x:A).b(x))(a)≡b(a):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash b(x):B}{\Gamma, a:A \vdash (\lambda(x:A).b(x))(a) \equiv b(a):B}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B⊢f≡λ(x:A).f(x):A→B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B \vdash f \equiv \lambda(x:A).f(x):A \to B}
Strict function types appear in most dependent type theories such as Martin-Löf type theory, observational type theory, and cubical type theory.
For strict function types, the judgmental computation and uniqueness rules automatically imply the propositional computation and uniqueness rules, as by the rules for judgmental equality and identity types, judgmental equality of two terms always implies propositional equality of the two terms.
As types of anafunctions
In dependent type theory, in the same way that one could define equivalence types as types of one-to-one correspondences, one could also define function types as types of anafunctions. This requires both identity types and heterogeneous identity types being defined first, which we shall write as a= Aba =_A b and x= B pyx =_{B}^{p} y respectively for a:Aa:A, b:Ab:A, p:a= Abp:a =_A b, x:B(a)x:B(a), and y:B(b)y:B(b).
Rules for function types
Γ⊢AtypeΓ⊢BtypeΓ⊢A→BtypeΓ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A,y:B⊢ℱ A,B(f,x,y)type\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma \vdash A \to B \; \mathrm{type}} \qquad \frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A, y:B \vdash \mathcal{F}_{A, B}(f, x, y) \; \mathrm{type}}
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢f(x):BΓ⊢x↦f(x):A→B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash f(x):B}{\Gamma \vdash x \mapsto f(x):A \to B}
Γ⊢AtypeΓ⊢BtypeΓ,x:A⊢f(x):BΓ,x:A⊢α(x):ℱ A,B(x↦f(x),x,f(x))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A \vdash f(x):B}{\Gamma, x:A \vdash \alpha(x):\mathcal{F}_{A, B}(x \mapsto f(x), x, f(x))}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A⊢ev(f,x):B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A \vdash \mathrm{ev}(f, x):B}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A⊢β(f,x):ℱ A,B(f,x,ev(f,x))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A \vdash \beta(f, x):\mathcal{F}_{A, B}(f, x, \mathrm{ev}(f, x))}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A,y:B,u:ℱ A,B(f,x,y)⊢κ(f,x,y,u):ev(f,x)= By\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A, y:B, u:\mathcal{F}_{A, B}(f, x, y) \vdash \kappa(f, x, y, u):\mathrm{ev}(f, x) =_B y}
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B,x:A,y:B,u:ℱ A,B(f,x,y)⊢η(f,x,y,u):β(f,x)= ℱ A,B(f,x) κ(f,x,y,u)u\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B, x:A, y:B, u:\mathcal{F}_{A, B}(f, x, y) \vdash \eta(f, x, y, u):\beta(f, x) =_{\mathcal{F}_{A, B}(f, x)}^{\kappa(f, x, y, u)} u}
By the rules for dependent sum types and dependent product types, one could derive that
Γ⊢AtypeΓ⊢BtypeΓ,f:A→B⊢η(f):∏ x:AisContr(∑ y:Bℱ A,B(f,x,y))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma, f:A \to B \vdash \eta(f):\prod_{x:A} \mathrm{isContr}\left(\sum_{y:B} \mathcal{F}_{A, B}(f, x, y) \right)}
which is precisely the statement that ℱ A,B(f)\mathcal{F}_{A, B}(f) is an anafunction for all functions f:A→Bf:A \to B.
Properties
Relation to dependent product types
In dependent type theory a function type A→BA \to B is the special case the dependent product type over a:Aa : A for the special case that BB is regarded as an AA-dependent type x:A⊢Bx:A \vdash B that actually happens to be AA-independent; this type family x:A⊢Bx:A \vdash B can always be constructed by the weakening rule of dependent type theory, which is an admissible rule.
(X→A)=∏ x:XA. (X \to A) = \prod_{x \colon X} A \,.
In categorical semantics this is the statement that a section of a product projection A×B→AA \times B \to A is equivalently just a morphism A→BA \to B.
See also at function monad.
Typal congruence rules and uniqueness rules
The typal computation rule for function types is provable from the other four typal type formers of function types. Given types AA and BB and function f:A→Bf:A \to B, we have, by the elimination rule and the introduction rule, a function λx:A.f(x):A→B\lambda x:A.f(x):A \to B, which by the uniqueness rules of dependent product types are equal to each other
η A→B(f):f= A→Bλx:A.f(x)\eta_{A \to B}(f):f =_{A \to B} \lambda x:A.f(x)
By the inductively defined function idtohomotopy\mathrm{idtohomotopy} which takes identifications between functions to homotopies between functions]], we have that
idtohomotopy(f,λx:A.f(x))(η A→B(f)):∏ x:Af(x)= A→B(λx:A.f(x))(x)\mathrm{idtohomotopy}(f, \lambda x:A.f(x))(\eta_{A \to B}(f)):\prod_{x:A} f(x) =_{A \to B} (\lambda x:A.f(x))(x)
which is the typal computation rule for function types.
Function types as hom-objects
Function types play the role of hom-objects in a kind of enriched category whose objects are the types. (In fact, in the presence of compatible product types this is a cartesian closed category-structure, cf. Lambek & Scott 1986). They have identity functions and a composition-operation which together satisfy the associativity and unitality laws:
-
For strict function types, the associative and unital laws are represented by judgmental equality
-
For weak function types, the associative and unital laws are represented by associator and unitor homotopies, and, assuming function extensionality, also by associator and unitor identifications. In addition, there is also an infinite tower of coherence laws representing the $(\infty,1)$-categorical structure of function types by constructing the pentagonator and so forth, but this isn’t demonstrated in this section, and is unnecessary in the presence of a set truncation axiom like UIP or axiom K.
Strict function types
\begin{definition} Given a type AA, we define the identity function on AA as the function
id A≡λ(x:A).x:A→A\mathrm{id}_A \equiv \lambda (x:A).x:A \to A
\end{definition}
\begin{theorem} By the computation rules for strict function types, the identity function on a type AA comes with a family of judgmental equalities
x:A⊢id A(x)≡x:Ax:A \vdash \mathrm{id}_A(x) \equiv x:A
\end{theorem}
\begin{definition} Given types AA, BB, and CC and functions f:A→Bf:A \to B, and g:B→Cg:B \to C, function composition of ff and gg is defined as
g∘ A,B,Cf≡λ(x:A).g(f(x)):A→Cg \circ_{A, B, C} f \equiv \lambda (x:A).g(f(x)):A \to C
\end{definition}
\begin{theorem} By the computation rules for strict function types, function composition comes with a family of judgmental equalities
x:A⊢(g∘ A,B,Cf)(x)≡g(f(x)):Cx:A \vdash (g \circ_{A, B, C} f)(x) \equiv g(f(x)):C
\end{theorem}
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, there is a family of judgmental equalities
x:A⊢(id B∘ A,B,Bf)(x)≡f(x):Bx:A \vdash (\mathrm{id}_B \circ_{A, B, B} f)(x) \equiv f(x):B
\end{theorem}
\begin{proof} By the computation rule for strict function types, there is a family of judgmental equalities
x:A⊢(id B∘ A,B,Bf)(x)≡id B(f(x)):Bx:A \vdash (\mathrm{id}_B \circ_{A, B, B} f)(x) \equiv \mathrm{id}_B(f(x)):B
and a family of judgmental equalities
x:A⊢id B(f(x))≡f(x):Bx:A \vdash \mathrm{id}_B(f(x)) \equiv f(x):B
Now, by the structural rules for judgmental equality, there is a family of judgmental equalities
x:A⊢(id B∘ A,B,Bf)(x)≡f(x):Bx:A \vdash (\mathrm{id}_B \circ_{A, B, B} f)(x) \equiv f(x):B
\end{proof}
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, there is a family of judgmental equalities
x:A⊢(f∘ A,A,Bid A)(x)≡f(x):Bx:A \vdash (f \circ_{A, A, B} \mathrm{id}_A)(x) \equiv f(x):B
\end{theorem}
\begin{proof} By the computation rule for strict function types, there is a family of judgmental equalities
x:A⊢(f∘ A,A,Bid A)(x)≡f(id A(x)):Bx:A \vdash (f \circ_{A, A, B} \mathrm{id}_A)(x) \equiv f(\mathrm{id}_A(x)):B
and a family of identifications
x:A⊢f(id A(x))≡f(x):Bx:A \vdash f(\mathrm{id}_A(x)) \equiv f(x):B
Now, by the structural rules for judgmental equality, there is a family of judgmental equalities
x:A⊢(f∘ A,A,Bid A)(x)≡f(x):Bx:A \vdash (f \circ_{A, A, B} \mathrm{id}_A)(x) \equiv f(x):B
\end{proof}
\begin{theorem} For all types AA, BB, CC, and DD, and functions f:A→Bf:A \to B, g:B→Cg:B \to C, and h:C→Dh:C \to D, there is a family of judgmental equalities
x:A⊢(h∘ A,C,D(g∘ A,B,Cf))(x)≡((h∘ B,C,Dg)∘ A,B,Df)(x):Dx:A \vdash (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) \equiv ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x):D
\end{theorem}
\begin{proof} By the computation rule for strict function types, there are families of judgmental equalities
x:A⊢(h∘ A,C,D(g∘ A,B,Cf))(x)≡h((g∘ A,B,Cf)(x)):Dx:A \vdash (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) \equiv h((g \circ_{A, B, C} f)(x)):D
x:A⊢((h∘ B,C,Dg)∘ A,B,Df)(x)≡(h∘ B,C,Dg)(f(x)):Dx:A \vdash ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x) \equiv (h \circ_{B, C, D} g)(f(x)):D
x:A⊢(h∘ B,C,Dg)(f(x))≡h(g(f(x))):Dx:A \vdash (h \circ_{B, C, D} g)(f(x)) \equiv h(g(f(x))):D
x:A⊢h((g∘ A,B,Cf)(x))≡h(g(f(x)):Dx:A \vdash h((g \circ_{A, B, C} f)(x)) \equiv h(g(f(x)):D
Now, by the structural rules for judgmental equality, there is a family of judgmental equalities
x:A⊢(h∘ A,C,D(g∘ A,B,Cf))(x)≡((h∘ B,C,Dg)∘ A,B,Df)(x):Dx:A \vdash (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) \equiv ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x):D
\end{proof}
Now, the judgmental uniqueness rule for strict function types implies function extensionality for judgmental equality: for types AA and BB and functions f:A→Bf:A \to B and g:A→Bg:A \to B such that there is a family of judgmental equalities x:A⊢f(x)≡g(x):Bx:A \vdash f(x) \equiv g(x):B, there is a judgmental equality f≡g:A→Bf \equiv g:A \to B. (See exercise 2.1 of Rijke 2022)
As a result, the associative and unital laws hold for functions:
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, there is a judgmental equality
id B∘ A,B,Bf≡f:A→B\mathrm{id}_B \circ_{A, B, B} f \equiv f:A \to B
\end{theorem}
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, there is a judgmental equality
f∘ A,A,Bid A≡f:A→Bf \circ_{A, A, B} \mathrm{id}_A \equiv f:A \to B
\end{theorem}
\begin{theorem} For all types AA, BB, CC, and DD, and functions f:A→Bf:A \to B, g:B→Cg:B \to C, and h:C→Dh:C \to D, there is a judgmental equality
(h∘ A,C,D(g∘ A,B,Cf))≡((h∘ B,C,Dg)∘ A,B,Df):A→D(h \circ_{A, C, D} (g \circ_{A, B, C} f)) \equiv ((h \circ_{B, C, D} g) \circ_{A, B, D} f):A \to D
\end{theorem}
Weak function types
\begin{definition} Given a type AA, we define the identity function on AA as the function
id A≡λ(x:A).x:A→A\mathrm{id}_A \equiv \lambda (x:A).x:A \to A
\end{definition}
\begin{theorem} By the computation rules for weak function types, the identity function on a type AA comes with a family of identifications
x:A⊢β A→A x:A.x(x):id A(x)= Axx:A \vdash \beta_{A \to A}^{x:A.x}(x):\mathrm{id}_A(x) =_{A} x
\end{theorem}
\begin{definition} Given types AA, BB, and CC and functions f:A→Bf:A \to B, and g:B→Cg:B \to C, function composition of ff and gg is defined as
g∘ A,B,Cf≡λ(x:A).g(f(x)):A→Cg \circ_{A, B, C} f \equiv \lambda (x:A).g(f(x)):A \to C
\end{definition}
\begin{theorem} By the computation rules for weak function types, function composition comes with a family of identifications
x:A⊢β A→C x:A.g(f(x))(x):(g∘ A,B,Cf)(x)= Cg(f(x))x:A \vdash \beta_{A \to C}^{x:A.g(f(x))}(x):(g \circ_{A, B, C} f)(x) =_{C} g(f(x))
\end{theorem}
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, the dependent function type
∏ x:A(id B∘ A,B,Bf)(x)= Bf(x)\prod_{x:A} (\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} f(x)
has a homotopy. \end{theorem}
\begin{proof} By the computation rule for weak function types, there is a family of identifications
x:A⊢β A→B x:A.id B(f(x))(x):(id B∘ A,B,Bf)(x)= Bid B(f(x))x:A \vdash \beta_{A \to B}^{x:A.\mathrm{id}_B(f(x))}(x):(\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} \mathrm{id}_B(f(x))
and a family of identifications
x:A⊢β B→B x:A.f(x)(x):id B(f(x))= Bf(x)x:A \vdash \beta_{B \to B}^{x:A.f(x)}(x):\mathrm{id}_B(f(x)) =_{B} f(x)
Now, by concatenating the individual identifications together and then using lambda abstraction, we have the homotopy
λ(x:A).β A→B x:A.id B(f(x))(x)•β B→B x:A.f(x)(x):∏ x:A(id B∘ A,B,Bf)(x)= Bf(x)\lambda (x:A).\beta_{A \to B}^{x:A.\mathrm{id}_B(f(x))}(x) \bullet \beta_{B \to B}^{x:A.f(x)}(x):\prod_{x:A} (\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} f(x)
\end{proof}
\begin{definition} For types AA and BB and function f:A→Bf:A \to B, we define the left unitor homotopy as the homotopy
lunith A,B(f)≡λ(x:A).β A→B x:A.id B(f(x))(x)•β B→B x:A.f(x)(x):∏ x:A(id B∘ A,B,Bf)(x)= Bf(x)\mathrm{lunith}_{A, B}(f) \equiv \lambda (x:A).\beta_{A \to B}^{x:A.\mathrm{id}_B(f(x))}(x) \bullet \beta_{B \to B}^{x:A.f(x)}(x):\prod_{x:A} (\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} f(x)
\end{definition}
\begin{theorem} For all types AA and BB and functions f:A→Bf:A \to B, the dependent function type
∏ x:A(f∘ A,A,Bid A)(x)= Bf(x)\prod_{x:A} (f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(x)
has a homotopy. \end{theorem}
\begin{proof} By the computation rule for weak function types, there is a family of identifications
x:A⊢β A→B x:A.f(id A(x))(x):(f∘ A,A,Bid A)(x)= Bf(id A(x))x:A \vdash \beta_{A \to B}^{x:A.f(\mathrm{id}_A(x))}(x):(f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(\mathrm{id}_A(x))
and also by the action on identifications of the function f:A→Bf:A \to B, a family of identifications
x:A⊢ap B(f,id A(x),x,β A→A x:A.x(x)):f(id A(x))= Bf(x)x:A \vdash \mathrm{ap}_B(f, \mathrm{id}_A(x), x, \beta_{A \to A}^{x:A.x}(x)):f(\mathrm{id}_A(x)) =_{B} f(x)
Now, by concatenating the individual identifications together and then using lambda abstraction, we have the homotopy
λ(x:A).β A→B x:A.f(id A(x))(x)•ap B(f,id A(x),x,β A→A x:A.x(x)):∏ x:A(f∘ A,A,Bid A)(x)= Bf(x)\lambda (x:A).\beta_{A \to B}^{x:A.f(\mathrm{id}_A(x))}(x) \bullet \mathrm{ap}_B(f, \mathrm{id}_A(x), x, \beta_{A \to A}^{x:A.x}(x)):\prod_{x:A} (f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(x)
\end{proof}
\begin{definition} For types AA and BB and function f:A→Bf:A \to B, we define the right unitor homotopy as the homotopy
runith A,B(f)≡λ(x:A).β A→B x:A.f(id A(x))(x)•ap B(f,id A(x),x,β A→A x:A.x(x)):∏ x:A(f∘ A,A,Bid A)(x)= Bf(x)\mathrm{runith}_{A, B}(f) \equiv \lambda (x:A).\beta_{A \to B}^{x:A.f(\mathrm{id}_A(x))}(x) \bullet \mathrm{ap}_B(f, \mathrm{id}_A(x), x, \beta_{A \to A}^{x:A.x}(x)):\prod_{x:A} (f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(x)
\end{definition}
\begin{theorem} For all types AA, BB, CC, and DD, and functions f:A→Bf:A \to B, g:B→Cg:B \to C, and h:C→Dh:C \to D, the dependent function type
∏ x:A(h∘ A,C,D(g∘ A,B,Cf))(x)= D((h∘ B,C,Dg)∘ A,B,Df)(x)\prod_{x:A} (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x)
has a homotopy. \end{theorem}
\begin{proof} By the computation rule for weak function types, there are families of identifications
x:A⊢β A→D x:A.h((g∘ A,B,Cf)(x))(x):(h∘ A,C,D(g∘ A,B,Cf))(x)= Dh((g∘ A,B,Cf)(x))x:A \vdash \beta_{A \to D}^{x:A.h((g \circ_{A, B, C} f)(x))}(x):(h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} h((g \circ_{A, B, C} f)(x))
x:A⊢β A→D x:A.(h∘ B,C,Dg)(f(x))(x):((h∘ B,C,Dg)∘ A,B,Df)(x)= D(h∘ B,C,Dg)(f(x))x:A \vdash \beta_{A \to D}^{x:A.(h \circ_{B, C, D} g)(f(x))}(x):((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x) =_{D} (h \circ_{B, C, D} g)(f(x))
x:A⊢β A→D x:A.h(g(f(x)))(x):(h∘ B,C,Dg)(f(x))= Dh(g(f(x)))x:A \vdash \beta_{A \to D}^{x:A.h(g(f(x)))}(x):(h \circ_{B, C, D} g)(f(x)) =_{D} h(g(f(x)))
and also by the action on identifications of the function h:C→Dh:C \to D, there is a family of identifications
x:A⊢ap D(h,(g∘ A,B,Cf)(x),g(f(x)),β A→C x:A.g(f(x))(x)):h((g∘ A,B,Cf)(x))= Dh(g(f(x))x:A \vdash \mathrm{ap}_D(h, (g \circ_{A, B, C} f)(x), g(f(x)), \beta_{A \to C}^{x:A.g(f(x))}(x)):h((g \circ_{A, B, C} f)(x)) =_{D} h(g(f(x))
Now, by concatenating and inverting the individual identifications together and then using lambda abstraction, we have the homotopy
λ(x:A).β A→D x:A.h((g∘ A,B,Cf)(x))(x)•ap D(h,(g∘ A,B,Cf)(x),g(f(x)),β A→C x:A.g(f(x))(x)) •β A→D x:A.h(g(f(x)))(x) −1•β A→D x:A.(h∘ B,C,Dg)(f(x))(x) −1:∏ x:A(h∘ A,C,D(g∘ A,B,Cf))(x)= D((h∘ B,C,Dg)∘ A,B,Df)(x)\begin{array}{c} \lambda (x:A).\beta_{A \to D}^{x:A.h((g \circ_{A, B, C} f)(x))}(x) \bullet \mathrm{ap}_D(h, (g \circ_{A, B, C} f)(x), g(f(x)), \beta_{A \to C}^{x:A.g(f(x))}(x)) \\ \bullet \beta_{A \to D}^{x:A.h(g(f(x)))}(x)^{-1} \bullet \beta_{A \to D}^{x:A.(h \circ_{B, C, D} g)(f(x))}(x)^{-1}:\prod_{x:A} (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x) \end{array}
\end{proof}
\begin{definition} For types AA, BB, CC, and DD and functions f:A→Bf:A \to B, f:B→Cf:B \to C, and h:C→Dh:C \to D, we define the associator homotopy as the homotopy
assoch A,B,C,D(f,g,h)≡λ(x:A).β A→D x:A.h((g∘ A,B,Cf)(x))(x)•ap D(h,(g∘ A,B,Cf)(x),g(f(x)),β A→C x:A.g(f(x))(x)) •β A→D x:A.h(g(f(x)))(x) −1•β A→D x:A.(h∘ B,C,Dg)(f(x))(x) −1:∏ x:A(h∘ A,C,D(g∘ A,B,Cf))(x)= D((h∘ B,C,Dg)∘ A,B,Df)(x)\begin{array}{c} \mathrm{assoch}_{A, B, C, D}(f, g, h) \equiv \lambda (x:A).\beta_{A \to D}^{x:A.h((g \circ_{A, B, C} f)(x))}(x) \bullet \mathrm{ap}_D(h, (g \circ_{A, B, C} f)(x), g(f(x)), \beta_{A \to C}^{x:A.g(f(x))}(x)) \\ \bullet \beta_{A \to D}^{x:A.h(g(f(x)))}(x)^{-1} \bullet \beta_{A \to D}^{x:A.(h \circ_{B, C, D} g)(f(x))}(x)^{-1}:\prod_{x:A} (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x) \end{array}
\end{definition}
Now, recall that the canonical idtohomotopy\mathrm{idtohomotopy} function
idtohomotopy A,B(f,g):f= A→Bg→∏ x:Af(x)= Bg(x)\mathrm{idtohomotopy}_{A, B}(f, g):f =_{A \to B} g \to \prod_{x:A} f(x) =_{B} g(x)
is inductively defined by
idtohomotopy A,B(f,f)(refl A→B(f))≡λ(x:A).refl B(f(x)):∏ x:Af(x)= Bg(x)\mathrm{idtohomotopy}_{A, B}(f, f)(\mathrm{refl}_{A \to B}(f)) \equiv \lambda (x:A).\mathrm{refl}_{B}(f(x)):\prod_{x:A} f(x) =_{B} g(x)
function extensionality states that idtohomotopy A,B(f,g)\mathrm{idtohomotopy}_{A, B}(f, g) is an equivalence of types for all functions f:A→Bf:A \to B and g:A→Bg:A \to B
funext A,B:∏ f:A→B∏ g:A→BisEquiv(idtohomotopy A,B(f,g))\mathrm{funext}_{A, B}:\prod_{f:A \to B} \prod_{g:A \to B} \mathrm{isEquiv}(\mathrm{idtohomotopy}_{A, B}(f, g))
Thus, there is an inverse function
idtohomotopy A,B(f,g) −1:(∏ x:AId B(f(x),g(x)))→f= A→Bg\mathrm{idtohomotopy}_{A, B}(f, g)^{-1}:\left(\prod_{x:A} \mathrm{Id}_{B}(f(x), g(x))\right) \to f =_{A \to B} g
With function extensionality, we can now prove the associative and unital laws, showing that function are a category:
\begin{theorem} Assuming function extensionality, for all types AA and BB and functions f:A→Bf:A \to B, the identity type
id B∘ A,B,Bf= A→Bf\mathrm{id}_B \circ_{A, B, B} f =_{A \to B} f
has an identification. \end{theorem}
\begin{proof} By function extensionality, the function
idtohomotopy A,B(id B∘ A,B,Bf,f):(id B∘ A,B,Bf= A→Bf)→∏ x:A(id B∘ A,B,Bf)(x)= Bf(x)\mathrm{idtohomotopy}_{A, B}(\mathrm{id}_B \circ_{A, B, B} f, f):(\mathrm{id}_B \circ_{A, B, B} f =_{A \to B} f) \to \prod_{x:A} (\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} f(x)
has an inverse function
idtohomotopy A,B(id B∘ A,B,Bf,f) −1:(∏ x:A(id B∘ A,B,Bf)(x)= Bf(x))→(id B∘ A,B,Bf= A→Bf)\mathrm{idtohomotopy}_{A, B}(\mathrm{id}_B \circ_{A, B, B} f, f)^{-1}:\left(\prod_{x:A} (\mathrm{id}_B \circ_{A, B, B} f)(x) =_{B} f(x)\right) \to (\mathrm{id}_B \circ_{A, B, B} f =_{A \to B} f)
One then gets the identification
idtohomotopy A,B(id B∘ A,B,Bf,f) −1(lunith A,B(f)):id B∘ A,B,Bf= A→Bf\mathrm{idtohomotopy}_{A, B}(\mathrm{id}_B \circ_{A, B, B} f, f)^{-1}(\mathrm{lunith}_{A, B}(f)):\mathrm{id}_B \circ_{A, B, B} f =_{A \to B} f
\end{proof}
\begin{definition} For types AA and BB and function f:A→Bf:A \to B, we define the left unitor as the identification
lunit A,B(f)≡idtohomotopy A,B(id B∘ A,B,Bf,f) −1(lunith A,B(f)):id B∘ A,B,Bf= A→Bf\mathrm{lunit}_{A, B}(f) \equiv \mathrm{idtohomotopy}_{A, B}(\mathrm{id}_B \circ_{A, B, B} f, f)^{-1}(\mathrm{lunith}_{A, B}(f)):\mathrm{id}_B \circ_{A, B, B} f =_{A \to B} f
\end{definition}
\begin{theorem} Assuming function extensionality, for all types AA and BB and functions f:A→Bf:A \to B, the identity type
f∘ A,A,Bid A= A→Bff \circ_{A, A, B} \mathrm{id}_A =_{A \to B} f
has an identification. \end{theorem}
\begin{proof} By function extensionality, the function
idtohomotopy A,B(f∘ A,A,Bid A,f):(f∘ A,A,Bid A= A→Bf)→∏ x:A(f∘ A,A,Bid A)(x)= Bf(x)\mathrm{idtohomotopy}_{A, B}(f \circ_{A, A, B} \mathrm{id}_A, f):(f \circ_{A, A, B} \mathrm{id}_A =_{A \to B} f) \to \prod_{x:A} (f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(x)
has an inverse function
idtohomotopy A,B(f∘ A,A,Bid A,f) −1:(∏ x:A(f∘ A,A,Bid A)(x)= Bf(x))→(f∘ A,A,Bid A= A→Bf)\mathrm{idtohomotopy}_{A, B}(f \circ_{A, A, B} \mathrm{id}_A, f)^{-1}:\left(\prod_{x:A} (f \circ_{A, A, B} \mathrm{id}_A)(x) =_{B} f(x)\right) \to (f \circ_{A, A, B} \mathrm{id}_A =_{A \to B} f)
One then gets the identification
idtohomotopy A,B(f∘ A,A,Bid A,f) −1(runith A,B(f)):f∘ A,A,Bid A= A→Bf\mathrm{idtohomotopy}_{A, B}(f \circ_{A, A, B} \mathrm{id}_A, f)^{-1}(\mathrm{runith}_{A, B}(f)):f \circ_{A, A, B} \mathrm{id}_A =_{A \to B} f
\end{proof}
\begin{definition} For types AA and BB and function f:A→Bf:A \to B, we define the right unitor as the identification
runit A,B(f)≡idtohomotopy A,B(f∘ A,A,Bid A,f) −1(runith A,B(f)):f∘ A,A,Bid A= A→Bf\mathrm{runit}_{A, B}(f) \equiv \mathrm{idtohomotopy}_{A, B}(f \circ_{A, A, B} \mathrm{id}_A, f)^{-1}(\mathrm{runith}_{A, B}(f)):f \circ_{A, A, B} \mathrm{id}_A =_{A \to B} f
\end{definition}
\begin{theorem} Assuming function extensionality, for all types AA, BB, CC, and DD and functions f:A→Bf:A \to B, f:B→Cf:B \to C, and h:C→Dh:C \to D, the identity type
h∘ A,C,D(g∘ A,B,Cf)= A→D(h∘ B,C,Dg)∘ A,B,Dfh \circ_{A, C, D} (g \circ_{A, B, C} f) =_{A \to D} (h \circ_{B, C, D} g) \circ_{A, B, D} f
has an identification. \end{theorem}
\begin{proof} By function extensionality, the function
idtohomotopy A,D(h∘ A,C,D(g∘ A,B,Cf),(h∘ B,C,Dg)∘ A,B,Df): (h∘ A,C,D(g∘ A,B,Cf)= A→D(h∘ B,C,Dg)∘ A,B,Df) →∏ x:A(h∘ A,C,D(g∘ A,B,Cf))(x)= D((h∘ B,C,Dg)∘ A,B,Df)(x) \begin{array}{c} \mathrm{idtohomotopy}_{A, D}(h \circ_{A, C, D} (g \circ_{A, B, C} f), (h \circ_{B, C, D} g) \circ_{A, B, D} f): \\ (h \circ_{A, C, D} (g \circ_{A, B, C} f) =_{A \to D} (h \circ_{B, C, D} g) \circ_{A, B, D} f) \\ \to \prod_{x:A} (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x) \end{array}
has an inverse function
idtohomotopy A,D(h∘ A,C,D(g∘ A,B,Cf),(h∘ B,C,Dg)∘ A,B,Df) −1: (∏ x:A(h∘ A,C,D(g∘ A,B,Cf))(x)= D((h∘ B,C,Dg)∘ A,B,Df)(x)) →(h∘ A,C,D(g∘ A,B,Cf)= A→D(h∘ B,C,Dg)∘ A,B,Df) \begin{array}{c} \mathrm{idtohomotopy}_{A, D}(h \circ_{A, C, D} (g \circ_{A, B, C} f), (h \circ_{B, C, D} g) \circ_{A, B, D} f)^{-1}: \\ \left(\prod_{x:A} (h \circ_{A, C, D} (g \circ_{A, B, C} f))(x) =_{D} ((h \circ_{B, C, D} g) \circ_{A, B, D} f)(x)\right) \\ \to (h \circ_{A, C, D} (g \circ_{A, B, C} f) =_{A \to D} (h \circ_{B, C, D} g) \circ_{A, B, D} f) \end{array}
One then gets the identification
idtohomotopy A,D(h∘ A,C,D(g∘ A,B,Cf),(h∘ B,C,Dg)∘ A,B,Df) −1(assoch A,B,C,D(f,g,h)): h∘ A,C,D(g∘ A,B,Cf)= A→D(h∘ B,C,Dg)∘ A,B,Df \begin{array}{c} \mathrm{idtohomotopy}_{A, D}(h \circ_{A, C, D} (g \circ_{A, B, C} f), (h \circ_{B, C, D} g) \circ_{A, B, D} f)^{-1}(\mathrm{assoch}_{A, B, C, D}(f, g, h)):\\ h \circ_{A, C, D} (g \circ_{A, B, C} f) =_{A \to D} (h \circ_{B, C, D} g) \circ_{A, B, D} f \end{array}
\end{proof}
\begin{definition} For types AA, BB, CC, and DD and functions f:A→Bf:A \to B, f:B→Cf:B \to C, and h:C→Dh:C \to D, we define the associator as the identification
assoc A,B,C,D(f,g,h)≡idtohomotopy A,D(h∘ A,C,D(g∘ A,B,Cf),(h∘ B,C,Dg)∘ A,B,Df) −1(assoch A,B,C,D(f,g,h)): h∘ A,C,D(g∘ A,B,Cf)= A→D(h∘ B,C,Dg)∘ A,B,Df \begin{array}{c} \mathrm{assoc}_{A, B, C, D}(f, g, h) \equiv \mathrm{idtohomotopy}_{A, D}(h \circ_{A, C, D} (g \circ_{A, B, C} f), (h \circ_{B, C, D} g) \circ_{A, B, D} f)^{-1}(\mathrm{assoch}_{A, B, C, D}(f, g, h)):\\ h \circ_{A, C, D} (g \circ_{A, B, C} f) =_{A \to D} (h \circ_{B, C, D} g) \circ_{A, B, D} f \end{array}
\end{definition}
Typal congruence rules
These are called typal congruence rules because they are the analogue of the judgmental congruence rules which use identity types and equivalence types instead of judgmental equality.
Strict function types
Since function types are negative types, we first present the typal congruence rule for the elimination rule of function types
\begin{theorem} Given types AA and BB, functions f:A→Bf:A \to B and g:A→Bg:A \to B and an identification p:f= A→Bgp:f =_{A \to B} g there are families of identifications x:A⊢compelim(f,g,p)(x):f(x)= Bg(x)x:A \vdash \mathrm{compelim}(f, g, p)(x):f(x) =_B g(x). \end{theorem}
\begin{proof} We simply define the dependent function compelim\mathrm{compelim} to be the canonical inductively defined function idtohomotopy\mathrm{idtohomotopy} which takes identifications between functions to homotopies between functions. \end{proof}
The next is the typal congruence rule for the introduction rule of function types. However, unlike the case for the other two rules, one needs function extensionality.
\begin{theorem} Assuming function extensionality, given types AA and BB, families of elements x:A⊢b(x):Bx:A \vdash b(x):B and x:A⊢b′(x):Bx:A \vdash b'(x):B, and families of identifications x:A⊢p(x):b(x)= Bb′(x)x:A \vdash p(x):b(x) =_B b'(x), there is an identification
congintro x:A.p(x):λ(x:A).b(x)= A→Bλ(x:A).b′(x)\mathrm{congintro}_{x:A.p(x)}:\lambda (x:A).b(x) =_{A \to B} \lambda (x:A).b'(x)
\end{theorem}
\begin{proof} By the computation rule of strict function types, there are families of judgmental equalities
x:A⊢((λx:A.b(x))(x)≡b(x):Bx:A \vdash ((\lambda x:A.b(x))(x) \equiv b(x):B
x:A⊢((λx:A.b′(x))(x)≡b′(x):Bx:A \vdash ((\lambda x:A.b'(x))(x) \equiv b'(x):B
Thus, by the structural rules of judgmental equality, there are families of identificaitons
x:A⊢p(x):(λx:A.b(x))(x)= B(λx:A.b′(x))(x)x:A \vdash p(x):(\lambda x:A.b(x))(x) =_B (\lambda x:A.b'(x))(x)
and by λ\lambda-abstraction, one gets the dependent function
λ(x:A).p(x):∏ x:A(λx:A.b(x))(x)= B(λx:A.b′(x))(x)\lambda (x:A).p(x):\prod_{x:A} (\lambda x:A.b(x))(x) =_B (\lambda x:A.b'(x))(x)
By function extensionality, there is an equivalence of types
funext:(λx:A.b(x))= A→B(λx:A.b′(x))≃∏ x:AId B((λx:A.b(x))(x),(λx:A.b′(x))(x))\mathrm{funext}:(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x)) \simeq \prod_{x:A} \mathrm{Id}_B((\lambda x:A.b(x))(x), (\lambda x:A.b'(x))(x))
which yields an identification
funext −1(λ(x:A).p(x)):(λx:A.b(x))= A→B(λx:A.b′(x))\mathrm{funext}^{-1}(\lambda (x:A).p(x)):(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x))
We define
congintro x:A.p(x)≔funext −1(λ(x:A).p(x)):(λx:A.b(x))= A→B(λx:A.b′(x))\mathrm{congintro}_{x:A.p(x)} \coloneqq \mathrm{funext}^{-1}(\lambda (x:A).p(x)):(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x))
\end{proof}
Finally, we present the typal congruence rule for the formation rule of function types, which relies upon the previous two results.
\begin{theorem} Given types AA, A′A', BB, B′B' and equivalences e A:A≃A′e_A:A \simeq A' and e B:B≃B′e_B:B \simeq B', there is an equivalence
congform(e A,e B):(A→B)≃(A′→B′)\mathrm{congform}(e_A, e_B):(A \to B) \simeq (A' \to B')
\end{theorem}
\begin{proof} We define the function congform(e A,e B):(A→B)→(A′→B′)\mathrm{congform}(e_A, e_B):(A \to B) \to (A' \to B') by
congform(e A,e B)≔λ(f:A→B).λx:A′.e B(f(e A −1(x)))\mathrm{congform}(e_A, e_B) \coloneqq \lambda (f:A \to B).\lambda x:A'.e_B(f(e_A^{-1}(x)))
and the inverse function by
congform(e A,e B) −1≔λ(g:A′→B′).λx:A.e B −1(g(e A(x)))\mathrm{congform}(e_A, e_B)^{-1} \coloneqq \lambda (g:A' \to B').\lambda x:A.e_B^{-1}(g(e_A(x)))
Now it suffices to construct homotopies
∏ f:A→Bcongform(e A,e B) −1(congform(e A,e B)(f))= A→Bf\prod_{f:A \to B} \mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) =_{A \to B} f
∏ g:A′→B′congform(e A,e B)(congform(e A,e B) −1(g))= A′→B′g\prod_{g:A' \to B'} \mathrm{congform}(e_A, e_B)(\mathrm{congform}(e_A, e_B)^{-1}(g)) =_{A' \to B'} g
from where it implies that congform(e A,e B)\mathrm{congform}(e_A, e_B) has a coherent inverse and contractible fibers and is thus an equivalence of types.
By definition,
congform(e A,e B) −1(congform(e A,e B)(f))≡λx:A.e B −1((λx:A′.e B(f(e A −1(x))))(e A(x)))\mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) \equiv \lambda x:A.e_B^{-1}((\lambda x:A'.e_B(f(e_A^{-1}(x))))(e_A(x)))
By the computation rules of strict function types, there is a family of judgmental equalities
x:A⊢(λx:A′.e B(f(e A −1(x))))(e A(x))≡e B(f(e A −1(e A(x))))x:A \vdash (\lambda x:A'.e_B(f(e_A^{-1}(x))))(e_A(x)) \equiv e_B(f(e_A^{-1}(e_A(x))))
and thus by the structural rules of judgmental equalities and the judgmental congruence rules for function types, a judgmental equality
congform(e A,e B) −1(congform(e A,e B)(f))≡λx:A.e B −1(e B(f(e A −1(e A(x)))))\mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) \equiv \lambda x:A.e_B^{-1}(e_B(f(e_A^{-1}(e_A(x)))))
The equivalence e B:B≃B′e_B:B \simeq B' has a family of identifications
x:B⊢ret e B(x):e B −1(e B(x))= Bxx:B \vdash \mathrm{ret}_{e_B}(x):e_B^{-1}(e_B(x)) =_{B} x
witnessing that e B −1e_B^{-1} is a retraction of e Be_B.
This means that by applying the canonical inductively defined function idtohomotopy\mathrm{idtohomotopy} which takes identifications between functions to homotopies between functions, one gets the family of identifications
idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x))):e B −1(e B(f(e A −1(e A(x)))))= Bf(e A −1(e A(x)))\mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))):e_B^{-1}(e_B(f(e_A^{-1}(e_A(x))))) =_{B} f(e_A^{-1}(e_A(x)))
Similarly, the equivalence e A:A≃A′e_A:A \simeq A' has a family of identifications
x:B⊢ret e A(x):e A −1(e A(x))= Axx:B \vdash \mathrm{ret}_{e_A}(x):e_A^{-1}(e_A(x)) =_{A} x
witnessing that e A −1e_A^{-1} is a retraction of e Ae_A.
This means by applying ff to the above family of identifications, one gets the family of identifications
x:A⊢ap(f,e A −1(e A(x)),x,ret e A(x)):f(e A −1(e A(x)))= Bf(x)x:A \vdash \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x)):f(e_A^{-1}(e_A(x))) =_{B} f(x)
By concatenation of identifications, one gets the family of identifications
x:A⊢idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x)))•ap(f,e A −1(e A(x)),x,ret e A(x)):e B −1(e B(f(e A −1(e A(x)))))= Bf(x)x:A \vdash \mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))) \bullet \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x)):e_B^{-1}(e_B(f(e_A^{-1}(e_A(x))))) =_{B} f(x)
By lambda abstraction, one gets the homotopy
λx:A.idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x)))•ap(f,e A −1(e A(x)),x,ret e A(x)):∏ x:Ae B −1(e B(f(e A −1(e A(x)))))= Bf(x)\lambda x:A.\mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))) \bullet \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x)):\prod_{x:A} e_B^{-1}(e_B(f(e_A^{-1}(e_A(x))))) =_{B} f(x)
and by function extensionality, this is the same as
funext −1(λx:A.idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x)))•ap(f,e A −1(e A(x)),x,ret e A(x))):λ(x:A).e B −1(e B(f(e A −1(e A(x)))))= A→Bλx:A.f(x)\mathrm{funext}^{-1}(\lambda x:A.\mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))) \bullet \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x))):\lambda (x:A).e_B^{-1}(e_B(f(e_A^{-1}(e_A(x))))) =_{A \to B} \lambda x:A.f(x)
By the computation rules of strict function types and the structural rules of judgmental equality, the type
λ(x:A).e B −1(e B(f(e A −1(e A(x)))))= A→Bλx:A.f(x)\lambda (x:A).e_B^{-1}(e_B(f(e_A^{-1}(e_A(x))))) =_{A \to B} \lambda x:A.f(x)
is judgmentally equal to congform(e A,e B) −1(congform(e A,e B)(f))= A→Bf\mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) =_{A \to B} f, so we have
funext −1(λx:A.idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x)))•ap(f,e A −1(e A(x)),x,ret e A(x))):congform(e A,e B) −1(congform(e A,e B)(f))= A→Bf\mathrm{funext}^{-1}(\lambda x:A.\mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))) \bullet \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x))):\mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) =_{A \to B} f
λ\lambda-abstraction on functions f:A→Bf:A \to B leads to the dependent function
λ(f:A→B).funext −1(λx:A.idtohomotopy(λx:A.e B −1(e B(x)),λx:A.x,f(e A −1(e A(x)))•ap(f,e A −1(e A(x)),x,ret e A(x))):∏ f:A→Bcongform(e A,e B) −1(congform(e A,e B)(f))= A→Bf\lambda (f:A \to B).\mathrm{funext}^{-1}(\lambda x:A.\mathrm{idtohomotopy}(\lambda x:A.e_B^{-1}(e_B(x)), \lambda x:A.x, f(e_A^{-1}(e_A(x))) \bullet \mathrm{ap}(f, e_A^{-1}(e_A(x)), x, \mathrm{ret}_{e_A}(x))):\prod_{f:A \to B} \mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) =_{A \to B} f
By a similar argument swapping the types around and the corresponding equivalences with inverse equivalences; one also has
λ(g:A′→B′).funext −1(λx:A′.idtohomotopy(λx:A′.e B(e B −1(x)),λx:A′.x,g(e A(e A −1(x)))•ap(g,e A(e A −1(x)),x,ret e A −1(x))):∏ g:A′→B′congform(e A,e B)(congform(e A,e B) −1(g))= A′→B′g\lambda (g:A' \to B').\mathrm{funext}^{-1}(\lambda x:A'.\mathrm{idtohomotopy}(\lambda x:A'.e_B(e_B^{-1}(x)), \lambda x:A'.x, g(e_A(e_A^{-1}(x))) \bullet \mathrm{ap}(g, e_A(e_A^{-1}(x)), x, \mathrm{ret}_{e_A^{-1}}(x))):\prod_{g:A' \to B'} \mathrm{congform}(e_A, e_B)(\mathrm{congform}(e_A, e_B)^{-1}(g)) =_{A' \to B'} g
Thus, congform(e A,e B):(A→B)→(A′→B′)\mathrm{congform}(e_A, e_B):(A \to B) \to (A' \to B') is an equivalence of types. \end{proof}
Weak function types
\begin{theorem} Given types AA, A′A', BB, B′B' and equivalences e A:A≃A′e_A:A \simeq A' and e B:B≃B′e_B:B \simeq B', there is an equivalence
congform(e A,e B):(A→B)≃(A′→B′)\mathrm{congform}(e_A, e_B):(A \to B) \simeq (A' \to B')
\end{theorem}
\begin{proof} We define the function congform(e A,e B):(A→B)→(A′→B′)\mathrm{congform}(e_A, e_B):(A \to B) \to (A' \to B') by
congform(e A,e B)≔λ(f:A→B).λx:A′.e B(f(e A −1(x)))\mathrm{congform}(e_A, e_B) \coloneqq \lambda (f:A \to B).\lambda x:A'.e_B(f(e_A^{-1}(x)))
and the inverse function by
congform(e A,e B) −1≔λ(g:A′→B′).λx:A.e B −1(g(e A(x)))\mathrm{congform}(e_A, e_B)^{-1} \coloneqq \lambda (g:A' \to B').\lambda x:A.e_B^{-1}(g(e_A(x)))
Now it suffices to construct homotopies
∏ f:A→Bcongform(e A,e B) −1(congform(e A,e B)(f))= A→Bf\prod_{f:A \to B} \mathrm{congform}(e_A, e_B)^{-1}(\mathrm{congform}(e_A, e_B)(f)) =_{A \to B} f
∏ g:A′→B′congform(e A,e B)(congform(e A,e B) −1(g))= A′→B′g\prod_{g:A' \to B'} \mathrm{congform}(e_A, e_B)(\mathrm{congform}(e_A, e_B)^{-1}(g)) =_{A' \to B'} g
from where it implies that congform(e A,e B)\mathrm{congform}(e_A, e_B) has a coherent inverse and contractible fibers and is thus an equivalence of types.
To be finished… \end{proof}
Since function types are negative types, we first present the typal congruence rule for the elimination rule of function types
\begin{theorem} Given types AA and BB, functions f:A→Bf:A \to B and g:A→Bg:A \to B and an identification p:f= A→Bgp:f =_{A \to B} g there are families of identifications x:A⊢compelim(f,g,p)(x):f(x)= Bg(x)x:A \vdash \mathrm{compelim}(f, g, p)(x):f(x) =_B g(x). \end{theorem}
\begin{proof} We simply define the dependent function compelim\mathrm{compelim} to be the canonical inductively defined function idtohomotopy\mathrm{idtohomotopy} which takes identifications between functions to homotopies between functions. \end{proof}
The next is the typal congruence rule for the uniqueness rule of function types.
\begin{theorem} Given types AA and BB, functions f:A→Bf:A \to B and g:A→Bg:A \to B, and an identification p:f= A→Bgp:f =_{A \to B} g, there is an identification
etaCong A→B(f,g,p):transport h:A→B.h= A→Bλx:A.h(x)(f,g,p)(η A→B(f))= g= A→Bλx:A.g(x)η A→B(g)\mathrm{etaCong}_{A \to B}(f, g, p):\mathrm{transport}_{h:A \to B.h =_{A \to B} \lambda x:A.h(x)}(f, g, p)(\eta_{A \to B}(f)) =_{g =_{A \to B} \lambda x:A.g(x)} \eta_{A \to B}(g)
\end{theorem}
\begin{proof} We simply define etaCong A→B(f,g,p)\mathrm{etaCong}_{A \to B}(f, g, p) to be the dependent function application to identifications
apd h:A→B.h= A→Bλx:A.h(x)(λx:A→B.η A→B(x),f,g,p)\mathrm{apd}_{h:A \to B.h =_{A \to B} \lambda x:A.h(x)}(\lambda x:A \to B.\eta_{A \to B}(x), f, g, p)
where
f:A→B⊢η A→B(f):f= A→Bλx:A.f(x)f:A \to B \vdash \eta_{A \to B}(f):f =_{A \to B} \lambda x:A.f(x)
is the family of elements in the conclusion of the uniqueness rule for weak function types. \end{proof}
The next is the typal congruence rule for the introduction rule of function types. However, unlike the case for the other two rules, one needs function extensionality.
\begin{theorem} Assuming function extensionality, given types AA and BB, families of elements x:A⊢b(x):Bx:A \vdash b(x):B and x:A⊢b′(x):Bx:A \vdash b'(x):B, and families of identifications x:A⊢p(x):b(x)= Bb′(x)x:A \vdash p(x):b(x) =_B b'(x), there is an identification
congintro x:A.p(x):λ(x:A).b(x)= A→Bλ(x:A).b′(x)\mathrm{congintro}_{x:A.p(x)}:\lambda (x:A).b(x) =_{A \to B} \lambda (x:A).b'(x)
\end{theorem}
\begin{proof} By the computation rule of weak function types, there are families of identifications
x:A⊢β A→B x:A.b(x)(b(x)):((λx:A.b(x))(x)= Bb(x)x:A \vdash \beta_{A \to B}^{x:A.b(x)}(b(x)):((\lambda x:A.b(x))(x) =_{B} b(x)
x:A⊢β A→B x:A.b′(x)(b′(x)):((λx:A.b′(x))(x)= Bb′(x)x:A \vdash \beta_{A \to B}^{x:A.b'(x)}(b'(x)):((\lambda x:A.b'(x))(x) =_{B} b'(x)
Thus, there are families of identifications
x:A⊢β A→B x:A.b(x)(b(x))•p(x)•β A→B x:A.b′(x)(b′(x)) −1:(λx:A.b(x))(x)= B(λx:A.b′(x))(x)x:A \vdash \beta_{A \to B}^{x:A.b(x)}(b(x)) \bullet p(x) \bullet \beta_{A \to B}^{x:A.b'(x)}(b'(x))^{-1}:(\lambda x:A.b(x))(x) =_B (\lambda x:A.b'(x))(x)
and by λ\lambda-abstraction, one gets the dependent function
λ(x:A).β A→B x:A.b(x)(b(x))•p(x)•β A→B x:A.b′(x)(b′(x)) −1:∏ x:A(λx:A.b(x))(x)= B(λx:A.b′(x))(x)\lambda (x:A).\beta_{A \to B}^{x:A.b(x)}(b(x)) \bullet p(x) \bullet \beta_{A \to B}^{x:A.b'(x)}(b'(x))^{-1}:\prod_{x:A} (\lambda x:A.b(x))(x) =_B (\lambda x:A.b'(x))(x)
By function extensionality, there is an equivalence of types
funext:(λx:A.b(x))= A→B(λx:A.b′(x))≃∏ x:A(λx:A.b(x))(x)= B(λx:A.b′(x))(x)\mathrm{funext}:(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x)) \simeq \prod_{x:A} (\lambda x:A.b(x))(x) =_B (\lambda x:A.b'(x))(x)
which yields an identification
funext −1(λ(x:A).β A→B x:A.b(x)(b(x))•p(x)•β A→B x:A.b′(x)(b′(x)) −1):(λx:A.b(x))= A→B(λx:A.b′(x))\mathrm{funext}^{-1}(\lambda (x:A).\beta_{A \to B}^{x:A.b(x)}(b(x)) \bullet p(x) \bullet \beta_{A \to B}^{x:A.b'(x)}(b'(x))^{-1}):(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x))
We define
congintro x:A.p(x)≔funext −1(λ(x:A).β A→B x:A.b(x)(b(x))•p(x)•β A→B x:A.b′(x)(b′(x)) −1):(λx:A.b(x))= A→B(λx:A.b′(x))\mathrm{congintro}_{x:A.p(x)} \coloneqq \mathrm{funext}^{-1}(\lambda (x:A).\beta_{A \to B}^{x:A.b(x)}(b(x)) \bullet p(x) \bullet \beta_{A \to B}^{x:A.b'(x)}(b'(x))^{-1}):(\lambda x:A.b(x)) =_{A \to B} (\lambda x:A.b'(x))
\end{proof}
Application in logic
In logic, functions types express implication. More precisely, for ϕ,ψ\phi, \psi two propositions, under propositions as types the implication ϕ⇒ψ\phi \Rightarrow \psi is the function type ϕ→ψ\phi \to \psi (or rather the bracket type of that if one wishes to force this to be of type PropProp again ).
Graph of a function
Given a type AA and BB, there is a function
graph:(A→B)→(A→A×B)\mathrm{graph}:\left(A \to B\right) \to \left(A \to A \times B\right)
which takes a function f:A→Bf:A \to B and returns the graph of a function
graph(f):A→(A×B)\mathrm{graph}(f):A \to (A \times B)
defined by graph(f)(x)≡(x,f(x))\mathrm{graph}(f)(x) \equiv (x, f(x)) for all x:Ax:A. As a dependent anafunction the graph of the function is represented by the identity type family
x:A,y:B⊢f(x)= Byx:A, y:B \vdash f(x) =_{B} y
and so is equivalently the dependent sum type
graph(f)≔∑ x:A∑ y:Bf(x)= By\mathrm{graph}(f) \coloneqq \sum_{x:A} \sum_{y:B} f(x) =_{B} y
References
A textbook account in the context of programming languages is in section III of
Another textbook account could be found in section 2.2 of:
- Egbert Rijke, Introduction to Homotopy Type Theory, Cambridge Studies in Advanced Mathematics, Cambridge University Press (arXiv:2212.11082)
See also
- Richard Garner, On the strength of dependent products in the type theory of Martin-Löf.
Last revised on January 30, 2024 at 16:11:21. See the history of this page for a list of all contributions to it.