IA: Computational Logic . Propositional Logic Achim Blumensath blumens@fi.muni.cz Faculty of Informatics, Masaryk University, Brno Basic Concepts Propositional Logic Syntax ▸ Variables A, B, C, . . . , X, Y, Z, . . . ▸ Operators ∧, ∨, ¬, →, ↔ Examples φ ∶= A ∧ (A → B) → B , ψ ∶= ¬(A ∧ B) ↔ (¬A ∨ ¬B) . Terminology ▸ entailment φ ⊧ ψ ▸ equivalence φ ≡ ψ ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ Terminology ▸ entailment φ ⊧ ψ ▸ equivalence φ ≡ ψ ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ ▸ satisfiability φ ≢ false ▸ validity φ ≡ true ▸ Every valid formula is satisfiable. ▸ φ is valid iff ¬φ is not satisfiable. ▸ φ ⊧ ψ iff φ → ψ is valid. Examples ▸ A ∧ (A → B) → B is Terminology ▸ entailment φ ⊧ ψ ▸ equivalence φ ≡ ψ ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ ▸ satisfiability φ ≢ false ▸ validity φ ≡ true ▸ Every valid formula is satisfiable. ▸ φ is valid iff ¬φ is not satisfiable. ▸ φ ⊧ ψ iff φ → ψ is valid. Examples ▸ A ∧ (A → B) → B is valid. ▸ A ∨ B is Terminology ▸ entailment φ ⊧ ψ ▸ equivalence φ ≡ ψ ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ ▸ satisfiability φ ≢ false ▸ validity φ ≡ true ▸ Every valid formula is satisfiable. ▸ φ is valid iff ¬φ is not satisfiable. ▸ φ ⊧ ψ iff φ → ψ is valid. Examples ▸ A ∧ (A → B) → B is valid. ▸ A ∨ B is satisfiable but not valid. ▸ ¬A ∧ A is Terminology ▸ entailment φ ⊧ ψ ▸ equivalence φ ≡ ψ ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ ▸ satisfiability φ ≢ false ▸ validity φ ≡ true ▸ Every valid formula is satisfiable. ▸ φ is valid iff ¬φ is not satisfiable. ▸ φ ⊧ ψ iff φ → ψ is valid. Examples ▸ A ∧ (A → B) → B is valid. ▸ A ∨ B is satisfiable but not valid. ▸ ¬A ∧ A is not satisfiable. Normal Forms Conjunctive Normal Form (CNF) (A ∨ ¬B) ∧ (¬A ∨ C) ∧ (A ∨ ¬B ∨ ¬C) Disjunctive Normal Form (DNF) (A ∧ C) ∨ (¬A ∧ ¬B) ∨ (A ∧ ¬B ∧ ¬C) Clauses Definitions ▸ literal A or ¬A ▸ clause set of literals {A, B, ¬C} short-hand for disjunction A ∨ B ∨ ¬C Clauses Definitions ▸ literal A or ¬A ▸ clause set of literals {A, B, ¬C} short-hand for disjunction A ∨ B ∨ ¬C Example CNF φ ∶= (A ∨ ¬B ∨ C) ∧ (¬A ∨ C) ∧ B clauses {A, ¬B, C}, {¬A, C}, {B} Clauses Definitions ▸ literal A or ¬A ▸ clause set of literals {A, B, ¬C} short-hand for disjunction A ∨ B ∨ ¬C Example CNF φ ∶= (A ∨ ¬B ∨ C) ∧ (¬A ∨ C) ∧ B clauses {A, ¬B, C}, {¬A, C}, {B} Notation Φ[L ∶= true] ∶= {C ∖ {¬L} C ∈ Φ , L ∉ C } . The Satisfiability Problem Davis-Putnam-Logemann-Loveland (DPLL) Algorithm Input: a set of clauses Φ Output: true if Φ is satisfiable, false otherwise. DPLL(Φ) for every singleton {L} in Φ (* simplify Φ *) Φ ∶= Φ[L ∶= true] for every literal L whose negation does not occur in Φ Φ ∶= Φ[L ∶= true] if Φ contains the empty clause then (* are we done? *) return false if Φ is empty then return true choose some literal L in Φ (* try L ∶= true and L ∶= false *) if DPLL(Φ[L ∶= true]) then return true else return DPLL(Φ[L ∶= false]) Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Step : B ∶= true Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Step : B ∶= true {C, D}, {¬D}, {¬C}, {¬C, ¬D} Step : C ∶= false and D ∶= false Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Step : B ∶= true {C, D}, {¬D}, {¬C}, {¬C, ¬D} Step : C ∶= false and D ∶= false {D}, {¬D} Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Step : B ∶= true {C, D}, {¬D}, {¬C}, {¬C, ¬D} Step : C ∶= false and D ∶= false {D}, {¬D} ∅ failure Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Backtrack to step : B ∶= false Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Backtrack to step : B ∶= false {C, D}, {¬C, ¬D} Step : C ∶= true Example Φ ∶= {{A, B, ¬C}, {¬B, C, D}, {¬A, ¬B, ¬D}, {B, C, D}, {¬A, ¬B, ¬C}, {¬A, ¬C, ¬D}} Step : A ∶= true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Backtrack to step : B ∶= false {C, D}, {¬C, ¬D} Step : C ∶= true {¬D} satisfiable Solution: A = true, B = false, C = true, D = false The Satisfiability Problem Theorem -SAT (satisfiability for formulae in -CNF) is NP-complete. Proof Turing machine M = ⟨Q, Σ, ∆, q, F+, F−⟩ Q set of states Σ tape alphabet ∆ set of transitions ⟨p, a, b, m, q⟩ ∈ Q × Σ × Σ × {−, , } × Q q initial state F+ accepting states F− rejecting states nondeterministic, runtime bounded by the polynomial r(n) Proof Turing machine M = ⟨Q, Σ, ∆, q, F+, F−⟩ Q set of states Σ tape alphabet ∆ set of transitions ⟨p, a, b, m, q⟩ ∈ Q × Σ × Σ × {−, , } × Q q initial state F+ accepting states F− rejecting states nondeterministic, runtime bounded by the polynomial r(n) Encoding in PL St,q state q at time t Ht,k head in field k at time t Wt,k,a letter a in field k at time t φw ∶= ⋀ t