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

informatics 1
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Informatics 1

Computation and Logic

Boolean Algebra CNF DNF Michael Fourman

1

slide-2
SLIDE 2

{x | G(x) ↔ R(x) ↔ A(x)}

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

The meaning of an expression is the set of states in which it is true.

2

To determine whether to expressions are equivalent, we 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.

slide-3
SLIDE 3

{x | G(x) ↔ R(x) ↔ A(x)}

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

R(x) ∧ A(x) ∧ G(x) ∨ R(x) ∧ ¬A(x) ∧ ¬G(x) ∨ ¬R(x) ∧ ¬A(x) ∧ G(x) ∨ ¬R(x) ∧ A(x) ∧ ¬G(x)

Disjunctive Normal Form (DNF)

3

A boolean function of three variables is given by a truth table with eight entries We can easily write down a disjunction of terms, each one

  • f which corresponds to a

single state in which the function is true. This is called a Disjunctive Normal Form (DNF)

slide-4
SLIDE 4

{x | G(x) ↔ R(x) ↔ A(x)}

¬ ✓ R(x) ∧ ¬A(x) ∧ G(x) ∨ ¬R(x) ∧ A(x) ∧ G(x) ∨ ¬R(x) ∧ ¬A(x) ∧ ¬G(x) ∨ R(x) ∧ A(x) ∧ ¬G(x) ◆

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

4

We can do things differently. Here we say that we are not in a state where the function is false

slide-5
SLIDE 5

{x | G(x) ↔ R(x) ↔ A(x)}

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

¬

  • 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

Using de Morgan, this becomes a conjunction of negated conjunctions.

slide-6
SLIDE 6

{x | G(x) ↔ R(x) ↔ A(x)}

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

  • ¬R(x) ∨ A(x) ∨ ¬G(x)
  • R(x) ∨ ¬A(x) ∨ ¬G(x)
  • R(x) ∨ A(x) ∨ G(x)
  • ¬R(x) ∨ ¬A(x) ∨ G(x)
  • Conjunctive Normal Form (CNF)

6

Using de Morgan again, this becomes a conjunction of disjunctions. We will return to CNF later. CNF

slide-7
SLIDE 7

Exercise 2.2 Generate CNF for this subset

7

slide-8
SLIDE 8

Exercise 2.3 Generate CNF for this subset

8

slide-9
SLIDE 9

To produce conjunctive normal form (CNF)
 eliminate ——— 
 push negations in
 push ⋁ inside ⋀

9

¬(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

↔ →

We can transform any Boolean expression algebraically to create an equivalent CNF

slide-10
SLIDE 10

10

R ↔ A = (R → A) ∧ (A → R) = (¬R ∨ A) ∧ (¬A ∨ R)

eliminate ↔ →

In this case, once we have eliminated implications, we have CNF . Clauses with only two literals correspond to implications.

slide-11
SLIDE 11

eliminate

11

R ↔ A = (R → A) ∧ (A → R) = (¬R ∨ A) ∧ (¬A ∨ R) G ↔ (R ↔ A) =

  • ¬G ∨ ((¬R ∨ A) ∧ (¬A ∨ R))
  • ¬((¬R ∨ A) ∧ (¬A ∨ R)) ∨ G

Here, we use the previous result to re-write the part in parentheses.

slide-12
SLIDE 12

push negations in

12

G ↔ (R ↔ A) =

  • ¬G ∨ ((¬R ∨ A) ∧ (¬A ∨ R))
  • ¬((¬R ∨ A) ∧ (¬A ∨ R)) ∨ G
  • =
  • ¬G ∨ ((¬R ∨ A) ∧ (¬A ∨ R))
  • (¬(¬R ∨ A) ∨ ¬(¬A ∨ R)) ∨ G
slide-13
SLIDE 13

push negations in

13

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
slide-14
SLIDE 14

push ⋁ inside ⋀

14

G ↔ (R ↔ A) =

  • ¬G ∨ ((¬R ∨ A) ∧ (¬A ∨ R))
  • ((R ∧ ¬A) ∨ (A ∧ ¬R)) ∨ G
  • =
  • ((¬G ∨ ¬R ∨ A) ∧ (¬G ∨ ¬A ∨ R))
  • ((R ∧ ¬A) ∨ (A ∧ ¬R)) ∨ G
slide-15
SLIDE 15

push ⋁ inside ⋀

15

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
slide-16
SLIDE 16

simplify

16

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
  • ¬A _ A = >

R _ ¬R = > x ^ > = x

slide-17
SLIDE 17

push ⋁ inside ⋀

17

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)

slide-18
SLIDE 18

check!

18

✔ ✔ ✔ ✔

𐄃 𐄃 𐄃 𐄃

G ↔ (R ↔ A) = (¬G ∨ ¬R ∨ A) ∧ (¬G ∨ ¬A ∨ R) ∧ (R ∨ A ∨ G) ∧ (¬A ∨ ¬R ∨ G)

slide-19
SLIDE 19

19

slide-20
SLIDE 20

(A?B:C)

20

if A then B else C