AAA615: Formal Methods. Lecture 2 First-Order Logic

Similar documents
First-Order Logic (FOL)

CS156: The Calculus of Computation Zohar Manna Winter 2010

Predicate Logic: Sematics Part 1

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

Syntax. Notation Throughout, and when not otherwise said, we assume a vocabulary V = C F P.

Exercises 1 - Solutions

Overview. CS389L: Automated Logical Reasoning. Lecture 7: Validity Proofs and Properties of FOL. Motivation for semantic argument method

The Calculus of Computation: Decision Procedures with Applications to Verification. Part I: FOUNDATIONS. by Aaron Bradley Zohar Manna

Outline. Formale Methoden der Informatik First-Order Logic for Forgetters. Why PL1? Why PL1? Cont d. Motivation

Logic for Computer Scientists

Predicate Calculus - Syntax

CS156: The Calculus of Computation


Logic for Computer Scientists

First-Order Predicate Logic. Basics

Decision Procedures. Jochen Hoenicke. Software Engineering Albert-Ludwigs-University Freiburg. Winter Term 2015/16

First-Order Logic. Chapter Overview Syntax

Propositional Logic Language

02 Propositional Logic

First Order Logic (FOL) 1 znj/dm2017

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

Logic as a Tool Chapter 4: Deductive Reasoning in First-Order Logic 4.4 Prenex normal form. Skolemization. Clausal form.

Introduction to Sets and Logic (MATH 1190)

The predicate calculus is complete

Logic for Computer Scientists

Automated Reasoning Lecture 5: First-Order Logic

Comp487/587 - Boolean Formulas

Informal Statement Calculus

Predicate Logic. CSE 191, Class Note 02: Predicate Logic Computer Sci & Eng Dept SUNY Buffalo

CS156: The Calculus of Computation Zohar Manna Autumn 2008

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning.

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/26)

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 2: Propositional Logic

Introduction to first-order logic:

Logic Part I: Classical Logic and Its Semantics

Predicate Calculus. Formal Methods in Verification of Computer Systems Jeremy Johnson

Tecniche di Verifica. Introduction to Propositional Logic

03 Review of First-Order Logic

Logic: First Order Logic

First order Logic ( Predicate Logic) and Methods of Proof

Part 1: Propositional Logic

Formal Logic: Quantifiers, Predicates, and Validity. CS 130 Discrete Structures

All psychiatrists are doctors All doctors are college graduates All psychiatrists are college graduates

Predicate Calculus - Semantics 1/4

THE LANGUAGE OF FIRST-ORDER LOGIC (FOL) Sec2 Sec1(1-16)

1 Introduction to Predicate Resolution

Predicate Calculus lecture 1

Language of Propositional Logic

3 Propositional Logic

Notes. Corneliu Popeea. May 3, 2013

Herbrand Theorem, Equality, and Compactness

Motivation. CS389L: Automated Logical Reasoning. Lecture 10: Overview of First-Order Theories. Signature and Axioms of First-Order Theory

Transparencies to accompany Rosen, Discrete Mathematics and Its Applications Section 1.3. Section 1.3 Predicates and Quantifiers

Conjunction: p q is true if both p, q are true, and false if at least one of p, q is false. The truth table for conjunction is as follows.

Logic: First Order Logic (Part I)

Incomplete version for students of easllc2012 only. 6.6 The Model Existence Game 99

Classical Propositional Logic

First Order Logic (FOL)

Automated Reasoning in First-Order Logic

