Next Article in Journal
INCO-GAN: Variable-Length Music Generation Method Based on Inception Model-Based Conditional GAN
Previous Article in Journal
An Autoregressive Disease Mapping Model for Spatio-Temporal Forecasting
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

On Correspondence between Selective CPS Transformation and Selective Double Negation Translation

Department of Computer Science and Engineering, Interdisciplinary Graduate Program in Medical Bigdata Convergence, Kangwon National University, Chuncheon-si, Gangwon-do 24341, Korea
Mathematics 2021, 9(4), 385; https://doi.org/10.3390/math9040385
Submission received: 5 January 2021 / Revised: 5 February 2021 / Accepted: 8 February 2021 / Published: 15 February 2021
(This article belongs to the Special Issue Mathematical Philosophy and Mathematical Logic)

Abstract

:
A double negation translation (DNT) embeds classical logic into intuitionistic logic. Such translations correspond to continuation passing style (CPS) transformations in programming languages via the Curry-Howard isomorphism. A selective CPS transformation uses a type and effect system to selectively translate only nontrivial expressions possibly with computational effects into CPS functions. In this paper, we review the conventional call-by-value (CBV) CPS transformation and its corresponding DNT, and provide a logical account of a CBV selective CPS transformation by defining a selective DNT via the Curry-Howard isomorphism. By using an annotated proof system derived from the corresponding type and effect system, our selective DNT translates classical proofs into equivalent intuitionistic proofs, which are smaller than those obtained by the usual DNTs. We believe that our work can serve as a reference point for further study on the Curry-Howard isomorphism between CPS transformations and DNTs.

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 callcc (call-with-current continuation) and throw ( λ cont ) [3,4].
Classical logic differs from intuitionistic logic, also known as constructive logic, in that it includes the law of excluded middle (EM), A ¬ A , as a theorem, which states that for any proposition A, either A is true or its negation ¬ A is true (i.e., A is false). Classical logic also includes Peirce’s law, ( ( A B ) A ) A , and double negation elimination (DNE), ¬ ¬ A A . 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 callcc and Felleisen et al.’s C 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, A ¬ ¬ A , it only rejects double negation elimination, ¬ ¬ A A . In other words, ¬ ¬ A 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 ¬ ¬ A 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 ¬ ¬ A * , where A * 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 A cont 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 A cont can be understood as a function type A Ans , where Ans stands for the type of final results. If we interpret Ans as ⊥ and define ¬ A as a syntactic abbreviation of A as usual, then DNTs correspond to CPS transformations, which translate an expression M of type A into a CPS function of type ( A * ) 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 A * because, as in DNTs, CPS transformations also recursively translate every subexpression of the given expression into CPS expressions. The CPS transformations from λ cont 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 λ cont 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 λ cont with control operators callcc and throw into an operationally equivalent program in the target language λ without control operators.

2.1. Simply Typed λ -Calculus with Control Operators

