Lectures onType Theory
Chapter 167
Chapter 167Optional

Internal Parametricity without an Interval

Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.

The relational translation of chapter 59 sends a derivation to a term. It is a function on derivations, and a derivation is not a value of any type, so a program of the theory cannot apply it. The statement we would like to have available inside the theory is for every f:x:y:UEl(y)El(pr1x) and every A and a:A,f(A,a)=a. Adding (167.1) as an axiom breaks canonicity, by the argument of proposition 164.21. What is needed instead is a type former whose elements are the relational data, with binders that place them in the context and computation rules that let them reduce.

Cubical type theories supply such a former by adding an interval and paths along it. The calculus of this chapter does not: it adds one operator sending a type to the type of its logical spans, together with the operations that project a span to its legs, degenerate an element into a span, and exchange two span dimensions. Nothing in the syntax mentions a dimension variable, and nothing above dimension three appears.

The core theory

Definition 167.1 — Core theory

The core theory is extensional Martin-Löf type theory with

  • a unit type 1 with and its uniqueness rule t=;

  • dependent sums x:AB with (u,v), pr1, pr2, the two computation rules and the uniqueness rule t=(pr1t,pr2t);

  • extensional identity types EqA(u,v) with refl, equality reflection, and uniqueness of identity proofs;

  • dependent products x:AB with β and η;

  • a Coquand universe U with decoder El();

  • 2 with tt, ff and the dependent eliminator itey.Btuv.

We present it as a second-order theory: judgments are A for types and t:A for terms, binders are written with a turnstile inside the operation, and no rule about contexts or substitutions is displayed, since substitution is that of the ambient second-order framework.

Equality reflection and uniqueness of identity proofs are used at two places below and nowhere else: they make Eq(,) strictly preserved by the span operator, and they make the preservation of refl automatic.

The span operator

Definition 167.2 — Spans and their operations

Fix a finite nonempty set of legs, indexed by a metavariable k; the unary calculus has one leg and the binary calculus two. Extend definition 167.1 by

A
A
Span
x:At:Ba2:A
ap(x.t)a2:B
Ap
x:ABa2:A
d(x.B)a2
Spand
x:At:Ba2:A
apd(x.t)a2:d(x.B)a2
Apd
a2:A
kAa2:A
Leg
a:A
RAa:A
Refl
a22:(A)
SAa22:(A)
Sym
AkAx:Atk:Ak
unspanAkA(x.tk):U
Unspan

and write, for x:AB, a2:A and b2:d(x.B)a2, kx.Bda2b2:=pr2(kx:AB(a2,b2)) : B[kAa2/x].

Read A as the type of spans over A: an element has one leg kAa2 in A for each k, and an apex which the type does not name. The operation ap says that a map preserves spans, and d and apd are the dependent versions, over a given span in the base. The operation apd is the one that does the work in every application below.

Definition 167.3 — Equations of the span calculus

Functorialityap(x.g[f/y])a2=ap(y.g)(ap(x.f)a2),ap(x.x)a2=a2,1=1,d(x.C[f/y])a2=d(y.C)(ap(x.f)a2),apd(x.t[f/y])a2=apd(y.t)(ap(x.f)a2),Constancyd(_.B)a2=B,apd(x.t)a2=ap(x.t)a2 when xt,LegskB(ap(x.f)a2)=f[kAa2/x],kA(RAa)=a,ap(x.f)(RAa)=RB(f[a/x]),kA(SAa22)=ap(x2.kAx2)a22,SA(RAa2)=ap(x.RAx)a2,SA(SAa22)=a22,SA(ap(x22.SAx22)(SAa222))=ap(x22.SAx22)(SA(ap(x22.SAx22)a222)),Sum(x:AB)=x2:Ad(x.B)x2,d(x.y:BC)a2=y2:d(x.B)a2d((x,y).C)(a2,y2),apd(x.(u,v))a2=(apd(x.u)a2,apd(x.v)a2),Equalityd(x.EqB(u,v))a2=Eqd(x.B)a2(apd(x.u)a2,apd(x.v)a2),UniverseEl(kU(unspanAkAtk))=Ak,d(x.El(x))(unspanAkAtk)=A,kx.El(x)d(unspanAkAtk)a=tk[a/x],Booleans2=2,ap(x.tt)a2=tt,ap(x.ff)a2=ff,apd(x.itey.Btuv)a2=itey.d(x.B)a2(ap(x.t)a2)(ap(x.u)a2)(ap(x.v)a2).

