A New Proof of P-time Completeness of Linear Lambda Calculus

Similar documents
CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

CMSC 330: Organization of Programming Languages. Operational Semantics

Lecture Notes on Induction and Recursion

Typed Lambda Calculus for Syntacticians

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

Introduction to SML Getting Started

Introduction to Type Theory August 2007 Types Summer School Bertinoro, It. Herman Geuvers Nijmegen NL

Typed Lambda Calculus

The Typed λ Calculus and Type Inferencing in ML

Demonstrating Lambda Calculus Reduction

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

Introduction to Lambda Calculus. Lecture 7 CS /08/09

Lecture slides & distribution files:

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

λ calculus is inconsistent

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

Type Theory. Lecture 2: Dependent Types. Andreas Abel. Department of Computer Science and Engineering Chalmers and Gothenburg University

Beluga: A Framework for Programming and Reasoning with Deductive Systems (System Description)

Lecture 3: Recursion; Structural Induction

1.3. Conditional expressions To express case distinctions like

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

4.5 Pure Linear Functional Programming

Introduction to the Lambda Calculus

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Lambda Calculus. Variables and Functions. cs3723 1

LOGIC AND DISCRETE MATHEMATICS

Linear lambda calculus and PTIME-completeness

The design of a programming language for provably correct programs: success and failure

Formal Semantics. Prof. Clarkson Fall Today s music: Down to Earth by Peter Gabriel from the WALL-E soundtrack

Contents. Chapter 1 SPECIFYING SYNTAX 1

CS 6110 S11 Lecture 12 Naming and Scope 21 February 2011

Formal Systems and their Applications

Chapter 2 The Language PCF

Polymorphism and Type Inference

Com S 541. Programming Languages I

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Propositional Logic. Andreas Klappenecker

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

Core-TyCO The Language Definition Version 0.1

CIS 500 Software Foundations Fall September 25

02157 Functional Programming Lecture 1: Introduction and Getting Started

Combining Programming with Theorem Proving

Lists. Michael P. Fourman. February 2, 2010

Lambda Calculus and Type Inference

Polymorphism and Type Inference

Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008

Introductory logic and sets for Computer scientists

Calculus of Inductive Constructions

Logical Verification Course Notes. Femke van Raamsdonk Vrije Universiteit Amsterdam

Introduction. chapter Functions

CS3110 Spring 2017 Lecture 9 Inductive proofs of specifications

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Extracting the Range of cps from Affine Typing

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Programming Language Concepts: Lecture 19

CSE 341: Programming Languages

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

THE RELATIONAL MODEL. University of Waterloo

JOURNAL OF OBJECT TECHNOLOGY

Type Systems COMP 311 Rice University Houston, Texas

Propositional Calculus. Math Foundations of Computer Science

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Lecture Notes on Computational Interpretations of Modalities

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

Refinement Types as Proof Irrelevance. William Lovas with Frank Pfenning

Concepts of programming languages

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

Negations in Refinement Type Systems

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Part I Logic programming paradigm

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Binary Decision Diagrams

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources

From the λ-calculus to Functional Programming Drew McDermott Posted

Lambda Calculus and Type Inference

TIC. %goo~~oo eomputer-science. ELECTE f. No-te on Coridhitiom Cominliati"I~n Standard ML1

Lecture 5: The Untyped λ-calculus

Lambda Calculus. Lecture 4 CS /26/10

LECTURE 16. Functional Programming

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

CHAPTER ONE OVERVIEW. 1.1 Continuation-passing style

Propositional Logic. Part I

15-819M: Data, Code, Decisions

CSE-321 Programming Languages 2010 Final

Operational Semantics

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Basic Foundations of Isabelle/HOL

Recursive Definitions, Fixed Points and the Combinator

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

CLF: A logical framework for concurrent systems

CSCI-GA Scripting Languages

2 Robert Harper However, the program contains a subtle error that we tease out by attempting to carry out a proof of its correctness. The development

CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point

7. Introduction to Denotational Semantics. Oscar Nierstrasz

EXTENSIONS OF FIRST ORDER LOGIC

15 150: Principles of Functional Programming Some Notes on Regular Expression Matching

