Adequate set of connectives, logic gates and circuits

Similar documents
Chapter 2: Switching Algebra and Logic Circuits

DIGITAL CIRCUIT LOGIC BOOLEAN ALGEBRA

Boolean Algebra CHAPTER 15

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

Boolean Algebra. The Building Blocks of Digital Logic Design. Section. Section Overview. Binary Operations and Their Representation.

CHAPTER1: Digital Logic Circuits Combination Circuits

Combinational Logic Design Principles

CHAPTER 12 Boolean Algebra

Propositional Logic: Equivalence

Propositional Calculus: Formula Simplification, Essential Laws, Normal Forms

Boolean Algebra, Gates and Circuits

Discrete Mathematics. CS204: Spring, Jong C. Park Computer Science Department KAIST

Binary Logic and Gates. Our objective is to learn how to design digital circuits.

CS 226: Digital Logic Design

Digital Logic (2) Boolean Algebra

Unit 2 Boolean Algebra

2. Associative Law: A binary operator * on a set S is said to be associated whenever (A*B)*C = A*(B*C) for all A,B,C S.

Boolean algebra. Examples of these individual laws of Boolean, rules and theorems for Boolean algebra are given in the following table.

Chapter 2: Boolean Algebra and Logic Gates

E&CE 223 Digital Circuits & Systems. Lecture Transparencies (Boolean Algebra & Logic Gates) M. Sachdev

Digital Circuit And Logic Design I. Lecture 3

Predicate Calculus - Syntax

Logic Design. Chapter 2: Introduction to Logic Circuits

Boolean algebra. Values

Circuits & Boolean algebra.

SAMPLE ANSWERS MARKER COPY

Boolean Algebra & Logic Gates. By : Ali Mustafa

Computer Organization: Boolean Logic

Sample Marking Scheme

CHAPTER 2 BOOLEAN ALGEBRA

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

COSC 243. Introduction to Logic And Combinatorial Logic. Lecture 4 - Introduction to Logic and Combinatorial Logic. COSC 243 (Computer Architecture)

Chapter 2 Combinational Logic Circuits

Binary Logic and Gates

E&CE 223 Digital Circuits & Systems. Lecture Transparencies (Boolean Algebra & Logic Gates) M. Sachdev. Section 2: Boolean Algebra & Logic Gates

CS61c: Representations of Combinational Logic Circuits

Unit 8A Computer Organization. Boolean Logic and Gates

Review CHAPTER. 2.1 Definitions in Chapter Sample Exam Questions. 2.1 Set; Element; Member; Universal Set Partition. 2.

CSE 20 DISCRETE MATH. Fall

BOOLEAN LOGIC. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region. Based on CBSE curriculum Class 11. Neha Tyagi, KV 5 Jaipur II Shift

CSC9R6 Computer Design. Practical Digital Logic

XI STANDARD [ COMPUTER SCIENCE ] 5 MARKS STUDY MATERIAL.

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

CprE 281: Digital Logic

Applications. Smartphone, tablet, game controller, antilock brakes, microprocessor, Wires

20. Combinational Circuits

Computer Science. 20. Combinational Circuits. Computer Science COMPUTER SCIENCE. Section

BOOLEAN ALGEBRA. Introduction. 1854: Logical algebra was published by George Boole known today as Boolean Algebra

Digital electronics form a class of circuitry where the ability of the electronics to process data is the primary focus.

DIGITAL CIRCUIT LOGIC BOOLEAN ALGEBRA

Packet #2: Set Theory & Predicate Calculus. Applied Discrete Mathematics

THE LOGIC OF COMPOUND STATEMENTS

UNIVERSITI TENAGA NASIONAL. College of Information Technology

Informal Statement Calculus

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

MC9211 Computer Organization

Signals and Systems Digital Logic System

Unit 2 Boolean Algebra

School of Computer Science and Electrical Engineering 28/05/01. Digital Circuits. Lecture 14. ENG1030 Electrical Physics and Electronics

Switches: basic element of physical implementations

