todays programme predicate logic predicate logic and
play

Todays programme: Predicate Logic Predicate Logic and Program - PowerPoint PPT Presentation

Todays programme: Predicate Logic Predicate Logic and Program Verification Sten kan ikke flyve og morlille kan ikke flyve Familiarity with basic concepts/results of predicate logic ergo er morlille en sten! Syntax: variables,


  1. Todays programme: Predicate Logic Predicate Logic and Program Verification • Sten kan ikke flyve og morlille kan ikke flyve • Familiarity with basic concepts/results of predicate logic ergo er morlille en sten! – Syntax: variables, quantification, scope • ( ∀ x. (S(x) → ¬ F(x))) ∧ ¬F(morlille)) | = S(morlille) – Semantics: interpretations, valuations, satisfaction truth, validity – Axiomatic proof system FOPL – Gödels completeness theorem for predicate logic •Fugle kan flyve og piphans er en fugl • Describe the use of predicate logic in program verification ergo kan piphans flyve! – Syntax: program specifications, Hoare triples •( ∀ x. (B(x) → F(x))) ∧ B(piphans)) | = F(piphans) – Semantics: partial and total correctness – Proof system: Hoare proof rules dBerLog 2007 1 dBerLog 2007 2 Predicate Logic Predicate Logic Female(girl). Female(girl), Floats(duck). Floats(duck), Sameweigth(girl, duck). Sameweigth(girl, duck), ∀ x Witch(x) ← Burns(x), Witch(X) :- Burns(X). ∀ x Burns(x) ← Wooden(x), Burns(X) :- Wooden(X). ∀ x Wooden(x) ← Floats(x), Wooden(X) :- Floats(X). ∀ x,y (Floats(x) ← Sameweight(x, y) ∧ Floats(y)) Floats(X) :- Sameweight(X, Y), Floats(Y). | = ? Witch(girl)? Witch(girl) dBerLog 2007 3 dBerLog 2007 4

  2. Predicate Logic - syntax examples Predicate Logic for Natural Numbers ∀ ∀ x. Even(x) → Even(succ(succ(x))) • Constants: girl, duck • Predicate symbols P: Female, Floats,.... with arity 1 ∀ ∀ x. ∀ y. (Even(x) ∧ y = x+2) → Even(y) Sameweight with arity 2 ∀ ∀ x. x + 0 = x (A(0) ∧ ( ∀ x. A(x) → A(x+1)) → ∀ x. A(x) • dBerLog 2007 5 dBerLog 2007 6 Predicate Logic - syntax examples Predicate Logic - syntax • Constants: • Variables x,y,z,... girl, duck • Predicate symbols P: Female, Floats,.... with arity 1 • Constants C: c 1 , c 2 ,.... Sameweight with arity 2 • Function symbols F: f,g,h... each with some arity n>0 • Constants 0,1,2,... • Terms +, × both with arity 2 t ::= c | x | f(t 1 , t 2 ,..t n ) • Function symbols F: • Predicate symbols P: = with arity 2 dBerLog 2007 7 dBerLog 2007 8

  3. Predicate Logic - first order language, wwf’s Predicate Logic - Interpretations • Predicate symbols P: P, Q, R each with some arity n 0 • An interpretation I for a first order predicate logic language ≥ consists of • Well formed formulae wff : Φ ::= P(t 1 , t 2 , .., t n ) | D, a domain of concrete values ¬ Φ | Φ ∨ Φ | Φ ∧ Φ | Φ → Φ | for each constant c I an element of D ∀ x Φ | ∃ x Φ for each f ∈ F with arity n, a function f I : D n → D for each P ∈ P with arity n, a subset P I ⊆ D n dBerLog 2007 9 dBerLog 2007 10 Predicate Logic - interpretations example Predicate Logic Female(girl), • D: objects from the real world Floats(duck), girl: the girl in question Sameweigth(girl, duck), ∀ x Witch(x) ← Burns(x), duck: the duck on the scales ∀ x Burns(x) ← Wooden(x), Female: those objects which are female ∀ x Wooden(x) ← Floats(x), Sameweight: those pairs of objects with the same ∀ x,y (Floats(x) ← Sameweight(x, y) ∧ Floats(y)) weight | = ? Witch(girl) I |= ¬ Wooden(girl) ∧ ¬ Witch(duck) I |= ∃ x Female(x) since I |= Female(girl) dBerLog 2007 11 dBerLog 2007 12

  4. Predicate Logic - interpretations example Predicate Logic - valuations • D: • A valuation v in an interpretation I of a first order language Natural numbers, N is a function from the terms of L to the domain D of I such 0,1,..: the numbers zero, one,... that +, × : sum and mutiplication on N v (c) = c I for all constants =: equality on N v (x) ∈ D for all variables x for each f ∈ F with arity n, v (f(t 1 ,..,t n )) = f I ( v (t 1 ),.., v (t n )) I |= ∀ x. x + 0 = x • That is essentially a ”look-up table” ∀ x ∃ y (y = x+1) I |= v : free variables → D I |= x + 1 = y? dBerLog 2007 13 dBerLog 2007 14 Predicate logic - free and bound variables Predicate logic - free and bound variables • ( ∀ x (P(x) ∧ Q(x)) → (P(x) → Q(y)) • ( ∀ x (P(x) ∧ Q(x)) → (P(x) → Q(y)) → → → → ∀ x ∀ x Scope of ∧ ∧ P Q P Q P P Q Q bound free x y x y x x x x dBerLog 2007 15 dBerLog 2007 16

  5. Predicate Logic - satisfaction (semantics) Predicate Logic - interpretations examples • Given an interpretation, I, for a first order language, a D: natural numbers 0, 1, 2,... +, × : valuation v , and a formula A, v satisfies A adition and multiplication =: equality • I |= v A iff if A = P(t 1 , t 2 ,.., t n ) then ( v (t 1 ), v (t 2 ),.., v (t n )) ∈ P I I |= v ∃ y (y = x+1) ? if A = ∀ x B then I |= v [x ← d] B for all d ∈ D if A = ∃ x B then I |= v [x ← d] B for some d ∈ D if A = ¬ B, B ∨ C, B ∧ C, B → C then ”as in propositional logic” dBerLog 2007 17 dBerLog 2007 18 Predicate Logic - interpretations examples Predicate Logic - interpretations examples • D: D: natural numbers 0, 1, 2,... integers ...-2, -1, 0, 1, 2,... +, × : +, × : adition and multiplication adition and multiplication =: equality =: equality I |= [0/x] ∃ y (y = x+1) I |= [0/x] ∃ y (y = x+1) I |= [0/x] ∃ y (x = y+1) I |= [0/x] ∃ y (x = y+1) dBerLog 2007 19 dBerLog 2007 20

  6. Predicate Logic -Truth and Validity Predicate Logic - interpretations examples • A wwf A is true in an interpretation I iff every valuation in D: natural numbers 0, 1, 2,... I satisfies A, notation: I |= A +, × : adition and multiplication • A wwf A is false in an interpretation I iff no valuation in I =: equality satisfies A I |= ∀ x ∃ y (y = x+1) • A wwf A of a first order language L is (logically) valid iff I |= ∀ x ∃ y (x = y+1) since I |= [0/x] ∃ y (x = y+1) it is true in every interpretation of L, notation: |= A • A wwf A of a first order language L is (logically) contradictory iff it is false in every interpretation of L |= ∀ x ∃ y (x = y+1) - follows from above! |= ∀ x ∃ y (y = x+1) - why? dBerLog 2007 21 dBerLog 2007 22 Predicate Logic - quiz Predicate Logic - quiz Truth in N: True False Valid Contr. Truth in N: True False Valid Contr. 1. x+1 = y 1. x+1 = y 2. ∀ x (x = x+1) 2. ∀ x (x = x+1) √ 3. ∀ x ∀ y (x+y = y+x) 3. ∀ x ∀ y (x+y = y+x) √ 4. ∃ x (P(x) ∧¬ P(x)) 4. ∃ x (P(x) ∧¬ P(x)) √ √ 5. ( ∃ x ¬ P(x)) → 5. ( ∃ x ¬ P(x)) → ( ¬ ∀ x P(x)) ( ¬ ∀ x P(x)) √ √ dBerLog 2007 23 dBerLog 2007 24

  7. Todays programme: Predicate Logic -Truth and Validity Predicate Logic and Program Verification • Following Kelly we include the following predicate • Familiarity with basic concepts/results of predicate logic constants in our syntax for predicate logic: – Syntax: variables, quantification, scope – Semantics: interpretations, valuations, satisfaction truth, validity • _|_ standing for the always false predicate, i.e. the – Axiomatic proof system FOPL predicate which is false in every interpretation – Gödels completeness theorem for predicate logic ∀   | standing for the always true predicate, i.e. the • Describe the use of predicate logic in program verification predicate which is true in every interpretation – Syntax: program specifications, Hoare triples – Semantics: partial and total correctness – Proof system: Hoare proof rules dBerLog 2007 25 dBerLog 2007 26 Predicate logic - axiomatic proof system Predicate logic - axiomatic proof system • Axioms: • Axioms: A → ( B → A) A → ( B → A) – Ax1 – Ax1 (A → ( B → C)) → ((A → B) → (A → C)) – Ax2 (A → ( B → C)) → ((A → B) → (A → C)) – Ax2 ( ¬ A → ¬ B) → (B → A) – Ax3 ( ¬ A → ¬ B) → (B → A) – Ax3 ( ∀ x) A(x) → A(t/x) where t is free for x in A! – Ax4 ( ∀ x) (A → B) → (A → ( ∀ x) B) no free occ’s of x in A! – Ax5 • Deduction rules: A, A → B • Deduction rules: A, A → B – Modus ponens MP B – Modus ponens MP B dBerLog 2007 27 dBerLog 2007 28

  8. Predicate logic - substitution Predicate logic - substitution • A[t/x] is only defined if ”t is free for x in A”: A[t/x] notation for ”A with all free occurrences of x substituted by t” no free occurrence of x in A occurs within the scope of ∀ y or ∃ y for any variable y occurring in t • Examples • For all t,x,A, - t can always be made free for x in A (( ∀ x (P(x) ∧ Q(x)) → (P(x) → Q(y))) [f(y)/x] = by a suitable renaming of bindings ∀ y, ∃ y in A ( ∀ x (P(x) ∧ Q(x)) → (P(f(y)) → Q(y)) • Example (( ∀ y (P(y) ∧ Q(x)) → (P(y) → Q(x))) [f(y)/x] = (( ∀ y (P(y) ∧ Q(x)) → (P(y) → Q(x))) [f(y)/x] = ?? ( ∀ z (P(z) ∧ Q(f(y))) → (P(y) → Q(f(y))) dBerLog 2007 29 dBerLog 2007 30 Predicate logic - axiomatic proof system Example of proof • Axioms: • Assume that y does not occur in A(x) A → ( B → A) – Ax1 Prove ( ∀ x) A(x) → ( ∀ y) A(y) (A → ( B → C)) → ((A → B) → (A → C)) – Ax2 ( ¬ A → ¬ B) → (B → A) – Ax3 ( ∀ x) A(x) ( ∀ x) A(x) → A(t) where t is free for x in A! 1. Hyp – Ax4 ( ∀ x) (A → B) → (A → ( ∀ x) B) no free occ’s of x in A! 2. ( ∀ x) A(x) → A(y) – Ax5 Ax4 (y free for x in A) • Inference rules: A, A → B 3. A(y) MP 1,2 – Modus ponens MP B ( ∀ y) A(y) 4. G – Generalisation G A ( ∀ x) A dBerLog 2007 31 dBerLog 2007 32

Recommend


More recommend