an application of boolean algebra

11
151 An Application of Boolean Algebra Will Watkins Department of Mathematics & Computer Science University of Texas Pan American Edinburg, Texas 78539 Henjin Chi Department of Mathematics & Computer Science Indiana State University Terre Haute, Indiana 47809 Every mathematician has suffered through recurrent variations of this conversation. "Oh, you’re a mathematician. ... " You agonize for a microsecond anticipating one of the following. "Mathematics was my worst subject," "Are you a high school coach?," or "Oh, you can help me with my income tax." What is an appropriate response? The conversation moves on and the mathematician is left to respond to himself or herself, "Mathematics is not so much the content as it is the form. If completing an income tax 1040 form is based on logic and inner consistency then . . . oh, maybe ’help me with* means ’help me pay\" Finally everyone is relieved the conversation has turned to football. Unfortunately, our own students may, at times, express misunderstanding of what mathematics really is. Students begin, or at least are encouraged, to identify the field axioms of arithmetic as early as grade school. Many of us can remember the relief we felt upon realizing we only needed to memorize half of the multiplication tables because 7x5=5x7. Other than the distributive law (more technically the distributive law of multiplication over addition), the axioms seem almost too obvious to state. It can be very instructive for students to realize there are other algebraic structures, many arising from common experience, and that identifying the properties, or axioms, of these structures can be very practical. Bertrand Russell credits George Boole (Boyer, 1968) as having discovered pure mathematics with Boole*s work The Laws of Thought (1854/1958). Boolean algebra may indeed be at the root of pure mathematics but it also has fascinating applications in the applied world of computer design. Students are very aw^are of the influence of computers on mathematics but less aware of the profound impact of mathematics on computers. In this article, an application of a binary Boolean algebra in computer design is illustrated, but first, agreement on notation is required. The simplest Boolean algebra is the algebra of true and false. The statement, "She has blue eyes and she has brown hair" is true precisely when both of the components statements, "She has blue eyes" and "She has brown School Science and Mathematics Volume 90 (2) February 1990

Upload: will-watkins

Post on 30-Sep-2016

225 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: An Application of Boolean Algebra

151

An Application of Boolean AlgebraWill WatkinsDepartment of Mathematics & Computer ScienceUniversity of Texas Pan AmericanEdinburg, Texas 78539

Henjin ChiDepartment of Mathematics & Computer ScienceIndiana State UniversityTerre Haute, Indiana 47809

Every mathematician has suffered through recurrent variations of thisconversation. "Oh, you’re a mathematician. ... " You agonize for amicrosecond anticipating one of the following. "Mathematics was my worstsubject," "Are you a high school coach?," or "Oh, you can help me with myincome tax." What is an appropriate response? The conversation moves onand the mathematician is left to respond to himself or herself, "Mathematicsis not so much the content as it is the form. If completing an income tax 1040form is based on logic and inner consistency then . . . oh, maybe ’help mewith* means ’help me pay\" Finally everyone is relieved the conversation hasturned to football. Unfortunately, our own students may, at times, expressmisunderstanding of what mathematics really is.

Students begin, or at least are encouraged, to identify the field axioms ofarithmetic as early as grade school. Many of us can remember the relief wefelt upon realizing we only needed to memorize half of the multiplicationtables because 7x5=5x7. Other than the distributive law (moretechnically the distributive law of multiplication over addition), the axiomsseem almost too obvious to state. It can be very instructive for students torealize there are other algebraic structures, many arising from commonexperience, and that identifying the properties, or axioms, of these structurescan be very practical.

Bertrand Russell credits George Boole (Boyer, 1968) as having discoveredpure mathematics with Boole*s work The Laws of Thought (1854/1958).Boolean algebra may indeed be at the root of pure mathematics but it also hasfascinating applications in the applied world of computer design. Students arevery aw^are of the influence of computers on mathematics but less aware ofthe profound impact of mathematics on computers. In this article, anapplication of a binary Boolean algebra in computer design is illustrated, butfirst, agreement on notation is required.The simplest Boolean algebra is the algebra of true and false. The

statement, "She has blue eyes and she has brown hair" is true precisely whenboth of the components statements, "She has blue eyes" and "She has brown

School Science and MathematicsVolume 90 (2) February 1990

