Computer-Aided Verification

Similar documents
Logic and Computation

Propositional Logic: Models and Proofs

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

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

AAA615: Formal Methods. Lecture 2 First-Order Logic


α-formulas β-formulas

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

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

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

First Order Logic (FOL) 1 znj/dm2017

Propositional Logic Language

INF3170 / INF4171 Notes on Resolution

1 Introduction to Predicate Resolution

Propositional and Predicate Logic - II

Propositional Logic: Part II - Syntax & Proofs 0-0

Predicate Calculus. CS 270 Math Foundations of Computer Science Jeremy Johnson

Predicate Logic: Syntax

Tecniche di Verifica. Introduction to Propositional Logic

First Order Logic: Syntax and Semantics

First-Order Logic (FOL)

Propositional and Predicate Logic - V

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4

Exercises 1 - Solutions

Resolution for Predicate Logic

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

Predicate Logic: Sematics Part 1

Reasoning with Quantified Boolean Formulas

Predicate Logic - Introduction

Propositional logic (revision) & semantic entailment. p. 1/34

Mathematics 114L Spring 2018 D.A. Martin. Mathematical Logic

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

CS156: The Calculus of Computation Zohar Manna Winter 2010

Introduction to first-order logic:

06 From Propositional to Predicate Logic

Introduction to Logic in Computer Science: Autumn 2007

Syntax of FOL. Introduction to Logic in Computer Science: Autumn Tableaux for First-order Logic. Syntax of FOL (2)

Learning Goals of CS245 Logic and Computation

Automated Reasoning in First-Order Logic

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

Automated Reasoning Lecture 5: First-Order Logic

The Importance of Being Formal. Martin Henz. February 5, Propositional Logic

Computation and Logic Definitions

03 Review of First-Order Logic

Completeness in the Monadic Predicate Calculus. We have a system of eight rules of proof. Let's list them:

Knowledge representation DATA INFORMATION KNOWLEDGE WISDOM. Figure Relation ship between data, information knowledge and wisdom.

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

CS 730/830: Intro AI. 3 handouts: slides, asst 6, asst 7. Wheeler Ruml (UNH) Lecture 12, CS / 16. Reasoning.

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

Propositional logic. First order logic. Alexander Clark. Autumn 2014

1 First-order logic. 1 Syntax of first-order logic. 2 Semantics of first-order logic. 3 First-order logic queries. 2 First-order query evaluation

Logic Part I: Classical Logic and Its Semantics

COMP 409: Logic Homework 5

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

ECE473 Lecture 15: Propositional Logic

First-Order Logic. Chapter Overview Syntax

Warm-Up Problem. Is the following true or false? 1/35

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

Part 1: Propositional Logic

Logic: Propositional Logic (Part I)

Agenda. Artificial Intelligence. Reasoning in the Wumpus World. The Wumpus World

Herbrand Theorem, Equality, and Compactness

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

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

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

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

Introduction to Model Theory

A Logic Primer. Stavros Tripakis University of California, Berkeley

Deductive Systems. Lecture - 3

CHAPTER 10. Predicate Automated Proof Systems

Informal Statement Calculus

The predicate calculus is complete

CS156: The Calculus of Computation

Resolution for Predicate Logic

Propositional logic. Programming and Modal Logic

Chapter 3: Propositional Calculus: Deductive Systems. September 19, 2008

Advanced Topics in LP and FP

CS2742 midterm test 2 study sheet. Boolean circuits: Predicate logic:

Predicate Calculus - Syntax

Propositional Logic. Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

CS 730/730W/830: Intro AI

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.

02 Propositional Logic

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

Introduction to Metalogic

Computational Logic Automated Deduction Fundamentals

Logic for Computer Scientists

