Jakob Rehof
Technical University of Dortmund
Joint work w. B. D¨ udder, M. Martens (Dortmund) and P. Urzyczyn (Warsaw) and special thanks to Roger Hindley and the Torino λ-calculus group
September 2014
Combinatory Logic Synthesis (CLS)
A type-theoretic approach to component-oriented synthesis
Bottom-up specification Hoare logic
Classification Taxonomy
…
Types Component-oriented Synthesis
Synthesis relative to library (repository) of components Combinatory Logic Synthesis (CLS)
Libraries need classification systems to enable retrieval and composition
CLS
2 / 46
References
I (CL)S-Framework: Combinatory Logic Synthesizer. With J. Bessai, A.
Dudenhefner, B. D¨ udder and M. Martens. To appear ISOLA 2014.
I Staged Composition Synthesis. With B. D¨ udder and M. Martens. ESOP 2014.
I Intersection Type Matching with Subtyping. With B. D¨ udder and M. Martens.
TLCA 2013.
I Towards Combinatory Logic Synthesis. BEAT 2013.
I Bounded Combinatory Logic. With B. D¨ udder, M. Martens and P. Urzyczyn.
CSL 2012.
I Using Inhabitation in Bounded Combinatory Logic with Intersection Types for Composition Synthesis. With B. D¨ udder, O.Garbe, M. Martens and P.
Urzyczyn. EPTCS 2012.
I The Complexity of Inhabitation with Explicit Intersection. With P. Urzyczyn.
R.L. Constable and A. Silva (Eds.): Logic and Program Semantics. Essays Dedicated to Dexter Kozen 2012.
I Finite Combinatory Logic with Intersection Types. With P. Urzyczyn. TLCA 2011.
I See also: Dagstuhl Seminar “Design and Synthesis from Components”, Schloss Dagstuhl, June 1–6 2014.
3 / 46
Roadmap: Three Levels of Computation
L1 L2
CL Combinatory Logic
Compositional Metalanguage
Native Language
Composition-time
Inhabitation Composition-time
Reduction
Run-time
Execution Languages Notions
of computation
4 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
5 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
5 / 46
Composition Synthesis
I Typed function composition (modus ponens) Γ ` F : τ 0 → τ Γ ` G : τ 0
Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I CLS is inherently component-oriented
6 / 46
Composition Synthesis
I Typed function composition (modus ponens) Γ ` F : τ 0 → τ Γ ` G : τ 0
Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I CLS is inherently component-oriented
6 / 46
Composition Synthesis
I Typed function composition (modus ponens) Γ ` F : τ 0 → τ Γ ` G : τ 0
Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I CLS is inherently component-oriented
6 / 46
Composition Synthesis
I Typed function composition (modus ponens) Γ ` F : τ 0 → τ Γ ` G : τ 0
Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I CLS is inherently component-oriented
6 / 46
Foundations in Combinatory Logic
Types τ ::= α | τ → τ 0 Terms e, e 0 ::= X | (e e 0 ) Rules
Γ, (X : τ ) ` X : S(τ ) (var)
Γ ` e : τ 0 → τ Γ ` e 0 : τ 0 Γ ` (e e 0 ) : τ (→ E)
Under Curry-Howard isomorphism, Hilbert-style presentation of minimal propositional logic (schematism + modus ponens)
7 / 46
CL vs λ-calculus
I Fixed base Γ equivalent to λ-calculus:
{S : (α → β → γ) → (α → β) → α → γ, K : α → β → α}
I Inhabitation in SK-calculus is Pspace -complete (Statman)
I Proof/term enumeration (Ben-Yelles, Hindley)
I But fixed base is not the right model for composition synthesis, since repository (Γ) varies
I And λ-calculus as model is not component-oriented as is CL
8 / 46
CL vs λ-calculus
I Fixed base Γ equivalent to λ-calculus:
{S : (α → β → γ) → (α → β) → α → γ, K : α → β → α}
I Inhabitation in SK-calculus is Pspace -complete (Statman)
I Proof/term enumeration (Ben-Yelles, Hindley)
I But fixed base is not the right model for composition synthesis, since repository (Γ) varies
I And λ-calculus as model is not component-oriented as is CL
8 / 46
Relativized Inhabitation
I We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition
9 / 46
Relativized Inhabitation
I We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition
9 / 46
Relativized Inhabitation
I We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition
9 / 46
Turing-Completeness of Simple Types!
Two-counter automaton acceptance is undecidable. Two counter automaton A = hQ, q 0 , q F , δi, control states Q, inital state q 0 , final state q F , counters c 1 , c 2 ∈ N , transition relation δ given by (i = 1, 2):
I q : c i := c i + 1; goto p
I q : c i := c i − 1; goto p
I q : if (c i = 0) then goto p else goto r
Configurations C = (q, n, m), q ∈ Q , n and m contents of counters c 1 resp. c 2 .
Types of the form [C ] = q → s n (0) → s m (0) will represent configurations C = (q, n, m)
10 / 46
Encoding of A into Γ A
I Fin : q F → α → β
I q : c 1 := c 1 + 1; goto p:
Add 1 [q, p] : p → s(α) → β
→ q → α → β .
I q : c 1 := c 1 − 1; goto p:
Sub 1 [q, p] : p → α → β
→ q → s (α) → β .
I q : if (c 1 = 0) then goto p else goto r :
I
Tst
Z1[q, p] : p → 0 → β
→ q → 0 → β and
I
Tst
NZ1[q, r] : r → s(α) → β
→ q → s(α) → β .
11 / 46
Reduction
Theorem
Let A be a two-counter automaton with initial configuration (q 0 , n 0 , m 0 ). A accepts if and only if there exists a term e with Γ A ` e : q 0 → s n
0(0) → s m
0(0).
Lemma
Let C and C 0 be configurations in A. We have C → C 0 if and only if there is a term e with Γ A ` e : [C 0 ] → [C ].
Lemma
Let C be a configuration of A. C leads to acceptance in A if and only if there is a term e with Γ A ` e : [C ].
JR: BEAT 2013
12 / 46
Reduction
Consider the two-counter automaton A = q 0 : c 1 := c 1 − 1; goto q 1
q 1 : if (c 1 = 0) then goto q F else goto q 0
from initial state (q 0 , 1, 0). Since Fin : q F → 0 → 0
Tst Z 1 [q 1 , q F ] : (q F → 0 → 0) → (q 1 → 0 → 0) Sub 1 [q 0 , q 1 ] : (q 1 → 0 → 0) → (q 0 → s(0) → 0) we get
Γ A ` Sub 1 [q 0 , q 1 ] (Tst Z 1 [q 1 , q F ] Fin) : q 0 → s(0) → 0
13 / 46
Types as Logic Programs for Composition
I The input repository Γ is a logic program at the level of types
I Each combinator type is a rule in the program
I The inhabitation goal is the input goal to the program
I Search for inhabitants is the execution of the program
I Inhabitants are programs synthesized as solution space to the program
Broadly related (proof search as semantics of generalized logic programming):
D. Miller, G. Nadathur, F. Pfenning, A. Scedrov:Uniform Proofs as a Foundation for Logic Programming, Ann.
Pure App. Logic, 1991
14 / 46
“Linial-Post Spectrum”
∞
Ptime co-NP Pspace Exptime 2Exptime
. . .
CPL IPL (S4)
T
R
?
Intermediate logics Subintuitionistic logics
R
15 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
15 / 46
Situation
We are given a repository of component names X i with associated implementations C i in a native implementation language L1
X 1 , C 1 : τ 1 , . . . , X n , C n : τ n
and an associated combinatory type environment C = { X 1 : φ 1 , . . . , X n : φ n } where φ i are enriched interface types with (φ i ) ◦ ≡ τ i . We ask for combinatory compositions e such that
C ` e : φ and `
L1e [C i /X i ] : (φ) ◦ The condition `
L1e [C i /X i ] : (φ) ◦ is implementation type correctness.
16 / 46
Situation
We are given a repository of component names X i with associated implementations C i in a native implementation language L1
X 1 , C 1 : τ 1 , . . . , X n , C n : τ n
and an associated combinatory type environment C = { X 1 : φ 1 , . . . , X n : φ n } where φ i are enriched interface types with (φ i ) ◦ ≡ τ i . We ask for combinatory compositions e such that
C ` e : φ and `
L1e [C i /X i ] : (φ) ◦ The condition `
L1e [C i /X i ] : (φ) ◦ is implementation type correctness.
16 / 46
Intersection Types for Semantic Specification
Semantic types t ::= a | t → t
0| t ∩ t
0Interface types φ ::= τ | φ∩t | φ → φ
0| φ∩φ
0(whereτis L1-type)Combinatory Logic with intersection types:
C , X : φ `
C1X : S(φ) (var) C `
C1e : φ → φ
0C `
C1e
0: φ C `
C1(e e
0) : φ
0(→E) C `
C1e : φ C `
C1e : φ
0C `
C1e : φ∩φ
0(∩I) C `
C1e : φ φ ≤ φ
0C `
C1e : φ
0(≤) (elimination rule contained in φ
1∩ φ
2≤ φ
i).
Barendregt-Coppo-Dezani 1983, Dezani-Hindley 1992 Wells-Yakobowski 2005, Haack-Howard-Stoughton-Wells 2002
17 / 46
Intersection Types for Semantic Specification
Semantic types t ::= a | t → t
0| t ∩ t
0Interface types φ ::= τ | φ∩t | φ → φ
0| φ∩φ
0(whereτis L1-type)Combinatory Logic with intersection types:
C , X : φ `
C1X : S(φ) (var) C `
C1e : φ → φ
0C `
C1e
0: φ C `
C1(e e
0) : φ
0(→E) C `
C1e : φ C `
C1e : φ
0C `
C1e : φ∩φ
0(∩I) C `
C1e : φ φ ≤ φ
0C `
C1e : φ
0(≤) (elimination rule contained in φ
1∩ φ
2≤ φ
i).
Barendregt-Coppo-Dezani 1983, Dezani-Hindley 1992 Wells-Yakobowski 2005, Haack-Howard-Stoughton-Wells 2002
17 / 46
Example Repository
Γ = {
O : TrObj
Tr : TrObj → D((R, R), R, R) pos : D((R, R), R, R) → ((R, R), R) cdn : ((R, R), R) → (R, R)
fst : (R, R) → R snd : (R, R) → R
tmp : D((R, R), R, R) → R cc2pl : ((R, R), R) → ((R, R), R) cl2fh : R → R
}
JR:Towards Combinatory Logic Synthesis, BEAT’13
18 / 46
Semantic Type Structure
Trackdata
Pos Temp
Coord Time Cel Fh
Cart Polar Gpst Utc
Cx Cy Radius Angle
19 / 46
Semantic Repository
C = {
O : TrObj
Tr : TrObj → D((R, R)∩Cart, R∩Gpst, R∩Cel) pos : D((R, R)∩a, R ∩a 0 , R) → ((R, R)∩a, R ∩a 0 )∩Pos cdn : ((R, R)∩a, R)∩Pos → (R, R)∩a
fst : ((R, R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius) snd : ((R, R)∩Coord → R)∩
(Cart → Cy )∩(Polar → Angle) tmp : D((R, R), R, R ∩a) → R ∩a
cc2pl : (R, R)∩Cart → (R, R)∩Polar cl2fh : R∩Cel → R∩Fh
}
20 / 46
Composition Synthesis via Inhabitation
C = {
O : TrObj
Tr : TrObj → D((R,R)∩Cart,R∩Gpst, R∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R,R)∩a, R∩a
0)∩Pos cdn : ((R,R)∩a, R)∩Pos → (R, R)∩a
fst : ((R,R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius ) snd : ((R,R)∩Coord → R)∩
(Cart → Cy)∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a cc2pl : (R,R)∩Cart → (R,R)∩Polar cl2fh : R∩Cel → R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
21 / 46
Composition Synthesis via Inhabitation
C = {
O : TrObj
Tr : TrObj → D((R,R)∩Cart,R∩Gpst, R∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R,R)∩a, R∩a
0)∩Pos cdn : ((R,R)∩a, R)∩Pos → (R, R)∩a
fst : ((R,R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius ) snd : ((R,R)∩Coord → R)∩
(Cart → Cy)∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a cc2pl : (R,R)∩Cart → (R,R)∩Polar cl2fh : R∩Cel → R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
21 / 46
Composition Synthesis via Inhabitation
C = {
O : TrObj
Tr : TrObj → D((R,R)∩Cart,R∩Gpst, R∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R,R)∩a, R∩a
0)∩Pos cdn : ((R,R)∩a, R)∩Pos → (R, R)∩a
fst : ((R,R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius ) snd : ((R,R)∩Coord → R)∩
(Cart → Cy)∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a cc2pl : (R,R)∩Cart → (R,R)∩Polar cl2fh : R∩Cel → R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
21 / 46
Composition Synthesis via Inhabitation
C = {
O : TrObj
Tr : TrObj → D((R,R)∩Cart,R∩Gpst, R∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R,R)∩a, R∩a
0)∩Pos cdn : ((R,R)∩a, R)∩Pos → (R, R)∩a
fst : ((R,R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius ) snd : ((R,R)∩Coord → R)∩
(Cart → Cy)∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a cc2pl : (R,R)∩Cart → (R,R)∩Polar cl2fh : R∩Cel → R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
21 / 46
Composition Synthesis via Inhabitation
C = {
O : TrObj
Tr : TrObj → D((R,R)∩Cart,R∩Gpst, R∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R,R)∩a, R∩a
0)∩Pos cdn : ((R,R)∩a, R)∩Pos → (R, R)∩a
fst : ((R,R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius ) snd : ((R,R)∩Coord → R)∩
(Cart → Cy)∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a cc2pl : (R,R)∩Cart → (R,R)∩Polar cl2fh : R∩Cel → R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
21 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
21 / 46
Bounded Combinatory Logic bcl k (→, ∩)
• Levels
`(a) = 0, for a ∈ A ;
`(τ → σ) = 1 + max{`(τ ), `(σ)};
`( T
ni=1
τ
i) = max{`(τ
i) | i = 1, . . . , n}.
`(S) = max{`(S(α)) | S(α) 6= α}
• bcl
k(→, ∩), k ≥ 0 (and finite CL, fcl , with S = id ).
[`(S) ≤ k]
Γ, X : τ `
kX : S(τ ) (var) Γ `
ke : τ → σ Γ `
ke
0: τ Γ `
k(e e
0) : σ (→E)
Γ `
ke : τ Γ `
ke : σ
Γ `
ke : τ ∩ σ (∩I) Γ `
ke : τ τ ≤ σ Γ `
ke : σ (≤)
D¨udder, Martens, Rehof, Urzyczyn CSL 2012
22 / 46
Bounded Combinatory Logic bcl k (→, ∩)
• Levels
`(a) = 0, for a ∈ A ;
`(τ → σ) = 1 + max{`(τ ), `(σ)};
`( T
ni=1
τ
i) = max{`(τ
i) | i = 1, . . . , n}.
`(S) = max{`(S(α)) | S(α) 6= α}
• bcl
k(→, ∩), k ≥ 0 (and finite CL, fcl , with S = id ).
[`(S) ≤ k]
Γ, X : τ `
kX : S(τ ) (var) Γ `
ke : τ → σ Γ `
ke
0: τ Γ `
k(e e
0) : σ (→E)
Γ `
ke : τ Γ `
ke : σ
Γ `
ke : τ ∩ σ (∩I) Γ `
ke : τ τ ≤ σ Γ `
ke : σ (≤)
D¨udder, Martens, Rehof, Urzyczyn CSL 2012
22 / 46
Complexity for Finite and Bounded CL
Theorem (RU TLCA 2011) For finite combinatory logic fcl :
1. Relativized inhabitation in fcl (→) is in Ptime
2. Relativized inhabitation in fcl(→, ∩) is Exptime-complete Theorem (DMRU CSL 2012)
For bounded combinatory logic bcl k :
1. Relativized inhabitation in bcl k (→) is Exptime -complete for all k
2. Relativized inhabitation in bcl k (→, ∩) is (k + 2)- Exptime -complete
23 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Upper Bound ATM for bcl k (→, ∩): Aspace (exp k +1 (n))
Input : Γ, τ, k Γ = {f : (0 → 1) ∩ (1 → 0),
x : (α → β) → (β → γ) → (α → γ)}
τ = (0 → 0) ∩ (1 → 1) loop :
1 choose (x : σ) ∈ Γ; σ
0= (0 → 0) → (0 → 0) → (0 → 0) ∩ · · · ∩ 2 σ
0:= T {S(σ) | S ∈ S
x(Γ,τ,k)}; (1 → 1) → (1 → 1) → (1 → 1) 3 choose m ∈ {0, . . . , kσ
0k}; (0 → 1)→(1 → 0)→(0 → 0)∩
4 choose P ⊆ P
m(σ
0); (1 → 0)→(0 → 1)→(1 → 1) 5 if ( T
π∈P
tgt
m(π) ≤ τ) then (0 → 0)∩(1 → 1)≤ τ 6 if (m = 0) then accept ;
7 else
8 forall(i = 1 . . . m)
9 τ := T
π∈P
arg
i(π); τ :=(0 → 1)∩(1 → 0) τ :=(1 → 0)∩(0 → 1)
10 goto loop;
11 else reject;
(x f ) f : (0 → 0) ∩ (1 → 1)
24 / 46
Lower bound
Generic reduction by simulation of exp k+1 (n)-space bounded alternating Turing machines.
Given ATM M, we construct, in polynomial time, an environment Γ such that M is accepting if and only if Γ ` k ? : Tape is solvable.
25 / 46
Lower bound - main ideas
For any fixed level-parameter K :
I Intersection type numerals hi i K : we can represent numbers 0 ≤ i ≤ exp K+1 (n) − 1 as intersection types.
I We can represent ATM configurations C of size exp K+1 (n) as intersection types [ C ]
I Exploiting K -bounded polymorphism, we can represent these types implicitly in polynomial sized types
I ATM sequences C 1 C 2 · · · C m coded by reverse implications [C i+1 ] → [C i ] in Γ
26 / 46
Lower bound - main ideas
For any fixed level-parameter K :
I Intersection type numerals hi i K : we can represent numbers 0 ≤ i ≤ exp K+1 (n) − 1 as intersection types.
I We can represent ATM configurations C of size exp K+1 (n) as intersection types [ C ]
I Exploiting K -bounded polymorphism, we can represent these types implicitly in polynomial sized types
I ATM sequences C 1 C 2 · · · C m coded by reverse implications [C i+1 ] → [C i ] in Γ
26 / 46
Lower bound - main ideas
For any fixed level-parameter K :
I Intersection type numerals hi i K : we can represent numbers 0 ≤ i ≤ exp K+1 (n) − 1 as intersection types.
I We can represent ATM configurations C of size exp K+1 (n) as intersection types [ C ]
I Exploiting K -bounded polymorphism, we can represent these types implicitly in polynomial sized types
I ATM sequences C 1 C 2 · · · C m coded by reverse implications [C i+1 ] → [C i ] in Γ
26 / 46
Lower bound - main ideas
For any fixed level-parameter K :
I Intersection type numerals hi i K : we can represent numbers 0 ≤ i ≤ exp K+1 (n) − 1 as intersection types.
I We can represent ATM configurations C of size exp K+1 (n) as intersection types [ C ]
I Exploiting K -bounded polymorphism, we can represent these types implicitly in polynomial sized types
I ATM sequences C 1 C 2 · · · C m coded by reverse implications [C i+1 ] → [C i ] in Γ
26 / 46
Lower bound: intersection type numerals
B = {0, 1}, B [n] = {0
1, . . . , 0
n} ∪ {1
1, . . . , 1
n} I N
0= { T
ni=1
b
i| b
i∈ {0
i, 1
i} for i = 1 . . . n}
I N
k+1= { T
τ∈Nk
(τ → b
τ) | b
τ∈ {0, 1}, for τ ∈ N
k} I J
T
ni=1
b
iK = P
ni=1
J b
iK × 2
i−1, with J 0
iK = 0 and J 1
iK = 1 I J
T
σ∈Nk
(τ → b
τ) K = P
τ∈Nk
b
τ× 2
JτKI J 0
1∩ 1
2∩ 0
3∩ 1
4K = 2 + 8 = 10
I J ((0
1∩ 0
2) → 0) ∩ ((0
1∩ 1
2) → 1) ∩ ((1
1∩ 0
2) → 0) ∩ ((1
1∩ 1
2) → 1) K = 10 I σ ∈ N
k: 0 ≤ J σ K ≤ exp
k+1(n) − 1, uniquely
27 / 46
Lower bound: intersection type numerals
B = {0, 1}, B [n] = {0
1, . . . , 0
n} ∪ {1
1, . . . , 1
n} I N
0= { T
ni=1
b
i| b
i∈ {0
i, 1
i} for i = 1 . . . n}
I N
k+1= { T
τ∈Nk
(τ → b
τ) | b
τ∈ {0, 1}, for τ ∈ N
k} I J
T
ni=1
b
iK = P
ni=1
J b
iK × 2
i−1, with J 0
iK = 0 and J 1
iK = 1 I J
T
σ∈Nk
(τ → b
τ) K = P
τ∈Nk
b
τ× 2
JτKI J 0
1∩ 1
2∩ 0
3∩ 1
4K = 2 + 8 = 10
I J ((0
1∩ 0
2) → 0) ∩ ((0
1∩ 1
2) → 1) ∩ ((1
1∩ 0
2) → 0) ∩ ((1
1∩ 1
2) → 1) K = 10
I σ ∈ N
k: 0 ≤ J σ K ≤ exp
k+1(n) − 1, uniquely
27 / 46
Lower bound: intersection type numerals
B = {0, 1}, B [n] = {0
1, . . . , 0
n} ∪ {1
1, . . . , 1
n} I N
0= { T
ni=1
b
i| b
i∈ {0
i, 1
i} for i = 1 . . . n}
I N
k+1= { T
τ∈Nk
(τ → b
τ) | b
τ∈ {0, 1}, for τ ∈ N
k} I J
T
ni=1
b
iK = P
ni=1
J b
iK × 2
i−1, with J 0
iK = 0 and J 1
iK = 1 I J
T
σ∈Nk
(τ → b
τ) K = P
τ∈Nk
b
τ× 2
JτKI J 0
1∩ 1
2∩ 0
3∩ 1
4K = 2 + 8 = 10
I J ((0
1∩ 0
2) → 0) ∩ ((0
1∩ 1
2) → 1) ∩ ((1
1∩ 0
2) → 0) ∩ ((1
1∩ 1
2) → 1) K = 10
I σ ∈ N
k: 0 ≤ J σ K ≤ exp
k+1(n) − 1, uniquely
27 / 46
Configurations
The explicit representation of an ATM configuration C is
[ C ] =
exp
K+1(n)−1
\
i=0
Cell(a i , q, hmi K , hii K )
where
I hii K is the address of the cell
I hmi K is the address of the cell under the r/w-head
I q is the control state
I a i is the symbol in the cell
We will represent configurations implicitly as Cell(α, β, γ, δ)
28 / 46
Configurations
The explicit representation of an ATM configuration C is
[ C ] =
exp
K+1(n)−1
\
i=0
Cell(a i , q, hmi K , hii K )
where
I hii K is the address of the cell
I hmi K is the address of the cell under the r/w-head
I q is the control state
I a i is the symbol in the cell
We will represent configurations implicitly as Cell(α, β, γ, δ)
28 / 46
Corollary: n.e. with uniform (refinement) types
Fix X ⊆ A and define uniform types Ξ
X(τ) for τ ∈ T
0:
Ξ
X(0) = X
∩Ξ
X(τ → σ) = (Ξ
X(τ ) ⇒ Ξ
X(σ))
∩Note: With such types we can represent any finite function f : A → B by T
x∈A
x → f (x ).
Corollary
Relativized inhabitation with uniform types refining monomorphic native types is nonelementary recursive.
Proof.
Upper bound: every problem Γ `? : φ
0is decidable within bcl
k(→, ∩) with k = max{`(φ
◦) | φ ∈ rn(Γ)}.
Lower bound: notice that all constructions in l.b. for bcl
k(→, ∩) can be carried out with uniform types.
29 / 46
Corollary: Henkin’s theory Ω in bcl k (→, ∩)
Satisfiability of formulae
Φ ::= 0 ∈ x
1| 1 ∈ x
1| x
k∈ y
k+1| ¬Φ | ∀x
k.Φ | Φ ∧ Φ
0where x
kranges over D
kwith D
0= {0, 1}, D
k+1= P(D
k).
L. Henkin: A theory of propositional types, Fundamenta Mathematicae 52 (1963) 323–344.
Representation in bcl
k(→, ∩) (for sufficiently large k):
I A set variable x
kis represented by a type variable x
k. I Membership predicate Mem
kNum
k(x
k) → Num
k+1(y
k+1) → In
k(x
k, y
k+1) → Mem
k(x
k, y
k+1) where In
k(x
k, x
k→ 1) and NotIn(x
k, x
k→ 0) are axioms.
I Use alternation to code quantifiers as usual (Urzyczyn 1997).
30 / 46
Ongoing: optimization & algorithm engineering
B. D¨ udder: Automatic Synthesis of Component & Connector-Software Architectures with Bounded Combinatory Logic, Diss. Dortmund, Aug. 2014.
31 / 46
Intersection Type Subtyping
• Intersection type subtyping [Barendregt, Coppo, Dezani 1983] is the least preorder generated by the axioms A. Types are taken modulo associativity, commutativity and idempotence of ∩.
σ ≤
Aω, ω ≤
Aω → ω, σ ∩ τ ≤
Aσ, σ ∩ τ ≤
Aτ, σ ≤
Aσ ∩ σ;
(σ → τ ) ∩ (σ → ρ) ≤
Aσ → τ ∩ ρ;
If σ ≤
Aσ
0and τ ≤
Aτ
0then σ ∩ τ ≤
Aσ
0∩ τ
0and σ
0→ τ ≤
Aσ → τ
0.
• Matching: Given τ, σ, does there exist S with S(τ) ≤
Aσ?
Theorem (DMR TLCA 2013)
Intersection type matching is NP -complete.
32 / 46
Open Problems
I Is intersection type unification induced by ≤ A decidable?
I
Close (but no cigar!):
Anantharaman, Narendran, Rubinowitch. Unification Modulo ACUI Plus Distributivity Axioms. Journal of Automated Reasoning (33) 2004.
I Complexity of inhabitation in bcl k (→, ∩) w/o (∩I )
I
Compare RU: The Complexity of Inhabitation with Explicit Intersection. Essays dedicated to Dexter Kozen, 2012.
33 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
33 / 46
SCS (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
34 / 46
SCS (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
34 / 46
SCS (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
34 / 46
SCS (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
34 / 46
Main Ideas in SCS
Use modal types φ (“code of type φ”) to expose language distinction to compostion synthesis.
I Introduction of modal intersection types
I Davies and Pfenning’s calculus λ ,→ e as L2 implementation language
I Challenges of staging solved by theory of λ ,→ e
I Challenge of implementation type correctness solved by conservative extension theorem
I Extension of inhabitation (semi-)algorithm for modal intersection types
I Extension of (CL)S-framework and experiments
35 / 46
Main Ideas in SCS
Use modal types φ (“code of type φ”) to expose language distinction to compostion synthesis.
I Introduction of modal intersection types
I Davies and Pfenning’s calculus λ ,→ e as L2 implementation language
I Challenges of staging solved by theory of λ ,→ e
I Challenge of implementation type correctness solved by conservative extension theorem
I Extension of inhabitation (semi-)algorithm for modal intersection types
I Extension of (CL)S-framework and experiments
35 / 46
Metalanguage L2
Modal types σ ::= τ | σ → σ
0, where τ ranges over L1-types Metalanguage L2 (adapted from λ
e,→) over L1:
∆; (Γ, x : σ) `
L2x : σ (var)
∆; (Γ, x : σ) `
L2M : σ
0∆; Γ `
L2λx : σ.M : σ → σ
0(→I) ∆; Γ `
L2M
1: σ → σ
0∆; Γ `
L2M
2: σ
∆; Γ `
L2(M
1M
2) : σ
0(→E)
∆; ∅ `
L1T : τ
∆; Γ `
L2box T : τ (I) ∆; Γ `
L2M
1: τ (∆, u : τ); Γ `
L2M
2: σ
∆; Γ `
L2letbox u : τ = M
1in M
2: σ (E)
Reduction
letbox u = box T in M 7−→ M[u := T]
Davies and Pfenning:A Modal Analysis of Staged Computation, JACM, 2001
36 / 46
Combinatory Logic C2
Semantic types s ::= b | s → s
0| s ∩ s
0| t Interface types ψ ::= σ | ψ∩s | φ | ψ → ψ
0| ψ∩ψ
0Combinatory Logic C2 over C1
C = {box X i : φ} ∪ {Y j : ψ} (φ by rule of necessitation)
Logically, contains modal logic S4
@ , λF : (α → β).λX : α.
letbox f : α → β = F in letbox x : α = X in
box f (x)
@ : (α → β) → α → β
eval , λX : α. letbox x : α = X in x eval : α → α
37 / 46
Combinatory Logic C2
Semantic types s ::= b | s → s
0| s ∩ s
0| t Interface types ψ ::= σ | ψ∩s | φ | ψ → ψ
0| ψ∩ψ
0Combinatory Logic C2 over C1
C = {box X i : φ} ∪ {Y j : ψ} (φ by rule of necessitation)
Logically, contains modal logic S4
@ , λF : (α → β).λX : α.
letbox f : α → β = F in letbox x : α = X in
box f (x)
@ : (α → β) → α → β
eval , λX : α. letbox x : α = X in x eval : α → α
37 / 46
Combinatory Logic C2
Semantic types s ::= b | s → s
0| s ∩ s
0| t Interface types ψ ::= σ | ψ∩s | φ | ψ → ψ
0| ψ∩ψ
0Combinatory Logic C2 over C1
C = {box X i : φ} ∪ {Y j : ψ} (φ by rule of necessitation)
Logically, contains modal logic S4
@ , λF : (α → β).λX : α.
letbox f : α → β = F in letbox x : α = X in
box f (x)
@ : (α → β) → α → β
eval , λX : α. letbox x : α = X in x eval : α → α
37 / 46
Stratified logics and languages
Mmap , λF : (α → β).λA : Array(α).
letbox f : α → β = F in letbox a : Array(α) = A in
box(for (i := 0) to sizeof(a) − 1{a[i] := f(a[i]); }) Mmap : (α → β) → Array(α) → Array(β)
38 / 46
Stratified logics and languages
Ppar , λP
1: Proc.λP
2: Proc.
letbox p
1: Proc = P
1in letbox p
2: Proc = P
2in
box(p
1k p
2) Ppar : Proc → Proc → Proc
Ppar : (Proc ∩ A
1) → (Proc ∩ A
2) → (Proc ∩ A
1× A
2)
Ppar : ((Proc ∩ A
1) → (Proc ∩ A
2) → (Proc ∩ A
1× A
2)) ∩ ParComp
39 / 46
Example
C = {
O , box O : TrObj
Tr , box Tr : (TrObj → D((R, R) ∩ Cart,R ∩ Gpst, R ∩ Cel)) tmp , box tmp : (D((R,R),R,R ∩ a) → R ∩ a ∩ ms)
} D = {
@ : (α → β) → α → β
• : (β → γ) → (α → β) → (α → γ) cl2fh : ((R ∩ Cel) → (R ∩ Fh))∩Conv
♦ : (α ∩ ms) → (α → β)∩Conv → (β ∩ ms) }
40 / 46
Example
Combinator bindings for D :
• , λG : (β → γ).λF : (α → β).
letbox f : α → β = F in
letbox g : β → γ = G in box(fn y : α => (g (f y)))
cl2fh , λz : R.
letbox u : R = z in
box(let x : R = u in x ∗ (9 div 5) + 32)
♦ , λz : α.λF : α → β.(F z)
41 / 46
Example
I Query: C ∪ D ` C2 ? : (TrObj → (R ∩ Cel ∩ ms))
I Solution: tmp • Tr : (TrObj → (R ∩ Cel ∩ ms ))
I L2-reduction:
tmp • Tr 7−→ ∗
box(fn y : TrObj => (tmp (Tr y)))
42 / 46
Example
I Query: C ∪ D ` C2 ? : (TrObj → (R ∩ Cel ∩ ms))
I Solution: tmp • Tr : (TrObj → (R ∩ Cel ∩ ms ))
I L2-reduction:
tmp • Tr 7−→ ∗
box(fn y : TrObj => (tmp (Tr y)))
42 / 46
Example
I Query: C ∪ D ` C2 ? : (TrObj → (R ∩ Cel ∩ ms))
I Solution: tmp • Tr : (TrObj → (R ∩ Cel ∩ ms ))
I L2-reduction:
tmp • Tr 7−→ ∗
box(fn y : TrObj => (tmp (Tr y)))
42 / 46
Example
I Query: C ∪ D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: (tmp @ (Tr @ O)) ♦ cl2fh
I L2-reduction:
(tmp @ (Tr @ O)) ♦ cl2fh 7−→ ∗
box(let x : R = tmp (Tr O) in x ∗(9 div 5) + 32)
43 / 46
Example
I Query: C ∪ D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: (tmp @ (Tr @ O)) ♦ cl2fh
I L2-reduction:
(tmp @ (Tr @ O)) ♦ cl2fh 7−→ ∗
box(let x : R = tmp (Tr O) in x ∗(9 div 5) + 32)
43 / 46
Example
I Query: C ∪ D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: (tmp @ (Tr @ O)) ♦ cl2fh
I L2-reduction:
(tmp @ (Tr @ O)) ♦ cl2fh 7−→ ∗
box(let x : R = tmp (Tr O) in x ∗(9 div 5) + 32)
43 / 46
Example
Let us add to C
c2f : ((R ∩ Cel ∩ ms ) → (R ∩ Fh ∩ ms))
I Query: C ; D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: c2f @ ((tmp • Tr) @ O)
I After L2-reduction:
box((c2f ((fn y : TrObj => (tmp (Tr y))) O))
44 / 46
Example
Let us add to C
c2f : ((R ∩ Cel ∩ ms ) → (R ∩ Fh ∩ ms))
I Query: C ; D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: c2f @ ((tmp • Tr) @ O)
I After L2-reduction:
box((c2f ((fn y : TrObj => (tmp (Tr y))) O))
44 / 46
Example
Let us add to C
c2f : ((R ∩ Cel ∩ ms ) → (R ∩ Fh ∩ ms))
I Query: C ; D ` C2 ? : (R ∩ Fh ∩ ms)
I Solution: c2f @ ((tmp • Tr) @ O)
I After L2-reduction:
box((c2f ((fn y : TrObj => (tmp (Tr y))) O))
44 / 46
Outline
Background on CLS
Intersection Types for Semantic Specification Bounded Combinatory Logic
Staged Composition Synthesis Conclusion and Future Work
44 / 46
Some Main Points
I A new approach to component-oriented synthesis
I An “Aristotelian” rather than “Fregean” approach
I Types as logic programs that compute compostions
I Easily applicable to native API’s
I Very large set of application scenarios
I Robust foundations in proof theory
I Implemented in (CL)S-framework (B. D¨ udder, M. Martens)
I Applied in several experiments
45 / 46
Ongoing & Future Work
I Application to connector synthesis (B. D¨ udder: ArchiType)
I Application to OO-synthesis (traits, dependency injection)
I Combinatory process synthesis
I Algorithm engineering
I Constrained types Q (~ α) ⇒ φ
I Automatic software configuration
I Stratified logics
I Component-oriented synthesis in theorem-proving?
I . . .
46 / 46