A Logical Study of Program Equivalence Guilhem Jaber Ecole des - - PowerPoint PPT Presentation

a logical study of program equivalence
SMART_READER_LITE
LIVE PREVIEW

A Logical Study of Program Equivalence Guilhem Jaber Ecole des - - PowerPoint PPT Presentation

A Logical Study of Program Equivalence Guilhem Jaber Ecole des Mines de Nantes LINA - Ascola PhD Defense Institut Henri Poincar e (Paris) July 11th 2014 1 / 38 Why study the Equivalence of Programs ? Specification of programs


slide-1
SLIDE 1

A Logical Study of Program Equivalence

Guilhem Jaber

Ecole des Mines de Nantes LINA - Ascola

PhD Defense Institut Henri Poincar´ e (Paris) July 11th 2014

1 / 38

slide-2
SLIDE 2

Why study the Equivalence of Programs ?

Specification of programs

Equivalence between a program we can trust and an optimized one.

2 / 38

slide-3
SLIDE 3

Why study the Equivalence of Programs ?

Specification of programs

Equivalence between a program we can trust and an optimized one.

Compiler optimizations.

Towards verified compilers.

2 / 38

slide-4
SLIDE 4

Why study the Equivalence of Programs ?

Specification of programs

Equivalence between a program we can trust and an optimized one.

Compiler optimizations.

Towards verified compilers.

Representation independence of Data

Parametricity, Free theorems.

2 / 38

slide-5
SLIDE 5

Why study the Equivalence of Programs ?

Specification of programs

Equivalence between a program we can trust and an optimized one.

Compiler optimizations.

Towards verified compilers.

Representation independence of Data

Parametricity, Free theorems.

Crucial in denotational semantics

Full-abstraction result.

2 / 38

slide-6
SLIDE 6

What kind of Equivalence ?

Contextual Equivalence

Programs seen as black boxes.

3 / 38

slide-7
SLIDE 7

What kind of Equivalence ?

Contextual Equivalence

Programs seen as black boxes.

Extensional behavior of programs

Observational equivalence.

3 / 38

slide-8
SLIDE 8

What kind of Equivalence ?

Contextual Equivalence

Programs seen as black boxes.

Extensional behavior of programs

Observational equivalence.

Depends on the language contexts are written in

discriminating power of contexts, from purely functional languages to assembly code.

3 / 38

slide-9
SLIDE 9

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x}

4 / 38

slide-10
SLIDE 10

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x} with Integers and Booleans: if b then 0 else n + 1

4 / 38

slide-11
SLIDE 11

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x} with Integers and Booleans: if b then 0 else n + 1 with higher-order references: ref 2, ref (λx.M) stored in heap via locations: (ref v, h) → (ℓ, h · [ℓ → v]) (ℓ fresh in h) mutable: x :=!x + 1

4 / 38

slide-12
SLIDE 12

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x} with Integers and Booleans: if b then 0 else n + 1 with higher-order references: ref 2, ref (λx.M) stored in heap via locations: (ref v, h) → (ℓ, h · [ℓ → v]) (ℓ fresh in h) mutable: x :=!x + 1 No pointer arithmetic: (ℓ + 1) is ill-typed But equality test: ℓ1 == ℓ2 is well-typed

4 / 38

slide-13
SLIDE 13

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x} with Integers and Booleans: if b then 0 else n + 1 with higher-order references: ref 2, ref (λx.M) stored in heap via locations: (ref v, h) → (ℓ, h · [ℓ → v]) (ℓ fresh in h) mutable: x :=!x + 1 No pointer arithmetic: (ℓ + 1) is ill-typed But equality test: ℓ1 == ℓ2 is well-typed Full recursion (via“Landin”knot).

4 / 38

slide-14
SLIDE 14

For what kind of Language: RefML

A typed call-by-value λ-calculus: (λx : τ.M)v → M {v/x} with Integers and Booleans: if b then 0 else n + 1 with higher-order references: ref 2, ref (λx.M) stored in heap via locations: (ref v, h) → (ℓ, h · [ℓ → v]) (ℓ fresh in h) mutable: x :=!x + 1 No pointer arithmetic: (ℓ + 1) is ill-typed But equality test: ℓ1 == ℓ2 is well-typed Full recursion (via“Landin”knot). Contextual equivalence of M1, M2: ∀C.∀h.(C[M1] ⇓, h) ⇐ ⇒ (C[M2] ⇓, h)

4 / 38

slide-15
SLIDE 15

Synchronization of Callbacks (I/II)

λf.f() is not equivalent to λf.f(); f()

5 / 38

slide-16
SLIDE 16

Synchronization of Callbacks (I/II)

λf.f() is not equivalent to λf.f(); f() Contexts can check how many time f is called. Callbacks are fully observable! C[•] def = let x = ref 0 in • (λ .x :=!x + 1); if !x > 1 then Ω else() can discriminate them.

