ioan despi - university of new...

27
Boolean Functions Ioan Despi [email protected] University of New England September 4, 2013

Upload: others

Post on 21-Feb-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Boolean Functions

Ioan Despi

[email protected]

University of New England

September 4, 2013

Page 2: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Outline

1 Basic Definitions

2 Convertion of Boolean Function to Boolean ExpressionExample

3 Canonical FormExample

4 Minimal RepresentationExample

5 Logic GatesExamples

Ioan Despi – AMTH140 2 of 27

Page 3: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Basic Definitions

Let B = {0, 1} and let 𝑛 be a positive integer.

Definition

A Boolean function (a.k.a. truth function, switching function) of 𝑛variables, 𝑓(𝑥1, · · ·𝑥𝑛), is a mapping on B𝑛 into B,

𝑓 : B𝑛 → B

A more general definition replaces B = {0, 1} with an arbitrary Booleanalgebra 𝐵(+, ·, ′, 0, 1).The most elementary way to define a Boolean function is to provide itstruth table, a complete list of all the points in B𝑛 together with the valueof the function at each point.We say that the Boolean function is defined explicitly and it iscompletely determined by the corresponding truth table and vice versa.In general, for 𝑓 : B𝑛 → B, there are 2𝑛 rows!

Definition

A point 𝑥⋆ ∈ B𝑛, 𝑥⋆ = (𝑥1, 𝑥2, . . . , 𝑥𝑛), is a true point of the Booleanfunction 𝑓 : B𝑛 → B if 𝑓(𝑥⋆) = 1 and it is a false point if 𝑓(𝑥⋆) = 0.

Ioan Despi – AMTH140 3 of 27

Page 4: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Boolean Function → Boolean ExpressionThe explicit definition of a Boolean function grows exponentially on 𝑛.A better way to represent it is implicitly.

Let B = {0, 1} and 𝑓 : B𝑛 → B be a Boolean function.

Implicit Boolean functions

(i) List all possible input states and the corresponding function values, i.e.,list the truth table

𝑥1 𝑥2 · · · 𝑥𝑛−1 𝑥𝑛 𝑓(𝑥1, · · · , 𝑥𝑛)

2𝑛 rows

⏞ ⏟

0 0 0 0 *0 0 0 1 *

XXXXXy

“*” represents 0 or 1depending on the function 𝑓

0 0 1 0 *...

......

......

1 1 1 1 *(ii) remove all rows whose output state is 0, i.e., 𝑓(𝑥1, · · · , 𝑥𝑛) = 0.

(iii) replace 0 and 1 in 𝑥𝑖–columns by 𝑥′𝑖 and 𝑥𝑖 respectively in the Boolean

expression.

(iv) Sum up all the (input state) product terms.

Ioan Despi – AMTH140 4 of 27

Page 5: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Boolean Function → Boolean Expression (cont.)

To get rid of parenthesis when writing Boolean expressions,

(a) keep in mind the order of precedence

′ · +

(b) discard any parenthesis that become redundant as a consequence ofassociativity of · and + .

Ioan Despi – AMTH140 5 of 27

Page 6: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

Example

1. Let 𝑓 : {0, 1}3 → {0, 1} be given by 𝑓(𝑥, 𝑦, 𝑧) = 𝑥𝑦𝑧 + min (𝑥, (𝑦 + 𝑧)′).Here min means minimum. Write 𝑓 as a Boolean expression, i.e., as a sum ofproduct terms.

Solution. From the following truth table

𝑥 𝑦 𝑧 𝑓(𝑥, 𝑦, 𝑧)0 0 0 00 0 1 00 1 0 00 1 1 0Q

QQs

𝑥

1

�������1

𝑦′

0 0

������

���

𝑧′

1 �contributes to 𝑥 · 𝑦′ · 𝑧′1 0 1 0

1 1 0 0

1 1 1 1

Ioan Despi – AMTH140 6 of 27

Page 7: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

Example

1. Let 𝑓 : {0, 1}3 → {0, 1} be given by 𝑓(𝑥, 𝑦, 𝑧) = 𝑥𝑦𝑧 + min (𝑥, (𝑦 + 𝑧)′).Here min means minimum. Write 𝑓 as a Boolean expression, i.e., as a sum ofproduct terms.

We see that only two rows will actually contribute to the final Booleanexpression

𝑓(𝑥, 𝑦, 𝑧) = 𝑥𝑦′𝑧′ + 𝑥𝑦𝑧

where the binary operator “·” is omitted for simplicity.

Once we know that all Boolean functions can be expressed as a sum ofproduct terms, it will be meaningful to introduce the concept of canonicalrepresentation so that each function will have a unique canonical form.