Page 2: An Application of Boolean Algebra

152 Boolean AIgebra

hair" are true. The frequently used conjunction "or" is unfortunately moreambiguous. The use of "or" is different in the following two statements:"Eat your vegetables or you will have no dessert" and "Each person in yourclass has a pen or a pencil." In the first case, there seems to be an impliedexclusion; that is, either "you eat your vegetables" or "you will have nodessert" but not both. You might feel cheated if you ate your vegetables andstill had no dessert! But in the second case, you would feel the statement wasstill true if some person had both a pen and a pencil. In the interest ofconsistency and precision, the following interpretation of "and" and "or" isused. Suppose A and B are two statements, "1" represents true, "0"represents false. Then the following truth tables specify our future use of"and" and "or."

ABAandBABAor B

0000 1 01 0 01 1 1

0000 1 11 0 1

This definition of "or" is the "inclusive or" definition, sometimes calleddisjunction. The other definition of "or"�"exclusive or"�that is, "A or Bbut not both" is not used, but is shown in the following truth table. The"inclusive or" will be used.

A B A or B but not both

00 00 1 11 0 11 1 0

To complete this algebra, the operation of negation is included. If A is avariable that is either true or false, then A’ will denote the opposite ornegation of A. The following truth table defines negation.

A A’

0 11 0

This algebra is well known, having been extensively studied, but studentscan discover it for themselves by drawing on their acquaintance with Englishto develop the axioms of the algebra. Many students will discover, withsurprise, that there are two distributive laws: (a) the distributive law of "and"over "or," and (b) the distributive law of "or" over "and."

Besides its close connection with English statements, this algebra also enjoysa physical realization in the world of electrons. For years, electrical engineers

School Science and MathematicsVolume 90 (2) February 1990

Page 3: An Application of Boolean Algebra

Boolean Algebra 153

and computer scientists have used switching devices that model the Booleanalgebra of true and false. The modern devices are called gates�"and gates,"and "or gates," and "inverters." In simple terms, an "and gate" consists oftwo input wires and one output wire. When current is applied to both of theinput wires, then the output wire emits current, while in any other case theoutput wire of an "and gate" will not emit current. If we imagine that currentflowing is a true condition and current not flowing is a false condition, thenthe "and gate" is operating just as the "and" truth table dictates. An "orgate," on the other hand, operates just as the "inclusive or" truth tabledictates.

Understanding the properties of this true/false algebra is helpful indesigning logic circuits used in computers. With that goal in mind, thefollowing list of easily verifiable properties is provided. These are the axiomsthat students can develop on their own with a minimum of direction, based ontheir acquaintance with the English language. First, both "and" and "or" arecommutative. That is, if A and B are two variables that can take on the valuesof true or false then,

A and B = B and AA or B = B or A

Second, there is a redundancy property,

A and A = A,A or A = A

Third, we note six important identities,

A and A’ = false,A or A/ = true,

A and false = false,A or true = true,A or false = A.

Students are readily willing to accept these as axioms based on their experiencewith the English language. Other properties seem to take more effort beforethey are accepted, however. For example, remember the famous de’Morgan*slaws,

(A and B)’ = A’ or W(A or B)’ = A’ and B’,

or, the associative and distributive laws,

A and (B and C) = (A and B) and CA or (B or C) = (A or B) or CA and (B or C) = (A and B) or (A and C)A or (B and C) = (A or B) and (A or C).

School Science and MathematicsVolume 90 (2) February 1990

Page 4: An Application of Boolean Algebra

154Boolean Algebra

Again, students can verify the reasonableness of such statements because oftheir language maturity. Notice the two distributive laws.As an example of the application of this algebra, consider the following

engineering problem, many parts of which students can help solve. Design a"Family Feud" type device. The device should have three push buttonswitches and two lights. One of the switches will allow the host to reset thesystem, while each of the other switches will be assigned to the respectivecontestants. When the appropriate signal is given, each contestant races topush his or her switch. One of the two lights identifying the winningcontestant will be lit, the other light unlit, and the system will remain in thatstate regardless of what the contestants then do, until the host pushes his orher switch. Once the host’s switch is pushed, the light goes out and anotherrace can begin. This is not a precise statement of the problem and the engineeris left with some choices to make. There is, of course, more than one solutionto this problem. A possible solution is given, and appropriate places thestudents could be asked to assist in the solution are provided.Think of each switch defining a value of true or false respectively,

