Approximations, Fibrations and Intersection Type Systems

Damiano Mazza*, Luc Pellissier† & Pierre Vial‡ June 16, 2017

Introduction The discovery of linear logic [7] has introduced the notionof linearity in computer science and proof theory. A remarkable fact of linear logic lies in its approximation theorem, stating that an arbitrary proof (not necessarily linear, that is, using its premisses any number of times) can be approximated arbitrarily well by a linear proof. This notion of approximation has then been explored in different directions [4, 10,14]. Approximations are known to be related to relational models, which in turn are related to intersection types [2, 12, 13]. In this work, we investigate approximations in the “type-systems as functors” perspective pioneered by [11]. After recasting fundamental properties of type systems, such as subject reduction and expansion in this framework, we give an intersection framework for linear logic, whose derivations are simply-typed approximations. Any calculus that translates meaningfully to linear logic is then endowed by a intersection type system, computed by pulling back one of these intersection type systems for linear logic, and which inherit its properties. All standard intersection type systems (idempotent, such as in [6, 1] or not, such as in [3]) for call-by-name and call-by-value λ-calculus, characterizing weak, strong, and head normalization, fit in this picture, thus justifying the equation:

Simply-typed approximations = intersection types derivations.

We moreover obtain new type systems, by considering other translations and reductions.

1 What is a type system? The starting point of this research is the work of [11]. From their perspective, a type system isafunctor U ∶ 풟 → 풞 from a category 풟, seen as a category of types and type derivations, to a category 풞 whose arrows are thought of as untyped terms. The functor U is then simply a forgetful functor that maps a derivation to its subject. We add the two following twists: • we find more natural to consider programs with possibly more than one free variable. For this reason, we will move fromcategoriesto multicategories, which are structures similar to categories, but with morphisms having multiple sources 푓 ∶ A 1,…,A 푛 → B. • we are interested not only in the static behavior of programs but also in the dynamical aspects, i.e. reductions between programs. We add a second dimension to the multicategory by considering arrows (representing reductions) between the multiarrows. To sum up, we will consider our languages to be symmetric Cat-multicategories, or, for short, Cat-operads.1 Seen as a type system, a morphism of operads type not only the terms but also some reductions. As we aim to capture in the type system the properties of the reduction, the derivation reductions are to closely mirror the term reductions. This prompts us to give the following definition: Definition 1 (type system) Let 풞 be a Cat-operad. A type system for 풞 is a morphism of Cat-operads F ∶ 풟 → 풞 such that, for all 2-morphisms 푓 ∶ 푡 ⇒ 푡′, (composition) if F푓 = 푔 ∘ ℎ, then, there exists 푘, ℓ such that 푓 = 푘 ∘ ℓ, F푘 = 푔 and Fℓ = ℎ;

(identity) if F푓 = id푎, then 푓 is an identity.

Intuitively, these conditions ensure that a typable reduction path in 풞 can be simulated in 풟 by a path of same length. Though conceptually clear, this definition does not give any insight on how to define a type system: in particular, theoperad 풟 may be a mysterious. We can give an equivalent definition of a dynamic type system by applying a variant of the Grothendieck construction. Theorem 1

A type system F for 풞, with types in a 핋 is equivalent to a family of functors (FΓ;A ∶ 풞 (FΓ; FA) → Rel)Γ∈핋∗,A∈핋 that verify all possible composition equations. This equivalence is expressed as an equivalence of categories.

′ We understand the set FΓ;A(푡) as the set of all type derivations of Γ ⊢ 푡 ∶ A in the type system F and the relation FΓ;A(θ) ⊆ FΓ;A(푡) × FΓ;A(푡 ) is to be understood as relating couples of derivations following the reduction θ ∶ 푡 → 푡′.

*LIPN, CNRS & Université Paris 13, [email protected] †LIPN, Université Paris 13, [email protected] ‡IRIF, Université Paris Diderot, [email protected] 1. The standard terminology would be colored Cat-operads, the colors being the different objects. We prefer to drop the “colored” adjective because this is the default situation in our setting.