15 212: Principles of Programming. Some Notes on Induction

Transcription:

A New Proof of P-time Completeness of Linear Lambda Calculus National Institute of Advanced Industrial Science and Technology (AIST), 1-1-1 Umezono, Tsukuba, Ibaraki, 305-8563 Japan arxiv:1301.2763v1 [cs.lo] 13 Jan 2013 Satoshi Matsuoka January 27, 2018 Abstract We give a new proof of P-time completeness of Linear Lambda Calculus, which was originally given by H. Mairson in 2003. Our proof uses an essentially different Boolean type from the type Mairson used. Moreover the correctness of our proof can be machined-checked using an implementation of Standard ML. 1 Introduction In [Mai04], H. Mairson gave a proof of P-time completeness of Linear Lambda Calculus. It is an excellent exercise of linear functional programming. The crucial point of the proof is that the copy function of truth values is representable by a linear term: this is relatively easy in Affine Lambda Calculus as shown in [Mai04], but quite difficult in Linear Lambda Calculus. So, the key issue there is to avoid the use of the weakening rule. The issue was also treated from a different angle in [Mat07], which established typed Böhm theorem without the weakening rule. In this paper we give a new proof of P-time completeness of Linear Lambda Calculus. Our proof is different from that of [Mai04] in the following points: In [Mai04] Mairson used the base Boolean typeb MH = p p (p p p) p while we use B=(p p) (p p) (p p). Although both have two normal forms, they are different because whileb MH reduces to itself by the linear distributive transformation given in Section 3 of [Mat07] (which was called third order reduction in [Mat07]), B reduces to which has six normal forms. B red = p p (p p) (p p p) p, All the two variable functions that can be representable overb MH without any polymorphism are only exclusive or and its negation, but in B they are all the boolean functions except for exclusive or and its negation, i.e., fourteen functions. 1

our proof is also an interesting application of the linear distributive transformation. As in [Mai04], our proof is also machine-checkable: all the linear λ-terms in this paper are also well-formed expressions of Standard ML [MTHM97]. So the reader may confirm the correctness of our proof using an implementation of Standard ML. We used the interactive system of Standard ML of New Jersey. 2 Typing Rules We give our term assignment system for Linear Lambda Calculus. Our system is based on Natural Deduction, e.g., given in [Tro92], which is equivalent to the system based on Sequent Calculus or proof nets in [Gir87] (see [Tro92]). Its notation is unusual in the Linear Logic community, but its purpose is to make our proof machine-checkable. Types A ::= a A1*A2 A1->A2 The symbol a stands for a type variable. On the other hand A1*A2 stands for the tensor product A1 A2 and A1->A2 for the linear implication A1 A2. Terms We usex,y,z for term variables, x, y, z for finite lists of term variables, and t,s for general terms. Term Assignment System x:a, y:γ t:b y:γ fn x=>t:a->b x:a x:a x:γ t:a->b y: s:a x:γ, y : ts:b x:γ s:a y: s:b x:γ, y : (s,t):a *B x:γ s:a *B x:a,y:b, y: t:c x:γ, y: let val (x,y)=s in t end:c Moreover, function declaration fun f x1 x2 xn = t is interpreted as the following term: f = fn x1 => (fn x2 => ( (fn xn => t) )) We only consider closed term (or combinator) t:a. The following proposition is proved easily by structural induction: Proposition 2.1 Ifx1:A1,...,xn:An -t:b then fun f x1 x2 xn = t is a well formed function declaration of Standard ML. 2

