1. Introduction
The Curry-Howard isomorphism [
1,
2] states that formulas and proofs in mathematical logic correspond to types and programs in programming languages. For example, propositions and proofs in intuitionistic propositional logic (IPL) correspond to types and terms in the simply typed
-calculus (
). A similar correspondence also exists between classical propositional logic (CPL) and the simply typed
-calculus with control operators such as
(call-with-current continuation) and
(
) [
3,
4].
Classical logic differs from intuitionistic logic, also known as constructive logic, in that it includes the law of excluded middle (EM),
, as a theorem, which states that for any proposition
A, either
A is true or its negation
is true (i.e.,
A is false). Classical logic also includes Peirce’s law,
, and double negation elimination (DNE),
. Any of these three theorems can be added as an axiom to proof systems for intuitionistic logic in order to obtain a sound and complete proof system for classical logic. Taking Peirce’s law and DNE as axioms corresponds to the control operators such as
and Felleisen et al.’s
operator, which allow a nonlocal transfer of program control, respectively [
3,
4,
5].
A double negation translation (DNT), also known as a negative translation, translates a classically valid formula into an intuitionistically valid one [
6,
7,
8,
9,
10,
11], for example, by placing a double negation
in front of every subformula of the given formula [
9]. More precisely, while intuitionistic logic admits double negation
introduction,
, it only rejects double negation
elimination,
. In other words,
is weaker than
A in intuitionistic logic, but they are equivalent in classical logic. Hence, in general, an instance of
A in a classical proof derivation only corresponds to a weaker proposition
in an intuitionistic proof derivation. In this regard, DNTs can be thought of as a proof transformation which eliminates every instance of DNE (or equivalently, EM or Peirce’s law) used in a classical derivation of
A, yielding an intuitionistic proof of
, where
is the formula obtained by placing
in front of every proper subformula of
A. One important consequence of DNTs is the equivalence between the consistency of classical Peano arithmetic and the consistency of intuitionistic Heyting arithmetic.
The programming language counterpart of DNTs is continuation passing style (CPS) transformations [
4,
12,
13], which are often used in compiler optimization [
14,
15]. Operationally, a continuation of type
is a reification of an evaluation context, i.e., the rest of the program, that expects the result of the current expression of type
A. Hence, a continuation type
can be understood as a function type
, where
stands for the type of final results. If we interpret
as ⊥ and define
as a syntactic abbreviation of
as usual, then DNTs correspond to CPS transformations, which translate an expression
M of type
A into a CPS function of type
that explicitly takes a continuation
k as an argument and applies it to the result of
M in its body. Here, the continuation
k expects a value of type
because, as in DNTs, CPS transformations also recursively translate every subexpression of the given expression into CPS expressions. The CPS transformations from
into
[
3,
4], which eliminate control operators, correspond to a DNT from CPL with Peirce’s law or DNE into IPL.
In this paper, we study the logical meaning of a selective CPS transformation [
16] and present a selective DNT for CPL via the Curry-Howard isomorphism. The usual CPS transformations translate into CPS functions not only “nontrivial” expressions (possibly) with control operators (computational effects) but also “trivial” expressions, which lack them, yielding unnecessarily large expressions. In contrast, the selective CPS transformation only translates nontrivial expressions into CPS functions and keeps trivial expressions intact. To do so, it uses a type and effect system to keep track of the uses of control operators. Similarly, when viewed as a proof transformation, the usual DNTs also yield unnecessarily large proofs because they translate even intuitionistically valid proof derivations. Our selective DNT uses an annotated proof system to keep track of the uses of only classical axioms, which is similar to the type and effect system in [
16], and only selectively translates the part of the given proof that exploits such axioms.
The main contributions of our paper are summarized as follows:
We review the Curry-Howard isomorphism between the standard call-by-value (CBV) CPS transformation with control operators and the corresponding DNT from CPL into IPL.
We review a CBV selective CPS transformation based on a type and effect system [
16] and propose a corresponding selective DNT based on an annotated proof system, with its correctness proof showing that provability is preserved under the translation.
Our work can serve as a reference point for the close correspondence between the selective CPS transformation and the selective DNT and further research on this topic.
The remainder of the paper is organized as follows.
Section 2 reviews the standard CBV CPS transformation from
with control operators into
without these operators [
3]. In
Section 3, we present the corresponding DNT from CPL with Peirce’s law into IPL.
Section 4 reviews a CBV selective CPS transformation based on a type and effect system. In
Section 5, we present an annotated proof system and propose a selective DNT corresponding to the selective CPS transformation via the Curry-Howard isomorphism. We also prove the correctness of the translation by showing that provability is preserved under the translation. Finally,
Section 6 discusses related work and concludes.
2. A Call-by-Value CPS Transformation
In this section, we review the standard CBV CPS transformation [
3] which translates a program in the source language
with control operators
and
into an operationally equivalent program in the target language
without control operators.
2.1. Simply Typed -Calculus with Control Operators
The source language
is the simply typed
-calculus with two control operators:
and
[
3]. Its abstract syntax is defined as follows.
Definition 1 (Abstract syntax of
)
. An expression M is either a constant p, a variable x, a lambda abstraction (anonymous function) , a lambda application (function application) , or a control operator to be explained below. As for types, P ranges over an arbitrary but fixed set of primitive types, denotes the type of functions from domain A to range B, and denotes the type of continuations that expect a value of type A.
We consider a left-to-right CBV operational semantics for using evaluation contexts, where a well-typed expression evaluates to a value.
Definition 2 (Operational semantics of
)
. An evaluation context E is an expression with a hole . Every expression M can be decomposed into a unique context E and a unique reducible expression (redex) N, i.e., , where denotes the expression obtained by filling the hole in E with N. An evaluation context can be considered a pending computation which expects the result of another computation. Hence, we represent a continuation as a captured evaluation context of the form . A value V is then either a constant, a lambda abstraction, or a continuation.
We use a reduction judgment to denote one-step reduction of M to . Given any program, the redex to be reduced is implicitly determined by the left-to-right CBV definition of evaluation contexts. There are three kinds of redexes. First, a lambda application of the form reduces to (-reduction), where denotes the standard capture-avoiding substitution which replaces every occurrence of x in M with V. Since we use a CBV semantics, -reduction always substitutes a value for the formal parameter. Second, captures the current context E, stores a continuation in x, and proceeds to reduce M. Finally, throws a value V to a continuation and discards the current evaluation context, thus allowing a nonlocal transfer of control.
We evaluate only well-typed closed expressions [
3]. To type expressions, we use a typing judgment
which means that expression
M is of type
A under typing context
. Here, a typing context
is a set of type bindings of the form
, and we use · to denote an empty context. We assume that each variable is associated with at most one type, for example, by means of
-conversion.
A closed expression M is well-typed with respect to a type A if is provable using the typing rules in Definition 3.
Definition 3 (Typing rules for ).
The above typing rules are standard [
3]. In the rule
,
is a predefined mapping from constants to primitive types. In the rule
,
is of type
A if
M is also of type
A assuming
. Please note that
x will at runtime be bound to a continuation that expects the result of
M. Therefore,
itself can be given a type
for any type
A, which corresponds to Peirce’s law. In the rule
, if
M and
N are of type
and
A, respectively, then
can be assigned an arbitrary type
C because its reduction never returns to the current evaluation context. Therefore, the rule
corresponds to the law of non-contradiction (followed by false elimination).
The type system given in Definition 3 is sound with respect to the operational semantics given in Definition 2 in that well-typed expressions never go wrong, i.e., cannot cause type errors during evaluation [
17].
2.2. A Call-by-Value CPS Transformation
The CBV CPS transformation [
3] translates the source language
into the target language
without
and
. The abstract syntax of
is defined as follows.
Definition 4 (Abstract syntax of
)
. The main idea of the transformation is twofold. First, it interprets a continuation of type as a function of type , where we use ⊥ to denote the type of final answers. Second, it translates every expression M into a CPS function that explicitly takes as argument a continuation k expecting the result of M and applies k to the result in its body. Formally, the CBV CPS transformation associates each type A with , which is the type of values of type A after the CPS transformation and defined in Definition 5. Based on this, it translates each expression M of type A into a CPS expression of type , which is defined in Definition 6.
Definition 6 (CBV CPS transformation)
. The transformation simply translates values and variables into the CPS form. Please note that in the translation of a lambda abstraction, the body is also translated into a CPS expression. For a lambda application , let us first analyze the type structure of the transformed expression:
In the transformed expression ,
will bind the CPS-transformed evaluation result of M to f and will bind that of N to v. Then the function f is called with the argument v and the initial continuation k as , which returns an answer of type ⊥. In the translation of , of type will apply the initial continuation k of type to the CPS-transformed evaluation result of M, which is of type . Moreover, the continuation variable x of type is substituted with the explicit continuation k in . Finally, in the translation of , will bind the continuation evaluated from M to , and then will apply to the CPS-transformed evaluation result of N. Please note that the initial continuation k is not used.
The above transformation preserves the operational meaning of the source program of primitive type: when applied to an initial continuation (an identity function), the translated program terminates if and only if the source program does, and in that case they evaluate to the same value of primitive type [
3,
16].
Theorem 1. If M is a closed expression of type P, thenwhere is the reflexive and transitive closure of one-step reduction ↦. The transformation also preserves typing [
3], i.e., provability, as stated below, where
is the typing context such that
if and only if
.
Theorem 2. If , then
Proof. By induction on the structure of M. □
3. A Double Negation Translation
By the Curry-Howard isomorphism, types and expressions in
correspond to formulas and proofs in classical implicational propositional logic (CPL) [
4]. The formulas of CPL are defined as follows.
P ranges over atomic propositions. We choose only implication ⊃ and negation ¬ as primitive connectives to clearly show the connection between and CPL. Other connectives and can be notionally defined as and , respectively. A continuation type in is interpreted as a negated formula in CPL.
The type system for given in Definition 3 can be interpreted as the proof system for CPL given in Definition 8. We use a hypothetical judgment to mean that a proposition A is true under a set of hypotheses (where the subscript stands for Klassical). Below, by removing the terms in each typing rule in Definition 3, we obtain the corresponding inference rule for CPL. (For simplicity, we omit the rule corresponding to because it is not necessary for studying the Curry-Howard isomorphism between CPL and IPL. However, it is needed for proving the observational soundness for the CPS transformation, stated in Theorem 1).
Definition 8 (Proof system for CPL).
The typing rules
and
for control operators correspond to the rules
and
which internalize Peirce’s law and the law of non-contradiction, respectively. Using them, we can derive the following rules for double negation elimination and the law of excluded middle.
The DNT corresponding to the CBV CPS transformation translates CPL into intuitionistic implicational propositional logic (IPL) which corresponds to in Definition 4. The formulas of IPL are defined as follows.
A natural deduction system for IPL is defined below. We use a judgment to mean that a proposition A is true in IPL under a set of hypotheses (where the subscript stands for Intuitionistic).
Definition 10 (Proof system for IPL).
Although we include the
rule in Definition 10 for the completeness of the system, it is never used in the translation of CPL proof trees into IPL ones. In other words, our study is still valid without the
rule. Please note that ⊥ is not even included in CPL (although it can be encoded, for example, as
). Meanwhile, we regard
as a syntactic abbreviation of
in IPL. Therefore, the following rules are special cases of the ⊃ introduction and elimination rules.
We define a translation of CPL formulas into IPL formulas exactly like the CBV CPS transformation of types, as follows.
Our translation slightly differs from the double negation translations proposed by Kolmogorov [
9], Gödel and Gentzen [
6,
8], and Kuroda [
10]. Kolmogorov’s translation directly corresponds to the call-by-name CPS transformation [
4,
12,
18] via the Curry-Howard isomorphism. In particular, in his translation,
is translated into
.
The correctness of the DNT is stated as follows, where applies the translation elementwise: if and only if .
Theorem 3. If is provable, then is also provable.
Proof. We define a recursive function that maps a derivation of into a derivation of . In particular, for each case, we build a derivation tree corresponding to its counterpart CPS transformation in Definition 6 (although a smaller derivation may be constructed). □
4. A Call-by-Value Selective CPS Transformation
In this section, we review Nielsen’s CBV selective CPS transformation [
16]. The main idea is to distinguish trivial expressions whose evaluation does not give rise to computational effects (i.e., evaluation of
or
) from nontrivial ones whose evaluation may give rise to effects. In general, it is undecidable to determine if the evaluation of an expression gives rise to effects, for example, in the presence of a recursive operator or recursive types. Since it is safe to assume that every expression might have an effect, the usual CPS transformation assumes every expression as nontrivial and translates into the CPS form.
To translate only nontrivial expressions selectively, while keeping trivial ones in the direct style, we use a type and effect system, where (definitely) trivial expressions are annotated with while (possibly but not necessarily) nontrivial ones with . The following is the minimally annotated syntax of the source language , where we omit annotations when clear from the structure of the given expression.
We understand values and identifiers to always be implicitly annotated with and control expressions with , and thus do not explicitly mark them in the syntax. Moreover, we denote an application by instead of for specifying annotations. Still, when annotations do not matter, we use the usual notation . Special care should be taken for abstractions and applications. For an application of the form , if the function body M is nontrivial, the evaluation of its -reduct gives rise to an effect. For such applications, we annotate @ with as in . An application is annotated with , i.e., , if the evaluation of M, N, or its -reduct (obtained after both M and N are reduced to values) gives rise to an effect. Furthermore, in the presence of higher-order functions, different abstractions may be applied at the same application point (e.g., M and N in where and p is a some constant), and such abstractions should be transformed into the same style. Therefore, some abstraction with a trivial body might sometimes need to be transformed into the CPS form. For such abstractions, we annotate with as in . Correspondingly, if is of type , then and respectively have an annotated type and .
We say that annotations are consistent (with respect to the program’s behavior) if
every expression annotated with is indeed trivial,
every abstraction annotated with (resp. ) is applied only at application points annotated with (resp. ), and
every abstraction whose body is annotated with is also annotated with .
To check the consistency of annotations, we use a type and effect system using a judgment which means that expression M is of type A and can be annotated with under typing context .
Definition 13 (Type and effect system).
The relation in the rule allows us to annotate an abstraction with a trivial body with . Similarly, in the rule , even if , , and are all , the application can be annotated with . From now on, we consider only well-annotated expressions which are allowed by the type and effect system, i.e., typable by Definition 13. The following theorem shows that the type and effect system indeed ensures the consistency of annotations. As a corollary, if a closed expression M can be annotated with , the evaluation of M does not give rise to an effect.
Theorem 4. If , annotations in M are consistent.
Proof. By induction on a derivation of . □
Corollary 1. Given a closed expression M, if , no effects occur during the evaluation of M.
The CBV selective CPS transformation associates each type A with defined below. The main difference from Definition 5 is the translation of function types, where a trivial function type is kept in the direct style.
Definition 14 (Selective type translation)
. In order to transform expressions selectively, we use two functions: translates expressions of type A into those of type and translates expressions of type A into those of type . Given an expression, the former translates it into a CPS expression, whereas the latter keeps it in the direct style. In particular, takes only trivial expressions.
Definition 15 (Selective CPS transformation)
. The main difference between Definitions 6 and 15 is the transformation of functions and applications annotated with . In the translation of a function , the body M is kept in the direct style, i.e., translated using . Similarly, in the translation of an application , both M and N are kept in the direct style. Finally, for an application , the annotation for @ indicates that M is of type for some types A and B. In other words, if M evaluates to an abstraction , then would be trivial. Therefore, in the transformed expression, is applied to a continuation of type . Specifically, at runtime, f will be bound to the result evaluated from M, which is of type , and will evaluate to a value of type , which is in the direct style. Hence, we apply to a continuation k that expects the result of .
The operational meaning of the source program of primitive type is preserved by the selective CPS transformation as stated below [
16].
Theorem 5. If M is a closed and well-annotated expression of type P, then The transformation also preserves typing, as stated below, where is the typing context such that if and only if .
Theorem 6 (Preservation of typing).
- (1)
If , then .
- (2)
If , then .
Proof. By simultaneous induction on derivations. □
5. A Selective Double Negation Translation
In this section, we present an annotated proof system for CPL, which corresponds to the type and effect system given in Definition 13 via the Curry-Howard isomorphism. It keeps track of the uses of the and rules using annotations. Based on the annotations in the proof, our selective DNT translates only the parts of the proof which use the or rules into the double negation form.
We use annotated formulas defined below, where annotations are defined as in Definition 12.
Definition 16 (Annotated CPL formulas)
. A formula means that assuming A is provable, B is also provable under the assumption A, (possibly) using the or rules. In contrast, a formula means that assuming A is provable, B is also provable but without using those rules.
The proof system for annotated formulas is obtained from the type and effect system by removing the terms in each typing rule. (As in Definition 8, we omit the rule corresponding to for simplicity.) We use a judgment which means that A is true under a set of hypotheses, and its proof does not use the or rules if is ; otherwise, the proof may use them.
Definition 17 (Annotated proof system).
The interpretation of the annotations in the rules and is similar to the one for the rules and in Definition 13. In the rule , even if B is proved without using the or rules, we may annotate the implication with as if B is proved using them. In the rule , if all of , , and are , then it means that the derivation of does not use the or rules. Nevertheless, it can be annotated with as in the type and effect system. The annotated proof system is equivalent to the original proof system in the following sense.
Theorem 7 (Soundness and completeness).
- 1.
If is provable, then is also provable, where the function erase removes every annotation in the given context and formula.
- 2.
If is provable, then there exists at least one annotation for A that is provable in the annotated proof system.
Proof. (1) By straightforward induction on a derivation of . (2) The one where every implication is marked with is always provable. □
We can further extend the completeness statement such that there exists a maximal annotation with as many ’s as possible. We now define a selective translation of annotated CPL formulas into IPL formulas as follows, which directly corresponds to the selective type translation in Definition 14.
Definition 18 (Selective DNT for formulas)
. The correctness of our selective DNT is stated as follows, where applies the translation elementwise: if and only if .
Theorem 8 (Correctness).
- 1.
If is provable, then is also provable.
- 2.
If is provable, then is also provable.
Proof. We define two mutually recursive functions f and g which translate derivations of and into derivations of and , respectively. Their definitions directly correspond to the selective CPS transformation and in Definition 15. In the translations below, whenever necessary, we implicitly apply weakening on the induction hypothesis, i.e., the result of a recursive call.
- 1.
- 2.
- 3.
- 4.
- 5.
- (6)
- (7)
- (8)
- (9)
In the above translations, whereas f eliminates the instances of the rules and used in the given derivation by double-negating the goal formula, g keeps the given derivation as it is since it is also valid in IPL. □
The following diagram summarizes the relationship between the selective CPS transformation and the selective DNT. We note that the selective CPS transformation can be derived from the selective DNT by assigning proof terms to each inference rule.
6. Discussion and Conclusions
In this paper, we studied the logical meaning of a selective CPS transformation [
16]. Although we considered only a CBV semantics, our analysis can also be applied to a call-by-name (CBN) CPS transformation [
4,
12,
18]. In a CBN semantics, a lambda application
reduces to
regardless of whether
N is a value or not. Therefore, under the CBN CPS transformation, a translated function is passed an argument in the CPS form, and thus a function type
is translated into
. The corresponding DNT, such as Kolmogorov’s translation [
9], translates
into
, and we can exploit our annotated proof system, presented in
Section 5, to derive a CBN selective DNT.
While our selective DNT is a direct logical interpretation of Nielsen’s selective CPS transformation [
16], there is still room for further improvement. First, unlike the rule
, the rule
is valid not only in classical logic but also in intuitionistic logic, and therefore we may not need to translate the instances of
into the double negation form. We choose to translate them in order to keep the direct correspondence between the CPS transformation and the DNT. Second, by further analyzing annotations, we can produce a smaller proof. For example, the following derivation
can be translated into
which is much smaller than the result of the selective DNT given in the proof of Theorem 8. The corresponding case of the selective CPS transformation given in Definition 15 can also be improved as follows.
We leave as future work a further investigation into whether or not this finer analysis of annotations still preserves the operational meaning of the source program in the sense of Theorem 5. Moreover, in this paper, we considered only control operators
and
and the corresponding selective CPS transformation. Since there are other control structures (e.g., delimited continuations [
19,
20,
21] and exceptions [
22]) and corresponding selective CPS transformations, it will also be interesting to investigate their logical interpretation by parameterizing our analysis over such control operators. For further details on various control structures and CPS transformations, the reader may refer to [
23].
Another interesting direction for future work is to include other connectives such as conjunction and disjunction which respectively correspond to product and sum types in programming languages. In addition, since we consider only propositional logic, one natural extension is to consider first-order predicate logic, which corresponds to dependently typed
-calculus. However, it is challenging to define a computationally sound double negation proof translation for classical predicate logic, namely a CPS transformation for a dependently typed language. For example, the standard CPS transformation based on double negation is not type preserving for a dependently typed language with
types (strong dependent pairs which correspond to universal quantifiers) [
24]. Moreover, unrestricted uses of
and
together with
types and equality even leads to an inconsistent system [
25]. Recently, Bowman et al. [
26] developed type-preserving CBN and CBV CPS transformations for a dependently typed language with
and
types based on answer type polymorphism [
27]. It would be interesting to investigate the logical meaning of such translations, which we leave as future work.