The University of Texas at Arlington Algebraic Methods
CSE 2441 – Introduction to Digital Logic Dr. Gergely Záruba
Bridge from Discrete Structures • To describe we use the description tools of “A i “Axiomatic ti Th Theory”: ” • Unambiguous definitions • Axioms (Postulates) – the starting truths • Theorems – the provably correct statements
• We began acquiring tools of description in Di Discrete t St Structures t • Here we acquire more such tools, and put some of the theory in practical perspective • Vocabulary is crucial (makes the material simple 2 and makes sure we all talk the same language)
1
BOOLEAN ALGEBRA 3
A Model to Represent Logic • We need a model that can be used to representt logical l i l th thought ht and d reason. • George Bool (1849) has come up with an abstract algebraic structure that has been used since. This includes: • A set of postulates • A set of theorems (or rules)
4
2
Boolean Algebra Postulate-1 • Defintion: • Boolean algebra is a closed algebraic system, containing a set of K (two or more) elements and two operators * and + • It is closed as any element a in K and b in K, the “sum or OR” (a+b) and the “product or AND” ( a*b) b both th will ill b belong l tto K • Precedence is given to the * operator
5
Boolean Algebra Postulate-2 • Existence of 1 and 0 elements • There exist unique elements 1 and 0 such that : • a+0=a • a *1 = a
• We call 0 the identity element for the OR operation ti and d 1 the th id identity tit element l t ffor the th AND operation
6
3
Boolean Algebra Postulate -3 • Commutativity of the operators: • For a,bK: • a+b=b+a • a*b = b*a
7
Boolean Algebra Postulate -4 • Associativity of the operators: • For a,b,cK: • a + (b +c) = (a + b) + c • a * (b * c) = (a * b) * c
8
4
Boolean Algebra Postulate -5 • Distributivity of the + over * and * over +: • For a,b,cK: • a + (b * c) = (a + b) * (a + c) • a * (b + c) = (a * b) + (a * c)
9
Boolean Algebra Postulate -6 • Existence of the complement: • For aK, there exists an āK such that: • a+ā=1 • a*ā = 0
10
5
Venn Diagrams for Visualization • E.g., a+b K a
b
• Could be used to visualize more than 2 variables • Could be used to visualize the postulates 11
The Principle of Duality • If an expression is valid then the dual of th t expression that i iis also l valid lid • The dual can be found by swapping all operators against their counterparts (i.e., + with * and vice versa) and by swapping the identity elements with each other (i.e., 1 by 0 and vice versa) • E.g.,: the dual of (a+b)(a+c) is (ab+ac) • The following theories are numbered arbitrarily so theory-1 is not going to be called theory-1 by other textbooks…
12
6
Boolean Algebra Theorem -1 • Idempotency: • a+a=a • a*a=a (notice that they are duals so it is enough to prove one of them)) p
13
Boolean Algebra Theorem -2 • Null elements: • a+1=1 • a*0=0 (notice that they are duals so it is enough to prove one of them)) p
14
7
Boolean Algebra Theorem -3 • Involution: • a =a
15
Boolean Algebra Theorem -4 • Absorption: • a + ab = a • a * (a+b) = a (notice that they are duals so it is enough to prove one of them)) p
16
8
Boolean Algebra Theorem -5 • Absorption-2: • a + āb = a+b • a * (ā+b) = ab (notice that they are duals so it is enough to prove one of them)) p
17
Boolean Algebra Theorem -6 • Absorption-3: • ab + āb = b • (a+b) * (ā+b) = b (notice that they are duals so it is enough to prove one of them)) p
18
9
Boolean Algebra Theorem -7 • Absorption-4: • ab + ābc = ab + bc • (a + b) * (ā + b + c) = (a + b) (b + c) (notice that they are duals so it is enough to prove one of them)) p
19
Boolean Algebra Theorem -8 • DeMorgan Theorems: •
a+b=a*b
•
a*b = a + b
((notice that they y are duals so it is enough g to prove one of them) They can be generalized for an arbitrary (but fininte) number of variables 20
10
Boolean Algebra Theorem -9 • Consensus: • ab + āc +bc = ab + āc • (a + b) * (ā + c) * (b + c) = (a + b) (ā + c) (notice that they are duals so it is enough to prove one of them)) p
21
Boolean Algebra Theorem -10 • Shanon’s Expansion: • f(x1,x2,…,xn)=x1f(1,x2,…,xn)+x1f(0,x2,…,xn) • f(x1,x2,…,xn)=[x1+f(0,x2,…,xn)]+[x1+f(1,x2,…,xn)] (notice that they are duals)
22
11
Boolean Algebra – Cheat Sheet
Textbook Table 2.2 (pg. 91)
23
SWITCHING ALGEBRA/FUNCTIONS
24
12
From Boolean Algebra to Switching Algebra • For switching algebra, we specify K to contain exactly two elements K={0 K={0,1} 1} • We can refer to these values as {false,true}, or {low,high} as well. • (In general capital letters represent variables and small letters represent values that they take, i e X1 vs. i.e., vs x1)
25
Number of Switching Functions • A function f(X1, X2, .., Xn) has n variables. Since each of these variables can take one of exactly two values, there are 2n different ways variables can be assigned to functions. • Since each(!) one of those assignments can n result in two possible outcomes, there are 22 different switching functions • For n=0, there are two functions: f0=0 and f1=1 • For n=1, there are four functions f(A): f0(A)=0, f1(A)=A, f2(A)=A, and f0(A)=1 26
13
Switching Functions for n=2 • There are thus 16 two-variable switching functions f0(A,B) functions, (A B) to f15(A,B) (A B) A
B
f0
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10 f11 f12 f13 f14 f15
0
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
1
0
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
1
1
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
• Any two variable function can be reduced to one of these • Note: f8 is AND, f14 is OR, f6 is XOR, f7 is NAND, and f1 is NOR 27
Truth Tables • Previous slide contains 16 truth tables in one. This is still doable for n=2. n 2. For n=3, n 3, there are a total of 256 different switching functions, 65536 for n=4, ~4.29B for n=5, and ~1.16*1077 for n=8 (the number of atoms in the observable universe is about 1080) • A truth table has four sections: ABC f(A,B,C)=AB+AC 000 001 010 011 100 101 110 111
0 0 0 0 0 1 1 1
28
14
Algebraic Forms • The same switching function can be given in many ways. ways There are some forms that are more desirable • SOP form (Sum of Products), the OR-ing of several AND-ed literals (uncomplemented or complemented variables) • E.g., E g f(A f(A,B,C,D)=ABC+DC+ACD B C D)=ABC+DC+ACD
(true heavy)
• POS form (Product of Sums) • E.g., f(A,B,C,D,E) =(A+E)(C+D+E)(B+D)
(false heavy)
29
Algebraic Forms: Canonical SOP a.k.a. disjunctive normal form
• If a product (AND) contains all variables of the function in either complemented or uncomplemented form then this product is called a minterm • A canonical SOP is a form where all products are minterms • E.g., f(A,B,C) = ABC + ABC + ABC + ABC
• If we looked at the literals as a n-bit binary code (n is the number of variables in the function) and assigned 0 to a literal if it is complemented and 1 otherwise, then each of the minterms could be uniquely numbered. • E.g., ABC would be 001 and thus minterm-1 or m1 • E.g., ABC would be 101 and thus minterm-5 or m5 • Thus the above f(A,B,C) = m1+m2+m5+m7 = m(1,2,5,7) (Note, that this is a notation only!) • The order of the variables in this notation becomes important; the minterms for f(A,B,C) and f(B,A,C) are not the same
30
15
Algebraic Forms: Canonical POS a.k.a. conjunctive normal form
• If a product (OR) contains all variables of the function in either complemented or uncomplemented form then this product is called a maxterm • A canonical POS is a form where all products are maxterms • E.g., f(A,B,C) = (A+B+C) (A+B+C) (A+B+C) (A+B+C)
• If we looked at the literals as a n-bit binary code (n is the number of variables in the function) and assigned 1 to a literal if it is complemented and 0 otherwise(!!!), then each of the minterms could be uniquely numbered. • E.g., (A+B+C) would be 110 and thus maxterm-6 or M6 • E.g., (A+B+C) would be 010 and thus maxterm-52or M2 • Thus the above f(A,B,C) = M0 * M2* M5* M6 = M(0,2,5,6) (Note, that this is a notation only!) • Notice, that order of variables is important again 31
Duality of Canonical POS and SOP • Minterms and maxterms are complements off each h other th • i.e., Mi=mi=Mi and mi=Mi=mi • e.g., if f(A,B,C)= m(1,2,5,7) then f(A,B,C)
= M(1,2,5,7)
• And since f(A,B,C)= m(0,3,4,6) it becomes apparent that in order to convert from canonical SOP to POS (or vice versa) the complementing min/maxterms need to be 32 used.
16
So, How Do We Obtain Canonical SOP Forms? • Recall Shanon’s expansion theorem (T10) • f(x1,x2,…,xn)=x1f(1,x2,…,xn)+x1f(0,x2,…,xn) • This can be used one after the other for all variables to obtain canonical SOP
• Alternatively Theory-6 could be used • ab+ab=a ab ab a use this for each product not containing a variable • How about canonical POS? Same tricks could be used (b versions of theories) or just use the duality rule by finding canonical SOP first. 33
Incompletely Specified Functions • In real life, many times, functions do need to be true for some minterms, do need to be false for some others, but there may be some minterms for which the designer does not care (don’t care) if the function is false or not. • For example if we know that some input combinations will never happen (e.g., BCD input) or if for some input combination it really does not matter what the output is. • In canonical SOP we can represent don’t don t care minterms as di instead of mi. In canonical POS we can use Di. • E.g., a function working on BCD input could be: f(A,B,C,D) = m(0,2,4,6,8)+d(10,11,12,13,14,15)
• Don’t cares can actually be helpful when minimizing functions (to make them as simple as possible).
34
17
Simplifying Switching Functions • Normal forms (POS,SOP, and cannonicals) are not necessarily the simplest forms of a function. • E.g., f(A,B,C,D)=ABC+D= m(1,3,5,7,9,11,13,14,15) • Former requires one 3-input AND and one 2-input OR gates, latter requires nine 4-input AND and one 9-input OR gates.
• If we want our function to be realized with the least amount of logic gates, then we need to reduce the number of operators and the number of inputs to those operators. • Having said that that, in order to simplify (or minimize) switching functions we usually (but not always) first put them in canonical SOP • We can then use switching algebra (or Boolean algebra) to try to reduce them. This is cumbersome and requires a lot of experience. It is also not easily automated. • Would be nice to have some simple methods…
35
KARNAUGH MAPS 36
18
The Need for Karnaugh Maps • Is a semi-systematic way to reduce switching functions • Can be used to up to five (becomes somewhat tricky) maybe six (becomes really tricky) variable switching functions • Recall Theory-6: ab+ab=a • This is the best way to reduce functions
• Thus, if we could organize minterms, so that the ones differing in just a single literal (complemented vs vs. uncomplemnted) would be placed next to each other then these two could be simplified • E.g., f(A,B,C)=ABC+ABC=BC = m7+m3
• How could we graphically put adjacent minterms next to37 each other?
Two/Three Variable K-Maps • Organizing minterms into such a map is somewhat h t straight t i ht forward f d for f smallll n-s A 0
1
0 m0
m2
1 m1
m3
B
AB C 0
00 m0
1 m1
01 m2
11 m6
10 m4
m3
m7
m5
Note, that m4 and m0 are adjacent And that m5 and m1 are adjacent as well 38
19
Four Variable K-Map • Graph theory indicates we can still do this f four for f variables i bl AB 00 m0
01 m4
11 m12
10 m8
m1
m5
m13
m9
11 m3
m7
m15
m11
10 m2
m6
m14
m10
CD 00 01
Adjacencies wrap around borders! Where are the white arrows? Order has to be learned, not really straight forward
39
Five Variable K-Map • Graph theory indicates we can’t really do this so it becomes tricky – we need two tables f(A f(A,B,C,D,E) B C D E) BC
BC
m0
01 m4
11 m12
m8
m1
m5
m13
m9
01
11 m3
m7
m15
10 m2
m6
m14
DE 00 01
00
10
m16
01 m20
11 m28
m24
m17
m21
m29
m25
m11
11 m19
m23
m31
m27
m10
10 m18
m22
m30
m26
DE 00
00
A=0
10
A=1 What are those adjacencies again?
40
20
Mahoney Maps • Can we rearrange the variables so there is more method th d tto the th madness? d ? BD 00 m0
01 m1
11 m5
10 m4
m2
m3
m7
m6
11 m10
m11
m15
m14
10 m8
m9
m13
m12
AC 00 01
Adjacencies wrap around borders! Order is somewhat simpler
41
So How Do We Plot Switching Functions? • E.g., f(A,B,C,D)=
m(0,2,4,6,8,12)
AB 00
CD m0
01
01
1
m4
m1
0
11
m3
10
m2
00
11
1
m12
m5
0
0
m7
1
m6
10
1
m8
1
m13
0
m9
0
0
m15
0
m11
0
1
m14
0
m10
0 42
21
Minterm and Maxterm K-Maps • E.g., f(A,B,C,D)= MINTERM
AB 00
CD 00
m0
m(0,2,4,6,8,12)
1
01 m4
1
MAXTERM
AB 11
m12
1
10 m8
1
00
CD 00
m0
01 m4
11 m12
10 m8
01
m1
m5
m13
m9
01
m1
0
m5
0
m13
0
m9
11
m3
m7
m15
m11
11
m3
0
m7
0
m15
0
m11
0
10
m2
m14
m10
10
m2
m14
0
m10
0
1
m6
1
m6
0
• E.g., f(A,B,C,D)= M(1,3,5,7,9,10,1113,14,15) 43
Why Did We Do This Again? • SIMPLIFICATION! • So, how do we simplify? • We look for representatives of T6 by circling 1-s next to each other. Pairs work, 4-neighbors work (if they are either in line or in box), box) 8-neighbors work, work 16-neighbors work, etc.
44
22
K-Map Based Simplification • We need to find groups (implicants) that cover the entire map. map AB
F(A,B,C,D)=CD+ACD 00
CD 00
m0
1
01 m4
1
11 m12
1
10 m8
1
01
m1
m5
m13
m9
11
m3
m7
m15
m11
10
m2
m14
m10
1
m6
1
Some terms: •Implicant •Prime implicant •Essential prime implicant •Cover
45
K-Map Based Simplification • We need to find groups (implicants) that cover the entire map. map AB 00
F(A,B,C,D)=AD+CAD 00
CD m0
1
01 m4
1
11 m12
1
10 m8
01
m1
m5
m13
m9
11
m3
m7
m15
m11
10
m2
m14
m10
1
m6
1
1
Some terms: •Implicant •Prime implicant •Essential prime implicant •Cover
46
23
K-Map Based Simplification • We need to find groups (implicants) that cover the entire map. map AB 00
F(A,B,C,D)=AD+CD 00
CD m0
1
01 m4
1
11 m12
1
10 m8
01
m1
m5
m13
m9
11
m3
m7
m15
m11
10
m2
m14
m10
1
m6
1
1
Some terms: •Implicant •Prime implicant •Essential prime implicant •Cover
47
Algorithm-1 for Finding the Best Cover 1. Count the adjacencies for each minterm 2 Select 2. S l t an uncovered d minterm i t with ith llowestt adjacency number (if several are the same, pick randomly) 3. Check which prime implicant covers most other uncovered minterms and select that. 4 Go 4. G to t 2 •
Is this optimal? We are making random choices, how can we be sure?
48
24
Algorithm-2 for Finding the Best Cover 1. Circle all prime implicants 2 Select 2. S l t allll essential ti l prime i iimplicants li t 3. Select the minimum cover from the remaining prime implicants to finish the cover • •
Is this optimal? Step three is still random… How could we make it optimal? – An exhaustive search on step-3 would make this algorithm optimal. This is expensive. 49
How about POS Forms? • Terminology is different: instead of i li implicant t we have h i li t implicate • We can do the same operations over zeros. • When writing the POS form – keep in mind that variables need to be complemented • It is just easier to to do the complemented function using SOP form and apply DeMorgan
50
25
Incomplete Functions • If the function is incomplete then we can d id tto include decide i l d or iignore don’t d ’t cares. • We include them only if they make a prime implicant larger. • For example: • f(A f(A,B,C,D)= B C D)= m(2,4,5,6,8,10)+d(7,9,12,13,14) m(2 4 5 6 8 10)+d(7 9 12 13 14) = M(0,1,3,11,16)+D(7,9,12,13,14) • Note that the two minimizations may not result in equivalent functions! 51
QUINE-MCCLUSKY TABULAR METHOD 52
26
Quine-McCluskey Method • Systematic method (can be easily computerized) • Minterms are written up in a table (n-variable minterms). Based on this (n-1)-variable implicants are identified. Based on this (n-2) variable implicants are identified – and so on. • Then we identify essential prime implicants, and prime implicants. The cover is based on these. 53
Q-M Method – Step-1 • Step 1. Write all minterms in a two column table; organize minterms in groups based on how many 1-s 1s they have (not neccesarily the minterm order) • E.g, f(A,B,C,D)= m(0,1,2,4,5,7,10,12,14) Minterm #
ABCD
0
0000
1
0001
2
0010
4
0100
5
0101
10
1010
12
1100
7
0111
14
1110
Group-0 Group-1 Group 1
Group-2 Group-3 54
27
Q-M Method – Step-2 • Do an exhaustive search between adjacent groups to see if minterms can be combined; repeat this for the new columns as well well. List-1
List-2
List-3
Minterm
ABCD
Minterms ABCD
Minterms ABCD
0
0000 √
0,1
000- √
0,4,1,5
1
0001 √
0,2
00-0
2
0010 √
0,4
0-00 √
4
0100 √
1,5
0-01 √
5
0101 √
2,10
-010
10
1010 √
4,5
010- √
12
1100 √
4,12
-100
7
0111 √
5,7
01-1
14
1110 √
10,14
1-10
12,14
11-0
0-0-’s have to be in the same place and they can differ in only one digit
55
Q-M Method – Step-2 • Do an exhaustive search between adjacent groups to see if minterms can be combined; repeat this for the new columns as well well. List-1
List-2
List-3
Minterm
ABCD
Minterms ABCD
Minterms ABCD
0
0000 √
0,1
000- √ PI2
0,4,1,5
1
0001 √
0,2
00-0 PI23
2
0010 √
0,4
0-00 √
4
0100 √
1,5
0-01 √
5
0101 √
2,10
-010 PI34
10
1010 √
5,7 4,5
01001-1 PI √5
12
1100 √
10,14 4,12
1-10 PI46 -100
7
0111 √
12,14 5,7
01-1 11-0 PI75
14
1110 √
10,14
1-10 PI6
12,14
11-0 PI7
0-0- PI PI11
56
28
Q-M Method Step-3 • Now need to find a minimum cover. For that we need to create another “cross cross reference table”. table .
0
1
PI1
X
X
PI2
X
2
4
5
X
X
7
10
12
14 Separating Pis with different number of implicants
X
PI3
X
PI4
X X
PI5
X X
X X
PI6
X X
PI7
X 57
Q-M Method Step-4 • Identify essential prime implicants (minterm is only covered by them). They need to be chosen. √
√
0
1
**PI1
X
PI2
X
PI3 PI4 **PI5
PI6 PI7
2
√
√
√
4
5
7
X
X
10
12
14
X X
X X
X X
X
X X
X 58
29
Q-M Method Step-4.2 • Select PIs to finish cover; ((remove essentials and their minterms for more visibility). y) √
√
0
1
**PI1
X
PI2
X
2
√
√
√
4
5
7
X
X
10
12
X
PI3
X
X
PI4
X
X
**PI5
PI6
X
PI7
PI2
X
PI3
X
10
X
X
PI6
X
PI7
12
14
X X
PI4
X
2
14
X
X X
X
• But even then, how to choose?
59
Q-M Method Step-4.2 √
√
0
1
**PI1
X
PI2
X
2
√
√
√
4
5
7
X
X
10
12
14
X
PI3
X
X X
PI4 **PI5
X X
PI6
X X
PI7 List-2
X
List-3
Minterm
ABCD
Minterms ABCD
Minterms ABCD
0
0000 √
0,1
000- √
0,4,1,5
1
0001 √
0,2
00-0 PI2
2
0010 √
0,4
0-00 √
4
0100 √
1,5
0-01 √
5
0101 √
2,10
-010 PI3
10
1010 √
4,5
010- √
12
1100 √
4,12
-100 PI4
7
0111 √
5,7
01-1 PI5
14
1110 √
10,14
1-10 PI6
12,14
11-0 PI7
√
√
√
2
10
12
14
PI2
X
*PI3
X
X
PI4
X
List-1
√
0-0- PI1
PI6 *PI7
X X
X X
X Cyclic chart
Thus, PI1,PI3,PI5,PI7 f(A,B,C,D)= AC+BCD+ABD+ABD 60
30
How About Q-M and Incomplete Functions? • Same first and second steps, handling d’s as if they th were m’s ’ • In step three do not create columns for d’s
61
What if We have Multiple Outputs? • If we have multiple outputs (more than one function), we could benefit from shared implicants. • We can extend the Q-M tables to include more functions. We just need one more column for the lists that indicates in which function they are used. • For step 2: terms can only be combined if they have a common flag (and the combination can carry only those) • For step 3: each function should be represented by columns of those minterms that they have PIs for.
62
31