Term Reduction Rules Two of our reduction rules are (β): (fn x=>t)s t[s/x] ( -red): let val (x,y)=(u,v) in w end w[u/x,v/y] In fact, in Standard ML, s,u,v must be values in order for these rules to be applied. But Linear Lambda Calculus satisfies SN and CR properties. So we don t need to care the evaluation order. Then note that if a functionfis defined by fun f x1 x2 xn = t and x1:a1,...,xn:an -s:b, -t1:a1,..., -tn:an then, we have f t1 tn t[t1/x1,...,tn/xn]. Moreover we need the following reduction for a theoretical reason, which is absent from Standard ML: (η): t (fn x => t x) In the following = βη denotes the congruence relation generated by the three reduction rules. 3 Review of Mairson s Proof In this section we review the proof in [Mai04] briefly. Below by normal forms we mean βη-long normal forms. The basic construct is the following term: - fun Pair x y z = z x y; val Pair = fn : a -> b -> ( a -> b -> c) -> c Using this, we definetrue andfalse: - fun True x = Pair x y; val True = fn : a -> b -> ( a -> b -> c) -> c - fun False x = Pair y x; val True = fn : a -> b -> ( b -> a -> c) -> c Note that these are the normal forms of B MH. In order to define the term Copy two auxiliary terms are needed: - fun I x = x; val I = fn : a -> a - fun id B = B I I I ; val id = fn : (( a -> a) -> ( b -> b) -> ( c -> c) -> d) -> d The formal argumentbis supposed to receivetrue orfalse. It is easy to see that id True I, id False I, Then the termcopy is defined as follows: - fun Copy P = P (Pair True True) (Pair False False) (fn U => fn V => U (fn u1 => fn u2 => V (fn v1 => fn v2 => ((id v1) u1, (id v2) u2))))) We omit its type since it is too long. The formal argumentpis supposed to receivetrue or False. While [Mai04] uses continuation passing style, the above term not since we 3

have the (= )-connective and can do a direct encoding using this connective. Then Copy True; val it=(fn,fn):( a -> b -> ( a -> b -> c) -> c)*( d -> e -> ( d -> e -> f) -> f) Copy False; val it=(fn,fn):( a -> b -> ( b -> a -> c) -> c)*( d -> e -> ( e -> d -> f) -> f) (in fact, since SML/NJ does not allow any function values, it gives warnings, but the results are basically the same). These are (True, True) and (False, False) respectively since Copy True ((id False) True, (id False) True) Copy False ((id True) False, (id True) False) The basic observation here is that the type ofpis unifiable with that of bothtrue andfalse; the types of Copy True and Copy False are desirable ones, i.e., both have B MH B MH as a instance. Since the and gate can be defined similarly and more easily and the not gate without any ML-polymorphism, it is concluded that all the boolean gates can be defined overb MH. 4 A Partial Solution In this section we present our failed attempt. Let the following two terms betrue andfalse : fun True x y f = Pair x (f y); val True = fn : a -> b -> ( b -> c) -> ( a -> c -> d) -> d fun False x y f = Pair (f x) y; val False = fn : a -> b -> ( a -> c) -> ( c -> b -> d) -> d Both are normal forms of B red = p p (p p) (p p p) p, which have the six normal forms. Below we define a copy function for them as in the previous section. In order to do that, we need several auxiliary terms: fun not f x y g h = f y x g (fn u => fn v => (h v u)); val not = fn : ( a -> b -> c -> ( d -> e -> f) -> g) -> b -> a -> c -> ( e -> d -> f) -> g The termnot is the not gate for the new boolean values. fun swap f g = f (fn u => fn v => g v u); val swap = fn : (( a -> b -> c) -> d) -> ( b -> a -> c) -> d We note that swap(pair False True )g = βη (Pair False True )(fnu=>fnv=>g u v) = βη g True False = βη Pair True False g The termnewid is similar toid, but receives four arguments: fun newid B = B I I I I; 4

