55
CS031 Lecture 4 (a) Page 1 CS31 Pascal Van Hentenryck Boolean Functions and Gates

Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) Page 1

CS31

Pascal Van Hentenryck

Boolean Functions

and Gates

Page 2: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 2

Overview

We have seen so far that

•! computers deal with words of binary

digits

•! these words can be used to store a

variety of objects (e.g. numbers, characters, ...)

We now study

•! how to build circuits to perform

operations on these representations

Fundamental Idea

•! a new abstraction called combinational

device

Page 3: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 3

The Big Picture

Page 4: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 4

Abstraction Hierarchy

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

Page 5: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 5

Combinational Devices

A combinational device is a circuit having

•! some binary input

•! some binary output

•! a functional specification, stating the values of

the output in terms of the inputs

•! a timing specification, giving the maximum

time necessary to compute the outputs given

the inputs

Static Discipline

•! This is the guarantee that, given valid inputs, the circuit will deliver valid outputs (after some

propagation delay)

This is the simplest tool to build computers

Combinational devices can be combined to

produce other combinational devices when:

•! the circuit contains no directed cycle

Page 6: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 6

The main goal

Show how to build combinational

devices

•! for the operations we have seen

•! given a set of basic boolean functions

Organization

•! Basic Boolean functions

•! Truth table

•! Properties

•! Normal forms

Page 7: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 7

Truth Tables

Page 8: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 8

Truth Tables Specification of combinational

devices

•! lots of ways to choose f (24, to be

exact)

Page 9: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 9

And

and(a,b) = 1 if and only if a = 1 and b = 1

Alternative notations for and(a,b)

include:

•! ab (we’ll be using this one)

•! a!b

•! a 杏 b

This is also called the conjunction

operator.

Page 10: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 10

Or or(a,b) = 1 if and only if a = 1 or b = 1

Alternative notations for or(a,b)

include:

•! a + b (we’ll be using this one)

•! a以 b

This is also called the disjunction

operator.

Page 11: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 11

Not not(a) = 1 if and only if a = 0

Alternative notations for not(a)

include:

•! a’

•! ¬a

This is also called the negation

operator.

Page 12: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 12

De Morgan’s Laws If you have and and not, you can

create the or function; if you have or

and not, you can create the and

function.

a + b = (a’b’)’

Similarly (try this one out yourself)

ab = (a’ + b’)’

1

1

1

1

0

0

0 0

0 0 1

1

1 1

1

1

1 0

0

0

Page 13: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 13

Exclusive Or (xor)

ab’ + a’b

1

0

1 0

0

0

0

0

0

0

1

1

Page 14: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 14

Nand nand(a,b) = 1 if and only if it is not

the case that both a = 1 and b = 1

Nand is universal:

a’ =

ab =

=

a+b=

Page 15: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 15

Nand nand(a,b) = 1 if and only if it is not the case

that both a = 1 and b = 1

Nand is universal:

a’ = nand(a,a)

ab =

=

a+b= =

=

=

Page 16: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 16

Nand nand(a,b) = 1 if and only if it is not the case

that both a = 1 and b = 1

Nand is universal:

a’ = nand(a,a)

ab = nand(nand(a,b),nand(a,b))

= (nand(a,b))’

a+b= =

=

=

Page 17: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 17

Nand nand(a,b) = 1 if and only if it is not

the case that both a = 1 and b = 1

Nand is universal:

a’ = nand(a,a)

ab = nand(nand(a,b),nand(a,b))

= (nand(a,b))’

a+b= nand(nand(a,a),nand(b,b))

= nand(a’, b’)

Page 18: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 18

Associativity

Basic rules

•! A ( B C ) = ( A B ) C = A B C

•! A + ( B + C ) = ( A + B ) + C = A + B + C

Name Conventions

•! ABC is called a product

•! A+B+C is called a sum

Priorities

•! Negation has highest priority

•! “and” has higher priority than “or”

Page 19: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 19

Other Properties

Commutativity

•! A B = B A

•! A + B = B + A

Distributivity

•! A ( B + C) = A B + A C

•! A + ( B C) = (A + B) (A + C)

Which rule is not true for integers?

Page 20: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 20

Other Properties

Commutativity

•! A B = B A

•! A + B = B + A

Distributivity

•! A ( B + C) = A B + A C

•! A + ( B C) = (A + B) (A + C)

Which rule is not true for integers?

Distributivity:

2 + (3*3) " (2+3)(2+3)

11 " 25

Page 21: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 21

Truth Tables Specification of combinational

devices

•! lots of ways to choose f (24, to be

exact)

Page 22: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 22

Truth Tables

Page 23: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 23

Sum of Products Representing a function by a logical

expression

The expression is

Basic Idea

Associate a product term with each row with an

output at 1; the term has the variable if its

value is 1 and the negation of the variable

otherwise

Page 24: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 24

Sum of Products Representing a function by a logical

expression

The expression is

a’b’c + a’bc + ab’c’ + ab’c

Basic Idea

Associate a product term with each row with an

output at 1; the term has the variable if its

value is 1 and the negation of the variable

otherwise

Page 25: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 25

Product of Sums

The expression is

Basic Idea The result is a product term. Each sum in this

product negates a row which has a zero output. Associate a sum term with each row with an output at 0; the term has the variable if its value is 0 and the negation of the variable otherwise

Page 26: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 26

Product of Sums

