PROPOSITIONAL LOGIC: MORE ON NORMAL FORMS

VL Logic, Lecture 3, WS 20/21

Armin Biere, Martina Seidl Institute for Formal Models and Verification Johannes Kepler University Linz PROPOSITIONAL FORMULAS: SATISFIABILITY EQUIVALENCES

VL Logic Part I: Propositional Logic Recap: Semantic Equivalence

Two formulas φ and ψ are semanticly equivalent (written as φ ⇔ ψ) iff forall interpreta-

tions [.]ν it holds that [φ]ν = [ψ]ν.

 ⇔ is a meta-symbol, i.e., it is not part of the language.  φ ⇔ ψ iff φ ↔ ψ is valid, i.e., we can express semantics by means of syntactics.  If φ and ψ are not equivalent, we write φ 6⇔ ψ.

Example:  a ∨ ¬a 6⇔ b → ¬b  (a ∨ b) ∧ ¬(a ∨ b) ⇔ ⊥  a ∨ ¬a ⇔ b ∨ ¬b  a ↔ (b ↔ c) ⇔ (a ↔ b) ↔ c

1/3 Satisfiability Equivalence

Two formulas φ and ψ are satisfiability-equivalent (written as φ ⇔S AT ψ) iff both formu- las are satisfiable or both are contradictory.

 Satisfiability-equivalent formulas are not necessarily satisfied by the same assignments.  Satisfiability equivalence is a weaker property than semantic equivalence.  Often sufficient for simplification rules: If the complicated formula is satisfiable then also the simplified formula is satisfiable.

2/3 Example: Satisfiability Equivalence

positive pure literal elimination rule: If a literal x occurs in an NNF formula but ¬x does not occur in this formula, then x can be substituted by >. The resulting formula is satisfiability-equivalent.

Example:

 x ⇔S AT >, but x 6⇔ >

 (a ∧ b) ∨ (¬c ∧ a) ⇔S AT b ∨ ¬c, but (a ∧ b) ∨ (¬c ∧ a) 6⇔ b ∨ ¬c

3/3 PROPOSITIONAL FORMULAS: FUNCTIONAL COMPLETENESS

VL Logic Part I: Propositional Logic Examples of Semantic Equivalences (1/2)

φ ∧ ψ ⇔ ψ ∧ φ φ ∨ ψ ⇔ ψ ∨ φ commutativity

φ ∧ (ψ ∧ γ) ⇔ (φ ∧ ψ) ∧ γ φ ∨ (ψ ∨ γ) ⇔ (φ ∨ ψ) ∨ γ associativity

φ ∧ (φ ∨ ψ) ⇔ φ φ ∨ (φ ∧ ψ) ⇔ φ absorption

φ ∧ (ψ ∨ γ) ⇔ (φ ∧ ψ) ∨ (φ ∧ γ) φ ∨ (ψ ∧ γ) ⇔ (φ ∨ ψ) ∧ (φ ∨ γ) distributivity

¬(φ ∧ ψ) ⇔ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ⇔ ¬φ ∧ ¬ψ laws of De Morgan

φ ↔ ψ ⇔ (φ → ψ) ∧ (ψ → φ) φ ↔ ψ ⇔ (φ ∧ ψ) ∨ (¬φ ∧ ¬ψ) synt. equivalence

1/3 Examples of Semantic Equivalences (2/2)

φ ∨ ψ ⇔ ¬φ → ψ φ → ψ ⇔ ¬ψ → ¬φ implications

φ ∧ ¬φ ⇔ ⊥ φ ∨ ¬φ ⇔ > complement

¬¬φ ⇔ φ double

φ ∧ > ⇔ φ φ ∨ ⊥ ⇔ φ neutrality

φ ∨ > ⇔ > φ ∧ ⊥ ⇔ ⊥

¬> ⇔ ⊥ ¬⊥ ⇔ >

2/3 Functional Completeness

 In propositional logic there are  2 functions of arity 0 (>, ⊥)  4 functions of arity 1 (e.g., not)  16 functions of arity 2 (e.g., and, or, ...) n  22 functions of arity n.  A function of arity n has 2n different combinations of arguments (lines in the truth table).  A functions maps its arguments either to 1 or 0.

A set of functions is called functional complete for propositional logic iff it is possible to express all other functions of propositional logic with functions from this set.

{¬, ∧}, {¬, ∨}, {nand} are functional complete.

3/3 PROPOSITIONAL FORMULAS: NORMAL FORMS

VL Logic Part I: Propositional Logic Negation Normal Form (1/2)

Negation Normal Form (NNF) is defined as follows:  Literals and truth constants are in NNF;  φ ◦ ψ (◦ ∈ {∨, ∧}) is in NNF iff φ and ψ are in NNF;  no other formulas are in NNF.

