informatics 1
play

Informatics 1 Computation and Logic Boolean Algebra CNF DNF - PDF document

Informatics 1 Computation and Logic Boolean Algebra CNF DNF Michael Fourman 1 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


  1. Informatics 1 Computation and Logic Boolean Algebra CNF DNF Michael Fourman 1

  2. 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. 2

  3. 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. This is called a 3 Disjunctive Normal Form (DNF)

  4. We can do things differently. { x | G ( x ) ↔ R ( x ) ↔ A ( x ) } Here we say that we are not in a state where the function is 𐄃 ✓ R ( x ) ∧ ¬ A ( x ) ∧ G ( x ) ¬ false ✔ 𐄃 ∨ ¬ R ( x ) ∧ A ( x ) ∧ G ( x ) 𐄃 ∨ ✔ ¬ R ( x ) ∧ ¬ A ( x ) ∧ ¬ G ( x ) 𐄃 ∨ ✔ ◆ R ( x ) ∧ A ( x ) ∧ ¬ G ( x ) ✔ 4

  5. 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 ) ¬ ✔ 5

  6. 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 ) ✔ 6

  7. Exercise 2.2 Generate CNF for this subset 7

  8. Exercise 2.3 Generate CNF for this subset 8

  9. We can transform any Boolean To produce conjunctive normal form (CNF) 
 expression algebraically to eliminate ——— 
 ↔ → create an equivalent CNF push negations in 
 push ⋁ inside ⋀ ¬ ( a → b ) = a ∧ ¬ b a ↔ b = ( a → b ) ∧ ( b → a ) a → b = ¬ a ∨ b ¬ ( a ∨ b ) = ¬ a ∧ ¬ b ¬ ( a ∨ b ) = ¬ a ∧ ¬ b ¬ 0 = 1 ¬¬ a = a ¬ 1 = 0 a ∨ 1 = 1 a ∨ ( b ∧ c ) = ( a ∨ b ) ∧ ( a ∨ c ) a ∧ 0 = 0 a ∨ 0 = a a ∨ ¬ a = 1 a ∧ ¬ a = 0 a ∧ 1 = a 9

  10. In this case, once we have eliminate ↔ eliminated implications, we → have CNF . Clauses with only two literals R ↔ A = ( R → A ) ∧ ( A → R ) = ( ¬ R ∨ A ) ∧ ( ¬ A ∨ R ) correspond to implications. 10

  11. Here, we use the previous eliminate result to re-write the part in ↔ → parentheses. R ↔ A = ( R → A ) ∧ ( A → R ) = ( ¬ R ∨ A ) ∧ ( ¬ A ∨ R ) G ↔ ( R ↔ A ) = � ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) � ∧ � � ¬ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∨ G 11

  12. push negations in G ↔ ( R ↔ A ) � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � ¬ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∨ G � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � ( ¬ ( ¬ R ∨ A ) ∨ ¬ ( ¬ A ∨ R )) ∨ G � � 12

  13. push negations in G ↔ ( R ↔ A ) � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � ¬ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∨ G � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � ( ¬ ( ¬ R ∨ A ) ∨ ¬ ( ¬ A ∨ R )) ∨ G � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � (( R ∧ ¬ A ) ∨ ( A ∧ ¬ R )) ∨ G 13

  14. push ⋁ inside ⋀ G ↔ ( R ↔ A ) � � = ¬ G ∨ (( ¬ R ∨ A ) ∧ ( ¬ A ∨ R )) ∧ � � (( R ∧ ¬ A ) ∨ ( A ∧ ¬ R )) ∨ G � � = (( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R )) ∧ � � (( R ∧ ¬ A ) ∨ ( A ∧ ¬ R )) ∨ G 14

  15. push ⋁ inside ⋀ G ↔ ( R ↔ A ) = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ � � (( R ∧ ¬ A ) ∨ ( A ∧ ¬ R )) ∨ G = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ � � (( R ∨ A ) ∧ ( ¬ A ∨ A ) ∧ ( R ∨ ¬ R ) ∧ ( ¬ A ∨ ¬ R )) ∨ G 15

  16. ¬ A _ A = > simplify R _ ¬ R = > x ^ > = x G ↔ ( R ↔ A ) = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ � � (( R ∨ A ) ∧ ( ¬ A ∨ A ) ∧ ( R ∨ ¬ R ) ∧ ( ¬ A ∨ ¬ R )) ∨ G = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ � � (( R ∨ A ) ∧ ( ¬ A ∨ ¬ R )) ∨ G 16

  17. push ⋁ inside ⋀ G ↔ ( R ↔ A ) = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ � � (( R ∨ A ) ∧ ( ¬ A ∨ ¬ R )) ∨ G = ( ¬ G ∨ ¬ R ∨ A ) ∧ ( ¬ G ∨ ¬ A ∨ R ) ∧ ( R ∨ A ∨ G ) ∧ ( ¬ A ∨ ¬ R ∨ G ) 17

  18. check! G ↔ ( R ↔ A ) = 𐄃 ( ¬ G ∨ ¬ R ∨ A ) ✔ ∧ 𐄃 ( ¬ G ∨ ¬ A ∨ R ) 𐄃 ∧ ( R ∨ A ∨ G ) ✔ 𐄃 ∧ ✔ ( ¬ A ∨ ¬ R ∨ G ) ✔ 18

  19. 19

  20. (A?B:C) if A then B else C 20

Recommend


More recommend