• Keine Ergebnisse gefunden

Signatures – Example

N/A
N/A
Protected

Academic year: 2021

Aktie "Signatures – Example"

Copied!
31
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Synthesis

Jan Bessai

2017-06-21

(2)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Last Time: Pandoras Box

Real Programming Languages

mostly informal specifications

complex rule systems (ML: approx. 200 rules)

lots and lots of variation (c.f. Pure Type Systems)

sometimes ”broken”

(c.f. Java Unsoundness [1])

F.S.Church - Opening up Pandoras Box, source: wikimedia.org

2 / 27

(3)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Today: Equipment for Ghostbusters

source: wikimedia.org

Language Independence with Algebra

mathematical abstraction of interfaces

implementation in any target language

Synthesis

pick an inhabitation friendly target language

translate results

Demo

(4)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Formal Interfaces

Definition (Term Signatures)

Given a map 𝕊 ∶ Set → Setand a finite set of variables𝕍, the term signature Σ𝕊,𝕍= (𝕆,arity,domain,range)is defined by:

A set𝕆 of operation symbols

A function arity∶ 𝕆 → ℕ0

A family domain∶ (∏arity(𝑜𝑝)𝑖=1 𝕊(𝕍))𝑜𝑝∈𝕆

A function range∶ 𝕆 → 𝕊(𝕍)

4 / 27

(5)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Example

Informally: Σ𝕊,𝕍 = {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } Or formally:

𝕍 ∶ Set 𝕍 = {𝛼}

𝕊 ∶ Set → Set

𝕊(𝑋) = 𝑋 ∪ {String, int} ∪ {List(𝑥) ∣ 𝑥 ∈ 𝕊(𝑋)}

(6)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Example

Informally: Σ𝕊,𝕍 = {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } Or formally:

𝕆 ∶ Set

𝕆 = {allUsers,newUser,allUserIds, newUserId,append,first}

arity∶ 𝕆 → ℕ0

arity= {allUsers↦ 0,newUser↦ 0,allUserIds↦ 0, newUserId↦ 0,append↦ 2,first↦ 1}

5 / 27

(7)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Example

Informally: Σ𝕊,𝕍 = {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } Or formally:

domain∶ (∏arity(𝑜𝑝)

𝑖=1 𝕊(𝕍))𝑜𝑝∈𝕆

domain= {allUsers↦ (),newUser↦ (), allUserIds↦ (),newUserId↦ (), append↦ (𝛼, List(𝛼)),first↦ List(𝛼)}

range∶ 𝕆 → 𝕊(𝕍)

range= {allUsers↦ List(String),newUser↦ String, allUserIds↦ List(int),newUserId↦ int, append↦ List(𝛼),first↦ 𝛼}

(8)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Substitutions

Definition (Substitution)

Given a map 𝕊 ∶ Set → Setand a set of variables 𝕍, we lift substitutions 𝑆 ∶ 𝕍 → 𝕊(∅) to𝑆+∶ 𝕊(𝕍) → 𝕊(∅) by applying a substitution map _+∶ (𝕍 → 𝕊(∅)) → 𝕊(𝕍) → 𝕊(∅).

We call𝑠 ∈ 𝕊(∅)a closed sort and require closed sorts to be countable.

Open sorts𝑠 ∈ 𝕊(𝕍) are used to provide parametric polymorphism and closed sorts can be created from open sorts by applying substitutions.

Example:

𝕍 ∶ Set 𝕍 = {𝛼}

𝕊 ∶ Set → Set

𝕊(𝑋) = 𝑋 ∪ {String, int} ∪ {List(𝑥) ∣ 𝑥 ∈ 𝕊(𝑋)}

_+∶ (𝕍 → 𝕊(∅)) → 𝕊(𝕍) → 𝕊(∅)

𝑆+= { 𝛼 ↦ 𝑆(𝛼), List(𝑥) ↦ List(𝑆+(𝑥)), String ↦ String, int ↦ int}

𝑆 ∶ 𝕍 → 𝕊(∅) 𝑆(𝛼) = int

𝑆+(List(List(𝛼)) = List(List(𝑖𝑛𝑡))) 6 / 27

(9)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Signatures – Extensions

subsorting: define a preorder≤𝕊⊆ 𝕊(∅) × 𝕊(∅) on closed sorts

reflexivity: 𝑠1𝕊 𝑠1

