1 Explicit Contexts in LF Karl Crary Carnegie Mellon University Workshop on Mechanized Metatheory, 9/21/06.

Slides:



Advertisements
Similar presentations
Programmed Strategies for Program Verification Richard B. Kieburtz OHSU/OGI School of Science and Engineering and Portland State University.
Advertisements

Substitution & Evaluation Order cos 441 David Walker.
Certified Typechecking in Foundational Certified Code Systems Susmit Sarkar Carnegie Mellon University.
Foundational Certified Code in a Metalogical Framework Karl Crary and Susmit Sarkar Carnegie Mellon University.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
March 4, 2005Susmit Sarkar 1 A Cost-Effective Foundational Certified Code System Susmit Sarkar Thesis Proposal.
Cayley Theorem Every group is isomorphic to a permutation group.
A Type Theory for Memory Allocation and Data Layout Leaf Petersen, Robert Harper, Karl Crary and Frank Pfenning Carnegie Mellon.
CLF: A Concurrent Logical Framework David Walker Princeton (with I. Cervesato, F. Pfenning, K. Watkins)
Refining Mechanized Metatheory: Subtyping for LF William Lovas (with Frank Pfenning)
Formal Logic Proof Methods Direct Proof / Natural Deduction Conditional Proof (Implication Introduction) Reductio ad Absurdum Resolution Refutation.
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
What’s left in the course. The course in a nutshell Logics Techniques Applications.
Formalizing Alpha: Soundness and Completeness Bram van Heuveln Dept. of Cognitive Science RPI.
Twelf: The Quintessential Proof Assistant for Language Metatheory Karl Crary Carnegie Mellon University Joint work with Robert Harper and Michael Ashley-Rollman.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
POPLmark 1A in Cinic Evan Austin, Aaron Stump, and Edwin Westbrook 1.
Syntax With Binders COS 441 Princeton University Fall 2004.
Reading: Chapter 4, section 4 Nongraded Homework: Problems at the end of section 4. Graded Homework #4 is due at the beginning of class on Friday. You.
After today Week 9 –Tu: Pat Rondon –Th: Ravi/Nathan Week 10 –Tu: Nathan/Ravi –Th: Class canceled Finals week –Th: Zach, John.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 6 Limitations of propositional logic Introduction to predicate logic Symbols, terms and formulae, Parse.
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
No new reading for Monday or Wednesday Exam #2 is next Friday, and we’ll review and work on proofs on Monday and Wed.
App IV. Supplements to the Theory of Symmetric Groups Lemma IV.1: x p = p x p –1 Let { h } & { v } be horizontal & vertical permutations of Young tableaux.
3 DIFFERENTIATION RULES.
Chapter 6: Objections to the Physical Symbol System Hypothesis.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
SOLVING SYSTEMS OF LINEAR EQUATIONS BY ELIMINATION Section 17.3.
91587 Mathematics and Statistics Apply systems of simultaneous equations in solving problems Level 3 Credits 2 Assessment Internal.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
A Locally Nameless Theory of Objects 1.Introduction:  -calculus and De Bruijn notation 2.locally nameless technique 3.formalization in Isabelle and proofs.
Lesson 4 Typed Arithmetic Typed Lambda Calculus 1/21/02 Chapters 8, 9, 10.
Type Safety Kangwon National University 임현승 Programming Languages.
Towards Automatic Verification of Safety Architectures Carsten Schürmann Carnegie Mellon University April 2000.
Logic in Computer Science - Overview Sep 1, 2009 박성우.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
Non-interference in Constructive Authorization Logic Deepak Garg and Frank Pfenning Carnegie Mellon University.
Types and Programming Languages Lecture 12 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
Mechanizing Metatheory without Typing Contexts TYPES 2011 September 10, 2011 Jonghyun Park, Jeongbong Seo, Sungwoo Park, Gyesik Lee* Pohang University.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Advanced Formal Methods Lecture 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
CSE-321 Programming Languages Abstract Machine E POSTECH May 1, 2006 박성우.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Higher-Order Encodings in Intensional Type Theory Edwin Westbrook Rice University.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
1 A Certified Type-Preserving Compiler from Lambda Calculus to Assembly Language Adam Chlipala University of California, Berkeley An experiment with variable.
1 Interactive Computer Theorem Proving CS294-9 November 30, 2006 Adam Chlipala UC Berkeley Lecture 14: Twelf.
Generic Programming and Proving for Programming Language Metatheory
Chapter 2: Lambda Calculus
CSE-321 Programming Languages Simply Typed -Calculus
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
A Verified Compiler for an Impure Functional Language
Corky Cartwright January 18, 2017
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Advanced Functional Programming
Typed Arithmetic Expressions
Programming Languages and Compilers (CS 421)
Engineering Aspects of Formal Metatheory
Scoping and Binding of Variables
6.001 SICP Variations on a Scheme
L Calculus.
Presentation transcript:

