Recursion and Intro to Coq

Similar documents
A λ-calculus with Constants and Let-blocks

Beyond First-Order Logic

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications. Gerwin Klein Formal Methods

Proof assistants as a tool for thought

Problem Set 1 Solutions

CIS 500: Software Foundations

Gerwin Klein, June Andronick, Ramana Kumar S2/2016

Automating Interactive Theorem Proving with Coq and Ltac. by Oron Propp and Alex Sekula Mentored by Drew Haven PRIMES

Elementary Linear Algebra, Second Edition, by Spence, Insel, and Friedberg. ISBN Pearson Education, Inc., Upper Saddle River, NJ.

The Process of Mathematical Proof

Sec$on Summary. Mathematical Proofs Forms of Theorems Trivial & Vacuous Proofs Direct Proofs Indirect Proofs

An Introduction to Proof Assistants

The following techniques for methods of proofs are discussed in our text: - Vacuous proof - Trivial proof

Discrete Structures. Lecture Notes for CSE 191. Matthew G. Knepley

Semantics and Verification of Software

1. Propositional Calculus

Formal Logic and Deduction Systems

SEMANTICS OF INTUITIONISTIC PROPOSITIONAL LOGIC: HEYTING ALGEBRAS AND KRIPKE MODELS

15414/614 Optional Lecture 3: Predicate Logic

The Double Sum as an Iterated Integral

Formal Techniques for Software Engineering: Denotational Semantics

Your quiz in recitation on Tuesday will cover 3.1: Arguments and inference. Your also have an online quiz, covering 3.1, due by 11:59 p.m., Tuesday.

Handout: Proof of the completeness theorem

The Coq Proof Assistant

Proofs. Example of an axiom in this system: Given two distinct points, there is exactly one line that contains them.

Foundations of Mathematics MATH 220 FALL 2017 Lecture Notes

Logic Background (1A) Young W. Lim 5/14/18

Teaching Natural Deduction as a Subversive Activity

3 The language of proof

The Curry-Howard Isomorphism

2.7.1 Foundations of Proof Systems

Inductive types and identity types

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

Yet Another Proof of the Strong Equivalence Between Propositional Theories and Logic Programs

Discrete Mathematics

Program-ing in Coq. Matthieu Sozeau under the direction of Christine Paulin-Mohring

Lecture Notes on Heyting Arithmetic

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Spring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

Logic I - Session 10 Thursday, October 15,

Contribution of Problems

Solutions Manual. Selected odd-numbers problems from. Chapter 3. Proof: Introduction to Higher Mathematics. Seventh Edition

Continuity. Chapter 4

Intelligent Agents. First Order Logic. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University. last change: 19.

MAI0203 Lecture 7: Inference and Predicate Calculus

A Weak Post s Theorem and the Deduction Theorem Retold

Learning Goals of CS245 Logic and Computation

A Fixed Point Representation of References

Synchronous Reactive Systems

A New Look at Generalized Rewriting in Type Theory

4.4 Contracting Proofs to Programs

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

Natural deduction for propositional logic via truth tables

PSPACE-completeness of LTL/CTL model checking

COMP 182 Algorithmic Thinking. Proofs. Luay Nakhleh Computer Science Rice University

Typed Arithmetic Expressions

Lecture 5 : Proofs DRAFT

Introduction to Metalogic

Should We Teach Formal Methods at All?

Propositional Logic. CS 3234: Logic and Formal Systems. Martin Henz and Aquinas Hobor. August 26, Generated on Tuesday 31 August, 2010, 16:54

Verifying Self-stabilizing Population Protocols with Coq

Clause/Term Resolution and Learning in the Evaluation of Quantified Boolean Formulas

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley

Logic I - Session 22. Meta-theory for predicate logic

FORMAL METHODS LECTURE V: CTL MODEL CHECKING

COMP219: Artificial Intelligence. Lecture 19: Logic for KR

Review. Propositions, propositional operators, truth tables. Logical Equivalences. Tautologies & contradictions

Propositional Logic Review

Theory of Computation

Formal (natural) deduction in propositional logic

DR.RUPNATHJI( DR.RUPAK NATH )

COMP219: Artificial Intelligence. Lecture 19: Logic for KR

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Semantics and Verification of Software

Data Cleaning and Query Answering with Matching Dependencies and Matching Functions

CS422 - Programming Language Design

First-order resolution for CTL

Human-Readable Machine-Verifiable Proofs for Teaching Constructive Logic

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics

Writing proofs for MATH 61CM, 61DM Week 1: basic logic, proof by contradiction, proof by induction

cse 311: foundations of computing Fall 2015 Lecture 6: Predicate Logic, Logical Inference

Proofs of Mathema-cal Statements. A proof is a valid argument that establishes the truth of a statement.

Iris: Higher-Order Concurrent Separation Logic. Lecture 6: Case Study: foldr

SKETCHY NOTES FOR WEEKS 7 AND 8

Proving Inter-Program Properties

The Formal Proof Susan Gillmor and Samantha Rabinowicz Project for MA341: Appreciation of Number Theory Boston University Summer Term

The syntactic guard condition of Coq

Spring 2018 Exam 2 MARK BOX HAND IN PART NAME: PIN: INSTRUCTIONS

Mechanized Proof of Buchberger s Algorithm in ACL2

The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

CORES OF ALEXANDROFF SPACES

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination I (Spring 2008)

1. Propositional Calculus

Propositional Logic Arguments (5A) Young W. Lim 10/11/16

Partial model checking via abstract interpretation

Proofs: A General How To II. Rules of Inference. Rules of Inference Modus Ponens. Rules of Inference Addition. Rules of Inference Conjunction

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

Operational Semantics

Transcription:

L02-1 Recursion and Intro to Coq Armando Solar Lezama Computer Science and Artificial Intelligence Laboratory M.I.T. With content from Arvind and Adam Chlipala. Used with permission. September 21, 2015

L02-2 Recursion and Fixed Point Equations Recursive functions can be thought of as solutions of fixed point equations: fact = n. Cond (Zero? n) 1 (Mul n (fact (Sub n 1))) Suppose then H = f. n.cond (Zero? n) 1 (Mul n (f (Sub n 1))) fact = H fact fact is a fixed point of function H!

L02-3 Fixed Point Equations f : D D A fixed point equation has the form f(x) = x Its solutions are called the fixed points of f because if x p is a solution then x p = f(x p ) = f(f(x p )) = f(f(f(x p ))) =... We want to consider fixed-point equations whose solutions are functions, i.e., sets that contain their function spaces domain theory, Scottary,...

L02-4 An example Consider f n = if n=0 then 1 else (if n=1 then f 3 else f (n-2)) H = f. n.cond(n=0, 1, Cond(n=1, f 3, f (n-2)) Is there an f p such that f p = H f p? f1 n = 1 if n is even = otherwise f2 n = 1 if n is even = 5 otherwise f1 contains no arbitrary information and is said to be the least fixed point (lfp) Under the assumption of monotonicity and continuity least fixed points are unique and computable

L02-5 Computing a Fixed Point Recursion requires repeated application of a function Self application allows us to recreate the original term Consider: W = ( x. x x) ( x. x x) Notice b-reduction of W leaves W : W W Now to get F (F (F (F...))) we insert F in W: W F = ( x.f (x x)) ( x.f (x x)) which b-reduces to: W F F( x. F(x x))( x. F(x x)) F W F F(F W F ) F(F(F W F ))... Now -abstract F to get a Fix-Point Combinator: Y f.( x. (f (x x))) ( x.(f (x x)))

L02-6 Y : A Fixed Point Operator Y f.( x. (f (x x))) ( x.(f (x x))) Notice Y F ( x.f (x x)) ( x.f (x x)) F ( x.f (x x)) ( x.f (x x)) F (Y F) F (Y F) = Y F (Y F) is a fixed point of F Y computes the least fixed point of any function! There are many different fixed point operators.

L02-7 Mutual Recursion odd n = if n==0 then False else even (n-1) even n = if n==0 then True else odd (n-1) odd = H 1 even even = H 2 odd where H 1 = f. n.cond(n=0, False, f(n-1)) H 2 = f. n.cond(n=0, True, f(n-1)) substituting H 2 odd for even odd = H 1 (H 2 odd) = H odd where H = odd = Y H Can we express odd using Y? f. H 1 (H 2 f)

L02-8 Self-application and Paradoxes Self application, i.e., (x x) is dangerous. Suppose: u y. if (y y) = a then b else a What is (u u)? (u u) if (u u) = a then b else a Contradiction!!! Any semantics of -calculus has to make sure that functions such as u have the meaning, i.e. totally undefined or no information. Self application also violates every type discipline.

L02-9 Intro to Coq

Warning I am not a Coq Expert So if I can do it, you can do it too! September 21, 2015 L02-10

Formal Reasoning About Programs New course Prof. Adam Chlipala will teach next semester An introduction to a spectrum of techniques for rigorous mathematical reasoning about correctness of software, emphasizing commonalities across approaches. Taught around a formalization of all the different correctness approaches with the Coq proof assistant Will go into depth into different program logics, different approaches to formalize concurrency, behavioral refinement of interacting modules, etc. September 21, 2015 L02-11

Some useful references The reference manual isn't bad: http://coq.inria.fr/distrib/current/refman/ Prof. Chlipala s book Certified Programming with Dependent Types A draft is available online (http://adam.chlipala.net/cpdt/) most of what it covers goes beyond the scope of 6.820. Another popular book: Bertot & Casteran, Interactive Theorem Proving and Program Development (Coq'Art) https://www.labri.fr/perso/casteran/coqart/ A popular online book that uses Coq to introduce ideas in semantics: Software Foundations by Pierce et al. http://www.cis.upenn.edu/~bcpierce/sf/ September 21, 2015 L02-12

L02-13 Key ideas Introduce Definitions and theorems Prove them by applying simple deductive steps called tactics Example: Defining Natural numbers Inductive nat := O S (n : nat). Fixpoint plus (n m : nat) : nat := match n with O => m S n' => S (plus n' m) end. Just a familiar ADT and Recursive Function Definition

Proving theorems with tactics Basic syntax to introduce lemmas and theorems Lemma O_plus : forall n, plus O n = n. Proof. (* Sequence of tactics *) Qed. Lemma and Theorem are interchangeable (You can also say Remark, Corollary, Fact or Proposition) September 21, 2015 L02-14

Tactics They instruct Coq on the steps to take to prove a theorem reflexivity prove an equality goal that follows by normalizing terms. induction x prove goal by induction on quantified variable [x] Structural Induction: X is any recursively defined structure All variables appearing _before_ [x] will remain _fixed_ throughout the induction! September 21, 2015 L02-15

More tactics simpl apply standard heuristics for computational simplification in conclusion. Often it will involve doing some β reduction rewrite H use (potentially quantified) equality [H] to rewrite in the conclusion. intros move quantified variables and/or hypotheses "above the double line. apply thm apply a named theorem, reducing the goal into one new subgoal for each of the theorem's hypotheses, if any. September 21, 2015 L02-16

And a few more assumption Prove a conclusion that matches a known hypothesis. destruct E Do case analysis on the constructor used to build term [E]. September 21, 2015 L02-17

MIT OpenCourseWare http://ocw.mit.edu 6.820 Fundamentals of Program Analysis Fall 2015 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.