Logic and Proof Computer Science Tripos Part IB
Total Page:16
File Type:pdf, Size:1020Kb
Logic and Proof Computer Science Tripos Part IB Lawrence C Paulson Computer Laboratory University of Cambridge [email protected] Copyright c 2014 by Lawrence C. Paulson Contents 1 Introduction and Learning Guide 1 2 Propositional Logic 2 3 Proof Systems for Propositional Logic 5 4 First-order Logic 8 5 Formal Reasoning in First-Order Logic 11 6 Clause Methods for Propositional Logic 13 7 Skolem Functions, Herbrand’s Theorem and Unification 17 8 First-Order Resolution and Prolog 21 9 Decision Procedures and SMT Solvers 24 10 Binary Decision Diagrams 27 11 Modal Logics 28 12 Tableaux-Based Methods 30 i 1 INTRODUCTION AND LEARNING GUIDE 1 1 Introduction and Learning Guide 2008 Paper 3 Q6: BDDs, DPLL, sequent calculus • 2008 Paper 4 Q5: proving or disproving first-order formulas, This course gives a brief introduction to logic, including • resolution the resolution method of theorem-proving and its relation 2009 Paper 6 Q7: modal logic (Lect. 11) to the programming language Prolog. Formal logic is used • for specifying and verifying computer systems and (some- 2009 Paper 6 Q8: resolution, tableau calculi • times) for representing knowledge in Artificial Intelligence 2007 Paper 5 Q9: propositional methods, resolution, modal programs. • logic The course should help you to understand the Prolog 2007 Paper 6 Q9: proving or disproving first-order formulas language, and its treatment of logic should be helpful for • 2006 Paper 5 Q9: proof and disproof in FOL and modal logic understanding other theoretical courses. It also describes • 2006 Paper 6 Q9: BDDs, Herbrand models, resolution a variety of techniques and data structures used in auto- • mated theorem provers. Understanding the various deduc- (Lect. 6–8) tive methods is a crucial part of the course, but in addition 2005 Paper 5 Q9: resolution (Lect. 6, 8, 9) • to this purely mechanical view of logic, you should try to 2005 Paper 6 Q9: DPLL, BDDs, tableaux (Lect. 6, 10, 12) acquire an intuitive feel for logical reasoning. • 2004 Paper 5 Q9: semantics and proof in FOL (Lect. 4, 5) The most suitable course text is this book: • 2004 Paper 6 Q9: ten true or false questions Michael Huth and Mark Ryan, Logic in • Computer Science: Modelling and Reasoning 2003 Paper 5 Q9: BDDs; clause-based proof methods • (Lect. 6, 10) about Systems, 2nd edition (CUP, 2004) 2003 Paper 6 Q9: sequent calculus (Lect. 5) It covers most aspects of this course with the exception of • 2002 Paper 5 Q11: semantics of propositional and first-order resolution theorem proving. It includes material (symbolic • logic (Lect. 2, 4) model checking) that could be useful later. 2002 Paper 6 Q11: resolution; proof systems The following book may be a useful supplement to Huth • and Ryan. It covers resolution, as well as much else relevant 2001 Paper 5 Q11: satisfaction relation; logical equivalences • to Logic and Proof. 2001 Paper 6 Q11: clause-based proof methods; ordered • ternary Mordechai Ben-Ari, Mathematical Logic for decision diagrams (Lect. 6, 10) Computer Science, 2nd edition (Springer, 2001) 2000 Paper 5 Q11: tautology checking; propositional se- • quent calculus (Lect. 2, 3, 10) The following book provides a different perspective on 2000 Paper 6 Q11: unification and resolution (Lect. 8, 9) modal logic, and it develops propositional logic carefully. • Finally available in paperback. 1999 Paper 5 Q10: Prolog resolution versus general resolu- • tion Sally Popkorn, First Steps in Modal Logic (CUP, 1999 Paper 6 Q10: Herbrand models and clause form 2008) • 1998 Paper 5 Q10: BDDs, sequent calculus, etc. (Lect. 3, There are numerous exercises in these notes, and they are • 10) suitable for supervision purposes. Most old examination 1998 Paper 6 Q10: modal logic (Lect. 11); resolution questions for Foundations of Logic Programming (the for- • 1997 Paper 5 Q10: first-order logic (Lect. 4) mer name of this course) are still relevant. As of 2013/14, • Herbrand’s theorem has been somewhat deprecated, still 1997 Paper 6 Q10: sequent rules for quantifiers (Lect. 5) • mentioned but no longer in detail. Some unification the- 1996 Paper 5 Q10: sequent calculus (Lect. 3, 5, 10) ory has also been removed. These changes created space • 1996 Paper 6 Q10: DPLL versus Resolution (Lect. 9) for a new lecture on Decision Procedures and SMT Solvers. • 1995 Paper 5 Q9: BDDs (Lect. 10) 2014 Paper 5 Q5: proof methods for propositional logic: • • 1995 Paper 6 Q9: outline logics; sequent calculus (Lect. 3, BDDs and DPLL • 5, 11) 2014 Paper 6 Q6: decision procedure; resolution with selec- • 1994 Paper 5 Q9: resolution versus Prolog (Lect. 8) tion • 1994 Paper 6 Q9: Herbrand models (Lect. 7) 2013 Paper 5 Q5: DPLL, sequent or tableau calculus • • 1994 Paper 6 Q9: most general unifiers and resolution 2013 Paper 6 Q6: resolution problems • • (Lect. 9) 2012 Paper 5 Q5: (Herbrand: deprecated) • 1993 Paper 3 Q3: resolution and Prolog (Lect. 8) 2012 Paper 6 Q6: sequent or tableau calculus, modal logic, • • BDDs Acknowledgements. Chloë Brown, Jonathan Davies and 2011 Paper 5 Q5: resolution, linear resolution, BDDs • Reuben Thomas pointed out numerous errors in these notes. 2011 Paper 6 Q6: unification, modal logic • David Richerby and Ross Younger made detailed sugges- 2010 Paper 5 Q5: BDDs and models tions. Thanks also to Darren Foong, Thomas Forster, Si- • 2010 Paper 6 Q6: sequent or tableau calculus, DPLL. Note: mon Frankau, Adam Hall, Ximin Luo, Steve Payne, Tom • the formula in the first part of this question should be Puverle, Max Spencer, Ben Thorner, Tjark Weber and John . x P.x/ Q/ x .P.x/ Q/. Wickerson. 9 ! ! 8 ! 2 PROPOSITIONAL LOGIC 2 2 Propositional Logic the meaning of the propositional symbols it contains. The meaning can be calculated using the standard truth tables. Propositional logic deals with truth values and the logical connectives and, or, not, etc. Most of the concepts in propo- AB AA BA BA BA B : ^ _ ! $ sitional logic have counterparts in first-order logic. Here are 1 1 0 1 1 1 1 the most fundamental concepts. 1 0 0 0 1 0 0 0 1 1 0 1 1 0 Syntax refers to the formal notation for writing assertions. 0 0 1 0 0 1 1 It also refers to the data structures that represent asser- tions in a computer. At the level of syntax, 1 2 is a By inspecting the table, we can see that A B is equiv- ! string of three symbols, or a tree with a nodeC labelled alent to A B and that A B is equivalent to .A : _ $ ! + and having two children labelled 1 and 2. B/ .B A/. (The latter is also equivalent to .A B/, where^ !is exclusive-or.) : ⊕ Semantics expresses the meaning of a formula in terms of Note⊕ that we are using t and f in the language as symbols mathematical or real-world entities. While 1 2 and to denote the truth values 1 and 0. The former belongs to C 2 1 are syntactically distinct, they have the same se- syntax, the latter to semantics. When it comes to first-order C mantics, namely 3. The semantics of a logical state- logic, we shall spend some time on the distinction between ment will typically be true or false. symbols and their meanings. We now make some definitions that will be needed Proof theory concerns ways of proving statements, at least throughout the course. the true ones. Typically we begin with axioms and arrive at other true statements using inference rules. Definition 1 An interpretation, or truth assignment, for a Formal proofs are typically finite and mechanical: set of formulas is a function from its set of propositional their correctness can be checked without understand- symbols to 1; 0 . ing anything about the subject matter. An interpretationf g satisfies a formula if the formula eval- uates to 1 under the interpretation. Syntax can be represented in a computer. Proof methods A set S of formulas is valid (or a tautology) if every in- are syntactic, so they can be performed by computer. On terpretation for S satisfies every formula in S. the other hand, as semantics is concerned with meaning, it A set S of formulas is satisfiable (or consistent) if there is exists only inside people’s heads. This is analogous to the some interpretation for S that satisfies every formula in S. way computers handle digital photos: the computer has no A set S of formulas is unsatisfiable (or inconsistent) if it conception of what your photos mean to you, and internally is not satisfiable. they are nothing but bits. A set S of formulas entails A if every interpretation that satisfies all elements of S, also satisfies A. Write S A. jH 2.1 Syntax of propositional logic Formulas A and B are equivalent, A B, provided A B and B A. ' jH Take a set of propositional symbols P, Q, R, :::. A formula jH consisting of a propositional symbol is called atomic. We Some relationships hold among these primitives. Note use t and f to denote true and false. the following in particular: Formulas are constructed from atomic formulas using the S A if and only if A S is inconsistent. logical connectives1 • jH f: g [ If S is inconsistent, then S A for any A. This is an (not) • instance of the phenomenonjH that we can deduce any- : (and) thing from a contradiction. ^ (or) _ (implies) A if and only if A is valid, if and only if A is ! (if and only if) •inconsistent. jH f: g $ These are listed in order of precedence; is highest. We It is usual to write A B instead of A B. We may shall suppress needless parentheses, writing,: for example, similarly identify a one-elementjH set withf ag jHformula in the other definitions.