The source language λ cont is the simply typed λ -calculus with two control operators: callcc and throw [3]. Its abstract syntax is defined as follows.
Definition 1
(Abstract syntax of λ cont ).
expressions M , N : : = p x λ x . M M N callcc x . M throw M N types A , B , C : : = P A B A cont
An expression M is either a constant p, a variable x, a lambda abstraction (anonymous function) λ x . M , a lambda application (function application) M N , or a control operator to be explained below. As for types, P ranges over an arbitrary but fixed set of primitive types, A B denotes the type of functions from domain A to range B, and A cont denotes the type of continuations that expect a value of type A.
We consider a left-to-right CBV operational semantics for λ cont using evaluation contexts, where a well-typed expression evaluates to a value.
Definition 2
(Operational semantics of λ cont ).
extended expressions M , N : : = E evaluation contexts E : : = [ ] E N V E throw E N throw V E values V : : = p λ x . M E
E [ ( λ x . M ) V ] E [ M [ V / x ] ] E [ callcc x . M ] E [ M [ E / x ] ] E [ throw E 1 V ] E 1 [ V ]
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., M = E [ N ] , where E [ N ] 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 E . A value V is then either a constant, a lambda abstraction, or a continuation.
We use a reduction judgment M M to denote one-step reduction of M to M . 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 ( λ x . M ) V reduces to M [ V / x ] ( β -reduction), where M [ V / x ] 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, callcc x . M captures the current context E, stores a continuation E in x, and proceeds to reduce M. Finally, throw E 1 V throws a value V to a continuation E 1 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 Γ M : A 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 x : A , 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.
typing contexts Γ : : = · Γ , x : A
A closed expression M is well-typed with respect to a type A if · M : A is provable using the typing rules in Definition 3.
Definition 3
(Typing rules for λ cont ).
Γ , x : A x : A Tvar CONST TYPE ( p ) = P Γ p : P Tconst Γ , x : A M : B Γ λ x . M : A B Tlam
Γ M : A B Γ N : A Γ M N : B Tapp Γ , x : A cont M : A Γ callcc x . M : A Tcallcc
Γ M : A cont Γ N : A Γ throw M N : C Tthrow
The above typing rules are standard [3]. In the rule Tconst , CONST - TYPE is a predefined mapping from constants to primitive types. In the rule Tcallcc , callcc x . M is of type A if M is also of type A assuming x : A cont . Please note that x will at runtime be bound to a continuation that expects the result of M. Therefore, callcc itself can be given a type ( A cont A ) A for any type A, which corresponds to Peirce’s law. In the rule Tthrow , if M and N are of type A cont and A, respectively, then throw M N can be assigned an arbitrary type C because its reduction never returns to the current evaluation context. Therefore, the rule Tthrow 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 λ cont into the target language λ without callcc and throw . The abstract syntax of λ is defined as follows.
Definition 4
(Abstract syntax of λ ).
expressions M , N : : = p x λ x . M M N types A , B , C : : = P A B values V : : = p λ x . M
The main idea of the transformation is twofold. First, it interprets a continuation of type A cont as a function of type A , 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 A * , 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 C M of type ( A * ) , which is defined in Definition 6.
Definition 5
(CBV type translation).
P * = P ( A B ) * = A * ( ( B * ) ) ( A cont ) * = A *
Definition 6
(CBV CPS transformation).
C p = λ k . k p C x = λ k . k x C λ x . M = λ k . k ( λ x . C M ) C M N = λ k . C M ( λ f . C N ( λ v . f v k ) ) C callcc x . M = λ k . ( C M [ k / x ] ) k C throw M N = λ k . C M ( λ k . C N k )
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 M N , let us first analyze the type structure of the transformed expression:
In the transformed expression λ k : B * . C M ( λ f : ( A B ) * . C N ( λ v : A * . f v k ) ) ,
C M will bind the CPS-transformed evaluation result of M to f and C N will bind that of N to v. Then the function f is called with the argument v and the initial continuation k as f v k , which returns an answer of type ⊥. In the translation of callcc x . M , C M of type ( A * ) will apply the initial continuation k of type A * to the CPS-transformed evaluation result of M, which is of type A * . Moreover, the continuation variable x of type A cont is substituted with the explicit continuation k in C M . Finally, in the translation of throw M N , C M will bind the continuation evaluated from M to k , and then C N will apply k 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, then
M * V C M ( λ x . x ) * V
where * 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 x : A * Γ * if and only if x : A Γ .
Theorem 2.
If Γ M : A , then Γ * C M : ( A * ) .
Proof. 
By induction on the structure of M. □

3. A Double Negation Translation

