Engineering Aspects of Formal Metatheory

Slides:



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

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Some important properties Lectures of Prof. Doron Peled, Bar Ilan University.
Substitution & Evaluation Order cos 441 David Walker.
Chapter Three: Closure Properties for Regular Languages
Proofs and Programs Wei Hu 11/01/2007. Outline  Motivation  Theory  Lambda calculus  Curry-Howard Isomorphism  Dependent types  Practice  Coq Wei.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
March 4, 2005Susmit Sarkar 1 A Cost-Effective Foundational Certified Code System Susmit Sarkar Thesis Proposal.
Semantics Syntax Lunch: Strongly-typed term representations in Coq Andrew Kennedy Microsoft Research Cambridge TexPoint fonts used in EMF. Read the TexPoint.
Section 7.4: Closures of Relations Let R be a relation on a set A. We have talked about 6 properties that a relation on a set may or may not possess: reflexive,
VeriML: Revisiting the Foundations of Proof Assistants Zhong Shao Yale University MacQueen Fest May 13, 2012 (Joint work with Antonis Stampoulis)
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
Introduction to Computability Theory
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with 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.
POPLmark 1A in Cinic Evan Austin, Aaron Stump, and Edwin Westbrook 1.
Syntax With Binders COS 441 Princeton University Fall 2004.
Sparkle A theorem prover for the functional language Clean Maarten de Mol University of Nijmegen February 2002.
1 Explicit Contexts in LF Karl Crary Carnegie Mellon University Workshop on Mechanized Metatheory, 9/21/06.
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
A Locally Nameless Theory of Objects 1.Introduction:  -calculus and De Bruijn notation 2.locally nameless technique 3.formalization in Isabelle and proofs.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Type Safety Kangwon National University 임현승 Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
ASPfun: A Distributed Object Calculus and its Formalization in Isabelle Work realized in collaboration with Florian Kammüller and Henry Sudhof (Technische.
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 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
A Mechanized Model of the Theory of Objects 1.Functional  -calculus in Isabelle 2.Confluence Proof in Isabelle 3.Ongoing Work, Applications, Conclusion.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
June 21, Reasoning about explicit strictness in a lazy language using mixed lazy/strict semantics Marko van Eekelen Maarten de Mol Nijmegen University,
Higher-Order Encodings in Intensional Type Theory Edwin Westbrook Rice University.
Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.
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.
Advanced Science and Technology Letters Vol.41 (Mechanical Engineering 2013), pp Two Recent Approaches.
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.
1 Interactive Computer Theorem Proving CS294-9 September 7, 2006 Adam Chlipala UC Berkeley Lecture 3: Data structures and Induction.
A LISP interepreter for the Lambda Calculus Functional Programming
1 Parametric Higher-Order Abstract Syntax for Mechanized Semantics Adam Chlipala Harvard University ICFP 2008.
1 Representing and Reasoning on XML Documents: A Description Logic Approach D. Calvanese, G. D. Giacomo, M. Lenzerini Presented by Daisy Yutao Guo University.
Generic Programming and Proving for Programming Language Metatheory
Lecture 11: Proof by Reflection
CS 550 Programming Languages Jeremy Johnson
Introduction to Logic for Artificial Intelligence Lecture 2
Sparkle a functional theorem prover
Standard Representations of Regular Languages
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
PDAs Accept Context-Free Languages
A Verified Compiler for an Impure Functional Language
Corky Cartwright January 18, 2017
Proving Properties of Recursive List Functions
Typed Arithmetic Expressions
IS 2935: Developing Secure Systems
An overview of Coq Xinyu Feng USTC.
On Kripke’s Alleged Proof of Church-Turing Thesis
MA/CSSE 474 More Math Review Theory of Computation
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
L Calculus.
Department of Computer Science Abdul Wali Khan University Mardan
Formal Methods in software development
Formal Methods in software development
Propositional Logic CMSC 471 Chapter , 7.7 and Chuck Dyer
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Applications of Regular Closure
Relating Static and Dynamic Semantics
COMPILER CONSTRUCTION
An overview of Coq.
Presentation transcript:

Engineering Aspects of Formal Metatheory Stephanie Weirich joint work with Brian Aydemir, Arthur Chargueraud, and Benjamin Pierce

Why Mechanize PL Metatheory? Many ICFP and POPL papers accompanied by "write-only" technical reports. Difficult to develop and keep consistent From paper: "… we define the subtype relation as the greatest fixpoint of these subtype rules." From tech report: "Proof: by routine induction on the subtype derivation." Solution: replace tech report by machine-checked mathematics But how? Which prover? How to treat binding? 12/3/2018

How to compare systems Transparency Overhead Cost of entry How close are developments to informal conventions? How difficult to know what has been proved? Overhead How much additional work (operations/proof obligations) is necessary? Cost of entry Can non-experts read definitions and theorems? What help is available to get started? 12/3/2018

This work A Coq template for developing programming language metatheory A methodology for representing binding and specifying induction principles Compiles the best ideas of the past Includes our own novel contributions A library that supports this methodology reasoning about freshness representing environments Reference examples & supporting experience multiple calculi (STLC, F<:, CoC) multiple theorems (type soundness, confluence) All currently available online 12/3/2018

Basic datastructure Locally nameless representation Names for free variables de Bruijn indices for bound variables Example: Untyped lambda calculus Inductive exp : Set := | Lam : exp -> exp | App : exp -> exp -> exp | BVar : nat -> exp | FVar : atom -> exp. x. y. (x y) z represented as Lam (Lam (App (App (BVar 1) (BVar 0)) (FVar "z") 12/3/2018

Basic operations Two substitution functions Important special case [k -> u]t replace index k with u [x ~> u]t replace free variable x with u Important special case t ^ x replace index 0 with x Free variable calculation fv t finite set of free atoms in t 12/3/2018

Why locally nameless rep? Transparency: Alpha-equivalent terms have a unique representation Alternative: Pollute semantics or lemmas G |- e : t t = t' G |- e : t' If G |- e : t and e -> e' then G' |- e' : t' for some t' = t and G' = G. 12/3/2018

Why locally nameless rep? Allows name-based reasoning about environments Simple defs for operations, simple proofs about them de Bruijn indices: position-based reasoning Shifting of indices required Requires careful consideration of the environment at all times 12/3/2018

Issues with locally nameless rep Three important issues to resolve Local closure Not all exps are lambda calculus terms Induction principles How to make reasoning close to the "Barendregt Variable Convention" Function definitions How to define semantic functions with Coq functions and reason about them 12/3/2018

Local closure Not all members of type exp are lambda calculus terms Lam (BVar 3)? Predicate term : exp -> Prop Picks out members of type exp that are locally-closed Type { e | term e } Includes only lambda calculus terms Never actually use this type 12/3/2018

Treatment of local closure Definitions respect local closure If term u and term t, then term ([x ~> u]t) If t  t' then term t and term t' Many theorems need not refer to local closure If t  t' and t  t'', then t' = t''. Some theorems require it, tactics discharge assumptions [x ~> u](t ^ y) = ([x ~> u]t) ^ y when x  y, term u 12/3/2018

Local closure and Induction Inductive term : exp -> Prop := | t_var : x. term (FVar x) | t_app : t1 t2. term t1 -> term t2 -> term (App t1 t2) | t_lamE : x t1. x  fv t1 -> term (t1 ^ x) -> term (Lam t1) Can show t.term t -> P(t) when x. P(FVar x) t1 t2. P(t1) -> P(t2) -> P(App t1 t2) x t1. x  fv t1 -> P(t1 ^ x) -> P (Lam t1) [McKinna & Pollack 93] 12/3/2018

Weak principle In Lam case know that P holds for an arbitrary name not already free in t1. x t1. x  fv t1 -> P(t1 ^ x) -> P (Lam t1) Not strong enough for some proofs. 12/3/2018

Substitution Lemma In Lam case, WTP term [y ~> u](Lam t1) Lemma subst_term : t u y. term u -> term t -> term [y ~> u]t In Lam case, WTP term [y ~> u](Lam t1) IH in Lam case: for some x  fv t1 term [y ~> u](t1^x) By lemma term ([y ~> u]t1)^x By t_lamE term (Lam [y ~> u]t1) By def of subst term [y ~> u](Lam t1) Uh oh! Only holds if x  y 12/3/2018

A stronger induction principle Show t.term t -> P(t) when x. P(FVar x) t1 t2. P(t1) -> P(t2) -> P(App t1 t2) t1. (x. P(t1 ^ x)) -> P (Lam t1) IH applies to any x. Why is it sound? How to define it? 12/3/2018

Coq definition Change definition of local closure [MP 93] | t_lamA : t1. (x. term (t1 ^ x)) -> term (Lam t1) Soundness from equivalence of relations Lemma t_lamE : x t1. x  fv t1 -> term (t1 ^ x) -> term (Lam t1) Proof relies on swapping operation Definition swap:atom -> atom -> exp Lemma swap_term:t x y, term t -> term (swap x y t) 12/3/2018

Substitution lemma Lemma subst_term : t u y. term u -> term t -> term [y ~> u]t In Lam case, WTP term [y ~> u](Lam t1) IH in Lam case: x. term [y ~> u](t1 ^ x) Let x  {y}  fv u  fv t1 be arbitrary By lemma term ([y ~> u]t1) ^ x By t_lamE term (Lam [y ~>u]t1) By def of subst term [y ~>u](Lam t1) 12/3/2018

Swapping and Substitution Must we define and prove properties of both? interaction with opening terms [x ~> u](t ^ y) = ([x ~> u]t) ^ y when x  y, term u swap x z (t ^ y) = (swap x z t) ^ y when x,z  y interaction with free variables x  fv t -> [x ~> u]t = t x  fv t -> y  fv t -> swap x y t = t interaction with local closure term u -> term t -> term ([x ~> u] t) term t -> term (swap x y t) 12/3/2018

A not-so-strong IH New definition of local closure | t_lamC : t1 L. (x. x  L -> term (t1 ^ x)) -> term (Lam t1) Can prove substitution lemma directly. 12/3/2018

Substitution lemma Lemma subst_term : t u y. term u -> term t -> term [y ~> u]t In Lam case, WTP term [y ~> u](Lam t1) IH in Lam case: x. x  L -> term [y ~> u](t1 ^ x) Let x  {y}  L be arbitrary By lemma term ([y ~> u]t1) ^ x By t_lamC term (Lam [y ~> u]t1) By def of subst term [y ~> u](Lam t1) 12/3/2018

Soundness without swapping Use substitution to prove t_lamE without swapping. Lemma term_rename : t1 x y. x  fv t1 -> term (t1 ^ x) -> term (t1 ^ y). Lemma t_lamE : x t1. x  fv t1 -> term (t1 ^ x) -> term (Lam t1). 12/3/2018

General Form of Development Def. of syntax Def. of index substitution (t ^ x) Def. of local closure (term t) Def. of free variable substitution ([x ~> u]t) Def. of free variable function (fv t) Interaction lemmas Def. of semantic relations (t -> t', etc.) Show semantic relations respect local closure Substitution lemma for each relation w/ binding Show derived existential form of rules 12/3/2018

Conclusions Can use Coq's standard mechanisms for reasoning (inductive defs, tactics, etc.) Swapping does not appear to be essential. Seldom need to rename during proofs. IH applies to an infinite # of suitably fresh variables. Specialized tactics help local closure obligations fresh variable introduction 12/3/2018

Related work McKinna and Pollack 93 Gordon 94 Urban "Locally-named" representation Local closure def / structural induction Strong ind. principle using forall Gordon 94 Gives a "nominal" interface to a locally-nameless representation Urban Nominal Isabelle package Strengthened induction principle 12/3/2018

Mark your calendars! Using Proof Assistants for Programming Language Research or, How to write your next POPL paper in Coq SIGPLAN sponsored tutorial at POPL San Francisco, CA / January 8, 2008 12/3/2018