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 ∧, ∨, ¬, →, ↔ Semantics J ⊧ φ J Variables → {true, false} Examples φ = A ∧ (A → B) → B , ψ = ¬(A ∧ B) ↔ (¬A ∨ ¬B) . Terminology ▸ entailment φ ⊧ ψ (do not confuse with J ⊧ φ!) ▸ equivalence φ ≡ ψ (do not confuse with φ = ψ!) ▸ φ ≡ ψ iff φ ⊧ ψ and ψ ⊧ φ Terminology ▸ entailment φ ⊧ ψ (do not confuse with J ⊧ φ!) ▸ equivalence φ ≡ ψ (do not confuse with φ = ψ!) ▸ φ ≡ ψ 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 φ ⊧ ψ (do not confuse with J ⊧ φ!) ▸ equivalence φ ≡ ψ (do not confuse with φ = ψ!) ▸ φ ≡ ψ 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 φ ⊧ ψ (do not confuse with J ⊧ φ!) ▸ equivalence φ ≡ ψ (do not confuse with φ = ψ!) ▸ φ ≡ ψ 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 φ ⊧ ψ (do not confuse with J ⊧ φ!) ▸ equivalence φ ≡ ψ (do not confuse with φ = ψ!) ▸ φ ≡ ψ 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. Equivalence Transformations De Morgan’s laws ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ Equivalence Transformations De Morgan’s laws ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ Distributive laws φ ∧ (ψ ∨ ϑ) ≡ (φ ∧ ψ) ∨ (φ ∧ ϑ) φ ∨ (ψ ∧ ϑ) ≡ (φ ∨ ψ) ∧ (φ ∨ ϑ) 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, Σ, ∆, q0, F+, F−⟩ Q set of states Σ tape alphabet ∆ set of transitions ⟨p, a, b, m, q⟩ ∈ Q × Σ × Σ × {−1, 0, 1} × Q q0 initial state F+ accepting states F− rejecting states nondeterministic, runtime bounded by the polynomial r(n) Proof Turing machine M = ⟨Q, Σ, ∆, q0, F+, F−⟩ Q set of states Σ tape alphabet ∆ set of transitions ⟨p, a, b, m, q⟩ ∈ Q × Σ × Σ × {−1, 0, 1} × Q q0 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