Behavioral Types and Logical Frameworks An Introduction Carsten Sch - - PowerPoint PPT Presentation

behavioral types and logical frameworks an introduction
SMART_READER_LITE
LIVE PREVIEW

Behavioral Types and Logical Frameworks An Introduction Carsten Sch - - PowerPoint PPT Presentation

Behavioral Types and Logical Frameworks An Introduction Carsten Sch urmann IT University of Copenhagen carsten@demtech.dk March 7, 2019 March 7, 2019 1 / 41 Motivation Buzzwords Concurrency Linear Logic Delegation


slide-1
SLIDE 1

Behavioral Types and Logical Frameworks An Introduction

Carsten Sch¨ urmann IT University of Copenhagen

carsten@demtech.dk

March 7, 2019

March 7, 2019 1 / 41

slide-2
SLIDE 2

Motivation

Buzzwords

◮ Concurrency ◮ Linear Logic ◮ Delegation ◮ Services ◮ Security

March 7, 2019 2 / 41

slide-3
SLIDE 3

Motivating Example

On a laptop not far from here ...

You want to buy a book form and online store, but only if the price is right.

March 7, 2019 3 / 41

slide-4
SLIDE 4

Motivating Example

On a laptop not far from here ...

You want to buy a book form and online store, but only if the price is right. Observations:

◮ More than one agent involved ◮ It is difficult to capture the invariant of such a system ◮ The “type” needs to capture the protocol of how messages are exchanged.

March 7, 2019 3 / 41

slide-5
SLIDE 5

Buyer B Seller S Select book title Lookup price price Sorry msc No!

March 7, 2019 4 / 41

slide-6
SLIDE 6

Buyer B Seller S Select book title Lookup price price Choose address address msc Yes!

March 7, 2019 5 / 41

slide-7
SLIDE 7

Ingredients

◮ Concurrency Theory

[Caires, Carbone, Gay, Honda, Yoshida]

◮ Logic

[Pfenning, CS, Toninho, Wadler]

◮ Programming Languages

[Pfenning, Montesi, Toninho]

March 7, 2019 6 / 41

slide-8
SLIDE 8

Substructural Logical Frameworks

“25 + 5 = 3 × 10”

March 7, 2019 7 / 41

slide-9
SLIDE 9

Substructural Logical Frameworks

“25 + 5 = 3 × 10”

March 7, 2019 7 / 41

slide-10
SLIDE 10

Substructural Logical Frameworks

“25 + 5 = 3 × 10”

March 7, 2019 7 / 41

slide-11
SLIDE 11

Substructural Logical Frameworks

“25 + 5 = 3 × 10” Concurrent LF [Cervesato et al. ’02] SSOS [Pfenning, Simmons ’13] Celf [Schack-Nielsen, CS’11] R1 : q ⊸ {d ⊗ d ⊗ n}. R2 : n ⊸ n ⊸ {d}.

March 7, 2019 7 / 41

slide-12
SLIDE 12

Substructural Logical Frameworks

“25 + 5 = 3 × 10” Concurrent LF [Cervesato et al. ’02] SSOS [Pfenning, Simmons ’13] Celf [Schack-Nielsen, CS’11] R1 : q ⊸ {d ⊗ d ⊗ n}. R2 : n ⊸ n ⊸ {d}.

Observation

◮ Multi-formula premisses ◮ Multi-formula conclusions ◮ Multi-set rewriting

March 7, 2019 7 / 41

slide-13
SLIDE 13

The Concurrent World is Substructural

Substructural Logical Framework

Dependently typed language for multi-set rewriting rules ⊗ Connective to group facts ⊸ Connective to express rewrite rules ∃ To create new evidence of facts Π To quantify over evidence of facts

Substructural Operational Semantics

Multi-set rewriting semantics

◮ Forward-Chaining Search ◮ Runs until quiescence ◮ All truth is ephemeral

March 7, 2019 8 / 41

slide-14
SLIDE 14