CS 121 Digital Logic Design. Chapter 2. Teacher Assistant. Hanin Abdulrahman

Chapter 2. Boolean Algebra and Logic Gates

Logic Gates and Boolean Algebra

Propositional Language - Semantics

. T SHREE MAHAPRABHU PUBLIC SCHOOL & COLLEGE NOTES FOR BOARD EXAMINATION SUBJECT COMPUTER SCIENCE (Code: 083) Boolean Algebra

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

3 Boolean Algebra 3.1 BOOLEAN ALGEBRA

Contents. Chapter 2 Digital Circuits Page 1 of 30

1. Name the person who developed Boolean algebra

Floating Point Representation and Digital Logic. Lecture 11 CS301

Digital Techniques. Figure 1: Block diagram of digital computer. Processor or Arithmetic logic unit ALU. Control Unit. Storage or memory unit

CSE20: Discrete Mathematics for Computer Science. Lecture Unit 2: Boolan Functions, Logic Circuits, and Implication

Packet #1: Logic & Proofs. Applied Discrete Mathematics

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

Chapter 4, Logic using Propositional Calculus Handout

Week-I. Combinational Logic & Circuits

Functions. Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways:

Section 1.2 Propositional Equivalences. A tautology is a proposition which is always true. A contradiction is a proposition which is always false.

Combinatorial Logic Design Principles

control in out in out Figure 1. Binary switch: (a) opened or off; (b) closed or on.

Review: Additional Boolean operations

Boolean Algebra & Digital Logic

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

Propositional and Predicate Logic - II

Boolean Algebra. Philipp Koehn. 9 September 2016

Combinational Logic Fundamentals

Chapter 2 (Lect 2) Canonical and Standard Forms. Standard Form. Other Logic Operators Logic Gates. Sum of Minterms Product of Maxterms

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

Note: The area of logic that deals with propositions is called the propositional calculus or propositional logic.

Chapter 2 Boolean Algebra and Logic Gates

Intro To Digital Logic

Combinational Logic. Course Instructor Mohammed Abdul kader

Logic Synthesis and Verification

Computation and Logic Definitions

2.2 Classical circuit model of computation

ENG2410 Digital Design Combinational Logic Circuits

II. COMBINATIONAL LOGIC DESIGN. - algebra defined on a set of 2 elements, {0, 1}, with binary operators multiply (AND), add (OR), and invert (NOT):

Truth-Functional Logic

3. Abstract Boolean Algebras

Chapter 4: Combinational Logic Solutions to Problems: [1, 5, 9, 12, 19, 23, 30, 33]

Transcription:

Adequate set of connectives, logic gates and circuits Lila Kari University of Waterloo Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 1 / 59

Connectives We have mentioned so far one unary and four binary connectives There are many more unary and binary connectives, and also n-ary connectives, for n > 2. How many unary connectives? How many binary connectives? Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 2 / 59

Binary connectives p q g 1 g 2 g 3 g 4 g 5 g 6 g 7 g 8 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 p q g 9 g 10 g 11 g 12 g 13 g 14 g 15 g 16 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 3 / 59

Binary and n-ary connectives Which binary connectives do you recognize? Question: How many n-ary connectives are there? For an n-ary connective (that involves n variables), the truth table has 2 n rows, and the number of possible columns equals the number of possible binary numbers of length (height) 2 n. Answer: 2 (2n ) Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 4 / 59

Adequate set of connectives Definition: Any set of connectives with the capability to express all truth tables is said to be adequate. Post observed that the set of standard connectives, {,,,, }, is adequate. Emil Post, 1897-1954 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 5 / 59

Proving adequacy of a connective set We can show that a new set S of connectives is adequate if we can express all standard connectives in terms of S. This is achieved by translating all the standard connectives in terms of the new connectives in S, by using tautological equivalences. Example: A B and A B are tautologically equivalent. This means that is definable in terms of ( is reducible to ; can be expressed in terms of ) and. Similarly, is definable in terms of and because A B is tautologically equivalent to A B. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 6 / 59

