Logical Properties of CPS Transforms
Deepak GargFall, 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
Simply Typed -calculus
• Terms:
• Types (Logical Propositions):
Evaluation and Typing Rules
• Standard Typing Rules
• Small step, call by value evaluation
Abort (A) Operator
What we have so far …
• We have INTUITIONISTIC logic with ?
Control (C) Operator
What we have now …
• We have CLASSICAL logic!
• Why? Rule of double negation elimination.
Summary
-calculus + A $
Intuitionistic logic with ?
-calculus + A + C$
Classical logic
CPS Transforms
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.
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!
CPS: Term Translation
• -calculus
• CPS translation
• Each translated term expects a continuation
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.
CPS: Type Translation
• Translation for types:
• Types:
CPS: Logical Interpretation
CPS: A-Operator
• k is thrown away like E[ ]
Soundness: A-Operator
CPS: C-Operator
• d is thrown away like E’[ ].
Soundness: C-Operator
CPS: Logical Interpretation
Summary of CPS
CPS as an Embedding
CPS as an Embedding
CPS as an Embedding
CPS as an Embedding
Two more theorems (unrelated to proof-terms):
Doing it all in Twelf
Representing Terms
• Use HOAS
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
Classical and Intuitionistic Terms
Representing the CPS Transform
• Terms represented with HOAS
• No direct representation for variables
• How do we represent the following?
• Create a judgment:
More Trouble …
The solution
• We make the translation a hypothetical judgment
• Recall:
• We get:
The solution
Soundness Theorem
Problems: Soundness Theorem
Input Coverage Problem:
Problem: Soundness Theorem
From worlds (soundnessblock)
Output
External
Can’t be changed
(Needed for Induction)
Make this an output?
Soundness Theorem Solution
• New Theorem:
Soundness Theorem?
• What have we shown?
• What we need …
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!
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
Telling Twelf about Uniqueness
• Now we prove a theorem
A Typing-soundness Theorem
• We also need the following theorem
True Soundness
• Using all our previous theorems, we can now prove the soundness with correct modes.
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