A brief introduction to Logic. (slides from

Inference in first-order logic

Introduction to Logic in Computer Science: Autumn 2006

Přednáška 12. Důkazové kalkuly Kalkul Hilbertova typu. 11/29/2006 Hilbertův kalkul 1

Comp487/587 - Boolean Formulas

CS 512, Spring 2017, Handout 10 Propositional Logic: Conjunctive Normal Forms, Disjunctive Normal Forms, Horn Formulas, and other special forms

Notes on Propositional and First-Order Logic (CPSC 229 Class Notes, January )

Resolution for mixed Post logic

Logic for Computer Scientists

Review of Predicate Logic

Example. Lemma. Proof Sketch. 1 let A be a formula that expresses that node t is reachable from s

Outline. Logic. Definition. Theorem (Gödel s Completeness Theorem) Summary of Previous Week. Undecidability. Unification

Logic: First Order Logic (Part I)

Transcription:

Computer-Aided Verification CS745/ECE745 Dr. Borzoo Bonakdarpour University of Waterloo (Fall 2013) Predicate Logic and Theorem Proving (Some Slides Adapted from Nancy Day s Lectures) Computer-Aided Verification p. 1/80

Agenda Predicate Logic Sytax and Semantics Extension of Sequent Calculus for FOL Resolution Definability and Compactness Computer-Aided Verification p. 2/80

First-order Logic Syntax and Semantics Computer-Aided Verification p. 3/80

Motivation There are some kinds of human reasoning that we cannot do in propositional logic. For example: Every person likes ice cream. Billy is a person. Therefore, Billy likes ice cream. In propositional logic, the best we can do is (A B) C, which is not a tautology. Computer-Aided Verification p. 4/80

Motivation We need to be able to refer to objects. We want to symbolize both a claim and the object about which the claim is made. We also need to refer to relations between objects, as in Waterloo is west of Toronto. If we can refer to objects, we also want to be able to capture the meaning of every and some of. The predicates and quantifiers of predicate logic allow us to capture these concepts. Computer-Aided Verification p. 5/80

Examples All grass is green. y Grass(y) Green(y) Something is rotten in the state of Denmark. x Rotten(x) Denmark(x) We can also have n-ary predicates. Example: Every even number is divisible by two. x Even(x) Div(x,2) The is pronounced such that. For the moment, we are not dealing with types. Computer-Aided Verification p. 6/80

Quantifiers Universal quantification corresponds to finite or infinite conjunction of the application of the predicate to all elements of the domain. Existential quantification corresponds to finite or infinite disjunction of the application of the predicate to all elements of the domain. Relationship between and : x P(x) is the same as x P(x) x P(x) is the same as x P(x) Computer-Aided Verification p. 7/80

Functions Consider how to formalize: Mary s father likes music One possible way: x Father(x, Mary) Likes(x, Music) which means: Mary has at least one father and he likes music. We d like to capture the idea that Mary only has one father. We use functions to capture a single object that can be in relation to another object. Example: Likes(father(Mary), Music) We can also have n-ary functions. Computer-Aided Verification p. 8/80

Predicate Logic: Syntax The syntax of predicate logic consists of: 1. constants 2. variables x,y, 3. functions 4. predicates 5. logical connectives 6. quantifiers (, ) 7. punctuation:, ( ) Computer-Aided Verification p. 9/80

Predicate Logic: Syntax Definition. Terms are defined as follows: 1. Every constant is a term. 2. Every variable is a term. 3. If t 1,t 2,t 3, t n are terms then f(t 1,t 2,t 3, t n ) is a term, where f is an n-ary function. 4. Nothing else is a term. Computer-Aided Verification p. 10/80

Predicate Logic: Syntax Definition. Well-formed formulas are defined as follows: 1. P(t 1,t 2,t 3, t n ) is a wff, where t i is a term, and P is an n-ary predicate. These are called atomic formulas. 2. If A and B are wffs, then so are ( A), (A B), (A B), (A B), and (A B). 3. If A is a wff, so is x A. 4. If A is a wff, so is x A. 5. Nothing else is a wff. We often omit the brackets using the same precedence rules as propositional logic for the logical connectives. Computer-Aided Verification p. 11/80

Scope and Binding of Variables Consider a parse tree for x (P(x) Q(x)) S(x, y): x S P Q x y x y Computer-Aided Verification p. 12/80

Scope and Binding of Variables Variables occur both in nodes next to quantifiers and as leaf nodes in the parse tree. A variable x is bound if starting at the leaf of x, we walk up the tree and run into a node with a quantifier and x. A variable x is free if starting at the leaf of x, we walk up the tree and do not run into a node with a quantifier and x. The scope of a variable x is the subtree starting at the node with the variable and its quantifier (where it is bound) minus any subtrees with x or x at their root. Example: x ( x (P(x) Q(x))) ( P(x) Q(y)) A wff is closed if it contains no free occurrences of any variable. Computer-Aided Verification p. 13/80

Substitution Variables are place holders. Given a variable x, a term t and a formula P, we define P[t/x] to be the formula obtained by replacing all free occurrences of variable x in P with t. We have to watch out for variable capture in substitution. Given a term t, a variable x and a formula A, we say that t is free for x in A if no free x leaf in A occurs in the scope of y or y for any free variable y occurring in t. Example: A is y P(x) Q(y) Whenever we use P[t/x], t and t is f(y) x must both be free for x in P. t is NOT free for x in A. Computer-Aided Verification p. 14/80

Predicate Logic: Semantics Recall that a semantics is a mapping between two worlds. A model for predicate logic consists of: 1. a non-empty domain of objects: D 2. a mapping I, called an interpretation that associates the terms of the syntax with objects in a domain It s important that D be non-empty, otherwise some tautologies would not hold such as ( x.a(x)) ( x.a(x)). Computer-Aided Verification p. 15/80

Interpretations An interpretation assigns: 1. a fixed element c D to each constant c of the syntax 2. an n-ary function f : D n D to each n-ary function, f, of the syntax 3. an n-ary relation R D n to each n-ary predicate, R, of the syntax Computer-Aided Verification p. 16/80

Example of a Model Let s say our syntax has the constant c, the function f (unary), and two predicates P, and Q (both binary). In our model, choose the domain to be the natural numbers. I(c) is 0 I(f) is suc, the successor function I(P) is < I(Q) is = Computer-Aided Verification p. 17/80

Example of a Model What is the meaning of P(c,f(c)) in this model? I(P(c,f(c))) = I(c) < I(f(c)) = 0 < suc(i(c)) = 0 < suc(0) = 0 < 1 which is true. Computer-Aided Verification p. 18/80

Valuations Definition. A valuation v, in an interpretation I, is a function from the terms to the domain D such that: 1. v(c) = I(c) 2. v(f(t1, t n )) = f(v(t 1, t n )) 3. v(x) D, i.e., each variable is mapped onto some element in D Computer-Aided Verification p. 19/80

Example of a Valuation D is the set of natural numbers g is the function + h is the function suc c (constant) is 3 y (variable) is 1 v(g(h(c),y)) = v(h(c))+v(y) = suc(v(c))+1 = suc(3)+1 = 5 Computer-Aided Verification p. 20/80

Predicate Logic: Satisfiability Given a model m, with domain D and interpretation I, and a valuation v, 1. If A is an atomic wff, P(t 1 t n ), m and v satisfy A iff P (v(t 1 ) v(t n )) 2. If A has form B, then m and v satisfy A iff m and v do not satisfy B. 3. If A has the form B C, then m and v satisfy A iff m and v satisfy B and m and v satisfy C, etc. for the other connectives. Computer-Aided Verification p. 21/80

Predicate Logic: Satisfiability 5. If A has the form x B, then m and v satisfy A iff v satisfies B for all elements of D, i.e., for all v(x) D. 6. If A has the form x B, then v satisfies A iff v satisfies B for some element of D, i.e., there is some v(x) D for which B is satisfied. Notice that if the formula is closed, then the valuation depends only on the model. Notational convenience: while we have defined valuations for terms only, we will extend the use of v to be for wff also, mapping relations to their counterparts on the domain, and the logical connectives as we did in Boolean valuations. Computer-Aided Verification p. 22/80

Validity (Tautologies) Definition. A predicate logic formula is satisfiable if there exists a model and there exists a valuation that satisfies the formula (i.e., in which the formula returns T). Definition. A predicate logic formula is logically valid (tautology) if it is true in every model. It must be satisfied by every valuation in every model. Definition. A wff, A, of predicate logic is a contradiction if it is false in every model. It must be false in every valuation in every model. Computer-Aided Verification p. 23/80

Semantic Entailment Semantic entailment has the same meaning as it did for propositional logic. φ 1,φ 2,φ 3 = ψ means that for all v if v(φ 1 ) = T and v(φ 2 ) = T, and v(φ 3 ) = T, then v(ψ) = T, which is equivalent to saying (φ 1 φ 2 φ 3 ) ψ is a tautology, i.e., φ 1,φ 2,φ 3 = ψ (φ 1 φ 2 φ 3 ) ψ Computer-Aided Verification p. 24/80

Closed Formulas Recall: A wff is closed if it contains no free occurrences of any variable. We will mostly restrict ourselves to closed formulas. For formulas with free variables, close the formula by universally quantifying over all its free variables. Computer-Aided Verification p. 25/80

Sat., Tautologies, Contradictions A closed predicate logic formula, is satisfiable if there is a model I in which the formula returns T. A closed predicate logic formula, A, is a tautology if it is T in every model. = A A closed predicate logic formula is a contradiction if it is F in every model. Question. What is the complexity of checking the satisfiability of a predicate logic formula?. Computer-Aided Verification p. 26/80

Counterexamples How can we show a formula is not a tautology? Provide a counterexample. A counterexample for a closed formula is a model in which the formula does not have the truth value T. Computer-Aided Verification p. 27/80

Sequent Calculus in FOL Computer-Aided Verification p. 28/80

Sequent Calculus Rules for FOL Rules for universal quantifier: Γ,F(a) Γ, x.f(x) Γ,F(a) Γ, x.f(x) Here, the variable a is free in F and F(x) is obtained from F(a) by replacing all free occurrences of a by x. Computer-Aided Verification p. 29/80

Sequent Calculus Rules for FOL Rules for existential quantifier: Γ,F(a) Γ, x.f(x) Γ,F(a) Γ, x.f(x) Here, the variable a is free in F and F(x) is obtained from F(a) by replacing all free occurrences of a by x. Computer-Aided Verification p. 30/80

Sequent Calculus Rules for FOL Example. Show that.a(x) x. A(x) Step1: A(a) A(a) Step2: A(a) x.a(x) Step3: x.a(x) A(a) Step4: x.a(x) x. A(x) Step4: x.a(x) x. A(x) Computer-Aided Verification p. 31/80

Proof by Resolution Computer-Aided Verification p. 32/80

Literals and Clauses A literal is a propositional variable or the negation of a propositional variable. Two literals are said to be complements (or conjugate), if one is the negation of the other (e.g., p and p) A formula of the form C i = p 1 p 2 p n, where each p i is a literal is called a clause. Computer-Aided Verification p. 33/80

CNF A formula in the conjunctive normal form (CNF) is a conjunction of clauses For example, these formulas are in CNF: (p q) ( q r m) (m n) p q It is possible to convert any formula into an equivalent formula in CNF. Computer-Aided Verification p. 34/80

CNF The CNF equivalent of the following formulas: (p q) r (p q) are these: (p r) (q r) p q Computer-Aided Verification p. 35/80

Resolution Rule p 1 p i...p n, q 1 q j...q m p 1 p i 1 p i+1...p n q 1 q j 1 q j+1 q m where p 1...p n,q 1...q m are propositions and p i and q j are complements. The clause produced by the resolution rule is called the resolvent of the two input clauses. The upper side of the rull is in CNF and may have multiple clauses. Computer-Aided Verification p. 36/80

Proof by Resolution The resolution rule can be used to develop a finite-step proof for propositional logic: 1- Transform the CNF formual into a set S of caulses. For example, for formula: we have: (p q r) ( r p m) q S = {{p,q,r},{ r, p,m},{q}} Computer-Aided Verification p. 37/80

Proof by Resolution 2- The resolution rule is applied to all possible pairs of clauses that contain complementary literals. After each application of the resolution rule, the resulting sentence is simplified by Removing repeated literals. If the sentence contains complementary literals, it is removed (as a validity). If not, and if it is not yet present in the clause set S, then it is added to S, and is considered for further resolution inferences. Computer-Aided Verification p. 38/80

Proof by Resolution Example: p q, p r q r This is equal to (different syntax): {p,q},{ p,r} {q,r} Computer-Aided Verification p. 39/80

Proof by Resolution Example (in directed acyclic graph): {p, q} {p, q} { p, q} {p} {q} 3- If the empty clause cannot be derived, and the resolution rule cannot be applied to derive any more new clauses, then the original formula is satisfiable. Computer-Aided Verification p. 40/80

Proof by Resolution 4- If after applying a resolution rule the empty clause is derived, the original formula is unsatisfiable (i.e., a contradiction). Example: {p,q} {p q} { p q} { p q} {p} {q} { p} {} Computer-Aided Verification p. 41/80

Example S = (p r) (r q) q (p t) s (t s) S = (p r) ( r q) q ( p t) s ( t s) S = {{p,r},{ r,q},{ q},{ p,t},{ s},{ t,s}} {p,r} {q, r} { p, t} {s, t} {p,q} { q} { s} { p, s} {p} { p} {} Computer-Aided Verification p. 42/80

Soundness and Completeness Resolution for propositional logic is sound and complete. Computer-Aided Verification p. 43/80

Prenex Normal Form A first-order formula is in prenex normal form (PNF), if it is written as a string of quantifiers followed by a quantifier-free part. Every first-order formula has an equivalent formula in PNF. For example, formula x(( ya(y)) (( zb(z)) C(x))) has the following PNF: x y z(a(y) (B(z) C(x))) Computer-Aided Verification p. 44/80

Conversion to PNF The rules for conjunction and disjunction say that ( xφ) ψ is equivalent to x(φ ψ) ( xφ) ψ is equivalent to x(φ ψ) and ( xφ) ψ is equivalent to x(φ ψ) ( xφ) ψ is equivalent to x(φ ψ) Computer-Aided Verification p. 45/80

Conversion to PNF The rules for negation say that xφ is equivalent to x φ and xφ is equivalent to x φ Computer-Aided Verification p. 46/80

Conversion to PNF The rules for removing quantifiers from the antecedent are: ( xφ) ψ is equivalent to x(φ ψ) ( xφ) ψ is equivalent to x(φ ψ) The rules for removing quantifiers from the consequent are: φ ( xψ) is equivalent to x(φ ψ) φ ( xψ) is equivalent to x(φ ψ) Computer-Aided Verification p. 47/80

Example Suppose that φ, ψ, and ρ are quantifier-free formulas and no two of these formulas share any free variable. The formula (φ xψ) zρ can be transformed into PNF as follows: ( x(φ ψ)) zρ x((φ ψ) zρ) x( z((φ ψ) ρ)) x z((φ ψ) ρ) Computer-Aided Verification p. 48/80

NNF A formula is in negation normal form if negation occurs only immediately above propositions, and {,, } are the only allowed Boolean connectives. It is possible to convert any first-order formula to an equivalent formula in NNF. For exmple: ( x.g) is x. G ( x.g) is x. G G is G (G 1 G 2 ) is ( G 1 ) ( G 2 ) (G 1 G 2 ) is ( G 1 ) ( G 2 ) Computer-Aided Verification p. 49/80

SNF: Skolemization Reduction to Skolem normal form is a method for removing existential quantifiers from first-order formulas A first-order formula is in SNF, if it is in conjunctive PNF with only universal first-order quantifiers. Important note: Skolemization only preserves satisfiability. Computer-Aided Verification p. 50/80

Skolemization Skolemization is performed by replacing every existentially quantified variable y with a term f(x 1,...,x n ) where function f does not occur anywhere else in the formula. If the formula is in PNF, x 1,...,x n are the variables that are universally quantified where quantifiers precede that of y. The function f is called a Skolem function. Computer-Aided Verification p. 51/80

In general, Skolemization x 1...x k y.ϕ(x 1...x k,y) is x 1...x k.ϕ(x 1...x k,f(x 1...x k )) For example, the formula x y z.p(x,y,z) is not in SNF. Skolemization results in x z.p(x,f(x),z) Computer-Aided Verification p. 52/80

Ground Clauses A sentence A is in clause form iff it is a conjunction of (prenex) sentences of the form x 1... x m.c, where C is a disjunction of literals, and the sets of bound variables {x 1,...,x m } are disjoint for any two distinct clauses. Each sentence x 1... x m.c is called a clause. If a clause in A has no quantifiers and does not contain any variables, we say that it is a ground clause. Computer-Aided Verification p. 53/80

Ground Clauses Lemma. For every sentence A, a sentence B in clause form such that A is valid iff B is unsatisfiable can be constructed. Computer-Aided Verification p. 54/80

Example Let A = y. z.(p(z,y) x.(p(z,x) P(x,z))). First, we negate A and eliminate : y. z.[( P(z,y) x.(p(z,x) P(x,z))) ( x.(p(z,x) P(x,z)) P(z,y))] Computer-Aided Verification p. 55/80

Example Next, we put in this formula in NNF: y. z.[( P(z,y) x.( P(z,x) P(x,z))) ( x.(p(z,x) P(x,z)) P(z,y))] Next, we Skolemize: z.[( P(z,a) x.( P(z,x) P(x,z))) ((P(z,f(z)) P(f(z),z)) P(z,a))] Computer-Aided Verification p. 56/80

Example We now put in prenex form: z. x.[( P(z,a) ( P(z,x) P(x,z))) ((P(z,f(z)) P(f(z),z)) P(z,a))] We put in CNF by distributing over : z. x.[( P(z,a) ( P(z,x) P(x,z))) (P(z,f(z)) P(z,a)) (P(f(z),z)) P(z,a))] Computer-Aided Verification p. 57/80