The five equations grouped under Legs after the first line are the content of the two-dimensional structure, and each says one thing. The legs of a degenerate span are the element it came from. The two ways of taking a leg of a double span are related by S. The two ways of degenerating a span into a double span are related by S. Double symmetry is the identity. And on a triple span, swapping dimensions 0 and 1, then 1 and 2, then 0 and 1, agrees with swapping 1 and 2, then 0 and 1, then 1 and 2; with naturality this makes the induced symmetries of an n-fold span the full symmetric group.

Two formers are not preserved strictly, and each needs one further operation.

Definition 167.4 — Products and the universe

x:ABx:A,y:BCa2:Atk:y:B[kAa2/x]C[kAa2/x]t:y2:d(x.B)a2d((x,y).C)(a2,y2)y2tk(kx.Bda2y2)=k(x,y).Cd(a2,y2)(ty2)
mkΠ a2tkt:d(x.y:BC)a2
MkPi

with the three equations kx.y:BCda2(mkΠ a2tkt)=tk,λy2.apd((x,f,y).fy)(a2,(mkΠ a2tkt,y2))=t,mkΠ a2(kx.y:BCda2t2)(λy2.apd((x,f,y).fy)(a2,(t2,y2)))=t2. The operation unspan of definition 167.2 plays the same role for U: the canonical map from a2:U to the span with apex d(x.El(x))a2, legs El(kUa2) and projections kx.El(x)da2 has unspan as a section, and the three Universe equations of definition 167.3 say exactly that.

Remark 167.5 — Why Π needs mk Π

One might expect (y:BC)y2:Bd(y.C)y2, matching the Σ equation. It fails from right to left. From an element of the left-hand side, ky:BC produces a function y:BC at the legs. From an element of the right-hand side there is no way to produce one, because the right-hand side speaks only about spans and a leg of a span of functions is a function that the data does not mention. The premise of MkPi adds exactly that missing datum: functions tk at the legs, together with the square saying they are compatible with the function t at the apex.

Proposition 167.6 — Spans of the four base formers

In the calculus of definition 167.2definition 167.4:

  1. 1=1;

  2. 2=2, and ap sends each constructor to itself;

  3. (x:AB)=x2:Ad(x.B)x2, and apd commutes with pairing and with both projections;

  4. d(x.y:BC)a2 is isomorphic to the type of triples (tk,t,e) satisfying the square of MkPi.

Proof of Proposition 167.6 — Spans of the four base formers

Proof. Items 1–3 and the isomorphism of item 4 are the corresponding equations of definition 167.3, definition 167.4; only the claim about projections needs an argument, and it is a calculation: apd(x.prkt)a2=Σηprk(apd(x.pr1t)a2,apd(x.pr2t)a2)=apdpairprk(apd(x.(pr1t,pr2t))a2)=Σηprk(apd(x.t)a2). ◻

Lemma 167.7 — Four derived equations

  1. RAa=ap(_.a);

  2. ap(_.b)a2=ap(_.b)a2 for all a2,a2;

  3. kx:AB(a2,b2)=(kAa2,kx.Bda2b2);

  4. kx.Bda2(apd(x.t)a2)=t[kAa2/x].

Proof of Lemma 167.7 — Four derived equations

Proof. For 1, a=a[/_], so RAa=RA(a[/_])=ap(_.a)(R1) by the second Legs equation, and R1= because 1=1 is a unit type.