A brief introduction to Logic. (slides from

Computational Logic. Recall of First-Order Logic. Damiano Zanardini

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

2. Use quantifiers to express the associative law for multiplication of real numbers.

Deductive Systems. Lecture - 3

Advanced Topics in LP and FP

Part 1: Propositional Logic

Theory of Computation

A Little Logic. Propositional Logic. Satisfiability Problems. Solving Sudokus. First Order Logic. Logic Programming

Discrete Mathematics and Its Applications

7. Propositional Logic. Wolfram Burgard and Bernhard Nebel

3. Only sequences that were formed by using finitely many applications of rules 1 and 2, are propositional formulas.

Logic and Proofs. (A brief summary)

4 Predicate / First Order Logic

α-formulas β-formulas

First-Order Theorem Proving and Vampire. Laura Kovács (Chalmers University of Technology) Andrei Voronkov (The University of Manchester)

Predicate Calculus. Lila Kari. University of Waterloo. Predicate Calculus CS245, Logic and Computation 1 / 59

Predicate Logic - Semantic Tableau

Chapter 4: Classical Propositional Semantics

Propositional Logic: Models and Proofs

Lecture 13: Soundness, Completeness and Compactness

COMP9414: Artificial Intelligence First-Order Logic

Foundations of Artificial Intelligence

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Foundations of Artificial Intelligence

Chapter 11: Automated Proof Systems

Proseminar on Semantic Theory Fall 2013 Ling 720 First Order (Predicate) Logic: Syntax and Natural Deduction 1

ICS141: Discrete Mathematics for Computer Science I

Lecture 4: Proposition, Connectives and Truth Tables

Propositional and Predicate Logic - V

Computational Logic Automated Deduction Fundamentals

Computer-Aided Verification

Chapter 11: Automated Proof Systems (1)

Logic and Computation

Mat 243 Exam 1 Review

CHAPTER 10. Predicate Automated Proof Systems

Logic. Foundations of First Order Logic. franconi. Enrico Franconi

Propositional and Predicate Logic - II

Predicate Calculus - Semantic Tableau (2/2) Moonzoo Kim CS Division of EECS Dept. KAIST

Part 2: First-Order Logic

PREDICATE LOGIC. Schaum's outline chapter 4 Rosen chapter 1. September 11, ioc.pdf

Transcription:

AAA615: Formal Methods Lecture 2 First-Order Logic Hakjoo Oh 2017 Fall Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 1 / 29

First-Order Logic An extension of propositional logic with predicates, functions, and quantifiers. First-order logic is also called predicate logic, first-order predicate calculus, and relational logic. First-order logic is expressive enough to make it suitable for reasoning about programs. However, it does not admit completely automated reasoning. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 2 / 29

cf) First-Order Logic vs. Second-Order Logic In first-order logic, quantifications are allowed only for variables. In second-order logic, quantifers are allowed for sets, e.g., mathematical induction: P.((0 P i.(i P i + 1 P )) n.(n P )) In third-order logic, quantifiers for sets of sets. In higher-order logic, quantifiers are allowed over arbitrarily nested sets. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 3 / 29

Terms While formulas in PL evaluate to true or false, terms in FOL evaluate to values other than truth values such as integers, people, etc. Basic terms are variables (x, y, z,... ) and constants (a, b, c,... ). Composite terms include n-ary functions applied to n terms, i.e., f(t 1,..., t n ), where t i s are terms. A constant can be viewed as a 0-ary function. Examples: f(a), a unary function f applied to a constant g(x, b), a binary function g applied to a variable x and a constant b f(g(x, f(b))) Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 4 / 29

Predicates The propositional variables of PL are generalized to predicates in FOL, denoted p, q, r,.... An n-ary predicate takes n terms as arguments. A FOL propositional variable is a 0-ary predicate, denoted P, Q, R,.... Examples: P, a propositional variable (or 0-ary predicate) p(f(x), g(x, f(x))), a binary predicate applied to two terms Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 5 / 29

Syntax Atom: basic elements truth symbols ( false ) and ( true ) n-ary predicates applied to n terms Literal: an atom α or its negation α. Formula: a literal or the application of a logical connective (boolean connective) to formulas, or the application of a quantifier to a formula. F p(t 1,..., t n ) atom F negation ( not ) F 1 F 2 conjunction ( and ) F 1 F 2 disjunction ( or ) F 1 F 2 implication ( implies ) F 1 F 2 iff ( if and only if ) x.f [x] existential quantification x.f [x] universal quantification Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 6 / 29

Notations on Quantification In x.f [x] and x.f [x], x is the quantified variable and F [x] is the scope of the quantifier. We say x is bound in F [x]. x. y.f [x, y] is often abbreviated by x, y.f [x, y]. The scope of the quantified variable extends as far as possible: e.g., x.p(f(x), x) ( y.p(f(g(x, y)), g(x, y))) q(x, f(x)) A variable is free in F [x] if it is not bound. free(f ) and bound(f ) denote the free and bound variables of F, respectively. A formula F is closed if F has no free variables. E.g., x.p(f(x), y) y.p(f(x), y) If free(f ) = {x 1,..., x n }, then its universal closure is x 1... x n.f and its existential closure is x 1... x n.f. They are usually written.f and.f. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 7 / 29

Example FOL Formulas Every dog has its day. x.dog(x) y.day(y) itsday(x, y) Some dogs have more days than others. x, y.dog(x) dog(y) #days(x) > #days(y) The length of one side of a triangle is less than the sum of the lengths of the other two sides. x, y, z.triangle(x, y, z) length(x) < length(y)+length(z) Fermat s Last Theorem. n.integer(n) n > 2 x, y, z. integer(x) integer(y) integer(z) x > 0 y > 0 z > 0 x n + y n z n Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 8 / 29