transitivity: 𝑠1𝕊 𝑠2and𝑠2𝕊𝑠3 imply𝑠1𝕊 𝑠3

well-formed substitution spaces: restrict the space of valid substitions, s.t. 𝑆 ∈WF⊆ 𝕍 → 𝕊(∅)

Example:

𝕊(𝑋) = 𝑋 ∪ {Odd, Even, Nat} 𝕍 = {𝛼, 𝛽}

Σ𝕊,𝕍 = {one∶ Odd;

succ∶ 𝛼 ↠ 𝛽 }

Even ≤𝕊Natand Odd ≤𝕊Nat

WF⊆ 𝕍 → 𝕊(∅) WF= { {𝛼 ↦ Odd, 𝛽 ↦ Even}, {𝛼 ↦ Even, 𝛽 ↦ Odd}

{𝛼 ↦ Nat, 𝛽 ↦ Nat}}

(10)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Connecting Interface and Implementation

Definition (Subsorted Σ𝕊,𝕍-Algebra)

Given a term signature Σ𝕊,𝕍= (𝕆,arity,domain,range), a sort preorder ≤𝕊 and a function spaceWF⊆ 𝕍 → 𝕊(∅)of well-formed substitutions, a subsorted Σ𝕊,𝕍-Algebra is

A carrierℂ, which is a family of sets indexed by closed sorts𝑠 ∈ 𝕊(∅)and

A𝕊(∅) indexed family of morphisms𝑚𝑠∶ 𝔽𝑠(ℂ) → ℂ𝑠 where

𝔽𝑠(ℂ) = ∑

𝑆∈WF

𝑜∈ranged(𝑠,𝑆) arity(𝑜)

𝑖=1

𝑆+(𝜋𝑖(domain𝑜))

with ranged∶ 𝕊(∅) ×WF→ Setdefined by ranged(𝑠, 𝑆) = {𝑜 ∈ 𝕆 ∣ 𝑆+(range(𝑜)) ≤𝕊𝑠}.

8 / 27

(11)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Example (Carrier)

Σ𝕊,𝕍= {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } ℂ𝑠=

{exp∣ expis a Java expression s.t. program

import java.util.List;

public class C { private translate(𝑠) x = exp; }

compiles for

translate = { int ↦int, String ↦String, List(𝑥) ↦List<translate(𝑥)>}}

(12)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Example (morphisms)

Σ𝕊,𝕍= {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } 𝑚𝑠∶ 𝔽𝑠(ℂ) → ℂ𝑠 where

𝔽𝑠(ℂ) = ∑𝑆∈WF𝑜∈ranged(𝑠,𝑆)arity(𝑜)𝑖=1𝑆+(𝜋𝑖(domain𝑜))

with ranged(𝑠, 𝑆) = {𝑜 ∈ 𝕆 ∣ 𝑆+(range(𝑜)) ≤𝕊 𝑠}

𝑚List(String)(𝑆,allUsers, ()) =

new java.util.Arrays.asList("bob", "jack")

𝑚List(String)({𝛼 ↦ String},append, (𝑥, 𝑙)) = l.add(x)

10 / 27

(13)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Example (morphisms)

Σ𝕊,𝕍= {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } 𝑚𝑠∶ 𝔽𝑠(ℂ) → ℂ𝑠 where

𝔽𝑠(ℂ) = ∑𝑆∈WF𝑜∈ranged(𝑠,𝑆)arity(𝑜)𝑖=1𝑆+(𝜋𝑖(domain𝑜))

with ranged(𝑠, 𝑆) = {𝑜 ∈ 𝕆 ∣ 𝑆+(range(𝑜)) ≤𝕊 𝑠}

𝑚List(int)(𝑆,allUserIds, ()) =

new java.util.Arrays.asList(1, 2)

𝑚List(int)({𝛼 ↦ int},append, (𝑥, 𝑙)) = l.add(x)

(14)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Example (morphisms)

Σ𝕊,𝕍= {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } 𝑚𝑠∶ 𝔽𝑠(ℂ) → ℂ𝑠 where

𝔽𝑠(ℂ) = ∑

𝑆∈WF

𝑜∈ranged(𝑠,𝑆)arity(𝑜)

𝑖=1𝑆+(𝜋𝑖(domain𝑜))

