Refining Mechanized Metatheory: Subtyping for LF William Lovas (with Frank Pfenning)

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.
Types and Programming Languages Lecture 15 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Substitution & Evaluation Order cos 441 David Walker.
Static and User-Extensible Proof Checking Antonis StampoulisZhong Shao Yale University POPL 2012.
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
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.
March 4, 2005Susmit Sarkar 1 A Cost-Effective Foundational Certified Code System Susmit Sarkar Thesis Proposal.
Propositional Logic CMSC 471 Chapter , 7.7 and Chuck Dyer
VeriML: Revisiting the Foundations of Proof Assistants Zhong Shao Yale University MacQueen Fest May 13, 2012 (Joint work with Antonis Stampoulis)
Catriel Beeri Pls/Winter 2004/5 last 55 Two comments on let polymorphism I. What is the (time, space) complexity of type reconstruction? In practice –
CLF: A Concurrent Logical Framework David Walker Princeton (with I. Cervesato, F. Pfenning, K. Watkins)
1 Meta-Programming through Typeful Code Representation Chiyan Chen and Hongwei Xi Boston University.
A Concurrent Logical Framework (Joint work with Frank Pfenning, David Walker, and Kevin Watkins) Iliano Cervesato ITT Industries,
Twelf: The Quintessential Proof Assistant for Language Metatheory Karl Crary Carnegie Mellon University Joint work with Robert Harper and Michael Ashley-Rollman.
1 A Dependently Typed Assembly Language Hongwei Xi University of Cincinnati and Robert Harper Carnegie Mellon University.
Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper.
Syntax With Binders COS 441 Princeton University Fall 2004.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
MinML: an idealized programming language CS 510 David Walker.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
After today Week 9 –Tu: Pat Rondon –Th: Ravi/Nathan Week 10 –Tu: Nathan/Ravi –Th: Class canceled Finals week –Th: Zach, John.
1 Explicit Contexts in LF Karl Crary Carnegie Mellon University Workshop on Mechanized Metatheory, 9/21/06.
1 Type-Directed Concurrency Deepak Garg, Frank Pfenning {dg+, Carnegie Mellon University.
3-4 Algebra Properties Used in Geometry The properties of operations of real numbers that you used in arithmetic and algebra can be applied in geometry.
1.3 – AXIOMS FOR THE REAL NUMBERS. Goals  SWBAT apply basic properties of real numbers  SWBAT simplify algebraic expressions.
4.4 Linear Inequalities in Two Variables
Equational Reasoning Math Foundations of Computer Science.
VeriML DARPA CRASH Project Progress Report Antonis Stampoulis October 5 th, 2012 A language-based, dependently-typed, user-extensible approach to proof.
Intro to Discrete Structures
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
Proof Systems KB |- Q iff there is a sequence of wffs D1,..., Dn such that Dn is Q and for each Di in the sequence: a) either Di is in KB or b) Di can.
CSE 311 Foundations of Computing I Lecture 8 Proofs and Set Theory Spring
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.
Singleton Kinds and Singleton Types Christopher A. Stone August 2, 1999 Thesis Committee Bob Harper, chair Peter Lee John Reynolds Jon Riecke (Bell Laboratories)
Non-interference in Constructive Authorization Logic Deepak Garg and Frank Pfenning Carnegie Mellon University.
CSE 311 Foundations of Computing I Lecture 9 Proofs and Set Theory Autumn 2012 CSE
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.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Supercompilation and Normalisation by Evaluation Gavin Mendel-Gleason & Geoff Hamilton Dublin City University.
LDK R Logics for Data and Knowledge Representation Propositional Logic Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia,
CSE 311: Foundations of Computing Fall 2013 Lecture 8: Proofs and Set theory.
Key understandings in mathematics: synthesis of research Anne Watson NAMA 2009 Research with Terezinha Nunes and Peter Bryant for the Nuffield Foundation.
Set-theoretical models of untyped -calculus Motivation for models: Better intuition about the formal theory. Consistency results follow by soundness. Completeness.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CSE 311 Foundations of Computing I Lecture 8 Proofs Autumn 2012 CSE
Program Analysis and Verification
2.5 Reasoning in Algebra and Geometry Algebraic properties of equality are used in Geometry. –Will help you solve problems and justify each step. In Geometry,
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 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.
Lesson 10 Type Reconstruction
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
2.5 and 2.6 Properties of Equality and Congruence
Jared Davis The University of Texas at Austin April 6, 2006
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Typed Arithmetic Expressions
Engineering Aspects of Formal Metatheory
Logics for Data and Knowledge Representation
1.3 – AXIOMS FOR THE REAL NUMBERS
Presentation transcript:

Refining Mechanized Metatheory: Subtyping for LF William Lovas (with Frank Pfenning)

LFMTP '07 2 LF: a framework for defining logics (Harper, Honsell, and Plotkin, 1987, 1993) Dependently-typed lambda calculus Encode deductive systems and metatheory, in a machine-checkable way – e.g. a programming language and its type safety theorem Guiding principle: “judgements as types”

LFMTP '07 3 Judgements as types On paper: Syntax – e ::= … Judgement – Γ ⊢ e : τ Deduction – D :: Γ ⊢ e : τ Proof checking In LF: Simple type – exp : type. Type family – of : exp →  tp → type. Well-typed term – M : of E T Type checking

LFMTP '07 4 Inclusion as subtyping Some judgements have a natural notion of inclusion – all values are expressions – all odd natural numbers are positive More interesting types means more interesting judgements!

LFMTP '07 5 Example: natural numbers nat : type. z : nat. s : nat → nat. double : nat → nat → type. % plus rules even : nat → type. % plus some rules… odd : nat → type. % plus some rules… dbl-even : Π X :nat. Π Y :nat. % plus cases double X Y → even Y → type.

LFMTP '07 6 Example: nats using refinements nat : type. z : nat. s : nat → nat. double : nat → nat → type. % plus rules even : nat → type. % plus some rules… odd : nat → type. % plus some rules… dbl-even : Π X :nat. Π Y :nat. % plus cases double X Y → even Y → type. nat : type. even ≤ nat. odd ≤ nat. z : even. s : even → odd ∧ odd → even. double : nat → even → type. % plus rules metatheorem checking problem ⇝ typechecking problem!

LFMTP '07 7 Example: nats using refinements nat : type. even ≤ nat. odd ≤ nat. z : even. s : even → odd ∧ odd → even. double : nat → even → type. dbl-z : double z z. dbl-s : Π X :nat. Π Y :even. double X Y → double (s X ) (s (s Y )). dbl-s : Π X :nat. Π Y :even. double X Y → double (s X ) (s (s Y )).

LFMTP '07 8 Example: the lambda calculus exp : type. val : type. lam : (val → exp) → val. app : exp → exp → exp. $ : val → exp. lam (λ x. app ($ x ) ($ x )) : val Intrinsic values encoding: val ≤ exp. lam (λ x. app x x ) : val

LFMTP '07 9 Technology

LFMTP '07 10 Adequacy Does this really mean what I think it means? Strategy: exhibit a compositional bijection between mathematical objects and canonical forms following judgements as types. – “canonical forms” are β-normal and η-long.

LFMTP '07 11 Canonical forms method Represent only the canonical forms. – β-normal: syntactically – η-long: through typing – Hereditary substitutions contract redexes Simplifies metatheory, emphasizes adequacy Concurrent LF (Watkins, et al, 2003)

LFMTP '07 12 LF typing Bidirectional typing Synthesis: Γ ⊢ R ⇒ A – elims: R ::= x | c | R N Checking: Γ ⊢ N ⇐ A – intros: N ::= R | λ x. N

LFMTP '07 13 Checking Γ ⊢ R ⇒ P’ P’ = P Γ ⊢ R ⇐ P Γ ⊢ N ⇐ A Key rule: – base type, so atoms fully applied – the only appeal to type equality

LFMTP '07 14 Checking… with subtyping! Γ ⊢ R ⇒ P’ P’ ≤ P Γ ⊢ R ⇐ P Γ ⊢ N ⇐ A Easy to adapt! – just change equality to subtyping – subtyping… only at base type?

LFMTP '07 15 Intersections Kind of like pairs, but the terms don’t change Γ ⊢ N ⇐ A 1 Γ ⊢ N ⇐ A 2 Γ ⊢ N ⇐ A 1 ∧ A 2 Γ ⊢ N ⇐ ⊤ Γ ⊢ R ⇒ A 1 ∧ A 2 Γ ⊢ R ⇒ A 1 Γ ⊢ R ⇒ A 1 ∧ A 2 Γ ⊢ R ⇒ A 2

LFMTP '07 16 Metatheory

LFMTP '07 17 LF(R) as a logic Entailment should be reflexive: – A ⊢ A and transitive: – if A ⊢ B and B ⊢ C, then A ⊢ C