val newid = fn : (( a -> a) -> ( b -> b) -> ( c -> c) -> ( d -> d) -> e) -> e The termconstnot is also similar toid, but always returnsnot : fun constnot B = B I not I I; val constnot = fn : (( a -> a) -> (( b -> c -> d -> ( e -> f -> g) -> h) -> c -> b -> d -> ( f -> e -> g) -> h) -> ( i -> i) -> ( j -> j) -> k) -> k The formal argument B in newid and constnot is supposed to receivetrue and False. We can easily see newid True I, newid False I, constnot True not, constnot False not Under the preparation above, we can definecopy as follows: fun Copy P = P (Pair False True ) (Pair False True ) swap (fn U => fn V => U (fn u1 => fn u2 => V (fn v1 => fn v2 => ((constnot v1) u1, (newid v2) u2)))); Again we omit the type. The formal parameter P is supposed to receive True or False. Then Copy True ((constnot True) False, (newid False) True) (True, True) Copy False ((constnot False) True, (newid True) False) (False, False) Unfortunately we could not find a term that represents the and gate over True and False. So, we must find a similar, but different substitute. Fortunately we have found a solution described in the next section. 5 Our Solution Our solution uses the type B =(p p) (p p) (p p), which has the two normal forms: fun True x = (fn z => z, fn y => x y); val True = fn : ( a -> b) -> ( c -> c) * ( a -> b) fun False x = (fn y => x y, fn z => z); val False = fn : ( a -> b) -> ( a -> b) * ( c -> c) The linear distributive transformation (which was called third-order reduction in [Mat07]) turnbintob red. The next term is its internalized version: fun LDTr h x y f z = let val (k, l) = h f in z (k x) (l y) end; 5

val LDTr = fn : ( a -> ( b -> c) * ( d -> e)) -> b -> d -> a -> ( c -> e -> f) -> f Then LDTr True = βη True, LDTr False = βη False Our not gate fortrue andfalse is fun not h f = let val (k, l) = h f in (l, k) end; val not = fn : ( a -> b * c) -> a -> c * b Then not True = βη False, not False = βη True Moreover we can write down a and gate for them as follows: fun and f g h = let val (u, v) = g (fn k => h k) in (let val (x, y) = f (fn w => v w) in (fn s => x (u s), fn t => y t) end) end; val and = fn : (( a -> b) -> ( c -> d) * ( e -> f)) -> (( g -> h) -> ( i -> c) * ( a -> b)) -> ( g -> h) -> ( i -> d) * ( e -> f) Note that the definition ofand does not use any ML-polymorphism. Then and True True = βη True, and False False = βη False, and True False = βη False, and False True = βη False Next, we define a copy function fortrue andfalse. In order to do that, we need a modified version ofconstnot: fun constnot B = B I not I I; Then we can easily see newid True I, newid False I, constnot True not, constnot False not Under the preparation above, we can define Copy, which is a modified version of Copy as follows: fun Copy P = LDTr P (Pair False True ) (Pair False True ) swap (fn U => fn V => U (fn u1 => fn u2 => V (fn v1 => fn v2 => ((constnot (LDTr v1)) u1, (newid (LDTr v2)) u2)))); Then Copy True (True, True ), Copy False (False, False ) From what precedes we can conclude that we can represent all the boolean gates overb. 6

6 Concluding Remarks In this paper we showed thatb MH is not the only choice in order to establish P-time completeness of Linear Lambda Calculus. We note that we found the term and manually using proof nets syntax (and then translating the proof net into and ), but Copy and Copy interactively with Standard ML of New Jersey. From our result a natural question comes up: which linear type other thanb MH andband its two normal forms establishes P-time completeness of Linear Lambda Calculus? For example it is unlikely that B = p (p p) (p p) p and its two normal forms establish that. But it is an easy exercise to show that(p p) (p p) and its two normal forms can do that. As wrote before, we could not prove thatb red and its normal formstrue andfalse establish P-time completeness of Linear Lambda Calculus. But we also could not prove that they cannot establish that. At this moment we do not have any idea to do that. Our n {}}{ typeband its generalization(p p) (p p) (p p) have further interesting properties. For example we can establish weak typed Böhm theorem over B. But the subject is beyond the scope of this paper, and will be discussed elsewhere. References [Gir87] J.-Y. Girard. Linear Logic, Theoretical Computer Science, 50, 1-102, 1987. [Mat07] Satoshi Matsuoka. Weak Typed Böhm Theorem on IMLL, Annals of Pure and Applied Logic, 145(1): 37-90, 2007. [Mai04] H.G. Mairson. Linear Lambda Calculus and PTIME-completeness, Journal of Functional Programing, 14(6): 623-633, 2004. [MTHM97] Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. The Definition of Standard ML (Revised). MIT Press, 1997. [Tro92] A.S. Troelstra. Lectures on Linear Logic, CSLI, 1992. 7