Download presentation

Presentation is loading. Please wait.

Published byDayton Bircher Modified over 2 years ago

1
CS1022 Computer Programming & Principles Lecture 9.1 Boolean Algebra (1)

2
Plan of lecture Introduction Boolean operations Boolean algebra vs. logic Boolean expressions Laws of Boolean algebra Boolean functions Disjunctive normal form 2 CS1022

3
Introduction Boolean algebra Is a logical calculus – Structures and rules applied to logical symbols – Just like ordinary algebra is applied to numbers Uses a two-valued set {0, 1} – Operations: conjunction, disjunction and negation Is related with – Propositional logic and – Algebra of sets Underpins logical circuits (electronic components) 3 CS1022

4
Boolean operations (1) Boolean algebra uses set B 0, 1 of values Operations: – Disjunction ( ), – Conjunction ( ) and – Negation () 4 CS1022

5
Boolean operations (2) If p and q are Boolean variables – “Variables” because they vary over set B 0, 1 – That is, p, q B We can build the following tables: 5 CS1022 pq p qp q p p 01 10

6
Boolean algebra vs. logic Boolean algebra is similar to propositional logic Boolean variables p, q,... like propositions P, Q,... Values B 0, 1 like F (false) and T (true) Operators are similar: p q similar to P or Q p q similar to P and Q p similar to not P Tables also called “truth tables” (as in logic) 6 CS1022

7
As in logic, we can build more complex constructs from basic variables and operators , and – Complex constructs are called Boolean expressions A recursive definition for Boolean expressions: – All Boolean variables (p, q, r, s, etc.) are Boolean exprns. – If α and β are Boolean expressions then α is a Boolean expression (and so is β) (α β) is a Boolean expression (α β) is a Boolean expression Example: ((p q) (r s)) Boolean expressions 7 CS1022

8
Two Boolean expressions are equivalent if they have the same truth table – The final outcome of the expressions are the same, for any value the variables have We can prove mechanically if any two expressions are equivalent or not – “Mechanic” means “a machine (computer) can do it” – No need to be creative, clever, etc. – An algorithm explains how to prove equivalence Equivalence of expressions 8 CS1022

9
Some equivalences are very useful – They simplify expressions, making life easier – They allow us to manipulate expressions Some equivalences are “laws of Boolean algebra” – We have, in addition to truth-tables, means to operate on expressions – Because equivalence is guaranteed we won’t need to worry about changing the meaning Laws of Boolean algebra (1) 9 CS1022

10
Laws of Boolean algebra (2) 10 CS1022 Commutative Laws p q q p p q q p Associativity Laws p (q r) (p q) r p (q r) (p q) r Distributive Laws p (q r) (p q) (p r) p (q r) (p q) (p r) Idempotent Laws p p p p p p Absorption Laws p (p q) p p (p q) p De Morgan’s Laws (p q) p q (p q) p q

11
Do they look familiar? – Logics, sets & Boolean algebra are all related Summary of correspondence: Laws of Boolean algebra (3) 11 CS1022 Logical operation Set operation Boolean operation not or and

12
Very important: – Laws shown with Boolean variables (p, q, r, etc.) – However, each Boolean variable stand for an expression – Wherever you see p, q, r, etc., you should think of “place holders” for any complex expression – A more “correct” way to represent e.g. idempotent law: Laws of Boolean algebra (4) 12 CS1022

13
What do we mean by “place holders”? – The laws are “templates” which can be used in many different situations For example: ((p q) (q s)) ((p q) (q s)) ((p q) (q s)) Laws of Boolean algebra (5) 13 CS1022

14
We should be able to prove all laws – We know how to build truth tables (lectures 2.1 & 2.2) – Could you work out an algorithm to do this? – There is help at hand... Laws of Boolean algebra (6) 14 CS1022

15
Using the laws of Boolean algebra, show that – (p q) (p q) is equivalent to p Solution: (p q) (p q) (p q) (p q)De Morgan’s (p q) (p q)since p p p (q q)Distr. Law p 0since (q q) 0 pfrom def. of Laws of Boolean algebra (7) 15 CS1022

16
A Boolean function of n variables p 1, p 2,..., p n is – A function f : B n B – Such that f(p 1, p 2,..., p n ) is a Boolean expression Any Boolean expression can be represented in an equivalent standard format – The so-called disjunctive normal form Format to make it easier to “process” expressions – Simpler, fewer operators, etc. Boolean functions (1) 16 CS1022

17
Example: function minterm m(p, q, r) – It has precisely one “1” in the final column of truth table – m(p, q, r) 1 if p 0, q 1 and r 1 We can define m(p, q, r) p q r The expression p q r is the product representation of the minterm m Boolean functions (2) 17 CS1022 pqrm

18
Any minterm m(p 1, p 2,..., p r ) can be represented as a conjunction of the variables p i or their negations Here’s how: – Look at row where m takes value 1 – If p i 1, then p i is in the product representation of m – If p i 0, then p i is in the product representation of m – We thus have m(p, q, r) p q r Boolean functions (3) 18 CS1022 pqrm 0111

19
We can express any Boolean function uniquely as a disjunction (a sequence of “ ”) of minterms – This is the disjunctive normal form The idea is simple: – Each minterm is a conjunction (sequence of “ ”) which, if all holds, then we have output (result) “1” – The disjunction of minterms lists all cases which, if at least one holds, then we have output (result) “1” – In other words: we list all cases when it should be “1” and say “at least one of these is 1” Disjunctive normal form (1) 19 CS1022

20
Find disjunctive normal form for (p q) (q r) Let f (p q) (q r). Its truth table is as below The minterms are (rows with f 1) –p q r–p q r – p q r Disjunctive normal form is (p q r) (p q r) (p q r) Disjunctive normal form (2) 20 CS1022 pqrf pqrf pqrf pqrf pqrf pqrf

21
Any Boolean function can be represented with Boolean operators , , This is a complete set of operators – “Complete” = “we can represent anything we need” It is not minimal, though: – De Morgan’s (p q) p q, so (p q) (p q) – We can define “ ” in terms of , Minimal set of Boolean operators: , or , – Actually, any two operators suffice Minimality comes at a price: expressions become very complex and convoluted Minimal set of operators 21 CS1022

22
Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd (Chapter 9) Wikipedia’s entry on Boolean algebra Wikibooks entry on Boolean algebra 22 CS1022

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google