logical properties of cps transforms deepak garg fall, 2004

45
Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Post on 21-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Logical Properties of CPS Transforms

Deepak GargFall, 2004

Page 2: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Introduction

• CPS = Continuation Passing Style

• Studied to simulate cbv with cbn

• We look at CPS transforms as proof-transformations

• CPS transforms embed classical logic into intuitionistic logic

Page 3: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Simply Typed -calculus

• Terms:

• Types (Logical Propositions):

Page 4: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Evaluation and Typing Rules

• Standard Typing Rules

• Small step, call by value evaluation

Page 5: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Abort (A) Operator

Page 6: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

What we have so far …

• We have INTUITIONISTIC logic with ?

Page 7: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Control (C) Operator

Page 8: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

What we have now …

• We have CLASSICAL logic!

• Why? Rule of double negation elimination.

Page 9: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Summary

-calculus + A $

Intuitionistic logic with ?

-calculus + A + C$

Classical logic

Page 10: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS Transforms

Page 11: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS Transform: History

• [1975] Plotkin. CPS studied formally.

• [1986] Felleisen et al. Extended to control operators (call/cc, C and A).

• [1993] Griffin. Typed CPS transforms.

• [2003] Wadler. Duality with CPS transforms.

Page 12: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS Transform: Properties

• Translate terms, types and proofs

• On terms:– No control (C) operator in transformed terms

• On types:– No double negation elimination in transformed

proofs– Translates classical into intuitionistic logic!

Page 13: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: Term Translation

• -calculus

• CPS translation

• Each translated term expects a continuation

Page 14: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: Operational Interpretation

• Explicitly formalize evaluation in terms of continuations

To evaluate (M N) in the continuation k, evaluate M in the continuation that binds its input to m and evaluates N in the continuation that binds its input to n and evaluates (m n) in the continuation k.

Page 15: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: Type Translation

• Translation for types:

• Types:

Page 16: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: Logical Interpretation

Page 17: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: A-Operator

• k is thrown away like E[ ]

Page 18: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness: A-Operator

Page 19: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: C-Operator

• d is thrown away like E’[ ].

Page 20: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness: C-Operator

Page 21: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS: Logical Interpretation

Page 22: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Summary of CPS

Page 23: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS as an Embedding

Page 24: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS as an Embedding

Page 25: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS as an Embedding

Page 26: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

CPS as an Embedding

Two more theorems (unrelated to proof-terms):

Page 27: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Doing it all in Twelf

Page 28: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Representing Terms

• Use HOAS

Page 29: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Classical and Intuitionistic Terms

• The previous definition is not enough.

• We have to distinguish classical and intuitionistic logic

• Introduce two types of terms: – Classical: termc– Intuitionistic: termi

Page 30: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Classical and Intuitionistic Terms

Page 31: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Representing the CPS Transform

• Terms represented with HOAS

• No direct representation for variables

• How do we represent the following?

• Create a judgment:

Page 32: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

More Trouble …

Page 33: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

The solution

• We make the translation a hypothetical judgment

• Recall:

• We get:

Page 34: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

The solution

Page 35: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness Theorem

Page 36: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Problems: Soundness Theorem

Input Coverage Problem:

Page 37: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Problem: Soundness Theorem

From worlds (soundnessblock)

Output

External

Can’t be changed

(Needed for Induction)

Make this an output?

Page 38: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness Theorem Solution

• New Theorem:

Page 39: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness Theorem?

• What have we shown?

• What we need …

Page 40: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Soundness Theorem?

• Are these theorems the same?

• To us they are

• Why?

• We know that given A, there is exactly one A’ such that A* = A’.

• We never told Twelf this fact

• So, in Twelf these are different theorems!

Page 41: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Telling Twelf about Uniqueness

• Can we tell Twelf that A* is unique?

• Not directly! There is no uniqueness check

• We can make an equality judgment

Page 42: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Telling Twelf about Uniqueness

• Now we prove a theorem

Page 43: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

A Typing-soundness Theorem

• We also need the following theorem

Page 44: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

True Soundness

• Using all our previous theorems, we can now prove the soundness with correct modes.

Page 45: Logical Properties of CPS Transforms Deepak Garg Fall, 2004

Extensions

• Can be extended to include conjunction and disjunction.

• We can also use a call-by-name transform– Gives a translation from classical to minimal logic

– Very similar to Kolmogrov’s double negation translation