Theorem. {,, } is an adequate set of connectives. Proof. We can use the theorem that states that any formula is equivalent to a formula in DNF. Alternatively, observe that, for any formulas A, B, A = A A B = A B A B = A B A B = A B A B = ( A B) ( B A). All the five standard connectives can be expressed in terms of,,, therefore {,, } is an adequate set of connectives. Corollary {, }, {, }, and {, } are adequate. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 7 / 59

One connective is enough Schroder showed in 1880 that each of the standard connectives is definable in terms of a single binary connective, where the truth table associated with is p q p q 1 1 0 1 0 0 0 1 0 0 0 1 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 8 / 59

Proof of adequacy We can express the standard connectives in terms of by p = p p p q = (p p) (q q) p q = (p q) (p q) p q = ((p p) q) ((p p) q) p q = ((p p) q) ((q p) p). Thus it follows that a single connective (also called NOR) is adequate. Consequently, to test a given S for being adequate it suffices to test if can be expressed by S. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 9 / 59

Sheffer stroke In 1913 Sheffer showed that the Sheffer stroke with associated truth table p q p q 1 1 0 1 0 1 0 1 1 0 0 1 is another single binary connective (also caled NAND) in terms of which the standard connectives can be expressed. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 10 / 59

Proving inadequacy How do we show that a given set S of connectives is not adequate? Inadequacy is proven by showing that some standard connective cannot be expressed by using the connectives in S. Example. The set S = { } is not adequate. Proof. To see this, note that a formula depending on only one variable and which uses only the connective has the property that its truth value for a value assignment that makes p = 0 is always 0. In order to define the negation p in terms of, there should exist a formula f depending on the variable p and using only the connective such that p = f. However, for a value assignment v such that v( p) = 1, we have v(p) = 0 and therefore v(f ) = 0, which shows that p and f cannot be tautologically equivalent. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 11 / 59

A ternary connective Let us use the symbol τ for the ternary connective whose truth table is given by p q r τ(p, q, r) 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 1 0 0 0 0 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 12 / 59

A ternary connective Note that, for any value assignment v, we have v(τ(p, q, r)) equals v(q) if v(p) = 1, and equals v(r) if v(p) = 0. This is the familiar if-then-else connective from computer science, namely if p then q else r Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 13 / 59

Comments We can consider now propositional logic based not upon the five common connectives, but upon any adequate set of connectives, for instance {, }. Let L p 0 be a sublanguage of Lp obtained by deleting from L p the three connectives,,, and let Form(L p 0 ) be the set of formulas of L p 0. Theorem. Form(L p 0 ) = Form(Lp ). Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 14 / 59

Proof Proof. Obviously, Form(L p 0 ) Form(Lp ). Conversely, for A Form(L p ) we define (by recursion) its translation A 0 into L p 0 as follows: A 0 = A for atomic variable A, ( A) 0 = A 0, (A B) 0 = A 0 B 0, (A B) 0 = ( A 0 B 0 ), (A B) 0 = (A 0 B 0 ), (A B) 0 = (A B) 0 (B A) 0 = = (A 0 B 0 ) ( A 0 B 0 ) Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 15 / 59

Boolean Algebra and Logic Circuits George Boole (1815-1864) Author of the book The Laws of Thought : introduced propositional logic, algebra of logic The design of the following treatise is to investigate the fundamental laws of those operations of the mind by which reasoning is performed; to give expression to them in the symbolical language of Calculus, and upon this foundation to establish the science of Logic and construct its method. Boolean algebra has been fundamental in the development of digital electronics. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 16 / 59

Boolean Algebra A Boolean algebra is a set B with two binary operations + and, elements 0 and 1, and a unary operation, such that the following properties hold for all x, y, z in B: Identity laws: x + 0 = x and x 1 = x. Domination laws: x + x = 1, x x = 0. Associative laws: (x + y) + z = x + (y + z), (x y) z = x (y z) Commutative laws: x + y = y + x, x y = y x Distributive laws: x + (y z) = (x + y) (x + z) and x (y + z) = (x y) + (x z). Using the laws given in this definition, it is possible to prove many other laws that hold for every Boolean algebra. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 17 / 59