The expression is (a+b+c)(a+b’+c)(a’+b’+c)(a’+b’+c’)

Basic Idea The result is a product term. Each sum in this

product negates a row which has a zero output. Associate a sum term with each row with an output at 0; the term has the variable if its value is 0 and the negation of the variable otherwise

Page 27: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 27

Logical Gates

Page 28: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 28

Combinational Device

f(a,b,c) = ab + b’c

Page 29: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (a) 29

We still have a way to go to

get to our Linux boxes...

...but we’ll get there!

Page 30: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) Page 1

CS31 Pascal Van Hentenryck

Karnaugh Maps

Page 31: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 2

Overview

Karnaugh Maps

•! Simplifying Boolean functions

Page 32: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 3 (b) 3

The Big Picture

Page 33: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 3 (b) 4

Abstraction Hierarchy

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

Programming Language

Assembly Language

Machine Language

Sequential Circuit

Combinational Circuit

Binary Value

Voltage

Page 34: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 5

Minimizing Boolean

Functions

The problem •! Given a truth table, find a small circuit

to compute it

•! The problem is very hard in general (no really efficient algorithm exists)

Possible solutions •! Put the function as a sum of products

and build the corresponding circuit

•! Put the function as product of sums and build the corresponding circuit

Limitation •! The size of the circuit may be far from

the minimal size

Karnaugh Maps •! A heuristic method to minimize the

size of the circuit

Page 35: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 6

Karnaugh Map

Another Presentation of a Truth Table

The Karnaugh map looks like this

Page 36: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 7

Karnaugh Map

3 variables

4 variables

Page 37: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 8

Karnaugh Maps

Property

•! Adjacent entries differ by at most one

variable

•! The whole table is wrapping up on

itself. The end of a row is adjacent to

the beginning of the row and so on.

Z’

Z

Z

Z’

Page 38: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 9

Boxes Boxes of sizes 1,2,4,8 or 16

Page 39: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 10

A K-Map

Page 40: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 11

Minimization

The basic strategy

1.! Draw the Karnaugh map

2.! Fill it with the truth table

3.! Cover all the 1s with boxes of size 1, 2, 4, 8,

16. ... (an entry can be covered by several

boxes if needed)

4.! Generate a product for each box; each

element of the product corresponds to a

variable which stays constant over the box. It

is the variable if the variable stays at 1 and

the negation of the variable otherwise.

5.! The result is the sum of all these products

The main goal

•! As few boxes as possible

•! The biggest possible boxes

Page 41: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 12

A simplification

Another Presentation of a Truth Table

The Karnaugh map looks like this

What is the boolean function?

Page 42: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 13

A simplification

Another Presentation of a Truth Table

The Karnaugh map looks like this

What is the boolean function? f(a,b)=a’

Page 43: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 14

Another Simplification Problem

Sum of Products gives us:

Page 44: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 15

Another Simplification Problem

Sum of Products gives us: f(x,y,z) = x’yz + xy’z’ + xyz’ + xyz

Karnaugh map:

Page 45: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 16

Another Simplification Problem

Sum of Products gives us: f(x,y,z) = x’yz + xy’z’ + xyz’ + xyz

Karnaugh map:

f(x,y,z) = yz + xz’

Page 46: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 17

A Really Big One

Page 47: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 18

Don’t Cares

Sometimes, it doesn’t matter exactly

which output is generated in a certain

situation.

A don’t care value is represented by a

x and we can choose any value that

is convenient to us.

What do we choose?

By setting the left and right x’s to 1 we

can make a 2x2 square, reducing the

function to: f(x,y,z)=z’

Page 48: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 19

Don’t Cares

Sometimes, it doesn’t matter exactly

which output is generated in a certain

situation.

A don’t care value is represented by a

x and we can choose any value that

is convenient to us.

What do we choose?

By setting the left and right x’s to 1 we

can make a 2x2 square, reducing the

function to: f(x,y,z)=z’

1

1

Page 49: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 20

We Still Don’t Care!

What if the x’s were 0’s?

f(w,x,y,z)=(w’x’y) + (w’xz) + (xyz)

Page 50: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 21

We Still Don’t Care!

What if the x’s were 0’s?

f(w,x,y,z)=(w’x’y) + (w’xz) + (xyz)

What if they’re don’t cares?

Page 51: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 22

We Still Don’t Care!

What if the x’s were 0’s?

f(w,x,y,z)=(w’x’y) + (w’xz) + (xyz)

What if they’re don’t cares?

f(w,x,y,z)=(x’y) + (xz)

How many operations do we save?

Including negations, 11-4=7

Page 52: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 23

Half Adder

Given two inputs, generate the sum and carry.

Page 53: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 24

Full Adder

Add three inputs, generating the sum and carry.

Page 54: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 25

Simplification for FA

Karnaugh map for S

Karnaugh map for C

Page 55: Boolean Functions and Gates - Brown Universitycs.brown.edu/courses/csci0310/content/lectures/L04.pdfPossible solutions •!Put the function as a sum of products and build the corresponding

CS031 Lecture 4 (b) 26

Chaining Adders We can add two 4-bit numbers

by chaining full adders. FAFAFAFA0x0y0y2x2y2x2y1x1S0S1S2S3C

FA

FA

FA

FA

0 x0 y0

x1

x2

x3

y1

y2

y3

S0

S1

S2

S3

C