depending on whether the switch is pushed or not pushed. Examine thecurrent flow in the wire attached to the switch. If current is flowing, weconsider the value of that switch as true; if current is not flowing, we considerthe value of that switch as false. Depending on the history of the game, thewire attached to each light will either carry current, thus lighting the light, ornot carry current. Again consider the value of the wire as true if current isflowing and false otherwise. Give these five wires variable names of H, Ci,�2, Li, L^ respectively for the host’s switch, contestant one’s switch,contestant two’s switch, contestant one’s light, and contestant two’s light. Ourjob, then is to design a box with three input wires and two output wires(Figure 1).

Figure 1.

School Science and MathematicsVolume 90 (2) February 1990

Page 5: An Application of Boolean Algebra

Boolean Algebra 155

The operation of this box is described with a state diagram. A state diagramis a directed graph in which each node denotes a different historical result inthe progress of the game and each edge identifies conditions necessary formoving from one node to another. For each state, a determination of which ifany of the lights must be lit is made. The state diagram in Figure 2 suggeststhe operation of our box. The variable expression associated with eachdirected edge specifies the conditions under which movement from the initialnode of that edge to the terminal node is made. As indicated, movement fromnode a to node b is expected on the condition that C, is true, or Ci = 1;while movement from node a to node c is expected on the condition that C^ istrue, or �3 = 1. But what happens if C, and C^ are simultaneously true? Thestate diagram is ambiguous about this. From a practical standpoint, this willseldom if ever happen; that is, the probability of contestant one andcontestant two both initially pushing their switches at exactly the same instantis so remote as to not be a real concern. Nevertheless, for each state, eightdifferent conditions must be considered, namely when each of the followingare true:

<VC/C/c,’c,c,CiCi

andandandandandandandand

CVc,’CzC;C,’C^’C2c^

andandandandandandandand

H’,H,H’,H,H’,H,H’,H.

Figure 2.

School Science and MathematicsVolume 90 (2) February 1990

Page 6: An Application of Boolean Algebra

156 Boolean AIgebra

Expressions like "Ci and C, and H" and "H and (C, or �3)" arecumbersome. A more convenient notation is to use juxtaposition to represent"and," and "+" to represent "or." As such "Ci and �3 and H" becomesC^C^H, and "H and (Ci or C^Y’ becomes H(Ci+C2). By accepting thenotation of 1 = true and 0 = false, the fundamental properties can berestated. If A, B, and C are Boolean variables then:

AB = BAAA = AAA’ = 0Al = A

(AB)’ = A’+B’A+B = B+AA+A = AA+A’ == 1A+0 == A

(A+B)’ = A’B’(A+B)+C = A+(B+C)

(AB)C = A(BC)A(B+C) = (AB) + (AC)A + (BC) == (A+B)(A+C)

Many of these statements are identical to field axioms students are familiarwith from arithmetic. Some are markedly different; in particular, notice thedistributive property of addition over multiplication.With some coaching students are able to specify the conditions under which

they move from one state to another. Thinking in English is helpful here. Forexample, consider moving from state a to state b if one of two circumstancesexists: (a) the first contestant’s switch is on and the second contestant’s switchis off and the host’s switch is off, or (b) the first contestant’s switch is on andthe second contestant’s switch is on and the host’s switch is off. In otherwords, choose to give the tie to the first contestant. In symbols, this becomesexpression F^ below.The state diagram in Figure 3 considers the effect of all eight possible

conditions on each state. The following functions correspond to Figure 3.

Pi = C/C/H^ + C/C/H + C/CyH + CiC^HF^ = CiC^H7 + CiCyrF3 = c/cy-rF4 = C/C/H + C/C2H + CiC2’H + CiC^HF = F^6 = C/C/H^ + Ci’cy^ + CiC/H’ + CiCjr?7 = F6

The CiC^H^ term had to have a unique assignment to one of the exitfunctions leaving state "a." The likelihood of both contestants hitting

School Science and MathematicsVolume 90 (2) February 1990

Page 7: An Application of Boolean Algebra

