IA008: Computational Logic 1. 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 ψ ⊧ φ ▸ 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 ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ 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 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 1: A = true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Step 2: B = true {C, D}, {¬D}, {¬C}, {¬C, ¬D} Step 3: 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 1: A = true {¬B, C, D}, {¬B, ¬D}, {B, C, D}, {¬B, ¬C}, {¬C, ¬D} Backtrack to step 2: B = false {C, D}, {¬C, ¬D} Step 3: C = true {¬D} satisfiable Solution: A = true, B = false, C = true, D = false Expressing graph problems Vertex cover Variables: Cv vertex v belongs to the cover Formulae: Cu ∨ Cv for every edge ⟨u, v⟩ ∈ E Size≤ k “At most k of the Cv are true.” Clique Variables: Cv vertex v belongs to the clique Formulae: ¬Cu ∨ ¬Cv for every non-edge ⟨u, v⟩ ∉ E Size≥ k “At least k of the Cv are true.” Expressing graph problems The Size≥ k formulae Fix an enumeration v0, . . . , vn−1 of V. Variables: Sk m at least k variables Cvi with i < m are true Formulae: S0 m ¬Sk 0 for k > 0 Cvi → [Sk i ↔ Sk+1 i+1 ] ¬Cvi → [Sk i ↔ Sk i+1] Sk n v0 v1 v2 Cvi 1 0 1 S0 i 1 1 1 1 S1 i 0 1 1 1 S2 i 0 0 0 1 S3 i 0 0 0 0 A similar construction works for Size≤ k . The Satisfiability Problem Theorem 3-SAT (satisfiability for formulae in 3-CNF) is NP-complete. Proof Given Turing machine M and input w, construct formula φ such that M accepts w iff φ is satisfiable. 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