1 Explicit Contexts in LF Karl Crary Carnegie Mellon University Workshop on Mechanized Metatheory, 9/21/06

2 The LF methodology Construct isomorphisms between: –Syntactic classes and LF types –Expressions and LF terms (of appropriate type) –Judgements and LF types –Derivations and LF terms (of appropriate type)

3 The LF methodology Isomorphisms must commute with substitution. To do so: –Identify OL variables with LF variables. –Identify OL assumptions with LF assumptions. –Consequently, identify OL contexts with (fragments of) LF contexts.

4 LF example: Syntax tp : type. exp : type. o : tp. arrow : tp -> tp -> tp. b : exp. lam : tp -> (exp -> exp) -> exp. app : exp -> exp -> exp.

5 LF example: Semantics of : exp -> tp -> type. of/b : of b o. of/lam : of (lam A ([x] M x)) (arrow A B) of (M x) B). of/app : of (app M N) B <- of M (arrow A B) <- of N A.

6 The problem Contexts are implicit. Cannot be manipulated by proofs. Can be a problem for theorems involving a distinguished bound variable.

7 Distinguished bound variable If of M A and ({x} of x A -> of (N x) B) then of (N M) B In Twelf syntax: subst : of M A -> ({x} of x A -> of (N x) B) -> of (N M) B -> type. %mode subst +D1 +D2 -D3.

8 Important caveat There’s no reason to do this! Substitution lemma is free in LF. –If D1 : of M A and D2 : ({x} of x A -> of (N x) B) then D2 M D1 : of (N M) B Illustrative example, not a motivating one.

9 Motivating examples Substitution lemma for languages with different judgements on left and right – Sequent calculus, imperative type systems Narrowing in F-sub (Poplmark challenge) Functionality Defined notions of substitution –Hereditary substitution Linear and modal logic

10 Substitution theorem If of M A and ({x} of x A -> of (N x) B) then of (N M) B By induction on the second argument.

11 A proof case Suppose: D1 : of M A D2 = [x] [d:of x A] of/lam ([y] [e] D x d y e) : {x} of x A -> of (lam B ([y] N x y)) (arrow B C) D : {x} of x A -> {y} of y B -> of (N x y) C

12 A proof case Let y:exp and e:of y B be arbitrary. Therefore: [x] [d:of x A] D x d y e : {x} of x A -> of (N x y) C By induction there exists: D’ y e : of (N M y) C Therefore of/lam D’ : of (lam B ([y] N M y)) (arrow B C)

13 A proof case in Twelf -: subst D1 ([x] [d:of x A] of/lam ([y] [e:of y B] D x d y e)) (of/lam D') <- ({y} {e:of y B} subst D1 ([x] [d:of x A] D x d y e) (D' y e : of (N M y) C)).

14 Assumption permutation Proof permutes x & d with y & e. No room for bindings between distinguished variable and its scope. –Undistinguished variables go in context. In essence, the distinguished variable must appear last. –Permute assumptions to preserve this condition.

15 Uh oh! With dependent types, we cannot permute assumptions. When e ’s type depends on x, it cannot be pulled outside.

16 The problem When: –doing an inductive proof in Twelf –that involves a distinguished bound variable, –and the setting includes dependent types, You have a problem: –Cannot keep the designated bound variable last.

17 Explicit contexts Make the context into an explicit object that the proof can manipulate. –This allows us to place the variable of interest anywhere in the context. Proof technique only! –No change to LF or Twelf. No change to syntax! –Still using higher-order abstract syntax. Can convert from and to implicit contexts.