Motivation

The Central Questions of this Talk

What happens if we shift from a process algebra view of concurrency/session types to a purely logical view? And how to do this shift?

March 7, 2019 9 / 41

slide-15
SLIDE 15

1 Linear Logic 2 Session Types -as- Judgments 3 Adding Choice 4 Substructual Logical Framework CLF 5 Programming with Session Types 6 Demo 7 Conclusion and Future Work

March 7, 2019 10 / 41

slide-16
SLIDE 16

Linear Logic

Linear Logic March 7, 2019 11 / 41

slide-17
SLIDE 17

Judgmental reconstruction

Intuitionistic Logic

Logic of truth. .

Linear Logic

Logic of ephemeral resources. . ∆ ⊢ A

Linear Logic March 7, 2019 12 / 41

slide-18
SLIDE 18

Judgmental reconstruction

Intuitionistic Logic

Logic of truth. (Logic of facts).

Linear Logic

Logic of ephemeral resources. (Logic of food). ∆ ⊢ A

Linear Logic March 7, 2019 12 / 41

slide-19
SLIDE 19

Judgmental reconstruction

Intuitionistic Logic

Logic of truth. (Logic of facts).

Linear Logic

Logic of ephemeral resources. (Logic of food). ∆ ⊢ A Important Properties:

◮ Cut-Elimination guarantees proof normalization ◮ Focusing limits proofs but not provability

Linear Logic March 7, 2019 12 / 41

slide-20
SLIDE 20

Linear Logic – The Rules

· ⊢ 1 1R ∆ ⊢ C ∆, 1 ⊢ C 1L ∆1 ⊢ A ∆2 ⊢ B ∆1, ∆2 ⊢ A ⊗ B ⊗R ∆, A, B ⊢ C ∆, A ⊗ B ⊢ C ⊗L ∆, A ⊢ B ∆ ⊢ A ⊸ B ⊸R ∆1 ⊢ A ∆2, B ⊢ C ∆1, ∆2, A ⊸ B ⊢ C ⊸L A ⊢ A init ∆1 ⊢ A ∆2, A ⊢ C ∆1, ∆2 ⊢ C cut

Linear Logic March 7, 2019 13 / 41

slide-21
SLIDE 21

Linear Logic — Theorems

Goes back to ... [Girard ’89]

Theorem (Admissibility of init)

For any formula A: A ⊢ A.

Theorem (Admissibility of cut)

If ∆1 ⊢ A and ∆2, A ⊢ C then ∆1, ∆2 ⊢ C.

Linear Logic March 7, 2019 14 / 41

slide-22
SLIDE 22

Session Types -as- Judgments

Session Types -as- Judgments March 7, 2019 15 / 41

slide-23
SLIDE 23

Linear Logic - Primitive Types

◮ Making Linear Logic practical ◮ τ ranges over strings, integers, ...

Γ ⊢ τ inhabited Γ; ∆ ⊢ B Γ; ∆ ⊢ τ ∧ B ∧R Γ, τ; ∆, B ⊢ C Γ; ∆, τ ∧ B ⊢ C ∧L Γ, τ; ∆ ⊢ B Γ; ∆ ⊢ τ ⊃ B ⊃ R Γ ⊢ τ inhabited Γ; ∆, B ⊢ C Γ; ∆, τ ⊃ B ⊢ C ⊃ L

Session Types -as- Judgments March 7, 2019 16 / 41

slide-24
SLIDE 24

Linear Logic - Primitive Types

◮ Making Linear Logic practical ◮ τ ranges over strings, integers, ...

Γ ⊢ M : τ inhabited Γ; ∆ ⊢ T : B Γ; ∆ ⊢ send M; T : τ ∧ B ∧R Γ, x : τ; ∆, u : B ⊢ T : C Γ; ∆, u : τ ∧ B ⊢ receive (x) [u]; T : C ∧L Γ, x : τ; ∆ ⊢ T : B Γ; ∆ ⊢ receive (x); T : τ ⊃ B ⊃ R Γ ⊢ M : τ inhabited Γ; ∆, u : B ⊢ T : C Γ; ∆, u : τ ⊃ B ⊢ send M [u]; T : C ⊃ L

