introduction to cs231 0 electronic circuits:an application of propositional logic why talk about...
TRANSCRIPT
Introduction to CS231 1
Electronic circuits:an application of propositional logic
Why talk about chips when we’re really interested in logic?
• Show how propositional-logic expressions play a crucial part in the way chips (and hence computers) work
• Show how logical inference allows us to optimise the way inwhich electronic circuits are built
• Thereby highlight some computational aspects of propositional logic
Our strategy: we’ll be looking over the shoulders of engineers, trying to understand what they are doing. We shall use slides adapted from a course on Computer Architecture by
Luddy Harrison and Howard Huang, University of Illinois at Urbana Champaign, Spring 2006
(We shall be taking many liberties: leaving things out, making additions, and annotating existing slides.)
©2000-2002 Howard Huang 2
• Computers use voltages to represent information. In modern CPUs the voltage is usually limited to 1.6-1.8V to minimize power consumption.
• It’s convenient for us to translate these analogvoltages into the discrete, or digital, values 1 and 0.
• But how can two lousy digits be useful for anything?
– First, we’ll see how to represent numbers withjust 1s and 0s.
– Then we’ll introduce special operationsfor computing with 1s and 0s, by treating them asthe logical values “true” and “false.”
Volts1.8
0
1
0
Introduction to CS231 3
The Modest Switch
• At the heart of a computer lies one extremely simple component:
– A controllable switch
• The usual Electrical switch we use every day
– The electric switch we use turns current on and off
– But we need to turn it on and off by hand
– The result of turning the switch on?
• The “top end” in the figure becomes raised to a high voltage
• Which makes the current flow through the bulb
•The Controllable Switch
• No hands
•Voltage controls if the switch is on or off
•High voltage at input: switch on
•Otherwise it is off
Introduction to CS231 4
Using the switch
Output
Input Output is high (voltage) if and only if the input is high
Now we can make one circuit control another switch…
Neat!This is getting
boring..
Introduction to CS231 5
Lets use them creatively
Output is high if both the inputs input1 AND input2 are high
If either of the inputs is low, the output is low.
Input1
Input2
OutputThis is called an AND gate
This is an electronic
implementation of the (i.e., conjunction) of propositional logic
Now, can you make an OR gate with switches (i.e., inclusive disjunction)?
Introduction to CS231 6
OR Gate
Input1
Input2
Output
Output is low iff both inputs are low
I.e. Output is high if either of the inputs (or both) are high (input1 OR input2)
Introduction to CS231 7
The two diagrams simplified (without earth)
• Current flows iff A is closed and B is closed:
• Current flows iff A is closed or B is closed (or both):
A B
A
B
Input Output
OutputInput
Introduction to CS231 8
Basic Gates
• There are three basic kinds of logic gates
ANDof two inputs
OR of two inputs
NOT(complement)on one input
Operation:
Logic gate:
•Two Questions:
•How can we implement them?
•What can we build with them? And How?
Introduction to CS231 9
How to make switches?
• In principle one might use mechanical power or hydrolic pressure
• Most often: Complementary Metal-Oxide Semi-conductors (CMOS: These circuits work with separate sources of high and low power.)
• ...
We leave all this to the engineers. Just remember:
• They can now manufacture millions of transistors on a single silicon chip
• Still, the size of chips is one of their main worries. The smaller the size,
– the smaller the propagation delay (typically)
– the less power is consumed
– the less heat is generated
– the cheaper it is to make the processor
Introduction to CS231 10
What can we do with Gates?
Example: adding numbers automatically
• How to add numbers, depends on how they are represented. E.g.,
– Roman XVII
– Decimal: 17
• Try adding two long roman numbers!
• Decimal is better but
– We have only two “values”, high and low, in our gates
• Decimal system (and the idea of “0”) was invented in India around 100-500AD
• Why did they use 10? Anything special about it?
– Not really.
– Probably the fact that we have 10 fingers influenced this
Introduction to CS231 11
Decimal review
• Numbers consist of a bunch of digits, each with a weight
• These weights are all powers of the base, which is 10:
• To find the decimal value of a number, multiply each digit by its weight and sum the products.
1 6 2 . 3 7 5 Digits100 10 1 1/ 10 1/ 100 1/ 1000 Weights
1 6 2 . 3 7 5 Digits102 101 100 10-1 10-2 10-3 Weights
(1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375
Introduction to CS231 12
Converting binary to decimal
• We can use the same trick to convert binary, or base 2, numbers to decimal. This time, the weights are powers of 2.
– Example: 1101.01 in binary
– The decimal value is:
1 1 0 1 . 0 1 Binary digits, or bits23 22 21 20 2-1 2-2 Weights (in base 10)
(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) = 8 + 4 + 0 + 1 + 0 + 0.25 = 13.25
Powers of 2: Useful abbreviations:
20 = 1 24 = 16 28 = 256 K = 210 = 1,02421 = 2 25 = 32 29 = 512 M = 220 = 1,048,57622 = 4 26 = 64 210 = 1024 G = 230 = 1,073,741,82423 = 8 27 = 128
Introduction to CS231 13
Binary addition example worked out
• The trick when adding numbers: positional weights and carry !
• Exercise: what are the black numbers equivalent to in decimal?
1 1 1 0 (Carries)1 0 1 1 (Augend)
+ 1 1 1 0 (Addend)1 1 0 0 1 (Sum)
The initial carryin is implicitly 0
most significantbit (MSB)
least significantbit (LSB)
Introduction to CS231 14
Doing addition with gates
• Lets do simple stuff first:– Can we add two numbers each with just 1 bit?
• Bit: binary digit– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ???
• 2. But 2 is not a symbol.• 10 (just as 5 + 5 is 10 in decimal)• Result is 0 with 1 carried over to the next bit.
• So if we disregard the carry, then what we get is– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0
• Does this remind you of something?
Introduction to CS231 15
Doing addition with gates
• Lets do simple stuff first:– Can we add two numbers each with just 1 bit?
• Bit: binary digit– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ???
• 2. But 2 is not a symbol.• 10 (just as 5 + 5 is 10 in decimal)• Result is 0 with 1 carried over to the next bit.
• So if we disregard the carry, then what we get is– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0
• Does this remind you of something?
• It’s the exclusive disjunction!
Introduction to CS231 16
Doing addition with gates
• Lets do simple stuff first:– Can we add two numbers each with just 1 bit?
• Bit: binary digit– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ???
• 2. But 2 is not a symbol.• 10 (just as 5 + 5 is 10 in decimal)• Result is 0 with 1 carried over to the next bit.
• So if we disregard the carry, then what we get is– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0
• What rule governs the carry?
• Carry=1 iff both inputs are 1
Introduction to CS231 17
Doing addition with gates
• Lets do simple stuff first:– Can we add two numbers each with just 1 bit?
• Bit: binary digit– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = ???
• 2. But 2 is not a symbol.• 10 (just as 5 + 5 is 10 in decimal)• Result is 0 with 1 carried over to the next bit.
• So if we disregard the carry, then what we get is– 0+0 = 0, 0+1 = 1 , 1+0 = 1, and 1+1 = 0
• What rule governs the carry?
• Carry=1 iff both inputs are 1
• It’s the logical conjunction (i.e., ).
Introduction to CS231 18
Doing addition with gates
• What does addition look like in a circuit?
Result
Carry
Half adder
Introduction to CS231 19
Half adder: result
Result
Exclusive OR
Output is 1 iff exactly one of the 2 inputs is 1
A special symbol for this gate:
Introduction to CS231 20
XOR
A
BA Å B
A
B
A Å B
A Å B = AB’ + A’BA Å B = (A ØB) Ú (ØA B)
Introduction to CS231 21
Adding two bits
• A half adder is used to add two bits.
• The result consists of two bits: a sum (the right bit) and a carry out (the left bit)
• Here is the circuit and its block symbol
0 + 0 = 00 + 1 = 11 + 0 = 11 + 1 = 10
• But, half adders do not take into account that there may have been a pre-existing carry. We shall write Cin, short for “Carry in(put)” (as opposed to Cout, which is short for “Carry out(put)”).
Introduction to CS231 22
Adding three bits
• What we really need to do is add three bits: the augend and addend, and the carry in from the right.
1 1 1 01 0 1 1
+ 1 1 1 01 1 0 0 1
0 + 0+ 0 = 000 + 0+ 1 = 010 + 1+ 0 = 010 + 1+ 1 = 101 + 0+ 0 = 011 + 0+ 1 = 101 + 1+ 0 = 101 + 1+ 1 = 11
X Y Cin Cout S
0 0 0 0 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 1 1
(The bitstring onthe right is the binary representationof the sum of the three numbers on the left)
Introduction to CS231 23
Full adder circuit
• Why are these things called half adders and full adders?
• You can build a full adder by putting together two half adders.
• In this way, Cin (as well as X and Y) is used as an input.
Introduction to CS231 24
An example of 4-bit addition
• Let’s put our initial example into this circuit: A=1011, B=1110
• Step 1: Fill in all the inputs, including CI=0
• Step 2: The circuit produces C1 and S0 (1 + 0 + 0 = 01)
• Step 3: Use C1 to find C2 and S1 (1 + 1 + 0 = 10)
• Step 4: Use C2 to compute C3 and S2 (0 + 1 + 1 = 10)
• Step 5: Use C3 to compute CO and S3 (1 + 1 + 1 = 11)
• The final answer is 11001
1 1 1 0 1 1 0 1
0
1 1 0 0 1
011
Introduction to CS231 25
So, we have built a calculator
• It is not a computer yet…
• Two new ideas and components are needed:
– Addressable memory
– Stored Program
• These are also based on electronic circuits(memory is achieved by feeding back the output of a gateto its input)
• Sorry to be a bit brief about this ...
Introduction to CS231 26
Basic Boolean operations
• There are three basic operations for logical values.
x y xy
0 0 0
0 1 0
1 0 0
1 1 1
x y x+y
0 0 0
0 1 1
1 0 1
1 1 1
x x’
0 1
1 0
AND (product)of two inputs
OR (sum) of two inputs
NOT(complement)on one input
xy, or xy x + y x’
Operation:
Expression:
Truth table:
Introduction to CS231 27
Boolean expressions
• We can use these basic operations to form more complex expressions. For example:
f(x,y,z) = (x + y’)z + x’
• Some terminology and notation:
– f is the name of the function.
– (x,y,z) are the input variables, each representing 1 or 0.
– A literal is any occurrence of an input variable or its complement. The function above has four literals: x, y’, z, and x’.
Introduction to CS231 28
Truth tables
• A truth table shows all possible inputs and outputs of a function.
• Inputs are listed in binary order—in this example, from 000 to 111.
x y z f (x,y,z)
0 0 0 10 0 1 10 1 0 10 1 1 11 0 0 01 0 1 11 1 0 01 1 1 1
f(0,0,0) = (0 + 1)0 + 1 = 1f(0,0,1) = (0 + 1)1 + 1 = 1f(0,1,0) = (0 + 0)0 + 1 = 1f(0,1,1) = (0 + 0)1 + 1 = 1f(1,0,0) = (1 + 1)0 + 0 = 0f(1,0,1) = (1 + 1)1 + 0 = 1f(1,1,0) = (1 + 0)0 + 0 = 0f(1,1,1) = (1 + 0)1 + 0 = 1
f(x,y,z) = (x + y’)z + x’
Introduction to CS231 29
Primitive logic gates
• Each of our basic operations can be implemented in hardware using a primitive logic gate.
Logic gate:
AND (product)of two inputs
OR (sum) of two inputs
NOT(complement)on one input
xy, or xy x + y x’
Operation:
Expression:
Introduction to CS231 30
Expressions and circuits
• Any Boolean expression can be converted into a circuit by combining basic gates.
– This follows from functional completeness!
• The diagram below shows the inputs and outputs of each gate.
• The precedences are explicit in a circuit.
(x + y’)z + x’
Introduction to CS231 31
Standard forms of expressions
• We can write expressions in many ways, but some ways are more useful than others
• A sum of products (SOP) expression contains:
– Only OR (sum) operations at the “outermost” level
– Each term that is summed must be a product of literals
• Any sum of products expression can be implemented using a two-level circuit
– literals and their complements at the “0th” level
– AND gates at the first level
– a single OR gate at the second level
• This diagram uses some shorthands…
– NOT gates are implicit
– literals are reused
f(x,y,z) = y’ + x’yz’ + xz
Introduction to CS231 32
Minterms
• A minterm is a special product of literals, in which each input variable appears exactly once.
• A three-variable function, such as f(x,y,z), has 23 = 8 minterms: Each minterm is true for exactly one combination of inputs:
x’y’z’ x’y’z x’yz’ x’yzxy’z’ xy’z xyz’ xyz
Minterm Is true when… Shorthandx’y’z’ x=0, y=0, z=0 m0
x’y’z x=0, y=0, z=1 m1
x’yz’ x=0, y=1, z=0 m2
x’yz x=0, y=1, z=1 m3
xy’z’ x=1, y=0, z=0 m4
xy’z x=1, y=0, z=1 m5
xyz’ x=1, y=1, z=0 m6
xyz x=1, y=1, z=1 m7
Introduction to CS231 33
Minterms
• You have encountered these before ...
Introduction to CS231 34
Minterms
• You have encountered these before ...
• ... when we proved that every truth function could be expressed using only and Ø ( i.e., functional completeness of { ,Ø} )
• Recall:
– every T-row of the truth table gave rise to a minterm
– we then formed the disjunction (“sum”) of these minterms ...
– ... replacing pÚq by Ø (Øp Øq)
Introduction to CS231 35
Sum of minterms form
• So: Every function can be written as a sum of minterms, in a unique way
• If you have a truth table for a function, you can write a “sum of minterms” expression just by picking out the rows of the table where the function output is 1.
x y z f (x,y,z) f ’(x,y,z)
0 0 0 1 00 0 1 1 00 1 0 1 00 1 1 1 01 0 0 0 11 0 1 0 11 1 0 1 01 1 1 0 1
f = x’y’z’ + x’y’z + x’yz’ + x’yz + xyz’= m0 + m1 + m2 + m3 + m6
= m(0,1,2,3,6)
f’ = xy’z’ + xy’z + xyz
= m4 + m5 + m7
= m(4,5,7)f’ contains all the minterms not in f
Introduction to CS231 36
(The dual idea: products of sums)
• A product of sums (POS) expression contains:
– Only AND (product) operations at the “outermost” level
– Each term must be a sum of literals
• Product of sums expressions can be implemented with two-level circuits
– literals and their complements at the “0th” level
– OR gates at the first level
– a single AND gate at the second level
• Compare this with sums of products
f(x,y,z) = y’ (x’ + y + z’) (x + z)
• Analogous to minterms, one can now define maxterms. (Let’s not further pursue these in our logic class).
Introduction to CS231 37
Circuit analysis
• Circuit analysis involves figuring out what some circuit does.
– Every circuit computes some function, which can be described with Boolean expressions or truth tables.
– So, the goal is to find an expression or truth table for the circuit.
• The first thing to do is figure out what the inputs and outputs of the overall circuit are.
– This step is often overlooked!
– The example circuit here has three inputs x, y, z and one output f.
Introduction to CS231 38
Write algebraic expressions...
• Next, write expressions for the outputs of each individual gate, based on that gate’s inputs.
– Start from the inputs and work towards the outputs.
– It might help to do some algebraic simplification along the way.
Introduction to CS231 39
Write algebraic expressions...
• Next, write expressions for the outputs of each individual gate, based on that gate’s inputs.
– Start from the inputs and work towards the outputs.
– It might help to do some algebraic simplification along the way.
• Here is the example again.
– We did a little simplification for the top AND gate.
– You can see the circuit computes f(x,y,z) = xz + y’z + x’yz’
Introduction to CS231 40
...or make a truth table
• It’s also possible to find a truth table directly from the circuit.
• Once you know the number of inputs and outputs, list all the possible input combinations in your truth table.
– A circuit with n inputs should have a truth table with 2n rows.
– Our example has three inputs, so the truth table will have 23 = 8 rows. All the possible input combinations are shown.
x y z f
0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1
Introduction to CS231 41
Simulating the circuit
• Then you can simulate the circuit, either by hand or with a program like LogicWorks, to find the output for each possible combination of inputs.
• For example, when xyz = 101, the gate outputs would be as shown below.
– Use truth tables for AND, OR and NOT to find the gate outputs.
– For the final output, we find that f(1,0,1) = 1.
x y z f
0 0 00 0 10 1 00 1 11 0 01 0 1 11 1 01 1 1
1
0
1
1
0
0
1
1
0
1
Introduction to CS231 42
Finishing the truth table
• Doing the same thing for all the other input combinations yields the complete truth table.
• This is simple, but tedious.
x y z f
0 0 0 00 0 1 10 1 0 10 1 1 01 0 0 01 0 1 11 1 0 01 1 1 1
Introduction to CS231 43
Truth tables and expressions
• It’s easy to come up with an expression if you have a truth table.
• We saw that you can quickly convert a truth table into a “sum of minterms” expression. The minterms correspond to the truth table rows where the output is 1. Compare the proof that {Ø, } is functionally complete (second lecture, also in tutorial exercise)!
• You can then simplify this sum of minterms if desired.
x y z f
0 0 0 00 0 1 10 1 0 10 1 1 01 0 0 01 0 1 11 1 0 01 1 1 1
f(x,y,z) = x’y’z + x’yz’ + xy’z + xyz
= m1 + m2 + m5 + m7
Introduction to CS231 44
Let’s compare the resulting circuits
• Here are two different but equivalent circuits.
• In general the one with fewer gates is “better”:
– It costs less to build
– It requires less power
– But we had to do some work to find the second form
Introduction to CS231 45
Karnaugh maps
• K-maps are a graphical technique for simplifying an expression into a minimal sum of products (MSP) form:
– There are a minimal number of product terms in the expression.
– Each term has a minimal number of literals.
• Circuit-wise, this leads to a minimal two-level implementation.
Introduction to CS231 46
Re-arranging the truth table
• A two-variable function has four possible minterms. We can re-arrange these minterms into a Karnaugh map.
• Now we can easily see which minterms contain common literals.
– Minterms on the left and right sides contain y’ and y respectively.
– Minterms in the top and bottom rows contain x’ and x respectively.
x y minterm
0 0 x’y’
0 1 x’y
1 0 xy’
1 1 xy
Y
0 1
0 x’y’ x’yX
1 xy’ xy
Y
0 1
0 x’y’ x’yX
1 xy’ xy
Y’ Y
X’ x’y’ x’y
X xy’ xy
Introduction to CS231 47
Karnaugh map simplifications
• Imagine a two-variable sum of minterms:
x’y’ + x’y
• Both of these minterms appear in the top row of a Karnaugh map, which means that they both contain the literal x’.
• This expression can be simplified using equivalence laws:x’y’ + x’y = x’(y’ + y) [ Distributive ]
= x’ 1 [ y + y’ = 1 ]= x’ [ x 1 = x ]
Y
x’y’ x’y
X xy’ xy
Introduction to CS231 48
More two-variable examples
• Another example expression is x’y + xy.
– Both minterms appear in the right side, where y is uncomplemented.
– Thus, we can reduce x’y + xy to just y.
• How about x’y’ + x’y + xy?
– We have x’y’ + x’y in the top row, corresponding to x’.
– There’s also x’y + xy in the right side, corresponding to y.
– This whole expression can be reduced to x’ + y.
Y
x’y’ x’y
X xy’ xy
Y
x’y’ x’y
X xy’ xy
Introduction to CS231 49
Summing: K-maps applied to 2 variables
• Karnaugh-maps are applied to sums of minterms
• They can help you find simpler sums of minterm that are equivalent to the original ones, because some of their disjuncts (i.e., minterms) contain literals that are negations of each other
• We’ve seen examples involving minterms... xy’ + ... + xy ... = ... x ...... x’y’ + ... + x’y ... = ... x’ ...... x’y + ... + xy ... = ... y ...... x’y’ + ... + xy’ ... = ... y’ ...
• More complex cases can be handled too:
Introduction to CS231 50
A three-variable Karnaugh map
• For a three-variable expression with inputs x, y, z, the arrangement of minterms is more tricky:
• Another way to label the K-map (use whichever you like):Y
x’y’z’ x’y’z x’yz x’yz’
X xy’z’ xy’z xyz xyz’
Z
Y
m0 m1 m3 m2
X m4 m5 m7 m6
Z
YZ00 01 11 10
0 x’y’z’ x’y’z x’yz x’yz’X
1 xy’z’ xy’z xyz xyz’
YZ00 01 11 10
0 m0 m1 m3 m2X1 m4 m5 m7 m6
Introduction to CS231 51
Why the funny ordering?
• With this ordering, any group of 2, 4 or 8 adjacent squares on the map contains common literals that can be factored out.
• “Adjacency” includes wrapping around the left and right sides:
• We’ll use this property of adjacent squares to do our simplifications.
x’y’z + x’yz= x’z(y’ + y)= x’z 1= x’z
x’y’z’ + xy’z’ + x’yz’ + xyz’= z’(x’y’ + xy’ + x’y + xy)= z’(y’(x’ + x) + y(x’ + x))= z’(y’+y)= z’
Y
x’y’z’ x’y’z x’yz x’yz’
X xy’z’ xy’z xyz xyz’
Z
Y
x’y’z’ x’y’z x’yz x’yz’
X xy’z’ xy’z xyz xyz’
Z
Introduction to CS231 52
Example K-map simplification
• Let’s consider simplifying f(x,y,z) = xy + y’z + xz.
• First, you should convert the expression into a sum of minterms form, if it’s not already.
– The easiest way to do this is to make a truth table for the function, and then read off the minterms.
– You can either write out the literals or use the minterm shorthand.
• Here is the truth table and sum of minterms for our example:x y z f (x,y,z)
0 0 0 00 0 1 10 1 0 00 1 1 0
1 0 0 01 0 1 11 1 0 11 1 1 1
f(x,y,z) = x’y’z + xy’z + xyz’ + xyz
= m1 + m5 + m6 + m7
Introduction to CS231 53
Making the example K-map
• Next up is drawing and filling in the K-map.
– Put 1s in the map for each minterm, and 0s in the other squares.
– You can use either the minterm products or the shorthand to show you where the 1s and 0s belong.
• In our example, we can write f(x,y,z) in two equivalent ways.
• In either case, the resulting K-map is shown below.Y
0 1 0 0
X 0 1 1 1
Z
Y
x’y’z’ x’y’z x’yz x’yz’
X xy’z’ xy’z xyz xyz’
Z
f(x,y,z) = x’y’z + xy’z + xyz’ + xyz
Y
m0 m1 m3 m2
X m4 m5 m7 m6
Z
f(x,y,z) = m1 + m5 + m6 + m7
Introduction to CS231 54
Grouping the minterms together
• The most difficult step is grouping together all the 1s in the K-map.
– Make rectangles around groups of one, two, four or eight 1s.
– All of the 1s in the map should be included in at least one rectangle.
– Do not include any of the 0s.
• Each group corresponds to one product term. For the simplest result:
– Make as few rectangles as possible, to minimize the number of products in the final expression.
– Make each rectangle as large as possible, to minimize the number of literals in each term.
– It’s all right for rectangles to overlap, if that makes them larger.
Y
0 1 0 0
X 0 1 1 1
Z
Introduction to CS231 55
Reading the MSP from the K-map
• Finally, you can find the MSP.
– Each rectangle corresponds to one product term.
– The product is determined by finding the common literals in that rectangle.
• For our example, we find that xy + y’z + xz = y’z + xy.
Y
x’y’z’ x’y’z x’yz x’yz’
X xy’z’ xy’z xyz xyz’
Z
Y
0 1 0 0
X 0 1 1 1
Z
Introduction to CS231 56
Practice K-map 1
• Simplify the sum of minterms m1 + m3 + m5 + m6.
Y
X
Z
Y
m0 m1 m3 m2
X m4 m5 m7 m6
Z
Introduction to CS231 57
Solutions for practice K-map 1
• Here is the filled in K-map, with all groups shown.
– The magenta and green groups overlap, which makes each of them as large as possible.
– Minterm m6 is in a group all by its lonesome.
• The final MSP here is x’z + y’z + xyz’.
Y
0 1 1 0
X 0 1 0 1
Z
Introduction to CS231 58
Four-variable K-maps
• We can do four-variable expressions too!
– The minterms in the third and fourth columns, and in the third and fourth rows, are switched around.
– Again, this ensures that adjacent squares have common literals.
• Grouping minterms is similar to the three-variable case, but:
– You can have rectangular groups of 1, 2, 4, 8 or 16 minterms.
– You can wrap around all four sides.
Y
m0 m1 m3 m2
m4 m5 m7 m6
m12 m13 m15 m14X
Wm8 m9 m11 m10
Z
Y
w’x’y’z’ w’x’y’z w’x’yz w’x’yz’
w’xy’z’ w’xy’z w’xyz w’xyz’
wxy’z’ wxy’z wxyz wxyz’X
Wwx’y’z’ wx’y’z wx’yz wx’yz’
Z
Introduction to CS231 59
Example: Simplify m0+m2+m5+m8+m10+m13
• The expression is already a sum of minterms, so here’s the K-map:
• We can make the following groups, resulting in the MSP x’z’ + xy’z.
Y
1 0 0 1
0 1 0 0
0 1 0 0X
W1 0 0 1
Z
Y
m0 m1 m3 m2
m4 m5 m7 m6
m12 m13 m15 m14X
Wm8 m9 m11 m10
Z
Y
1 0 0 1
0 1 0 0
0 1 0 0X
W1 0 0 1
Z
Y
w’x’y’z’ w’x’y’z w’x’yz w’x’yz’
w’xy’z’ w’xy’z w’xyz w’xyz’
wxy’z’ wxy’z wxyz wxyz’X
Wwx’y’z’ wx’y’z wx’yz wx’yz’
Z
Introduction to CS231 60
K-maps can be tricky!
• There may not necessarily be a unique MSP. The K-map below yields two valid and equivalent MSPs, because there are two possible ways to include minterm m7.
• Remember that overlapping groups is possible, as shown above.
Y
0 1 0 1
X 0 1 1 1
Z
y’z + yz’ + xy y’z + yz’ + xz
Y
0 1 0 1
X 0 1 1 1
Z
Y
0 1 0 1
X 0 1 1 1
Z
Introduction to CS231 61
Limitations of K(arnaugh) -maps
A postscript from Aberdeen ...
• Simpification using K-maps is an essentially visual method intended for use by people. It’s not an algorithm and cannot be mechanised directly.
• With more than 5-or-so variables, the method is no longer visually appealing for people.
• Real algorithms have also been developed and implemented.
• Best known: the Quine-McClusky algorithm, which can handle any number of variables, and always results in a minimal-size expression equivalent with the input.
Introduction to CS231 62
Am algorithm for circuit simplification
• Quine-McClusky algorithm (a very rough sketch!)
– Input: a “sum of products” representation of a given function (e.g., obtained via the truth table, as above). Then two steps:
1. List all the minterms in this representation, trying all their pairwise simplifications (e.g., wxyz’ + wx’yz’ = wyz’), then all their pairwise simplifications, and so on. This gives you a set of candidate products, whose sum is equivalent to the input.
2. Then check which of these products is actually needed. This is done by checking which of the original minterms are “covered” by each of these products, then removing products that are not needed. (This is nondeterministic, since different choices may be possible.)
• Algorithm originally invented for the teaching of logic!
• Details: Ken Rosen, “Discrete Mathematics and its Applications”, (fifth edition) chapter 10.
• Implementations on the web (e.g., from Oefai, an AI institute at the University of Vienna)