Download presentation

Presentation is loading. Please wait.

Published byJaime Wrinkle Modified over 2 years ago

1
Introduction to CS231 0 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 in which 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.)

2
© Howard Huang 1 Computers use voltages to represent information. In modern CPUs the voltage is usually limited to V to minimize power consumption. It’s convenient for us to translate these analog voltages 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 with just 1s and 0s. – Then we’ll introduce special operations for computing with 1s and 0s, by treating them as the logical values “true” and “false.” Volts

3
Introduction to CS231 2 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

4
Introduction to CS231 3 Using the switch Output InputOutput 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..

5
Introduction to CS231 4 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 Output This 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)?

6
Introduction to CS231 5 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)

7
Introduction to CS231 6 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 InputOutput Input

8
Introduction to CS231 7 Basic Gates There are three basic kinds of logic gates AND of 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?

9
Introduction to CS231 8 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

10
Introduction to CS231 9 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 AD Why did they use 10? Anything special about it? – Not really. – Probably the fact that we have 10 fingers influenced this

11
Introduction to CS 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 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x ) + (7 x ) + (5 x ) =

12
Introduction to CS 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: in binary – The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = = 13.25

13
Introduction to CS Binary addition example worked out The trick when adding numbers: positional weights and carry ! Exercise: what are the black numbers equivalent to in decimal? 1110(Carries) 1011(Augend) +1110(Addend) 11001(Sum) The initial carry in is implicitly 0 most significant bit (MSB) least significant bit (LSB)

14
Introduction to CS 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 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?

15
Introduction to CS 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 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!

16
Introduction to CS 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 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

17
Introduction to CS 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 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., ).

18
Introduction to CS Doing addition with gates What does addition look like in a circuit? Result Carry Half adder

19
Introduction to CS Half adder: result Result Exclusive OR Output is 1 iff exactly one of the 2 inputs is 1 A special symbol for this gate:

20
Introduction to CS XOR

21
Introduction to CS 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= = = = 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)”).

22
Introduction to CS Adding three bits What we really need to do is add three bits: the augend and addend, and the carry in from the right = = = = = = = = 11 (The bitstring on the right is the binary representation of the sum of the three numbers on the left)

23
Introduction to CS 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.

24
Introduction to CS 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 ( = 01) Step 3:Use C1 to find C2 and S1 ( = 10) Step 4:Use C2 to compute C3 and S2 ( = 10) Step 5:Use C3 to compute CO and S3 ( = 11) The final answer is

25
Introduction to CS 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 gate to its input) Sorry to be a bit brief about this...

26
Introduction to CS Basic Boolean operations There are three basic operations for logical values. AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input xy, or x yx + yx’ Operation: Expression: Truth table:

27
Introduction to CS 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’.

28
Introduction to CS 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. f(0,0,0)= (0 + 1)0 + 1= 1 f(0,0,1)= (0 + 1)1 + 1= 1 f(0,1,0)= (0 + 0)0 + 1= 1 f(0,1,1)= (0 + 0)1 + 1= 1 f(1,0,0)= (1 + 1)0 + 0= 0 f(1,0,1)= (1 + 1)1 + 0= 1 f(1,1,0)= (1 + 0)0 + 0= 0 f(1,1,1)= (1 + 0)1 + 0= 1 f(x,y,z) = (x + y’)z + x’

29
Introduction to CS 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 x yx + yx’ Operation: Expression:

30
Introduction to CS 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’

31
Introduction to CS 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

32
Introduction to CS 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 2 3 = 8 minterms: Each minterm is true for exactly one combination of inputs: x’y’z’x’y’zx’yz’x’yz xy’z’xy’zxyz’xyz MintermIs true when…Shorthand x’y’z’x=0, y=0, z=0m 0 x’y’zx=0, y=0, z=1m 1 x’yz’x=0, y=1, z=0m 2 x’yzx=0, y=1, z=1m 3 xy’z’x=1, y=0, z=0m 4 xy’zx=1, y=0, z=1m 5 xyz’x=1, y=1, z=0m 6 xyzx=1, y=1, z=1m 7

33
Introduction to CS Minterms You have encountered these before...

34
Introduction to CS 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)

35
Introduction to CS 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. f = x’y’z’ + x’y’z + x’yz’ + x’yz + xyz’ = m 0 + m 1 + m 2 + m 3 + m 6 = m(0,1,2,3,6) f’ = xy’z’ + xy’z + xyz = m 4 + m 5 + m 7 = m(4,5,7) f’ contains all the minterms not in f

36
Introduction to CS (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).

37
Introduction to CS 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.

38
Introduction to CS 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.

39
Introduction to CS 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’

40
Introduction to CS 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 2 n rows. – Our example has three inputs, so the truth table will have 2 3 = 8 rows. All the possible input combinations are shown.

41
Introduction to CS 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) =

42
Introduction to CS Finishing the truth table Doing the same thing for all the other input combinations yields the complete truth table. This is simple, but tedious.

43
Introduction to CS 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. f(x,y,z)= x’y’z + x’yz’ + xy’z + xyz = m 1 + m 2 + m 5 + m 7

44
Introduction to CS 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

45
Introduction to CS 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.

46
Introduction to CS 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.

47
Introduction to CS 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 ]

48
Introduction to CS 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.

49
Introduction to CS 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:

50
Introduction to CS 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):

51
Introduction to CS 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’

52
Introduction to CS 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: f(x,y,z)= x’y’z+ xy’z+ xyz’+ xyz = m 1 +m 5 +m 6 +m 7

53
Introduction to CS 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. f(x,y,z) = x’y’z + xy’z + xyz’ + xyzf(x,y,z) = m 1 + m 5 + m 6 + m 7

54
Introduction to CS 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.

55
Introduction to CS 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.

56
Introduction to CS Practice K-map 1 Simplify the sum of minterms m 1 + m 3 + m 5 + m 6.

57
Introduction to CS 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 m 6 is in a group all by its lonesome. The final MSP here is x’z + y’z + xyz’.

58
Introduction to CS 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.

59
Introduction to CS Example: Simplify m 0 +m 2 +m 5 +m 8 +m 10 +m 13 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.

60
Introduction to CS 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 m 7. Remember that overlapping groups is possible, as shown above. y’z + yz’ + xyy’z + yz’ + xz

61
Introduction to CS 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.

62
Introduction to CS 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)

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google