Interpretation A FOL interpretation I : (D I, α I ) is a pair of a domain and an assignment. DI is a nonempty set of values such as integers, real numbers, dogs, people, etc. αi maps variables, constant, functions, and predicate symbols to elements, functions, and predicates over D I. each variable x is assigned a value from D I each n-ary function symbol f is assigned an n-ary function f I : DI n D I. each n-ary predicate symbol p is assigned an n-ary predicate p I : DI n {true, false}. Example: F : x + y > z y > z x Note +,, > are just symbols: p(f(x, y), z) p(y, g(z, x)). Domain: D I = Z = {..., 1, 0, 1,...} Assignment: α I = {+ + Z, Z, > > Z, x 13, y 42, z 1,...} Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 9 / 29

Semantics of First-Order Logic Given an interpretation I : (D I, α I ), I F or I F. I, I, I p(t 1,..., t n ) iff α I [p(t 1,..., t n )] = true I F iff I F I F 1 F 2 iff I F 1 and I F 2 I F 1 F 2 iff I F 1 or I F 2 I F 1 F 2 iff I F 1 or I F 2 I F 1 F 2 iff (I F 1 and I F 2 ) or (I F 1 and I F 2 ) I x.f iff for all v D I, I {x v} F I x.f iff there exists v D I, I {x v} F where J : I {x v} denotes an x-variant of I: D J = D I α J [y] = α I [y] for all constant, free variable, function, and predicate symbols y, except that α J (x) = v. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 10 / 29

Example F : x.f(x) = g(x) Consider the interpretation I : (D : {v 1, v 2 }, α I ): α I : {f(v 1 ) v 1, f(v 2 ) v 2, g(v 1 ) v 2, g(v 2 ) v 1 } Compute the truth value of F under I as follows: 1. I {x v} f(x) = g(x) for v D 2. I x.f(x) = g(x) since v D is arbitrary Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 11 / 29

Satisfiability and Validity A formula F is satisfiable iff there exists an interpretation I such that I F. A formula F is valid iff for all interpretations I, I F. Satisfiability and validity only apply to closed FOL formulas. If we say that a formula F such that free(f ) is valid, we mean that its universal closure.f is valid. If we say that F is satisfiable, we mean that its existential closure.f is satisfiable. Duality still holds:.f is valid. F is unsatisfiable. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 12 / 29

Extension of the Semantic Argument Method Most of the proof rules from PL carry over to FOL: I F I F I F G I F, I G I F G I F I G I F G I F I G I F G I F G I F G I F I F I F G I F I G I F G I F, I G I F G I F, I G I F G I F G I F G Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 13 / 29

Rules for Quantifiers Universal elimination I: Existential elimination I: Existential elimination II: Universal elimination II: I x.f I {x v} F for any v D I I x.f I {x v} F for any v D I I x.f I {x v} F for a fresh v D I I x.f I {x v} F for a fresh v D I Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 14 / 29

Contradiction Rule A contradiction exists if two variants of the original interpretation I disagree on the truth value of an n-ary predicate p for a given tuple of domain values: J : I p(s 1,..., s n ) K : I p(t 1,..., t n ) I for i {1,..., n}, α J [s i ] = α K [t i ] Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 15 / 29

Example 1 Prove that the formula is valid: F : ( x.p(x)) ( y.p(y)) Suppose not; there is an interpretation I such that I F. 1. I F assumption 2. I x.p(x) 1 and 3. I y.p(y) 1 and 4. I {y v} p(y) 3 and, for some v D I 5. I {x v} p(x) 2 and 6. I 4 and 5 Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 16 / 29

Example 2 Prove that the formula is valid: F : ( x.p(x)) ( x. p(x)) We need to show both of forward and backward directions. F 1 : ( x.p(x)) ( x. p(x)), F 2 : ( x.p(x)) ( x. p(x)) Suppose F 1 is not valid; there is an interpretation I such that I F 1. 1. I x.p(x) assumption 2. I x. p(x) assumption 3. I x. p(x) 2 and 4. I {x v} p(x) 3 and, for some v D I 5. I {x v} p(x) 1 and 6. I 4 and 5 Exercise) Prove that F 2 is valid. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 17 / 29

Example 3 Prove that the formula is invalid: F : ( x.p(x, x)) ( x. y.p(x, y)) It suffices to find an interpretation I such that I F. Choose D I = {0, 1} and p I = {(0, 0), (1, 1)}. The interpretation falsifies F. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 18 / 29

Soundness and Completeness of FOL A proof system is sound if every provable formula is valid. It is complete if every valid formula is provable. Theorem (Sound) If every branch of a semantic argument proof of I F closes, then F is valid. Theorem (Complete) Each valid formula F has a semantic argument proof. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 19 / 29