Example Omitting universal quantifiers, we have the following three clauses: C 1 = ( P(z 1,a) ( P(z 1,x) P(x,z 1 )) C 2 = (P(z 2,f(z 2 )) P(z 2,a)) C 3 = (P(f(z 3 ),z 3 )) P(z 3,a))] Computer-Aided Verification p. 58/80

Ground Resolution Suppose, we want to prove (for the previous example) that B = A is unsatisfiable. The ground resolution method is the resolution method applied to sets of ground clauses. Computer-Aided Verification p. 59/80

Ground Resolution For example, G 1 = ( P(a,a)) (from C 1, substituting a for x and z 1 ) G 2 = (P(a,f(a)) P(a,a)) (from C 2, substituting a for z 2 ) G 3 = (P(f(a),a)) P(a,a)) (from C 3, substituting a for z 3 ) G 4 = ( P(f(a),a) P(a,f(a))) (from C 1, substituting f(a) for z 1 and a for x) Computer-Aided Verification p. 60/80

Example G 2 G 1 G 3 G 4 {P(a,f(a))} {P(f(a),a)} { P(a,f(a))} {} Computer-Aided Verification p. 61/80

Unification To generalize ground resolution to arbitrary clauses, one is allowed to apply substitutions to the parent clauses. For example, to obtain {P(a,f(a))} from C 1 = ( P(z 1,a) P(z 1,x) P(x,z 1 )) and C 2 = (P(z 2,f(z 2 )) P(z 2,a)), first we substitute a for z 1, a for x, and a for z 2, obtaining G 1 = ( P(a,a)) and G 2 = (P(a,f(a)) P(a,a)) and then we resolve on the literal P(a,a). Computer-Aided Verification p. 62/80