By the Curry-Howard isomorphism, types and expressions in λ cont correspond to formulas and proofs in classical implicational propositional logic (CPL) [4]. The formulas of CPL are defined as follows.
Definition 7
(CPL formulas).
formulas A , B , C : : = P A B ¬ A
P ranges over atomic propositions. We choose only implication ⊃ and negation ¬ as primitive connectives to clearly show the connection between λ cont and CPL. Other connectives A B and A B can be notionally defined as ¬ A B and ¬ ( A ¬ B ) , respectively. A continuation type A cont in λ cont is interpreted as a negated formula ¬ A in CPL.
The type system for λ cont given in Definition 3 can be interpreted as the proof system for CPL given in Definition 8. We use a hypothetical judgment Γ K A to mean that a proposition A is true under a set Γ of hypotheses (where the subscript K 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 Tconst 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).
Γ , A K A Hyp Γ , A K B Γ K A B I Γ K A B Γ K A Γ K B E
Γ , ¬ A K A Γ K A Peirce Γ K ¬ A Γ K A Γ K C Contra
The typing rules Tcallcc and Tthrow for control operators correspond to the rules Peirce and Contra 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.
Γ K ¬ ¬ A A DNE Γ K A ¬ A EM
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.
Definition 9
(IPL formulas).
formulas A , B , C : : = P A B
A natural deduction system for IPL is defined below. We use a judgment Γ I A to mean that a proposition A is true in IPL under a set Γ of hypotheses (where the subscript I stands for Intuitionistic).
Definition 10
(Proof system for IPL).
Γ , A I A Hyp Γ , A I B Γ I A B I Γ I A B Γ I A Γ I B E Γ I Γ I C E
Although we include the E 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 E rule. Please note that ⊥ is not even included in CPL (although it can be encoded, for example, as A ¬ A ). Meanwhile, we regard ¬ A as a syntactic abbreviation of A in IPL. Therefore, the following rules are special cases of the ⊃ introduction and elimination rules.
Γ , A I Γ I ¬ A ¬ I Γ I ¬ A Γ I A Γ I ¬ E
We define a translation of CPL formulas into IPL formulas exactly like the CBV CPS transformation of types, as follows.
Definition 11
(DNT for formulas).
P * = P ( A B ) * = A * ( ( B * ) ) A * ¬ ¬ B * ( ¬ A ) * = A *
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, A B is translated into ¬ ¬ A * ¬ ¬ B * .
The correctness of the DNT is stated as follows, where Γ * applies the translation elementwise: A * Γ * if and only if A Γ .
Theorem 3.
If Γ K A is provable, then Γ * I ¬ ¬ A * is also provable.
Proof. 
We define a recursive function that maps a derivation of Γ K A into a derivation of Γ * I ¬ ¬ A * . 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 callcc or throw ) 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 T while (possibly but not necessarily) nontrivial ones with N . The following is the minimally annotated syntax of the source language λ cont , where we omit annotations when clear from the structure of the given expression.
Definition 12
(Annotated syntax).
annotations a : : = T N where N < T expressions M , N : : = p x λ a x . M ( M @ a N ) a callcc x . M throw M N types A , B , C : : = P A a B A cont
We understand values and identifiers to always be implicitly annotated with T and control expressions with N , and thus do not explicitly mark them in the syntax. Moreover, we denote an application by M @ N instead of M N for specifying annotations. Still, when annotations do not matter, we use the usual notation M N . Special care should be taken for abstractions and applications. For an application of the form ( λ x . M ) @ V , if the function body M is nontrivial, the evaluation of its β -reduct M [ V / x ] gives rise to an effect. For such applications, we annotate @ with N as in ( λ x . M ) @ N V . An application M @ N is annotated with N , i.e., ( M @ N ) N , 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 ( λ f . fst ( f M ) ( f N ) ) ( λ g . g p ) where fst = λ x . λ y . x 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 N as in λ N x . M . Correspondingly, if λ x . M is of type A B , then λ N x . M and λ T x . M respectively have an annotated type A N B and A T B .
We say that annotations are consistent (with respect to the program’s behavior) if
  • every expression annotated with T is indeed trivial,
  • every abstraction annotated with T (resp. N ) is applied only at application points annotated with T (resp. N ), and
  • every abstraction whose body is annotated with N is also annotated with N .