For 2, both sides equal ap(_.b): ap(_.b)a2=b=b[/_]ap(_.b)(ap(_.)a2)=1=1ap(_.b), the second step because ap(_.)a2 is an element of 1=1 and so is .

For 3, apply the Σ-uniqueness rule to kx:AB(a2,b2) and compute the first projection by the first Legs equation applied to ap(w.pr1w), using the Σ equation of definition 167.3; the second projection is kd by its definition in definition 167.2.

For 4, apply 3 to (a2,apd(x.t)a2)=apd(x.(x,t))a2 and use the first Legs equation on the right-hand side. ◻

Exercise 167.1

★☆☆ Using 2=2 and lemma 167.7, compute k2b2 for b2:2, and ap(x.ite_.2xfftt)b2. Then state what 2=2 says about a binary span over 2, and why that does not make the two legs equal in a calculus with more than one leg.

Two syntaxes for the same theory

Definition 167.2 presents the span operations as operations on types and terms. A second presentation makes them operations on contexts, and it is the one that the model of section 167.4 interprets directly.

Definition 167.8 — Global theory

A model of the global theory is a model of the core theory (definition 167.1) as a category with families, equipped with

  • an endofunctor on contexts, preserving the terminal context, with an action on types ΓA and terms Γt commuting with substitution;

  • natural transformations kΓ:ΓΓ, RΓ:ΓΓ and SΓ:ΓΓ satisfying Rk=id, Sk=k, RS=R, SS=id, and the braid equation SSS=SSS;

  • the isomorphism for Π and the section for U of definition 167.4, and strict preservation of 1, Σ, Eq(,) and 2.

The local theory is the presentation of definition 167.2definition 167.4.

Theorem 167.9 — The two syntaxes agree; imported

The initial models of the local and the global theory are isomorphic, by mutually inverse maps α from the global to the local syntax and β back, both of which act as the identity on the core theory.

What is imported is the construction of α and β and the verification that they are mutually inverse, due to Altenkirch, Chamoun, Kaposi and Shulman, Internal Parametricity, without an Interval, §4. What it supplies here is the transfer of theorem 167.15, proved for the global syntax, back to the local one; because α and β fix the core theory, a closed Boolean term is fixed by both, and the transfer is the two-line argument displayed in that theorem’s proof.

The cube category and the presheaf model

Definition 167.10 — The cube category

The category has the natural numbers as objects. Its morphisms are generated by a category structure together with suc:(J,I)(1+J,1+I),kI:(I,1+I),RI:(1+I,I),SI:(2+I,2+I), subject to suc(fg)=sucfsucg,sucid=id,kIf=sucfkJ,RIsucf=fRJ,SIsuc(sucf)=suc(sucf)SJ,RIkI=idI,SIk1+I=suckI,R1+ISI=sucRI,SISI=id2+I,S1+IsucSIS1+I=sucSIS1+IsucSI. Equivalently, is the free symmetric semicartesian strict monoidal category on a cylinder; the last equation is the braid relation, so the automorphisms of the object I are the permutations of an I-element set.

Lemma 167.11 — Generalized symmetries

Define, by induction on I0, (sym0,1idI1):=id1+I1,(sym1+I0,1idI1):=SI0+I1suc(symI0,1idI1),(sym1,0idI1):=id1+I1,(sym1,1+I0idI1):=suc(sym1,I0idI1)SI0+I1. Then the two composites are the identities on 1+I0+I1 and on I0+1+I1 respectively.

Proof of Lemma 167.11 — Generalized symmetries

Proof. By induction on I0. At I0=0 both are identities by definition. At 1+I0, (sym1+I0,1id)(sym1,1+I0id)=def.Ssuc(symI0,1id)suc(sym1,I0id)S=IHSS=SS=idid, using functoriality of suc at the middle step. The other composite is the same calculation with the two definitions exchanged. ◻

Theorem 167.12 — Presheaf model

The presheaf category [op,Set] carries a model of the global theory, in which is precomposition by suc, and k, R, S are precomposition by the generators of the same names.

Proof of Theorem 167.12 — Presheaf model

Proof. Proof structure. The core theory is interpreted by the standard presheaf model of chapter 52: contexts are presheaves, types over Γ are presheaves on the category of elements, and the formers of definition 167.1 are the pointwise ones, with U a Hofmann–Streicher universe. What must be added is the interpretation of the span structure, and each item of definition 167.8 is one line.

The endofunctor. Set (Γ)I:=Γ1+I, with the action of f:(J,I) given by sucf. Functoriality is the first two equations of definition 167.10, and preservation of the terminal presheaf is immediate since 1 is the constant one-point presheaf. The action on types and terms is the same reindexing, so it commutes with substitution.

The three transformations. Set kΓ, RΓ and SΓ to be precomposition by kI, RI and SI. Naturality is the third, fourth and fifth equations of definition 167.10, contravariantly; the remaining four equations of definition 167.10 become, again contravariantly, the four equations required in definition 167.8, with the braid equation last.

Strict preservation. 1, Σ, Eq(,) and 2 are interpreted pointwise, and reindexing along suc commutes with a pointwise former; hence each is preserved on the nose.

Π and U. Neither is pointwise. For Π, an element of (ΠBC) at I is an element of (ΠBC) at 1+I, which is a family of functions indexed by morphisms out of 1+I; splitting those morphisms according to whether they factor through k gives exactly the triple (tk,t,e) of MkPi, and the splitting is a bijection by the case analysis on -morphisms that lemma 167.11 makes available. For U, the canonical map to the span of its decodings has a section by the same case analysis; the reverse round trip is not the identity in this model, which is why definition 167.4 asks only for a section and definition 167.3 lists only the three Universe equations. ◻

Canonicity

Definition 167.13 — The gluing model

Let Syn be the initial model of the global theory and let G:Syn[op,Set] be the global-sections functor, GΓI:=Sub(-shaped context,Γ) at dimension I, extended to types and terms in the standard way. The gluing model is the displayed model over Syn whose displayed types over A are predicates on the global sections of A, closed under the formers, and whose displayed terms are proofs.

Lemma 167.14 — G preserves the span structure

G is a weak morphism of models of the global theory: it commutes with , and with k, R and S.

Proof of Lemma 167.14 — G preserves the span structure

Proof. For , unfolding the two definitions at dimension I, G(Γ)γ1+I=def.ofGI(Γ)[γ1+I]=def.of1+IΓ[γ1+I]=def.ofG(GΓ)γ1+I=def.in[op,Set](GΓ)γ1+I. For k, GkΓγ1+I=def.ofGIkΓγ1+I=definition167.10γ1+I[kI]=def.kGΓγ1+I, and the arguments for R and S are the same computation with RI and SI in place of kI, using the corresponding generator of definition 167.10. ◻

Theorem 167.15 — Boolean canonicity

In the local or the global syntax, every t:Tm2 satisfies t=tt or t=ff.

Proof of Theorem 167.15 — Boolean canonicity

Proof. Global syntax. Glue along G, using lemma 167.14 to know that the displayed model of definition 167.13 is a model of the global theory. Induction on Syn interprets a closed t:2 as a term of Tm[op,Set] (G1.) (:2Eq(iteq(Gtt[p])(Gff[p]),Gt[p])). Supplying id and the element of the metatheoretic unit set yields a pair consisting of a metatheoretic Boolean b together with a proof that itebttff=t; case analysis on b gives the two alternatives.

Local syntax. Let t be closed of type 2 in the local syntax. By theorem 167.9, αt is a closed term of type 2 in the global syntax, since α acts as the identity on the core theory and 2, belong to it. The previous paragraph gives, say, αt=tt. Applying β and using that β also fixes the core theory, t=βα=idβ(αt)=hypothesisβtt=βfixesthecorett. ◻

The polymorphic identity, internally

Theorem 167.16 — Uniqueness of the polymorphic identity

Let f have type x:y:UEl(y)El(pr1x), let A be a type with code cA:U, and let a:A. Then EqA(f(cA,a),a) is inhabited.

Proof of Theorem 167.16 — Uniqueness of the polymorphic identity

Proof. The unary calculus suffices, so k has one value.

The span. Let x:AP be any predicate and let p:P[a/x]. Form s:=unspan A (x:AP) (x.pr1x) : U, whose leg is A, whose apex is x:AP, and whose projection is the first projection. Then (s,(a,p)) is an element of (y:UEl(y)), by the Σ equation of definition 167.3 together with the second Universe equation.

The term. Apply apd to f: u:=apd(x.fx)(s,(a,p)). Its type computes as d(x.El(pr1x))(s,(a,p))=functorialityd(x.El(x))(ap(x.pr1x)(s,(a,p)))=legsofapaird(x.El(x))s=Universex:AP.

The first component. Compute pr1u: pr1u=thirdUniverseeq.kx.El(x)dsu=lemma167.7(3)kx.El(pr1x)d(s,(a,p))u=lemma167.7(4)(fx)[ky:UEl(y)(s,(a,p))/x]=lemma167.7(3)f(cA,a), using in the last step that the leg of s is A, whose code is cA, and that the projection sends (a,p) to a.

Conclusion. Hence pr2u:P[f(cA,a)/x]. Choose P:=EqA(a,x) and p:=refl; then pr2u:EqA(a,f(cA,a)), and symmetry of the extensional identity type gives the stated inhabitant. ◻

Theorem 167.16 is (167.1), proved by a term of the calculus rather than by a metatheoretic translation, and by theorem 167.15 the calculus containing that term still has canonical Booleans. The predicate P was arbitrary: the same term proves that f preserves every predicate, which is the internal form of the free theorem of example 164.15.

Exercise 167.2

★★☆ Theorem 167.16 used one leg.

  1. Redo the construction in the binary calculus, with s replaced by an unspan over two types A0,A1 and two maps out of a relation, and state the conclusion it yields about f(cA0,a0) and f(cA1,a1).

  2. State which of the two conclusions is stronger and why the unary one does not follow from the binary one by taking A0=A1.

Exercise 167.3

★★★ Let N:=x:y:z:UEl(z)(El(pr1y)El(pr1y))El(pr1(pr1x)) be the type of Church numerals, with zero:=λx.pr2(pr1x), suc:=λn.λx.pr2x(nx) and ite(A,zA,sA):=λn.n(A,zA,sA).

  1. Using the binary calculus and mkΠ, show that ite respects algebra morphisms: for f with fzA=zB and f(sAn)=sB(fn), f(iteAn)=iteBn.

  2. Using the unary calculus, show that (N,zero,suc) is initial among algebras, and state which premise of MkPi carries the compatibility square in each part.

  3. Say why the same argument cannot be carried out by the external translation of chapter 59 without adding an axiom.

Boundary

Proved here. The span calculus in its local presentation (definition 167.2definition 167.4); the computation of spans at 1, 2, Σ and Π (proposition 167.6); the four derived equations (lemma 167.7); the generalized symmetries in (lemma 167.11); the presheaf model (theorem 167.12); the gluing model and Boolean canonicity (lemma 167.14, theorem 167.15); and the internal uniqueness of the polymorphic identity (theorem 167.16). The isomorphism of the two syntaxes (theorem 167.9) is imported at the stated signature.

Not consequences of theorem 167.15.

  1. Indexed heterogeneous bridges. The operator takes a type to the spans over it. A relation between two different types indexed by a further parameter is a different former with different rules, and no clause of definition 167.3 is a rule for one.

  2. Fibrancy and transport. A span is not a path: nothing above provides a transport operation along a span, and none is derivable, since has no elimination rule beyond the legs.

  3. Normalization. Definition 167.1 has equality reflection, so conversion is undecidable. A normalization theorem would concern a variant of the theory without reflection, and no such variant is constructed here.

  4. Higher dimensions. The syntax mentions no cube above dimension three: S is two-dimensional and its braid equation is three-dimensional. The model of theorem 167.12 has cubes of every dimension, and a statement about them is a statement about the model, not about the theory.

Any later calculus that reuses this substrate must restate its own delta against definition 167.2definition 167.4 and may not carry theorem 167.15 across.

Suggested first pass.

Problems exercise 167.4, exercise 167.5, and exercise 167.7 form the suggested first pass. None of these problems is a prerequisite for a later chapter.

Exercise 167.4

★★★ Definition 167.10 presents by generators and relations.

  1. Show that the objects 0,1,2 have respectively one, 1+|k| and a computable number of morphisms into 1, by listing them.

  2. Prove that the automorphism group of the object I is the symmetric group on I letters, using lemma 167.11 and the braid equation.

  3. Show that is semicartesian but not cartesian, by exhibiting a morphism that no diagonal could provide, and say which equation of definition 167.10 a diagonal would have to satisfy.

Exercise 167.5

★★★ Remark 167.5 explains why Π needs an extra operation.

  1. Write the canonical map d(x.y:BC)a2y2:d(x.B)a2d((x,y).C)(a2,y2) and verify from definition 167.3 that it is well typed.

  2. Show that it is not injective, by exhibiting two elements of the source with the same image in a model where B and C are constant.

  3. Show that adding the compatibility square of MkPi makes it injective, and identify the equation of definition 167.4 that supplies the inverse.

Exercise 167.6

★★☆ Theorem 167.15 used lemma 167.14 and theorem 167.9.

  1. Identify exactly where the proof uses that 2 is preserved strictly by , and show that the argument fails if 2 were preserved only up to isomorphism.

  2. Explain why the theorem is stated for 2 and not for U, and exhibit the step that would break.

  3. State what the theorem gives for a closed term of type 2×2, and prove it from the displayed statement.

Exercise 167.7

★★★ Practical project.span-calculus-checker Implement, in Kappa, a checker for the local span calculus and run it on the terms of this chapter.

Calculus to implement. The core theory of definition 167.1 restricted to 1, Σ, extensional Eq(,), Π, 2 and a single universe U with El(); and the span operations of definition 167.2definition 167.4. Represent terms with de Bruijn indices, and implement the equations of definition 167.3 as a left-to-right rewriting relation with a fuel bound, so that conversion is decided by rewriting both sides to a normal form of that relation and comparing — which is a decision procedure for the displayed equations, not for the conversion of definition 167.1, whose equality reflection the checker does not implement.

Invariant. Every rewrite must be an instance of exactly one equation of definition 167.3 or definition 167.4, and the checker must record which one; the recorded sequence for each accepted judgment is the certificate. The checker must also verify the compatibility square of MkPi whenever mkΠ is applied, and reject when it fails.

Concrete result. For each named input, an accept or reject verdict together with the rewrite certificate, or the offending premise.

Acceptance test. The following must be accepted with the printed certificate matching the chapter: the four computations of proposition 167.6; the four derived equations of lemma 167.7, each as a rewrite from left to right; the type computation of u in theorem 167.16, whose certificate must be exactly the three steps displayed there; and the computation of pr1u, whose certificate must be the four steps displayed there, ending at f(cA,a). The following must be rejected: an application of mkΠ whose square premise is omitted; a use of unspan whose apex and legs do not match the supplied maps; and a term asserting the reverse round trip for U, which definition 167.4 does not provide. Produce three mutations that still run — make preserve Π strictly, drop SS=id, and let unspan be a full inverse — and confirm that each accepts a judgment the unchanged checker rejects. State explicitly that the program checks the displayed equations on finitely many terms and proves neither theorem 167.15 nor theorem 167.12.

Search the book

Type to search the local edition.