Normal Forms Boolean Satisfiability Sectoins 5.3 and 5.5 Prof. Sandy Irani
Normal Forms for Boolean Expressions Boolean expressions can be put into standardized forms. Useful for manipulating expressions systematically or automated reasoning Disjunctive Normal Form (DNF) Sum of products of literals. Conjunctive Normal Form (CNF) Product of sums of literals
Disjunctive Normal Form DNF: Sum of products of literals The sum of minterms expressions obtained from I/O tables is an example of DNF Form: f(x, y, z) = xҧ തy z ҧ + xҧ y z ҧ + x തy z For an expression to be in DNF, the product terms are not required to be minterms. The following Boolean expressions are all in DNF form: ഥx ഥy തz + ഥx + ഥy z uxഥyz + ഥx തz + y x + y + z xyz
Disjunctive Normal Form A Boolean expression is DNF if: 1. Multiplication only applied to literals 2. Complement only applied to variables The following expressions are not DNF: (x+y)z + xҧ തy zҧ z(x+y)u xyz + തy zҧ yz + xy
Conjunctive Normal Form CNF: Product of sums of literals The following Boolean expressions are all in CNF form: (ഥx + ഥy + തz)(x + y)(ഥu + x) u( ഥy + തz )y x + ഥy + z xyz
Conjunctive Normal Form A Boolean expression is CNF if: 1. Addition only applied to literals 2. Complement only applied to variables The following expressions are not CNF: (x+y+uz)( ഥy + തz ) zҧ xy + z ( x + y )( ഥy + തz )
CNF/DNF * Which Boolean expression is neither DNF nor CNF? A) തy + z ҧ + xҧ y(തu + z)(u ҧ + z) B) z + xy + y C) yതux zҧ D) z + തux z ҧ + y
CNF/DNF We know that every Boolean function has an equivalent DNF expression (sum of minterms). Does every Boolean function have an equivalent CNF expression?...yes. Worked out in homework! Which is better CNF or DNF? Depending on the function, one or the other may be more efficient (fewer variables and terms) DNF can be easier to work with CNF is natural for expressing certain kinds of constraints
Boolean Satisfiability (SAT) Input: Boolean expression with n variables Output: Yes/No Is there a setting of the n input variables that causes the Boolean expression to evaluate to 1? f(x, y, z) = z(x + തy)( z ҧ + x) ҧ f(x, y, z) = z(x + തy)( z ҧ + x)(y ҧ + z) ҧ
Boolean Satisfiability (SAT) * Which Boolean function is not satisfiable? A) തy + zҧ y(തu + z)(u ҧ + z) B) തu + തy y(തy + z)(u ҧ + z) C) x + z y( x ҧ + തy)(y + x) D xy(x + തy)( z ҧ + x)
Boolean Satisfiability (SAT) One way to check satisfiability is by truth table: f(x, y, z) = (z+y)(x + തy)( z ҧ + x)(z+തy)(y ҧ + z) ҧ x y z f(x,y,z) 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
Boolean Satisfiability (SAT) If a Boolean expression has 200 vairables, exhaustively searching the truth table could require as many as 2 200 function evaluations. 1 nanosecond per evaluation:.over a billion years!
Why is SAT Imporant? The language of Boolean logic can be used to express many important and practical computational problems. Efficient algorithm for SAT Efficient algorithm for all of those problems
Example Application of SAT Will use Boolean satisfiability to express a scheduling problem. If we can solve SAT, then we can solve the scheduling problem. Scheduling Classes: Input: Set of classes Set of time slots Constraints: certain pairs of classes can not be assigned to the same time slot Output: Is there a way to schedule all the classes that does not violate any of the constraints?
I: input to the scheduling problem n: number of classes k: number of time slots Pairs (j,k) class j and k can not be schedule during the same time Boolean Expression E. E is satisfiable if and only if there is a feasible schedule for I
Example Application of SAT For example: 5 Classes {A, B, C, D, E} 2 Time slots These pairs of classes can not be scheduled during the same time: (A, B), (C, D), (D, E), (B, E), (A, D) Boolean Variables: x A1, x B1, x C1, x D1, x E1, x A2, x B2, x C2, x D2, x E2 x C2 = 1 if class C is scheduled during time slot 2
Example Application of SAT Boolean Variables: x A1, x B1, x C1, x D1, x E1, x A2, x B2, x C2, x D2, x E2 x C2 = 1 if class C is scheduled during time slot 2 Create a Boolean expression that is a product of terms Each term represents a constraint: Boolean expression is satisfiable There is an assignment to variables in which every term equals 1 There is a schedule of the classes that satisfies all the constraints
Example Application of SAT Boolean Variables: x A1, x B1, x C1, x D1, x E1, x A2, x B2, x C2, x D2, x E2 x C2 = 1 if class C is scheduled during time slot 2 Boolean assignment must represent a valid schedule: Each class must be scheduled in exactly one time slot. For example, for class D: (x D1 + x D2 )( x D1 + x D2 ) D must be scheduled in at least one time slot D can not be scheduled in both time slots
Example Application of SAT Boolean Variables: x A1, x B1, x C1, x D1, x E1, x A2, x B2, x C2, x D2, x E2 x C2 = 1 if class C is scheduled during time slot 2 Constraint (D, E) means that D and E can not be scheduled in the same time slot: ( x D1 + x E1 )( x D2 + x E2 ) D and E can not both be scheduled in time slot 1 D and E can not both be scheduled in time slot 2
Put all the constraints together in one big product: x A1 + x A2 x A1 + x A2 x B1 + x B2 x B1 + x B2 x C1 + x C2 x C1 + x C2 x D1 + x D2 x D1 + x D2 (x E1 + x E2 )( x E1 + x E2 ) Each class scheduled in exactly one time slot. ( x A1 + x B1 )( x A2 + x B2 ) x C1 + x D1 x C2 + x D2 ( x D1 + x E1 )( x D2 + x E2 )( x B1 + x E1 )( x B2 + x E2 ) ( x A1 + x D1 )( x A2 + x D2 ) For constraints: (A, B), (C, D), (D, E), (B, E), (A, D) Note: this is a CNF expression.
Example Application of SAT * For example: 5 Classes {A, B, C, D, E} 2 Time slots These pairs of classes can not be scheduled during the same time: (A, B), (C, D), (D, E), (B, E), (A, D) Which assignment will cause the Boolean expression to evaluate to 1? A) x A1, x B2, x C1, x D2, x E1 = 1 x A2, x B1, x C2, x D1, x E2 = 0 B) x A1, x A2, x C1, x D2, x E1 = 1 x B1, x B2, x C2, x D1, x E2 = 0 C) x A1, x B2, x C1, x D1, x E1 = 1 x A2, x B1, x C2, x D2, x E2 = 0 D) x A1, x C1, x D1, x E1 = 1 x A2, x B1, x B2, x C2, x D2, x E2 = 0