Ioan Despi – AMTH140 7 of 27

Page 8: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Canonical Form

Let (B,+, ·, ′, 0, 1) be a Boolean algebra and 𝑥, 𝑦 and 𝑧 be any variablestaking values in B, then

I literals are individual variables or their complements, e.g. 𝑥, 𝑥′, 𝑦, 𝑦′

I product terms are expressions made up of literals and the binaryoperation “·” although the symbol “·” is optional, e.g.,

I 𝑥, 𝑥′, 𝑥 · 𝑦′𝑧, 𝑥 · 𝑦 · 𝑥′𝑦 · 𝑧I Boolean expression is a sum of product terms, e.g. 𝑥 + 𝑥′ · 𝑦(𝑧 + 𝑦′)

I standard product term of an expression is a product in which eachvariable appears in the product exactly once, e.g. 𝑥𝑦′ is a standardproduct of 𝑥𝑦′ + 𝑥 + 𝑥′𝑦′, but is not a standard product of 𝑥𝑦′ + 𝑥𝑦𝑧because variable 𝑧 is missing from the product.

I a Boolean expression is canonical if it is a sum of distinct standardproduct terms, e.g.,

I 𝑥𝑦 + 𝑥′𝑦′ is canonical, but 𝑥𝑦 + 𝑥′𝑦 + 𝑧 is not canonical.

Given 𝑛 Boolean variables, one can obtain 2𝑛 distinct standard product terms.

Ioan Despi – AMTH140 8 of 27

Page 9: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

The Conversion Procedure

To convert a Boolean function into its canonical form:

Conversion Procedure

1 expand the expression into a sum of standard product terms.I Use the distributive law

𝑎 · (𝑏+ 𝑐) = 𝑎 · 𝑏+ 𝑎 · 𝑐

for this.

2 inspect each term to see if it contains all the variables.

3 if a term misses one or more variables, it is multiplied with an expressionsuch as

𝑎 + 𝑎′ (= 1)

where 𝑎 is one of the missing variables.

Ioan Despi – AMTH140 9 of 27

Page 10: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Equivalent Boolean Expressions

Definition

Two Boolean expressions are equivalent if they represent the same Booleanfunction.

Two Boolean expressions are equivalent if they either

I have the same truth table, orI can be transformed from one to another through the use of the axioms

B1 – B5 in the previous lecture, and their induced properties such as theDe Morgan’s Laws, or

I have the same canonical form.

Ioan Despi – AMTH140 10 of 27

Page 11: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

2. Show Boolean expressions 𝑥 and 𝑥𝑦 + 𝑥𝑦′ are equivalent.

(a) By truth table

𝑥 𝑦 𝑦′ 𝑥𝑦 𝑥𝑦′ 𝑥𝑦 + 𝑥𝑦′

0 0 1 0 0 00 1 0 0 0 01 0 1 0 1 11 1 0 1 0 16

same6

(b) By properties of Boolean algebra

𝑥𝑦 + 𝑥𝑦′B3= 𝑥(𝑦 + 𝑦′)

B5= 𝑥 · 1

B4= 𝑥

(c) By canonical form

𝑥 = 𝑥 · (𝑦 + 𝑦′) = 𝑥𝑦 + 𝑥𝑦′}︁

same canonical form𝑥𝑦 + 𝑥𝑦′ = 𝑥𝑦 + 𝑥𝑦′

Ioan Despi – AMTH140 11 of 27

Page 12: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Minimal Representation

Among equivalent Boolean functions or expressions, it is natural that weoften want a simpler or even “simplest” form.

Definition

A Boolean expression 𝐸 is a minimal representation of a Boolean function𝑓 if 𝐸 represents 𝑓 and

(i) E is identical to 0 or 1;

(ii) 𝐸 is a sum of product terms;

(iii) if 𝐹 is any sum of product terms representing 𝑓 , then the number ofproduct terms in 𝐸 is no greater than that in 𝐹 ;

(iv) if 𝐹 is any sum of product terms representing 𝑓 and having the samenumber of product terms as in 𝐸, then the total number of literals in 𝐸 isno greater than that in 𝐹 .

Ioan Despi – AMTH140 12 of 27

Page 13: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

3. Find the minimal representation for 𝑓 = 𝑎′ · 𝑏′ + 𝑎′ · 𝑏.

Solution. First we observe

𝑓 = 𝑎′ · 𝑏′ + 𝑎′ · 𝑏= 𝑎′ · (𝑏′ + 𝑏)

= 𝑎′ · 1 = 𝑎′