5 / 38

slide-17
SLIDE 17

Synchronization of Callbacks (II/II)

λf.(f 1) + (f 2) is not equivalent to λf.(f 2) + (f 1)

6 / 38

slide-18
SLIDE 18

Synchronization of Callbacks (II/II)

λf.(f 1) + (f 2) is not equivalent to λf.(f 2) + (f 1) Arguments given to callbacks must be related. C[•] def = let x = ref 0 in • (λy.x := y); if !x == 1 then Ω else() can discriminate them.

6 / 38

slide-19
SLIDE 19

Disclosure of Locations (I/II)

λ .let x = ref0 in 1 is equivalent to λ .1 The creation of the reference bounded to x is not observable by the context. It is private to the term!

7 / 38

slide-20
SLIDE 20

Disclosure of Locations (II/II)

λf.let x = ref0 in fx; x := 1 is not equivalent to λf.let x = ref0 in fx; x := 2

8 / 38

slide-21
SLIDE 21

Disclosure of Locations (II/II)

λf.let x = ref0 in fx; x := 1 is not equivalent to λf.let x = ref0 in fx; x := 2 The reference bounded to x is disclosed to the context. It can look inside afterward to see what is stored. C[•] def = let z = ref (ref 0) in • (λy.z := y); if !!z == 1 then Ω else() can discriminate them.

8 / 38

slide-22
SLIDE 22

How to prove equivalence of programs of RefML ?

Contextual equivalence is hard to reason on Quantification over any contexts and heaps.

9 / 38

slide-23
SLIDE 23

How to prove equivalence of programs of RefML ?

Contextual equivalence is hard to reason on Quantification over any contexts and heaps. Nominal Game Semantics (Murawski & Tzevelekos, LICS’11)

Fully-abstract for RefML Trace representation (Laird, ICALP’07) automata-based interpretation: Algorithmic Game Semantics.

9 / 38

slide-24
SLIDE 24

How to prove equivalence of programs of RefML ?

Contextual equivalence is hard to reason on Quantification over any contexts and heaps. Nominal Game Semantics (Murawski & Tzevelekos, LICS’11)

Fully-abstract for RefML Trace representation (Laird, ICALP’07) automata-based interpretation: Algorithmic Game Semantics.

Kripke Logical Relations

World as heap-invariants (Pitts & Stark) Evolution of invariants (Ahmed, Dreyer, Neis & Birkedal).

9 / 38

slide-25
SLIDE 25

How to prove equivalence of programs of RefML ?

Contextual equivalence is hard to reason on Quantification over any contexts and heaps. Nominal Game Semantics (Murawski & Tzevelekos, LICS’11)

Fully-abstract for RefML Trace representation (Laird, ICALP’07) automata-based interpretation: Algorithmic Game Semantics.

Kripke Logical Relations

World as heap-invariants (Pitts & Stark) Evolution of invariants (Ahmed, Dreyer, Neis & Birkedal).

Bisimulations

Environmental Bisimulations (Pierce & Sumii, Koutavas, Wand) Open Bisimulations (Lassen, Levy, Stovring). Parametric Bisimulations (Hur, Dreyer & Vafeiadis).

9 / 38

slide-26
SLIDE 26

The Ultimate Goal of this Thesis

Formalize proofs of equivalence of programs:

in a Proof Assistant based on Dependent Type Theory (Coq), abstracting over bureaucracy details (step-indexing, evolution of worlds,...).

10 / 38

slide-27
SLIDE 27

The Ultimate Goal of this Thesis

Formalize proofs of equivalence of programs:

in a Proof Assistant based on Dependent Type Theory (Coq), abstracting over bureaucracy details (step-indexing, evolution of worlds,...).

Model-check equivalence of programs:

Only need to give precise enough invariants on heaps and their evolution w.r.t. control flow (i.e. worlds), Model-check a formula, representing the equivalence of programs, with such worlds.

10 / 38

slide-28
SLIDE 28

The Ultimate Goal of this Thesis

Formalize proofs of equivalence of programs:

in a Proof Assistant based on Dependent Type Theory (Coq), abstracting over bureaucracy details (step-indexing, evolution of worlds,...).

Model-check equivalence of programs:

Only need to give precise enough invariants on heaps and their evolution w.r.t. control flow (i.e. worlds), Model-check a formula, representing the equivalence of programs, with such worlds.

Decide equivalence of programs:

undecidable in general, even without recursion and with bounded integers (Murawski & Tzevelekos) but for fragments of the language by generating such worlds, need completeness of our approach.

10 / 38

slide-29
SLIDE 29

Formalize Proofs of Equivalence of Programs (in MLTT)

Want to abstract over bureaucracy details: Step-indexing (Appel & McAlester, Ahmed)

Necessary to break circularity in definitions, But“pollutes”the proof with tedious details.

