Twelf: The Quintessential Proof Assistant for Language Metatheory Karl Crary Carnegie Mellon University Joint work with Robert Harper and Michael Ashley-Rollman.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Substitution & Evaluation Order cos 441 David Walker.
Boyce/DiPrima 9th ed, Ch 2.8: The Existence and Uniqueness Theorem Elementary Differential Equations and Boundary Value Problems, 9th edition, by William.
Comparing Semantic and Syntactic Methods in Mechanized Proof Frameworks C.J. Bell, Robert Dockins, Aquinas Hobor, Andrew W. Appel, David Walker 1.
Certified Typechecking in Foundational Certified Code Systems Susmit Sarkar Carnegie Mellon University.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Foundational Certified Code in a Metalogical Framework Karl Crary and Susmit Sarkar Carnegie Mellon University.
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.
March 4, 2005Susmit Sarkar 1 A Cost-Effective Foundational Certified Code System Susmit Sarkar Thesis Proposal.
1 Dependent Types for Termination Verification Hongwei Xi University of Cincinnati.
Closure Properties of CFL's
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)
Foundations of Interaction ETAPS `05 0 Ex nihilo: a reflective higher- order process calculus The  -calculus L.G. Meredith 1 & Matthias Radestock.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Foundations of Programming Languages: Introduction to Lambda Calculus
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
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.
Slides 09 1 Counting the Inhabitants of a Type Given a type , how many closed -terms in  - normal form can receive the type  in TA ? There exists an.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap Overview  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
1 Explicit Contexts in LF Karl Crary Carnegie Mellon University Workshop on Mechanized Metatheory, 9/21/06.
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
Mechanized Metatheory for User- Defined Type Extensions Dan Marino, Brian Chin, Todd Millstein UCLA Gang Tan Boston College Robert J. Simmons, David Walker.
1 10. Joint Moments and Joint Characteristic Functions Following section 6, in this section we shall introduce various parameters to compactly represent.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
© 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.
Proof-Carrying Code & Proof-Carrying Authentication Stuart Pickard CSCI 297 June 2, 2005.
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.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
12/2/20151 GC16/3011 Functional Programming Lecture 2 The Lambda Calculus: A Simple Introduction.
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.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Process Algebra (2IF45) Basic Process Algebra Dr. Suzana Andova.
CSE-321 Programming Languages Abstract Machine E POSTECH May 1, 2006 박성우.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
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 4 (Part 3): Mathematical Reasoning, Induction & Recursion
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
CSE-321 Programming Languages Simply Typed -Calculus
A Verified Compiler for an Impure Functional Language
CS21b: Structure and Interpretation
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Typed Arithmetic Expressions
Engineering Aspects of Formal Metatheory
L Calculus.
Copyright © Cengage Learning. All rights reserved.
CSE S. Tanimoto Lambda Calculus
Presentation transcript:

Twelf: The Quintessential Proof Assistant for Language Metatheory Karl Crary Carnegie Mellon University Joint work with Robert Harper and Michael Ashley-Rollman Poplmark meeting, January 2006

2 Outline LF –Higher-order abstract syntax –Adequacy –Subordination Metatheory using LF Twelf implementation –Meta-proof checking

3 What do we want? Framework for encoding deductive systems adequately. The encoding should serve as a substitute for the original system for all (formalist) purposes.

4 What is LF? Primarily, a methodology for encoding deductive systems. Secondarily, the language that methodology employs. Specifically: –A technique for encoding object languages. –A rigorous account of adequacy. –A language that makes everything work.

5 Higher-order abstract syntax Identify OL and ML variables. Represent binding using abstractions. Represent substitution using application.

6 Example: simply-typed lambda calculus exp : type. lam : (exp -> exp) -> exp. app : exp -> exp -> exp. d x. y.x y e = lam( x.lam( y.app x y))

7 Example: simply-typed lambda calculus of : exp -> tp -> type. of_lam : of (lam E) (arrow T 1 T 2 ) Ã (  x:exp. of x T 1 ! of (E x) T 2 ) of_app : of (app E 1 E 2 ) T 2 Ã of E 1 (arrow T 1 T 2 ) Ã of E 2 T 1

8 Adequacy A correct encoding must establish an isomorphism between the OL and its encoding. For syntax: –Bijection between OL syntax and ML canonical forms of appropriate type. –The bijection should respect substitution (compositionality). Not concerned with cosmetic matters.

9 Canonical forms Beta-normal, eta-long. Theorem: every LF term has a unique canonical form.

10 LF Dependently typed lambda calculus. User-specified “signature” provides type- and term-level constants. Principal virtue is that it provides the right notion of canonical form. –No case analysis on user-specified types! –The “weakness” of LF is its strength.

11 Example: adequacy Define: – d { x 1,..., x n } e = x 1 : exp,..., x n : exp – d x.e e = lam ( x. d e e ) – d e 1 e 2 e = app d e 1 e d e 2 e Then d¢e defines an isomorphism between lambda terms (with free variables contained in X) and LF canonical forms C such that d X e ` C : exp.

