boolean functions boolean expressions
play

Boolean Functions Boolean Expressions Let B = { 0 , 1 } . 1 ... - PowerPoint PPT Presentation

Boolean Functions Boolean Expressions Let B = { 0 , 1 } . 1 ... true, 0 ... false Let x 1 , x 2 , . . . , x n be boolean variables. Boolean Function of Arity n Semantics and Verification 2005 Abstract Syntax for Boolean Expressions ( x ranges


  1. Boolean Functions Boolean Expressions Let B = { 0 , 1 } . 1 ... true, 0 ... false Let x 1 , x 2 , . . . , x n be boolean variables. Boolean Function of Arity n Semantics and Verification 2005 Abstract Syntax for Boolean Expressions ( x ranges over variables) f : B n → B t , t 1 , t 2 ::= 0 | 1 | x | ¬ t | t 1 ∧ t 2 | t 1 ∨ t 2 | t 1 ⇒ t 2 | t 1 ⇔ t 2 Lecture 13 Boolean functions are often described using truth tables . Truth Assignment x 1 x 2 x 3 f ( x 1 , x 2 , x 3 ) 0 0 0 1 v : { x 1 , . . . , x n } → B 0 0 1 0 0 1 0 0 Function v is often written as [ v ( x 1 ) / x 1 , v ( x 2 ) / x 2 , . . . , v ( x n ) / x n ]. 0 1 1 1 boolean expressions and normal forms 1 0 0 1 Example: 1 0 1 1 binary decision diagrams (BDDs) boolean expression: ¬ ( x 1 ∧ x 2 ) ⇒ ( ¬ x 1 ∨ x 4 ) 1 1 0 0 algorithms on BDDs 1 1 1 1 truth assignment: [1 / x 1 , 0 / x 2 , 1 / x 3 , 1 / x 4 ] Problem: arity n gives truth table of size θ (2 n ). Lecture 13 () Semantics and Verification 2005 1 / 24 Lecture 13 () Semantics and Verification 2005 2 / 24 Lecture 13 () Semantics and Verification 2005 3 / 24 Evaluation of Boolean Expressions Terminology Conjunctive Normal Form (CNF) A boolean expression t defines a boolean function f t : B n → B by the Definitions Equivalent Boolean Expressions following (structural) rules: Literal is a boolean variable or its negation. Boolean expressions t 1 and t 2 are equivalent iff f t 1 = f t 2 , i.e., they yield t 1 t 2 t 1 ∧ t 2 t 1 t 2 t 1 ∨ t 2 Clause is a disjunction of literals. the same truth value for all truth assignments. t ¬ t 0 0 0 0 0 0 A boolean expression if CNF is a conjunction of clauses. Example: ¬ ( x 1 ∧ x 2 ) is equivalent to ¬ x 1 ∨ ¬ x 2 0 1 0 1 0 0 1 1 Example: ( x 1 ∨ ¬ x 3 ) ∧ ( ¬ x 1 ∨ x 2 ∨ x 3 ) ∧ ( x 2 ∨ ¬ x 3 ) 1 0 1 0 0 1 0 1 Tautology 1 1 1 1 1 1 A boolean expression t is a tautology if it yields true for all truth assignment. t 1 ⇒ t 2 t 1 ⇔ t 2 t 1 t 2 t 1 t 2 Theorem 0 0 1 0 0 1 For any boolean expression there is an equivalent one in CNF. Satisfiability 0 1 1 0 1 0 1 0 0 1 0 0 A boolean expression t is satisfiable if it yields true for at least one truth Cook’s Theorem 1 1 1 1 1 1 assignment. Satisfiability of boolean expressions (in CNF) is NP-complete. Lecture 13 () Semantics and Verification 2005 4 / 24 Lecture 13 () Semantics and Verification 2005 5 / 24 Lecture 13 () Semantics and Verification 2005 6 / 24

  2. Combinatorial Circuits Representations of Boolean Functions If-Then-Else Operator Let t , t 1 and t 2 be boolean expressions. Problems over Boolean Expressions are Hard Syntax Many problems related to boolean expressions are hard from the t → t 1 , t 2 theoretical point of view (NP-complete or co-NP-complete). Semantics Our Aim If-Then-Else operator t → t 1 , t 2 is equivalent to ( t ∧ t 1 ) ∨ ( ¬ t ∧ t 2 ) . We are looking for t t 1 t 2 t → t l , t 2 compact representation and 0 0 0 0 efficient manipulation 0 0 1 1 0 1 0 0 with boolean expressions for real-life examples. 0 1 1 1 Are these two circuits equivalent? 1 0 0 0 1 0 1 0 co-NP-hard problem! We will have a look at Binary Decision Diagrams (BDDs) [Randal E. 1 1 0 1 Bryant’86]. 1 1 1 1 Lecture 13 () Semantics and Verification 2005 7 / 24 Lecture 13 () Semantics and Verification 2005 8 / 24 Lecture 13 () Semantics and Verification 2005 9 / 24 If-Then-Else Normal Form Shannon’s Expansion Law Binary Decision Diagrams Let the set of boolean variables be { x 1 , . . . , x n } . Let t be a boolean expression and x a variable. We define boolean expressions Binary Decision Diagram (BDD) Definition t [0 / x ] where every occurrence of x in t is replaced with 0, and A BDD is a rooted, directed, acyclic graph ( V , E ) such that A boolean expression is in If-Then-Else normal form (INF) iff it is given t [1 / x ] where every occurrence of x in t is replaced with 1. 0 , 1 ∈ V (representing false and true) and the nodes 0 and 1 have no by the following abstract syntax outgoing edges t , t 1 , t 2 ::= 0 | 1 | x → t 1 , t 2 every node v ∈ V � { 0 , 1 } has exactly two successors low ( v ) ∈ V and Shannon’s Expansion Law high ( v ) ∈ V Let x be an arbitrary boolean variable. Any boolean expressions t is where x ranges over boolean variables. every node v ∈ V � { 0 , 1 } has a label var ( v ) ∈ { x 1 , . . . , x n } . equivalent to x → t [1 / x ] , t [0 / x ] . Example: x 1 → ( x 2 → 1 , 0) , 0 (equivalent to x 1 ∧ x 2 ) Assume a given total ordering < on boolean variables. Boolean expressions in INF can be drawn as decision trees . Ordered BDD Corollary A BDD is ordered if on all paths from the root the variables respect the For any boolean expression there is an equivalent one in INF. ordering < . Lecture 13 () Semantics and Verification 2005 10 / 24 Lecture 13 () Semantics and Verification 2005 11 / 24 Lecture 13 () Semantics and Verification 2005 12 / 24

  3. � � � � � � � Canonicity of ROBDDs Reduced Ordered BDDs (ROBDDs) Ordering of Variables (Exponential Difference in Size) ( x 1 ⇔ x 2 ) ∧ ( x 3 ⇔ x 4 ) ∧ ( x 5 ⇔ x 6 ) ∧ ( x 7 ⇔ x 8 ) Reduced BDD Canonicity Lemma For any boolean function f : B n → B and a given ordering of variables A BDD is reduced iff for all nodes u , v ∈ V � { 0 , 1 } : x1 x1 x 1 < x 2 < · · · < x n there is exactly one ROBDD with root u which 1 low ( u ) � = high ( u ) x3 x3 x2 x2 describes the function f , i,e. 2 low ( u ) = low ( v ) and high ( u ) = high ( v ) and var ( u ) = var ( v ) implies x3 x5 x5 x5 x5 that u = v . t u [ v 1 / x 1 , . . . , v n / x n ] = f ( v 1 , . . . , v n ) x4 x4 x7 x7 x7 x7 x7 x7 x7 x7 for all ( v 1 , . . . , v n ) ∈ B n . ROBDD with a root node u describes a boolean expression t u according to x5 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 x2 the following (inductive) definition: x6 x6 x4 x4 x4 x4 x4 x4 x4 x4 t 0 def Consequences: = 0 x7 x6 x6 x6 x6 t 1 def = 1 A given ROBDD with root u is tautology iff u = 1. x8 x8 x8 x8 t u def = var ( u ) → t high ( u ) , t low ( u ) A given ROBDD with root u is satisfiable iff u � = 0. 1 1 x 1 < x 2 < · · · < x 8 x 1 < x 3 < x 5 < x 7 < x 2 < x 4 < x 6 < x 8 Lecture 13 () Semantics and Verification 2005 13 / 24 Lecture 13 () Semantics and Verification 2005 14 / 24 Lecture 13 () Semantics and Verification 2005 15 / 24 Representing ROBDDs in Memory – Array Implementation Makenode and Reducedness of BDDs Building an ROBDD from a Boolean Expression Table T : Let t be a boolean expression and x 1 < x 2 < · · · < x n . Assume x 1 < x 2 < x 3 . T : u �→ ( var ( u ) , low ( u ) , high ( u )) H : ( var , low , high ) �→ u ���� ���� u �→ ( var ( u ) , low ( u ) , high ( u )) Build( t , 1 ) builds a corresponding ROBDD and returns its root. x 1 � 6 u var low high Makenode ( var , low , high ): Node = � ����� � � � 0 4 - - � if low = high then Build ( t , i ): Node = � ���� ���� ���� ���� � � 1 4 - - return low if i > n then x 2 x 2 � 4 � 5 2 3 0 1 else if t is true then return 0 else return 1 � ����� � � � � � 3 3 1 0 u := H ( var , low , high ) � � else � � � � ���� ���� ���� ���� � � 4 2 0 2 � � if u � = undef then low := Build( t [0 / x i ] , i + 1) x 3 x 3 � 2 3 5 2 2 3 return u high := Build( t [1 / x i ] , i + 1) ���������������������� � � � � � � � � � � 6 1 4 5 else var := i � � � � add a new node (row) to T with attributes ( var , low , high ) � return Makenode( var , low , high ) Inverse table H : 0 1 return H ( var , low , high ) end if ( var , low , high ) �→ u . end if Complexity: exponentially many recursive calls! end if Example: T (4) = (2 , 0 , 2), H (1 , 4 , 5) = 6, and H (3 , 0 , 2) = undef . Is this necessary? Yes, checking if t is a tautology is co-NP-hard! Lecture 13 () Semantics and Verification 2005 16 / 24 Lecture 13 () Semantics and Verification 2005 17 / 24 Lecture 13 () Semantics and Verification 2005 18 / 24

Recommend


More recommend