• Keine Ergebnisse gefunden

Logische Methoden des Software Engineerings Vertiefungsmodul 2

N/A
N/A
Protected

Academic year: 2021

Aktie "Logische Methoden des Software Engineerings Vertiefungsmodul 2"

Copied!
26
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Logische Methoden des Software Engineerings Vertiefungsmodul 2

Combinatory Logic Synthesis (Simple Types)

Jakob Rehof & Andrej Dudenhefner LS XIV – Software Engineering

TU Dortmund WS 2018/19

WS 2018/19

(2)

Composition Synthesis

Function composition in Combinatory Logic Γ`F :τ0→τ Γ`G:τ0

Γ`(F G) :τ (→E)

as logical model of applicative composition of named component interfaces(F :ρ)∈Γ from arepository Γ, satisfying goalτ

Inhabitation problemas foundation for automatic synthesis:

∃F.Γ`F :τ ? Notation Γ`?:τ

I Does there exist a program compositionF from repositoryΓwith Γ`F :τ ? Inhabitation algorithm is used toconstruct(synthesize)F fromΓandτ

CLS is inherently component-oriented

(3)

Composition Synthesis

Function composition in Combinatory Logic Γ`F :τ0→τ Γ`G:τ0

Γ`(F G) :τ (→E)

as logical model of applicative composition of named component interfaces(F :ρ)∈Γ from arepository Γ, satisfying goalτ Inhabitation problemas foundation for automatic synthesis:

∃F.Γ`F :τ ? Notation Γ`?:τ

I Does there exist a program compositionF from repositoryΓwith Γ`F:τ ? Inhabitation algorithm is used toconstruct(synthesize)F fromΓandτ

CLS is inherently component-oriented

(4)

Composition Synthesis

Function composition in Combinatory Logic Γ`F :τ0→τ Γ`G:τ0

Γ`(F G) :τ (→E)

as logical model of applicative composition of named component interfaces(F :ρ)∈Γ from arepository Γ, satisfying goalτ Inhabitation problemas foundation for automatic synthesis:

∃F.Γ`F :τ ? Notation Γ`?:τ

I Does there exist a program compositionF from repositoryΓwith Γ`F:τ ? Inhabitation algorithm is used toconstruct(synthesize)F fromΓandτ

CLS is inherently component-oriented

(5)

Composition Synthesis

Function composition in Combinatory Logic Γ`F :τ0→τ Γ`G:τ0

Γ`(F G) :τ (→E)

as logical model of applicative composition of named component interfaces(F :ρ)∈Γ from arepository Γ, satisfying goalτ Inhabitation problemas foundation for automatic synthesis:

∃F.Γ`F :τ ? Notation Γ`?:τ

I Does there exist a program compositionF from repositoryΓwith Γ`F:τ ? Inhabitation algorithm is used toconstruct(synthesize)F fromΓandτ

CLS is inherently component-oriented

(6)

Foundations in Combinatory Logic

Components are exposed as typed combinator symbols (F :τ), representing component names with types as interfaces. Types will be generalized later.

Component composition as applicative combinations (F G).

Composition will be generalized later.

However, we will first have to generalize the notion of combinatory logic from any particular fixed base (likeB={S,K,I}) to arbitrary finite sets of combinators.

(7)

CL vs λ-calculus

Recall that the fixed baseB={S,K,I} (evenB={S,K}) is equivalent toλ-calculus, both untyped and in simple types.

We saw that inhabitation inλ and simple typed SKI-calculus is Pspace-complete (Statman).

Proof/term enumeration, Ben-Yelles, Hindley: See [Hin08].

But afixed base is not the right model for composition synthesis, since repository (Γ) varies

Andλ-calculus (SKI-calculus) as model is notcomponent-orientedas is CL

(8)

CL vs λ-calculus

Recall that the fixed baseB={S,K,I} (evenB={S,K}) is equivalent toλ-calculus, both untyped and in simple types.

We saw that inhabitation inλ and simple typed SKI-calculus is Pspace-complete (Statman).

Proof/term enumeration, Ben-Yelles, Hindley: See [Hin08].

But afixed base is not the right model for composition synthesis, since repository (Γ) varies

Andλ-calculus (SKI-calculus) as model is notcomponent-orientedas is CL