11 / 38

slide-30
SLIDE 30

Formalize Proofs of Equivalence of Programs (in MLTT)

Want to abstract over bureaucracy details: Step-indexing (Appel & McAlester, Ahmed)

Necessary to break circularity in definitions, But“pollutes”the proof with tedious details.

Solution: use modality ⊲ to abstract over it.

Using G¨

  • del-Lob Logic (Appel, Mellies, Richards & Vouillon, Nakano).

11 / 38

slide-31
SLIDE 31

Formalize Proofs of Equivalence of Programs (in MLTT)

Want to abstract over bureaucracy details: Step-indexing (Appel & McAlester, Ahmed)

Necessary to break circularity in definitions, But“pollutes”the proof with tedious details.

Solution: use modality ⊲ to abstract over it.

Using G¨

  • del-Lob Logic (Appel, Mellies, Richards & Vouillon, Nakano).

Problem: extend this solution to Type Theory

Guarded Recursive Types in Topos of Tree (Birkedal et al.).

11 / 38

slide-32
SLIDE 32

Formalize Proofs of Equivalence of Programs (in MLTT)

Want to abstract over bureaucracy details: Step-indexing (Appel & McAlester, Ahmed)

Necessary to break circularity in definitions, But“pollutes”the proof with tedious details.

Solution: use modality ⊲ to abstract over it.

Using G¨

  • del-Lob Logic (Appel, Mellies, Richards & Vouillon, Nakano).

Problem: extend this solution to Type Theory

Guarded Recursive Types in Topos of Tree (Birkedal et al.).

Our solution: Generic extension of Martin-L¨

  • f Type Theory via presheaf translation

11 / 38

slide-33
SLIDE 33

Formalize Proofs of Equivalence of Programs (in MLTT)

Want to abstract over bureaucracy details: Step-indexing (Appel & McAlester, Ahmed)

Necessary to break circularity in definitions, But“pollutes”the proof with tedious details.

Solution: use modality ⊲ to abstract over it.

Using G¨

  • del-Lob Logic (Appel, Mellies, Richards & Vouillon, Nakano).

Problem: extend this solution to Type Theory

Guarded Recursive Types in Topos of Tree (Birkedal et al.).

Our solution: Generic extension of Martin-L¨

  • f Type Theory via presheaf translation

Could be useful to other problems:

Reasoning on binding and substitution (HOAS, Nominal Logic), Kripke semantics over worlds.

11 / 38

slide-34
SLIDE 34

Model-Check Equivalence of Programs

Soundness of Temporal Logical Relations Let ⊢ M1, M2 : τ two non-recursive terms: Generate automatically a formula Eτ(M1, M2) in a logic with:

(branching time) temporal modalities , X, . . ., heap constraints, ex: ℓ ֒ → v ∧ v = 3.

12 / 38

slide-35
SLIDE 35

Model-Check Equivalence of Programs

Soundness of Temporal Logical Relations Let ⊢ M1, M2 : τ two non-recursive terms: Generate automatically a formula Eτ(M1, M2) in a logic with:

(branching time) temporal modalities , X, . . ., heap constraints, ex: ℓ ֒ → v ∧ v = 3.

Kripke Semantics: w | =A ϕ

w: current invariant ⇒ meaning to heap constraints A: fixed transition system ⇒ meaning to temporal modalities.

12 / 38

slide-36
SLIDE 36

Model-Check Equivalence of Programs

Soundness of Temporal Logical Relations Let ⊢ M1, M2 : τ two non-recursive terms: Generate automatically a formula Eτ(M1, M2) in a logic with:

(branching time) temporal modalities , X, . . ., heap constraints, ex: ℓ ֒ → v ∧ v = 3.

Kripke Semantics: w | =A ϕ

w: current invariant ⇒ meaning to heap constraints A: fixed transition system ⇒ meaning to temporal modalities.

Soundness: If there exists a transition system A s.t. w0 | =A Eτ(M1, M2) then M1, M2 are contextually equivalent.

12 / 38

slide-37
SLIDE 37

Model-Check Equivalence of Programs

Soundness of Temporal Logical Relations Let ⊢ M1, M2 : τ two non-recursive terms: Generate automatically a formula Eτ(M1, M2) in a logic with:

(branching time) temporal modalities , X, . . ., heap constraints, ex: ℓ ֒ → v ∧ v = 3.

Kripke Semantics: w | =A ϕ

w: current invariant ⇒ meaning to heap constraints A: fixed transition system ⇒ meaning to temporal modalities.

Soundness: If there exists a transition system A s.t. w0 | =A Eτ(M1, M2) then M1, M2 are contextually equivalent. Model-checking: taking A and w, automatically check that w | =A Eτ(M1, M2)

Using SMT-solvers ⇒ only possible with bounded heaps in w.

12 / 38

slide-38
SLIDE 38