1 2

Ξ1; ⊢ 푡1 ⊏ M ∶ A 1 …Ξ푛; ⊢ 푡푛 ⊏ M ∶ A 푛 pvar box ξ푖 ⊏ ξ ∶ A; ⊢ ξ푖 ⊏ ξ ∶ A Ξ1,…,Ξ푛; ⊢ ⟨푡1, … , 푡푛⟩ ⊏ !M ∶ ⟨A 1,…,A 푛⟩

Υ; Δ ⊢ 푢 ⊏ N ∶ ⟨A 1,…,A 푛⟩ Ξ, ξ1 ⊏ ξ ∶ A 1,…, ξ푛 ⊏ ξ ∶ A 푛; Γ ⊢ 푡 ⊏ M ∶ C let Ξ, Υ; Γ, Δ ⊢ 푡[⟨ξ1, … , ξ푛⟩ ∶= 푢] ⊏ M[!ξ ∶= N] ∶ C

Figure 1: Main rules of polyadic derivations, with term assignment (in green) and approximations (in gray).

2 Subject reduction and opfibrations This language is rich enough to express fundamental properties of type systems such as subject reduction and subject expansion. Indeed,a type system F ∶ 풟 → 풞 is said to have subject reduction if, for every reduction θ ∶ F푑 → 푐 in 풞, there exists a (non-necessarily unique) reduction κ ∶ 푑 → 푑′ in 풟 such that Fκ = θ. This property is reminiscent of the notion of opfibration, but the lifted morphism doesnot have any property of unicity nor canonicity. Hence, a type system enjoying subject reduction is a pointwise weak discrete opfibration. Through the equivalence of Theorem 1, a type system enjoying subject reduction is equivalent to a family of functors thatmapevery reduction to an entire relation, that is, for all reduction θ ∶ 푡 ⇒ 푡′, type context Γ and type A, we have:

′ ∀푥 ∈ FΓ;A(푡), ∃푦 ∈ FΓ;A(푡 ), (푥, 푦) ∈ FΓ;A(θ). That means that to every type derivation of Γ ⊢ 푡 ∶ A corresponds at least one type derivation of Γ ⊢ 푡′ ∶ A following the reduction θ. This is stronger than subject reduction usually defined as we ask the type derivation of the reduct 푡′ not only to exist, but to be related to the type derivation of the term 푡. We believe this strengthening to be not only harmless, but also desirable, as it reflects the way subject reduction is proved in practice. In the same way, a type system enjoying subject expansion corresponds to a family of functors that map reductions to op-entire relations, and one that enjoy both subject reduction and expansion corresponds to a family of functors into bi-entire relations. To sum up, we can specify a type system by associating to a term 푡, a context Γ and a type A the set of type derivations Γ ⊢ 푡 ∶ A, and to a reduction a relation coupling derivations that simulates the reduction. The type system satisfies subject reduction if all these relations are entire.

3 Simply-typed approximations are an intersection type system for linear logic…

We are now ready to give a type system enjoying both subject reduction and subject expansion for the λ-calculus Λ! of linear logic (that is a λ-calculus with explicit boxes and substitutions). Figure 1 shows (in different colors) the key term assignment rules of both the calculus Λ! (whose terms are written M, N,…), the approximating calculus Λ푝 (whose terms are written 푡, 푢,…), the approximation rules (the approximation relation is written 푡 ⊏ M) and the typing rules of the approximations. Given a context Γ and a type A, we define a relational presheaf 픸Γ;A ∶ Λ! → Rel by associating to every term of Λ! its set of approxima- tions typable by A under the context Γ, and to every reduction M → M ′ the set of couples (푡, 푡′) such that 푡 approximates M (respectively 푡′ approximates M ′) and the reduction 푡 → 푡′ simulates M → M ′. By giving limitations on the shape of the types, we can use this system to characterize strong normalization for different (non-deterministic) reductions of Λ!, such as shallow reduction (the reduction happens only outside of boxes), Böhm reduction, and non-erasing reduction (a box can only be erased if its content is in normal form).