with ranged(𝑠, 𝑆) = {𝑜 ∈ 𝕆 ∣ 𝑆+(range(𝑜)) ≤𝕊 𝑠}

𝑚String(𝑆,newUser, ()) ="trudy"

𝑚String({𝛼 ↦ String},first, 𝑙) =l.get(0)

12 / 27

(15)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Example (morphisms)

Σ𝕊,𝕍= {allUsers∶ List(String);

newUser∶ String;

allUserIds∶ List(int);

newUserId∶ int;

append∶ (𝛼, List(𝛼)) ↠ List(𝛼);

first∶ List(𝛼) ↠ 𝛼 } 𝑚𝑠∶ 𝔽𝑠(ℂ) → ℂ𝑠 where

𝔽𝑠(ℂ) = ∑

𝑆∈WF

𝑜∈ranged(𝑠,𝑆)arity(𝑜)

𝑖=1𝑆+(𝜋𝑖(domain𝑜))

with ranged(𝑠, 𝑆) = {𝑜 ∈ 𝕆 ∣ 𝑆+(range(𝑜)) ≤𝕊 𝑠}

𝑚int(𝑆,newUserId, ()) =3

𝑚int({𝛼 ↦ int},first, 𝑙) =l.get(0)

(16)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Algebra – Language Independence

By exchanging the carrierℂ we could have compiledΣ𝕊,𝕍 to any other language. Even untyped languages are no

problem, e.g. unary natural numbers:

Σ𝕊,𝕍 = {one∶ Odd;

succ∶ 𝛼 ↠ 𝛽 }

Odd∋ 𝑜 ∶∶=I∣I𝑒; ℂEven∋ 𝑒 ∶∶=I𝑜; ℂNat ∋ 𝑛 ∶∶= 𝑒 ∣ 𝑜 𝑚Even({𝛼 ↦ Odd, 𝛽 ↦ Even},succ, 𝑜) =I𝑜

𝑚Odd(𝑆,one, ()) =I

𝑚Odd({𝛼 ↦ Even, 𝛽 ↦ Odd},succ, 𝑒) =I𝑒 𝑚Nat = 𝑚Even∪ 𝑚Odd

14 / 27

(17)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Synthesis – Goal

Given a signatureΣ(𝕍,𝕊) (an interface), a well-formedness restriction WF, a subsort relation≤𝕊, an algebra (𝔻, ℎ)(an implementation), and a sort 𝑠(a goal), find all elements of 𝔻𝑠 (programs), which can be generated from the signature only using ℎ.

(18)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Synthesis – Battle Plan

1. Pick a well-understood small type system

Combinatory Logic with Intersection Types, Distributing Covariant Constructors and Finite Substitution Spaces 2. For the desired𝕊 find injective maps

J_K∶ (𝕊(𝑉 ) → 𝕋𝑉)𝑉 ∈{𝕍,∅}, from open and closed sorts to types𝕋 and type schemas 𝕋𝕍, such that

the maps respect subsorting/subtyping

commute with substitutions on sorts/type schemas

generated type (schemas) useonly in argument positioins of arrows

top-level arrows of generated type (schemas) are protected by type-constructors

3. GenerateΓ with entries

op∶J𝑠1K𝕍 →J𝑠2K𝕍→ … →J𝑠K𝕍 for each op∶ (𝑠1, 𝑠2, … , 𝑠𝑛) ↠ 𝑠 ofΣ(𝕊,𝕍)

4. Use inhabitationΓ ⊢ ? ∶J𝑠Kto produce terms of carrier ℂ𝑠= {𝑀 ∣ Γ ⊢ 𝑀 ∶J𝑠K}

5. Translate results to desired target carrier 𝔻𝑠

16 / 27

(19)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Combinatory Logic with Intersection Types

Γ(𝑥) = 𝜏 𝑆 ∈WF

(Var) Γ ⊢ 𝑥 ∶ 𝑆(𝜏 )

Γ ⊢ 𝑀 ∶a→b Γ ⊢ 𝑁 ∶a (→E) Γ ⊢ (𝑀 𝑁 ) ∶b

Γ ⊢ 𝑀 ∶a a≤b Γ ⊢ 𝑀 ∶b (≤)

Γ ⊢ 𝑀 ∶a Γ ⊢ 𝑀 ∶b (∩I) Γ ⊢ 𝑀 ∶a∩b

