Computational and Fine-Structure Aspects of Intersection Types A personal encounter with intersection types Jakob Rehof Technische Universit¨ at Dortmund TLT – Types and Logic in Torino Colloquium in honor of Mariangiola Dezani-Ciancaglini, Simona Ronchi Della Rocca and Mario Coppo Torino, Italy, September 22, 2017
From the Beginning ... Intersection types combine great logical simplicity and beauty with enormous expressive power, capturing deep semantic properties of λ -terms (normalization, solvability, ...) 2 / 55
Motivations The classical decision problems (typability and inhabitation) are undecidable for intersection types. Still, many interesting and useful problems can be solved computationally. Fine structure: Explore borderline between decidability and undecidability. Computational aspects: Algorithms & complexity of components and restrictions of the system. Applications: Intersection types as specifications (in typability, type checking, program analysis, refinement, synthesis, ...) 3 / 55
Acknowledgements My students in Dortmund (former and present) including: Jan Bessai (Dortmund), Boris D¨ udder (formerly Dortmund, now Copenhagen), Andrej Dudenhefner (Dortmund), Moritz Martens (formerly Dortmund, now in industry) Collaborators and colleagues, including: Mariangiola Dezani, Simona Ronchi Della Rocca, Mario Coppo and the Torino λ -calculus group, Tzu-Chun Chen (Darmstadt), George Heineman (WPI Boston), Ugo de’Liguoro (Torino), Paweł Urzyczyn, Aleksy Schubert and the Warsaw group, and Roger Hindley (Swansey) 4 / 55
“BCD” [BCDC83] 5 / 55
Intersection Types Definition The set T of intersection types, ranged over by σ, τ, ρ , is given by T ∋ σ, τ, ρ ::= a | α | ω | σ → τ | σ ∩ τ where a , b , c , . . . range over type constants drawn from the set C , ω is a special (universal type) constant, and α, β, γ range over type variables drawn from the set V . As a matter of notational convention, function types associate to the right, and ∩ binds stronger than → . A type τ ∩ σ is said to have τ and σ as components . Intersection ∩ is tacitly ACI. 6 / 55
λ -Calculus with Intersection Types Definition ([CDCV80],[BCDC83], . . . ) Γ , x : σ ⊢ M : τ (Var) ( → I) Γ , x : τ ⊢ x : τ Γ ⊢ λ x . M : σ → τ Γ ⊢ M : σ → τ Γ ⊢ N : σ ( → E) Γ ⊢ M N : τ Γ ⊢ M : τ 1 Γ ⊢ M : τ 2 ( ∩ I) Γ ⊢ M : τ 1 ∩ τ 2 Γ ⊢ M : τ 1 ∩ τ 2 ( ∩ E) Γ ⊢ M : τ τ ≤ σ ( ≤ ) Γ ⊢ M : τ i Γ ⊢ M : σ The system is centrally placed in the theory of typed λ -calculus, see Barendregt, Dekkers, Statman, Lambda Calculus with Types [BDS13]. 7 / 55
Subtyping (BCD) Definition Subtyping ≤ is the least preorder (reflexive and transitive relation) over T (cf. [BCDC83]) such that σ ≤ ω, ω ≤ ω → ω σ ∩ τ ≤ σ, σ ∩ τ ≤ τ ( σ → τ 1 ) ∩ ( σ → τ 2 ) ≤ σ → τ 1 ∩ τ 2 σ ≤ τ 1 ∧ σ ≤ τ 2 ⇒ σ ≤ τ 1 ∩ τ 2 σ 2 ≤ σ 1 ∧ τ 1 ≤ τ 2 ⇒ σ 1 → τ 1 ≤ σ 2 → τ 2 Write σ = τ for σ ≤ τ ∧ τ ≤ σ . Then ∩ is ACI, and ( σ → τ 1 ) ∩ ( σ → τ 2 ) = σ → ( τ 1 ∩ τ 2 ) ( σ 1 → τ 1 ) ∩ ( σ 2 → τ 2 ) ≤ ( σ 1 ∩ σ 2 ) → ( τ 1 ∩ τ 2 ) 8 / 55
Subtyping (BCD) Problem (Subtyping) Given σ, τ ∈ T , does σ ≤ τ hold? Lemma (Beta-Soundness [BCDC83]) Given σ = � i ∈ I ( σ i → τ i ) ∩ � a j ∩ � k ∈ K α k , we have j ∈ J ( i ) If σ ≤ a for some a ∈ C , then a ≡ a j for some j ∈ J. ( ii ) If σ ≤ α for some α ∈ V , then α ≡ α k for some k ∈ K. ( iii ) If σ ≤ σ ′ → τ ′ � ω for some σ ′ , τ ′ ∈ T , then I ′ = { i ∈ I | σ ′ ≤ σ i } � ∅ and i ∈ I ′ τ i ≤ τ ′ . � Theorem ([DMR17]) Subtyping is decidable in quadratic time. 9 / 55
Subtyping (BCD) Problem (Subtyping) Given σ, τ ∈ T , does σ ≤ τ hold? Lemma (Beta-Soundness [BCDC83]) Given σ = � i ∈ I ( σ i → τ i ) ∩ � a j ∩ � k ∈ K α k , we have j ∈ J ( i ) If σ ≤ a for some a ∈ C , then a ≡ a j for some j ∈ J. ( ii ) If σ ≤ α for some α ∈ V , then α ≡ α k for some k ∈ K. ( iii ) If σ ≤ σ ′ → τ ′ � ω for some σ ′ , τ ′ ∈ T , then I ′ = { i ∈ I | σ ′ ≤ σ i } � ∅ and i ∈ I ′ τ i ≤ τ ′ . � Theorem ([DMR17]) Subtyping is decidable in quadratic time. 9 / 55
Subtyping (BCD) Problem (Matching) Given a set of constraints C = { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } , where for each i ∈ { 1 , . . . , n } we have Var ( σ i ) = ∅ or Var ( τ i ) = ∅ , is there a substitution S : V → T such that S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n? We say that a substitution S satisfies { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } if S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n . Theorem ([DMR13]) Matching is NP-complete. Matching remains NP-hard even when restricted to a single type variable and a single type constant in the input [DMR17]. 10 / 55
Subtyping (BCD) Problem (Matching) Given a set of constraints C = { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } , where for each i ∈ { 1 , . . . , n } we have Var ( σ i ) = ∅ or Var ( τ i ) = ∅ , is there a substitution S : V → T such that S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n? We say that a substitution S satisfies { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } if S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n . Theorem ([DMR13]) Matching is NP-complete. Matching remains NP-hard even when restricted to a single type variable and a single type constant in the input [DMR17]. 10 / 55
Subtyping (BCD) Problem (Satisfiability) Given a set of constraints C = { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } , is there a substitution S : V → T such that S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n? Problem (Algebraic unification) Given a set of constraints C = { σ 1 � τ 1 , . . . , σ n � τ n } , is there a substitution S : V → T such that S ( σ i ) = S ( τ i ) for 1 ≤ i ≤ n? Theorem ([DMR16, DMR17]) The algebraic unification problem is E xptime -hard. Open problem Is algebraic unification decidable? 11 / 55
Subtyping (BCD) Problem (Satisfiability) Given a set of constraints C = { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } , is there a substitution S : V → T such that S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n? Problem (Algebraic unification) Given a set of constraints C = { σ 1 � τ 1 , . . . , σ n � τ n } , is there a substitution S : V → T such that S ( σ i ) = S ( τ i ) for 1 ≤ i ≤ n? Theorem ([DMR16, DMR17]) The algebraic unification problem is E xptime -hard. Open problem Is algebraic unification decidable? 11 / 55
Subtyping (BCD) Problem (Satisfiability) Given a set of constraints C = { σ 1 ˙ ≤ τ 1 , . . . , σ n ˙ ≤ τ n } , is there a substitution S : V → T such that S ( σ i ) ≤ S ( τ i ) for 1 ≤ i ≤ n? Problem (Algebraic unification) Given a set of constraints C = { σ 1 � τ 1 , . . . , σ n � τ n } , is there a substitution S : V → T such that S ( σ i ) = S ( τ i ) for 1 ≤ i ≤ n? Theorem ([DMR16, DMR17]) The algebraic unification problem is E xptime -hard. Open problem Is algebraic unification decidable? 11 / 55
Subtyping (BCD) An axiomatization of the equational theory of intersection type subtyping (without ω ) is derived in [Sta15]. We add two additional axioms (U) and (RE) to incorporate the universal type ω . Definition (ACIUD l R e A b ) The equational theory ACIUD l R e A b is given by (A) σ ∩ ( τ ∩ ρ ) = ( σ ∩ τ ) ∩ ρ (C) σ ∩ τ = τ ∩ σ (I) σ ∩ σ = σ (U) σ ∩ ω = σ (D l ) ( σ → τ ) ∩ ( σ → τ ′ ) = σ → τ ∩ τ ′ (RE) ω = ω → ω (AB) σ → τ = ( σ → τ ) ∩ ( σ ∩ σ ′ → τ ) 12 / 55
Subtyping (BCD) Writing ∩ as + and → as ∗ Definition (ACIUD l R e A b ) (A) σ + ( τ + ρ ) = ( σ + τ ) + ρ (C) σ + τ = τ + σ (I) σ + σ = σ (U) σ + ω = σ (D l ) ( σ ∗ τ ) + ( σ ∗ τ ′ ) = σ ∗ ( τ + τ ′ ) (RE) ω = ω ∗ ω (AB) σ ∗ τ = ( σ ∗ τ ) + (( σ + σ ′ ) ∗ τ ) Close to E xptime -complete ACID-theory studied in [ANR04, ANR03] ... Yet, due to (AB), probably far from it. 13 / 55
Principality and Unification [CDCV80, RDR88, CG95] 14 / 55
On the Power of Subtyping Restriction without ( ∩ I) studied by Kurata & Takahashi, TLCA 95 [KT95]. Subtyping (distributivity) captures a certain amount of ( ∩ I): { x : ( a → c ) ∩ ( b → d ) , y : a ∩ b } ⊢ ( xy ) : c ∩ d Theorem ([RU12]) The inhabitation problem for the system of [KT95] is E xpspace -complete with subtyping and P space -complete without subtyping. a a But including ( ∩ E). 15 / 55
Inhabitation Pieter Brueghel the Elder - The Dutch Proverbs - Google Art Project.jpg 1559 Problem (Inhabitation Γ ⊢ ? : τ ) Given Γ and τ , does there exist a term M such that Γ ⊢ M : τ ? 16 / 55
Inhabitation and Synthesis Problem (Inhabitation Γ ⊢ ? : τ ) Given Γ and τ , does there exist a term M such that Γ ⊢ M : τ ? 17 / 55
Inhabitation and Synthesis Component-oriented Synthesis Synthesis relative to library (repository) of components Combinatory Logic Synthesis (CLS) Libraries need classification systems to enable retrieval and composition Classification Taxonomy … Types CLS Bottom-up specification Hoare logic 18 / 55
Combinatory Logic Synthesis (CLS) A type-theoretic approach to component-oriented synthesis 19 / 55
CLS World View 20 / 55
Recommend
More recommend