In other words: A formula in NNF contains only conjunctions, disjunctions, and and negations only occur in front of variables and constants.

1/7 Negation Normal Form (2/2)

If a formula is in negation normal form then

 in the formula tree, nodes with negation symbols only occur directly before leaves.  there are no subformulas of the form ¬φ where φ is something else than a variable or a constant.  it does not contain NAND, NOR, XOR, equivalence, and implication connectives.

Example: The formula ((x ∨ ¬x1) ∧ (x ∨ (¬z ∨ ¬x1))) is in NNF but

¬((x ∨ ¬x1) ∧ (x ∨ (¬z ∨ ¬x1))) is not in NNF.

2/7 (CNF)

A propositional formula is in conjunctive normal form (CNF) iff it is a conjunction of clauses.

A formula in conjunctive normal form is

 in negation normal form  > if it contains no clauses  easy to check whether it can be refuted remark: CNF is the input of most SAT-solvers (DIMACS format)

3/7 (DNF)

A propositional formula is in disjunctive normal form (DNF) if it is a disjunction of cubes.

A formula in disjunctive normal form is

 in negation normal form  ⊥ if it contains no cubes  easy to check whether it can be satisfied

4/7 Examples for CNF and DNF

Examples CNF

 >  l1 ∧ l2 ∧ l3

 ⊥  l1 ∨ l2 ∨ l3

 a  (a1 ∨ ¬a2) ∧ (a1 ∨ b2 ∨ a2) ∧ a2 ∨ ∨ ∧ ∧ ∨ ∨  ¬a  ((l11 ... l1m1 ) ... (ln1 ... lnmn ))

Examples DNF

 >  l1 ∧ l2 ∧ l3

 ⊥  l1 ∨ l2 ∨ l3

 a  (a1 ∧ ¬a2) ∨ (a1 ∧ b2 ∧ a2) ∨ a2 ∧ ∧ ∨ ∨ ∧ ∧  ¬a  ((l11 ... l1m1 ) ... (ln1 ... lnmn ))

5/7 Representing Functions as CNFs

 Problem: Given the truth table of a φ. How is the function represented in propositional logic?

a b c φ clauses 0 0 0 0 a ∨ b ∨ c Solution (in CNF): 0 0 1 1 0 1 0 1 1. Represent each assignment ν where φ has 0 1 1 0 a ∨ ¬b ∨ ¬c value 0 as clause: 1 0 0 1  If variable x is 1 in ν, add ¬x to clause. 1 0 1 0 ¬a ∨ b ∨ ¬c  If variable x is 0 in ν, add x to clause. 1 1 0 0 ¬a ∨ ¬b ∨ c 1 1 1 1 2. Connect all clauses by conjunction. φ = (a ∨ b ∨ c) ∧ (a ∨ ¬b ∨ ¬c) ∧ (¬a ∨ b ∨ ¬c) ∧ (¬a ∨ ¬b ∨ c)

6/7 Representing Functions as DNFs

 Problem: Given the truth table of a Boolean function φ. How is the function represented in propositional logic?

a b c φ cubes 0 0 0 0 0 0 1 1 ¬a ∧ ¬b ∧ c Solution (in DNF): 0 1 0 1 ¬a ∧ b ∧ ¬c 1. Represent each assignment ν where φ 0 1 1 0 has value 1 as cube: 1 0 0 1 a ∧ ¬b ∧ ¬c 1 0 1 0  If variable x is 1 in ν, add x to cube. 1 1 0 0 ¬  If variable x is 0 in ν, add x to cube. 1 1 1 1 a ∧ b ∧ c 2. Connect all cubes by disjunction. φ = (¬a ∧ ¬b ∧ c) ∨ (¬a ∧ b ∧ ¬c) ∨ (a ∧ ¬b ∧ ¬c) ∨ (a ∧ b ∧ c)

7/7 PROPOSITIONAL FORMULAS: NORMAL FORM TRANSFORMATION

VL Logic Part I: Propositional Logic Transformation to Conjunctive Normal Form 1

Approach 1: Transformation by “multiplication”

1. Remove ↔, →, ⊕ as follows:  φ ↔ ψ ⇔ (φ → ψ) ∧ (ψ → φ)  φ → ψ ⇔ ¬φ ∨ ψ,  φ ⊕ ψ ⇔ (φ ∨ ψ) ∧ (¬φ ∨ ¬ψ) 2. Transform formula to negation normal form (NNF) by  application of laws of De Morgan  elimination of double negation 3. Transform formula to CNF by laws of distributivity

1/5 Example: Transformation to CNF 1

Transformation of ¬(a ↔ b) → (¬(c ∧ d) ∧ e) to an equivalent formula in CNF by approach 1

