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

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

06 From Propositional to Predicate Logic

15414/614 Optional Lecture 3: Predicate Logic

Classical First-Order Logic

Predicate Logic. Bow-Yaw Wang. Institute of Information Science Academia Sinica, Taiwan. November 22, 2017

GS03/4023: Validation and Verification Predicate Logic Jonathan P. Bowen Anthony Hall

Learning Goals of CS245 Logic and Computation

Classical First-Order Logic

Natural Deduction. Formal Methods in Verification of Computer Systems Jeremy Johnson

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

Predicate Logic: Sematics Part 1

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

PREDICATE LOGIC: UNDECIDABILITY AND INCOMPLETENESS HUTH AND RYAN 2.5, SUPPLEMENTARY NOTES 2

Introduction to Sets and Logic (MATH 1190)

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

Predicate Logic - Introduction

First Order Logic: Syntax and Semantics

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

Comp487/587 - Boolean Formulas


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

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

03 Review of First-Order Logic

Natural Deduction for Propositional Logic

PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2

Automated Reasoning Lecture 5: First-Order Logic

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

Propositional Logic Not Enough

Introduction to first-order logic:

Predicate Logic: Syntax

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

Predicate Calculus - Syntax

AAA615: Formal Methods. Lecture 2 First-Order Logic

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

ICS141: Discrete Mathematics for Computer Science I

Predicate Calculus - Semantics 1/4

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

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

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

Predicate Logic: Introduction and Translations

First-Order Logic. Chapter Overview Syntax

Predicate Logic & Quantification

Math Fundamentals of Higher Math

Propositional Logic: Deductive Proof & Natural Deduction Part 1

First-Order Predicate Logic. First-Order Logic 153/467

Mathematical Logic. Reasoning in First Order Logic. Chiara Ghidini. FBK-IRST, Trento, Italy

CS720 Class Notes. Steve Revilak

Predicate Logic. Andreas Klappenecker

Predicate Calculus lecture 1

Logic: Propositional Logic Truth Tables

Part I: Propositional Calculus

The predicate calculus is complete

Discrete Mathematics and Its Applications

03 Propositional Logic II

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

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

Lecture 10: Predicate Logic and Its Language

First Order Logic (FOL) 1 znj/dm2017

First order Logic ( Predicate Logic) and Methods of Proof

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

A Logic Primer. Stavros Tripakis University of California, Berkeley

Section Summary. Section 1.5 9/9/2014

CSE 1400 Applied Discrete Mathematics Definitions

Introduction to Logic in Computer Science: Autumn 2006

Propositional and Predicate Logic. jean/gbooks/logic.html

Propositional Logic Language

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

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

Description Logics. Deduction in Propositional Logic. franconi. Enrico Franconi

2/2/2018. CS 103 Discrete Structures. Chapter 1. Propositional Logic. Chapter 1.1. Propositional Logic

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

CHAPTER 2. FIRST ORDER LOGIC

A Logic Primer. Stavros Tripakis University of California, Berkeley. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 1 / 35

Predicate Logic. CSE 595 Semantic Web Instructor: Dr. Paul Fodor Stony Brook University

185.A09 Advanced Mathematical Logic

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

Logic Part II: Intuitionistic Logic and Natural Deduction

02 Propositional Logic

Predicates and Quantifiers. Nested Quantifiers Discrete Mathematic. Chapter 1: Logic and Proof

3. The Logic of Quantified Statements Summary. Aaron Tan August 2017

First-Order Logic (FOL)

Propositional logic. Programming and Modal Logic

