Discrete Structures
Total Page:16
File Type:pdf, Size:1020Kb
Discrete Structures Harriet Fell Javed A. Aslam Rajmohan Rajaraman Eric Ropiak Chris Burrows Ravi Sundaram Discrete Structures Version 2.1 Harriet Fell Javed A. Aslam Rajmohan Rajaraman Eric Ropiak Chris Burrows Ravi Sundaram College of Computer and Information Science Northeastern University Boston, Massachusetts c Copyright 2009 by Harriet Fell and Javed A. Aslam. All rights reserved. On the cover: Pascal's triangle, mod 2. The figure represents 256 rows of Pascal's triangle: each odd entry is denoted by a dot, and each even entry is left blank. The resulting self-similar pattern of dots is closely related to the Sierpinski triangle fractal. Table of Contents I Computers and Computing: Numbers, Circuits, and Logic 1 1 Number Representations 3 1.1 Binary Representation . 4 1.1.1 Simple Binary Arithmetic . 5 1.2 Bytes . 8 1.3 Hexadecimal Representation . 9 1.4 Octal Representation . 10 1.5 Converting Between Decimal and Binary . 11 1.6 Representing Negative Numbers: Two's Complement . 12 Exercises . 15 2 Circuits 19 2.1 Transistors and Switches . 19 2.2 Basic Logic Gates: AND, OR, NOT . 20 2.2.1 AND Gate . 20 2.2.2 OR Gate . 21 2.2.3 NOT Gate . 21 2.3 Other Logic Gates: NAND, NOR, XOR, XNOR . 22 2.3.1 NAND Gate . 22 2.3.2 NOR Gate . 22 2.3.3 XOR Gate . 23 2.3.4 XNOR Gate . 24 2.4 Binary Arithmetic: Ripple Carry Adders . 24 iii Exercises . 24 3 Logic 27 3.1 Truth Values . 27 3.2 Basic Operators . 28 3.3 Truth Tables . 29 3.4 Logical Equivalence . 29 3.5 Normal Forms . 31 3.5.1 Conjunctive Normal Form . 32 3.5.2 Disjunctive Normal Form . 32 3.5.3 Truth Tables, Formulae, and Circuits . 33 3.6 Further Reading . 36 Exercises . 36 4 Design of a Simple Processor 39 4.1 Architecture . 39 4.1.1 Addition . 39 4.1.2 Negation . 40 4.1.3 Loading . 40 4.1.4 Jump If Zero . 40 4.1.5 Programming the CPU . 41 4.2 Multiplexers and demultiplexers . 42 4.3 Design of the processor . 43 4.3.1 Registers . 45 4.3.2 Extracting the instruction and incrementing the PC . 46 4.3.3 The add instruction . 47 4.3.4 The negate instruction . 48 4.3.5 The load instruction . 49 4.3.6 The jump-if-zero instruction . 50 4.3.7 Storing the new values into the data registers and PC . 51 II Cryptography: Integers and Modular Arithmetic 53 5 Cryptography and Modular Arithmetic 55 5.1 Simple Shift Ciphers . 55 5.1.1 Simple Shift Cipher Links . 56 5.2 Encoding . 57 5.3 The mod Function . 58 5.3.1 Properties of mod . 58 5.4 Simple Substitution Ciphers . 59 5.4.1 Shift Cipher . 59 5.4.2 Linear Ciphers . 60 5.5 Modular Arithmetic . 61 5.6 Powers mod n . 62 Exercises . 63 6 Integers and Division 67 6.1 Divides . 67 6.2 Primes . 68 6.2.1 Finding Primes . 68 6.2.2 Prime Number Decomposition . 69 6.2.3 More about Primes . 70 6.3 Division . 70 6.3.1 Scheme Functions Related to Division . 70 6.4 Greatest Common Divisor and Least Common Multiple . 71 6.4.1 Applications of gcd and lcm . 72 6.5 Euclidean Algorithm . 73 6.5.1 Using the Euclidean Algorithm . 74 6.5.2 Euclidean Algorithm Links . 75 6.6 Extended Euclidean Algorithm . 75 6.7 Inverses mod n . 78 6.8 The RSA (Rivest-Shamir-Adelman) cryptosystem . 79 6.8.1 Introduction . 79 6.8.2 How do public-key cryptosystems work? . 79 6.8.3 How does RSA work? . 79 6.8.4 Why does RSA work? . 81 6.8.5 Is RSA secure and efficient? . 82 Exercises . 83 III Combinatorics: Sets, Counting, and Probability 85 7 Sets 87 7.1 Set Basics . 88 7.2 Set-Builder Notation . 88 7.2.1 Examples . 89 7.3 Venn Diagrams . 89 7.4 Set Operations . 90 7.4.1 [ Union . 91 7.4.2 \ Intersection . 91 7.4.3 A Complement . 92 7.4.4 Difference . 92 7.4.5 Symmetric Difference . 93 7.4.6 Power Set . 93 7.4.7 Cartesian Product . 94 7.5 Computer Representation of Sets . 95 Exercises . 96 8 Counting 99 8.1 Basic Rules . 100 8.2 Inclusion-Exclusion Principle . 104 8.3 Pigeonhole Principle . ..