Normalization by Gluing for Free 휆-Theories
Total Page:16
File Type:pdf, Size:1020Kb
Normalization by gluing for free 휆-theories Jonathan Sterling* Bas Spitters† Carnegie Mellon University Aarhus University December 30, 2018 Abstract The connection between normalization by evaluation, logical predicates and semantic gluing constructions is a matter of folklore, worked out in varying degrees within the literature. In this note, we present an elementary version of the gluing technique which corresponds closely with both semantic normalization proofs and the syntactic normalization by evaluation We will expand in more detail the insight presented in Streicher’s short note [Stre- icher, 1998] and in Fiore [2002], giving some explicit constructions. We will be consid- ering the case of free 휆-theories generated from many-typed first-order signatures. 1 휆-signatures and 휆-theories Definition 1.1 (Arity). A simply-typed first-order arity for a set 푇 of atomic types is a pair 훼 ≡ (휎,⃗ 휏) of a list of types and a types. We write 푇† ≝ 푇⋆ × 푇 for the set of such arities. Definition 1.2 (Many-typed signature). Following Jacobs [1999], a many-typed signa- ture Σ ≡ (풰, 휕) is a set of atomic types 풰 together with an arity-indexed family of sets of operations 휕, taking each operation 휗 to 휕(휗) ∈ 풰†. More abstractly, the category Sig of such signatures arises as the pullback of the fundamental fibration along the arity endofunctor. 휕 Sig Set→ ⌟ 풰 cod Set Set (−)† *[email protected] †[email protected] 1 From a collection of atomic types 풰, we generate the type structure of the 휆-calculus as the least set 풰̃ closed under the following formation rules: 휏 ∈ 풰 휎 ∈ 풰̃ 휏 ∈ 풰̃ 휎 ∈ 풰̃ 휏 ∈ 풰̃ 휏 ∈ 풰̃ 휎 × 휏 ∈ 풰̃ 휎 → 휏 ∈ 풰̃ 1.1 The clone of a 휆-signature From a 휆-signature Σ we can freely generate a special family of sets CnΣ(Γ, 휏) called its ̃† clone, indexed in (Γ, 휏) ∈ 풰Σ ; simultaneously, we define the indexed set of substitu- ̃⋆ ̃⋆ tions SbΣ(Γ, Δ), indexed in (Γ, Δ) ∈ 풰Σ × 풰Σ . In our presentation, we choose to use explicit substitutions rather than implicit substitutions, because they are more abstract and allow a formulation without explicit reference to preterms. Additionally, explicit substitutions scale up to the metatheory of dependent type theory in a way that the im- plicit (admissible) notion of substitution on preterms cannot. We will write Γ ⊢Σ 푡 ∶ 휏 and Γ ⊢Σ 훿 ∶ Δ to mean that 푡 ∈ CnΣ(Γ, 휏) and 훿 ∈ SbΣ(Γ, Δ) respectively, and Γ ⊢Σ 푠 = 푡 ∶ 휏 and Γ ⊢Σ 훿0 = 훿1 ∶ Δ to mean that 푠 and 푡 are equal elements of CnΣ(Γ, 휏) and 훿0 and 훿1 are equal elements of SbΣ(Γ, Δ) respectively. In our notation, we presuppose that 푠 and 푡 are elements of the clone when we state that they are equal. The clone of Σ is defined as a quotient using the following indexed inductive defini- tion: operation subst variable 휕Σ(휗) ≡ (Γ, 휏) Γ ⊢Σ 훿 ∶ Δ Δ ⊢Σ 푡 ∶ 휏 Γ, 휏 ⊢Σ v ∶ 휏 Γ ⊢Σ 휗 ∶ 휏 Γ ⊢Σ 푡[훿] ∶ 휏 abstraction application pair Γ, 휎 ⊢Σ 푡 ∶ 휏 Γ ⊢Σ 푠 ∶ 휎 → 휏 Γ ⊢Σ 푡 ∶ 휎 Γ ⊢Σ 푠 ∶ 휎 Γ ⊢Σ 푡 ∶ 휏 휎 Γ ⊢Σ 휆 (푡) ∶ 휎 → 휏 Γ ⊢Σ 푠(푡) ∶ 휏 Γ ⊢Σ (푠, 푡) ∶ 휎 × 휏 proj1 proj2 Γ ⊢Σ 푠 ∶ 휎 × 휏 Γ ⊢Σ 푠 ∶ 휎 × 휏 Γ ⊢Σ 푠.1 ∶ 휎 Γ ⊢Σ 푠.2 ∶ 휏 sb/ext sb/idn sb/proj Γ ⊢Σ 훿 ∶ Δ Γ ⊢Σ 푡 ∶ 휏 Γ ⊢Σ idΓ ∶ Γ Γ, 휏 ⊢Σ p ∶ Γ Γ ⊢Σ 훿.푡 ∶ Δ, 휏 sb/cmp Γ ⊢Σ 훿 ∶ Δ Δ ⊢Σ 휉 ∶ Ξ Γ ⊢Σ 휉 ∘ 훿 ∶ Ξ Before we define the equivalence relation by which the clone is quotiented, it will be useful to define an auxiliary substitution for De Bruijn lifting: ⇑[훾] ≝ (p ∘ 훾).v 2 Next, we generate equivalence relations on terms and substitutions from the follow- ing rules: app/beta abs/eta 휎 휎 Γ ⊢Σ (휆 (푡))(푠) = 푡[idΓ.푠] ∶ 휏 Γ ⊢Σ 푡 = 휆 ((푡[p])(v)) ∶ 휎 → 휏 fst/beta snd/beta pair/eta Γ ⊢Σ (푠, 푡).1 = 푠 ∶ 휎 Γ ⊢Σ (푠, 푡).2 = 푡 ∶ 휏 Γ ⊢Σ 푡 = (푡.1, 푡.2) ∶ 휎 × 휏 sb/cmp/idn/l sb/cmp/idn/r sb/cmp/assoc Γ ⊢Σ idΔ ∘ 훿 = 훿 ∶ Δ Γ ⊢Σ 훿 ∘ idΓ = 훿 ∶ Δ Γ ⊢Σ 훾 ∘ (훿 ∘ 휉) = (훾 ∘ 훿) ∘ 휉 ∶ Δ sb/cmp/proj sb/cmp/dot sb/var/idn Γ ⊢Σ p ∘ 훿.푡 = 훿 ∶ Δ Γ ⊢Σ 훿 ∘ (휉.푡) = (훿 ∘ 휉).푡[훿] ∶ Δ Γ ⊢Σ v[idΓ] = v ∶ 휏 sb/var/ext sb/abs 휎 휎 Γ ⊢Σ v[훿.푡] = 푡 ∶ 휏 Γ ⊢Σ (휆 (푡))[훿] = 휆 (푡[⇑[훿]]) ∶ 휎 → 휏 sb/app sb/pair Γ ⊢Σ (푡(푠))[훿] = 푡[훿](푠[훿]) ∶ 휏 Γ ⊢Σ (푠, 푡)[훿] = (푠[훿], 푡[훿]) ∶ 휎 × 휏 sb/proj1 sb/proj2 Γ ⊢Σ 푡.1[훿] = (푡[훿]).1 ∶ 휎 Γ ⊢Σ 푡.2[훿] = (푡[훿]).2 ∶ 휏 We omit the congruence cases for brevity. The clone of Σ is now defined as the indexed family of quotients generated by the formation and definitional equivalence rules given above. Representation of the quotient In these notes, we will not dwell on the technical repre- sentation of the quotiented terms. However, we will remark that the most convenient induction principle for the quotiented syntax would arrive from a presentation as a quo- tient inductive type; moreover, our inductive definition falls under a schema for finitary quotient inductive types which is already known to be interpretable in the setoid model of type theory [Dybjer and Moeneclaey, 2018]. 1.2 The classifying category of a 휆-signature We can see that the language of substitutions above has the structure of category; this cat- egory is in fact called ClΣ, the classifying category or Lawvere category of the 휆-signature Σ. The classifying category is also just called the (pure) 휆-theory generated by the sig- nature. Concretely, it has contexts Γ as objects, and equivalence classes of substitutions Γ ⊢Σ 훿 ∶ Δ as morphisms. Proposition 1.3. The classifying category ClΣ is cartesian closed. 1.3 The category of renamings Every 휆-signature gives rises to another category, namely the category of renamings RenΣ. Abstractly, this can be characterized as the free strictly associative cartesian category 3 ̃ generated by 풰Σ; concretely, its objects are contexts Γ, and its morphisms 휓 ∶ RenΣ[Γ, Δ] are vectors of projections (indices) from Γ into the types in Δ. An explicit presentation of RenΣ appears in Fiore [2002, 2005] as the opposite of the ̃ comma category ⌊−⌋ ↓ Const(풰Σ), where ⌊−⌋ ∶ 픽 → Set takes a finite cardinal to a set. ̃ ̃ Fiore writes 픽 ↓ 풰Σ for this comma construction, and 픽[풰Σ] for its opposite. Another possible presentation of Ren휎 is as the subcategory of ClΣ which has the same objects, but whose morphisms are all of the form idΓ or idΓ.푡0.⋯ 푡푛 for some 푛 > 0, with 푡푖 of the form v[p푘], writing p푘 for the 푘-fold composition of p with itself. 2 Normalization and the Yoneda embedding Working in a constructive metatheory, we can see that the intensional content of a cer- tain natural isomorphism hides within it a normalization function for the lambda calcu- ̂ lus over Σ, as observed in Čubrić et al. [1998]. Let ClΣ denote the category of presheaves over the classifying category of Σ. ̂ The Yoneda embedding is a cartesian closed functor y ∶ ClΣ → ClΣ, defined as yΔ = ClΣ[−, Δ]. Within the presheaf topos, it is easiest to think of the representable objects yΔ as the “type of substitutions into Δ”. There is another way to define the Yoneda embedding, which we will see is naturally ̂ isomorphic to what is written above. In this version, we define a functor [y] ∶ ClΣ → ClΣ by recursion on the objects of ClΣ. For an atomic type 휏 ∈ 풰Σ, [y]휏 = y휏; but the remainder of the cases are defined using the cartesian closed structure of the presheaf topos instead of the cartesian closed structure of the classifying category: [y](휎 × 휏) = [y]휎 × [y]휏 [y](휎 → 휏) = [y]휏[y]휎 Now, because the Yoneda embedding is cartesian closed, it is easy to see that we have a natural isomorphism y ≅ [y]. However, observe that the elements in the fibers of [y] are not 휆-terms, but a kind of eta-long Boehm-tree representation of 휆-terms. That is, whereas the action of y on a syntactic morphism/term Γ ⊢Σ 푡 ∶ 휎 × 휏 is to simply embed 푡 into the appropriate presheaf fiber, the action of [y] on the same term must take 푡 to an element of [y]휎 × [y]휏, that is, an actual pair. Considering the case where 푡 is actually a variable, we can see that the action of these two embeddings is intensionally quite different. The other side of the natural isomorphism is witnessed by a “readback” operation, which reads one of these expanded Boehm trees into a syntactic term (which can be seen to be 훽-normal and 휂-long). The normalization operation obtained by composing these operations can be seen to be an instance of normalization by evaluation. The problem with this kind of result, however, is that the categories have quotiented too much for us to be able to say in mathematical (rather than merely intuitive) language that we have obtained a normalization function.