LFMTP '07 18 LF(R) as a logic Assume x is a proof of A. Is x a proof of A ? – not necessarily! x : A 1 → A 2 ⊬ x ⇐ A 1 → A 2 – have to η-expand: x : A 1 → A 2 ⊢ λ y. x y ⇐ A 1 → A 2

LFMTP '07 19 LF(R) as a logic Assume x is a proof of A. Can M ⇐ A stand in for x ? – if substitution is hereditary? [M/ x ] A N not obviously defined…

LFMTP '07 20 Important principles Substitution if Γ, x :A ⊢ N ⇐ B and Γ ⊢ M ⇐ A, then Γ ⊢ [M/ x ] A N ⇐ [M/ x ] A B. Identity for all A, Γ, x :A ⊢ η A ( x ) ⇐ A. “Substitution” morally a normalization proof

LFMTP '07 21 More about subtyping

LFMTP '07 22 Key rule: Bidirectional: subtyping only at mode switch Canonical: mode switch only at base type Subtyping Γ ⊢ R ⇒ P’ P’ ≤ P Γ ⊢ R ⇐ P Γ ⊢ N ⇐ A

LFMTP '07 23 Subtyping at higher types? What happened to the structural rules? E.g., Distributivity? A 2 ≤ A 1 B 1 ≤ B 2 A 1 → B 1 ≤ A 2 → B 2 (A → B 1 ) ∧ (A → B 2 ) ≤ A → (B 1 ∧ B 2 )

LFMTP '07 24 Subtyping at higher types! Intrinsic subtyping: if A ≤ B and Γ ⊢ N ⇐ A, then Γ ⊢ N ⇐ B. Equivalently: if A ≤ B then x :A ⊢ η A ( x ) ⇐ B. – Just like the Identity principle! – … also the Substitution principle… Usual rules are all sound in this sense.

LFMTP '07 25 Subtyping at higher types!? … and also complete! Theorem: if x :A ⊢ η A ( x ) ⇐ B then A ≤ B. Also: if Γ ⊢ N ⇐ A implies Γ ⊢ N ⇐ B, then A ≤ B. There are no new subtyping principles.

LFMTP '07 26 Future work Two directions: 1. Extend LFR with Twelf stuff type reconstruction unification proof search 2. Extend LFR with CLF stuff more type constructors subtyping with linearity?

LFMTP '07 27 Summary Refinement types are a useful addition to LF. Canonical forms method is up to the task. Concentrating only on canonical forms and bidirectional typing yields new insights into subtyping.

LFMTP '07 28 secret slides

LFMTP '07 29 Related work Refinement types – Tim Freeman, Rowan Davies, Joshua Dunfield Logical frameworks – Robert Harper, Furio Honsell, Gordon Plotkin – Frank Pfenning Subtyping and dependent types – David Aspinall, Adriana Compagnoni

LFMTP '07 30 LF syntax Terms Types R ::= c | x | R N N ::= R | λ x. N P ::= a | P N A, B ::= P | Π x :A.B atomic normal atomic normal no redexes

LFMTP '07 31 Hereditary substitution Substitution must contract redexes Example: Indexed by type subscript for termination Sometimes undefined: [(λ x. d x x ) / y ] y z = d z z [M/ x ] A N [(λ x. x x ) / y ] A y y fails by induction on A

LFMTP '07 32 Synthesis Γ ⊢ R ⇒ Π x :A.B Γ ⊢ N ⇐ A Γ ⊢ R N ⇒ [N/ x ] A B x :A ∈ Γ Γ ⊢ x ⇒ A c:A ∈ Σ Γ ⊢ c ⇒ A Γ ⊢ R ⇒ A hereditary substitution

LFMTP '07 33 Checking Γ ⊢ R ⇒ P’ P’ = P Γ ⊢ R ⇐ P Γ, x :A ⊢ N ⇐ B Γ ⊢ λ x.N ⇐ Π x :A.B Γ ⊢ N ⇐ A

LFMTP '07 34 Example: the lambda calculus exp : type. val ⊏ exp. lam : (exp → exp) → exp. app : exp → exp → exp. value : exp → type. lam : (val → exp) → val.

LFMTP '07 35 s ⊏ a :: L Γ ⊢ R ⇒ P’ P’ = P Γ ⊢ R ⇐ P Γ ⊢ R ⇒ P’ P’ ≤ P Γ ⊢ R ⇐ P

LFMTP '07 36 Subtyping Key rule: Bidirectional: subtyping only at mode switch Canonical: mode switch only at base type subtyping only at base type!

LFMTP '07 37 ⇐Γ, x:A ⊢ M ⇐ B ≤ e abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ Γ ⊢ R ⇒ A