Informatics 1 Computation and Logic Boolean Algebra CNF DNF Michael Fourman 1 Basic Boolean operations 1 , > true, top _ disjunction, or ^ conjunction, and negation, not ¬ 0 , ? false, bottom Boole (1815 – 1864) 2
If we use one bit (binary unit, Z 2 = { 0 , 1 } 0 or 1) to code each truth value, with ⋁ 0 1 + 0 1 x ∧ y ≡ xy 0 0 1 0 0 1 0 ~ ⊥ and 1 ~ ⊤ x ∨ y ≡ x + y − xy 1 1 1 1 1 0 ¬ x ≡ 1 − x then we can express the ⨉ 0 1 ⋀ 0 1 0 0 0 0 0 0 Here, we use arithmetic logical operations 1 0 1 1 0 1 mod 2 The same equations − ¬ algebraically. work if we use ordinary 0 0 0 1 arithmetic! 1 1 1 0 It doesn’t matter whether we 3 interpret these expressions in Z or in Z 2 The algebra of sets P ( S ) = { X | X ⊆ S } X ∨ Y = X ∪ Y union X ∧ Y = X ∩ Y intersection ¬ X = S \ Y complement 0 = ∅ empty set 1 = S entire set 4
Derived Operations Definitions: implication x → y ≡ ¬ x ∨ y x ← y ≡ x ∨ ¬ y x ↔ y ≡ ( ¬ x ∧ ¬ y ) ∨ ( x ∧ y ) equality (i ff ) x ⊕ y ≡ ( ¬ x ∧ y ) ∨ ( x ∧ ¬ y ) inequality (xor) Some equations: x ↔ y = ( x → y ) ∧ ( x ← y ) x ⊕ y = ¬ ( x ↔ y ) x ⊕ y = ¬ x ⊕ ¬ y x ↔ y = ¬ ( x ⊕ y ) x ↔ y = ¬ x ↔ ¬ y 5 Once we know the rules for iff an algebraic proof and xor shown on the right, we can give an algebraic ( x ↔ y ) ↔ z = ¬ ( x ↔ y ) ↔ ¬ z ( a ↔ b = ¬ a ↔ ¬ b ) proof that the xor = ( x ⊕ y ) ↔ ¬ z ( ¬ ( a ↔ b ) = a ⊕ b ) = ( x ⊕ y ) ⊕ z ( a ↔ ¬ b = a ⊕ b ) combination of three variables is the same as their iff combination 6
Boolean connectives Some equalities: x ∨ y = ¬ ( ¬ x ∧ ¬ y ) x ∧ y = ¬ ( ¬ x ∨ ¬ y ) ¬ x = x → 0 x ∨ y = ¬ x → y We will see that ∧ , ∨ , ¬ and ⊥ are su ffi cient to define any boolean function. These equations show that { ∧ , ¬ , ⊥ } , { ∨ , ¬ , ⊥ } , and { → , ⊥ } are all su ffi cient sets. 7 The equations above the gap Boolean Algebra define a Boolean algebra. Those below the line follow x ∨ ( y ∨ z ) = ( x ∨ y ) ∨ z x ∧ ( y ∧ z ) = ( x ∧ y ) ∧ z associative x ∨ ( y ∧ z ) = ( x ∨ y ) ∧ ( x ∨ z ) x ∧ ( y ∨ z ) = ( x ∧ y ) ∨ ( x ∧ z ) distributive x ∨ y = y ∨ x x ∧ y = y ∧ x commutative from these. x ∨ 0 = x x ∧ 1 = x identity x ∨ 1 = 1 x ∧ 0 = 0 annihilation x ∨ x = x x ∧ x = x idempotent x ∨ ¬ x = 1 ¬ x ∧ x = 0 complements x ∨ ( x ∧ y ) = x x ∧ ( x ∨ y ) = x absorbtion ¬ ( x ∨ y ) = ¬ x ∧ ¬ y ¬ ( x ∧ y ) = ¬ x ∨ ¬ y de Morgan ¬¬ x = x x → y = ¬ x ← ¬ y 8
Exercise 2.1 Which of the following rules are not valid for arithmetic? Which of the rules are not valid for arithmetic in Z 2 ? x + ( y + z ) = ( x + y ) + z x × ( y × z ) = ( x × y ) × z associative x + ( y × z ) = ( x + y ) × ( x + z ) x × ( y + z ) = ( x × y ) + ( x × z ) distributive x + y = y + x x × y = y × x commutative x + 0 = x x × 1 = x identity x + 1 = 1 x × 0 = x annihilation x + x = x x × x = x idempotent x + ( x × y ) = x x + ( x × y ) = x absorbtion x + − x = 1 x × − x = 0 complements 9 Exercise 2.4 (for mathematicians) In any Boolean algebra, define, x y ⌘ x ^ y = x 1. Show that, for any x , y , and z , 0 x and x x and x 1 x ! y = > i ff x y if x y and y z then x z if x y and y x then x = y if x y then ¬ y ¬ x 2. Show that, in any Boolean Algebra, x ^ y = x i ff x _ y = y 10
To determine whether to { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } expressions are equivalent, we The meaning of an expression is the set of states in which it is true. can check whether they give the same values for all 2^n ✔ states of the system. ✔ The meaning of an expression ✔ is the set of states in which it ✔ is true. 11 A boolean function of three { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } variables is given by a truth Disjunctive Normal Form (DNF) table with eight entries R ( x ) ∧ A ( x ) ∧ G ( x ) We can easily write down a ✔ ∨ R ( x ) ∧ ¬ A ( x ) ∧ ¬ G ( x ) disjunction of terms, each one ∨ ✔ ¬ R ( x ) ∧ ¬ A ( x ) ∧ G ( x ) of which corresponds to a ∨ ✔ ¬ R ( x ) ∧ A ( x ) ∧ ¬ G ( x ) single state in which the ✔ function is true. 12
Here we say that we are not in { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } a state where the function is false ✓ R ( x ) ∧ ¬ A ( x ) ∧ G ( x ) ¬ ✔ ∨ ¬ R ( x ) ∧ A ( x ) ∧ G ( x ) ∨ ✔ ¬ R ( x ) ∧ ¬ A ( x ) ∧ ¬ G ( x ) ∨ ✔ ◆ R ( x ) ∧ A ( x ) ∧ ¬ G ( x ) ✔ 13 Using de Morgan, this { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } becomes a conjunction of negated conjunctions. � � R ( x ) ∧ ¬ A ( x ) ∧ G ( x ) ¬ ✔ ∧ � � ¬ R ( x ) ∧ A ( x ) ∧ G ( x ) ¬ ∧ ✔ � � ¬ R ( x ) ∧ ¬ A ( x ) ∧ ¬ G ( x ) ¬ ∧ ✔ � � R ( x ) ∧ A ( x ) ∧ ¬ G ( x ) ¬ ✔ 14
Using de Morgan again, this { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } becomes a conjunction of Conjunctive Normal Form (CNF) disjunctions. � � ¬ R ( x ) ∨ A ( x ) ∨ ¬ G ( x ) We will return to CNF later. ✔ ∧ � � R ( x ) ∨ ¬ A ( x ) ∨ ¬ G ( x ) CNF ∧ ✔ � � R ( x ) ∨ A ( x ) ∨ G ( x ) ∧ ✔ � � ¬ R ( x ) ∨ ¬ A ( x ) ∨ G ( x ) ✔ 15 Exercise 2.2 Generate CNF for this subset 16
Exercise 2.3 Generate CNF for this subset 17 To produce conjunctive normal form (CNF) eliminate ⟶ ↔ push negations in push ⋁ inside ⋀ ¬ ( a → b ) = a ∧ ¬ b a → b = ¬ a ∨ b ¬ ( a ∨ b ) = ¬ a ∧ ¬ b ¬ ( a ∨ b ) = ¬ a ∧ ¬ b ¬ 0 = 1 ¬¬ a = a ¬ 1 = 0 a ∨ 1 = 1 a ∧ 0 = 0 a ∨ 0 = a a ∧ 1 = a a ∨ ( b ∧ c ) = ( a ∨ b ) ∧ ( a ∨ c ) ( a ∧ b ) ∨ c = ( a ∨ c ) ∧ ( b ∨ c ) 18
19 (A?B:C) if A then B else C 20
Recommend
More recommend