<<

1.2 A logic circuit is a circuit with MAE113 Discrete Techniques for Computing • one or more inputs, each of which is Prof. Wilfrid Hodges either live (1) or dead (0) at any given time; Mathematics room 156 [email protected] • an output, which is either live (1) or dead (0) depending on which of the inputs are live. Course web site http://www.maths.qmul.ac.uk/∼wilfrid/dtc/ We use variables p, q, r etc. for the inputs and output. A variable whose values are 0 or 1 is called a boolean. We often read 1 as T (for True) and 0 as F (for ).

1 3

1.1 Logic circuits 1.3 Syllabus George Boole Logic: Truth tables, T/F and 1/0 notation, introduced boolean variables gates, logic formulas and around 1850 their simplifications

2 4 1.4 1.6 Example Example The following table describes one logic circuit with r = p ∨ q inputs p and q and output r: For the following we write , and we read ∨ as ‘or’. pqr pqr 111 111 100 101 010 011 000 000 This is the truth table of the logic circuit.

5 7

1.5

A logic circuit with this truth table is called 1.7 an AND gate and is written ✘ We write ✘ ✘ p p AND r ✙ OR r q q ✙ ✙ The value of r is a function of the values of p and q; for a logic circuit with boolean formula p ∨ q, ∧ for AND gates we write r = p q (or sometimes pq), and we call the circuit an OR gate. and we call p ∧ q the boolean formula of the circuit. Think of ∧ as short for And.

6 8 1.10

1.8 pqr(p ∧ q) ∨ r We can join two or more logic circuits to make a new one: TTTTTT ✘ TTF TTF p AND TFTTFT q ✙ ✘ ✘ TFFTFF OR s FTTFTT r ✙ ✙ FTF FTF The formula is s =(p ∧ q) ∨ r. FFTFFT FFFFFF

9 11

1.9 The truth table for (p ∧ q) ∨ r: 1.11

pqr(p ∧ q) ∨ r pqr(p ∧ q) ∨ r TTT TTTTTT T TTF TTF TTT F TFT TFTTFF T TFF TFFTFF F FTT FTTFFT T FTF FTF FFT F FFT FFTFFF T FFF FFFFFF F

10 12 1.12

pqr(p ∧ q) ∨ r 1.14 TTTTTTTT TTF TTTTF • Put enough brackets in the formula to make clear in TFTTFFTT what order the columns are calculated. The columns inside the most brackets are calculated first. TFFTFFFF • ⇑ FTTFFTTT The last column calculated (shown with ) FTF FFTFF is the output column of the truth table. It is the output of any logic circuit with this boolean FFTFFFTT formula. FFFFFFFF ⇑

13 15

1.15 Another truth table for you to calculate 1.13 ∨ ∧ ∨ Writing truth tables: pqr(p r) (q r) TTT • Under the letters, the lefthand column changes slowest, TTF the righthand fastest. TFT • T comes above F . TFF (Some people do the opposite; this is OK as long as you are consistent.) FTT FTF • If there are n letters then you need 2n rows of Ts and Fs. FFT FFF

14 16 1.16

The truth tables for 1.18 (p ∧ q) ∨ r, We say that two logic circuits are equivalent if they have (p ∨ r) ∧ (q ∨ r) equivalent boolean formulas. We can check equivalence of two logic circuits have the same output column. by finding their boolean formulas So we say that these two boolean formulas are equivalent, and showing that these formulas are equivalent. and that they have the same truth table. This is often more efficient than checking the 2n possible We express the same by writing input values, where there are n inputs. (p ∧ q) ∨ r ≡ (p ∨ r) ∧ (q ∨ r)

17 19

1.19

1.17 A NOT gate has the truth table A logic circuit with the formula (p ∨ r) ∧ (q ∨ r): p ✘ ✘ T F p OR F T r t ✙ ✙ ✘ and is written AND ✙ ✘ ✘ p ❅❅ ❤ q OR ✙ ✙ Its formula is written ¬p, or sometimes p, and called the of p. (Don’t write p¬ instead of p.)

18 20 1.20

More truth tables to calculate: 1.22 pqp ∧ q ¬ (¬ p ∨¬q) There are two more De Morgan’s laws: TT p ∨ q ≡¬(¬p ∧¬q), TF ¬(p ∨ q) ≡¬p ∧¬q. FT FF

21 23

1.23 1.21 Two more boolean laws: This proves that p ∧ (q ∧ r) ≡ (p ∧ q) ∧ r, p ∧ q ≡¬(¬p ∨¬q). p ∨ (q ∨ r) ≡ (p ∨ q) ∨ r. Now putting ¬ in front of a formula reverses the Ts One can check these by truth tables. and the Fs. So ¬¬ cancels out, and the equivalence above tells us Because of them we often write for example

