Introduction & propositional calculus First-order logic Miscellaneous Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution Propositional calculus: tableaux Logic: Compendium http://www.ida.liu.se/∼TDDD72/ Andrzej Szalas IDA, University of Linköping May 23, 2016 Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Semantic tableau for a formula A A semantic tableau T is a tree with each node labeled with a set of formulas, where T represents A in such a way that A is equivalent to the disjunction of formulas appearing in all leaves, assuming that sets of formulas labeling leaves are interpreted as conjunctions of their members. Slide 1 of 43 Andrzej Szalas Lecture II: tableaux, satisfiability Lecture III: resolution α-formulas Introduction & propositional calculus First-order logic Miscellaneous Slide 2 of 43 Lecture II: tableaux, satisfiability Lecture III: resolution β-formulas Rule (¬¬) (∧) (¬∨) (¬ →) (↔) α ¬¬A1 A1 ∧ A2 ¬(A1 ∨ A2 ) ¬(A1 → A2 ) A1 ↔ A 2 α1 A1 A1 ¬A1 A1 A1 → A2 Factorization Rule (fctr): remove redundant duplicates. α2 A2 ¬A2 ¬A2 A2 → A1 Rule β (¬∧) ¬(B1 ∧ B2 ) (∨) B1 ∨ B2 (→) B1 → B2 (¬ ↔) ¬(B1 ↔ B2 ) β1 ¬B1 B1 ¬B1 ¬(B1 → B2 ) E.g. p, q, p, r , r is simplified to p, q, r . Andrzej Szalas Slide 3 of 43 Andrzej Szalas Slide 4 of 43 β2 ¬B2 B2 B2 ¬(B2 → B1 ) Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution Literals and complementary formulas A literal is an atom (propositional variable) or the negation of an atom. Atoms are called positive literals and their negations are called negative literals. For any formula A, {A, ¬A} is a complementary pair of formulas. A is the complement of ¬A and ¬A is the complement of A. Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution Closed and open leaves A leaf is called closed if it contains a complementary pair of formulas. If a leaf consists of literals only and contains no complementary pair of literals then we call it open. A tableau is completed if all its leaves are open or closed. Remark Observe that the conjunction of a complementary pair of formulas is equivalent to false. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 5 of 43 Lecture II: tableaux, satisfiability Lecture III: resolution Construction of a semantic tableau for a formula C Initially, T consists of a single node labeled with {C }. If T is completed then no further construction is possible. Otherwise chose a leaf, say l, labeled with S containing a non-literal and chose from S a formula D which is not a literal and: if D is! an α-formula then create a successor of l and label it with S − {D} ∪ {α1 , α2 } Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 6 of 43 Lecture II: tableaux, satisfiability Lecture III: resolution Proving with semantic tableaux To prove that a formula A is a tautology we construct a completed tableau for its negation ¬A. If the tableau is closed then A is a tautology (its negation is not satisfiable). Otherwise A is not a tautology. if D is a β-formula then ! create two new successors of l, the first one labeled with S − {D} ∪ {β1 } and the second one ! labeled with S − {D} ∪ {β2 }. Andrzej Szalas Slide 7 of 43 Andrzej Szalas Slide 8 of 43 Introduction & propositional calculus First-order logic Miscellaneous NNF: Negation Normal Form A literal of the form A is called positive and of the form ¬A is called negative. We say that formula A is in negation normal form, abbreviated by Nnf, iff it contains no other connectives than ∧, ∨, ¬, and the negation sign ¬ appears in literals only. Introduction & propositional calculus First-order logic Miscellaneous Any propositional formula can be equivalently transformed into the Nnf by replacing subformulas according to the table below, until Nnf is obtained. Rule Subformula Replaced by 1 A↔B (¬A ∨ B) ∧ (A ∨ ¬B) 2 A→B ¬A ∨ B 3 ¬¬A A 4 ¬(A ∨ B) ¬A ∧ ¬B 5 ¬(A ∧ B) ¬A ∨ ¬B Slide 9 of 43 Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution CNF: Conjunctive Normal Form A clause is any formula of the form A1 ∨ A2 ∨ . . . ∨ Ak , where k ≥ 0 and A1 , A2 , . . . , Ak are literals. The empty clause (when k = 0), denoted by ∅, is equivalent to F. A Horn clause is a clause in which at most one literal is positive. Formula A is in conjunctive normal form, abbreviated by Cnf, if it is a conjunction of clauses. It is in clausal form if it is a set of clauses (considered to be an implicit conjunction of clauses). Andrzej Szalas Lecture II: tableaux, satisfiability Lecture III: resolution Transforming formulas into NNF Recall that a literal is a formula of the form A or ¬A, where A is an atomic formula. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution Slide 11 of 43 Slide 10 of 43 Lecture II: tableaux, satisfiability Lecture III: resolution Transforming formulas into CNF Any propositional formula can be equivalently transformed into the Cnf: 1 Transform the formula into Nnf 2 Replace subformulas according to the table below, until Cnf is obtained. Rule 6 7 Subformula (A ∧ B) ∨ C C ∨ (A ∧ B) Andrzej Szalas Replaced by (A ∨ C ) ∧ (B ∨ C ) (C ∨ A) ∧ (C ∨ B) Slide 12 of 43 Introduction & propositional calculus First-order logic Miscellaneous Introduction & propositional calculus First-order logic Miscellaneous Lecture II: tableaux, satisfiability Lecture III: resolution Resolution rule for propositional calculus Resolution method has been introduced by Robinson (1965) and is considered the most powerful automated proving technique. Resolution rule, denoted by (res), is formulated as follows: α ∨ L, ¬L ∨ β α∨β Factorization rule for propositional calculus Reminder Factorization rule, denoted by (fctr ): Remove from a clause redundant repetitions of literals. Example P ∨ P ∨ ¬Q ∨ P ∨ ¬Q P ∨ ¬Q where L is a literal and α, β are clauses. The position of L and ¬L in clauses does not matter. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 13 of 43 2 Introduction & propositional calculus First-order logic Miscellaneous Slide 14 of 43 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution DeMorgan’s laws for quantifiers The method, where formula A is to be proved 1 Andrzej Szalas Lecture II: tableaux, satisfiability Lecture III: resolution Resolution method Lecture II: tableaux, satisfiability Lecture III: resolution transform ¬A into the conjunctive normal form try to derive the empty clause ∅ by applying resolution (res) and factorization (fctr ): if the empty clause is obtained then A is a tautology, if the empty clause cannot be obtained no matter how (res) and (fctr ) are applied, then conclude that A is not a tautology. Andrzej Szalas Slide 15 of 43 DeMorgan laws for quantifiers are: [¬∀x A(x)] ↔ [∃x ¬A(x)] [¬∃x A(x)] ↔ [∀x ¬A(x)] Examples 1 “It is not the case that all animals are large” is equivalent to “Some animals are not large”. 2 “It is not the case that some animals are plants” is equivalent to “All animals are not plants”. 3 ¬∀x∃y ∀z [friend(x, y ) ∧ likes(y , z)] is equivalent to ∃x∀y ∃z ¬[friend(x, y ) ∧ likes(y , z)]. Andrzej Szalas Slide 16 of 43 Introduction & propositional calculus First-order logic Miscellaneous Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Other laws for quantifiers 1 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution γ-formulas Null quantification. Assume variable x is not free in formula P. Then: 1 2 3 4 2 Introduction & propositional calculus First-order logic Miscellaneous Rule (∀) (¬∃) ∀x[P] is equivalent to P; ∃x[P] is equivalent to P; ∀x[P ∨ Q(x)] is equivalent to P ∨ ∀x[Q(x)]; ∃x[P ∧ Q(x)] is equivalent to P ∧ ∃x[Q(x)]. 2 γ(a) A(a) ¬A(a) where a is an arbitrary constant. Pushing quantifiers past connectives: 1 γ ∀x A(x) ¬∃x A(x) ∀x[P(x) ∧ Q(x)] is equivalent to ∀x[P(x)] ∧ ∀x[Q(x)]; ∃x[P(x) ∨ Q(x)] is equivalent to ∃x[P(x)] ∨ ∃x[Q(x)] Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 17 of 43 Andrzej Szalas Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Introduction & propositional calculus First-order logic Miscellaneous Slide 18 of 43 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Tableaux δ-formulas δ-formulas Rule (∃) (¬∀) δ ∃x A(x) ¬∀x A(x) δ(a) A(a) ¬A(a) where a is a fresh constant. Construction of a semantic tableau for formula A Initially T consists of a single unmarked node labeled with {A}. Until possible choose anon-closed leaf l labeled with U(l) and apply: if U(l) contains a pair of complementary formulas then mark the leaf closed; otherwise: Andrzej Szalas Slide 19 of 43 Andrzej Szalas Slide 20 of 43 Introduction & propositional calculus First-order logic Miscellaneous Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Tableaux Introduction & propositional calculus First-order logic Miscellaneous Transforming formulas into NNF Construction of a semantic tableau for formula A if U(l) does not contain a pair of complementary literals and contains non-literals, choose a non-literal A ∈ U(l) or a γ-formula from any node on the path from l to the root, and: if A is an α- or β-formula, apply rules provided in slide 7; if A is a γ-formula, create a child node l ′ for l and label l ′ with U(l ′ ) = (U(l) − {A}) ∪ {γ(a)}, where a preferably is a constant appearing in U(l); if A is a δ-formula, create a child node l ′ for l and label l ′ with U(l ′ ) = (U(l) − {A}) ∪ {δ(a)}, where a is a constant not appearing in U(l). Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous NNF: Negation Normal Form Recall (see Slide 9) that in negation normal form, Nnf, negation ca appear only before atoms. Any first-order formula can be equivalently transformed into the Nnf by replacing subformulas according to the table given in Slide 10 and rules given below. Rule Subformula Replaced by 6’ ¬∀x A(x) ∃x[¬A(x)] 7’ ¬∃x A(x) ∀x[¬A(x)] Slide 21 of 43 Andrzej Szalas Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution PNF: Prenex Normal Form Introduction & propositional calculus First-order logic Miscellaneous Q1 x1 Q2 x2 . . . Qn xn [A(x1 , x2 , . . . , xn )], Examples 3 A(x) ∧ B(x, y ) ∧ ¬C (y ) is in Pnf ∀x∃y [A(x) ∧ B(x, y ) ∧ ¬C (y )] is in Pnf A(x) ∧ ∀x [B(x, y ) ∧ ¬C (y )] as well as ∀x [A(x) ∧ B(x, y ) ∧ ¬∃yC (y )] are not in Pnf. Andrzej Szalas Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Any predicate formula can be equivalently transformed into the Pnf 1 Transform the formula into Nnf; 2 where n ≥ 0, Q1 , Q2 , . . . , Qn are quantifiers (∀, ∃) and A is quantifier-free. 2 Slide 22 of 43 Transforming formulas into PNF We say A is in prenex normal form, abbreviated by Pnf, if all its quantifiers (if any) are in its prefix, i.e., it has the form: 1 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Slide 23 of 43 Replace subformulas according to the table below, until Pnf is obtained, where Q denotes any quantifier, ∀ or ∃. Rule Subformula 12 Qx[A(x)], A(x) without variable z 13 ∀x A(x) ∧ ∀x B(x) 14 ∃x A(x) ∨ ∃x B(x) 15 A ∨ Qx B, where A contains no x 16 A ∧ Qx B, where A contains no x Andrzej Szalas Slide 24 of 43 Replaced by Qz[A(z)] ∀x [A(x) ∧ B(x)] ∃x [A(x) ∨ B(x)] Qx (A ∨ B) Qx (A ∧ B) Introduction & propositional calculus First-order logic Miscellaneous Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Skolem normal form Transforming formulas into the Skolem normal form Eliminate existential quantifiers from left to right: 1 when we have ∃xA(x) then remove ∃x and replace x in A by a new constant symbol when we have ∀x1 . . . ∀xk ∃xA(x1 , . . . , xk , x) then remove ∃x and replace x in A by a term f (x1 , . . . , xk ), where f is a new function symbol. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 25 of 43 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution The unification algorithm 3 if the trees are identical then stop; let t and t ′ be subtrees that have to be identical, but are not: ′ if t and t are function symbols/constants then conclude that the substitutions do not exist and stop; otherwise t or t ′ is a variable; let t be a variable, then substitute all occurrences of t by the expression represented by t ′ assuming that t does not occur in t ′ (if it occurs then conclude that the substitutions do not exist and stop); 4 change the trees, according to the substitution determined in the previous step and repeat from step 2. Andrzej Szalas Given two expressions, unification depends on substituting variables by expressions so that both input expressions become identical. If this is possible, the given expressions are said to be unifiable. Examples 1 2 3 To unify expressions father (x) and father (mother (John)), it suffices to substitute x by expression mother (John). √ To unify expressions (x + f (y√)) and ( 2 ∗ z + f (3)), it suffices to substitute x by 2 ∗ z and y by 3. Expressions father (x) and mother (father (John)) cannot be unified. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 26 of 43 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Resolution rule for the predicate calculus Input: expressions e, e ′ Output: substitution of variables which makes e and e ′ identical or inform that such a substitution does not exist. 1 traverse trees corresponding to expressions e, e ′ ; 2 Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Unification A formula is in the Skolem normal form iff it is in the Pnf and contains no existential quantifiers. 2 Introduction & propositional calculus First-order logic Miscellaneous Slide 27 of 43 Resolution rule, denoted by (res), is formulated for first-order clauses as follows: L1 (t¯1 ) ∨ . . . ∨ Lk−1 (t̄k−1 ) ∨ Lk (t̄k ) ¬Lk (t¯k′ ) ∨ M1 (s̄1 ) ∨ . . . ∨ Ml (s̄l ) ′ L1 (t¯1 ′ ) ∨ . . . ∨ Lk−1 (t̄k−1 ) ∨ M1 (s̄1′ ) ∨ . . . ∨ Ml (s̄l′ ) , where: L1 , . . . , Lk , M1 , . . . , Ml are literals; tk and tk′ are unifiable; primed expressions are obtained from non-primed expressions by applying substitutions unifying tk and tk′ . Andrzej Szalas Slide 28 of 43 Introduction & propositional calculus First-order logic Miscellaneous Lecture IV: introduction Lecture V: tableaux Lecture VI: resolution Factorization rule for the predicate calculus The rule Factorization rule, denoted by (fctr ): Unify some terms in a clause and remove from the clause all repetitions of literals. Examples 1 2 (fctr ) with x = Jack, y = mother (Eve): parent(x, y ) ∨ parent(Jack, mother (Eve)) parent(Jack, mother (Eve)) (fctr ) with z = x, u = y : P(x, y ) ∨ S(y , z, u) ∨ P(z, u) P(x, y ) ∨ S(y , x, y ) Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Introduction & propositional calculus First-order logic Miscellaneous Datalog Facts in Datalog Facts in Datalog are represented in the form of relations name(arg1 , . . . , argk ), where name is a name of a relation and arg1 , . . . , argk are constants. Examples 1 address(John, ’Kungsgatan 12′ ) 2 likes(John, Marc). Slide 29 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Atomic queries about facts Lecture VII: deductive databases Lecture VIII: sequent calculus Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 30 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Rules in Datalog Atomic queries are of the form name(arg1 , . . . , argk ), where arg1 , . . . , argk are constants or variables, where ‘ ’ is also a variable (without a name, “do-not-care” variable). Rules in Datalog are expressed in the form of (a syntactic variant of) Horn clauses: R(Z̄ ):−R1 (Z̄1 ), . . . , Rk (Z̄k ) Examples 1 likes(John, Marc) – does John like Marc? 2 likes(X , Marc) – who likes Marc? (compute X ’s satisfying likes(X , Marc)) 3 likes(John, X ) – whom likes John? 4 likes(X , Y ) – compute all pairs hX , Y i such that likes(X , Y ) holds. Andrzej Szalas Slide 31 of 43 where Z̄ , Z̄1 , . . . , Z̄k are vectors of variable or constant symbols such that any variable appearing on the lefthand side of ‘:−’ (called the head of the rule) appears also at the righthand side of the rule (called the body of the rule). Andrzej Szalas Slide 32 of 43 Introduction & propositional calculus First-order logic Miscellaneous Lecture VII: deductive databases Lecture VIII: sequent calculus Rules in Datalog Introduction & propositional calculus First-order logic Miscellaneous Lecture VII: deductive databases Lecture VIII: sequent calculus Designing Datalog databases Semantics The intended meaning of the rule is that [R1 (Z̄1 ) ∧ . . . ∧ Rk (Z̄k )] → R(Z̄ ), where all variables that appear both in the rule’s head and body are universally quantified, while those appearing only in the rule’s body, are existentially quantified. Remark To define disjunction in rule’s body, one uses the following rules: h:−b1. h:−b2. These rules are equivalent to (b1 → h) ∧ (b2 → h) Example Rule: R(X , c):−Q(X , Z ), S(Z , X ) denotes implication: ∀X {∃Z [Q(X , Z ) ∧ S(Z , X )] → R(X , c)}. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 33 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Designing Datalog databases which, in turn, is equivalent to: (b1 ∨ b2) → h. Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 34 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus The Gentzen system for propositional calculus Remark One also often uses the following tautology: [(b → h1) ∧ (b → h2)] ↔ [b → (h1 ∧ h2)]. It allows to substitute: h1 ∧ h2:−b Gentzen systems are dual to tableaux or resolution in the sense that we directly prove validity rather than unsatisfiability of formulas. Sequents By a sequent we understand any expression of the form A ⇒ B, where A, B are finite sets of formulas. Let A = {A1 , . . . , Ak } and B = {B1 , . . . , Bm }. Then the sequent A ⇒ B represents: A1 ∧ . . . ∧ Ak → B1 ∨ . . . ∨ Bm , by two rules: h1:−b. h2:−b. where it is assumed that the empty disjunction is F and the empty conjunction is T. Andrzej Szalas Slide 35 of 43 Andrzej Szalas Slide 36 of 43 Introduction & propositional calculus First-order logic Miscellaneous Introduction & propositional calculus First-order logic Miscellaneous Lecture VII: deductive databases Lecture VIII: sequent calculus Sequent-based rules and axioms Lecture VII: deductive databases Lecture VIII: sequent calculus Rules for propositional connectives Negation General form of rules A⇒B − from A ⇒ B derive C ⇒ D C ⇒D A⇒B from A ⇒ B derive conjunction − C ⇒ D and E ⇒ F C ⇒ D; E ⇒ F (¬l) A, ¬B, C ⇒ D A, C ⇒ B, D Axioms Axioms are of the form A, B, C ⇒ D, B, E , i.e., the same formula appears at both sides of ⇒. Introduction & propositional calculus First-order logic Miscellaneous (∧r ) Slide 37 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Rules for propositional connectives A ⇒ B, ¬C , D A, C ⇒ B, D Conjunction (∧l) Andrzej Szalas (¬r ) A, B ∧ C , D ⇒ E A, B, C , D ⇒ E A ⇒ B, C ∧ D, E A ⇒ B, C , E ; A ⇒ B, D, E Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 38 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Derived rules for definable connectives Example: rule (→ l) for implication Consider first A, B → C , D ⇒ E : Disjunction A, B ∨ C , D ⇒ E (∨l) A, B, D ⇒ E ; A, C , D ⇒ E (∨r ) A ⇒ B, C ∨ D, E A ⇒ B, C , D, E (def ) A, B → C , D ⇒ E A, ¬B ∨ C , D ⇒ E (∨l) A, ¬B, D ⇒ E ; A, C , D ⇒ E (¬l) A, D ⇒ B, E Example: rule (→ l) for implication Thus we have the following derived rule for implication: (→ l) Andrzej Szalas Slide 39 of 43 A, B → C , D ⇒ E A, D ⇒ B, E ; A, C , D ⇒ E Andrzej Szalas Slide 40 of 43 Introduction & propositional calculus First-order logic Miscellaneous Introduction & propositional calculus First-order logic Miscellaneous Lecture VII: deductive databases Lecture VIII: sequent calculus Derived rules for definable connectives Lecture VII: deductive databases Lecture VIII: sequent calculus Gentzen rules for quantifiers Example: rule (→ r ) Consider now A ⇒ B, C → D, E : (def ) A ⇒ B, C → D, E A ⇒ B, ¬C ∨ D, E (∨r ) A ⇒ B, ¬C , D, E (¬r ) A, C ⇒ B, D, E Universal quantifier (∀l) A, ∀x B(x), C ⇒ D A, ∀x B(x), C , B(a) ⇒ D (∀r ) where, in application of (∀r ), a is a fresh constant. Example: rule (→ r ) Thus we have the following derived rule: (→ r ) A ⇒ B, C → D, E A, C ⇒ B, D, E Andrzej Szalas Introduction & propositional calculus First-order logic Miscellaneous Slide 41 of 43 Lecture VII: deductive databases Lecture VIII: sequent calculus Gentzen rules for quantifiers Existential quantifier (∃l) A ⇒ B, ∀x C (x), D A ⇒ B, C (a), D A, ∃x B(x), C ⇒ D A, B(a), C ⇒ D (∃r ) A ⇒ B, ∃x C (x), D A ⇒ B, ∃x C (x), D, C (a) where, in application of (∃l), a is a fresh constant. Andrzej Szalas Slide 43 of 43 Andrzej Szalas Slide 42 of 43