To check the consistency of annotations, we use a type and effect system using a judgment Γ M : A , a which means that expression M is of type A and can be annotated with a under typing context Γ .
Definition 13
(Type and effect system).
Γ , x : A x : A , T Tvar CONST TYPE ( p ) = P Γ p : P , T Tconst
Γ , x : A M : B , a 1 a a 1 Γ λ a x . M : A a B , T Tlam
Γ M : A a 3 B , a 1 Γ N : A , a 2 a min ( a 1 , a 2 , a 3 ) Γ ( M @ a 3 N ) a : B , a Tapp
Γ , x : A cont M : A , a Γ callcc x . M : A , N Tcallcc Γ M : A cont , a 1 Γ N : A , a 2 Γ throw M N : C , N Tthrow
The relation a a 1 in the rule Tlam allows us to annotate an abstraction with a trivial body with N . Similarly, in the rule Tapp , even if a 1 , a 2 , and a 3 are all T , the application can be annotated with N . 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 T , the evaluation of M does not give rise to an effect.
Theorem 4.
If Γ M : A , a , annotations in M are consistent.
Proof. 
By induction on a derivation of Γ M : A , a . □
Corollary 1.
Given a closed expression M, if · M : A , T , no effects occur during the evaluation of M.
The CBV selective CPS transformation associates each type A with A defined below. The main difference from Definition 5 is the translation of function types, where a trivial function type A T B is kept in the direct style.
Definition 14
(Selective type translation).
P = P ( A N B ) = A ( ( B ) ) ( A T B ) = A B A cont = A
In order to transform expressions selectively, we use two functions: S translates expressions of type A into those of type ( A ) and S t translates expressions of type A into those of type A . Given an expression, the former translates it into a CPS expression, whereas the latter keeps it in the direct style. In particular, S t takes only trivial expressions.
Definition 15
(Selective CPS transformation).
S M T = λ k . k S t M S ( M @ N N ) N = λ k . S M ( λ f . S N ( λ v . f v k ) ) S ( M @ T N ) N = λ k . S M ( λ f . S N ( λ v . k ( f v ) ) ) S callcc x . M = λ k . ( S M [ k / x ] ) k S throw M N = λ k . S M ( λ k . S N k ) S t x = x S t p = p S t λ N x . M = λ x . S M S t λ T x . M = λ x . S t M S ( M @ T N ) T = S t M S t N
The main difference between Definitions 6 and 15 is the transformation of functions and applications annotated with T . In the translation of a function λ T x . M , the body M is kept in the direct style, i.e., translated using S t . Similarly, in the translation of an application ( M @ T N ) T , both M and N are kept in the direct style. Finally, for an application ( M @ T N ) N , the annotation T for @ indicates that M is of type A T B for some types A and B. In other words, if M evaluates to an abstraction λ x . M , then M would be trivial. Therefore, in the transformed expression, S M is applied to a continuation of type ( A T B ) . Specifically, at runtime, f will be bound to the result evaluated from M, which is of type A B , and f v will evaluate to a value of type B , which is in the direct style. Hence, we apply to f v a continuation k that expects the result of M N .
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
M * V S M ( λ x . x ) * V .
The transformation also preserves typing, as stated below, where Γ is the typing context such that x : A Γ if and only if x : A Γ .
Theorem 6
(Preservation of typing).
(1)
If Γ M a : A , a , then Γ S M : ( A ) .
(2)
If Γ M T : A , T , then Γ S t M : A .
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 Peirce and Contra rules using annotations. Based on the annotations in the proof, our selective DNT translates only the parts of the proof which use the Peirce or Contra 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).
formulas A , B , C : : = P A a B ¬ A
A formula A N B means that assuming A is provable, B is also provable under the assumption A, (possibly) using the Peirce or Contra rules. In contrast, a formula A T B 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 Tconst for simplicity.) We use a judgment Γ K A , a which means that A is true under a set Γ of hypotheses, and its proof does not use the Peirce or Contra rules if a is T ; otherwise, the proof may use them.
Definition 17
(Annotated proof system).
Γ , A K A , T Hyp Γ , A K B , a 1 a a 1 Γ K A a B , T I Γ , ¬ A K A , a Γ K A , N Peirce
Γ K A a 3 B , a 1 Γ K A , a 2 a min ( a 1 , a 2 , a 3 ) Γ K B , a E
Γ K ¬ A , a 1 Γ K A , a 2 Γ K C , N Contra
The interpretation of the annotations in the rules I and E is similar to the one for the rules Tlam and Tapp in Definition 13. In the rule I , even if B is proved without using the Peirce or Contra rules, we may annotate the implication with N as if B is proved using them. In the rule E , if all of a 1 , a 2 , and a 3 are T , then it means that the derivation of Γ K B , a does not use the Peirce or Contra rules. Nevertheless, it can be annotated with N 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 Γ K A , a is provable, then erase ( Γ ) K erase ( A ) is also provable, where the function erase removes every annotation in the given context and formula.
2.
If Γ K A 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 Γ K A , a . (2) The one where every implication is marked with N is always provable. □
We can further extend the completeness statement such that there exists a maximal annotation with as many T ’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).
P = P ( A N B ) = A ( ( B ) ) A ( ¬ ¬ B ) ( A T B ) = A B ¬ A = A
The correctness of our selective DNT is stated as follows, where Γ applies the translation elementwise: A Γ if and only if A Γ .
Theorem 8
(Correctness).
1.
If Γ K A , a is provable, then Γ I ¬ ¬ A is also provable.
2.
If Γ K A , T is provable, then Γ I A is also provable.
Proof. 
We define two mutually recursive functions f and g which translate derivations of Γ K A , a and Γ K A , T into derivations of Γ I ¬ ¬ A and Γ I A , respectively. Their definitions directly correspond to the selective CPS transformation S and S t 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.
f Γ K A , T = Γ , ¬ A I ¬ A Hyp g ( Γ K A , T ) Γ , ¬ A I Γ I ¬ ¬ A I E
2.
f Γ K A T B , a 1 Γ K A , a 2 Γ K B , N E = let Γ 1 = Γ , ¬ B Γ 2 = Γ 1 , A B Γ 3 = Γ 2 , A and D = Γ 3 I ¬ B Hyp Γ 3 I A B Hyp Γ 3 I A Hyp Γ 3 I B E Γ 3 I E in
f ( Γ K A T B , a 1 ) f ( Γ K A , a 2 ) D Γ 2 I ¬ A I Γ 2 I E Γ 1 I ¬ ( A B ) I Γ 1 I E Γ I ¬ ¬ B I
3.
f Γ K A N B , a 1 Γ K A , a 2 Γ K B , N E = let Γ 1 = Γ , ¬ B Γ 2 = Γ 1 , A ¬ ¬ B Γ 3 = Γ 2 , A and E = Γ 3 I A ¬ ¬ B Hyp Γ 3 I A Hyp Γ 3 I ¬ ¬ B E Γ 3 I ¬ B Hyp Γ 3 I E in
f ( Γ K A N B , a 1 ) f ( Γ K A , a 2 ) E Γ 2 I ¬ A I Γ 2 I E Γ 1 I ¬ ( A ¬ ¬ B ) I Γ 1 I E Γ I ¬ ¬ B I
4.
f Γ , ¬ A K A , a Γ K A , N Peirce = f ( Γ , ¬ A K A , a ) Γ , ¬ A I ¬ A Hyp Γ , ¬ A I E Γ I ¬ ¬ A I
5.
f Γ K ¬ A , a 1 Γ K A , a 2 Γ K C , N Contra = f ( Γ K ¬ A , a 1 ) f ( Γ K A , a 2 ) Γ , ¬ C , ¬ A I ¬ A Hyp Γ , ¬ C , ¬ A I E Γ , ¬ C I ¬ ¬ A I Γ , ¬ C I E Γ I ¬ ¬ C I
(6)
g Γ , A K A , T Hyp = Γ , A I A Hyp
(7)
g Γ , A K B , T Γ K A T B , T I = g ( Γ , A K B , T ) Γ I A B I
(8)
g Γ , A K B , a Γ K A N B , T I = f ( Γ , A K B , a ) Γ I A ¬ ¬ B I
(9)
g Γ K A T B , T Γ K A , T Γ K B , T E = g ( Γ K A T B , T ) g ( Γ K A , T ) Γ I B E
In the above translations, whereas f eliminates the instances of the rules Peirce and Contra 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.
Γ M : A , a Γ M : A , T Γ K A , a Γ K A , T in CPL Selective GPS transformation Curry Howard isomorphic Selective DNT Γ S M : ( A ) Γ S t M : A Γ I ¬ ¬ A Γ I A

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 ( λ x . M ) N reduces to M [ N / x ] 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 A B is translated into ( ( A * ) ) ( B * ) . The corresponding DNT, such as Kolmogorov’s translation [9], translates A B into ¬ ¬ A * ¬ ¬ B * , 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 Peirce , the rule Contra is valid not only in classical logic but also in intuitionistic logic, and therefore we may not need to translate the instances of Contra 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
Γ K A             D T B , T Γ K             E A , T Γ K B , N E
can be translated into
Γ , ¬ B I ¬ B Hyp g Γ K A             D T B , T g Γ K             E A , T Γ , ¬ B I B E Γ , ¬ B I Γ I ¬ ¬ B I E
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.
S ( M T @ T N T ) N = λ k . k ( S t M S t N )
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 callcc and throw 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 callcc and throw 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.