(9)

Recall combinatory logic SKI

Γ, x:τ `skix:τ(var) Γ`skiI:τ τ(I) Γ`skiK:τ στ(K)

Γ`skiS: (τσρ) σ)τ ρ(S)

Γ`skiF:τσ Γ`skiG:τ Γ`ski(F G) :σ (→E)

Notice that variablesxhave fixed,monomorphic types, whereas combinatorsS,K,I have infinitely many types (their types areschematicorpolymorphic).

(10)

Combinatory logic cl (B)

Fix a typed baseB, for example SKI:

S : βγ)β)αγ K : αβα

I : αα with the rules, for any given baseB:

(X:τ)B, S:VT Γ`BX:S(τ) (comb)

Γ, x:τ`Bx:τ(var) Γ`BF:τσ Γ`BG:τ

Γ`B(F G) :σ (→E)

(11)

Combinatory logic cl

Assuming that variables xare considered special combinator symbols with constant types, we can assume that Γ is an arbitrary set of typed

combinator symbols and simplify the presentation to:

[S :V→T]

Γ, X:τ `clX :S(τ)(var) Γ`cl F :τ →σ Γ`clG:τ

Γ`cl(F G) :σ (→E)

(12)

Relativized Inhabitation

We consider the relativized inhabitation problem:

I Given Γandτ, does there existF such that Γ`clF :τ?

Relativized inhabitation in simple types is much harder than inhabitation in the fixed theory of λ (SKI)

I Undecidable: Linial-Post theorems, 1948 ff.

Reason: instead of considering a fixed theory (λ, IPC) we consider an arbitrary input theory

The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition

(13)

Relativized Inhabitation

We consider the relativized inhabitation problem:

I Given Γandτ, does there existF such that Γ`clF :τ?

Relativized inhabitation in simple types is much harder than inhabitation in the fixed theory of λ (SKI)

I Undecidable: Linial-Post theorems, 1948 ff.

Reason: instead of considering a fixed theory (λ, IPC) we consider an arbitrary input theory

The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition

(14)

Relativized Inhabitation

We consider the relativized inhabitation problem:

I Given Γandτ, does there existF such that Γ`clF :τ?

Relativized inhabitation in simple types is much harder than inhabitation in the fixed theory of λ (SKI)

I Undecidable: Linial-Post theorems, 1948 ff.

Reason: instead of considering a fixed theory (λ, IPC) we consider an arbitrary input theory

The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition

(15)

Relativized Inhabitation

We consider the relativized inhabitation problem:

I Given Γandτ, does there existF such that Γ`clF :τ?

Relativized inhabitation in simple types is much harder than inhabitation in the fixed theory of λ (SKI)

I Undecidable: Linial-Post theorems, 1948 ff.

Reason: instead of considering a fixed theory (λ, IPC) we consider an arbitrary input theory

The CLS view: Already in simple types, relativized inhabitation defines a Turing-complete logic programming language for component composition

(16)

Turing-Completeness of Simple Types!

Two-counter automaton acceptance is undecidable. Two counter

automaton A=hQ, q0, qF, δi, control states Q, inital stateq0, final state qF, counters c1, c2∈N, transition relationδ given by (i= 1,2):

q :ci:=ci+ 1;goto p q :ci:=ci−1;goto p

q :if (ci = 0)then gotop else gotor

ConfigurationsC = (q, n, m),q ∈Q,nand mcontents of counters c1 resp. c2.

Types of the form [C] =q→sn(0)→sm(0)will represent configurations C= (q, n, m)

(17)

Encoding of A into Γ

A

Fin:qF →α→β q :c1:=c1+ 1;goto p:

Add1[q,p]: p→s(α)→β

→ q→α→β . q :c1:=c1−1;goto p:

Sub1[q,p]: p→α→β

→ q →s(α)→β .

q :if (c1 = 0)then gotop else gotor:

I TstZ1[q,p]: p0β

q0β and

I TstNZ1 [q,r]: rs(α)β

qs(α)β .

(18)

Reduction

Consider the two-counter automaton

A = q0 :c1:=c1−1;goto q1

q1 :if (c1 = 0)then gotoqF else gotoq0

from initial state (q0,1,0). Since

Fin : qF →0→0