Boolean algebra examples The set of propositional formulas in n variables, with the and operators, 1 and 0, and the operator, satisfy all the properties of a Boolean algebra. The set of subsets of a universal set U, with the union and intersection operations, the empty set and the universal set, and the set complementation operator, is a Boolean algebra. So, to establish results about propositional logic, and sets, we need only prove results about abstract Boolean algebras. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 18 / 59

Boolean algebra and computers Boolean algebra is used to model the circuitry of electronic devices, including electronic computers. Each input and output of such a device can be thought of as a member of the set {0, 1}. An electronic computer is made up of a number of circuits. Each circuit can be designed using the rules of Boolean algebra. The basic elements of circuits are called logic gates. A gate is an electronic device that operates on a collection of binary inputs and produces a binary output. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 19 / 59

The transistor - a simplified model Logic gates are physically implemented by transitors. A transistor is simply a switch, it can be in an off state, which does not allow electricity to flow, or in an on state, in which electricity can pass unimpeded. Each transistor contains three lines: two input lines and one output line. The first input line, called the control line, is used to open or close the switch inside the transistor. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 20 / 59

How the transistor works Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 21 / 59

How the transistor works If we set the input value on the control line to a 1 by applying a sufficient amount of voltage, the switch closes and the transistor enters the ON state. In this state, voltage coming from the in line, called the collector, goes directly to the out line, called the emitter, and this voltage can be detected by a measuring device. This ON state can be used to represent the binary 1. If, instead, we set the input value of the control line to a 0 by not applying voltage, the switch opens and the transistor enters the OFF state. In this state, no voltage can get through the transistor, and none would be detected on the output line. The OFF state can be used to represent the binary 0. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 22 / 59

Binary computers = transistors? This solid-state switching device, the transistor, forms the basis of construction of virtually all computers built today, and it is thus the fundamental building block for all high-level computers. However, there is no theoretical reason why we must use transistors as our elementary particles when designing computer systems. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 23 / 59

Binary storage devices Binary computers can be built out of any bistable device. Formally, it is possible to construct a binary computer using any device that meets the following four conditions: It has two stable energy states (one for a 0, one for a 1). These two states are separated by a large energy barrier (so a 0 does not accidentally become a 1, or the reverse). It is possible to sense what state the device is in (to see if it is storing a 0 or a 1) without permanently destroying the stored value. It is possible to switch from a 0 to a 1 and viceversa by applying a sufficient amount of energy. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 24 / 59

Binary computers electronic computers! There are many devices that meet the four conditions, including some unexpected ones such as the familiar on-off light switch! Thus it would be possible to build a reliable (albeit very slow and bulky) binary computer out of ordinary light switches! Just as magnetic cores were replaced by transistors, it is possible that transistors will ultimately be replaced by some newer technology: optical, biological, quantum These new computation implementations may be faster, smaller, cheaper, and/or more versatile. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 25 / 59

Basic logic gates: The inverter The inverter accepts a Boolean value (0 or 1) as input and produces the complement of this value as its output. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 26 / 59

The opposite of OR To construct the negation of OR, we use two transistors connected in parallel. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 27 / 59

The opposite of OR If either or both of the lines Input-1 and Input-2 are set to 1, then the corresponding transistor is in the ON state, and the output is connected to the ground, producing an output value of 0. Only if both input lines are 0, effectively shutting off both transistors, will the output line contain a 1. This is the exact opposite of the definition of OR, and this gate is called NOR gate. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 28 / 59

The OR gate The OR gate can be implemented using a NOR gate and an inverter. The input to this gate are the values of two or more Boolean variables. The output is the Boolean sum ( ) of their values. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 29 / 59

The opposite of AND To construct the negation of AND, we use two transistors connected in series. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 30 / 59