Session Types -as- Judgments March 7, 2019 16 / 41

slide-25
SLIDE 25

Encoding in a Substructural Logical Framework

[Pfenning and Griffith ’15] Terms T 1R end 1L wait [u]; T ∧R send M; T ∧L receive (x) [u]; T ⊃R receive (x); T ⊃L send M [u]; T ⊗R, ⊗L ... ⊸R,⊸L ... Alternative: π-calculus [Caires & Pfenning ’10, Wadler ’12] Related: Classical version of linear logic [Wadler’12]

Session Types -as- Judgments March 7, 2019 17 / 41

slide-26
SLIDE 26

Session Typing our Buyer Seller Example

B ⊢ string ∧ (nat ⊃ 1) S (string ∧ (nat ⊃ 1)) ⊢ 1

Comments

◮ B aka buyer ◮ S aka seller ◮ Denote the derivation of the judgment

Session Types -as- Judgments March 7, 2019 18 / 41

slide-27
SLIDE 27

Buyer and Seller Example

B ⊢ string ∧ (nat ⊃ 1) S u:(string ∧ (nat ⊃ 1)) ⊸ 1 ⊢ 1 Buyer B = send ”Harry potter”; receive (price); end Seller S [u] = receive (title) [u]; send $45 [u]; wait [u]; end System C = cut B (S [u]).

Session Types -as- Judgments March 7, 2019 19 / 41

slide-28
SLIDE 28

Adding Choice

Adding Choice March 7, 2019 20 / 41

slide-29
SLIDE 29

Linear Logic – The Additives

∆ ⊢ A1 ∆ ⊢ A2 ∆ ⊢ A1&A2 &R ∆, A1 ⊢ C ∆, A1&A2 ⊢ C &L1 ∆, A2 ⊢ C ∆, A1&A2 ⊢ C &L2 ∆ ⊢ A1 ∆ ⊢ A1 ⊕ A2 ⊕R1 ∆ ⊢ A2 ∆ ⊢ A1 ⊕ A2 ⊕R2 ∆, A1 ⊢ C ∆, A2 ⊢ C ∆, A1 ⊕ A2 ⊢ C ⊕L

Adding Choice March 7, 2019 21 / 41

slide-30
SLIDE 30

Linear Logic – The Additives

∆ ⊢ T1 : A1 ∆ ⊢ T2 : A2 ∆ ⊢ offer (left ⇒ T1, right ⇒ T2) : A1&A2 &R ∆, u : A1 ⊢ T : C ∆, u : A1&A2 ⊢ left [u]; T : C &L1 ∆, u : A2 ⊢ T : C ∆, u : A1&A2 ⊢ right [u]; T : C &L2 ∆ ⊢ T : A1 ∆ ⊢ left; T : A1 ⊕ A2 ⊕R1 ∆ ⊢ T : A2 ∆ ⊢ right; T : A1 ⊕ A2 ⊕R2 ∆, v : A1 ⊢ T1 : C ∆, w : A2 ⊢ T2 : C ∆, u : A1 ⊕ A2 ⊢ offer [u] (left ⇒ [v]; T1, right ⇒ [w]; T2) : C ⊕L

Adding Choice March 7, 2019 21 / 41

slide-31
SLIDE 31

Buyer B Seller S Select book title Lookup price price Choose address address msc Yes! B = send ”Harry Potter”; receive (price); left; send (”Berlin”); end S = receive (title) [u]; send $45 [u];

  • ffer[u](

left ⇒ receive (address) [u]; wait [u]; end right ⇒ wait [u]; end)

Adding Choice March 7, 2019 22 / 41

slide-32
SLIDE 32

Substructual Logical Framework CLF