Decide Equivalence of Programs

Completeness of Temporal Logical Relations Completeness: If M1, M2 are contextually equivalent then there exists a transition system A s.t. w0 | =A Eτ(M1, M2).

13 / 38

slide-39
SLIDE 39

Decide Equivalence of Programs

Completeness of Temporal Logical Relations Completeness: If M1, M2 are contextually equivalent then there exists a transition system A s.t. w0 | =A Eτ(M1, M2). Generate automatically the transition system A s.t. w0 | =A Eτ(M1, M2) iff M1 ≃ctx M2.

13 / 38

slide-40
SLIDE 40

Decide Equivalence of Programs

Completeness of Temporal Logical Relations Completeness: If M1, M2 are contextually equivalent then there exists a transition system A s.t. w0 | =A Eτ(M1, M2). Generate automatically the transition system A s.t. w0 | =A Eτ(M1, M2) iff M1 ≃ctx M2.

For purely functional terms:

No heap-invariants needed, A : trivial single-state transition system.

13 / 38

slide-41
SLIDE 41

Decide Equivalence of Programs

Completeness of Temporal Logical Relations Completeness: If M1, M2 are contextually equivalent then there exists a transition system A s.t. w0 | =A Eτ(M1, M2). Generate automatically the transition system A s.t. w0 | =A Eτ(M1, M2) iff M1 ≃ctx M2.

For purely functional terms:

No heap-invariants needed, A : trivial single-state transition system.

Possible generalization of results from Algorithmic game semantics ?

Bounded heaps hypothesis rather than type restriction.

13 / 38

slide-42
SLIDE 42

Soundness and Completeness: A long road

Contextual Equivalence Γ ⊢ M1 ≃ctx M2 : τ Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | =A Eτ(M1, M2)

14 / 38

slide-43
SLIDE 43

Soundness and Completeness: A long road

Contextual Equivalence Γ ⊢ M1 ≃ctx M2 : τ Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | =A Eτ(M1, M2) Nominal Game Semantics Murawski & Tzevelekos (LICS’11) Fully-abstract Intentional model

  • f RefML,

No need of extensional quotient, Strategies as Nominal Sets over Locations.

15 / 38

slide-44
SLIDE 44

Soundness and Completeness: A long road

Contextual Equivalence Γ ⊢ M1 ≃ctx M2 : τ Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | =A Eτ(M1, M2) Operational Nominal Game Seman- tics: trace representation of interactions between a term and contexts, generated by an interactive reduction, a categorical structure on traces: closed-Freyd category, a formal link with Nominal Game Semantics, a treatment of visibility and ground references.

16 / 38

slide-45
SLIDE 45

Soundness and Completeness: A long road

Contextual Equivalence Γ ⊢ M1 ≃ctx M2 : τ Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | =A Eτ(M1, M2) Concrete Logical Relations avoid any quantification over complex elements in the definition, soundness and completeness via Operational Nominal Game Semantics.

17 / 38

slide-46
SLIDE 46

Soundness and Completeness: A long road

Contextual Equivalence Γ ⊢ M1 ≃ctx M2 : τ Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | =A Eτ(M1, M2) Temporal Logical Relations temporal modalities to reason abstractly over worlds, symbolic execution to reason abstractly over open ground variables.

18 / 38

slide-47
SLIDE 47

Extending Type Theory with Forcing

19 / 38

slide-48
SLIDE 48

First intuitions

Guarded recursive types can be seen as Presheaves

Work on Topos of Trees by Birkedal et al.

Forcing Models

Introduce by Cohen to build a model negating the Continuum Hypothesis Restatment of Lawvere and Tierney in terms of topos of (pre)sheafs.

Computational meaning of Forcing

Classical realizability by Krivine, Syntactic Forcing translations of proofs by Miquel, Computational interpretation of proofs of continuity, joint work with Coquand.

20 / 38

slide-49
SLIDE 49

Extending Type Theory with Forcing

Joint work with Tabareau & Sozeau (LICS’11) Internalization of Presheaf Models in Martin-L¨

  • f Type Theory.

21 / 38

slide-50
SLIDE 50

Extending Type Theory with Forcing

Joint work with Tabareau & Sozeau (LICS’11) Internalization of Presheaf Models in Martin-L¨

  • f Type Theory.

Allow to extend syntactically MLTT with new principles.

21 / 38

slide-51
SLIDE 51

Extending Type Theory with Forcing

Joint work with Tabareau & Sozeau (LICS’11) Internalization of Presheaf Models in Martin-L¨

  • f Type Theory.

Allow to extend syntactically MLTT with new principles. Keep good properties of the theory:

Consistency, Canonicity, Decidability of the Type-Checking

21 / 38

slide-52
SLIDE 52

Extending Type Theory with Forcing

Joint work with Tabareau & Sozeau (LICS’11) Internalization of Presheaf Models in Martin-L¨

  • f Type Theory.

