• Keine Ergebnisse gefunden

Combinatory Logic Synthesizer

N/A
N/A
Protected

Academic year: 2021

Aktie "Combinatory Logic Synthesizer"

Copied!
38
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Boris D¨ udder

Technical University of Dortmund, Germany

Joint work w. J. Bessai, A. Dudenhefner, M. Martens, and J. Rehof

ISoLA 2014 Evolving Critical Systems

Imperial, Corfu, Greece, October 8th 2014

(2)

Outline

Background on Combinatory Logic Synthesis

Combinatory Logic Synthesizer

Current and Future Work

(3)

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

(4)

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

(5)

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)

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

(7)

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)

(8)

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)

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

(10)

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

(11)

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

(12)

Semantic Type Structure

Trackdata

Pos Temp

Coord Time Cel Fh

Cart Polar Gpst Utc

Cx Cy Radius Angle

(13)

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

}

(14)

Composition Synthesis via Inhabitation

C={

O : TrObj

Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩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 `

C1

cl2fh (tmp (Tr O)) : R∩Fh

C `

C1

? : R∩Radius C `

C1

fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius

(15)

Composition Synthesis via Inhabitation

C={

O : TrObj

Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩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 `

C1

cl2fh (tmp (Tr O)) : R∩Fh

C `

C1

? : R∩Radius C `

C1

fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius

(16)

Composition Synthesis via Inhabitation

C={

O : TrObj

Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩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 `

C1

cl2fh (tmp (Tr O)) : R∩Fh

C `

C1

? : R∩Radius C `

C1

fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius

(17)

Composition Synthesis via Inhabitation

C={

O : TrObj

Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩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 `

C1

cl2fh (tmp (Tr O)) : R∩Fh

C `

C1

? : R∩Radius C `

C1

fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius

(18)

Composition Synthesis via Inhabitation

C={

O : TrObj

Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩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 `

C1

cl2fh (tmp (Tr O)) : R∩Fh

C `

C1

? : R∩Radius C `

C1

fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius

(19)

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

(20)

Staged Composition Synthesis (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?

(21)

Staged Composition Synthesis (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?

(22)

Staged Composition Synthesis (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?

(23)

Staged Composition Synthesis (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?

(24)

Main Ideas in Staged Composition Synthesis

Use modal types φ (“code of type φ”) to expose language distinction to composition 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

(25)

Main Ideas in Staged Composition Synthesis

Use modal types φ (“code of type φ”) to expose language distinction to composition 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

(26)

Tool Pipeline

User

Postprocessing Preprocessing

Semantic Types

SCS Combinator Repository

class B { ...

public String msg() { ...

} ...

L1 Target Code class A { ...

public int f() { ...

} ...

}

B L1 Source Code

L1 ASTs

<B msg="...">

<A><f/></A>

</B>

<A>

<f>

<B msg=".."/>

</f>

</A>

L1 Types L2 Types

L2 Implementations

<x>

<y/>

</x>

λx.λy.

λz.λm.

L1 Implementations

<A>

<f/>

</A>

<B msg="...">

...

(27)

Combinatory Logic Synthesizer Features

I

Theorem prover (proofs-as-programs correspondence)

I

Combinatory Logic Synthesis for BCL

0

(∩, ≤)

I

Version 1.0

I

Proof-of-concept

I

Enumerates inhabitants (even cyclic ones)

I

Variable kinding

I

Atomic subtyping extension for taxonomies

I

Version 2.0

I

Algebraic optimizations

I

Co-variant type constructors

(28)

Heuristic Optimizations

Strategies

I

Algorithm engineering

I

Type-theoretic / algebraic optimizations Experimental Runtime Performance for Γ

mn

in Z

n

(n, m) Initial (CL)S Lookahead-(CL)S Redesigned (CL)S

(2, 3) 210 ms 111 ms 93 ms

(3, 2) 12504 ms 124 ms 98 ms

(3, 3) – 354 ms 110 ms

(4, 4) – 7.5 ∗ 10

6

ms 121 ms

(7, 7) – – 1063 ms

(10, 10) – – 54250 ms

(43, 3) – – 8813 ms

(29)

Current & Future Work

I

Application to connector synthesis (ArchiType)

I

Application to OO-synthesis (mixins, traits, DI)

I

Combinatory process synthesis

I

Algorithm engineering

I

Constrained types Q (~ α) ⇒ φ

I

Automatic software configuration (OpenNebula Cloud)

I

Stratified logics

I

Component-oriented synthesis in theorem-proving?

I

. . .

(30)

Application – Spring DI DAO Synthesis

EmployeeController

:(

Scope∩α)→

(EmployeeDAO

∩α)

(EmployeeController

∩α∩setterTarget)

EmployeeController

:λScope. letbox

scope

=

Scope

in

λDAO.

letbox

dao

=

DAO

in

box "<bean xsi:type=’cls:Constructor’>"

"<name>EmployeeController</name>"

"<typeName>EmployeeController</typeName>"

"<scope>"scope"</scope>"

"<argument>"

"<typeName>EmployeeDAO</typeName>"

"<reference>"dao"</reference>"

"</argument>"

(31)

Application – Spring DI DAO Synthesis

Interface to request Spring Dependency Injection candidates (embedded DSL):

p u b l i c i n t e r f a c e

I n h a b i t a t i o n R e q u e s t

{ p u b l i c

C l a s s [ ] l i b r a r y C l a s s e s ( ) ;

p u b l i c

C o n f i g u r a b l e A p p l i c a t i o n C o n t e x t l i b r a r y C o n t e x t ( ) ;

p u b l i c

S t r i n g c l a s s N a m e E x c l u s i o n R e g e x p ( ) ;

p u b l i c

C l a s s t a r g e t T y p e ( ) ;

p u b l i c

S t r i n g t a r g e t S c o p e ( ) ;

}

Instead of using goal type:

(EmployeeController∩Session∩setterTarget)

(32)

Application – Spring DI DAO Synthesis

Interface to request Spring Dependency Injection candidates (embedded DSL):

p u b l i c i n t e r f a c e

I n h a b i t a t i o n R e q u e s t

{ p u b l i c

C l a s s [ ] l i b r a r y C l a s s e s ( ) ;

p u b l i c

C o n f i g u r a b l e A p p l i c a t i o n C o n t e x t l i b r a r y C o n t e x t ( ) ;

p u b l i c

S t r i n g c l a s s N a m e E x c l u s i o n R e g e x p ( ) ;

p u b l i c

C l a s s t a r g e t T y p e ( ) ;

p u b l i c

S t r i n g t a r g e t S c o p e ( ) ;

}

Instead of using goal type:

(EmployeeController

∩Session∩setterTarget)

(33)

ArchiType

(34)

ArchiType

(35)

ArchiType Taxonomy

WS-ReliableMessaging ReliableHMessaging

MessageHQueue

is-a instance-of Object

RabbitMQ Pipe

CommunicationHRole ConnectorHType

Linkage HTTP Mail

SOAP Protocol

TCP/IP REST

(36)

ArchiType Experiments

e-Commerce ERP Broker SC

Subsystems 37 137 11 3

Classes 1293 691 11 3

LLOC 225 763 38 250 839 37

Generated/LLOC 2171 1731 993 257

Time/s 21.98 18.11 7 8.1

Refactoring/LLOC 5 20 No No

(37)

Conclusion

I

A new approach to component-oriented synthesis

I

Types as logic programs that compute compositions

I

Easily applicable to native API’s

I

Very large set of application scenarios

I

Robust foundations in proof theory

I

Applied in several experiments and domains

(38)

References

I Staged Composition Synthesis. With J. Rehof and M. Martens. ESOP 2014.

I Intersection Type Matching with Subtyping. With J. Rehof and M. Martens.

TLCA 2013.

I Towards Combinatory Logic Synthesis. BEAT 2013.

I Bounded Combinatory Logic. With J. Rehof, M. Martens and P. Urzyczyn. CSL 2012.

I Using Inhabitation in Bounded Combinatory Logic with Intersection Types for Composition Synthesis. With J. Rehof, O.Garbe, M. Martens and P. Urzyczyn.

EPTCS 2012.

I The Complexity of Inhabitation with Explicit Intersection. J. Rehof and 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. J. Rehof and P. Urzyczyn.

TLCA 2011.

I Automatic Synthesis of Component & Connector-Software Architectures with Bounded Combinatory Logic. B. D¨udder. Dissertation. TU Dortmund 2014.

I See also:Dagstuhl Seminar “Design and Synthesis from Components”, Schloss

Referenzen

ÄHNLICHE DOKUMENTE

Skizze des ausgelenkten Systems und Kräfte eintragen2. Geschwindigkeitsproportionale Dämpfung

Vcru undc Lcandcr in Abydo domos habitans Er*ad amorc uenit, amorc ucro dcuixit &amp; ipamf, Ero clcgans gcncroium fanguincm fortita, t Vcnetf crat faccrdos.nuptiaru ucro iperita

Given that the comple ment of a believe type verb as in (19) and (20) does not project interrogative force (and perhaps lacks force altoge ther), distant denn must be in

[r]

Im Goldenen Sechseck haben die langen Diagonalen die Länge Φ und die kurzen Dia- gonalen die Länge 2 (Abb.. 4: Lange und kurze Diagonalen im

Bei der Abbildung 2c kommen zwei gleich große Teilfiguren vor (blau). Sie sind aber unterschiedlich entstanden. 2b), das andere der Major des Minors der ersten Zerlegung.. In

Das Goldene Trapez setzt sich zusammen aus einem gleichseitigen Dreieck und einem Parallelogramm mit dem spitzen Winkel 60° und dem Seitenverhältnis im Goldenen

Hans Walser: Kreise im Goldenen Schnitt 5 / 7 Auch dies ist nicht trivial und muss verifiziert werden.. Die insgesamt neun lila Kreise liegen in einem