_∶ (𝕍 → 𝕋) → (𝕋𝕍→ 𝕋) lifts substitutions to type schemas, just like _+∶ (𝕍 → 𝕊) → (𝕊𝕍→ 𝕊) on sorts.

WFis a translation of the well-formed space we specify with our signature

(20)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Intersection Types and Distributing Covariant Constructors

𝐶1𝐶2 |𝐶1| = |𝐶2| ∀𝑛 ∶a𝑛b𝑛

(CAx) 𝐶1(a1,a2, … ,a|𝐶1|) ≤ 𝐶2(b1,b2, … ,b|𝐶2|)

(≤ 𝜔)

a≤ 𝜔 (→ 𝜔)

𝜔 ≤ 𝜔 → 𝜔

(CDist) 𝐶1(a1,a2, … ,a|𝐶1|) ∩ 𝐶1(b1,b2, … ,b|𝐶1|) ≤

𝐶1(a1b1,a2b2, … ,a|𝐶1|b|𝐶1|) a2a1 b1b2

(Sub) a1b1a2b2

(Dist) (ab1) ∩ (ab2) ≤ab1b2

(Idem)

aaa a1a2 a2a3

(Trans) a1a3

ab1 ab2

(GLB) ab1b2

(LUB1)

aba (LUB2)

abb 18 / 27

(21)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Constructors – Examples

(CDist) Pair(URL, Protocol) ∩ Pair(DatabaseLocation, Network) ≤

Pair(URL ∩ DatabaseLocation, Protocol ∩ Network)

List ≤List |List| = 1

Even ≤Nat |Even| = 0 = |Nat|

(CAx) Even ≤ Nat

(CAx) List(Even) ≤ List(Nat)

Exercise:

Show 𝜔 ≤a→ 𝜔 and

(a1→b1) ∩ (a2→b2) ≤a1∩a2→b1∩b2

(22)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Sort Translations

We can find the sort translation J_K for all sorts isomorphic to regular trees:

𝔗𝕍 ∋ 𝑡1, 𝑡2… , 𝑡𝑛∶∶= 𝑙(𝑡1, … , 𝑡arity(𝑙)) ∣ 𝛼 respecting variance labeled subtyping:

𝑙1𝕃𝑙2 arity(𝑙1) = arity(𝑙2)

∀𝑛 ∶ v𝑙1(𝑛) = v𝑙2(𝑛) 𝑡𝑛𝔗𝑡𝑛 ifv𝑙1(𝑛) =co 𝑡𝑛𝔗𝑡𝑛ifv𝑙1(𝑛) =contra 𝑡𝑛𝔗𝑡𝑛∧ 𝑡𝑛𝔗𝑡𝑛ifv𝑙

1(𝑛) =in 𝑙1(𝑡1, … , 𝑡𝑛) ≤𝔗𝑙2(𝑡1, … , 𝑡𝑛)

Subtyping example:

arity(Arrow) = 2, vArrow(0) =contra, vArrow(1) =co Arrow(Nat, Even) ≤𝔗 Arrow(Even, Nat)

Translation idea:

J𝑙(𝑡1, 𝑡2, … 𝑡𝑛)K𝕍 =

■((𝑙(J𝑡1Kv𝑙,J𝑡2Kv𝑙, … ,J𝑡𝑛Kv𝑙) → •) → •)

J𝑡Kco= (J𝑡K𝕍→ •) → •J𝑡Kcontra= (• →J𝑡K𝕍) → • J𝑡Kin = (J𝑡K𝕍 →J𝑡K𝕍) → •

20 / 27

(23)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Inhabitation – Combinatory Logic with Intersection Types

For finite well-formed substitution spaces we have

Type checking (Γ ⊢ 𝑀 ∶a?) is decidable

Type inhabitation (Γ ⊢ ? ∶a) is decidable

the system is a slight extension of [3]

we also get a grammar describing all inhabitants

When we have specifications Γ1,WF1,a and Γ2,WF2,busing completely unrelated constructor symbols we can use

Γ(𝑥) = Γ1(𝑥) ∩ Γ2(𝑥),WF=WF1⊎WF2 and get Γ ⊢ 𝑀 ∶a∩b⇔ Γ1⊢ 𝑀 ∶aand Γ2⊢ 𝑀 ∶b

we can refine the search for inhabitants using multiple specifications in addition to signatures