Substitution A substitution is a map from FOL formulas to FOL formulas: σ : {F 1 G 1,..., F n G n } To compute F σ, replace each occurrence of F i in F by G i simultaneously. For example, consider formula and substitution F : ( x.p(x, y)) q(f(y), x) σ : {x g(x), y f(x), q(f(y), x) x.h(x, y)} Then, F σ : ( x.p(g(x), f(x))) x.h(x, y) Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 20 / 29

Safe Substitution A restricted application of substitution, which has a useful semantic property. Idea: Before applying substitution, replace bound variables to fresh variables. For example, consider formula and substitution F : ( x.p(x, y)) q(f(y), x) σ : {x g(x), y f(x), q(f(y), x) x.h(x, y)} Then, safe substitution proceeds 1 Renaming: ( x.p(x, y)) q(f(y), x) 2 Substitution: ( x.p(x, f(x))) x.h(x, y) Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 21 / 29

Safe Substitution A FOL version of Substitution of Equivalent Formulas: Theorem Consider substitution σ : {F 1 G 1,..., G n G n } such that for each i, F i G i. Then F F σ when F σ is computed as a safe substitution. A FOL version of Valid Templates: Theorem If H is a valid formula schema and σ is a substitution obeying H s side conditions, then Hσ is also valid. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 22 / 29

Examples on Valid Templates Consider valid formula schema: H : ( x.f ) ( x. F ) The formula G : ( x. y.q(x, y) ( x. y.q(x, y)) is valid because G = Hσ for σ : {F y.q(x, y)}. Consider valid formula schema: H : ( x.f ) F provided x free(f ) The formula G : ( x. y.p(z, y)) y.p(z, y) is valid because G = Hσ for σ : {F y.p(z, y)}. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 23 / 29

Negation Normal Form A FOL formula F can be transformed into NNF by using the following equivalences: F 1 F 1 (F 1 F 2 ) F 1 F 2 (F 1 F 2 ) F 1 F 2 F 1 F 2 F 1 F 2 F 1 F 2 (F 1 F 2 ) (F 2 F 1 ) x.f [x] x. F [x] x.f [x] x. F [x] Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 24 / 29

Example Convert the formula into NNF: G : x.( y.p(x, y) p(x, z)) w.p(x, w) 1 Use the equivalence F 1 F 2 F 1 F 2 : x. ( y.p(x, y) p(x, z)) w.p(x, w) 2 Use the equivalence x.f [x] x. F [x]: x.( y. (p(x, y) p(x, z))) w.p(x, w) 3 Use De Morgan s Law: x.( y. p(x, y) p(x, z)) w.p(x, w) Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 25 / 29

Prenex Normal Form (PNF) A formula is in prenex normal form (PNF) if all of its quantifiers appear at the beginning of the formula: Q 1 x 1.... Q n x n.f [x 1,..., x n ] where Q i {, } and F is quantifier-free. Every FOL F has an equivalent PNF. To convert F into PNF, 1 Convert F into NNF: F 1 2 Rename quantified variables to unique names: F 2 3 Remove all quantifiers from F 2 : F 3 4 Add the quantifiers before F 3 : F 4 : Q 1 x 1.... Q n x n.f 3 where Q i are the quantifiers such that if Q j is in the scope of Q i in F 1, then i < j. A FOL formula is in CNF (DNF) if it is in PNF and its main quantifier-free subformula is in CNF (DNF). Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 26 / 29

Example F : x. ( y.p(x, y) p(x, z)) y.p(x, y) 1 Conversion to NNF: F 1 : x.( y. p(x, y) p(x, z)) y.p(x, y) 2 Rename quantified variables: F 2 : x.( y. p(x, y) p(x, z)) w.p(x, w) 3 Remove all quantifiers: F 3 : p(x, y) p(x, z) p(x, w) 4 Add the quantifiers before F 3 : F 4 : x. y. w. p(x, y) p(x, z) p(x, w) Note that x. w. y.f 3 is okay, but y. w. x.f 3 is not. Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 27 / 29

Additional Meta-Theorems Theorem (Compactness Theorem) A countable (possibly infinite) set of first-order formulas S is simultaneously satisfiable iff the conjunction of every finite subset is satisfiable. Theorem (Craig Interpolation Lemma) If F G is valid, then there exists a formula I (called interpolant) such that F I and I G are valid and whose predicates and free variables occur in both F and G. F : f(a) = b p(f(a)) G : (b = c) p(c) I : p(b) Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 28 / 29

Summary Syntax and semantics of first-order logic Satisfiability and validity Substitution, Normal forms Meta-theorems: soundness, completeness, Craig interpolation Hakjoo Oh AAA615 2017 Fall, Lecture 2 September 24, 2017 29 / 29