¬(p ∧ q) ≡¬p ∨¬q. p ∧ q ∧ r ∧ s (or pqrs)

without brackets. A formula consisting of smaller formulas These equivalences are known as De Morgan’s laws. joined by ∧ is called a conjunction.

22 24 1.24 1.26 For a similar reason we write we often write for example A literal is a single letter or the negation of a single letter. Example: p, q, ¬r, r are literals. p ∨ q ∨ r ∨ s p ∧ q and q are not literals. without brackets. A minterm is a conjunction of literals. This formula is called the disjunction of p, q, r and s. (NB The Schaum book gets this definition wrong.)

25 27

1.27

1.25 Suppose we have a truth table for the inputs p1,... ,pn, Also one can check the equivalences and the output is 1 in just one row, say row R. For each i from 1 to n,put p ∧ q ≡ q ∧ p,

p ∨ q ≡ q ∨ p.  pi if pi is True in row R, pi =  pi if pi is False in row R. So in a conjunction or a disjunction of formulas, the order of the formulas doesn’t make any difference to the Then the truth table is the truth table of the minterm truth table.   p1 ...pn.

26 28 1.28 1.30 Next, suppose the truth table has the same inputs Consequence 1: Every boolean formula is equivalent but has 1s in the rows R1, ... , Rk. to a disjunction of one or more minterms.

For each row Rj, let Mj be the minterm we calculated (A formula that is a disjunction of one or more minterms in 1.27 for row Rj. is sometimes said to be in disjunctive normal form.) Then the truth table is the truth table of Consequence 2: Every logic circuit is equivalent to a logic circuit where all the NOT gates are at the left, ∨ ∨ M1 ... Mk. the AND gates in the middle and the OR gates at the right.

29 31

1.31 Example. Suppose given the truth table 1.29 pqr Finally suppose the truth table has 0 in every row. (1) T T T F Then it’s the truth table of the minterm (2) T T F T  p1p1. (3) T F T F (4) T F F F We’ve proved: (5) F T T F Every truth table is the truth table of a disjunction of (6) F T F T oneormoreminterms. (7) F F T F (8) F F F T

30 32 1.32 1.34 The truth table has T in rows (2), (6), (8). Another for you: find a disjunction of minterms  that has the truth table The minterm for row (2) is pqr .   pq The minterm for row (6) is p qr .    111 The minterm for row (8) is p q r . 100 So the truth table is the truth table of 010 pqr ∨ pqr ∨ pqr. 001

33 35

1.35 1.33 We introduce two symbols to represent the truth tables in Oneforyoutodo:find a disjunction of minterms 1.33 and 1.34, that has the truth table → (called ‘arrow’ or ‘if ... then’) and ↔ (called ‘double arrow’ or ‘if and only if’). pq 111 pqp → q p ↔ q 100 11 1 1 011 10 0 0 001 01 1 0 00 1 1

34 36 1.36 1.38 → ↔ The symbols and are useful for writing down Consider the formula conditions,  ∨   when we use the letters p, q etc. for true or false statements. p qr p q r. E.g. if p says ‘Light A is on’ Because order doesn’t matter in conjunctions, this is and q says ‘The oil needs filling up’, then equivalent to

p → q (pr)q ∨ (pr)q. expresses ‘If light A is on then the oil needs filling up’. Using truth tables, this is equivalent to

(When boolean formulas are thought of as making (pr) ∧ (q ∨ q). statements, we call them propositions.)

37 39

1.37 1.39 Simplification of formulas Now q ∨ q always has the value T, so It’s often important to bring logic circuits or boolean we can leave it out and the formula is equivalent to formulas to as simple a form as possible.  p r. There are various techniques. We consider one that uses the disjunctive normal form. If two of the minterms are the same except that ONE LETTER, p p p For more information, including the technique of say , appears as in one and in the other, then we can leave out Karnaugh maps, see Chapter 8 ‘Simplification of logic the letter and so get just one minterm in place of two. circuits’ in the Schaum book. (DON’T USE THIS TO DROP TWO LETTERS AT ONCE.)

38 40 1.40 Example (Exam 2003): Simplify the expression

pqr ∨ pqr ∨ pqr ∨ pqr ∨ pqr.

Solution

(pqr ∨ pqr) ∨ (pqr ∨ pqr) ∨ pqr ≡ pq ∨ qr ∨ pqr.

41