The opposite of AND The collector line of transistor 1 is connected to the power supply (logical 1) The emitter line of transistor 2 is connected to ground (logical 0). If both input lines, Input-1 and Input-2, are set to 1, then both transistors are in the ON state, and the output will be connected to the ground, resulting in a a value of 0 on the output line. If either (or both) Input-1 or Input-2 is 0, the the corresponding transistor is in the OFF state and does not allow the current to pass, resulting in a 1 on the output line. Thus the output of this gate is the opposite of AND and represented a gate called NAND gate. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 31 / 59

The AND gate The AND gate can be implemented using a NAND gate and an inverter. The inputs to this gate are the values of two or more Boolean variables. The output is the Boolean product ( ) of their values. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 32 / 59

Gates with multiple inputs We sometime permit multiple inputs to AND and OR gates, as below. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 33 / 59

Toffoli Gate x 1 x 2 x 3 y 1 y 2 y 3 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 It has a 3-bit input and 3-bit output: If the first two bits are both 1, it inverts the 3rd bit, otherwise all bits stay the same. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 34 / 59

Toffoli Gates and Quantum Computing The Toffoli gate is a universal, reversible logic gate Universal = any Boolean function can be realized by Toffoli gates Reversible = given the output one can uniquely reconstruct the input ( is reversible, but is not) The Toffoli gate can be realized by five two-qubit quantum gates This implies that a quantum computer can implement all possible classical computations A quantum-mechanics-based Toffoli gate has been successfully realized in January 2009 at the University of Innsbruck, Austria Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 35 / 59

Circuits: Combinations of logic gates Combinatorial circuits can be constructed using a combination of inverters, OR gates and AND gates. When combinations of circuits are formed, some gates may share inputs. This is shown in one of two ways in depictions of circuits. One method is to use branchings to indicate all the gates that use a given input. The other method is to indicate this input separately for each gate. Note that output from a gate may be used as input by one or more elements. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 36 / 59

How to draw circuits Both drawings below depict the circuit with output xy + xy. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 37 / 59

Example Example: Construct the circuits that produce the following outputs: (a) (x + y)x (b) x(y + z) (c) (x + y + z)(x y z). Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 38 / 59

Example answers (a) (x + y)x Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 39 / 59

(b) x(y + z) Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 40 / 59

(c) (x + y + z)(x y z). Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 41 / 59

Design a circuit that accomplishes a task Example 1. A committee of three individuals decides issues for an organization. Each individual votes either yes or no for each proposal that arises. A proposal is passed if it receives at least two yes votes. Design a circuit that determines whether a proposal passes. Solution: Let x = 1 be 1 if the first individual says yes and x = 0 if this individual says no. Similarly for y and z. Then a circuit must be designed that produces output 1 from the inputs x, y, z when two or more of x, y, z are 1. One representation of the Boolean function that has these output values is xy + xz + yz. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 42 / 59

Circuit for majority voting Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 43 / 59

Design a circuit for a 3-switch light fixture Example 2. Sometimes light fixtures are controlled by more than one switch. Circuits need to be designed so that flipping any one of the switches for the fixture turns the light on when it is off and turns the light off when it is on. Design circuits that accomplish this when there are three switches. Solution: We have three variables, x, y, z, one for each switch. Let x = 1 when the first switch is closed and 0 when it is open, and similarly for y and z. Let F (x, y, z) = 1 when the light is on and 0 when it is off. We can arbitrarily specify that the light be on when all three switches are closed, so that F (1, 1, 1) = 1. This determines all the other values of F. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 44 / 59

Circuit for 3-switch light fixture The function F can be represented as xyz + xy z + x yz + x y z. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 45 / 59

Example 3: Adders Logic circuits can be used to carry out addition of two positive integers from their binary expansions. We will build up the circuitry to do this addition from some component circuits. First we build a circuit that can be used to find x + y when x and y are two bits. The input to our circuit will be x and y, since each of these have value 0 or 1. The output will consist of two bits, namely s and c where s is the sum bit and c is the carry bit. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 46 / 59