Unification Note that the two sets of literals {P(z 1,a),P(z 1,x),P(x,z 1 )} and {P(z 2,a)} obtained by dropping the negation sign in C 1 have been unified by the substitution (a/x, a/z1, a/z2). Given two terms t and t that do not share any variables, a substitution θ is called a unifier iff θ(t) = θ(t ) Computer-Aided Verification p. 63/80

Example 1. Let t 1 = f(x,g(y)) and t 2 = f(g(u),g(z)). The substitution (g(u)/x,y/z) is a most general unifier yielding the most common instance f(g(u),g(y)). 2. However, t 1 = f(x,g(y)) and t 2 = f(g(u),h(z)) are not unifiable since this requires g = h. 3. Let t 1 = f(x,g(x),x) and t 2 = f(g(u),g(g(z)),z). To unify these two, we must have x = g(u) = z. But we also need g(x) = g(g(z)), that is, x = g(z). This implies z = g(z). Computer-Aided Verification p. 64/80

General Resolution 1. Find two clauses containing the same predicate, where it is negated in one clause but not in the other. 2. Perform a unification on the two predicates. (If the unification fails, you made a bad choice of predicates. Go back to the previous step and try again.) 3. If any unbound variables which were bound in the unified predicates also occur in other predicates in the two clauses, replace them with their bound values (terms) there as well. 4. Discard the unified predicates, and combine the remaining ones from the two clauses into a new Computer-Aided Verification p. 65/80 clause, also joined by the operator.

