Computational Boolean Algebra. Pingqiang Zhou ShanghaiTech University

Similar documents
EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

EECS150 - Digital Design Lecture 19 - Combinational Logic Circuits : A Deep Dive

CHAPTER1: Digital Logic Circuits Combination Circuits

Anand Raghunathan MSEE 348

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

Systems I: Computer Organization and Architecture

211: Computer Architecture Summer 2016

XI STANDARD [ COMPUTER SCIENCE ] 5 MARKS STUDY MATERIAL.

Multi-Level Logic Optimization. Technology Independent. Thanks to R. Rudell, S. Malik, R. Rutenbar. University of California, Berkeley, CA

EEE130 Digital Electronics I Lecture #4

Review. EECS Components and Design Techniques for Digital Systems. Lec 06 Minimizing Boolean Logic 9/ Review: Canonical Forms

CHAPTER 12 Boolean Algebra

Fundamentals of Computer Systems

Boolean Algebra, Gates and Circuits

Lecture 6: Manipulation of Algebraic Functions, Boolean Algebra, Karnaugh Maps

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

Equivalence Checking of Sequential Circuits

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic

Fundamentals of Computer Systems

Review for Test 1 : Ch1 5

Digital Logic. CS211 Computer Architecture. l Topics. l Transistors (Design & Types) l Logic Gates. l Combinational Circuits.

ECE/CS 250 Computer Architecture

Logic Design. Chapter 2: Introduction to Logic Circuits

Combinational Logic. Mantıksal Tasarım BBM231. section instructor: Ufuk Çelikcan

Digital Logic (2) Boolean Algebra

Combinational Logic. Review of Combinational Logic 1

CprE 281: Digital Logic

L4: Karnaugh diagrams, two-, and multi-level minimization. Elena Dubrova KTH / ICT / ES

Digital System Design Combinational Logic. Assoc. Prof. Pradondet Nilagupta

ECE/CS 250: Computer Architecture. Basics of Logic Design: Boolean Algebra, Logic Gates. Benjamin Lee

WEEK 2.1 BOOLEAN ALGEBRA

Lecture 5: NAND, NOR and XOR Gates, Simplification of Algebraic Expressions