warning: this only holds for unrelated constructor symbols!

(24)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Target Translation

Fs(D) Cs Ds

hs

fs

We want a function 𝑓𝑠to translate inhabitation results ℂ𝑠= {𝑀 ∣ Γ ⊢ 𝑀 ∶J𝑠K} to some target language carrier𝔻𝑠, for which we have an algebraℎ𝑠

We can proof that there is a coalgebra 𝑚−1𝑠 ∶ ℂ𝑠→ 𝔽𝑠(ℂ):

for a term𝑀 =op𝑀1𝑀2… 𝑀arity(𝑜𝑝) with typeJ𝑠K

we get𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(𝑜𝑝)))

We construct𝑓𝑠by solving the fixpoint equation: 𝑓 = (ℎ𝑠∘ 𝔽(𝑓)𝑠∘ 𝑚−1𝑠 )

𝑠∈𝕊(∅)

base case: the size of𝑀 is 1, hence𝑀 =op,

arity(op) = 0and𝑚−1𝑠 (𝑀) = (𝑆,op, ()): solve by𝑠.

recursion: the size is𝑛 + 1we have

𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(op)))with smaller𝑀𝑖: solve by𝑠 and𝑓𝑠 on smaller parts.

22 / 27

(25)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Target Translation

Fs(C) Fs(D) Cs Ds

hs

m−1s

fs

We want a function 𝑓𝑠to translate inhabitation results ℂ𝑠= {𝑀 ∣ Γ ⊢ 𝑀 ∶J𝑠K} to some target language carrier𝔻𝑠, for which we have an algebraℎ𝑠

We can proof that there is a coalgebra 𝑚−1𝑠 ∶ ℂ𝑠→ 𝔽𝑠(ℂ):

for a term𝑀 =op𝑀1𝑀2… 𝑀arity(𝑜𝑝) with typeJ𝑠K

we get𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(𝑜𝑝)))

We construct𝑓𝑠by solving the fixpoint equation: 𝑓 = (ℎ𝑠∘ 𝔽(𝑓)𝑠∘ 𝑚−1𝑠 )

𝑠∈𝕊(∅)

base case: the size of𝑀 is 1, hence𝑀 =op,

arity(op) = 0and𝑚−1𝑠 (𝑀) = (𝑆,op, ()): solve by𝑠.

recursion: the size is𝑛 + 1we have

𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(op)))with smaller𝑀𝑖: solve by𝑠 and𝑓𝑠 on smaller parts.

(26)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Target Translation

Fs(C) Fs(D) Cs Ds

F(f)s hs

m−1s

fs

We want a function 𝑓𝑠to translate inhabitation results ℂ𝑠= {𝑀 ∣ Γ ⊢ 𝑀 ∶J𝑠K} to some target language carrier𝔻𝑠, for which we have an algebraℎ𝑠

We can proof that there is a coalgebra 𝑚−1𝑠 ∶ ℂ𝑠→ 𝔽𝑠(ℂ):

for a term𝑀 =op𝑀1𝑀2… 𝑀arity(𝑜𝑝) with typeJ𝑠K

we get𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(𝑜𝑝)))

We construct𝑓𝑠 by solving the fixpoint equation:

𝑓 = (ℎ𝑠∘ 𝔽(𝑓)𝑠∘ 𝑚−1𝑠 )

𝑠∈𝕊(∅)

base case: the size of𝑀 is 1, hence𝑀 =op,

arity(op) = 0and𝑚−1𝑠 (𝑀) = (𝑆,op, ()): solve by𝑠.

recursion: the size is𝑛 + 1we have

𝑚−1𝑠 (𝑀) = (𝑆,op, (𝑀1, 𝑀2, … , 𝑀arity(op)))with

smaller𝑀𝑖: solve by𝑠 and𝑓𝑠 on smaller parts. 22 / 27

(27)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Target Translation – Properties

Fs(C) Fs(D) Cs Ds

F(f)s

hs m−1s

fs

The construction is (up to choice of well-formed sort substitutions):

Sound: all generated𝔻𝑠 terms areℎ𝑠 interpretations of signature operations

Complete: by listing allℂ𝑠 we get all 𝔻𝑠 which areℎ𝑠 interpretations of signature operations

Unique: all possible ways of constructing a translation 𝑓𝑠 yield identical results to our construction