Example For clauses A = ( P(z,a) ( P(z,x) P(x,z)) B = (P(z,f(z)) P(z,a)) We choose subsets A = A and B = {P(z,a)} and and unifier (a/z,a/x), we obtain resolvent C = {P(a,f(a)} Computer-Aided Verification p. 66/80

Example C 1 = ( P(z 1,a) ( P(z 1,x) P(x,z 1 )) C 2 = (P(z 2,f(z 2 )) P(z 2,a)) C 3 = (P(f(z 3 ),z 3 )) P(z 3,a))] Computer-Aided Verification p. 67/80

Example C 2 C 1 C 3 {P(a,f(a))} (a/z 1,a/z 2,a/x) {P(f(a),a)} (a/z 1,a/z 3,a/x) {} { P(a,f(a))} (f(a)/z 1,a/x) Computer-Aided Verification p. 68/80

Definability and Compactness Computer-Aided Verification p. 69/80

Definability Let I = (D,(.) I ) be a first-order interpretation and ϕ a first-order formula. A set S of k-tuples over D, S D k, is defined by the formula ϕ if S = {(θ(x 1 ),...,θ(x k )) I,θ = ϕ} A set S is definable in first-order logic if it is defined by some first-order formula ϕ. Computer-Aided Verification p. 70/80

Definability Let Σ be a set of first-order sentences and K a set of interpretations. We say that Σ defines K if I K if and only if I = Σ. A set K is (strongly) definable if it is defined by a (finite) set of first-order formulas Σ. Computer-Aided Verification p. 71/80

Compactness in FOL Theorem. Let Σ be a set of first-order formulas. Σ is satisfiable iff every finite subset of Σ is satisfiable. Computer-Aided Verification p. 72/80

Graphs An undirected graph is a tuple (V,E), where V is a set of vertices and E is a set of edges. An edge is a pair (v 1,v 2 ), where v 1,v 2 V. v 1 v 2 v 3 v 4 v 5 V = {v 1,v 2,v 3,v 4,v 5 } E = {(v 1,v 2 ),(v 2,v 3 ),(v 2,v 4 ),(v 1,v 4 ),(v 1,v 5 )} Computer-Aided Verification p. 73/80

Graphs in FOL If (v 1,v 2 ) E, we say that v 1 is adjacent to v 2. Adjacency in a graph can be expressed by a binary relation. Thus, relation E(v 1,v 2 ) is interpreted as v 1 is adjacent to v 2 ". A graph is any model of the following 2 axioms: 1. x. y.e(x, y) E(y, x) ( if x is adjacent to y, then y is adjacent to x ) 2. x. E(x,x) ( no x is adjacent to itself ) Computer-Aided Verification p. 74/80

Graphs in FOL We can express many properties of a graph in the language of first-order logic. For instance, the property G contains a triangle is the following formula: x. y. z.(e(x,y) E(y,z) E(z,x)) Computer-Aided Verification p. 75/80

Example Define first-order formulas for : A graph has girth of size 4 A graph is 3-colorable Computer-Aided Verification p. 76/80

Graph Connectivity in FOL We cannot express graph connectivity in FOL (i.e., graph connectivity is not definable in FOL). Proof. Let predicate C express G is a connected graph". We add constants s and t vertices. For any k, let L k be the proposition there is no path of length k between s and t. For example, L 3 = x. y.(e(s,x) E(x,y) E(y,t)) Computer-Aided Verification p. 77/80

Graph Connectivity in FOL Now consider the set of propositions Σ = {axiom(1), axiom(2),c,l 1,L 2,...} Σ is finitely satisfiable: there do exist connected graphs with s and t, that are connected by an arbitrarily long path. This is because any finite subset F Σ must have bounded k s, such a graph satisifes F. Computer-Aided Verification p. 78/80

Graph Connectivity in FOL By the compactness theorem, Σ is satisfiable; i.e., there exists some model G of all propositions Σ, which is a graph that cannot be connected by a path of length k, for any k, for all k. This is clearly wrong. In a connected graph, any 2 nodes are connected by a path of finite length! Computer-Aided Verification p. 79/80

What does first-order mean? We can only quantify over variables. In higher-order logics, we can quantify over functions, and predicates. For example, in second-order logic, we can express the induction principle: P (P(0) ( n P(n) P(n+1))) ( n P(n)) Propositional logic can also be thought of as zero-order. Computer-Aided Verification p. 80/80