1. a) remove equivalences: ⇔ ¬((a → b) ∧ (b → a)) → (¬(c ∧ d) ∧ e) b) remove implications: ⇔ ¬¬((¬a ∨ b) ∧ (¬b ∨ a)) ∨ (¬(c ∧ d) ∧ e) 2. NNF: ⇔ ((¬a ∨ b) ∧ (¬b ∨ a)) ∨ ((¬c ∨ ¬d) ∧ e) 3. ⇔ ((¬a ∨ b) ∨ ((¬c ∨ ¬d) ∧ e))) ∧ ((¬b ∨ a) ∨ ((¬c ∨ ¬d) ∧ e))) ⇔ (¬a ∨ b ∨ ¬c ∨ ¬d) ∧ (¬a ∨ b ∨ e) ∧ (¬b ∨ a ∨ ¬c ∨ ¬d) ∧ (¬b ∨ a ∨ e)

2/5 Transformation to Conjunctive Normal Form 2

Approach 2: Transformation by introducing labels for subformulas Given formula φ. The following approach transforms φ to an equi-satisfiable formula in CNF.

1. Introduce new label `ψ for each subformula ψ that is not a literal 0 0 2. Collect all definitions `ψ ↔ ψ in a big conjunction Φ (ψ0 is obtained from ψ by replacing its immediate subformulas by the respective labels) 3. Transform Φ0 to CNF Φ by approach 1 (no exponential blowup!)

(Φ ∧ `φ) and φ are equi-satisfiable

3/5 Example: Transformation to CNF 2

Transform φ := ¬(a ↔ b) → (¬(c ∧ d) ∧ e) to an equi-satisfiable formula in CNF

definitions Φ0 clauses Φ

v1 ↔ (a ↔ b) (¯v1 ∨ a¯ ∨ b), (¯v1 ∨ a ∨ b¯), (v1 ∨ a¯ ∨ b¯), (v1 ∨ a ∨ b)

v2 ↔ ¬v1 (v1 ∨ v2), (¯v1 ∨ v¯2)

v3 ↔ (c ∧ d) (¯v3 ∨ c), (¯v3 ∨ d), (v3 ∨ c¯ ∨ d¯)

v4 ↔ ¬v3 (v3 ∨ v4), (¯v3 ∨ v¯4)

v5 ↔ (v4 ∧ e) (¯v5 ∨ v4), (¯v5 ∨ e), (v5 ∨ v¯4 ∨ e¯)

v6 ↔ (v2 → v5) (¯v6 ∨ v¯2 ∨ v5), (v2 ∨ v6), (¯v5 ∨ v6)

(Φ ∧ v6) and φ are equi-satisfiable.

4/5 Some Remarks on Normal Forms

 Approach 1 is exponential in the worst case (e.g., transform

(a1 ∧ b1) ∨ (a2 ∧ b2) ∨ · · · ∨ (an ∧ bn) to CNF).  Approach 2 is polynomial  Basic idea: introduce labels for subformulas.  Also works for formulas with sharing (circuits).  Also known as “Tseitin Encoding”.

 CNF is usually not easier to solve, but easier to handle:  compact data structures: a CNF is simply a list of lists of literals.

 CNF very popular in practice: standard input format DIMACS  To solve satisfiability of CNF, there are many optimization techniques and dedicated algorithms.

5/5 PROPOSITIONAL FORMULAS: RESOLUTION

VL Logic Part I: Propositional Logic Resolution

 the resolution calculus consists of the single resolution rule Example x ∨ C ¬x ∨ D one application of resolution C ∨ D x ∨ y ∨ ¬z ¬x ∨ y0 ∨ ¬z  C and D are (possibly empty) clauses y ∨ ¬z ∨ y0  the clause C ∨ D is called resolvent derivation of empty clause:  variable x is called pivot y ¬y  usually antecedent clauses x ∨ C and ¬x ∨ D ⊥

are assumed not to be tautological derivation of tautology: resolution is sound and complete. x ∨ a ¬x ∨ ¬a  a ∨ ¬a

 the resolution calculus works only on formulas in CNF  if the empty clause can be derived then the formula is unsatisfiable  if no new clause can be generated by application of the resolution rule then the formula is satisfiable

1/2 Resolution Example

We prove unsatisfiability of

{(¬x1 ∨ ¬x5), (x4 ∨ x5), (x2 ∨ ¬x4), (x3 ∨ ¬x4), (¬x2 ∨ ¬x3), (x1 ∨ x4 ∨ ¬x6), (x6)} as follows:

¬x1 ∨ ¬x5 x4 ∨ x5 x2 ∨ ¬x4 x3 ∨ ¬x4 ¬x2 ∨ ¬x3 x1 ∨ x4 ∨ ¬x6 x6

¬x2 ∨ ¬x4

¬x4

x5 x1 ∨ ¬x6 ¬x1 x1

2/2