(28)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Related Approaches

Traditionally, multi-sorted signatures don’t use sub-typing and variables

if we leave them out, the signature specifications are compatible e.g. with those in lectures by Prof.

Padawitz [4]

the fixpoint constrution of𝑓𝑠 is related to Lambek’s Lemma ([6], Lemma 1)

Without additions one can also use SMT Solving [5]

An ad-hoc solving approach was used in [2]

24 / 27

(29)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala)

Conclusion References

Demo (Scala)

(30)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

Conclusion

Signatures are generic interface descriptions and algebras implementations

Algebraic bureaucracy is powerful enough to cut through the programming language chaos

We can connect (almost arbitrary) signatures with combinatory logic

Synthesis can be done outside the ”simple” world of𝜆

26 / 27

(31)

Synthesis Jan Bessai

Algebra

Signatures Terms

Synthesis

Type System Sort Translations Inhabitation Target Translation

Demo (Scala) Conclusion References

References

[1] Nada Amin and Ross Tate.“Java and Scala’s Type Systems are Unsound: The Existential Crisis of Null Pointers”.In:Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications.

ACM. 2016, pp. 838–848.

[2] Luís Eduardo de Souza Amorim, Sebastian Erdweg, Guido Wachsmuth, and Eelco Visser.“Principled Syntactic Code Completion Using Placeholders”.In:

Proceedings of the 2016 ACM SIGPLAN International Conference on Software Language Engineering. SLE 2016. Amsterdam, Netherlands: ACM, 2016, pp. 163–175.isbn: 978-1-4503-4447-0.doi:

10.1145/2997364.2997374.url:

http://doi.acm.org/10.1145/2997364.2997374.

[3] Boris Düdder, Moritz Martens, Jakob Rehof, and Pawel Urzyczyn.“Bounded Combinatory Logic”.In:

Computer Science Logic (CSL’12) - 26th International Workshop/21st Annual Conference of the EACSL, CSL 2012, September 3-6, 2012, Fontainebleau, France.

2012, pp. 243–258.doi:

10.4230/LIPIcs.CSL.2012.243.url:http:

//dx.doi.org/10.4230/LIPIcs.CSL.2012.243.

[4] Peter Padawitz.“From Grammars and Automata to Algebras and Coalgebras”.In:Algebraic Informatics - 4th International Conference, CAI 2011, Linz, Austria, June 21-24, 2011. Proceedings. 2011, pp. 21–43.doi:

10.1007/978-3-642-21493-6_2.url:http:

//dx.doi.org/10.1007/978-3-642-21493-6_2.

[5] Andrew Reynolds, Viktor Kuncak, Cesare Tinelli, Clark Barrett, and Morgan Deters.“Refutation-based synthesis in SMT”.In:Formal Methods in System Design(Feb. 16, 2017), p. 1.issn: 1572-8102.doi:

10.1007/s10703-017-0270-2.url:

http://dx.doi.org/10.1007/s10703-017-0270-2.

[6] Michael B. Smyth and Gordon D. Plotkin.“The Category-Theoretic Solution of Recursive Domain Equations”.In:SIAM J. Comput.11.4 (1982), pp. 761–783.doi:10.1137/0211062.

Referenzen

ÄHNLICHE DOKUMENTE

Proceedings of the 11th International Conference on Cognitive Modeling. 1HOH5X‰ZLQNHO8ZH'UHZLW] Hedderik van

In high speed networks, to achieve maximum capacity, sometimes extended MTU size (Jumbo frames till 9 000 bytes) is used. So it makes sense to check whether these packet sizes

Traditional FFT hardware architectures include trade-offs among complexity, power consumption, die size, and other similar parameters. Still, these architectures don’t have the

In order to solve this problem, in this paper we propose a novel memory-centric architecture that adds processing hardware directly to the code memory blocks used for

Figure 1: Class diagram of Strategy pattern Design patterns are classified by their purposes into three categories of patterns: creational, structural and behavioral

In OOPSLA ’05: Proceedings of the 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pages 519–538, New York, NY, USA,

To avoid the common problems that result from ontologies having greater expressive power compared to object-oriented pro- gramming (OOP) languages (as pointed out by [Or07]),

Rhapsody (see [Inc]) is based on the executable modeling work presented in [HG97], which was originally intended as a carefully worked out language set based on Booch and OMT