Propositional Calculus • Proof Calculus for Predicate Calculus
Total Page:16
File Type:pdf, Size:1020Kb
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 t1,…,tn are terms and f is an n-ary function then f(t1,…,tn ) is a term Formulas • Formula ::= • P is a predicate and t1,…,tn are terms then P(t1,…,tn) 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 ∨ ∀x ∨ ϕ[f(x,y)/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 S ∀y any quantifier for any variable y x → occurring in t. P Q x y Variable Capture • t is free for x in ϕ if ∧ no free x occurs in ϕ in the scope of S ∀y any quantifier for any variable y x → occurring in t. P Q f y y y Equality Rules • Introduction Rule = i t = t • Elimination Rule t1 = t2 φ[t1/x] =e φ[t2/x] Equivalence Relation • Symmetry: 1 = 2 2 = 1 = 1 푡 푡 1 ⊢ 2푡 푡 premise 2 = =i 푡1 푡1 3 = =e 1,2 푡2 푡1 푡 푡 • Transitivity: 1 = 2, 2 = 3 1 = 3 1 푡 푡1 = 푡2 푡 ⊢premise푡 푡 2 = premise 푡2 푡3 3 = =e 2,1 푡1 푡3 푡 푡 Conjunction Rules • Introduction Rule φ ψ ∧ i φ ∧ ψ • Elimination Rule φ ∧ ψ φ ∧ ψ ∧ e1 ∧ e2 φ ψ Universal Quantification Rules • Introduction Rule x0 … φ[x0/x] ∀ x i ∀x φ • 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 • ∀ P → Q , ∀ P( ) ∀ Q( ) 1 ∀ P → Q , premise 푥 푥 푥 푥 푥 ⊢ 푥 푥 2 ∀ ( ) premise 푥 푥 푥 3 x P(x ) →Q(x ) ∀ e1 0 푥푥0 푥 0 4 P(x ) ∀ e2 0 푥 5 Q(x ) →e3,4 0 푥 6 ∀ Q( ) ∀ 5 푥 푥 푥 푖푖 − Disjunction Rules • Introduction Rule φ ψ ∨ i1 ∨ i2 φ ∨ ψ φ ∨ ψ • Elimination Rule (proof by case analysis) φ ψ … … φ ∨ ψ χ χ ∨ e χ Existential Quantification Rules • Introduction Rule φ[t/x] ∃x i ∃x φ • Elimination Rule (proof by case analysis) x0 φ[x0/x] … ∃x φ χ ∃ e χ Example Proof • ∀ Q → R , ∃ (P ∧Q( )) ∃ (P ∧R( )) 푥 푥 푥 푥 푥 푥 ⊢ 1 ∀ Q → R , premise 푥 푥 푥 2 ∃ (P ∧Q( )) premise 푥 푥 푥 3 x P(x ) ∧ Q(x ) assumption 0푥 푥 0 푥 0 4 Q 0 → R 0 ∀ e1 5 Q(x ) ∧e 3 푥 0 푥 푥2 6 R 0 → 4,5 7 P(x ) ∧e 3 푥 0 푒1 8 P(x0) ∧ R(x0) ∧i7,6 9 ∃ (P ∧R( )) ∃ i 8 10 ∃ (P ∧R( )) ∃ e 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 ¬(p1∧ 2) (¬ p1∨¬ 2) 1 ¬(p1∧ 2) premise 2 ¬(¬ p ∨¬ ) assumption 푝 ⊢1 푝 2 푝 3 ¬ p assumption 1 푝 4 ¬ p1∨¬ 2 ∨i1 3 5 ¬e4,2 푝 6 p PBC 3-5 ⊥1 7 ¬ p2 assumption 8 ¬ p1∨¬ 2 ∨i2 7 9 ¬e4,2 푝 10 p PBC 7-9 ⊥2 11 (p1∧ 2) ∧i 6,1- 12 ¬e 11,1 푝 13 (¬ p ∨¬ ) PBC 2-12 1⊥ 2 푝 Generalized De Morgan’s Law ¬∀x P(x) ∃x ¬P(x) 1 ¬∀⊢x P(x) premise 2 ¬∃x ¬P(x) assumption 3 x0 4 ¬P(x0) assumption 5 ∃x ¬P(x) ∃x i 4 6 ¬e 5,2 7 P(x ) PBC 4-6 ⊥0 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 = fM • For each n-ary f ∈ F a function fM : An → A • For each n-ary P ∈ P a subset PM ⊆ An 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} • iM = a • RM = {(a,a),(a,b),(a,c),(b,c), (c,c)} • FM = {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} • eM = ε, ⋅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(t1,…,tn) → (a1,…,an) and M l ϕ iff (a1,…,an) ∈ RM ⊨ ⊨ • 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 ψ ∧⊨ ψ iff M ψ and M ψ holds ⊨l 1 2 ⊨ l 1 l 2 • M ψ ∨ ψ iff M ψ or M ψ holds ⊨l 1 2 ⊨l 1 ⊨l 2 • M ψ → ψ iff M ψ holds whenever M ⊨l 1 2 ⊨ l 2 ⊨ 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.