Docsity

Logical Equivalence of Algebraic Effects in Programming: A Sound and Complete Logic, Study notes of Logic

Partial preview of the text

Download Logical Equivalence of Algebraic Effects in Programming: A Sound and Complete Logic and more Study notes Logic in PDF only on Docsity!

A Sound and Complete Logic for

Algebraic Effects

Cristina Matache (joint work with Sam Staton)

University of Oxford

Question

Programming Language

▶ Higher-order functions ▶ Algebraic effects [Plotkin & Power] ▶ Recursive functions ▶ Continuation passing (CPS)

Logic M ⊧ ϕ

program

formula

program property

Contextual

Equivalence

Main

Theorem

[Matache & Staton, FoSSaCS’19]

Logical Equivalence

¾ϕ: M ⊧ ϕ ⟺ N ⊧ ϕ:

Motivation: [Simpson & Voorneveld, ESOP’18].

Outline

1 Introduction: Program Equivalence and CPS

2 Programming Calculus

3 Logic

4 Main Theorem

Program equivalence

Establishes when two programs have

the same behaviour.

Higher-order functions make it hard.

Effects make it hard.

Example or x ; y  nondeterministically choose x or y Want: or or 1 2

or 1 or 2 3

or

or

6 or

Behavioural Logic

Logic M ⊧ ϕ

program

formula

program property

⊧ describes the behaviour of programs

Example

or ( or 1 ; 2 ; 3 ) ⊧ ◇r 3 x may return 3

⊧ □r 1 ; 2 ; 3 x

always returns one of r 1 ; 2 ; 3 x

Behavioural Logic

Logic M ⊧ ϕ

program

formula

program property

⊧ describes the behaviour of programs

Logical Equivalence

M ≡log N iff ¾ϕ: M ⊧ ϕ ⟺ N ⊧ ϕ:

Want: ≡ log  ≡ctx

Outline

1 Introduction: Program Equivalence and CPS

2 Programming Calculus

3 Logic

4 Main Theorem

ECPS Calculus

▶ Types: A ; Ai ≔ A 1 ; : : : ; An R ∣ nat n ' 0  ▶ Values vs. computations

Γ;  x  ∶ A ⊢c^ t ∶ R Γ ⊢v^ 

x ∶ A : t ∶

A R

Γ ⊢v^ v ∶  A R Γ ⊢v^ wi ∶ Ai  i Γ ⊢c^ v  w  ∶ R

ECPS Calculus

▶ Types: A ; Ai ≔ A 1 ; : : : ; An R ∣ nat n ' 0  ▶ Values vs. computations Γ;  x  ∶ A ⊢c^ t ∶ R Γ ⊢v^  x ∶ A : t ∶  A R

Γ ⊢v^ v ∶  A R Γ ⊢v^ wi ∶ Ai  i Γ ⊢c^ v  w  ∶ R ▶ Effect operations.

 " Σ Γ ⊢v Σ vi ∶ nat i Γ ⊢v Σ kj ∶ nat; : : : ; natR j

Γ ⊢c Σ  vi ;

kj  ∶ R

▶ Recursion

Examples of Effect Signatures

Probability: p - or ∶ (R; R)R (^) like h ∶ R  R R

geom k (^) k 1

k 2

k 3

▶ geom computes the geometric distribution: it passes n to the continuation k with probability (^21) n.

geom  k ∶natR: (rec f :  n ∶nat; k ¬∶natR: p - or : k ¬^ n ; : f succ n ; k ¬ ) 1 ; k :

Examples of Effect Signatures

Probability: Σ r p - or ∶ (R; R)R;  ∶ Rx

Computation tree

geom k (^) k 1

k 2 k 3

Jgeom  x ∶nat:  K p - or  p - or  geometric distribution^ Jgeom^  x ∶nat:^ ^ K

Examples of Effect Signatures

Nondeterminism: Σ r or ∶ (R; R)R;  ∶ Rx

Abstract syntax tree Computation tree

three_or_four k

k 4

k 3 k 4

Jthree_or_four  x ∶nat: if x 4 then  else loop K or  or ⊥ 

▶ three_or_four returns either 3 or 4 to continuation.

Observations

Observation P Set of trees

▶ Σ Success: rx ▶ Σ Probability: for q " Q; 0 & q $ 1 P% q rtrees that succeed with probability % q x ▶ Σ Nondeterminism: ◇ rtrees with at least one  leafx □ rtrees of finite height with only  leavesx ▶ Σ Global store: S " L ⟶ N  S  rtrees that succeed when started in state S x

Observations

Observation P Set of trees

▶ Σ Success: rx

Jtest_zero 0 K  "