Allow to extend syntactically MLTT with new principles. Keep good properties of the theory:

Consistency, Canonicity, Decidability of the Type-Checking

Impletementation for Coq (with proof-irrelevance in conversion).

21 / 38

slide-53
SLIDE 53

Presheaf Translation

Extended Theory Ground Theory

[ ]

22 / 38

slide-54
SLIDE 54

Presheaf Translation

Extended Theory Ground Theory

[ ]p

22 / 38

slide-55
SLIDE 55

Presheaf Translation

Extended Theory Ground Theory Ground Theory Ground Theory

[ ]p2 [ ]p3 [ ]p1

22 / 38

slide-56
SLIDE 56

Presheaf Translation

Extended Theory Ground Theory Ground Theory Ground Theory

[ ]p2 [ ]p3 [ ]p1 θp1→p2 θp2→p3

22 / 38

slide-57
SLIDE 57

Focus: Translation of the Dependent Product

Πx : T.Uσ

p is defined as

Πq : Pp.Πx : Tσ

q.Uσ·(x,T,q) q

Like p T ⇒ U is usually defined as ∀q ≤ p.(q T) ⇒ (q U)

23 / 38

slide-58
SLIDE 58

Focus: Translation of the Dependent Product

Πx : T.Uσ

p is defined as

Πq : Pp.Πx : Tσ

q.Uσ·(x,T,q) q

Like p T ⇒ U is usually defined as ∀q ≤ p.(q T) ⇒ (q U) commΠ(f , T, U, p) enforces f to satisfy Tσ

p fp

  • θσ,T

p→q

pi θσ,U

p→q

q fq

q

23 / 38

slide-59
SLIDE 59

Focus: Translation of the Dependent Product

Πx : T.Uσ

p is defined as

{f : Πq : Pp.Πx : Tσ

q.Uσ·(x,T,q) q

| commΠ(f , T, U, p)} Like p T ⇒ U is usually defined as ∀q ≤ p.(q T) ⇒ (q U) commΠ(f , T, U, p) enforces f to satisfy Tσ

p fp

  • θσ,T

p→q

pi θσ,U

p→q

q fq

q

23 / 38

slide-60
SLIDE 60

Forcing Layer

MLTTF : extend MLTT with new constants ⊢F c1 : T1, . . . cn : Tn

ck does not appear in Tj for j ≤ k.

F[ ]p extends the translation [ ]p to MLTTF

F[ci]p is provided.

Check that p : Pp ⊢ F[ci]p : FTip, then:

Theorem

If Γ ⊢F M : T, then F[Γ]σ ⊢ F[M]σ

p : FTσ p.

24 / 38

slide-61
SLIDE 61

An Example: Guarded Recursive Types

Define as the following forcing layer over P = (Nat, ≤)

25 / 38

slide-62
SLIDE 62

An Example: Guarded Recursive Types

Define as the following forcing layer over P = (Nat, ≤) Guard on types: ⊲ : U → U Fixpoints on univers: fix : ΠT : U.(⊲T → T) → T fold, unfold, . . .

25 / 38

slide-63
SLIDE 63

An Example: Guarded Recursive Types

Define as the following forcing layer over P = (Nat, ≤) Guard on types: ⊲ : U → U Fixpoints on univers: fix : ΠT : U.(⊲T → T) → T fold, unfold, . . . Relation with contractive maps by Birkedal & Mogelberg (LICS’13)

25 / 38

slide-64
SLIDE 64

An Example: Guarded Recursive Types

Define as the following forcing layer over P = (Nat, ≤) Guard on types: ⊲ : U → U Fixpoints on univers: fix : ΠT : U.(⊲T → T) → T fold, unfold, . . . Relation with contractive maps by Birkedal & Mogelberg (LICS’13) Impletementation in Coq: F[⊲]σ

p def

= λq : Natp.λT : Uσ

q.

(λr : Natq.match r with | 0 => Unit | Sr′ => (π1T)r′ , λr : Natq.λt : Natr.λx : Ur.match t with | 0 => unit | St′ => (π2T) (Pred r) t′ x)

25 / 38

slide-65
SLIDE 65

Coherence issues

Intentional type theory : Distinction betwen conversion (≡) and propositional equality (=T).

26 / 38

slide-66
SLIDE 66

Coherence issues

Intentional type theory : Distinction betwen conversion (≡) and propositional equality (=T). Coherence issues arise:

T {M/x}p ≡ Tp

  • [M]p/x
  • ,

Link with coherence problems with categorical models of Dependent Types (work of Curien, Hofmann).

26 / 38

slide-67
SLIDE 67

Coherence issues

Intentional type theory : Distinction betwen conversion (≡) and propositional equality (=T). Coherence issues arise:

T {M/x}p ≡ Tp

  • [M]p/x
  • ,

