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

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

06 From Propositional to Predicate Logic

15414/614 Optional Lecture 3: Predicate Logic

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

Classical First-Order Logic

Learning Goals of CS245 Logic and Computation

Classical First-Order Logic

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

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

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

Comp487/587 - Boolean Formulas

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

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

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.

First Order Logic: Syntax and Semantics

Predicate Logic: Sematics Part 1


Propositional Logic Not Enough

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

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

Introduction to Sets and Logic (MATH 1190)

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

03 Review of First-Order Logic

Natural Deduction for Propositional Logic

Predicate Logic & Quantification

A Logic Primer. Stavros Tripakis University of California, Berkeley

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

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

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

Predicate Logic: Introduction and Translations

Predicate Logic - Introduction

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

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

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

ICS141: Discrete Mathematics for Computer Science I

Announcements CompSci 102 Discrete Math for Computer Science

Logic: Propositional Logic Truth Tables

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

The predicate calculus is complete

Predicate Calculus - Semantics 1/4

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

Introduction to first-order logic:

Propositional Logic: Deductive Proof & Natural Deduction Part 1

Predicate Logic: Syntax

02 Propositional Logic

AAA615: Formal Methods. Lecture 2 First-Order Logic

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

Discrete Mathematics and Its Applications

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

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

First Order Logic (FOL) 1 znj/dm2017

Section Summary. Predicate logic Quantifiers. Negating Quantifiers. Translating English to Logic. Universal Quantifier Existential Quantifier

Section Summary. Section 1.5 9/9/2014

First order Logic ( Predicate Logic) and Methods of Proof

Logic. Definition [1] A logic is a formal language that comes with rules for deducing the truth of one proposition from the truth of another.

Propositional Logic: Models and Proofs

Propositional Logic Language

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

The semantics of propositional logic

Predicate Calculus - Syntax

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

Lecture 10: Predicate Logic and Its Language

Computer-Aided Verification

INF3170 / INF4171 Notes on Resolution

Section Summary. Predicates Variables Quantifiers. Negating Quantifiers. Translating English to Logic Logic Programming (optional)

Automated Reasoning Lecture 5: First-Order Logic

Section Summary. Predicate logic Quantifiers. Negating Quantifiers. Translating English to Logic. Universal Quantifier Existential Quantifier

CS720 Class Notes. Steve Revilak

Predicates and Quantifiers. CS 231 Dianna Xu

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

CS156: The Calculus of Computation Zohar Manna Winter 2010

Logical Operators. Conjunction Disjunction Negation Exclusive Or Implication Biconditional

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

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