Since 𝑓 is not identical to 0 or 1, and its equivalent expression 𝑥 has only 1product term and 1 literal in total, this equivalent Boolean expression must bea minimal representation of 𝑓 .

Ioan Despi – AMTH140 13 of 27

Page 14: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

4. Find the minimal representation for 𝑓 = 𝑥𝑦 + 𝑥𝑦 + 𝑥𝑥′ + 𝑥𝑦′ .

Solution. First we observe

𝑓 = (𝑥𝑦 + 𝑥𝑦) + 𝑥𝑥′ + 𝑥𝑦′

= 𝑥𝑦 + 0 + 𝑥𝑦′ = 𝑥𝑦 + 𝑥𝑦′

= 𝑥(𝑦 + 𝑦′) = 𝑥 · 1 = 𝑥 .

Since 𝑓 is not identical to 0 or 1, and its equivalent expression 𝑥 has only 1product term and 1 literal in total, this equivalent Boolean expression must bea minimal representation of 𝑓 .

Ioan Despi – AMTH140 14 of 27

Page 15: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

5. Show 𝑓 = 𝑥𝑦𝑧′ + 𝑥𝑦′𝑧 + 𝑥𝑦′𝑧′ + 𝑥′𝑦𝑧 + 𝑥′𝑦𝑧′ is equivalent to any of the fourBoolean expressions below

(a) 𝑥𝑦′ + 𝑥′𝑦 + 𝑥𝑦𝑧′ (b) 𝑥𝑦′ + 𝑥′𝑦 + 𝑥𝑧′

(c) 𝑥𝑦′ + 𝑥′𝑦 + 𝑦𝑧′ (d) 𝑥𝑦′ + 𝑥′𝑦𝑧 + 𝑦𝑧′

and (a) and (d) are not minimal.

Solution. Since 𝑓 is already in canonical form, once we convert (a)–(d) intocanonical forms we should see that the newly obtained canonical forms are inexactly the same form as 𝑓 itself. For (a), for instance, we have

𝑥𝑦′ + 𝑥′𝑦 + 𝑥𝑦𝑧′ = 𝑥𝑦′(𝑧 + 𝑧′) + 𝑥′𝑦(𝑧 + 𝑧′) + 𝑥𝑦𝑧′

= 𝑥𝑦′𝑧 + 𝑥𝑦′𝑧′ + 𝑥′𝑦𝑧 + 𝑥′𝑦𝑧′ + 𝑥𝑦𝑧′

which is same as 𝑓 . We can also derive (a)–(d) directly from 𝑓 .For (c), for instance, we have

𝑓 = 𝑥𝑦𝑧′ + 𝑥𝑦′𝑧 + 𝑥𝑦′𝑧′ + 𝑥′𝑦𝑧 + 𝑥′𝑦𝑧′

= (𝑥𝑦′𝑧 + 𝑥𝑦′𝑧′) + (𝑥𝑦𝑧′ + 𝑥′𝑦𝑧′) + (𝑥′𝑦𝑧 + 𝑥′𝑦𝑧′)

= 𝑥𝑦′(𝑧 + 𝑧′) + (𝑥 + 𝑥′)𝑦𝑧′ + 𝑥′𝑦(𝑧 + 𝑧′)

= 𝑥𝑦′ + 𝑦𝑧′ + 𝑥′𝑦 .Ioan Despi – AMTH140 15 of 27

Page 16: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

It is easy to see that expressions (a)–(d) all have 3 product terms.

However (a) and (d) both have 7 literals while (b) and (c) both have only6 literals.

Hence neither (a) nor (d) is a minimal representation.

We finally note that (b) and (c) in example 4 are minimal representations.

Ioan Despi – AMTH140 16 of 27

Page 17: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

6. The Boolean expression 𝑓 in Example 4 may be drawn as a switchingcircuit below according to (b)

OR

x y’

x’ y

x z’

x y’

z’

x’ y

Ioan Despi – AMTH140 17 of 27

Page 18: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

7. The keys to Boolean minimisation lie in the following theorems:𝑎 + 𝑎 · 𝑏 = 𝑎 𝑎 · (𝑎 + 𝑏) = 𝑎 (Absorption)𝑎 + 𝑎′ · 𝑏 = 𝑎 + 𝑏 𝑎 · (𝑎′ + 𝑏) = 𝑎 · 𝑏𝑎 · 𝑏 + 𝑎 · 𝑏′ = 𝑎 (𝑎 + 𝑏) · (𝑎 + 𝑏′) = 𝑎 (Logic Adjancency)