Substructual Logical Framework CLF March 7, 2019 23 / 41

slide-33
SLIDE 33

Substructural Logics

Lambek Logic Linear Logic Affine Logic Relevant Logic Intuitionistic Logic

Substructual Logical Framework CLF March 7, 2019 24 / 41

slide-34
SLIDE 34

Substructural Logical Frameworks

OLF LLF/CLF LF

Substructual Logical Framework CLF March 7, 2019 25 / 41

slide-35
SLIDE 35

Substructural Logics

A1, . . . , Am B1, . . . , Bn name

◮ In LLF order matters

[Girard ’89, Cervesato et al ’96] name : A1 ⊗ · · · ⊗ Am ⊸ B1 ⊗ · · · ⊗ Bn

◮ In CLF order does not matter

[Cervesato et al ’02] name : A1 ⊗ · · · ⊗ Am ⊸ {B1 ⊗ · · · ⊗ Bn}

Substructual Logical Framework CLF March 7, 2019 26 / 41

slide-36
SLIDE 36

Execution as Proof Search

◮ Proof search

A . . . B corresponds to inhabitation of types. A ⊸ {B}

◮ All terms are equal modulo interleavings ◮ No leftovers in the multi-set allowed ◮ Lollimon

[Lopez et al. ’05]

◮ Focusing

[Andreoli ’92, Chaudhuri ’06, Miller ’05]

Substructual Logical Framework CLF March 7, 2019 27 / 41

slide-37
SLIDE 37

Logical Framework CLF

◮ Focused version of Linear Logic

[Andreoli ’92]

◮ Conservative Extension of LF

[Honsell, Harper, Plotkin ’93]

◮ Types:

A ::= P | S ⊸ A | Πx : S. A | A1 & A2 | {S} P ::= a | P N S ::= 1 | S1 ⊗ S2 |!A | @A | A | ∃x : S1. S2

◮ Kinds:

K ::= type | Πx : A. K We write A → B for Πx : A. B if x does not occur in B.

Substructual Logical Framework CLF March 7, 2019 28 / 41

slide-38
SLIDE 38

CLF — Terms

Term syntax: N ::= λp. N | N1, N2 | | {E} | c | x | N1 N2 | π1 N | π2 N Objects E ::= let {p} = N in E | M Expressions M ::= M1 ⊗ M2 | 1 | N |!N | @N | [N, M] Monadic objects p ::= p1 ⊗ p2 | 1 | x |!x | @x | [x, p] Patterns

Judgment

Let Γ unrestricted, Φ affine and ∆ linear context. Γ; Φ; ∆ ⊢ N : A Equational Theory: α, β, η + let-floating

Substructual Logical Framework CLF March 7, 2019 29 / 41

slide-39
SLIDE 39

Judgments-as-types

  • P

A1, . . . , An ⊢ C

  • =

·; u1 : hyp A1, . . . un : hyp An ⊢ M : conc A

Logical Framework Representation

  • : type.

(Formulas) conc : o -> type (Conclusions) hyp : o -> type ( Hypotheses)

Substructual Logical Framework CLF March 7, 2019 30 / 41

slide-40
SLIDE 40

Example

buyer : conc (and string (imp nat one)) = send "Harry Potter" ( receive λ!price. end). seller : hyp (and string (imp nat one)) -o conc one = λu. receive (λ!title. λv. send $45 (λw. wait end w) v) u.

Substructual Logical Framework CLF March 7, 2019 31 / 41

slide-41
SLIDE 41

Programming with Session Types

Programming with Session Types March 7, 2019 32 / 41

slide-42
SLIDE 42

Cut-Elimination

P ∆, A ⊢ B ∆ ⊢ A ⊸ B ⊸R Q1 ∆1 ⊢ A Q2 ∆2, B ⊢ C ∆1, ∆2, A ⊸ B ⊢ C ⊸L ∆, ∆1, ∆2 ⊢ C cut

Programming with Session Types March 7, 2019 33 / 41