18 Methodology Syntax is still entirely higher-order. Give two versions of the semantics. –Implicit and explicit context. Convert derivations to use explicit contexts when necessary.

19 Contexts ctx : type. nil : ctx. cons : ctx -> exp -> tp -> ctx.

20 First cut: lookup lookup : ctx -> exp -> tp -> type. lookup/hit : lookup (cons G X A) X A. lookup/miss : lookup (cons G Y _) X A <- lookup G X A.

21 First cut: semantics ofe: ctx -> exp -> tp -> type. ofe/var : ofe G X A <- lookup G X A. ofe/closed : ofe G M A <- of M A.

22 First cut: semantics ofe/lam : ofe G (lam A ([x] M x)) (arrow A B) <- ({x:exp} ofe (cons G x A) (M x) B). ofe/app : ofe G (app M N) B <- ofe G M (arrow A B) <- ofe G N A.

23 Problem: bad contexts Contexts are merely association lists of terms and types. Syntax permits: –“Binding” of non-variables. –Multiple bindings of a single variable. Need a context formation judgement –Each term should be a distinct variable.

24 Context formation Distinguish variables using a hypothetical judgement. –Also assigns an ordering to variables. Context formation judgement: –Only variables may appear. –Variables must be ordered. (Hence, no duplicates.)

25 Variable ordering isvar : exp -> nat -> type. %{ Assumption " isvar X I " indicates: (1) X is a variable, and (2) x carries order stamp I. }% precedes : exp -> exp -> type. precedes/i : precedes X Y <- isvar X I <- isvar Y J <- lt I J.

26 Context formation bounded : ctx -> exp -> type. bounded/nil: bounded nil X <- isvar X _. bounded/cons: bounded (cons G Y _) X <- precedes Y X <- bounded G Y. ordered : ctx -> type. ordered/nil: ordered nil. ordered/cons: ordered (cons G X _) <- bounded G X.

27 Lookup Lemma: if lookup G X A then ordered G. lookup : ctx -> exp -> tp -> type. lookup/hit : lookup (cons G X A) X A <- bounded G X. lookup/miss : lookup (cons G Y _) X A <- bounded G Y <- lookup G X A.

28 Semantics ofe/closed : ofe G M A <- of M A <- ordered G. ofe/lam : ofe G (lam A ([x] M x)) (arrow A B) ofe (cons G x A) (M x) B).

29 Usage When combined, these theorems allow us to do proofs for the implicit system. –Convert to explicit form. –Perform the desired proof. –Convert back to implicit form.

30 Substitution theorem Before: –If  ⊢ M : A and , x:A ⊢ N : B then  ⊢ [M/x] N : B Now: –If   ⊢ M : A and  1, x:A,  2 ⊢ N : B then  1,  2 ⊢ [M/x] N : B

31 Substitution theorem in Twelf If ({x} append (cons G1 x A) G2 (G x)) and append G1 G2 G’ and ofe G1 M A and ({x} isvar x I -> ofe (G x) (N x) B) then ofe G’ (N M) B

32 Context Lemmas If lookup G X A then X is not a lambda or application. –That is, contexts bind only variables. If ({x} append (cons G1 x A) G2 (G x)) and ({x} isvar x I -> lookup (G x) x B) then tp-eq A B. –That is, contexts bind distinct variables.

33 Translation to implicit form If ofe nil M A then of M A Proof is not very hard.

34 Translation to explicit form If of M A then ofe nil M A Proof is tricky. –This is the enabling technical achievement.

35 Cut elimination Main lemma is a form of cut elimination. –Cut explicit-context “lookup” against implicit-context “of” assumption. –Prove simultaneously for cuts into of and ofe. If ({x} of x A -> of (M x) B) and ({x} isvar x I -> lookup (G x) x A) then ({x} isvar x I -> ofe (G x) (M x) B)

36 Conclusion General technique for proofs involving: –A distinguished bound variable –Dependent types Used in type safety proof for SML IL. –See Daniel Lee’s talk this afternoon. Not an extension to LF. Not a new representation technique: –Still use higher-order syntax and judgements.