The proof is immediate, for instance:𝑎 + 𝑎′ · 𝑏 = 𝑎 + 𝑎 · 𝑏 + 𝑎′ · 𝑏 = 𝑎 + (𝑎 + 𝑎′) · 𝑏 = 𝑎 + 1 · 𝑏 = 𝑎 + 𝑏𝑎 · 𝑏 + 𝑎 · 𝑏′ = 𝑎 · (𝑏 + 𝑏′) = 𝑎 · 1 = 𝑎

In general it is difficult to show a Boolean expression is minimal from thevery definitions.

We shall instead claim that the simplified forms provided by Karnaughmaps, to be given shortly, are minimal representations.

Ioan Despi – AMTH140 18 of 27

Page 19: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Logic Gates

A logic circuit is a computer switching circuit that performs someprocessing or controlling function, that is some logical operations on data.

It can be seen as a black box, with some inputs and some outputs.

Logic circuit

Inp

uts

Outp

uts

"black box"

One can distinguish betweenI the analysis problem – given a logic circuit, determine binary outputs

for each combination of inputs, andI the design problem – given a task, develop a circuit that accomplishes

the task.

Ioan Despi – AMTH140 19 of 27

Page 20: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Logic Gates

Claude Shanon (1938) realised that Boolean algebra could be use inelectronic design by modeling logic gates.

Electronically, logic circuits are typically implemented through the use ofa collection of logic gates.

Logic gates are implemented by means of Boolean functions or expressionsand are, as usual, characterised by their input-output correspondence.

Physically, every terminal (input or output) in a logic gate is in one of thetwo binary conditions, represented by different voltage levels:∙ low (0) ≈ zero volts (0 V)∙ high (1) ≈ five volts (+5 V)

As the circuit processes data, the logical state of a circuit changes often.

This is a good example of a discrete approximation of an analoguephenomenon.

The most popular five logic gates are as follows.

Ioan Despi – AMTH140 20 of 27

Page 21: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

NOT-gate

NOT-gate:I taking 𝑝 as the input,I will output the logical value 𝑝′ :

p p p’

0 1

01

p’

Ioan Despi – AMTH140 21 of 27

Page 22: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

AND-gate

AND-gate:I taking 𝑝 and 𝑞 as the input,I will output the logical value 𝑝𝑞:

p

qpq p q pq

0

0

1

1

0

0

1

1

0

0

0

1

Ioan Despi – AMTH140 22 of 27

Page 23: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

OR-gate

OR-gate:I taking 𝑝 and 𝑞 as the input,I will output the logical value 𝑝+ 𝑞 :

p

qp+q p q p+q

0

1

1

0

1

0

1

1

1

0

0

1

Ioan Despi – AMTH140 23 of 27

Page 24: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

NAND-gate

NAND-gate:I taking 𝑝 and 𝑞 as the input,I will output the logical value (𝑝𝑞)′ ; orI it can be built through the use of an AND-gate and a NOT-gate:

p

q(pq)’

pq (pq)’

p q (pq)’

0

0

1

0

0

1

1

1

1

011

Ioan Despi – AMTH140 24 of 27

Page 25: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

NOR-gate

NOR-gate:I taking 𝑝 and 𝑞 as the input,I will output the logical value (𝑝+ 𝑞)′ ; orI it can be built from an OR-gate and a NOT-gate:

p

q (p+q)’

p

q(p+q)’

p q (p+q)’

0

0

1

1

0

0

1

1

1

0

0

0

Ioan Despi – AMTH140 25 of 27

Page 26: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

8. Draw a gate implementation for the Boolean expression 𝑥𝑦′𝑧′ + 𝑥𝑦𝑧.

Solution.

x

y

z

xy

y’

z’y’z’

xy’z’

xyz

xy’z’+xyz

The idea here is to work backwards, that is, from right to left, building up thediagram. A simple example is given in Tutorial 8.

Ioan Despi – AMTH140 26 of 27

Page 27: Ioan Despi - University of New Englandturing.une.edu.au/~amth140/Lectures/Lecture_21/Lecture/lecture.pdf · Ioan Despi – AMTH140 4 of 27. Boolean Function →Boolean Expression

Example

9. Show that any Boolean expression can be represented by NAND-gatesalone.

Solution. Since every Boolean expression can be represented by someAND-gates, OR-gates and NOT-gates, if we can construct these 3 types ofgates with NAND-gates alone, then we have shown that any Booleanexpression can be presented by just the NAND-gates.Since we can construct NOT-gates and AND-gates respectively via

p p’p

q

(pq)’ pq

and OR-gates via

p

q

p’

q’

p+q

because (𝑝′𝑞′)′ = 𝑝 + 𝑞, we conclude that NAND-gates alone are enough torepresent any Boolean expressions.

Ioan Despi – AMTH140 27 of 27