The half-adder This circuit is called a multiple output circuit. The circuit we are designing is called the half-adder since it adds two bits, without considering a carry from the previous addition. x y s c 1 1 0 1 1 0 1 0 0 1 1 0 0 0 0 0 From the truth table we see that c = xy and s = xy + xy If we use the fact that xy + xy = (x + y)(xy) we obtain a circuit with fewer gates Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 47 / 59

Circuit for half-adder Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 48 / 59

The full adder (3 inputs, 2 outputs) Input: Bits x and y and the carry bit c i. Output: The sum bit s and the carry bit c i+1. Input Output x y c i s c i+1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 0 0 0 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 49 / 59

Formulas for outputs of the full adder From the truth table we obtain s = xyc i + xy c i + x yc i + x y c i. c i+1 = xyc i + xyc i + xy c i + x yc i. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 50 / 59

Circuit for full adder using half adders However, instead of building the full adder from the scratch, we will use half adders to produce the desired outputs. Exercise: Verify that the output of the above circuit (based on definition of the outputs of the half-adder circuit and of the OR gate) is indeed s and c i+1 as determined by the truth table for a full-adder. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 51 / 59

Adding three-bit integers Full and half adders can be used to add the three-bit integers (x 2 x 1 x 0 ) 2 and (y 2 y 1 y 0 ) 2 to produce the sum (s 3 s 2 s 1 s 0 ) 2. Note that s 3, the highest-order bit in the sum, is given by the carry c 2. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 52 / 59

Circuit minimization through logic formula simplification Consider the circuit that has output 1 iff x = y = z = 1 or x = z = 1 and y = 0. The formula corresponding to this truth table is xyz + xy z. xyz + xy z = (y + y )(xz) = 1 (xz) = xz. Hence, xz is a Boolean expression with fewer operators that represents the circuit, and the corresponding simplified circuit will have fewer logic gates. Thus, one can use the essential laws for propositional logic (De Morgan, law of excluded middle, law of contradiction, etc) to minimize circuits. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 53 / 59

A circuit and its minimized version Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 54 / 59

Circuit minimization Build a circuit for the formula with the following truth table. Use the laws of propositional calculus (De Morgan, commutativity,..) to simplify the formula and minimize its circuit. A B C Z 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 55 / 59

Analyzing and simplifiying code through logic formula simplification if (C 1 or not C 2 ) then if (not (C 2 and C 3 )) then P 1 else if (C 2 and not C 3 ) then P 2 else P 3 else P 4 Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 56 / 59

Analyzing and simplifiying code Analyzing code Hint: Write the truth table for the conditions for each of the if-statements. Use this truth table to determine, for each value assignment for C 1, C 2, C 3, which code (P 1, P 2, P 3 or P 4 ) is executed. Prove that P 2 is a dead code (without truth tables) Hint: Determine what is the logical formula involving propositional variables C 1, C 2, C 3 that would lead to the execution of P 2. If that formula is a contradiction (always false), then P 2 is a dead code. Is P 3 a dead code? Hint: Determine what is the logical formula involving propositional variables C 1, C 2, C 3 that would lead to the execution of P 3. Find out whether that formula is a tautology, a contradiction, or a contingent formula. If it is not a contradiction, then P 3 is not a dead code. Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 57 / 59

Simplified Code Simplified code if (C 1 and C 2 and C 3 ) then P 3 else if (not C 1 and C 2 ) then P 4 else P 1 One can use the laws of propositional calculus to verify that the simplified code is equivalent to the original code. This is proved by showing that the formula with variables C 1, C 2, C 3 that leads to the execution of P 1 in the original code is logically equivalent to the formula that leads to the execution of P 1 in the simplified code, and the same holds for P 2, P 3 and P 4. (example from A.Lubiw, W15 notes) Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 58 / 59

Acknowledgements The figures in this set of notes are from K.Rosen, Discrete Mathematics and Its Applications, 7th edition, McGraw Hill, 2012 (The circuit figures). G.Schneider, J.Gersting, An Invitation to Computer Science, 5th edition, Course Technology, 2009. (The transistor and implementation of logic gates figures) Adequate set of connectives, logic gates and circuits CS245, Logic and Computation 59 / 59