Funding

This work was supported by the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT) (No. 2019R1F1A1063272 and 2020R1A4A3079947).

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Acknowledgments

We thank Sungwoo Park who proposed the problem of selective double negation translation. We also thank anonymous reviewers for their helpful comments on an earlier version of the paper.

Conflicts of Interest

The author declares no conflict of interest.

Abbreviations

The following abbreviations are used in this manuscript:
CBVcall-by-value
CBNcall-by-name
CPLClassical propositional logic
CPSContinuation passing style
DNEDouble negation elimination
DNTDouble negation Translation
EMExcluded middle
IPLIntuitionistic propositional logic

References

  1. Curry, H.B.; Feys, R.; Craig, W. Combinatory Logic; North-Holland Publishing Company: Amsterdam, The Netherlands, 1958; Volume 1. [Google Scholar]
  2. Howard, W.A. The formulae-as-types notion of constructions. In To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism; Academic Press: London, UK, 1980; pp. 479–490, Unpublished Manuscript of 1969. [Google Scholar]
  3. Duba, B.; Harper, R.; MacQueen, D. Typing First-class Continuations in ML. In Proceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Orlando, FL, USA, 16–18 January 1991; Association for Computing Machinery: New York, NY, USA, 1991; pp. 163–173. [Google Scholar] [CrossRef] [Green Version]
  4. Griffin, T.G. A Formulae-as-type Notion of Control. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Mumbai, India, 15–17 January 1989; Association for Computing Machinery: New York, NY, USA, 1990; pp. 47–58. [Google Scholar] [CrossRef]
  5. Felleisen, M.; Friedman, D.P.; Kohlbecker, E.E.; Duba, B.F. Reasoning with Continuations. In Proceedings of the Symposium on Logic in Computer Science (LICS ’86), Cambridge, MA, USA, 16–18 June 1986; pp. 131–141. [Google Scholar]
  6. Gentzen, G. Über das Verhältnis zwischen intuitionistischer und klassischer Arithmetik. Archiv für Mathematische Logik und Grundlagenforschung 1974, 16, 119–132. [Google Scholar] [CrossRef]
  7. Glivenko, V. Sur Quelques Points de la Logique de M. Brouwer. Bull. Classe Des. Sci. 1929, 15, 183–188. [Google Scholar]
  8. Gödel, K. Zur intuitionistischen arithmetik und zahlentheorie. Ergeb. Eines Math. Kolloquiums 1933, 4, 34–38. [Google Scholar]
  9. Kolmogorov, A.N. On the principle of the excluded middle. Mat. Sbornik 1925, 32, 646–667. (In Russian) [Google Scholar]
  10. Kuroda, S. Intuitionistische Untersuchungen der formalistischen Logik. Nagoya Math. J. 1951, 2, 35–47. [Google Scholar] [CrossRef] [Green Version]
  11. Miquey, É. Classical Realizability and Side-Effects. Ph.D. Thesis, Universidad de la República, Montevideo, Uruguay, 2017. [Google Scholar]
  12. Plotkin, G. Call-by-name, call-by-value and the λ-calculus. Theor. Comput. Sci. 1975, 1, 125–159. [Google Scholar] [CrossRef] [Green Version]
  13. Reynolds, J.C. Definitional Interpreters for Higher-order Programming Languages. In Proceedings of the ACM Annual Conference; Association for Computing Machinery: New York, NY, USA, 1972; pp. 717–740. [Google Scholar] [CrossRef] [Green Version]
  14. Appel, A.W. Compiling with Continuations; Cambridge University Press: New York, NY, USA, 1992. [Google Scholar]
  15. Reppy, J.H. Optimizing Nested Loops Using Local CPS Conversion. High. Order Symb. Comput. 2002, 15, 161–180. [Google Scholar] [CrossRef]
  16. Nielsen, L.R. A Selective CPS Transformation. Electron. Notes Theor. Comput. Sci. 2001, 45, 311–331. [Google Scholar] [CrossRef] [Green Version]
  17. Wright, A.; Felleisen, M. A Syntactic Approach to Type Soundness. Inf. Comput. 1994, 115, 38–94. [Google Scholar] [CrossRef] [Green Version]
  18. Danvy, O.; Hatcliff, J. On the Transformation Between Direct and Continuation Semantics. In Proceedings of the 9th International Conference on Mathematical Foundations of Programming Semantics, New Orleans, LA, USA, 7–10 April 1993; Springer: Berlin, Germany, 1993; pp. 627–648. [Google Scholar]
  19. Rompf, T.; Maier, I.; Odersky, M. Implementing First-Class Polymorphic Delimited Continuations by a Type-Directed Selective CPS-Transform. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, Edinburgh, Scotland, 31 August–2 September 2009; Association for Computing Machinery: New York, NY, USA, 2009; pp. 317–328. [Google Scholar] [CrossRef] [Green Version]
  20. Materzok, M.; Biernacki, D. Subtyping Delimited Continuations. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming, Tokyo, Japan, 19–21 September 2011; Association for Computing Machinery: New York, NY, USA, 2011; pp. 81–93. [Google Scholar] [CrossRef]
  21. Asai, K.; Uehara, C. Selective CPS Transformation for Shift and Reset. In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, Paris, France, 18–20 January 2017; Association for Computing Machinery: New York, NY, USA, 2017; pp. 40–52. [Google Scholar] [CrossRef]
  22. Kim, J.; Yi, K.; Danvy, O. Assessing the Overhead of ML Exceptions by Selective CPS Transformation. In ACM SIGPLAN Workshop on ML; ACM: New York, NY, USA, 1998; pp. 103–114. [Google Scholar]
  23. Berdine, J. Linear and Affine Typing of Continuation-Passing Style. Ph.D. Thesis, Queen Mary, University of London, London, UK, 2004. [Google Scholar]
  24. Barthe, G.; Uustalu, T. CPS Translating Inductive and Coinductive Types. In Proceedings of the 2002 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Portland, OR, USA, 14–15 January 2002; pp. 131–142. [Google Scholar] [CrossRef] [Green Version]
  25. Herbelin, H. On the Degeneracy of Σ-Types in Presence of Computational Classical Logic. In Proceedings of the International Conference on Typed Lambda Calculi and Applications, Nara, Japan, 21–23 April 2005; Springer: Berlin, Germany, 2005; pp. 209–220. [Google Scholar]
  26. Bowman, W.J.; Cong, Y.; Rioux, N.; Ahmed, A. Type-preserving CPS Translation of Σ and Π Types is Not Not Possible. Proc. ACM Program. Lang. 2018, 2, 22:1–22:33. [Google Scholar] [CrossRef] [Green Version]
  27. Thielecke, H. From Control Effects to Typed Continuation Passing. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, News Orleans, LA, USA, 15–17 January 2013; ACM: New York, NY, USA, 2003; pp. 139–149. [Google Scholar] [CrossRef] [Green Version]
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Im, H. On Correspondence between Selective CPS Transformation and Selective Double Negation Translation. Mathematics 2021, 9, 385. https://doi.org/10.3390/math9040385

AMA Style

Im H. On Correspondence between Selective CPS Transformation and Selective Double Negation Translation. Mathematics. 2021; 9(4):385. https://doi.org/10.3390/math9040385

Chicago/Turabian Style

Im, Hyeonseung. 2021. "On Correspondence between Selective CPS Transformation and Selective Double Negation Translation" Mathematics 9, no. 4: 385. https://doi.org/10.3390/math9040385

APA Style

Im, H. (2021). On Correspondence between Selective CPS Transformation and Selective Double Negation Translation. Mathematics, 9(4), 385. https://doi.org/10.3390/math9040385

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop