Let 𝑔 be a closed term of type ∏𝐴:U𝐴 →𝐴. Nothing in the typing rules forbids 𝑔 from behaving differently at different instances: the rules say that 𝑔 𝐴 has type 𝐴 →𝐴 for every 𝐴, and they say nothing about the relation between 𝑔 𝟐 and 𝑔 ℕ. Consider the informal specification 𝑔𝐴𝑥:={𝗍𝗍if 𝐴 is 𝟐,𝑥otherwise, which is well typed at every instance considered separately. It is not a term of the calculus, because there is no elimination form for U that could decide the case split. But that is a statement about which terms exist, and it is proved by inspecting the syntax; what we want is a statement about what every term does, proved once for all terms.
Reynolds’ answer is to interpret a type not as a set of values but as a relation, and to prove that every term is related to itself. In a dependent theory that answer needs revision twice over. The relation for ∏𝑥:𝐴𝐵 must relate 𝑓1 and 𝑓2 at arguments 𝑥1 and 𝑥2 that are themselves only related, and the codomain 𝐵 is then instantiated at two different arguments, so the relation for 𝐵 must be allowed to depend on a proof that 𝑥1 and 𝑥2 are related. And types are terms, so the relational interpretation must itself be a term of the theory.
The simply typed case, and one free theorem
We begin where the difficulty is absent. Fix a finite set of type variables Θ =𝛼1,…,𝛼𝑘 and let types be generated by 𝜎,𝜏::=𝛼𝑖∣𝜎→𝜏. A relation environment 𝜚 assigns to each 𝛼𝑖 a triple (𝑋𝑖,𝑌𝑖,𝑅𝑖) of two sets and a relation 𝑅𝑖 ⊆𝑋𝑖 ×𝑌𝑖.
For a type 𝜏 over Θ and a relation environment 𝜚 define a relation R𝜏[𝜚] between the two sets A1(𝜏) and A2(𝜏) given by A1(𝛼𝑖):=𝑋𝑖, A2(𝛼𝑖):=𝑌𝑖, and A𝑗(𝜎 →𝜏):= the set of functions A𝑗(𝜎) ⟶A𝑗(𝜏). A term ⃗𝑥 :⃗𝜎 ⊢𝑒 :𝜏 denotes, in the copy 𝑗, a function A𝑗(𝑒) from tuples in A𝑗(𝜎1) ×⋯ to A𝑗(𝜏), by the usual clauses for variables, abstraction and application. Set R𝛼𝑖[𝜚]:=𝑅𝑖,R𝜎→𝜏[𝜚]:={(𝑓1,𝑓2) ∣ ∀(𝑎1,𝑎2)∈R𝜎[𝜚]. (𝑓1𝑎1,𝑓2𝑎2)∈R𝜏[𝜚]}.
Referenced from 5 locations
Let 𝑥1 :𝜎1,…,𝑥𝑚 :𝜎𝑚 ⊢𝑒 :𝜏 over Θ and let 𝜚 be a relation environment. If (𝑎𝑗,𝑏𝑗) ∈R𝜎𝑗[𝜚] for every 𝑗, then (A1(𝑒)(⃗𝑎),A2(𝑒)(⃗𝑏)) ∈R𝜏[𝜚].
Referenced from 2 locations
Proof of Proposition 164.2 — Abstraction for simple types
Proof. By induction on the derivation. Variable case. A1(𝑥𝑗)(⃗𝑎) =𝑎𝑗 and A2(𝑥𝑗)(⃗𝑏) =𝑏𝑗, and the pair is related by hypothesis. Abstraction case. Let 𝑒 =𝜆𝑦. 𝑒0 with 𝑦 :𝜎0. To show the pair of functions is in R𝜎0→𝜏0[𝜚], take (𝑐1,𝑐2) ∈R𝜎0[𝜚]; the induction hypothesis for 𝑒0 with the extended environments gives (A1(𝑒0)(⃗𝑎,𝑐1),A2(𝑒0)(⃗𝑏,𝑐2)) ∈R𝜏0[𝜚], which is the required condition by definition 164.1. Application case. As in the abstraction case with the two quantifiers exchanged: the induction hypothesis for the operator gives membership in R𝜎0→𝜏[𝜚], and the induction hypothesis for the operand supplies the pair at which that membership is instantiated. ◻
Now add one quantifier. Suppose a term 𝑔 has, at every set 𝑋, an element 𝑔𝑋 ∈𝑋 →𝑋, and suppose these are related in the sense that (𝑔𝑋,𝑔𝑌) ∈R𝛼→𝛼[𝛼 ↦(𝑋,𝑌,𝑅)] for every relation 𝑅.
Under that hypothesis, 𝑔𝑋(𝑎) =𝑎 for every set 𝑋 and every 𝑎 ∈𝑋.
Referenced from 2 locations
Proof of Proposition 164.3 — The identity free theorem
Proof. Take 𝑌:=𝑋 and 𝑅:={(𝑎,𝑎)}, the one-element relation at the given 𝑎. Then (𝑎,𝑎) ∈𝑅, so by definition 164.1 the pair (𝑔𝑋(𝑎),𝑔𝑋(𝑎)) lies in 𝑅; the only pair in 𝑅 is (𝑎,𝑎), so 𝑔𝑋(𝑎) =𝑎. ◻
The proof used a relation that is not a function and not the identity: it is the graph of nothing at all. That freedom is the entire content of parametricity, and the reason (164.1) is impossible is that the relation 𝑅 can be chosen to separate 𝗍𝗍 from the intended answer.
The dependent case will repeat this argument at a signature in which the relation itself is a term. Two things must change. The environment 𝜚, an external object, becomes part of the context. And the clause for → becomes a clause for ∏𝑥:𝐴𝐵 in which 𝐵 is instantiated at both 𝑥1 and 𝑥2, so its relation depends on the proof relating them.
The dependent signature
S is Martin-Löf type theory with the following formers, presented in the order formation, introduction, elimination, computation.
A cumulative hierarchy of universes U0 :U1 :⋯, with types as terms of a universe (the Russell presentation), so that Γ ⊢𝐴 :U𝑖 and Γ ⊢𝐴 𝗍𝗒𝗉𝖾 are interchangeable at level 𝑖.
Dependent products ∏𝑥:𝐴𝐵, with 𝜆𝑥. 𝑏, application 𝑓 𝑎, the computation rule (𝜆𝑥. 𝑏) 𝑎 ≡𝑏[𝑎/𝑥] and the uniqueness rule 𝜆𝑥. 𝑓 𝑥 ≡𝑓.
Dependent sums ∑𝑥:𝐴𝐵, with (𝑎,𝑏), projections 𝗉𝗋1 and 𝗉𝗋2, the computation rules 𝗉𝗋1(𝑎,𝑏) ≡𝑎 and 𝗉𝗋2(𝑎,𝑏) ≡𝑏, and the uniqueness rule (𝗉𝗋1𝑝,𝗉𝗋2𝑝) ≡𝑝.
The unit type 𝟏 with ⋆ and the uniqueness rule 𝑢 ≡ ⋆.
The natural numbers ℕ with 𝟢, 𝗌𝗎𝖼 and the dependent recursor 𝗂𝗇𝖽ℕ.
Identity types 𝖨𝖽𝐴(𝑎,𝑏) with 𝗋𝖾𝖿𝗅 and the eliminator 𝖩, with 𝖩 computing on 𝗋𝖾𝖿𝗅.
We write U for an unspecified level when the level plays no role.
Referenced from 9 locations
Every judgment of S will be translated into a judgment of S itself, in which each variable 𝑥 of the source is replaced by three variables 𝑥1,𝑥2,𝑥𝑅. Write 𝑒1 and 𝑒2 for the two copies of a source expression 𝑒 obtained by subscripting all its free variables with 1 and with 2 respectively.
Referenced from 2 locations
The relational translation
For a raw expression 𝑒 of S write 𝑒𝖱 for its relational translation, the expression defined by the following clauses; for a type 𝐴 it is a relation between the two copies 𝐴1 and 𝐴2, and for a term 𝑎 it is a proof that 𝑎1 and 𝑎2 are related by the translation of 𝑎’s type. U𝑖𝖱:=𝜆𝑋1.𝜆𝑋2.𝑋1→𝑋2→U𝑖,𝑥𝖱:=𝑥𝑅,∏𝑥:𝐴𝐵𝖱:=𝜆𝑓1.𝜆𝑓2.∏𝑥1:𝐴1∏𝑥2:𝐴2∏𝑥𝑅:𝐴𝖱𝑥1𝑥2𝐵𝖱(𝑓1𝑥1)(𝑓2𝑥2),𝜆𝑥.𝑏𝖱:=𝜆𝑥1.𝜆𝑥2.𝜆𝑥𝑅.𝑏𝖱,𝑓𝑎𝖱:=𝑓𝖱𝑎1𝑎2𝑎𝖱. On contexts, ⋅𝖱:=⋅,Γ,𝑥:𝐴𝖱:=Γ𝖱,𝑥1:𝐴1,𝑥2:𝐴2,𝑥𝑅:𝐴𝖱𝑥1𝑥2.
Referenced from 17 locations
Read the clause for U𝑖 as the decision that fixes everything else: a type is translated to a relation, so the translation of the universe is the type of relations. Read the clause for ∏𝑥:𝐴𝐵 as the dependent form of definition 164.1: two functions are related when they send related arguments to related results, and the relation at the result is 𝐵𝖱 instantiated at both arguments, in a context that also holds the proof 𝑥𝑅.
For all raw expressions 𝑏 and 𝑎 and every variable 𝑥, 𝑏[𝑎/𝑥]𝖱=𝑏𝖱[𝑎1/𝑥1][𝑎2/𝑥2][𝑎𝖱/𝑥𝑅]. Consequently 𝐴 ⟶∗𝛽𝐴′ implies 𝐴𝖱 ⟶∗𝛽𝐴′𝖱.
Referenced from 5 locations
Proof of Lemma 164.8 — Translation commutes with substitution
Proof. By induction on 𝑏. Variable case. If 𝑏 =𝑥 then the left side is 𝑎𝖱 and the right side is 𝑥𝑅[𝑎𝖱/𝑥𝑅] =𝑎𝖱. If 𝑏 =𝑦 with 𝑦 distinct from 𝑥, both sides are 𝑦𝑅. Binder case. If 𝑏 =𝜆𝑦. 𝑏0 with 𝑦 ∉FV(𝑎) ∪{𝑥}, then both sides are 𝜆𝑦1. 𝜆𝑦2. 𝜆𝑦𝑅. − applied to the two sides of the induction hypothesis for 𝑏0, and the three fresh variables 𝑦1,𝑦2,𝑦𝑅 avoid FV(𝑎𝖱) by the same freshness condition. Remaining cases. Each clause of definition 164.6, definition 164.7 builds its output from the outputs at the immediate subterms and from the two copies 𝑒1,𝑒2, and both operations commute with substitution.
For the consequence, a one-step 𝛽-reduction (𝜆𝑥. 𝑏) 𝑎 ⟶𝛽𝑏[𝑎/𝑥] translates to (𝜆𝑥.𝑏)𝑎𝖱𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛164.6=(𝜆𝑥1.𝜆𝑥2.𝜆𝑥𝑅.𝑏𝖱)𝑎1𝑎2𝑎𝖱⟶∗𝛽𝑏𝖱[𝑎1/𝑥1][𝑎2/𝑥2][𝑎𝖱/𝑥𝑅], which is 𝑏[𝑎/𝑥]𝖱 by the displayed equation; the compatible closure follows because every clause is a congruence. ◻
If Γ ⊢𝑎 :𝐴 in S, then Γ𝖱 ⊢𝑎𝖱 :𝐴𝖱 𝑎1 𝑎2 in S.
Referenced from 10 locations
Proof of Theorem 164.9 — Abstraction
Proof. By induction on the derivation of Γ ⊢𝑎 :𝐴. Throughout, the induction hypothesis at a subterm 𝑏 of type 𝐵 is Γ𝖱 ⊢𝑏𝖱 :𝐵𝖱 𝑏1 𝑏2, and we use that each of the two copies Γ1,Γ2 is a sub-context of Γ𝖱, so every source judgment can be reused in each copy.
Variable. For 𝑥 :𝐴 in Γ, definition 164.6 puts 𝑥𝑅 :𝐴𝖱 𝑥1 𝑥2 in Γ𝖱, and 𝑥𝖱 =𝑥𝑅.
Universe. For Γ ⊢𝐴 :U𝑖 the required conclusion is Γ𝖱 ⊢𝐴𝖱 :U𝑖𝖱 𝐴1 𝐴2, and U𝑖𝖱𝐴1𝐴2𝛽≡𝐴1→𝐴2→U𝑖, so the conclusion says that 𝐴𝖱 is a relation between the two copies of 𝐴. This is what the induction hypothesis at 𝐴 delivers in every clause below, and the two statements are therefore proved simultaneously: types and terms are the same syntactic class in definition 164.4.
Product formation. Assume Γ ⊢𝐴 :U𝑖 and Γ,𝑥 :𝐴 ⊢𝐵 :U𝑗. The induction hypotheses give 𝐴𝖱 :𝐴1 →𝐴2 →U𝑖 over Γ𝖱 and 𝐵𝖱 :𝐵1 →𝐵2 →U𝑗 over Γ𝖱,𝑥1 :𝐴1,𝑥2 :𝐴2,𝑥𝑅 :𝐴𝖱 𝑥1 𝑥2. The displayed body of ∏𝑥:𝐴𝐵𝖱 in definition 164.6 is then a well-formed type of the universe at the level of the source product, formed by three nested products over those three variables.
Abstraction. Assume Γ,𝑥 :𝐴 ⊢𝑏 :𝐵, so that Γ ⊢𝜆𝑥. 𝑏 :∏𝑥:𝐴𝐵. The induction hypothesis gives 𝑏𝖱 :𝐵𝖱 𝑏1 𝑏2 over the extended translated context. Abstracting the three variables gives 𝜆𝑥.𝑏𝖱:∏𝑥1:𝐴1∏𝑥2:𝐴2∏𝑥𝑅:𝐴𝖱𝑥1𝑥2𝐵𝖱𝑏1𝑏2, and the type ∏𝑥:𝐴𝐵𝖱 (𝜆𝑥1. 𝑏1) (𝜆𝑥2. 𝑏2) 𝛽-reduces to the same one, because (𝜆𝑥𝑗. 𝑏𝑗) 𝑥𝑗 ≡𝑏𝑗 by the computation rule of definition 164.4.
Application. Assume Γ ⊢𝑓 :∏𝑥:𝐴𝐵 and Γ ⊢𝑎 :𝐴. The induction hypotheses give 𝑓𝖱 :∏𝑥:𝐴𝐵𝖱 𝑓1 𝑓2 and 𝑎𝖱 :𝐴𝖱 𝑎1 𝑎2. Instantiating the three products of ∏𝑥:𝐴𝐵𝖱 at 𝑎1,𝑎2,𝑎𝖱 yields 𝑓𝖱𝑎1𝑎2𝑎𝖱:𝐵𝖱[𝑎1,𝑎2,𝑎𝖱/𝑥1,𝑥2,𝑥𝑅](𝑓1𝑎1)(𝑓2𝑎2), and lemma 164.8 identifies the displayed type with 𝐵[𝑎/𝑥]𝖱 (𝑓1 𝑎1) (𝑓2 𝑎2), which is the required conclusion.
Sum, unit, natural numbers, identity. Each is a copy of the product case with the clause of definition 164.7 in place of the clause for ∏𝑥:𝐴𝐵: the introduction form translates to the introduction form of the translated type, and the elimination form is typed by instantiating the translated family. For ℕ and 𝖨𝖽𝐴(𝑎,𝑏) the eliminator case additionally uses that the translated inductive family has one constructor for each source constructor and the same recursive structure, so the translated motive is eliminated by the translated eliminator.
Conversion. If Γ ⊢𝐴 ≡𝐴′ 𝗍𝗒𝗉𝖾 is derived from 𝐴 ⟶∗𝛽𝐶 and 𝐴′ ⟶∗𝛽𝐶, then 𝐴𝖱 ⟶∗𝛽𝐶𝖱 and 𝐴′𝖱 ⟶∗𝛽𝐶𝖱 by lemma 164.8, so the two translated types are convertible and the conversion rule of S applies. ◻
If ⋅ ⊢𝑎 :𝐴 then ⋅ ⊢𝑎𝖱 :𝐴𝖱 𝑎 𝑎.
Referenced from 3 locations
Proof of Corollary 164.10 — Closed terms are self-related
Proof. Both copies of a closed expression are the expression itself, and ⋅𝖱 = ⋅ by definition 164.6. ◻
The translation computed on an abstract data type
Fix 𝖢𝗅𝗂𝖾𝗇𝗍:=∏𝑆:U0𝑆→(𝑆→𝑆)→(𝑆→ℕ)→ℕ, the type of programs that use a state type 𝑆 through an initial state, a step function and a readout, and return a number. Two implementations of the interface are first:𝑆:=ℕ,𝑖:=𝟢,𝑠:=𝗌𝗎𝖼,𝑟:=𝜆𝑛.𝑛;second:𝑆:=ℕ×ℕ,𝑖:=(𝟢,𝗌𝗎𝖼𝟢),𝑠:=𝜆𝑝.(𝗌𝗎𝖼(𝗉𝗋1𝑝),𝗉𝗋2𝑝),𝑟:=𝜆𝑝.𝗉𝗋1𝑝. The second carries an extra component that no operation reads.
Referenced from 4 locations
Apply definition 164.6 clause by clause. The outer product is over 𝑆 :U0, so by the universe clause the translation introduces three variables 𝑆1,𝑆2 :U0 and 𝑆𝑅 :𝑆1 →𝑆2 →U0. Each of the three remaining arguments is a non-dependent product, so its clause introduces two arguments and a relatedness hypothesis. The codomain is ℕ, whose translation is N. Writing 𝑐1,𝑐2 for the two copies, 𝖢𝗅𝗂𝖾𝗇𝗍𝖱𝑐1𝑐2≡ ∏𝑆1:U0∏𝑆2:U0∏𝑆𝑅:𝑆1→𝑆2→U0∏𝑖1:𝑆1∏𝑖2:𝑆2∏𝑖𝑅:𝑆𝑅𝑖1𝑖2∏𝑠1:𝑆1→𝑆1∏𝑠2:𝑆2→𝑆2∏𝑠𝑅:∏𝑥1:𝑆1∏𝑥2:𝑆2𝑆𝑅𝑥1𝑥2→𝑆𝑅(𝑠1𝑥1)(𝑠2𝑥2)∏𝑟1:𝑆1→ℕ∏𝑟2:𝑆2→ℕ∏𝑟𝑅:∏𝑥1:𝑆1∏𝑥2:𝑆2𝑆𝑅𝑥1𝑥2→N(𝑟1𝑥1)(𝑟2𝑥2)N(𝑐1𝑆1𝑖1𝑠1𝑟1)(𝑐2𝑆2𝑖2𝑠2𝑟2). Every hypothesis is forced: the clause for a product supplies exactly one relatedness argument for each argument of the source type, and no clause is free to omit one.
Referenced from 5 locations
For all 𝑚,𝑛 :ℕ the types N 𝑚 𝑛 and 𝖨𝖽ℕ(𝑚,𝑛) are logically equivalent: there are terms in each direction.
Referenced from 10 locations
Proof of Lemma 164.13 — Identity extension at
Proof. From N to 𝖨𝖽ℕ( −, −): eliminate the inductive relation with motive 𝜆𝑚. 𝜆𝑛. 𝜆_. 𝖨𝖽ℕ(𝑚,𝑛). The case 𝗓𝑅 requires 𝖨𝖽ℕ(𝟢,𝟢), discharged by 𝗋𝖾𝖿𝗅; the case 𝗌𝑅 𝑚 𝑛 𝑞 has an induction hypothesis 𝑝 :𝖨𝖽ℕ(𝑚,𝑛) and requires 𝖨𝖽ℕ(𝗌𝗎𝖼𝑚,𝗌𝗎𝖼𝑛), discharged by 𝖺𝗉𝗌𝗎𝖼(𝑝).
From 𝖨𝖽ℕ( −, −) to N: it suffices, by 𝖩 with motive 𝜆𝑚. 𝜆𝑛. 𝜆_. N 𝑚 𝑛, to give N 𝑚 𝑚 for every 𝑚, and that is obtained by induction on 𝑚 with 𝗂𝗇𝖽ℕ: the base case is 𝗓𝑅 and the step case is 𝗌𝑅 𝑚 𝑚 applied to the induction hypothesis. ◻
Lemma 164.13 is what makes a relational conclusion at ℕ usable: the abstraction theorem produces N, and the statement we want is an identity. The same question at an arbitrary type is the identity extension property, and remark 164.18 records exactly what is and is not available.
Let ⋅ ⊢𝑐 :𝖢𝗅𝗂𝖾𝗇𝗍. Then 𝖨𝖽ℕ(𝑐ℕ𝟢𝗌𝗎𝖼(𝜆𝑛.𝑛),𝑐(ℕ×ℕ)(𝟢,𝗌𝗎𝖼𝟢)(𝜆𝑝.(𝗌𝗎𝖼(𝗉𝗋1𝑝),𝗉𝗋2𝑝))(𝜆𝑝.𝗉𝗋1𝑝)) is inhabited.
Referenced from 4 locations
Proof of Theorem 164.14 — Representation independence for the counter
Proof. Proof idea. Instantiate the relation variable of example 164.12 at the relation “the first state is the first component of the second”, check the three relatedness hypotheses, and convert the relational conclusion at ℕ into an identity by lemma 164.13. The extra component of the second implementation is never mentioned by the relation, which is why it cannot be observed.
By corollary 164.10 we have 𝑐𝖱 :𝖢𝗅𝗂𝖾𝗇𝗍𝖱 𝑐 𝑐. Instantiate the first three arguments with 𝑆1:=ℕ,𝑆2:=ℕ×ℕ,𝑆𝑅:=𝜆𝑛.𝜆𝑝.𝖨𝖽ℕ(𝑛,𝗉𝗋1𝑝).
Initial states. The required type is 𝑆𝑅 𝟢 (𝟢,𝗌𝗎𝖼𝟢), which computes as 𝑆𝑅𝟢(𝟢,𝗌𝗎𝖼𝟢)𝛽≡𝖨𝖽ℕ(𝟢,𝗉𝗋1(𝟢,𝗌𝗎𝖼𝟢))𝗉𝗋1−𝑐𝑜𝑚𝑝.≡𝖨𝖽ℕ(𝟢,𝟢), inhabited by 𝗋𝖾𝖿𝗅.
Step functions. The required type is ∏𝑛:ℕ∏𝑝:ℕ×ℕ𝑆𝑅𝑛𝑝→𝑆𝑅(𝗌𝗎𝖼𝑛)((𝜆𝑝.(𝗌𝗎𝖼(𝗉𝗋1𝑝),𝗉𝗋2𝑝))𝑝). Given 𝑞 :𝖨𝖽ℕ(𝑛,𝗉𝗋1𝑝), the target computes as 𝑆𝑅(𝗌𝗎𝖼𝑛)(𝗌𝗎𝖼(𝗉𝗋1𝑝),𝗉𝗋2𝑝)𝛽, 𝗉𝗋1−𝑐𝑜𝑚𝑝.≡𝖨𝖽ℕ(𝗌𝗎𝖼𝑛,𝗌𝗎𝖼(𝗉𝗋1𝑝)), inhabited by 𝖺𝗉𝗌𝗎𝖼(𝑞).
Readouts. The required type is ∏𝑛:ℕ∏𝑝:ℕ×ℕ𝑆𝑅 𝑛 𝑝 →N 𝑛 (𝗉𝗋1𝑝), and given 𝑞 :𝖨𝖽ℕ(𝑛,𝗉𝗋1𝑝) the conclusion follows from lemma 164.13 in the direction from identities to N.
Conclusion. Instantiating 𝑐𝖱 at these twelve arguments gives a term of type N(𝑐ℕ𝟢𝗌𝗎𝖼(𝜆𝑛.𝑛))(𝑐(ℕ×ℕ)(𝟢,𝗌𝗎𝖼𝟢)(𝜆𝑝.(𝗌𝗎𝖼(𝗉𝗋1𝑝),𝗉𝗋2𝑝))(𝜆𝑝.𝗉𝗋1𝑝)), and lemma 164.13 in the direction from N to identities gives the displayed inhabitant. ◻
Let ⋅ ⊢𝑔 :∏𝐴:U0𝐴 →𝐴. Fix 𝐴 :U0 and 𝑎 :𝐴, and instantiate 𝑔𝖱 at 𝐴1:=𝐴,𝐴2:=𝐴,𝐴𝑅:=𝜆𝑥.𝜆𝑦.𝖨𝖽𝐴(𝑦,𝑎),𝑥1:=𝑎,𝑥2:=𝑎,𝑥𝑅:=𝗋𝖾𝖿𝗅. The hypothesis 𝐴𝑅 𝑎 𝑎 computes to 𝖨𝖽𝐴(𝑎,𝑎) and is inhabited by 𝗋𝖾𝖿𝗅, and the conclusion is 𝐴𝑅 (𝑔 𝐴 𝑎) (𝑔 𝐴 𝑎), which computes to 𝖨𝖽𝐴(𝑔 𝐴 𝑎,𝑎). Hence 𝑔 𝐴 𝑎 =𝑎 for every 𝐴 and 𝑎: no closed term of that type can behave as (164.1) describes. The relation 𝐴𝑅 used here is not the graph of a function and is not symmetric; the universe clause of definition 164.6 permits it because it quantifies over all relations.
Referenced from 6 locations
★☆☆ Let ⋅ ⊢𝑘 :∏𝐴:U0∏𝐵:U0𝐴 →𝐵 →𝐴. Choose relations and arguments as in example 164.15 and derive 𝖨𝖽𝐴(𝑘 𝐴 𝐵 𝑎 𝑏,𝑎). State which of the two relation variables must be instantiated at a singleton relation and why the other may be arbitrary.
Referenced from 3 locations
★★☆ Compute (∑𝐴:U0𝐴×(𝐴→𝐴))𝖱 𝑝1 𝑝2 in full by definition 164.7, and show that its inhabitants are exactly the triples consisting of a relation between the two carriers together with proofs that the two chosen elements and the two chosen functions are related. Then exhibit two closed elements of that sum whose relatedness fails for every relation, and name the component at which it fails.
Referenced from 2 locations
★★☆ Theorem 164.9 concludes Γ𝖱 ⊢𝑎𝖱 :𝐴𝖱 𝑎1 𝑎2, not Γ𝖱 ⊢𝑎𝖱 :𝐴𝖱 𝑎 𝑎.
Explain, using definition 164.6 for contexts, why the two statements differ for an open term, and give a term for which the second is not even well typed.
Show that they coincide for a closed term, and identify the clause of definition 164.6 that makes this work.
Referenced from 2 locations
Identity types, universes, and what is not derivable
Lemma 164.13 converted a relational conclusion at ℕ into an identity. The general question is whether 𝐴𝖱, instantiated at the reflexive relations, is the identity type of 𝐴.
The closed type 𝐴 of S satisfies identity extension when for all 𝑎1,𝑎2 :𝐴 the types 𝐴𝖱 𝑎1 𝑎2 and 𝖨𝖽𝐴(𝑎1,𝑎2) are logically equivalent.
Referenced from 2 locations
If ℕ →ℕ satisfies identity extension, then for all 𝑓1,𝑓2 :ℕ →ℕ, (∏𝑛:ℕ𝖨𝖽ℕ(𝑓1𝑛,𝑓2𝑛)) ⟶ 𝖨𝖽ℕ→ℕ(𝑓1,𝑓2) is inhabited.
Referenced from 3 locations
Proof of Proposition 164.17 — Identity extension is at least function extensionality
Proof. Unfolding definition 164.6 at the non-dependent product, (ℕ→ℕ)𝖱𝑓1𝑓2≡∏𝑛1:ℕ∏𝑛2:ℕN𝑛1𝑛2→N(𝑓1𝑛1)(𝑓2𝑛2). Assume 𝐻 of type ∏𝑛:ℕ𝖨𝖽ℕ(𝑓1 𝑛,𝑓2 𝑛), and let 𝑛1,𝑛2 and 𝑞 :N 𝑛1 𝑛2 be given. By lemma 164.13, 𝑞 yields 𝖨𝖽ℕ(𝑛1,𝑛2), and transporting 𝐻 𝑛1 along it gives 𝖨𝖽ℕ(𝑓1 𝑛1,𝑓2 𝑛2); the same lemma turns that back into N (𝑓1𝑛1) (𝑓2𝑛2). Hence 𝐻 yields an element of (ℕ→ℕ)𝖱 𝑓1 𝑓2, and identity extension converts it into 𝖨𝖽ℕ→ℕ(𝑓1,𝑓2). ◻
★☆☆ Show that ℕ and 𝟏 satisfy identity extension, and that ℕ ×ℕ does provided ℕ does. Then state what would have to be proved for ∑𝐴:U0𝐴, and identify the clause of definition 164.6 that makes the question depend on the universe.
Referenced from 2 locations
External and internal relational structure
Theorem 164.9 is a function on derivations, defined in the metatheory. Its instances are terms of S, but the function itself is not. A program of S that receives a term as input cannot apply the abstraction theorem to it, because the input is a value of a type, not a derivation.
The natural repair is to add the conclusion as an axiom.
Let S𝗉 be S extended, for every closed type 𝐵, with a constant 𝗉𝖺𝗋𝖺𝗆𝐵:∏𝑥:𝐵𝐵𝖱𝑥𝑥 and no computation rule.
Referenced from 3 locations
The assignment 𝗉𝖺𝗋𝖺𝗆𝐵 𝑎 ↦𝑎𝖱 does not define a translation from S𝗉 to S.
Referenced from 3 locations
Proof of Proposition 164.20 — The axiom has no local interpretation
Proof. Take 𝐵:=ℕ and the open term 𝑎:=𝑥 in the context 𝑥 :ℕ. Then 𝗉𝖺𝗋𝖺𝗆ℕ 𝑥 is well typed over 𝑥 :ℕ, whereas 𝑥𝖱 =𝑥𝑅 by definition 164.6, and 𝑥𝑅 is not declared in the context 𝑥 :ℕ. The proposed image is therefore not a term over the context of its source. ◻
S𝗉 has closed normal forms of type ℕ that are not numerals.
Referenced from 4 locations
Proof of Proposition 164.21 — The axiom breaks canonicity
Proof. Let 𝐵:=∏𝐴:U0𝐴 →𝐴 and let 𝗂𝖽:=𝜆𝐴. 𝜆𝑥. 𝑥. By example 164.15 the term 𝗉𝖺𝗋𝖺𝗆𝐵 𝗂𝖽, instantiated as there, has type 𝖨𝖽ℕ(𝗂𝖽 ℕ 𝟢,𝟢); call that term 𝑝. Now consider 𝖩(𝜆𝑢.𝜆𝑣.𝜆_.ℕ; 𝜆𝑢.𝗌𝗎𝖼𝑢; 𝑝). Its type is ℕ. It is closed. It has no reduction: the computation rule for 𝖩 in definition 164.4 fires only on 𝗋𝖾𝖿𝗅, and 𝑝 is headed by 𝗉𝖺𝗋𝖺𝗆𝐵, which has no computation rule by definition 164.19. ◻
The two propositions say what an internal account must supply that an axiom does not: a term former for relational structure must come with binders that place the relational variables in the context where they are needed, and with computation rules that let a proof built from it reduce. Both are changes to the syntax of S, not additions to its constants. A calculus that makes those changes replaces the metatheoretic operation −𝖱 by an operator of the object theory with its own formation, introduction, elimination and computation rules; the interval-free span calculus of Altenkirch, Kaposi and Shulman is one such system, and it is developed separately because its judgments and its metatheory are not those of definition 164.4.
Boundary
Proved here. The relational translation (definition 164.6, definition 164.7), its substitution lemma (lemma 164.8), the abstraction theorem (theorem 164.9) and its closed-term corollary, identity extension at ℕ (lemma 164.13), the free theorem for the polymorphic identity type (example 164.15), representation independence for the counter interface (theorem 164.14), and the two obstructions to internalizing the translation (proposition 164.20, proposition 164.21).
Owned elsewhere. The reflexive-graph model and its three theorems belong to Atkey, Ghani and Johann and hold at their signature, as recorded in remark 164.18. Proof-relevant relational structure — where a relation carries not a proposition but a type of witnesses — is a separate development; nothing above is generalized to it by analogy. Cubical paths and their bridge and Gel formers belong to the calculi that define them.
Inductive families. Definition 164.7 gives the clauses for ℕ and for the identity type by the same schema: a source inductive family with constructors 𝑐1,…,𝑐𝑘 translates to an inductive family with one constructor 𝑐𝖱𝑖 for each 𝑐𝑖, whose arguments are the translations of the arguments of 𝑐𝑖. The general statement for arbitrary inductive families, together with the argument that the translation preserves strict positivity and hence well-foundedness, is due to Bernardy, Jansson and Paterson; only the two instances used above are proved here.
Size indices. Uniformity can be used to control an index rather than a type: a quantifier that is parametric rather than continuous makes a function’s behaviour independent of the index it is instantiated at, and that is what allows an index to be treated as a size. The parametric quantifiers of Nuyts, Vezzosi and Devriese are the standard calculus for this, and their rules differ from those of definition 164.4: they distinguish a parametric from a continuous function type, with separate formation, introduction and elimination rules. This chapter defines no sized recursion calculus and proves no theorem about one.
Suggested first pass.
Problems exercise 164.6, exercise 164.5, and exercise 164.8 form the suggested first pass. None of these problems is a prerequisite for a later chapter.
★★★ Theorem 164.9 displayed the cases for variables, universes, products, abstraction, application and conversion, and delegated the sum, unit, natural-number and identity cases as copies of the product case. Write them.
Give the sum case in full: the formation, introduction and both elimination rules, checking at each step which clause of definition 164.7 is used and that the computation rules of definition 164.4 make the translated equations hold.
Give the case of 𝗂𝗇𝖽ℕ: state the translated motive, the two translated methods, and the type of the translated eliminator, and check that the translated computation rules follow from the source ones.
Give the case of 𝖩, and state exactly where the argument would fail if the identity type had the eliminator 𝖪 in addition.
Referenced from 3 locations
★★★ Replace the counter of definition 164.11 by a queue interface 𝖰𝖢𝗅𝗂𝖾𝗇𝗍:=∏𝑆:U0𝑆→(ℕ→𝑆→𝑆)→(𝑆→𝟏+(ℕ×𝑆))→ℕ, with the two standard implementations: a single list, and a pair of lists holding the front in order and the back reversed.
Write both implementations, using ℕ-indexed lists encoded with Σ and ℕ if no list former is available, and state the relation 𝑆𝑅 that relates them.
Compute 𝖰𝖢𝗅𝗂𝖾𝗇𝗍𝖱 as in example 164.12.
Prove the three relatedness hypotheses. The one for the dequeue operation requires a case analysis; display both cases and say which one needs the reversal.
Conclude representation independence, and state which step used lemma 164.13.
Referenced from 3 locations
★★☆ Investigate the boundary of theorem 164.14.
Add to 𝖢𝗅𝗂𝖾𝗇𝗍 a fourth argument of type 𝑆 →𝑆 →𝟐 testing states for equality, and exhibit two implementations of the extended interface, together with a client, for which the two runs differ. Identify the relatedness hypothesis that fails.
Show that if instead the fourth argument has type ℕ →ℕ →𝟐 the hypothesis is satisfied, and explain the difference in one sentence.
Referenced from 2 locations
★★★ Practical project.dependent-parametricity-translator Implement, in Agda, the relational translation of definition 164.6, definition 164.7 and use it to produce free theorems.
Calculus to implement. Represent the raw syntax of S restricted to U0, U1, dependent products, dependent sums, 𝟏, ℕ and identity types, with de Bruijn indices. Implement a bidirectional type checker for it and the translation −𝖱 as a function on raw terms, with the context translation of definition 164.6. Capture-avoiding substitution and the tripling of variables must both be handled explicitly: a source variable at de Bruijn index 𝑖 becomes three variables, and every index in a translated term must be recomputed.
Invariant. For every input derivation Γ ⊢𝑎 :𝐴 the program must produce a term 𝑎𝖱 that its own checker accepts at type 𝐴𝖱 𝑎1 𝑎2 in the context Γ𝖱. This is the executable form of theorem 164.9; the checker, not the translator, is the judge.
Concrete result. A report that, for each named input, prints the translated context, the translated type, the translated term, and the checker’s verdict.
Acceptance test. The following must be accepted, with the printed translated type equal to the one computed by hand in the chapter: the identity 𝜆𝐴. 𝜆𝑥. 𝑥 at ∏𝐴:U0𝐴 →𝐴, whose translation must be 𝜆𝐴1.𝜆𝐴2.𝜆𝐴𝑅.𝜆𝑥1.𝜆𝑥2.𝜆𝑥𝑅.𝑥𝑅; the term 𝜆𝐴. 𝜆𝐵. 𝜆𝑥. 𝜆𝑦. 𝑥 at the type of exercise 164.1; the counter clients of definition 164.11, whose translated type must match example 164.12 up to renaming; and 𝜆𝑛. 𝗌𝗎𝖼 𝑛 at ℕ →ℕ, whose translation must use 𝗌𝑅. The following must be rejected by the checker: the term 𝜆𝐴. 𝜆𝑥. 𝑥𝑅, in which a relational variable is used where a source variable is required; and a hand-written “translation” of 𝗂𝖽 that omits the argument 𝑥𝑅. Produce three mutations that still run — drop 𝑥𝑅 from the context translation, translate U0 to 𝜆𝑋1. 𝜆𝑋2. U0, and translate a product without the relatedness argument — and confirm that each makes the checker reject at least one accepted case. State explicitly that the program illustrates theorem 164.9 on finitely many derivations and does not prove it.
Referenced from 3 locations