12 Example: adequacy Define: – d x 1 :  1,...,x n :  n e = x 1 :exp, d 1 :of x 1 d  1 e,..., x n :exp, d n :of x n d  n e Then there exists a bijection between derivations of  ` e :  and LF canonical forms C such that d  e ` C : of d e e d  e.

13 Example: elims are bad Suppose we have elimination forms. Then consider: lam ( x.case x of app y z => y | lam f => x) This does not represent any lambda- calculus expression! Parametricity is essential: the body of the lambda must not analyze its argument.

14 Subordination Type family a is subordinate to type family b (written a ≤ b) if a canonical form of a can appear within a canonical form of b. Particularly interested in the negation. Useful for considering when extensions to the context are irrelevant.

15 Subordination example of ≤ exp –terms can appear in typing derivations, but not vice versa Adding assumptions with type of is irrelevant to syntactic considerations. For example, adequacy for syntax still holds with typing assumptions in play. /

16 Metatheory in LF, a simple case Theorem (type preservation) if ` e 1 :  and e 1  e 2 then ` e 2 :  Proof Suppose ` e 1 :  and e 1  e 2 By adequacy, there exists canonical d1 such that ` d 1 : of d e 1 e d  e By adequacy, there exists canonical d2 such that ` d 2 : step d e 1 e d e 2 e

17 Simple example, continued It follows (the real work happens here) that there exists canonical d 3 such that ` d 3 : of d e 2 e d  e By adequacy, we have ` e 2 : 

18 Metatheory in LF, with contexts Theorem (subject reduction) if  ` e 1 :  and e 1 ! e 2 then  ` e 2 :  Proof Suppose  ` e 1 :  and e 1 ! e 2 Let X = FV(e 1 ) By adequacy, there exists canonical d1 such that d  e ` d 1 : of d e 1 e d  e By adequacy, there exists canonical d2 such that d X e ` d 2 : reduce d e 1 e d e 2 e

19 Context example, continued By weakening, d  e ` d 2 : step d e 1 e d e 2 e It follows that there exists canonical d3 such that d  e ` d 3 : of d e 2 e d  e By adequacy, we have  ` e 2 : 

20 Metatheory in LF, general case Theorem (normalization) if  ` e 1 :  then e 1 normalizes to some e 2 Proof Suppose  ` e :  By adequacy, there exists canonical d 1 such that d  e ` d 1 : of d e 1 e d  e It follows that there exists canonical E 2, d 2 such that d  e ` d 2 : normalize d e 1 e E 2 By adequacy, E 2 = d e 2 e (for some e 2 )

21 General example, continued Thus, d  e ` d 2 : normalize d e 1 e d e 2 e Issue: normalize is untyped, so its adequacy uses X = FV(e 1 ), not  Since of ≤ normalize, typing assumptions cannot contribute to normalize derivations. Thus, d X e ` d 2 : normalize d e 1 e d e 2 e By adequacy, e 1 normalizes to e 2 /

22 Twelf Type checker for LF Proof search Meta-proof checker

23 Meta-proofs in Twelf Define a relation between derivations of interest: sr : reduce E1 E2 -> of E1 T -> of E2 T -> type.... Indicate inputs and outputs: %mode sr +D1 +D2 –D3.

24 Meta-proofs in Twelf, continued Specify world (set of contexts) by indicating permissible assumption blocks. %block bind : some {t:tp} block {x:exp} {d:of x t}. %worlds (bind) (sr _ _ _). Indicate an induction strategy.

25 Meta-proofs in Twelf, continued Twelf proves that sr is total: For all  2 W, For all canonical  ` E1, E2 : exp  ` T : tp  ` D1 : reduce E1 E2  ` D2 : of E1 T There exists canonical  ` D3 : of E2 T  ` D : sr D1 D2 D3. (Don’t care about this one)

26 Totality checking Type checking Mode checking Outputs are ground (well-specified) if inputs are ground. World checking Recursive calls preserve the world invariant. Termination Coverage checking All cases are covered.

27 How we use Twelf TALT: first foundational certified code system Definition of Standard ML Poplmark challenge (in a few days) Nearly everything we do