TstZ1[q1,qF] : (qF →0→0)→(q1 →0→0) Sub1[q0,q1] : (q1 →0→0)→(q0→s(0)→0) we get

ΓA `Sub1[q0,q1](TstZ1[q1,qF]Fin) :q0→s(0)→0

(19)

Reduction

Theorem 1

LetAbe a two-counter automaton with initial configuration(q0, n0, m0). Aaccepts if and only if there exists a termewithΓA`e:q0sn0(0)sm0(0).

Lemma 2

LetCandC0 be configurations inA. We haveC → C0 if and only if there is a terme withΓA`e: [C0][C].

Lemma 3

LetCbe a configuration ofA. Cleads to acceptance inAif and only if there is a term ewithΓA`e: [C].

Exercise 1

Prove Theorem 1.

(20)

Types as Logic Programs for Composition

The input repositoryΓ is a logic program at the level of types Each combinator type is a rule in the program

The inhabitation goal is the input goal to the program Search for inhabitants is the execution of the program

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

(21)

“Linial-Post Spectrum”

Ptime co-NP Pspace Exptime 2Exptime

. . .

IPL (S4) CPL

T R

?

R

(22)

Semantic specification

Simple types are not sufficient to specify composition (even though they are Turing-complete under relativized inhabitation).

(23)

Intersection types

Definition 4 (Intersection types)

LetVdenote a denumerable set oftype variables, ranged over by metavariables α, β, γ, . . ., and letbrange over a setBoftype constants. The setT ofintersection types, ranged over byτ, σ, ρ, . . ., is defined inductively by:

αVαT bBbT

τ T, σTτσT τ T, σTτσT

Intersection types are considered modulo associativity, commutativity and idempotence of intersection: τρ) = (τσ)ρ, τσ=στ, ττ=τ.

(24)

Intersection type system λ

Γ, x:τ`x:τ(var)

Γ, x:τ`M :σ Γ`λx.M:τσ(→I)

Γ`M:τ σ Γ`N:τ

Γ`M N :σ (→E)

Γ`M:τ1 Γ`M:τ2

Γ`M:τ1τ2

(∩I) Γ`M:τ1τ2

Γ`M :τi

(∩E)

Major reference for this system (a.k.a. “BCD”, Barendregt-Coppo-Dezani):

(25)

Intersection type system λ

A good exposition of the following fundamental result (which goes back to around 1980) can be found in [Ghi96].

Lemma 5 (Subject expansion)

SupposeMβ N by contracting the redex occurrence(λx.P)QinM. IfΓ`M :σ andQis typable in the same contextΓ, thenΓ`N :σ.

Theorem 6 (Fundamental theorem for λ)

A termM is typable in systemλ, if and only if,M is strongly normalizing.

Corollary 7 (Undecidability)

Typability inλis undecidable.

(26)

H. P. Barendregt, M. Coppo, and M. Dezani-Ciancaglini.

A Filter Lambda Model and the Completeness of Type Assignment.

Journal of Symbolic Logic, 48(4):931–940, 1983.

S. Ghilezan.

Strong Normalization and Typability with Intersection Types.

Notre Dame Journal of Formal Logic, 37(1):44–52, 1996.

J. Roger Hindley.

Basic Simple Type Theory.

Cambridge Tracts in Theoretical Computer Science, vol. 42, Cambridge University Press, 2008.

Referenzen

ÄHNLICHE DOKUMENTE

FK Informatik LS XIV Software Engineering Prof..

FK Informatik LS XIV Software Engineering Prof..

FK Informatik LS XIV Software Engineering Prof..

FK Informatik LS XIV Software Engineering Prof..

2.11.2016 Arbeite Kapitel 1 aus dem Buch Sørensen, Morten Heine B., Urzyczyn, Paweª: Lectures on the Curry- Howard Isomorphism, 1998 soweit durch, dass mindestens die

Geben sie formale Beweise (Deduktionen) für die drei Aussagen aus Beispiel 3.1.2 aus dem Buch Sørensen, Morten Heine B., Urzyczyn, Paweª: Lectures on the Curry-Howard Isomorphism,

Gemeinsame Abgaben von Gruppen bis zu 4 Personen

Gemeinsame Abgaben von Gruppen bis zu 4 Personen