4 …pulled back into all intersection type systems Let us suppose that we want to compute a type system for a calculus ℒ, and that this calculus has a translation ℒ → Λ , where Λ is ;! ;! a restriction of Λ! for a certain notion of reduction . We assume moreover that we have computed a sound and complete type system ℰ (픸) → Λ . A sound and complete type system 풟 → ℒ can be computed by the pullback ;! ;

풟 ℒ

ℰ (픸) Λ ;!

We can in this way recover usual intersection type systems (idempotent or non-idempotent) characterizing weak, strong and head normal- ization for both the call-by-name λ-calculus and the call-by-value λ-calculus by using Girard-like translations.

5 Two variants: λμ-calculus and infinitary λ-calculus

In order to accommodate λμ-calculus in our framework and compute intersection type systems for it, we need to replace the operad Λ! by a (cyclic) operad of proof-nets, in which we may embed the λμ-calculus, through the Laurent translation. It is then sufficient to define approximations for proof-nets (a variant of the Taylor expansion) to get intersection type systems. The intersection type systems computed by pulling them back along the Laurent translation have been defined and studied by Kesner and Vial [9]. In the same way, we can study a base system of infinitary linear λ-calculus, to compute intersection type systems for infinitary λ-calculi, such as presented in [5, 8]. Bibliography 3

Bibliography [1] Sébastien Carlier et al. “System E: Expansion Variables for Flexible Typing with Linear and Non-linear Types and Intersection Types”. In: Proceedings of ESOP 2004. 2004, pp. 294–309. [2] Daniel de Carvalho. “Execution Time of lambda-Terms via Denotational Semantics and Intersection Types”. In: CoRR abs/0905.4251 (2009). [3] Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. “Functional Characters of Solvable Terms”. In: Math. Log. Q. 27.2-6 (1981), pp. 45–58. [4] Thomas Ehrhard and Laurent Regnier. “Uniformity and the Taylor expansion of ordinary lambda-terms”. In: Theoretical Computer Science 403.2-3 (2008), pp. 347–372. [5] Jörg Endrullis et al. “A Coinductive Framework for Infinitary Rewriting and Equational Reasoning (Extended Version)”. In: CoRR abs/1505.01128 (2015). [6] Philippa Gardner. “Discovering Needed Reductions Using ”. In: Proceedings of TACS. 1994, pp. 555–574. [7] Jean-Yves Girard. “Linear logic”. In: Theoretical Computer Science 50.1 (1987), pp. 1–101. [8] Richard Kennaway et al. “Infinitary Lambda Calculus”. In: Theor. Comput. Sci. 175.1 (1997), pp. 93–125. [9] Delia Kesner and Pierre Vial. “Types as Resources for Classical Natural Deduction”. In: FSCD 2017. [10] Assaf J. Kfoury. “A linearization of the Lambda-calculus and consequences”. In: J. Log. Comput. 10.3 (2000), pp. 411–436. [11] Paul-André Melliès and Noam Zeilberger. “Functors are Type Refinement Systems”. In: POPL 2015. New York, USA: ACM Press, 2015, pp. 3–16. [12] Peter Møller Neergaard and Harry G. Mairson. “Types, potency, and idempotency: why nonlinearity and amnesia make a type system work”. In: Proceedings of ICFP. 2004, pp. 138–149. [13] Elaine Pimentel, Simona Ronchi Della Rocca, and Luca Roversi. “Intersection Types from a Proof-theoretic Perspective”. In: Fundam. Inform. 121.1-4 (2012), pp. 253–274. [14] Laurent Regnier. “Lambda-calcul et réseaux”. PhD Thesis. Université Paris 7, 1992.