Link with coherence problems with categorical models of Dependent Types (work of Curien, Hofmann).

but we can build a term of type T {M/x}p =U Tp

  • [M]p/x
  • ,

Use it to perform rewriting in the translation, Need explicit coercions of conversion.

26 / 38

slide-68
SLIDE 68

Towards automatizable proofs of equivalence

27 / 38

slide-69
SLIDE 69

Concrete Logical Relations

Game Semantics Γ ⊢ M1 : τ = Γ ⊢ M2 : τ Trace Semantics [Γ ⊢ M1 : τ] = [Γ ⊢ M2 : τ] Concrete Logical Relations (M1, M2) ∈ V τe w Temporal Logical Relations w | = Eτ(M1, M2)

28 / 38

slide-70
SLIDE 70

Logical Relations

Binary relations E τ , V τ on closed terms and values inductively defined on types. V Int

def

= {(n, n) | n ∈ Z} V τ → σ

def

= {(λx1.M1, λx2.M2) | ∀(v1, v2) ∈ V τ . ((λx1.M1)v1, (λx2.M2)v2) ∈ E σ} E τ

def

= {(M1, M2) | (M1 ⇑ ∧M2 ⇑) ∨((M1 →∗ v1) ∧ (M2 →∗ v2) ∧ (v1, v2) ∈ V τ}

29 / 38

slide-71
SLIDE 71

Kripke Logical Relations (Pitts & Stark, Ahmed, Birkedal, Dreyer, ...)

Extension to languages with references. Need worlds, i.e. invariants on heaps, which can evolve w.r.t. control flow of programs Parametrize the definition of logical relations with such worlds. E τ w

def

=

  • (M1, M2) | ∀(h1, h2) : w.
  • (M1, h1) ⇑ ∧(M2, h2) ⇑
  • ((M1, h1) →∗ (v1, h′

1)) ∧ ((M2, h2) →∗ (v2, h′ 2))

∃w′ ⊒ w.(h′

1, h′ 2) : w′ ∧ (v1, v2) ∈ V τ w′

30 / 38

slide-72
SLIDE 72

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition:

31 / 38

slide-73
SLIDE 73

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition: Quantification over applicative contexts in E τ w (Biorthogonality)

Direct-style definition.

31 / 38

slide-74
SLIDE 74

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition: Quantification over applicative contexts in E τ w (Biorthogonality)

Direct-style definition.

Quantification over functional values in V τ → σ w

When τ is functional, Use fresh free variables instead.

31 / 38

slide-75
SLIDE 75

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition: Quantification over applicative contexts in E τ w (Biorthogonality)

Direct-style definition.

Quantification over functional values in V τ → σ w

When τ is functional, Use fresh free variables instead.

Quantification over functional values in V ref(τ → σ) w

Deal with disclosed locations externally, in the definition of (h1, h2) : w. Remove the circularity between logical relations and worlds.

31 / 38

slide-76
SLIDE 76

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition: Quantification over applicative contexts in E τ w (Biorthogonality)

Direct-style definition.

Quantification over functional values in V τ → σ w

When τ is functional, Use fresh free variables instead.

Quantification over functional values in V ref(τ → σ) w

Deal with disclosed locations externally, in the definition of (h1, h2) : w. Remove the circularity between logical relations and worlds.

Quantification over new disjoint invariants in w′ ⊒ w

Use a fixed transition system instead.

31 / 38

slide-77
SLIDE 77

Toward simple proofs of equivalence

Starting Point : Kripke logical relations with STS of heap-invariants as world (Dreyer, Neis & Birkedal). Remove all the quantifier on“complex”elements of their definition: Quantification over applicative contexts in E τ w (Biorthogonality)

Direct-style definition.

Quantification over functional values in V τ → σ w

When τ is functional, Use fresh free variables instead.

Quantification over functional values in V ref(τ → σ) w

Deal with disclosed locations externally, in the definition of (h1, h2) : w. Remove the circularity between logical relations and worlds.

Quantification over new disjoint invariants in w′ ⊒ w

Use a fixed transition system instead.

Give rise to our definition of“Concrete Logical Relations”

31 / 38

slide-78
SLIDE 78

Concrete Logical Relations

All what we need to reason on equivalence:

32 / 38

slide-79
SLIDE 79

Concrete Logical Relations

All what we need to reason on equivalence:

A transition system representing the control flow between the term and its environment (i.e. contexts)

32 / 38

slide-80
SLIDE 80

Concrete Logical Relations

All what we need to reason on equivalence:

A transition system representing the control flow between the term and its environment (i.e. contexts) Private transitions: only the term can take them,

32 / 38

slide-81
SLIDE 81

Concrete Logical Relations

All what we need to reason on equivalence:

A transition system representing the control flow between the term and its environment (i.e. contexts) Private transitions: only the term can take them, Public transitions: execution to a value, so the environment can take them (well-bracketing),

32 / 38

slide-82
SLIDE 82

Concrete Logical Relations

All what we need to reason on equivalence:

A transition system representing the control flow between the term and its environment (i.e. contexts) Private transitions: only the term can take them, Public transitions: execution to a value, so the environment can take them (well-bracketing), Labels on transitions: heap-invariants, disclosure process of locations.

32 / 38

slide-83
SLIDE 83

Concrete Logical Relations

All what we need to reason on equivalence:

A transition system representing the control flow between the term and its environment (i.e. contexts) Private transitions: only the term can take them, Public transitions: execution to a value, so the environment can take them (well-bracketing), Labels on transitions: heap-invariants, disclosure process of locations.

Reason on open terms with free functional variables

Make the full control flow apparent in the operational reduction.

32 / 38

slide-84
SLIDE 84

Soundness and Completeness

Proofs by induction on typing judgment seems impossible (no “compatibility lemmas” ).

33 / 38

slide-85
SLIDE 85

Soundness and Completeness

Proofs by induction on typing judgment seems impossible (no “compatibility lemmas” ). Correspondence with Trace semantics.

33 / 38

slide-86
SLIDE 86

Soundness and Completeness

Proofs by induction on typing judgment seems impossible (no “compatibility lemmas” ). Correspondence with Trace semantics. Soundness:

Introduce Kripke trace semantics, Perform“surgery”on traces.

33 / 38

slide-87
SLIDE 87

Soundness and Completeness

Proofs by induction on typing judgment seems impossible (no “compatibility lemmas” ). Correspondence with Trace semantics. Soundness:

Introduce Kripke trace semantics, Perform“surgery”on traces.

Completeness:

No more biorthogonality, Need“adequate”LTS: dual of Kripke Logical Relations, Show that it always exists: exhaustive worlds.

33 / 38

slide-88
SLIDE 88

Callback with lock

Mcbl

1

= C [f(); x :=!x + 1] Mcbl

2

= C [let n =!x in f(); x := n + 1] where C = let b = ref true in let x = ref 0 in λf.if !b then b := false; • ; b := true else (), λ .!x

34 / 38

slide-89
SLIDE 89

Callback with lock

Mcbl

1

= C [f(); x :=!x + 1] Mcbl

2

= C [let n =!x in f(); x := n + 1] where C = let b = ref true in let x = ref 0 in λf.if !b then b := false; • ; b := true else (), λ .!x ⊤ ⇛ {ℓx →i 0, ℓb →i true} {ℓx →i n} ⇛ {ℓx →i n + 1, ℓb →i true} {ℓx →i n} ⇛ {ℓx →i n, ℓb →i false} {ℓx →i n} ⇛ {ℓx →i n + 1, ℓb →i true}

34 / 38

slide-90
SLIDE 90

Automatically generated temporal formula

Eτ(Mclb

1 , Mcbl 2 ) is equal to HN0.(N1ℓ2.(N1ℓ1.(N2ℓ4.(N2ℓ3.(X((ℓ2 →1 0) ∧ (ℓ1 →1 true) ∧ (ℓ4 →2 0) ∧ (ℓ3 →2 true)∧ (((HN5.(∀x6, x7, x8, x9.(((ℓ2 →1 x6) ∧ (ℓ1 →1 x7) ∧ (ℓ4 →2 x8) ∧ (ℓ3 →2 x9)) ⇒ ((X(((x7 = true) ∧ (x9 = true)) ⇒ ((ℓ2 →1 x6) ∧ (ℓ1 →1 false) ∧ (ℓ4 →2 x8) ∧ (ℓ3 →2 false)∧ (pub(∀x10, x11, x13, x14.(((ℓ2 →1 x10) ∧ (ℓ1 →1 x11) ∧ (ℓ4 →2 x13) ∧ (ℓ3 →2 x14)) ⇒ (X(∀x12, x15.(((x12 = x10 + 1) ∧ (x15 = x8 + 1)) ⇒ ((ℓ2 →1 x12) ∧ (ℓ1 →1 true)∧ (ℓ4 →2 x15) ∧ (ℓ3 →2 true) ∧ (Ppub(N5)))))))))))) ∧ (not((x7 = true) ∧ (x9 = false)))∧ (not((x7 = false) ∧ (x9 = true))) ∧ (X(((x7 = false) ∧ (x9 = false)) ⇒ ((ℓ2 →1 x6) ∧ (ℓ1 →1 x7) ∧ (ℓ4 →2 x8) ∧ (ℓ3 →2 x9) ∧ (Ppub(N5)))))))))) ∧((HN16.(∀[x17, x18, x19, x20].(((ℓ2 →1 x17) ∧ (ℓ1 →1 x18) ∧ (ℓ4 →2 x19) ∧ (ℓ3 →2 x20)) ⇒ (X((ℓ2 →1 x17) ∧ (ℓ1 →1 x18) ∧ (ℓ4 →2 x19) ∧ (ℓ3 →2 x20) ∧ (x17 = x19) ∧ (Ppub(N16))))))))) ∧(Ppub(N0))))))))

35 / 38

slide-91
SLIDE 91

Translation to SMT-LIB

(assert (exists ((s21 Int)(h22 Heap)(h23 Heap)(l2 Int)(l1 Int)) (and (not (= l1 l2)) (exists ((l4 Int)(l3 Int)) (and (not (= l3 l4)) (exists ((s25 Int)(h26 Heap)(h27 Heap)(S28 LocSpan)) (and (TransPriv s21 s25 h22 h23 h26 h27 S28) (and (= (select h26 l2) 0) (= (select h26 l1) 0) (= (select h27 l4) 0) (= (select h27 l3) 0) (and (forall ((s29 Int)(h30 Heap)(h31 Heap)(S32 LocSpan)) (=> (TransPrivT s25 s29 h26 h27 h30 h31 S32) (forall ((x6 Int)(x7 Int)(x8 Int)(x9 Int)) (=> (and (= (select h30 l2) x6) (= (select h30 l1) x7) (= (select h31 l4) x8) (= (select h31 l3) x9) ) (and (exists ((s33 Int)(h34 Heap)(h35 Heap)(S36 LocSpan)) (and (TransPriv s29 s33 h30 h31 h34 h35 S36) (=> (and (= x7 0) (= x9 0) ) (and (= (select h34 l2) x6) (= (select h34 l1) 1) (= (select h35 l4) x8) (= (select h35 l3) 1) (forall ((s37 Int)(h38 Heap)(h39 Heap)(S40 LocSpan)) (=> (TransPubT s33 s37 h34 h35 h38 h39 S40) (forall ((x10 Int)(x11 Int)(x13 Int)(x14 Int)) (=> (and (= (select h38 l2) x10) (= (select h38 l1) x11) (= (select h39 l4) x13) (= (select h39 l3) x14)) (exists ((s41 Int)(h42 Heap)(h43 Heap)(S44 LocSpan)) (and (TransPriv s37 s41 h38 h39 h42 h43 S44) (forall ((x12 Int)(x15 Int)) (=> (and (= x12 (+ x10 1)) (= x15 (+ x8 1)) ) (and (= (select h42 l2) x12) (= (select h42 l1) 0) (= (select h43 l4) x15) (= (select h43 l3) 0) (TransPub s29 s41 h30 h31 h42 h43 S44)))))))))))))) (not (and (= x7 0) (= x9 1) )) (not (and (= x7 1) (= x9 0) )) (exists ((s45 Int)(h46 Heap)(h47 Heap)(S48 LocSpan)) (and (TransPriv s29 s45 h30 h31 h46 h47 S48) (=> (and (= x7 1) (= x9 1) ) (and (= (select h46 l2) x6) (= (select h46 l1) x7) (= (select h47 l4) x8) (= (select h47 l3) x9) (TransPub s29 s45 h30 h31 h46 h47 S48)))))))))) (forall ((s49 Int)(h50 Heap)(h51 Heap)(S52 LocSpan))(=> (TransPrivT s25 s49 h26 h27 h50 h51 S52) (forall ((x17 Int)(x18 Int)(x19 Int)(x20 Int)) (=> (and (= (select h50 l2) x17) (= (select h50 l1) x18) (= (select h51 l4) x19) (= (select h51 l3) x20) ) (exists ((s53 Int)(h54 Heap)(h55 Heap)(S56 LocSpan)) (and (TransPriv s49 s53 h50 h51 h54 h55 S56) (and (= (select h54 l2) x17) (= (select h54 l1) x18) (= (select h55 l4) x19) (= (select h55 l3) x20) (= x17 x19) (TransPub s49 s53 h50 h51 h54 h55 S56))))))))) (TransPub s21 s25 h22 h23 h26 h27 S28))))))))) (check-sat) 36 / 38

slide-92
SLIDE 92

What’s Next?

Extend the presheaves translation with forcing conditions as categories

Useful for an implementation of a Nominal Dependent Type Theory ?

Reason on recursive programs:

Combination with Higher-order Recursive Schemes (Ong et al.) ?

Decidability results:

Semi-decidability: generate worlds, Full decidability: reason on adequate worlds, Decidability of the contextual equivalence of ν-calculus ?

Polymorphic languages ?

37 / 38

slide-93
SLIDE 93

A Unified Theory ?

Kripke Logical relations with worlds as Bisimulations over Traces generated by Game Semantics as Presheaves over                LTS Open maps (Joyal, Nielsen & Winskel) Innocent Strategies as Presheaves (Hirchowitz & Pous) Transition systems over games (Levy & Staton, LICS’14)

38 / 38