Boolean Algebra 157

Figure 3.

switches simultaneously is very small, so the engineering decision of assigningCiCyi’ to F2 gives contestant one a negligible advantage.The typical electronic "inverter," "and gate," and "or gate" used today

have a propagation delay. That is, once a signal change is introduced as inputto one of these devices there is typically 10 to 30 nanoseconds before theoutput responds. This is not a long delay since one nanosecond = 10 ~9

seconds. Take advantage of this propagation delay to "remember" the state.This is very short term memory but, when a change in the input occurs, it willbe long enough to compare the old state with the new inputs to determinewhat the new state must be. Suppose A and B are two logic lines, the valuesof which determine the state by the following table.

A State

1 1 no such state exists

This table assigns a binary code to each state in Figure 4. Now the next statewill be determined by the variables A, B, Ci, C^, and H, while the variables

Li and L2 will be determined by A and B. The problem is now reduced tothree smaller problems, each of which can be considered by the student.Design three boxes, two with inputs A and B that determine Lj and L^

School Science and MathematicsVolume 90 (2) February 1990

Page 8: An Application of Boolean Algebra

158 Boolean Algebra

respectively, and one with inputs A, B, C\, C^, and H that determine the newvalues of A and B. The variables A and B help determine their own newvalues. This is all possible because of the propagation delay.From the association made between the variables A and B and the states a,

b, and c, it is readily seen that L] = A and L^ = B. Defining the new A(respectively new B) in terms of the old A, the old B, Ci, C^, and H is a morechallenging problem. We are looking for functions of the form,

Anew = fi(A,B.Ci,C,,H), and

Bnew = f2(A.B,Ci,C,,H).