Spiral 2-4. Function synthesis with: Muxes (Shannon's Theorem) Memories

CS226 Mid-Semester Examination (Spring 2016)

Slide Set 3. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

CS61c: Representations of Combinational Logic Circuits

UNIT 4 MINTERM AND MAXTERM EXPANSIONS

Computer organization

Fundamentals of Computer Systems

ECE 2300 Digital Logic & Computer Organization

Every time has a value associated with it, not just some times. A variable can take on any value within a range

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

Karnaugh Maps Objectives

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Boolean Algebra and Digital Logic

COMBINATIONAL LOGIC FUNCTIONS

EECS150 - Digital Design Lecture 4 - Boolean Algebra I (Representations of Combinational Logic Circuits)

Propositional Logic. Logical Expressions. Logic Minimization. CNF and DNF. Algebraic Laws for Logical Expressions CSC 173

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

Outline. EECS150 - Digital Design Lecture 4 - Boolean Algebra I (Representations of Combinational Logic Circuits) Combinational Logic (CL) Defined

XOR - XNOR Gates. The graphic symbol and truth table of XOR gate is shown in the figure.

Binary Decision Diagrams

MC9211 Computer Organization

UNIT 5 KARNAUGH MAPS Spring 2011

Chapter 7 Logic Circuits

Lecture 10: Synchronous Sequential Circuits Design

Combinational Logic Design Combinational Functions and Circuits

The Design Procedure. Output Equation Determination - Derive output equations from the state table

Review: Additional Boolean operations

This form sometimes used in logic circuit, example:

Simplifying Logic Circuits with Karnaugh Maps

MODULAR CIRCUITS CHAPTER 7

Fundamentals of Digital Design

Boolean Algebra. Digital Logic Appendix A. Postulates, Identities in Boolean Algebra How can I manipulate expressions?

DO NOT COPY DO NOT COPY

Logic Minimization. Two-Level. University of California. Prof. Srinivas Devadas. Prof. Richard Newton Prof. Sanjit Seshia. Prof.

Number System. Decimal to binary Binary to Decimal Binary to octal Binary to hexadecimal Hexadecimal to binary Octal to binary

Chapter 2 Combinational Logic Circuits

Prove that if not fat and not triangle necessarily means not green then green must be fat or triangle (or both).

Digital Logic & Computer Design CS Professor Dan Moldovan Spring Copyright 2007 Elsevier 2-<101>

ENG2410 Digital Design Combinational Logic Circuits

Chapter 2 Combinational Logic Circuits

Appendix A: Digital Logic. Principles of Computer Architecture. Principles of Computer Architecture by M. Murdocca and V. Heuring

Principles of Computer Architecture. Appendix B: Reduction of Digital Logic. Chapter Contents

Boolean Algebra. Digital Logic Appendix A. Boolean Algebra Other operations. Boolean Algebra. Postulates, Identities in Boolean Algebra

Logic and Boolean algebra

CprE 281: Digital Logic

CPE100: Digital Logic Design I

Synthesis of 2-level Logic Exact and Heuristic Methods. Two Approaches

Sample Marking Scheme

WEEK 3.1 MORE ON KARNAUGH MAPS

Hardware Design I Chap. 2 Basis of logical circuit, logical expression, and logical function

Combinational Logic. By : Ali Mustafa

UC Berkeley College of Engineering, EECS Department CS61C: Representations of Combinational Logic Circuits

Ch 2. Combinational Logic. II - Combinational Logic Contemporary Logic Design 1

CPE100: Digital Logic Design I

VLSI CAD: Lecture 4.1. Logic to Layout. Computational Boolean Algebra Representations: Satisfiability (SAT), Part 1

Digital Logic: Boolean Algebra and Gates. Textbook Chapter 3

Latches. October 13, 2003 Latches 1

CSE140: Components and Design Techniques for Digital Systems. Logic minimization algorithm summary. Instructor: Mohsen Imani UC San Diego

Binary Decision Diagrams

Written reexam with solutions for IE1204/5 Digital Design Monday 14/

Digital Logic Appendix A

Chap 2. Combinational Logic Circuits

CHAPTER 7 MULTI-LEVEL GATE CIRCUITS NAND AND NOR GATES

2009 Spring CS211 Digital Systems & Lab CHAPTER 2: INTRODUCTION TO LOGIC CIRCUITS

Digital Logic & Computer Design CS Professor Dan Moldovan Spring 2010

Contents. Chapter 3 Combinational Circuits Page 1 of 36

1 Boolean Algebra Simplification

Building a Computer Adder

Transcription:

Computational Boolean Algebra Pingqiang Zhou ShanghaiTech University

Announcements Written assignment #1 is out. Due: March 24 th, in class. Programming assignment #1 is out. Due: March 24 th, 11:59PM. Online open course video available at coursera By Prof. Rob Rubentar, head of CS department at UIUC https://www.coursera.org/course/vlsicad 2

3 Online Course from UIUC

Karnaugh Map xy zw 00 01 11 10 00 01 11 10 1 1 0 0 0 1 1 0 0 1 1 0 1 1 0 1 4

Computational Boolean Algebra Motivation Background You ve done Boolean algebra, hand manipulations, Karnaugh maps to simplify But this is not sufficient for real designs! Example: a multiplier of two 16-bit numbers It has 32 inputs. Its Karnaugh map has 2 32 = 4,294,967,296 squares This is too big! There must be a better way 5

Need a Computational Approach 6 Need algorithmic, computational strategies for Boolean stuff. Need to be able to think of Boolean objects as data structures + operators What will we study? Decomposition strategies Ways of decomposing complex functions into simpler pieces. A set of advanced concepts and terms you need to be able to do this. Computational strategies Ways to think about Boolean functions that let them be manipulated by programs. Interesting applications When you have new tools, there are some useful new things to do.

Computational Boolean Algebra: Topics Cofactors Boolean difference Quantification Tautology 7

Advanced Boolean Algebra Useful Analogy to Calculus In calculus, you can represent complex functions like e x using simpler functions. If you can only use 1, x, x 2, x 3, as the pieces... turns out e x = 1 + x + x2 2! + x3 3! + It corresponds to the Taylor series expansion. f x = f 0 + f (0) 1! + f (0) 2! + f (0) 3! + Question: Anything like this for Boolean functions? Yes. It is called Shannon Expansion. 8

9

Shannon Expansion Proposed by Claude Shannon, the father of information theory. Suppose we have a function F(x 1, x 2,, x n ). Define a new function if we set one of the x i = const F(x 1, x 2,, x i = 1,, x n ) F(x 1, x 2,, x i = 0,, x n ) Example: F x, y, z = xy + x z + y( xz + F x = 1, y, z = F x, y = 0, z = y + z + y z x z z) Note: this is a new function, that no longer depends on the variable x i. 10

Shannon Expansion: Cofactors Turns out to be an incredibly useful idea. It is also known as Shannon cofactor with respect to x i. We write F(x 1, x 2,, x i = 1,, x n ) as F xi. We call it positive cofactor. We write F(x 1, x 2,, x i = 0,, x n ) as F x i. We call it negative cofactor. Often, just write them as F(x i = 1) and F(x i = 0). Why are these useful functions to get from F? 11

Shannon Expansion Theorem Why we care: Shannon Expansion Theorem Given any Boolean function F(x 1, x 2,, x n ) and pick any x i in F s inputs, F can be represented as F x 1, x 2,, x n = x i F x i = 1 + x i F(x i = 0) Proof: Consider any x 1, x 2,, x n If x i = 1 {0,1} n F, x i = 1, = F x i = 1 = 1 F x i = 1 + 1 F(x i = 0) If x i = 0 F, x i = 0, = F x i = 0 = 0 F x i = 1 + 0 F(x i = 0) 12

Shannon Expansion: Another View x 1 x i x n function F F Same as x 1 0 x n x 1 1 x i x i function F function F 0 MUX 1 F = x i F x i = 1 + x i F(x i = 0) x n 13 x i

Shannon Expansion: Multiple Variables Can do it on more than one variable, too. Just keep on applying the theorem on each variable. Example: Expand F x, y, z, w around x and y First, expand around x: F x, y, z, w = x F x = 1 + x F(x = 0) Then, expand cofactors F x = 1 and F x = 0 around y: F x = 1 = y F x = 1, y = 1 + y F(x = 1, y = 0) F x = 0 = y F x = 0, y = 1 + y F(x = 0, y = 0) Final result: F x, y, z, w = xy F x = 1, y = 1 + x y F x = 1, y = 0 + xy F x = 0, y = 1 + x y F(x = 0, y = 0) 14

Shannon Cofactors: Multiple Variables There is notation for these multiple-variable expansions as well. Shannon cofactor with respect to x i and x j : Write F(x 1,, x i = 1,, x j = 0,, x n ) as F xi x j. The same for any number of variables x i, x j, x k, Notice that order does not matter: (F x ) y = (F y ) x = F xy. 15 For the previous example: F x, y, z, w = xy F xy + x y F x y + xy F xy + x y F x y Again, remember: each of the cofactors is a function, not a number. F xy = F(x = 1, y = 1, z, w) is a Boolean function of only z and w.

Next Question: Properties of Cofactors What else can you do with cofactors? Suppose you have 2 functions F(X) and G(X), where X = (x 1, x 2,, x n ). Suppose you make a new function H, from F and G, say H = F H = F G, i.e., H X = F X G(X) H = F + G, i.e., H X = F X + G(X) H = F G, i.e., H X = F(X) G(X) Question: can you tell anything about H s cofactors from those of F and G? F G x = what? F x = what? 16

Nice Properties of Cofactors Cofactors of F and G tell you everything you need to know. Complements F x = (F x ) In English: cofactor of complement is complement of cofactor. Binary Boolean operators F G x = F x G x cofactor of AND is AND of cofactors F + G x = F x + G x cofactor of OR is OR of cofactors F G x = F x G x cofactor of XOR is XOR of cofactors Very useful! Can often help in getting cofactors of complex formulas. 17

Combinations of Cofactors Now consider operations on cofactors themselves. Suppose we have F(X), and get F x and F x F x F x =? F x F x =? F x + F x =? Turns out these are all useful new functions. Indeed, they even have names! Next: let s go look at these interesting, useful new functions. 18

Computational Boolean Algebra: Topics Cofactors Boolean difference Quantification Tautology 19

Calculus Revisited: Derivatives Remember how you defined derivatives? Suppose you have y = f(x). y = f(x) Defined as slope of curve as a function of point x. How to compute? df(x) dx = lim f x+δx f(x) Δx 0 Δx x 20

Boolean Derivatives So, do Boolean functions have derivatives? Actually, yes. Trick is how to define them... Basic idea For real-valued f(x), df dx tells how f changes when x changes. For 0,1-valued Boolean function, we cannot change x by small delta. Can only change 0 1, but can still ask how f changes with x... For Boolean function f(x), define f x = f x f x 21

Boolean Derivatives f x = f x f x Compare value of f when x = 0 against when x = 1. f x == 1 if and only if f(x = 0) is different from f(x = 1). f x is also known as Boolean difference. If function f is constant (f = 1 or f = 0 for all inputs), then f x = 0 for any x. 22

Boolean Difference Boolean difference also behaves sort of like regular derivatives... Order of variables does not matter ( f x) y = ( f y) x Derivative of XOR is XOR of derivatives (f g) = f x x g x Like addition 23

Boolean Difference But some things are just more complex Derivatives of (f g) and (f + g) do not work the same... Why? Because AND and OR on Boolean values do not always behave like ADDITION and MULTIPLICATION on real numbers. 24

Boolean Difference: Gate-Level View Consider simple examples for f x. Inverter: f = x f x = 0, f x = 1, AND: f = xy f x = y, f x = 0, OR: f = x + y f x = 1, f x = y, XOR: f = x y f x = y, f x = y, f x = f x f x = 1 f x = f x f x = y f x = f x f x = y f x = f x f x = 1 Meaning: When f x = 1, then f changes if x changes! 25

Interpreting the Boolean Difference a b w Combinational Logic F(a, b,, w, x) x What does F(a, b,, w, x) x = 1 mean? If you apply a pattern of inputs (a, b,, w) that makes F x = 1, then any change in x will force a change in output F. 26

Boolean Difference: Example a b c in 1-Bit Full Adder s c out s = a b c in c out = ab + ac in + bc in What is c out c in = 1? c out c in = 1 = a + b c out c in = 0 = ab c out c in = c out c in = 1 c out c in = 0 = a + b ab = a b Make sense? a b = 1 a b 27

Boolean Difference: Summary Boolean difference explains under what situations an inputchange can cause output-change for a Boolean function f. f x is another Boolean function, but it does not depend on x! It cannot, because it is made out of cofactors with respect to x, which eliminate all the x and x terms by setting them to constants. Very useful! (we will see more, later ) 28

Computational Boolean Algebra: Topics What you know Shannon expansion lets you decompose a Boolean function Combinations of cofactors do interesting things, e.g, the Boolean difference What you don t know Other combinations of cofactors that do useful things The big ones: Quantification operators Applications: Being able to do something impressive 29

Computational Boolean Algebra: Topics Cofactors Boolean difference Quantification Tautology 30

AND of F x and F x: Universal Quantification AND the cofactors: F xi F x i Name: Universal Quantification of function F with respect to variable x i. Represented as: x i F (x 1, x 2,, x i 1, x i+1,, x n ) x i F is a new function It does not depend on x i! sign is the for all symbol from logic. 0 x function F F x AND x F function F 1 x F x 31

OR of F x and F x: Existential Quantification OR the cofactors: F xi + F x i Name: Existential Quantification of function F with respect to variable x i. Represented as: x i F (x 1, x 2,, x i 1, x i+1,, x n ) x i F is a new function It does not depend on x i! sign is the there exists symbol from logic. 0 x function F F x OR x F Both x i F and x i F do not depend on x i function F 1 x F x 32

Quantification Notation Makes Sense 33 0 function F x function F F x 1 x F x 0 function F x function F F x 1 x F x AND OR x F When does x F(all vars except x) = 1? This input pattern of the other vars makes F = 1 for all values of x. x F When does x F(all vars except x) = 1? There exists a value of x that makes F = 1 for this input pattern of the other vars.

Quantification: Gate-Level View Consider simple examples for ( x f) and ( x f). Inverter: f = x f x = 0, f x = 1, x f = f x f x = 0, x f = f x + f x = 1 AND: f = xy f x = y, f x = 0, x f = f x f x = 0, x f = f x + f x = y OR: f = x + y f x = 1, f x = y, x f = f x f x = y, x f = f x + f x = 1 XOR: f = x y f x = y, f x = y, x f = f x f x = 0, x f = f x + f x = 1 Make sense? 34

Extends to More Variables in Obvious Way Like Boolean difference, can do with respect to more than 1 variable Suppose we have F(x, y, z, w). xy F z, w = x y F = F xy F xy F xy F x y xy F z, w = x y F = F xy + F xy + F xy + F x y Remember: ( x F), ( x F), and F x are all functions. but they are functions of all the variables except x. 35

Quantification Example Consider the following circuit, it adds x =0 or x =1 to a 2-bit number a 1 a 0. It s just a 2-bit adder, but instead of b 1 b 0 for the second operand, it is just 0x. It has a carry-in d and produces a carry-out c. Hence, c is function of a 1, a 0, d and x. Questions: a 1 0 a 0 x What is a 1 a 0 c x, d? A 1 B 1 A 0 B 0 What is a 1 a 0 c x, d? c adder d 36

Quantification Example a 1 0 a 0 x c A 1 B 1 A 0 B 0 adder d What is a 1 a 0 c x, d? A function of only x and d. Makes a 1 for values of x and d that make a carry c = 1 for all values of inputs a 1 and a 0. What is a 1 a 0 c x, d? A function of only x and d. Makes a 1 for values of x and d that make a carry c = 1 for some value of inputs a 1 and a 0, i.e., there exists some a 1 and a 0 that for this x and d, c = 1. 37

Quantification Example a 1 0 a 0 x c A 1 B 1 A 0 B 0 adder d c = a 1 (a 0 x + a 0 d + xd) Compute a 1 a 0 c x, d c a1 a 0 c a1 a 0 c a 1 a 0 c a 1 a 0 = 0 Compute a 1 a 0 c x, d c a1 a 0 + c a1 a 0 + c a 1 a 0 + c a 1 a 0 = x + d Need four cofactors: c a1 a 0 = x + d c a1 a 0 = xd c a 1 a 0 = 0 c a 1 a 0 = 0 38

Quantification Example a 1 0 a 0 x c A 1 B 1 A 0 B 0 adder d c = a 1 (a 0 x + a 0 d + xd) a 1 a 0 c x, d = 0 Make sense: No values of x and d that make c = 1 independent of a 1 and a 0 a 1 a 0 c x, d = x + d Make sense: If at least one of x and d = 1, then there exists a 1 and a 0 that let c = 1. 39

a b Quantification Application: Logic Network Repair Suppose that some one specified a logic block for you to implement: f a, b = ab + b but you implemented it wrong: in particular, you got ONE gate wrong. Specified ab + b f a, b a b Implemented AND?? g a, b 40 Goal Can we deduce how precisely to change this gate to restore correct function? Go with this very trivial test case to see how mechanics work...

MUX Network Repair a b Clever trick: Replace our suspect gate by a 4-to-1 MUX with 4 arbitrary new vars d 0, d 1, d 2, d 3. By cleverly assigning values to d 0, d 1, d 2, d 3, we can fake any gate. Question is: what are the right values of d i s so g is repaired, i.e., g = f? AND s 0 s 1?? a b g a, b AND d 0 d 1 d 2 d 3 00 01 10 11 s 1 s 0 G a, b, d 0,, d 3 41

MUX Aside: Faking a Gate with a MUX You can do any function of 2 vars with one 4-to-1 multiplexor (MUX). y x 0 1 1 1 00 01 10 11 s 1 s 0 x y OR 42

MUX Aside: Faking a Gate with a MUX You can do any function of 2 vars with one 4-to-1 multiplexor (MUX). y x 1 1 1 0 00 01 10 11 s 1 s 0 x y NAND 43

MUX Network Repair: Using Quantification Next trick: XNOR G a, b, d 0,, d 3 f a, b. with the specification a b AND s 1 s 0 d 0 d 1 d 2 d 3 00 01 10 11 G a, b, d 0,, d 3 z a, b, d0, d1, d2, d3 EXNOR 44 a b ab + b f a, b Note: z a, b, d 0, d 1, d 2, d 3 = 1 only when G == f.

Using Quantification What do we need? Values of d 0, d 1, d 2, d 3 that make z = 1 for all possible values of inputs a, b. There are values of d 0, d 1, d 2, d 3 that let ab z d 0, d 1, d 2, d 3 = 1 The above equation is universal quantification of function z with respect to a, b! Any pattern of (d 0, d 1, d 2, d 3 ) that makes ab z d 0, d 1, d 2, d 3 = 1 will do it! 45

MUX Network Repair via Quantification a b AND s 1 = b, s 0 = ab s 1 s 0 G = d 0 s 1 s 0 + d 1 s 1 s 0 + d 2 s 1 s 0 +d 3 s 1 s 0 d 0 d 1 d 2 d 3 00 01 10 11 G a, b, d 0,, d 3 XNOR a b ab + b f a, b z a, b, d 0, d 1, d 2, d 3 46

Network Repair via Quantification As a result G a, b, d 0,, d 3 = d 0 ab + d 1 ab + d 2 b f a, b = ab + b z a, b, d 0,, d 3 = G a, b, d 0,, d 3 f a, b We want to get ab z d 0, d 1, d 2, d 3 = z a b z ab z a b z ab 47

Network Repair via Quantification G a, b, d 0,, d 3 = d 0 ab + d 1 ab + d 2 b f a, b = ab + b z a, b, d 0,, d 3 = G a, b, d 0,, d 3 f a, b z a b = G a b f a b = d 2 1 = d 2 z ab = G ab f ab = d 0 0 = d 0 z a b = G a b f a b = d 2 1 = d 2 z ab = G ab f ab = d 1 1 = d 1 ab z d 0, d 1, d 2, d 3 = z a b z ab z a b z ab = d 0 d 1 d 2 48

Network Repair via Quantification Finally, we obtain ab z d 0, d 1, d 2, d 3 = d 0 d 1 d 2 To repair, we should find values of d 0, d 1, d 2, d 3 so that ab z d 0, d 1, d 2, d 3 = 1 Not hard: d 0 = 0, d 1 = 1, d 2 = 1, d 3 = X(don t care) 49

MUX Network Repair Does d 0 = 0, d 1 = 1, d 2 = 1, d 3 = X work? Case 1: d 0 = 0, d 1 = 1, d 2 = 1, d 3 = 1 Specified a b AND a b ab + b f a, b 0 1 1 1 d 0 d 1 d 2 d 3 00 01 10 11 s 1 s 0 50 MUX is an OR gate. Expected!

MUX Network Repair Does d 0 = 0, d 1 = 1, d 2 = 1, d 3 = X work? Case 2: d 0 = 0, d 1 = 1, d 2 = 1, d 3 = 0 Specified a b AND a b ab + b f a, b 0 1 1 0 d 0 d 1 d 2 d 3 00 01 10 11 s 1 s 0 51 MUX is an XOR gate. Unexpected but works!

Network Repair: Summary This example is tiny... But in a real example, you have a big network 100 inputs, 50,000 gates. When the design doesn t work, it is a major hassle to go through the design to fix it. This gives a mechanical procedure to answer: Can we change 1 gate to repair? What we haven t seen yet: Computation strategy to mechanically find inputs to make ab z d 0, d 1, d 2, d 3 = 1 This computation is called Boolean Satisfiability (SAT). We will see how to solve Boolean SAT problem efficiently later. 52

Review Cofactors Positive cofactor: F(x 1, x 2,, x i = 1,, x n ) Negative cofactor: F(x 1, x 2,, x i = 0,, x n ) Shannon expansion theorem F x 1, x 2,, x n = x i F x i = 1 + x i F(x i = 0) Combinations of cofactors Boolean difference: f x = f x f x Another Boolean function, but it does not depend on x. Explain under what situations on other variables that an input change can cause output change for a Boolean function. Universal quantification: x f = f x f x Existential quantification: x f = f x + f x Quantification Application: Network Repair 53

Computational Boolean Algebra: Topics Cofactors Boolean difference Quantification Tautology 54

Important Example of Computation: Tautology Checking Tautology: a Boolean function is 1 for every input pattern. We are going to look at how to do tautology checking, i.e. whether a Boolean function f is 1 for every input. Why study this problem? To show a representation, i.e., a data structure, for a Boolean function f. To show an important computational strategy: recursion How hard is this problem? Very, very hard! What happens if you are given a sum-of-product expression with 50 variables and 800 products? 55

Start with: Representation We use a simple, early representation scheme for functions Represent a function as a set of OR ed product terms, i.e., a sum of products (SOP). Each product term is also called a cube, e.g., a bc is a cube. Why call it cube? Boolean space of 3 variables 011 111 Circle all vertices that let 001 101 f = 1. 56 c b a 010 000 100 110 How does a product term look like?

Properties of Cubes In what follows, we refer to product term as cube. For each variable x, x and x do not appear simultaneously. However, for each variable x, it is possible that none of x and x appears in the cube. If for each variable x, one of x and x appears in the cube. The cube is a minterm. The number of vertices in a cube is 2 k. 011 Boolean space of 3 variables 001 101 111 57 c b a 010 000 100 110

Positional Cube Notation (PCN) We represent a cube using Positional Cube Notation (PCN). One slot per variable. In slot for variable x: put 1, if cube has x in it; put 0, if cube has x in it; put -, if cube has no x or x in it. Example: In a Boolean space on three variables a, b, c b: a c: a b c [ ] [ ] 58

Positional Cube Notation (PCN) To represent cube in program, we need to encode 1, 0, and -. We need at least two bits to encode three values. One encoding: 01 to encode 1 ; 10 to encode 0 ; 11 to encode -. Example: In a Boolean space on three variables a, b, c b: a c: a b c [ - 0 - ] [ 1-0 ] a b c [11 10 11] [01 11 10] 59

PCN Cube List A sum-of-products (SOP) expression of a Boolean function is also called as a cover of cubes. We present a cover of cubes using a list of cubes in positional cube notation. Example: f = a + bc + ab a bc ab a b c [10 11 11] [11 01 01] [01 01 11] 60

Tautology Checking How do we approach tautology checking as a computation? Input: a list of cube in PCN representing an SOP expression of f Output: Yes, when f is always 1; No, when f is not always 1. Cofactors to rescue Great result: f is a tautology if and only if f x and f x are both tautologies. This makes sense: If function f 1, then cofactors both obviously 1. If both cofactors 1, then f = x f x + x f x = x + x = 1 61

Recursive Tautology Checking Suggests a recursive computation strategy: If you cannot tell immediately that f is a tautology, go try to see if each cofactor is a tautology. f = 1?? Split on x (f x = 1 AND f x = 1)?? 62 What else do we need? f x = 1 f x = 1 Selection rules: which x is good to pick to split on? Termination rules: how do we know when to stop splitting, so we can answer that the function at this node of tree is tautology or not? Mechanics: how hard is it to actually obtain the cofactors?

Recursive Cofactoring Do mechanics first (easy!). For each cube in the list: If you want positive cofactor w.r.t. var x, look at x slot in each cube: [ 10 ] just remove this cube from list, since it s a term with x. [ 01 ] just make this slot 11 (don t care), since we will strike x from the product term. [ 11 ] just leave this alone, since this term doesn t have any x/ x in it. f = abd + b c f a f c 63 abd b c [01 01 11 01] [11 01 10 11] [11 01 11 01] [11 01 10 11] [01 01 11 01]

Recursive Cofactoring 64 Do mechanics first (easy!). For each cube in the list: If you want negative cofactor w.r.t. var x, look at x slot in each cube: [ 01 ] just remove this cube from list, since it s a term with x. [ 10 ] just make this slot 11 (don t care), since we will strike x from the product term. [ 11 ] just leave this alone, since this term doesn t have any x/ x in it. abd b c f = abd + b c [01 01 11 01] [11 01 10 11] f c [01 01 11 01] [11 01 11 11]

Unate Functions Selection/termination, another trick: Unate functions Special class of Boolean functions f is unate if a SOP representation only has each literal in exactly one polarity, either all true, or all complemented f is positive unate in var x: if changing x 0 1 but keeping other variables constant (no matter what values they are), keeps f constant or makes f change 0 1. f is negative unate in var x: if changing x 0 1 but keeping other variables constant (no matter what values they are), keeps f constant or makes f change1 0. Function that is not unate is called binate. 65 Examples: Is ab + a cd + cd e unate? Is xy + xy + xy z + z unate? Is f = ab positive unate?

Unate Functions Analogous to monotonic continuous functions. A monotonically non-decreasing function: whenever x 2 x 1, we have f(x 2 ) f(x 1 ). Example, for a Boolean function f positive unate in x: a b 66 w x 0 1 Boolean function f f(a, b,, w, x) 0 0, or 1 1, or 0 1

Checking Unateness How to check unateness? Not easy if f is represented using truth table. Very easy if f is represented as an SOP. Suppose that f is represented as an SOP. Then f is unate in var x if For all the cubes that contain var x, x appears in exactly one polarity, either all true, or all complemented. E.g., f = ab + a cd + cd e is unate in a, b, c, d, e. A sufficient condition only!! If not satisfied, may be either unate or not unate. E.g., f = xy + xy + xy z + z is unate in y, z, but may or may NOT be unate in x. (Actually, it is unate in x!) 67

Checking Unate Functions with Cube-List Suppose you have a cube-list for f. A cube-list is unate if for each var x and for all the cubes that contain var x, x only appears in one polarity, not both. Again, just a sufficient condition. E.g., f = a + bc + ac is unate. E.g., f = a + bc + bc may or may NOT be unate. Easier to see if draw the cube-list vertically. a + bc + ac a + bc + bc 68 a bc ac [01 11 11] [11 01 01] [01 11 01] a bc bc [01 11 11] [11 10 01] [11 01 01]

Using Unate Functions in Tautology Checking It is very easy to check a unate cube-list for tautology: Unate cube-list for f is tautology iff it contains a cube whose elements are all don t care: [11 11 11]. Question: what exactly is [11 11... 11] as a product term? 69 This result actually makes sense... a bc bc a + bc + bc [01 11 11] [11 10 01] [11 01 01] Cannot make a 1 with only product terms where all literals are in just one polarity!

Termination Rules Using Unateness 70 If we have a unate cube-list, we can check for tautology directly. Rule 1: The function is a tautology if cube-list has an all-don tcare cube [11 11 11]. Why? function = stuff + 1 + stuff = 1. Rule 2: The function is NOT tautology if cube-list does not have any all-don t-care cube [11 11 11]. Why? Unate cube-list for the function is tautology iff it contains all-don t-care cube. a b c 01 11 10 11 01 10 01 01 10

Other Possible Termination Rules Lots more possible termination rules. For example: Rule 3: The function is tautology if cube list has single var cube that appears in both polarities. Why? function = stuff + x + x + stuff = 1 71

Selection Rule 72 We can t use easy termination rules unless cube-list is unate. Selection rule...? Pick splitting var to make unate cofactors. Strategy: pick most non-unate (binate) var as split var. Pick binate var with the most product terms dependent on it Why? Simplify more cubes. If a tie, pick var with minimum #true_var #compl_var Why? Left subtree and right subtree are balanced. x y z w 01 01 01 01 10 11 01 01 10 11 11 10 01 01 11 01 x: binate, in 4 cubes, true-compl = 2-2 =0 y: unate z: unate w: binate, in 4 cubes, true-compl = 3-1 =2

73 Recursive Tautology Checking: Done! Algorithm tautology(f represented as cubelist) { /* check if we can terminate recursion */ if (f is unate) { apply unate tautology termination rules directly if (= =1) return (1) else return (0) } else if (any other termination rules, like rule 3, work?) { return the appropriate value if = =1 or = =0 } else { /* canot tell -- find splitting variable */ x = most-not-unate variable in f return ( tautology( f(x=1) ) && tautology( f(x=0) ) ) } }

Recursive Tautology Checking Example Example: f = ab + ac + a b c + a f a b c 01 01 11 01 11 01 01 10 10 10 11 11 f unate? No Which var to pick? Most non-unate var: a f a a b c 11 01 11 11 11 01 11 10 10 ------------ f a unate? No Need to further split f a a b c ------------ ------------ ------------ 11 11 11 f a unate? Yes! Tautology? Yes! Terminate! 74

Recursive Tautology Checking Example f a a b c 11 01 11 11 11 01 11 10 10 f a unate? No Which var to pick? Either b or c For example, we pick b f ab a b c 11 11 11 11 11 01 ------------ f ab unate? Yes! Tautology? Yes! (contain alldon t-care cube) Terminate! f a b a b c ------------ 11 11 01 11 11 10 f a b unate? No Can we terminate? Yes, due to Rule 3 75

Recursive Tautology Checking Example The recursion tree we finally get is f f a f a = 1 f ab = 1 f a b = 1 The tree has tautologies at all leaves, so f is tautology. Note: if any leaf is NOT tautology, f is NOT! 76

Recursive Tautology Checking Summary This strategy is so general and useful it has a name: Unate Recursive Paradigm (URP). Again, we see that cofactors are important and useful. Boolean difference, quantifications; real applications like logic network repair Representations (data structures) for Boolean functions are critical. Truth tables, Karnaugh maps, Boolean expressions cannot be manipulated by software. See one real representation: cube-list, positional cube notation 77

78 Complementary Materials

Representation of Digital Circuits We see how to represent an SOP of a Boolean function. but we will also deal with digital circuits. How can we represent digital circuits? As we know, there are two types of digital circuits Combinational circuits Sequential circuits 79

Two Types of Digital Circuits Combinational circuits Current outputs only depend on current inputs, not on the previous inputs. Sequential circuits Current outputs depend on the previous inputs. Primary Combinational Inputs Logic Primary Outputs 80 Memory Elements, e.g., Flip-Flops

Sequential Circuits The combinational part of a sequential circuit is critical. For the combinational part of a sequential circuit, its inputs include primary inputs and the outputs of the memory part. its outputs include primary outputs and the inputs to the memory part. Primary Inputs Combinational Logic Primary Outputs Memory Elements, e.g., Flip-Flops 81

Representation of Combinational Circuits Represented as a directed graph. Inputs, outputs, and gates nodes Wires directed edges. Why directed edges? Signal flow has direction. x 1 x 1 x 2 x 3 x 4 AND1 OR1 AND2 AND3 OR2 y x 2 x 3 x 4 A 1 A 3 O 1 A 2 O 2 y 82

Representation of Combinational Circuits Since a combinational circuit has no loops, the corresponding graph is a directed acyclic graphs (DAG). DAG: A directed graph with no cycles. x 1 x 1 x 2 AND1 x 2 A 1 A 3 x 3 x 4 OR1 AND3 OR2 y x 3 O 1 x 4 A 2 O 2 y AND2 83

Traversal of Combinational Circuits Many operations on combinational circuit need to traverse it. Example: obtain the output given an input pattern. 0 1 1 1 x 1 x 2 x 3 x 4 AND1 OR1 1 0 AND3 0 OR2 y 1 AND2 1 How to approach this kind of traversal as a computation? Answer: Topological Sorting. 84

Topological Sorting Observation on computing the output of a combinational circuit: The output of each gate can be computed only when all of its input are known. We have to obtain its inputs before obtaining output. In other words, if there is a wire (edge) from gate (node) u to v, then gate (node) u should be visited before gate (node) v. This is exactly topological sorting. 0 1 1 1 x 1 x 2 x 3 x 4 AND1 OR1 1 0 AND3 0 OR2 One possible visiting order: x 1, x 2, x 3, x 4, AND1, OR1, AND2, AND3, OR2, y. y 1 85 AND2 1

Topological Sorting A B C G D E F Topological sorting is not necessarily unique: A, G, D, B, E, C, F and A, B, G, D, E, F, C are both topological sorting. Are the following orderings topological sorting? A, B, E, G, D, C, F A, G, B, D, E, F, C 86

Topological Sorting: Algorithm Based on a queue. Algorithm: 1. Compute the in-degrees of all nodes. (in-degree: number of incoming edges of a node.) 2. Enqueue all in-degree 0 nodes into a queue. 3. While queue is not empty 1. Dequeue a node v from the queue and visit it. 2. Decrement in-degrees of node v s neighbors. 3. If any neighbor s in-degree becomes 0, enqueue it into the queue. 87

Topological Sorting Algorithm Example A B C Queue D E F G Enqueue A and G In-degrees A B C D E F G 0 1 2 2 2 1 0 Order 88

Topological Sorting Algorithm Example A B C D E F Queue A G G In-degrees Dequeue A, visit A, and decrement in-degrees of A s neighbors. A B C D E F G 0 1 2 2 2 1 0 Order 89

Topological Sorting Algorithm Example A B C D E F Queue G G Enqueue B In-degrees A B C D E F G 0 1 0 2 2 1 2 1 0 Order A 90

Topological Sorting Algorithm Example A B C D E F Queue G B G In-degrees A B C D E F G 0 0 2 1 2 1 0 Order A Dequeue G, visit G, and decrement in-degrees of G s neighbors. 91

Topological Sorting Algorithm Example A B C D E F Queue B G Enqueue D In-degrees A B C D E F G 0 0 2 1 0 2 1 0 Order A G 92

Topological Sorting Algorithm Example A B C D E F Queue B D G In-degrees A B C D E F G 0 0 2 0 2 1 0 Order A G Dequeue B, visit B, and decrement in-degrees of B s neighbors. 93

Topological Sorting Algorithm Example A B C D E F Queue D G In-degrees A B C D E F G 0 0 2 1 0 2 1 1 0 Order A G B Dequeue D, visit D, and decrement in-degrees of D s neighbors. 94

Topological Sorting Algorithm Example A B C Queue D E F G Enqueue E In-degrees A B C D E F G 0 0 1 0 1 0 1 0 Order A G B D 95

Topological Sorting Algorithm Example A B C D E F Queue E G In-degrees A B C D E F G 0 0 1 0 0 1 0 Order A G B D Dequeue E, visit E, and decrement in-degrees of E s neighbors. 96

Topological Sorting Algorithm Example A B C Queue D E F G Enqueue C and F In-degrees A B C D E F G 0 0 1 0 0 0 1 0 0 Order A G B D E 97

Topological Sorting Algorithm Example A B C D E F Queue C F G In-degrees A B C D E F G 0 0 0 0 0 0 0 Order A G B D E Dequeue C, visit C, and decrement in-degrees of C s neighbors. 98

Topological Sorting Algorithm Example A B C D E F Queue F G In-degrees Dequeue F, visit F, and decrement in-degrees of F s neighbors. A B C D E F G 0 0 0 0 0 0 0 Order A G B D E C 99

Topological Sorting Algorithm Example A B C Queue D E F G Queue is now empty. Done! In-degrees A B C D E F G 0 0 0 0 0 0 0 Order A G B D E C F 100

Circuit Netlist Format We also need to store circuits as a text file. to be processed by different programs, e.g., layout synthesis tool, SPICE, schematic viewer, etc. Such files essentially store a netlist of gates. Many formats exist: Berkeley Logic Interchange Format (BLIF) Structured Verilog Format Bench Format 101

Example: Bench Format INPUT(x1) INPUT(x2) INPUT(x3) INPUT(x4) OUTPUT(y) g1=and(x1,x2) g2=or(x3,x4) g3=and(x3,x4) g4=and(g1,g2) y=or(g3,g4) x 1 x 2 x 3 x 4 AND1 OR1 AND2 g1 g2 AND3 g3 g4 OR2 y 102