A brief introduction to Logic. (slides from

CSE 1400 Applied Discrete Mathematics Definitions

Part I: Propositional Calculus

Logic: Propositional Logic (Part I)

Predicate Calculus lecture 1

Final Exam (100 points)

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

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

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

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

Informal Statement Calculus

185.A09 Advanced Mathematical Logic

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

CS589 Principles of DB Systems Fall 2008 Lecture 4e: Logic (Model-theoretic view of a DB) Lois Delcambre

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

Introduction to Logic in Computer Science: Autumn 2006

Logic Part II: Intuitionistic Logic and Natural Deduction

CHAPTER 2. FIRST ORDER LOGIC

Propositional Resolution Introduction

Propositional logic. Programming and Modal Logic

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

Why Learning Logic? Logic. Propositional Logic. Compound Propositions

Part 1: Propositional Logic

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

First-Order Logic (FOL)

Transcription:

Predicate Calculus CS 270 Math Foundations of Computer Science Jeremy Johnson Presentation uses material from Huth and Ryan, Logic in Computer Science: Modelling and Reasoning about Systems, 2nd Edition

Outline 1. Motivation (program specification & derivation) 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

Hamiltonian Path G = (V,E) is an undirected graph with nodes V = {0,1,,n-1} and edges E V V 1 0 2 V = {0,1,2} E = {(0,1),(1,2)} edge(0,1), edge(1,0), edge(1,2), edge(2,1)

Hamiltonian Path A Hamiltonian path is a sequence of n nodes, where n = V where each node is visited exactly once (i.e. a permutation of the nodes) following edges 1 0 1 2 or 2 1 0 0 2

Hamiltonian Path path(i,j) is true when the jth node in the path is in the ith location Hamiltonian paths path(0,0), path(1,1), path(2,2) path(0,2), path(1,1), path(2,0) 1 0 2 Not Hamiltonian paths path(0,0), path(1,2), path(2,1) path(0,0), path(0,1), path(1,1), path(2,2) path(0,0), path(1,1), path(1,0), path(2,2)

Hamiltonian Path Constraints Every node occurs exactly once in the path j i path(i,j) j i k path(i,j) path(k,j) i = k Every location has exactly one node i j path(i,j) i j k path(i,j) path(i,k) j = k Adjacent nodes must be connected by an edge i j k (i<n-1) (path(i,j) path(i+1,k) edge(j,k))

Simplification Every node occurs exactly once in the path j i k path(i,j) path(k,j) i = k j i k (i k (path(i,j) path(k,j)) j i k (i k) path(i,j) path(k,j) j i k (i < k) path(i,j) path(k,j)

Simplification Adjacent nodes must be connected by an edge i j k (i<n-1) ((path(i,j) path(i+1,k)) edge(j,k)) i j k (i<n-1) ( edge(j,k) (path(i,j) path(i+1,k))) i j k (i<n-1) ( edge(j,k) ( path(i,j) path(i+1,k))) i j k ((i<n-1) & edge(j,k)) ( path(i,j) path(i+1,k)))

Conversion to SAT j i path(i,j) j=0..n-1 i=0..n-1 P ij j i k (i < k) path(i,j) path(k,j) j=0..n-1 i=0..n-1 k=i+1..n-1 P ij P kj i j k ((i<n-1) & edge(j,k)) path(i,j) path(i+1,k)) i=0..n-2 (j,k) E P ij P i+1,k

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: tt 1 = tt 2 tt 2 = tt 1 1 tt 1 = tt 2 premise 2 tt 1 = tt 1 =i 3 tt 2 = tt 1 =e 1,2 Transitivity: tt 1 = tt 2, tt 2 = tt 3 tt 1 = tt 3 1 tt 1 = tt 2 premise 2 tt 2 = tt 3 premise 3 tt 1 = tt 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 xx P xx Q xx, xxp(xx) xxq(xx) 1 xx P xx Q xx, premise 2 xxxx(xx) premise 3 x 0 P(x 0 ) Q(x 0 ) xx e1 4 P(x 0 ) xx e2 5 Q(x 0 ) e3,4 6 xx Q(xx) xx iii 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 xx Q xx R xx, xx(p xx Q(xx)) xx(p xx R(xx)) 1 xx Q xx R xx, premise 2 xx(p xx Q(xx)) premise 3 x 0 P(x 0 ) Q(x 0 ) assumption 4 Q xx 0 R xx 0 xx e1 5 Q(x 0 ) e 2 3 6 R xx 0 ee 4,5 7 P(x 0 ) e 1 3 8 P(x 0 ) R(x 0 ) i7,6 9 xx(p xx R(xx)) xxi 8 10 xx(p xx R(xx)) xxe 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 pp 2 ) ( p 1 pp 2 ) 1 (p 1 pp 2 ) premise 2 ( p 1 pp 2 ) assumption 3 p 1 assumption 4 p 1 pp 2 i 1 3 5 e4,2 6 p 1 e 3-5 7 p 2 assumption 8 p 1 pp 2 i 2 7 9 i 4,2 10 p 2 e 7-9 11 (p 1 pp 2 ) i 6,10 12 i 11,1 13 ( p 1 pp 2 ) e 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 i 5,2 7 P(x 0 ) e 4-6 8 x P(x) x i 3-7 9 i 8,1 10 x P(x) e 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 predicate Model string prefix 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)) x y (y x) y x (y x) x y z ((x y) (y z) (x z)) x y z ((x y) (x z y z))

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.