A brief introduction to Logic. (slides from

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

Packet #2: Set Theory & Predicate Calculus. Applied Discrete Mathematics

Logic: Propositional Logic (Part I)

Modal Logic. UIT2206: The Importance of Being Formal. Martin Henz. March 19, 2014

Description Logics. Foundations of Propositional Logic. franconi. Enrico Franconi

22c:145 Artificial Intelligence. First-Order Logic. Readings: Chapter 8 of Russell & Norvig.

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

Logic Overview, I. and T T T T F F F T F F F F

COMP219: Artificial Intelligence. Lecture 19: Logic for KR

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

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

First-order resolution for CTL

Informal Statement Calculus

CS156: The Calculus of Computation Zohar Manna Winter 2010

Logic for Computer Scientists

Logic for Computer Scientists

Computer-Aided Verification

Transcription:

Predicate Calculus Formal Methods in Verification of Computer Systems Jeremy Johnson

Outline 1. Motivation 1. Variables, quantifiers and predicates 2. Syntax 1. Terms and formulas 2. Quantifiers, scope and substitution 3. Rules of natural deduction for quantifiers 4. Semantics 1. Models and semantic entailment 5. Undecidability and limitations

Example 1 Every student is younger than some instructor x ( S(x) y(i(y) Y(x,y) ) S(x) : x is a student I(x) : is an instructor Y(x,y) : x is younger than y

Example 2 Not all birds can fly x ( B(x) F(x) ) x ( (B(x) F(x) ) B(x) : x is a bird F(x) : x can fly Semantically equivalent formulas

Example 3 Every child is younger than its mother x y ( C(x) M(y,x) Y(x,y) ) C(x) : x is child M(x,y) : x is y s mother Y(x,y) : x is younger than y x ( C(x) Y(x,m(x)) m(x) : function for mother of x

Example 4 Andy and Paul have the same maternal grandmother x y u v ( M(x,y) M(y,a) M(u,v) M(v,p) x = u ) m(m(a)) = m(m(p)) a, b : variables for Andy and Paul = : binary predicate

Example 5 Everyone has a mother x y ( M(y,x) ) x y ( M(y,x) ) [ not equivalent ] Everyone has exactly one mother x y ( M(y,x) z (M(z,x) z = y )

Example 6 Some people have more than one brother x y1 y2 ( B(y1,x) B(y2,x) (y1 = y2) )

Comparison to Propositional Calculus Proof calculus for predicate calculus φ 1,,φ n ψ [ extend natural deduction ] Provide semantics for predicate calculus φ 1,,φ n ψ [ models needed to evaluate functions and predicates may not be finite ] Soundness and Completeness φ 1,,φ n ψ holds iff φ 1,,φ n ψ is valid Undecidable No program exists that can always determine if φ holds

Terms Terms are made up of variables, constants, and functions Term ::= Variable If c is a nullary function c is a term If t 1,,t n are terms and f is an n-ary function then f(t 1,,t n ) is a term

Formulas Formula ::= P is a predicate and t 1,,t n are terms then P(t 1,,t n ) is a formula If ϕ is a formula ϕ is a formula If ϕ 1 and ϕ 2 are formulas, ϕ 1 ϕ 2, ϕ 1 ϕ 2, ϕ 1 ϕ 2 are formulas If ϕ is a formula and x is a variable x ϕ and x ϕ are formulas

Parse Trees x ( ( P(x) Q(x) ) S(x,y) ) x S P Q x y x x

Free and Bound Variables An occurrence of x in ϕ is free if it is a leaf node in the parse tree for ϕ with no quantifier as an ancestor x x S Q P Q x y P Q P y x x x x x

Substitution Given a variable x, a term t and a formula ϕ, ϕ[t/x] is the formula obtained by replacing each free occurrence of x by t x ϕ[f(x,y)/x] x Q Q P Q P y P Q P y x x x x x f x y

Variable Capture t is free for x in ϕ if no free x occurs in ϕ in the scope of any quantifier for any variable y occurring in t. S x P y Q x y

Variable Capture t is free for x in ϕ if no free x occurs in ϕ in the scope of any quantifier for any variable y occurring in t. S x P y Q f y y y

Equality Rules Introduction Rule t = t = i Elimination Rule t 1 = t 2 φ[t 1 /x] φ[t 2 /x] =e

Equivalence Relation Symmetry: t 1 = t 2 t 2 = t 1 1 t 1 = t 2 premise 2 t 1 = t 1 =i 3 t 2 = t 1 =e 1,2 Transitivity: t 1 = t 2, t 2 = t 3 t 1 = t 3 1 t 1 = t 2 premise 2 t 2 = t 3 premise 3 t 1 = t 3 =e 2,1

Conjunction Rules Introduction Rule φ ψ φ ψ i Elimination Rule φ ψ φ e1 φ ψ ψ e2

Universal Quantification Rules Introduction Rule x 0 φ[x 0 /x] x φ x i Elimination Rule x φ x e φ[t/x]

Illegal Substitution Leads to False Reasoning x ϕ ϕ = y (x < y) ϕ[y/x] = y (y < y) y is not free for x in ϕ

Example Proof x P x Q x, xp(x) xq(x) 1 x P x Q x, premise 2 xx(x) premise 3 x 0 P(x 0 ) Q(x 0 ) x e1 4 P(x 0 ) x e2 5 Q(x 0 ) e3,4 6 x Q(x) x ii 5

Disjunction Rules Introduction Rule φ φ ψ i1 ψ φ ψ i2 Elimination Rule (proof by case analysis) φ ψ φ χ χ ψ χ e

Existential Quantification Rules Introduction Rule φ[t/x] x φ x i Elimination Rule (proof by case analysis) x φ x 0 φ[x 0 /x] χ χ e

Example Proof x Q x R x, x(p x Q(x)) x(p x R(x)) 1 x Q x R x, premise 2 x(p x Q(x)) premise 3 x 0 P(x 0 ) Q(x 0 ) assumption 4 Q x 0 R x 0 x e1 5 Q(x 0 ) e 2 3 6 R x 0 e 4,5 7 P(x 0 ) e 1 3 8 P(x 0 ) R(x 0 ) i7,6 9 x(p x R(x)) xi 8 10 x(p x R(x)) xe 2,3-9

Quantifier Equivalences 1. x ϕ x ϕ 2. x ϕ x ϕ 3. x ϕ ψ x (ϕ ψ) [x not free in ψ] 4. x ϕ ψ x (ϕ ψ) 5. x ϕ ψ x (ϕ ψ) 6. x ϕ ψ x (ϕ ψ) 7. x (ψ ϕ) ψ x ϕ 8. x (ϕ ψ) x ϕ ψ 9. x (ϕ ψ) x ϕ ψ 10. x (ψ ϕ) ψ x ϕ

Quantifier Equivalences 1. x ϕ x ψ x (ϕ ψ) 2. x ϕ x ψ x (ϕ ψ) 3. x y ϕ y x ϕ 4. x y ϕ y x ϕ

De Morgan s Law (p 1 p 2 ) ( p 1 p 2 ) 1 (p 1 p 2 ) premise 2 ( p 1 p 2 ) assumption 3 p 1 assumption 4 p 1 p 2 i 1 3 5 e4,2 6 p 1 PBC 3-5 7 p 2 assumption 8 p 1 p 2 i 2 7 9 e4,2 10 p 2 PBC 7-9 11 (p 1 p 2 ) i 6,1-12 e 11,1 13 ( p 1 p 2 ) PBC 2-12

Generalized De Morgan s Law x P(x) x P(x) 1 x P(x) premise 2 x P(x) assumption 3 x 0 4 P(x 0 ) assumption 5 x P(x) x i 4 6 e 5,2 7 P(x 0 ) PBC 4-6 8 x P(x) x i 3-7 9 e 8,1 10 x P(x) PBC 2-9

Generalized De Morgan s Law x ϕ x ϕ 1 xϕ premise 2 x

Exercise Prove the reverse x ϕ x ϕ

Models Let F be a set of functions and P a set of predicates. A model M for (F,P) consists of A non-empty set A [universe] of concrete values For each nullary f F an element of A = f M For each n-ary f F a function f M : A n A For each n-ary P P a subset P M A n

Example 1 F = {i} and P = {R,F} i a constant function, R binary and F unary predicates Model A set of states, initial state i, state transitions R, final states F A = {a,b,c} i M = a R M = {(a,a),(a,b),(a,c),(b,c), (c,c)} F M = {b,c}

Example 1 y R(i,y) F(i) x y z (R(x,y) R(x,z) y = z ) x y R(x,y)

Example 2 F = {e, } and P = { } e a constant function, a binary function, a binary predicate1 Model A set of states, A = {binary strings} e M = ε, M concatenation, M prefix ordering [011 is a prefix of 011001

Example 2 x ((x x e) x e x)) y x (y x) x y (y x) x y z ((x y) (x z y z)) x y ((x y) (y x))

Satisfaction Given a model M for (F,P) and given an environment l : var A the satisfaction relation M l ϕ P(t 1,,t n ) (a 1,,a n ) and M l ϕ iff (a 1,,a n ) R M M l x ψ iff M l [x a]ψ holds for all a A M l x ψ iff M l [x a]ψ holds for some a A

Satisfaction Given a model M for (F,P) and given an environment l : var A the satisfaction relation M l ϕ M l ψ iff M l ψ does not hold M l ψ 1 ψ 2 iff M l ψ 1 and M l ψ 2 holds M l ψ 1 ψ 2 iff M l ψ 1 or M l ψ 2 holds M l ψ 1 ψ 2 iff M l ψ 2 holds whenever M l ψ 1 holds

Semantic Entailment For propositional calculus: If for all valuations (assignments of variables to truth values) for which all φ 1,,φ n evaluate to true, ψ also evaluates to true then the semantic entailment relation φ 1,,φ n ψ holds Decidable using truth tables

Semantic Entailment Let Γ be a set of formulas (possibly infinite) and ψ be a formula from predicate calculus Γ ψ holds iff for all models M and lookup tables l, whenever M l ϕ holds for all ϕ Γ then M l ψ holds as well ψ is satisfiable iff there is some model M and lookup table l such that M l ψ holds ψ is valid iff M l ψ holds for all models M and lookup tables l

Soundness and Completeness φ 1,,φ n ψ holds iff φ 1,,φ n ψ is valid In particular, ψ, a tautology, ψ is valid. I.E. ψ is a tautology iff ψ is provable Soundness you can not prove things that are not true in the truth table sense Completeness you can prove anything that is true in the truth table sense

Post Correspondence Given a finite sequence (s 1,t 1 ),,(s k,t k ) of pairs of binary strings. Is there a sequence of indices i 1,i 2,,i n such that s i 1 s in = t i1 t i n Example s 1 = 1, s 2 = 10, s 3 = 011 t 1 = 101, t 2 = 00, t 3 = 11 Solution (1,3,2,3) 101110011 101110011

Undecidability Theorem. The decision problem of validity for predicate calculus is undecidable: no program exists which, given any ϕ, can determine in a finite amount of time if ϕ Proof reduce to Post Correspondence problem. I.E. show that if the decision problem is solvable, we could solve the Post Correspondence problem. This is a contradiction.

Consequences of Undecidability From the soundness and completeness of predicate logic, which states that ϕ iff ϕ, we infer that we can not decide provability either Since ϕ is satisfiable iff ϕ is valid, we infer that satisfiability for predicate calculus is also undecidable.

Proof Construct a formula ϕ such that ϕ holds iff the corresponding Post correspondence problem has a solution. ϕ = ϕ 1 ϕ 2 ϕ 3 ϕ 1 = i=1..k P(f si (e),f ti (e)) ϕ 2 = v w (P(v,w) i=1..k P(f si (v),f ti (w))) ϕ 3 = z P(z,z)

Proof Find model which tells us the Post Correspondence problem has a solution e M = empty string f 0 (s) = s0, f 1 (s) = s1 P M = {(s,t) there is a sequence of indices i 1,i 2,,i n such that s i 1 s in = t i1 t in } Since ϕ holds M ϕ holds Both M ϕ 1 and M ϕ 2 holds so it follows that M ϕ 3 holds. This tells us there is a solution to the given PC problem

Proof Conversely assume that the PCP C has a solution i 1,i 2,,i n Show that if M is any model having a constant e M, two unary functions f0 M and f1 M, and a binary predicate P M, then the model has to satisfy ϕ Need to show if M ϕ 1 ϕ 2 then M ϕ 3

Proof Encode strings in A interpret(ε) = e M interpret(s0) = f 0M (interpret(s)) interpret(s1) = f 1M (interpret(s)) Interpret(011) = f 1 M (f 1 M (f 0M (e M ))) Since M ϕ 1, (interpret(s i ),interpret(t i )) P M Since M ϕ 2, If (s,t) P M then (interpret(ss i ),interpret(tt i )) P M

Proof Therefore, (interpret(s i1 s in ),interpret(t i1 t in )) P M Since i 1,i 2,,i n is a solution to the PCP interpret(s i1 s in ) = interpret(t i1 t in ) and z P(z,z) in M and thus M ϕ 3

Reachabilty When modeling systems via states and state transitions, we want to show that a bad state can not be reached from a good state. Given nodes n and n in a directed graph, is there a finite path of transitions from n to n. s0 s3 A = {s0,s1,s2,s3} R M = {(s0,s1), (s1,s0), (s1,s1),(s1,s2), (s2,s0),(s3,s0),(s3,s2)} s1 s2

Compactness Theorem Let Γ be a set of sentences of predicate calculus. If all finite subsets of Γ are satisfiable, then so is Γ. Proof uses soundness and completeness and finite length of proofs.

Reachability is Not Expressible Can reachability be expressed in predicate calculus? u=v x (R(u,x) R(x,v)) x 1 x 2 (R(u,x 1 ) R(x 1,x 2 ) R(x 2,v)) This is infinite The answer is no! Proof follows from compactness theorem.

Reachability is Not Expressible Theorem. There is no predicate-logic formula ϕ with u and v as its only free variables and R its only predicate such that ϕ holds in directed graphs iff there is a path from u to v. Proof. By contradiction. Suppose there is such a formula. Let ϕ n be the formula expressing that there is a path from c to c ϕ n = x 1 x n-1 (R(c,x 1 ) R(x n-1,c)).

Reachability is Not Expressible Proof. By contradiction. Suppose there is such a formula ϕ. Let ϕ n be the formula expressing that there is a path from c to c ϕ n = x 1 x n-1 (R(c,x 1 ) R(x n-1,c)). = { ϕ i I 0} ϕ[c/u][c /v] is unsatisfiable, but any finite subset is satisfiable. By compactness this leads to a contradiction and hence there is no such ϕ.

Reachability via HOL Encode Transitive closure P x y z (C 1 C 2 C 3 C 4 ) C 1 = P(x,x) C 2 = P(x,y) P(y,z) P(x,y) C 3 = P(u,v) C 4 = R(x,y) P(x,y) Note quantifier applied to predicate P (Existential second order logic)

Reachability via HOL Obtain formula for the existence of a path from u to v by negating previous formula (use DeMorgan s law) P x y z ( C 1 C 2 C 3 C 4 ) If both and can range over predicates then second order logic.