slide-43
SLIDE 43

Cut-Elimination

P ∆, A ⊢ B ∆ ⊢ A ⊸ B ⊸R Q1 ∆1 ⊢ A Q2 ∆2, B ⊢ C ∆1, ∆2, A ⊸ B ⊢ C ⊸L ∆, ∆1, ∆2 ⊢ C cut reduces to

Programming with Session Types March 7, 2019 33 / 41

slide-44
SLIDE 44

Cut-Elimination

P ∆, A ⊢ B ∆ ⊢ A ⊸ B ⊸R Q1 ∆1 ⊢ A Q2 ∆2, B ⊢ C ∆1, ∆2, A ⊸ B ⊢ C ⊸L ∆, ∆1, ∆2 ⊢ C cut reduces to Q1 ∆1 ⊢ A P ∆, A ⊢ B ∆, ∆1 ⊢ B cut Q2 ∆2, B ⊢ C ∆, ∆1, ∆2 ⊢ C cut

Programming with Session Types March 7, 2019 33 / 41

slide-45
SLIDE 45

Multi-Set Reduction

   P ∆, A ⊢ B , Q1 ∆1 ⊢ A , Q2 ∆2, B ⊢ C   

= ⇒ . . .

= ⇒    Q · ⊢ 1   

Programming with Session Types March 7, 2019 34 / 41

slide-46
SLIDE 46

Processes: always on, always connected!

   Q1 ∆1 ⊢ A , P ∆, u : A ⊢ B    = ⇒    R ∆1, ∆ ⊢ B   

Representation in CLF

proc : conc A -> hyp A -> type. Related: Modality •A [Carbone, Montesi, CS ’14]

Programming with Session Types March 7, 2019 35 / 41

slide-47
SLIDE 47

Example

Cutting buyer and seller

∆ = u: hyp one, p: proc (cut buyer λv. seller v) u,

After resolving the cut

∆′ = u : hyp one, a : hyp (and string (imp nat one)), p1: proc buyer a, p2: proc (seller a) u red/cut : proc (cut P (λv. Q v)) C ⊸ { ∃a. proc P a ⊗ proc (Q a) C }.

Programming with Session Types March 7, 2019 36 / 41

slide-48
SLIDE 48

Implementing Admissibility of Cut

red/lolli : proc (lolliR (λu. P u)) C ⊸ proc (lolliL Q1 (λv. Q2 v) C) C’’ ⊸ { ∃a. proc Q1 a ⊗ ∃b. proc (P a) b ⊗ proc (Q2 b) C’’}. red/one : proc end C ⊸ proc (wait T C) C’’ ⊸ { proc T C’’}. red/and : proc (send M P) C ⊸ proc (receive (λ!x. λu. Q !x u) C) C’’ ⊸ { ∃a. proc P a ⊗ proc (Q !M a) C’’}.

Programming with Session Types March 7, 2019 37 / 41

slide-49
SLIDE 49

Demo

Demo March 7, 2019 38 / 41

slide-50
SLIDE 50

Session types -as- Judgments -as- Types

Theorem (Adequacy)

The representation in the Logical Framework is adequate, meaning that there exists a bijection between “processes” and objects.

Theorem (Reduction)

A “process” reduces to normal form iff the forward-chaining semantics reduces the encoded processes. The normal forms correspond.

Theorem (Concurrency)

Concurrent interleavings are truthfully represented in the framework.

Demo March 7, 2019 39 / 41

slide-51
SLIDE 51

Conclusion and Future Work

Conclusion and Future Work March 7, 2019 40 / 41

slide-52
SLIDE 52

Conclusion and Future Work

◮ The logical framework community has developed tools useful for

understanding session typing.

◮ Equational theory of the logical framework hides commutative cuts, when

programming.

◮ We are currently working on extensions to multi-party session types.

Preliminary results, see our papers in Concur ’15 and ’16.

Conclusion and Future Work March 7, 2019 41 / 41