Where f, and f^ are Boolean functions of the variables indicated and thefunctions implement the above state diagram. Consider each functionseparately. The variable A is expected to become 1 under precisely twoconditions: (a) we are in state a (A=0,B=0), and F^ = 1; (b) we are in stateb (A=1,B=0), and F^ = 1. Whence, A^.v = (CiC/H’ + C.C^H^A’B’ +(Ci’C/H’ + Ci’C^H’ + CiC/H’ + C^H^AB’.By applying the properties of the Boolean algebra students are able to

obtain simpler expressions. For example, in the expression A^^, =

CiC^H’A’B’ + CiC^A’B’ + C/C/H’AB’ + Ci’C^H’AB’ +CiC/H’AB’ + CiC^H’AB’, any term containing a factor of AB will alwaysbe false because the AB state is never reached. Thus, C/C2’H’AB +C/C^H’AB + CiC/H’AB + CiC,H’AB = 0.

Furthermore, the redundant listing of a term in an expression does not alterthe value of the expression. Hence, A^ = CiC/H’A’B’ + C^C^H’A’B’+ C/C^H^AB’ + C/CsH’AB7 + (CiC/H’AB’ + CiC/H’AB’) +(ClC2H/AB/ + CiCJi^AB’) + (CyC/H’AB + C/C^H’AB +CiC/H’AB + CiC,H’AB).

After rearranging terms A^ = CiC/H’A’B’ + C^H’A’B’ +CiC^H^B’ + CiCJ^AB’ + C/C/H’AB^ + Ci’C2H’AB +CiC^H^B + C.C^H’AB + C/C^’H’AB’ + C/C^H’AB’ +CiC^’H’AB’ + CiCsH’AB’.

Verify that by using the properties of the algebra this last expression reducesto

A^, = H’A + H^’Cp

The variable B, on the other hand, is expected to become 1 under preciselythe two conditions: (a) in state a (A=0,B=0), and F3 = 1; (b) in state c(A=0,B=1), and F^ = 1. From which, B^v = Ci’C^H’A’B7 + (C/Cs’H’+ Ci^H’ + CiC/I-T + C^H^A’B. Again, after rearranging,introducing appropriate redundancies, and adding terms containing a factorAB we obtain B^, = Ci’CJ-TA^ + C/C^H’A’B + C/C/H’A’B +C/CsH’A’B + CiC^’H’A’B + C^H’A’B + C/C/H’AB +C/C^H^B + CiC/H’AB + CiC^H’AB, from which,

B^, = H’B + H’A’Cl’C^.

School Science and MathematicsVolume 90 (2) February 1990

Page 9: An Application of Boolean Algebra

Boolean Algebra 159

If Z^ denotes the integers modulo two (the smallest finite field), then (A,B)and (Ci,C2,H) could, respectively, be considered as a Z^2 vector and a Z^3vector. The problem we have solved could be restated: "Find a function ffrom Z^xZ^3 to Z^2 where f defines the next state in the state diagram. Thatis f(A,B,Ci,C2,H) = (Anew^new)’" Our solution consisted of finding thecomponent functions fi(A,B,Ci,C2,H) = A^. and f^(A,B,C^C^H) == B^.For each function, we listed each input that allowed a non-zero output, andthen simplified the resulting expression. More sophisticated methods exist foreffectively simplifying the expression (e.g., Karnaugh maps). This exampleillustrates the simplicity rather than the sophistication. This naive approachalso highlights the formal definitions and properties of the Boolean algebraplayed in the simplification�observations that are less obvious when moresophisticated algorithms are employed.The circuit designed here is an example of an asynchronous sequential

circuit. The behavior of an asynchronous sequential circuit is determined bythe order in which its input signals change and can be affected at any instantof time. The fact that the output can be affected by the feedback at anyinstant of time, combined with unpredictable propagation delays, introducesthe possibility of hazards in the circuit. Hazards occur if the circuit allows thepossibility of the output values representing anything besides the old state orthe new state during the transition time needed for propagation delay. Toillustrate, an expression containing a simple hazard is given, before returningto the original problem.

Figure 4.

y

Consider a circuit with the architecture as shown in Figure 4, where x,, x^are inputs and y is the output (and state address). For the state diagram inFigure 5, we have

School Science and MathematicsVolume 90 (2) February 1990

Page 10: An Application of Boolean Algebra

160Boolean Algebra

Vnew = XiX/y’ + Xi’x;,y + XiX^y = XiX/y,

which reduces to

Ynew = XiX^’ + x^y.

Suppose at time t=ti we are in the stable condition where y==l, x,=l, and

Figure 5.

V^’ + h^2 + V2

w A x! x?

xi’x^ + x^ + x^x^

School Science and MathematicsVolume 90 (2) February 1990

Page 11: An Application of Boolean Algebra

Boolean AIgebra 161

X2=l. At some time t^ > tj let x^ change to x^=0 while x, remains Xi=l.Because of propagation delay, at t^, y remains y= 1 and x/ remains x^’ =0,unaware of the change in x^. Hence both terms in y^w are both zero andhence at time t^, Ynew = 0- Finally, at some time 13 > tz, the x^’ = 1 and y^ewreturns to y^w = 1- Unfortunately, then, this reduction of y^evv has a hazard.The hazard arose because of the propagation delay through an invertor, andthe momentary confusion while x/ = x^. Returning to the original design, itis a manageable task to verify that no hazard of the type encountered aboveexists in our example.The algebraic properties of Boolean algebra provide the insights for logic

design and analysis. It is a rich and accessible area to expose students toapplicable pure mathematics and a nice example of an algebraic structuredifferent from the real numbers. These ideas are finding their way into collegelevel discrete structures courses for which there is an increasing long list oftextbooks, (Gersting, 1987; Laufer, 1984). From a self-study standpoint,Hoernes and Heilweil (1964) is "a program for self-instruction ... tointroduce the algebra used in the logical design of computers." The firstchapters in many textbooks on computer design for electrical engineeringstudents discuss these ideas (e.g., Mano, 1972).

References

Boole, G. (1958). An investigation: The laws of thought. New York: DoverPublications, Inc. (Original work published 1854)

Boyer, C. (1968). A history of mathematics. Princeton, NJ: PrincetonUniversity Press.

Gersting, J. (1987). Mathematical structures for computer science (2nd ed.).W. H. Freeman & Company.

Hoernes, G., & Heilweil, M. (1964). Introduction to Boolean algebra andlogic design. McGraw-Hill Book Company.

Laufer, H. B. (1984). Discrete mathematics and applied algebra. Prindle,Weber & Schmidt.

Mano, M. M. (1972). Computer logic design. Englewood Cliffs, NJ: Prentice-Hall, Inc.

School Science and MathematicsVolume 90 (2) February 1990