This preview shows page 1. Sign up to view the full content.
Unformatted text preview: CSE 1400 Applied Discrete Mathematics Handouts
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 Abstract This file contains handouts covering topics in the class. Numbers Numeral Systems Conversion Modular Numbers Sets Boolean Logic Predicate Logic Relations Graphs Equivalences Orders Functions Polynomials Logarithms & Exponentials Integer Functions Permutations Induction Sequences Recurrences Definitions Theorems Proofs Algorithms Problems CSE 1400 Applied Discrete Mathematics Numbers
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 1.7 Numbers
Integers 1
1 3 3 5 6 6 2 Natural Numbers Integers Mod n Rational Numbers The Real Numbers Complex Numbers Floating Point Numbers 2 Problems on Numbers 7
Abstract Numbers are used for many purposes, chiefly to count discrete things 1 Numbers There are many types of numbers: whole numbers, positive and negative numbers, fractional numbers, and continuous numbers. 1.1 Natural Numbers
To count things, the natural numbers are used. N = {0, 1, 2, 3, . . .} The natural numbers are unsigned, that is, no plus (+) or minus () sign is placed in front of a natural number. The natural numbers are closed under addition and multiplication.
Addition closure: If n and m are natural numbers, then n + m is a natural number. Multiplication closure: If n and m are natural numbers, then nm is a natural number.
The symbol N is used to refer to the set of natural numbers: zero, one, two, three, . . . . cse 1400 applied discrete mathematics numbers 2 Subtraction and division can be computed on some pairs of natural numbers, but the natural numbers are not closed under these operations. If n is less than or equal to m, then the difference m  n is a natural number. If m is a multiple of n, say m = nk for some natural number k, then the quotient m/n = k is a natural number. The natural numbers can be placed in order. 0 < 1 < 2 < 3 < 4 < Less than is a relation on the natural numbers. Less than is strict and total. 8  9 N; 5 2 N. A relation < is strict if a < b, then b < a. A relation < is total if for any a and b, either a < b, b < a, or a = b. 1.2 Integers
Integers are used to increment and decrement counts of things . The integers are the numbers in the set Z = {0, 1, 2, 3, . . .} The integers are closed under addition, multiplication, and subtraction. The integers are signed numbers: They are stored in computer memory with an explicit plus (+) or minus () sign. Surprisingly, the natural numbers and the integers can be put into a onetoone correspondence, which mathematicians understand to mean the sets have an equal number of members. A function that establishes this onetoone correspondence maps the even natural numbers to onehalf their value and the odd natural numbers to the negative of onehalf times their value plus 1. n/2 if n is even n N, f (n) = (n + 1)/2 if n is odd For instance, 00 21 42 63 84 . . . 1 1 3 2 5 3 7 4 9 5 . . .
Subtraction closure: If n and m are integers, then m  n is an integer. The symbol Z is commonly used to refer to the set of integers: zero, plus or minus one, plus or minus two, plus or minus three, . . . . Because of this onetoone correspondence, the two natural numbers N and the integers Z are said to have the same cardinality, meaning they have the same 'number' of elements. A set X is finite if it contains n members, where n is some natural number. For instance, B = {0, 1}, containing n = 2 members, is finite. The cardinality of a finite set is the numbers of members it contains. Two sets X and Y have identical cardinality if elements in X can be put into a onetoone correspondence with the elements in Y. cse 1400 applied discrete mathematics numbers 3 1.3 Integers Mod n
The first n natural numbers: 0, 1, 2, . . . , ( n  1 ) are called the integers mod n. The set Z n is the symbol for the set of integers mod n, Zn = {0, 1, 2, 3, . . . , (n  1)} In practical applications, the modulus n is most often a prime number p. Z p = {0, 1, 2, 3, . . . , ( p  1)} , where p P = {2, 3, 5, 7, . . .} Zn is pronounced "Z mod n." For instance, Z2 = {0, 1} and Z7 = {0, 1, 2, 3, 4, 5, 6} When arithmetic operations are performed on modular numbers the results can lie outside the set Zn . This overflow is prevented by defining arithmetic to be cyclic. Modular numbers cycle back to 0, for instance, 1 + 6 = 7 = 0 mod 7 and 4 + 5 = 9 = 2 mod 7 The integers mod n is a cyclic number system. For instance, in mod 5 arithmetic, counting starts at 0, goes to 4, and continues by cycling back to 0. While in mod 7 arithmetic counting cycles every seven steps. In this way every integer m can be identified with a mod n integer 0 r < n, by setting r equal to the nonnegative remainder when m is divided by n. In this sense the mod n integer r represents an entire subset of the integers: The subset {r + nk : k Z}, sometimes called the residue or equivalence class `r mod n'. 3+4 5+6 34 56 25 56 = = = = = = 7 11 12 30 3 1 = = = = = = 0+7 4+7 5+7 2+47 47 67 = = = = = = 0 4 5 2 4 6 [0]5
. . . 10 5 0 5 10 . . . Integers Mod 5 [1]5 [2]5 [3]5 . . . 9 4 1 6 11 . . . . . . 8 3 2 7 12 . . . . . . 7 2 3 8 13 . . . [4]5
. . . 6 1 4 9 14 . . . [0]7
. . . 14 7 0 7 14 . . . [1]7
. . . 13 6 1 8 15 . . . Integers Mod 7 [2]7 [3]7 [4]7 . . . 12 5 2 9 16 . . . . . . 11 4 3 10 17 . . . . . . 10 3 4 11 18 . . . [5]7
. . . 9 2 5 12 19 . . . [6]7
. . . 8 1 6 13 20 . . . When the context demands it, you may need to add syntatic sugar such as [r ]n make it clear that the integer r mod n is a set of residues. The key idea is: The integers mod n partition the integers into n equivalence classes written [0]n , [1]n , through [n  1]n and called 0 mod n, 1 mod n, through n  1 mod n. Each class is a subset of the integers: The integers with equal remainders when divided by n. 1.4 Rational Numbers To measure fractional quantities, the rational numbers are used. Q = { a/b : a, b Z, b = 0} cse 1400 applied discrete mathematics numbers 4 The rational numbers are closed under addition, multiplication, subtraction, and division.
Division closure: If r and s are rational numbers, then r s is an rational number. It is counterintuitive, but the natural numbers and the rational numbers have identical cardinality. Consider the SternBrocot tree r where each node r has two children: its left child r+s and its right s r +s child s .
1 1 The mediant of rationals numbers r s and u is r+u . An entry ij in the Sternv s+v Brocot tree it the mediant of the first left ancestor and first right ancestor on the path from ij to the root. 1 2 2 1 1 3 3 2 2 3 3 1 1 4 4 3 3 5 5 2 2 5 5 3 3 4 4 1 The following statements about the entries in the SternBrocot tree are true with easy to understand proofs 1 . 1. All the entries are in reduced form, that is, the numerator and denominator are relatively prime. Proof. At the root vertex 1 , the greatest common divisor of the 1 numerator and denominator is 1, that is, they are relatively prime. Similarly, observe at the next two levels gcd(1, 2) = 1 and gcd(1, 3) = 1, gcd(2, 3) = 1, gcd(3, 2) = 1, and gcd(3, 1) = 1 Suppose, by way of contradiction, there is some fraction r/s on the highest possible level and r and s are not relatively prime. That is, some natural number larger that 1 evenly divides both. If r/s is a left child, then its parent r/(s  r ), at a higher level, is not a reduced fraction either, a contradiction that r/s was at the highest level. If r/s is a right child, then its parent (r  s)/s, at a higher level, is not a reduced fraction either. Another contradiction. 2. Every positive rational number appears somewhere in this tree. and gcd(2, 1) = 1 1 Calkin, N. and Wilf, H. S. (2000). Recounting the rationals. The American Mathematical Monthly, 107:360363 The left child of r/(s  r ) is r/[(s  r ) + r ] = r/s The right child of (r  s)/s is [(r  s) + s]/s = r/s cse 1400 applied discrete mathematics numbers 5 Proof. The rational number 1 is at the root of the tree. Suppose, by way of contradiction, there is a fraction r/s that is not in the tree. We may assume that among all fractions that are not in the tree, r/s is the one with smallest denominator and smallest numerator. If r > s, then (r  s)/s would not be in the tree either, but its numerator (r  s) is smaller than r, a contradiction to the construction of r/s. If r < s, then r/(s  r ) would not be in the tree either, but its denominator (s  r ) is smaller than s, another contradiction. 3. No rational number appears twice in this tree. Proof. Can you suggest a proof? The rational numbers are discrete and can be enumerated like the natural numbers, but the natural concept of the "next" or "successor" is lost. 1.5 Floating Point Numbers
In computing, floating point numbers are a primitive data type. They are a finite subset of the rational numbers. Floating point numbers are used to approximate rational and real numbers. Normalized floating point numbers are written in scientific notation. Avogadro's Number Planck's Constant Gravitational Constant Speed of light 6.0221417 1023 mol1 6.626068 1034 Nms 6.67428 1011 N(m/kg)2 2.99792458 108 m/s Number of atoms in 12 grams of carbon12 The energy of a photon divided by its electromagnetic frequency Relates attractive force to masses and distance between two objects In decimal scientific notation a floating point number is written as d. f 10e
where d = 0 is a nonzero digit, f is a finite string of digits, and e is a signed integer. In binary scientific notation a floating point number is written as 1. f 2e
where f is a finite string of bits and e is a signed integer written in biased notation. cse 1400 applied discrete mathematics numbers 6 1.6 The Real Numbers
To measure continuous, instantaneous changes, the real numbers are used. There are more real numbers than natural numbers. That is, there is no onetoone correspondence between the natural numbers and the real numbers. Proof. By way of contradiction, pretend there is a function f (n) = xn that maps the natural numbers n N to real numbers xn [0, 1] in such a way that every real number x between 0 and 1 appears somewhere in the sequence x0 , x1 , x2 , x3 , . . . Consider writing a table of the numbers xk written as in decimal point notation, with unbounded precision. For example, the mapping might be like that shown in the table below. Index k 0 1 2 3 4 5 6 7 8 9 Diagonal Expansion of xk 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 1 5 0 0 0 0 0 0 6 6 6 6 6 6 6 6 3 0 0 0 0 0 0 0 2 5 0 0 0 0 0 0 1 3 3 3 3 3 3 3 6 0 0 0 0 0 0 0 9 9 9 6 9 3 9 9 0 0 0 0 0 0 3 3 0 0 6 6 0 0 0 0 3 3 0 0 6 9 Value 0.0 0.50 0.200 0.3333 0.15000 0.666666 0.3000000 0.25000000 0.133333333 0.6000000000 0.9996939969. . .
Similar to the way a graph may be drawn in order to understand an idea, the table is "madeup" to demonstrate a possible list of all real numbers in the interval [0, 1]. The diagonal number 0.9996939969 is not in the table, a contradiction that all real numbers between 0 and 1 are listed. 1.7 Complex Numbers
The complex numbers C= a + bi : a, b R, i = 1 Application of complex numbers in science and engineering are numerous. One important application is transforming a signal caught in the timedomain into its representation in the frequencydomain. The complex numbers are closed under addition, multiplication, subtraction, division, and exponentiation.
Exponentiation closure: If z and w are complex numbers, then zw is a complex number. cse 1400 applied discrete mathematics numbers 7 2 Problems on Numbers
The notation x X means element x is a member of set X. 1. Identify if the propositions are True or False. (a) 5 N. (c) 5 Q. (b) 5 N. (d) 5i Q. 2. Is the relation on the natural numbers N is strict? That is, is it True that if a b, then b a? 3. Place the sets N, Z, Q, R and C in order given by set inclusion. 4. What is the smallest positive rational number? 5. What is (3)3 ? 6. What is 43 mod 7? 8. Describe the residue (equivalence) classes for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 9. Construct an addition table for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 10. Construct a multiplication table for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 11. 0 is the symbol for the cardinality of N, the count of elements in the set of natural numbers. 0 is pronouced alephnaught. Cantor called 0 a "transfinite" number. Cantor called the cardinality of R, the set of real numbers, 1 and he proved 0 = 1 . (a) Why is transfinite a good word to use? (b) Are there transfinite numbers between 0 and 1 ? 7. What is 43 mod 7? (c) Read the Wikipedia page on natural numbers. The last time I checked, it provided a good summary of useful ideas. References
Calkin, N. and Wilf, H. S. (2000). Recounting the rationals. The American Mathematical Monthly, 107:360363. CSE 1400 Applied Discrete Mathematics Numeral Systems
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 Numeral Systems
The Unary System The Binary System 1
2 3 3 4 4 The Decimal System The Hexadecimal System The Sexagesimal System Finite Constraints 4 2 1 Problems on Numeral Systems Numeral Systems 7 There are several numeral systems used to write numbers. For instance, the natural number two thousand and ten can be written as the Roman numeral MMX or as 2010 in decimal Arabic numerals, or as 111 1101 1010 in binary Arabic numerals. In mathematics and computing, numbers are written in a positional system, where the position of a numeral determines its role in the computation of the value. The numeral systems commonly used in computing are decimal, binary, octal, and hexadecimal. For instance, 2010 can written in these four systems as 2010 = 1 210 + 1 29 + 1 28 + 1 27 + 1 26 + 0 25 + 1 24 + 1 23 + 0 22 + 1 21 + 0 20 = 3 83 + 7 82 + 3 81 + 2 80 = 7 162 + D 161 + A 160 = 2 103 + 0 102 + 1 101 + 0 100
Positional representation is a "polynomial form." The number can be represented as a polynomial evaluated at the base , and the polynomial's coefficients are integers mod . In general, a natural number n can be written as n = n 1 n 1 + n 2 n 2 + + 1 1 + 0 0 where = 2, 8, 10, 16 is one of the common bases, and the coefficients k are natural numbers between 0 and  1. cse 1400 applied discrete mathematics numeral systems 2 1.1 The Decimal System
The decimal system is the common notation The alphabet of the decimal system is the set of digits D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Natural numbers (unsigned whole values) are written as strings of these decimal numerals or digits. The natural numbers are members of the set N = {0, 1, 2, 3, . . . , n, . . .}
We'll need to expand the decimal alphabet later, so let's name it now: The alphabet for writing natural numbers is A = D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} You know how to add digits to compute a sum digit s and a carry digit c, which can be written as an ordered pair (c, s) and interpreted 0 1 2 3 4 to mean the natural number 10c + s. The table below shows the sums for adding 0 through 9 to itself. Because addition is commutative the table is symmetric and only the lower triangle needs to be written. 0 1 2 3 4 5 6 7 8 9 0 (0, 0) 1 (0, 1) (0, 2) 2 (0, 2) (0, 3) (0, 4) 3 (0, 3) (0, 4) (0, 5) (0, 6) 4 (0, 4) (0, 5) (0, 6) (0, 7) (0, 8) 5 (0, 5) (0, 6) (0, 7) (0, 8) (0, 9) (1, 0) 6 (0, 6) (0, 7) (0, 8) (0, 9) (1, 0) (1, 1) (1, 2) 7 (0, 7) (0, 8) (0, 9) (1, 0) (1, 1) (1, 2) (1, 3) (1, 4) 8 (0, 8) (0, 9) (1, 0) (1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) 9 (0, 9) (1, 0) (1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8) To write a integer (a signed whole value) the sign symbols + and  can inserted into the alphabet. Z = {0, +1, 1, +2, 2, +3, 3, . . .} For instance, 31, 42, 768, 6.0221415 is an integer. To write a rational number (a signed fractional value), the fraction symbol / can be included in the alphabet. Q = {q : q = a/b, a, b Z, b = 0} A rational number q can also be written in fixedpoint notation q = a/b = n. f Here n N is the unsigned whole part of a/b and f is the fractional part of a/b written as a (possibly unbounded) sequence of digits. A third way to write a rational number q is to use floatingpoint notation. For instance, n = 3142768 is a natural number. For readability it can be convenient to use commas to separate the digits, for instance n = 3, 142, 768. The glyphs used for decimal numerals come from Arabic numerals 5 6 7 8 9 Although it is common to drop the plus sign, a computer stores unsigned integers (natural numbers), say 3, differently from signed integer +3. For instance, 3, 142/768 is a rational number. For computability it can be convenient reduce a fraction to lowest terms, so that the numerator and denominator are relatively prime. For instance  3, 142 1, 571 = 768 384 The alphabet A = D {+, , /} {, , .} can be used to represent rational numbers. For instance, 3, 142/768 = 4.09114583333 For instance, 409.114583333 = 4.09114583333 102 cse 1400 applied discrete mathematics numeral systems 3 q = d. f 10e where d = 0 is a nonzero digit, f is a finite string of digits, and e is a signed integer. The requirement d = 0 is a normalization, meaning it makes the floating point representation unique. ~ Notice that the number = 3.1415 can be written in many ways: ~ = 3.1415 ~ = 0.31415 101 ~ = 0.031415 102 ~ = 314.15 102 ~ = 31.415 101 1.2 The Unary System
Although of limited use, the unary system uses an alphabet with just one character, usually written . The length of unary numbers quickly becomes unwieldy: To write twenty, you'd need to write down 20 strokes Consider writing 1, 000, 000 in unary. But in some situations, for example keep track of small counts, using unary makes sense. One interesting thing about unary is that it does not have a symbol for zero; instead of writing 0, we write nothing at all to represent zero. Addition in unary is easy to define.
: : Write ;, ;,;,;for 20 Please don't write "nothing at all" when you want to write zero in unary. += ,
: :: ::: + =
:::: ;:: 1.3 The Binary System
The binary system uses an alphabet with two characters. B = {0, 1} The natural numbers can be written in binary. Below are the first few natural number written in binary and decimal. Binary Decimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 0110 5 6 0111 7
Do you see a pattern? Can you translate from one notation to another? The characters 0 and 1 are called bits. 1000 1001 8 9 1010 10 The table below shows the sum and carry bits when addition is performed on two bits. For instance, the sum of 1 and 1 is 0, with a carry of 1. This can be represented as an ordered pair (c, s) = (0, 1). Binary addition + 0 1 0 (0, 0) (0, 1) 1 (0, 1) (1, 0) Interestingly, both the sum and carry bits can be computed using Boolean operations on the input bits. The sum bit is the xor of the input bits. The carry bit is the and of the input bits. For readability, bit strings are often written in groups of four. Each 4bit string is a hexadecimal numeral. For instance, (0011 1001)2 = (39)16 . cse 1400 applied discrete mathematics numeral systems 4 1.4 The Hexadecimal System
The hexadecimal system uses an alphabet with sixteen characters. H = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } Below are the first few natural number written in hexadecimal and decimal. Hexadecimal Decimal 0 0 1 1 C 12 2 2 D 13 3 3 E 14 4 4 F 15 5 5 6 6 7 7 8 8 9 9 A 10
For readability, 4bit strings are often converted to their hexadecimal equivalent. For instance, (0011 1001)2 = (39)16 . Hexadecimal B Decimal 11 10 11 12 13 14 15 16 17 18 19 20 21 1.5 The Sexagesimal System
Why are there 60 seconds in a minute? Why are there 60 minutes in an hour? Why are there 360 degrees in an circle? What is the history of base 60? 1.6 Finite Constraints
In practice, finite constraints limit our ability to compute. For instance, the central processing unit (CPU) of a computer contains a few registers each of which can hold a few bits.
0 1 2 3 4 5 6 7 1 0 1 1 1 0 0 0
Data is stored in data registers. Instructions are stored in instruction registers. Modern computers have many registers of different types. An 8bit register (littleendian). The size of a register is the number of cells it has. The content of a cell is a bit. But in practice, the content of a cell can be a higherorder character. The content of a register (the string of characters) is called a word. The size of the register is called the word length. The concepts of an empty word can be useful. Call the empty word . It's length is 0 and it contains no characters. Two fundamental questions are: 1. Given a word length n, how many different words can be written? And its inverse question: 2. Given the need to write m different words, what size register should be used? In given instances it is not hard to answer these questions. Pretend the computer's register size is 8 and any decimal numeral can be held in each of the 8 places. Then any natural number cse 1400 applied discrete mathematics numeral systems 5 from 0 to 9999 9999 can be stored in a register. That is, there are 100, 000, 000 = 108 different words that can be written.
0 1 2 3 4 5 6 7 Registers are "padded," meaning 0's fill a register, for instance 77, would be stored as 0000 0077. 7 7 0 0 0 0 0 0 An 8digit register (littleendian). If the register size is 8 and any hexadecimal numeral can be held in place, then any natural number from 0 to ( FFFF FFFF )16 = 168  1 = 4, 294, 967, 295 can be represented in hardware. That is, there are 4, 294, 967, 296 = 168 different words that can be written.
0 1 2 3 4 5 6 7 F F F F F F F F
7 6 5 4 3 2 1 0 An 8hexadecimal register (littleendian). In practice, computer registers hold bits: 0 or 1. On an 8bit computer any natural numbers from 0 to 28  1 = 255 can be stored in a register. On an 16bit computer any natural numbers from 0 to 65, 535 can be stored in a register. 216
The numbers 0, 1, 3, 7, 15, 31, 63, 127, 255, . . . 2n  1 are called Mersenne numbers. Of course, only one number is stored at a given time. 216 is 64 kilobits or 8 kilobytes. 1 = On an 32bit computer any natural numbers from 0 to 232  1 = 4, 294, 967, 295 can be stored in a register. On an 64bit computer any natural numbers from 0 to 264  1 = 18, 446, 744, 073, 709, 551, 615 can be stored in a register. Theorem 1 (String length count of different words). There are 2n different bit strings of length n. More generally, there are mn different words of length n over an alphabet A containing m characters, Proof. Reason inductively: Study initial cases. There is 1 = 20 bit string of length 0: The empty string . There are 2 = 21 bit strings of length 1: 0 and 1. There are 4 = 22 bit strings of length 2: 00, 01, 10 and 11. Make a prediction: 2n is the number of different bit strings of length n. Establish the conditional implication: "If there are 2n bit strings of length n, then there are 2n+1 bit strings of length n + 1." 232 is 4 gigabits or 1/2 gigabytes. 264 is 16 exabits or 2 exabytes. cse 1400 applied discrete mathematics numeral systems 6 Pretend there are 2n bit strings of length n. For each one of them construct new bits strings of length n + 1 by appending a 0 once and a 1 second time. This process creates 2n + 2n = 2n+1 different strings of length n + 1. There can be no more. For instance, the fourbit string 1011 generates two different fivebit strings 01011 and 11011. Theorem 2 (Mersenne Numbers). The largest natural number that can be written using n bits is the Mersenne numbers number Mn = 2n  1. Proof. Starting with 0 and and ending at 2n  1, 2n consecutive natural numbers are named using bit strings of length n. Reason inductively: Initial cases Using no bits, only the empty word can be written. It is convenient to define the value of the empty word to be 0 so that 20  1 = 0 is the largest natural number that can be written using n = 0 bits. Using 1 bit, the largest natural number that can be written is 1 = 21  1. Using 2 bits, the largest natural number that can be written is 11 = 3 = 22  1. Using 3 bits, the largest natural number that can be written is 111 = 7 = 23  1. Make a prediction: 2n  1 is largest natural number that can be written using nbits. Establish a conditional implication. Pretend 2n  1 is the largest natural number that can be written using n bits. The natural number 2n , written in binary, is 1 followed by n zeros. The sum of 2n and 2n  1 is the largest natural number that can be written using n + 1 bits. And this sum is 2n + (2n  1) = 2n+1  1. Now consider the inverse problem: How long do words have to be to name m different things? Lemma 1. If real number x is not an integer, then x + 1 = x Proof. Compute an integer n such that n  1 < x < n. Then x = n  1 and x = n cse 1400 applied discrete mathematics numeral systems 7 Theorem 3 (Count of different words string length). To name m different things requires words of length min { lg m , lg m + 1} Proof. Consider the sequence of powers of 2. 20 , 21 , 22 , 23 , 24 , . . . = 1, 2, 4, 8, 16, . . . If m is one of these powers of 2, say m = 2n , then, by Theorem 1, there are m things can be named using bit strings of length n = lg m = lg m < lg m + 1 Otherwise let m be natural number that is not a power of 2. Compute an exponent n 1 such that 2n 1 < m < 2n Any value m in this range can be written using n bits. Take the logarithm base 2 of the terms in the above inequalities to get n  1 < lg m < n n = lg m + 1 = lg m = n Reason inductively: Study initial cases. The words 0 and 1 name 2 things, and 1 = lg 2 . The words 00, 01, and 10 name 3 things, and 2 = lg 3 + 1. lg 3 Then take the ceiling or floor of the logarithm to get = The words 00, 01, 10, and 11 name 4 things, and 2 = lg 4 . The words 000, 001, 010, 011, and 100 name 5 things, and 3 = lg 5 = lg 5 + 1. Establish a conditional implication. Pretend you can name m things using bit strings of length n. If m < 2n  1, then m + 1 things can be named using bit strings of length n and n. 2 Problems on Numeral Systems 1. The following natural numbers are written using their binary names. What are their hexadecimal names? cse 1400 applied discrete mathematics numeral systems 8 (a) 0000 1001. (b) 1111 1111. (c) 011 1100 1100. (d) 110 1011 1010. 2. Why is it awkward to group the bits by fours from lefttoright when converting a binary string to hexadecimal? 3. Expand the hexadecimal names below to their binary equivalent. (a) FE. (b) ACED. (c) 577. (d) 3141. 4. Explain how to covert from binarytooctal and octaltobinary. 5. How many length n decimal strings are there? 6. How many length n octal strings are there? 7. How many length n hexadecimal strings are there? 8. How many length n strings of lower case English letters are there? 9. How many length n strings of lower case English letters and decimal numerals are there? 10. How many length n strings of lower case Greek letters are there? 11. Write the number twentyfive in Roman numerals, in decimal, in binary, in octal and in hexadecimal. 12. How many things can be named using strings of the given length and alphabet? (d) Length 4 hexadecimal strings. (e) Length n octal strings. (a) Length 4 decimal strings. (b) Length 4 binary strings. (c) Length 4 octal strings. (f) Length n decimal strings. (g) Length n binary strings. (h) Length n hexadecimal strings. 13. How many characters are needed to name the given number of things ? (a) 5 things in binary. (b) 50 things in decimal. (c) 500 things in hexadecimal. (d) n things in binary. (e) n things in decimal. (f) n things in hexadecimal. 14. Of the 128 ASCII characters, 94 are printable. How many printable strings of ASCII characters are there of the given length? (a) Length 0 strings. (b) Length 1 strings. (c) Length 2 strings. (d) Length 3 strings. (e) Length n  1 strings. (f) Strings of length 0 or 1. (g) Strings of length 0 or 1 or 2. (h) Strings of length 0, 1, 2, . . . , (n  1). 15. Pretend you need to blackbox test a program by entering each and every input combination to verify the output is correct for each input. Pretend the set of input combinations is a set of strings of length 1 through 10 drawn from an alphabet of 94 symbols. How many input combinations are there? CSE 1400 Applied Discrete Mathematics Conversions Between Number Systems
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 Conversion Algorithms: Decimal to Another Base
Conversion of Natural Numbers Conversion of Integers 4 5 6 7 Biased Notation for Integers Conversion of Rational Numbers 1 1 Conversion of Floating Point Numbers Problems on Converting Decimal to Another Base Conversion Algorithms: Another Base to Decimal
Conversion of Natural Numbers Conversion of Integers 11 11 12 Conversion of Rational Numbers Floating Point Arithmetic Machine Epsilon 14 13 10 8 9 Conversion of Floating Point Numbers Problems on Converting Another Base to Decimal
Abstract 14 Decimal notation using Arabic numerals is the standard system for writing numbers in everyday life. However, in many computing applications, other notations are used. Chiefly: binary and hexadecimal. Learning algorithms to translate names between these numerical systems forms a foundation for developing translations between more complex languages. Conversion Algorithms: Decimal to Another Base
Conversion of Natural Numbers
The unsigned whole numbers, the natural numbers, written in decimal 0, 1, 2, 3, 4, 5, . . . can be converted to binary by repeated division cse 1400 applied discrete mathematics conversions between number systems 2 by 2. Dividing a number by 2 produces one of two remainders: r = 0 or r = 1. The natural numbers can be converted to hexadecimal by repeated division by 16. Dividing a number by 16 produces one of 16 remainder: r = 0 through r = 15 = F. Convert q = 14 to binary. Repeatedly divide 14 and following quotients by 2 pushing the remainder bits onto a stack. Repeated Remaindering Mod 2 Quotients Remainders 14 0 7 1 3 1 1 1 ( 14 ) 10 = ( 1110 ) 2 Convert q = 14 to hexadecimal. Repeatedly divide 14 and following quotients by 16 pushing the remainder hexdigits onto a stack. Repeated Remaindering Mod 16 Quotients Remainders 14 E ( 14 ) 10 = ( E ) 16 Convert q = 144 to binary. Repeated Remaindering Mod 2 Quotients Remainders 144 0 72 0 36 0 18 0 9 1 4 0 2 0 1 1 ( 144 ) 10 = ( 1001 0000 ) 2 Convert q = 144 to hexadecimal. Repeated Remaindering Mod 16 Quotients Remainders 144 0 9 9 ( 144 ) 10 = ( 90 ) 16 cse 1400 applied discrete mathematics conversions between number systems 3 Convert q = 143 to binary. Repeated Remaindering Mod 2 Quotients Remainders 143 1 71 1 35 1 17 1 8 0 4 0 2 0 1 1 ( 143 ) 10 = ( 1000 1111 ) 2 Convert q = 143 to hexadecimal. Repeated Remaindering Mod 16 Quotients Remainders 143 F 8 8 ( 143 ) 10 = ( 8F ) 16 Convert q = 255 to binary. Repeated Remaindering Mod 2 Quotients Remainders 255 1 127 1 63 1 31 1 15 1 7 1 3 1 1 1 ( 255 ) 10 = ( 1111 1111 ) 2 Convert 161 to binary. Repeated Remaindering Mod 2 Quotients Remainders 161 1 80 0 40 0 20 0 10 0 5 1 2 0 1 1 ( 161 ) 10 = ( 1010 0001 ) 2 Convert 161 to ternary. Repeated Remaindering Mod 3 Quotients Remainders 161 2 53 2 17 2 5 2 1 1 ( 161 ) 10 = ( 12222 ) 3 . Notice that
161 = 1 3 4 + 2 3 3 + 2 3 2 + 2 3 1 + 2 3 0 cse 1400 applied discrete mathematics conversions between number systems 4 Conversion of Integers
The signed integers can be represented in two's complement notation. To write a decimal integer m in two's complement notation do the following. 1. Convert the natural number m to binary using repeated remaindering as described in the previous section. 2. Append a leading sign bit 0. 3. If m 0, return the result of step 2. Otherwise, if m < 0, return the two's complement of the result of step 2. The two's complement operation is performed as follows. 1. From righttoleft, copy each bit up to and including the first 1. 2. Flip (one's complement) the remaining bits to the left. The idea is: A number m and its negative m add to 0. Therefore, if m = 0100 1100 is a signed integer written in two's complement notation, then m and m's complement (its negative) m add to 0. 1. This integer m = 0100 1100 is positive: It's leading, leftmost, bit is 0. 2. The value of m is decimal 76. 3. The two's complement of m is m = 1011 0100. The sum of m and m is shown below with carry bits on the top row. c 1 1 1 1 1 1 0 0 0 m = 0 1 0 0 1 1 0 0 m = 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0
The two's complement of a positive integer is a negative integer. The two's complement of a negative integer is a positive integer. 1. 161 1010 0001 2. 1010 0001 0 1010 0001 3. If m = +161, return 0 1010 0001 else (if m = 161) return 1 0101 1111 By construction, the sum of m and it's two's complement m is 2s where s is the word length, size, or number of bits in m. m + m = 2s = 1 0000 0000 To write 2s in binary requires s + 1 bits. On an s bit computer the overflow, last carry, bit is discarded. Therefore, on an s bit computer m + m = 0 =0000 0000 Consider this example. Let m = 227 which when written as an unsigned binary number, is 1100 0111. To write m as a signed binary number, append a leading 0 so that
s 0's s 0's To write 2 = (10)2 requires 2 bits. To write 22 = (100)2 requires 3 bits. To write 28 = (1000)2 requires 4 bits. +227 = 0 1100 0111 cse 1400 applied discrete mathematics conversions between number systems 5 To write 227, perform the two's complement operation on 0 1100 0111 to get 227 = 1 0011 1001 Biased Notation for Integers
Biased notation is an alternative method used to represent signed integers. Biased notation represents an integer n as nb = n + b where b 0 is called the bias or excess. Adding a bias b to an integer n translates it to the right giving it a a new name. To compute the value n of a biased integer nb , solve the equation nb = n + b for n = nb  b, that is, subtract b from nb . For illustration, we'll use 8 bit strings .
For instance, pick a bias b = 32, and notice the integers from n = 32 to n = 31 map to biased integers from n32 = 0 to n32 = 63. Let n = 37 and let the bias be b = 127. Then the biased number (37)127 = (n)b = n + b = 37 + 127 = 90 is the biased name for the value 37. The subscript b = 127 is a hint to interpret the bit string as biased number with bias b = 127. Drop it when this is clear from context. The diagram show the integers from 127 to 128 along the top line. The bottom line shows the biased numbers 0 to 255 which are used to name integers from 127 to 128.
127
128 (b7 b6 b5 b4 b3 b2 b1 b0 )b=127
Each bi is either a 0 or a 1 for each i = 0, . . . , 7. Using a bias of b = 127 the 256 integers from 127 to 128 are named 0 to 255. For instance, consider the biased number (1111 1100)b=127 = nb = n + b = (1111 1100)2 + 127
Horner's rule converts the binary number (1111 1100)2 to 252. Horner's Rule 1 1 1 1 2 6 3 7 1 14 15 1 30 31 1 62 63 0 126 126 0 252 252 0 255 Subtract the bias b = 127 from n + b = 252 to get n = 125 as the value of the biased number (1111 1100)b=127 = 125
Biased notation is used to encode positive and negative exponents in floating point notation. That is, let t = 1. f 2eb be a normalized floating point number. The exponent eb is a biased integer. As a small example, the bias could be b = 4 and exponents from e4 = 0 to e4 = 7 represent values 4 to 3. cse 1400 applied discrete mathematics conversions between number systems 6 Conversion of Rational Numbers
To convert a positive rational number a/b, written in decimal notation, to another base do the following. 1. Write the number in fixed point notation: w. f 2. Convert the whole number part w as described in Conversion of Natural Numbers. 3. Convert the fractional number part f by repeated multiplication by 2 (or the appropriate base) inserting the overflow bit into a queue. Convert q = 39/4 to binary 1. Write 39/4 as 9.75 2. Convert 9 to binary 1001. 3. Convert 0.75 to binary. Repeatedly multiply 0.75 and following products by 2 inserting the overflow bits into a queue. Repeated Multiplying Mod 2 Fraction Overflow 0.75 1.5 1 1.0 1 0.0 0 Often the fractional part will not terminate as a finite string. ( 39/4 ) 10 = ( 1001.11 ) 2
Note that the binary fraction 0.11 represents the value 0.75 = 0.50 + 0.25 3 0.11 = 1 2  1 + 1 2  2 = 4 Convert q = 14/3 to binary 1. Write 14/3 as 4.333 2. Convert 4 to binary 100. 3. Convert 0.333 to binary. Repeatedly multiply 0.333 and following products by 2 inserting the overflow bits into a queue. Repeated Multiplying Mod 2 Fraction Overflow 0.333 0.666 0 1.333 1 0.666 0 1.333 1
Note the identity 1 1 1 1 1 = + + + = 3 4 16 64 4 1 1
1 4 ( 14/3 ) 10 = ( 100.0101 ) 2 cse 1400 applied discrete mathematics conversions between number systems 7 Convert q = 1/7 to binary 1. Write 1/7 as 0.142857 2. Convert 0 to binary 0. 3. Convert 0.142857 to binary. Repeatedly multiply 0.142857 and following products by 2 inserting the overflow bits into a queue. Repeated Multiplying Mod 2 Fraction Overflow 0.142857 0.285714 0 0.571428 0 0.142857 1 0.285714 0 0 1 Convert q = 57/5 to hexadecimal 1. Write 57/5 as 11.4 2. Convert 11 to hexadecimal B. 3. Convert 0.4 to hexadecimal. Repeatedly multiply 0.4 and following products by 16 inserting the overflow hexdigits into a queue. Repeated Multiplying Mod 16 Fraction Overflow 0.4 6.4 0 6.4 6 6.4 6 6.4 6 ( 1/7 ) 10 = ( 0.001001 ) 2 Note the identity 1 1 1 1 1 = + 2 + 3 + = 7 8 8 8 8 1 1
1 8 ( 57/5 ) 10 = ( B.666 ) 2 Note the identity 6 6 2 6 6 + + = = + 5 16 162 163 16 1 1 1  16 Conversion of Floating Point Numbers
A floating point number written in decimal can be converted to another base by writing the number in fixed point notation and using the methods of the previous section. Convert 3.75 101 to octal. 2. Repeatedly multiply 0.375 and following products by 8 inserting the overflow octaldigits into a queue. Repeated Multiplying Mod 8 Fraction Overflow 0.375 3.0 3 0.0 0 0 0 1. Write 3.75 101 as 0.375. 3.75 10  1 = ( 0.3 ) 8 cse 1400 applied discrete mathematics conversions between number systems 8 Convert 2.997 10 2 to hexadecimal. 2. Convert 299 to hexadecimal 1. Write 2.997 10 2 as 299.7. Repeated Remaindering Mod 16 Quotients Remainders 299 B 18 2 1 1 299 = ( 12B ) 16
3. Repeatedly multiply 0.7 and following products by 16 inserting the overflow hexdigits into a queue. Repeated Multiplying Mod 16 Fraction Overflow 0.7 0.2 B 0.2 3 0.2 3 3 2.997 10 2 = ( 12B.B333 ) 16 Problems on Converting Decimal to Another Base
1. Convert the following natural numbers (all named q) from decimal to binary. (a) q = 13. (b) q = 134. (c) q = 145. (d) q = 257.
Repeatedly divide q and following quotients by 2 pushing the remainder bits onto a stack. 2. Convert the following natural numbers from decimal to hexadecimal. (a) q = 13. (b) q = 134. (c) q = 145. (d) q = 257. Instead of dividing by 16 and stacking remainders, it may be easier to convert to binary and group bits by fours. 3. Convert the following signed integers from decimal to two's complement binary. (a) q = 13. (c) q = 145. (b) q = +134. (d) q = 257. 4. Convert the following signed integers from decimal to biased decimal notation. cse 1400 applied discrete mathematics conversions between number systems 9 (a) q = 13 with bias b = 32. (c) q = 145 with bias b = 256. (b) q = +134 with bias b = 256. (d) q = 257 with bias b = 512. 5. Convert the following rational numbers, written in decimal, to binary. (a) q = 27/8. (b) q = 5.1. (c) q = 0.3125. (d) q = 0.3333 . Conversion Algorithms: Another Base to Decimal
Horner's rule is a key algorithm for converting a number, written in base b, to decimal. A number m written in base b can be expressed in polynomial form. m = a n 1 b n 1 + a n 2 b n 2 + + a 1 b 1 + a 0 b 0 where the coefficients an1 , an2 , . . . , a1 , a0 are numbers in the set Zb of integers mod b Zb = {0, 1, 2, . . . , (b  1)} Horner's rule can be comprehended by parenthesizing the operations required to evaluate the value of m. m = ( (( an1 b + an2 )b + an3 )b + + a1 )b + a0 There are at least two choices for storing the coefficients: Littleendian
$[a_{0},\,a_{1},\,a_{2},\ldots,\,a_{n2},\,a_{n1}]$ and bigendian
$[a_{n1},\,a_{n2},\,a_{n3},\ldots,\,a_{1},\,a_{0}]$ If the coefficients are stored in littleendian, then
horner horner horner horner :: Float > [Float] > Float c = 0 c [x] = x c (x:xs) = x + c * (horner c xs) or
horner horner horner horner :: Float > [Float] > Float c = 0 c [x] = x c (x:xs) = horner c ([c * last xs]++tail xs) cse 1400 applied discrete mathematics conversions between number systems 10
horner horner horner horner :: Float > [Float] > Float c = 0 c [x] = x c (x:xs) = horner c ([c * x + head xs]++tail xs) Conversion of Natural Numbers
Consider the natural number fortyone. Written in binary, fortyone is (0010 1001)2 . Horner's rule will convert this string into its decimal form: (41)10 .
Table 1: Converting (0011 0101)2 to (41)10 . Horner's Rule 0 0 0 1 0 1 0 0 2 4 0 1 2 5 0 10 10 0 20 20 1 40 41 In a like manner 123 written in binary is (0111 1011)2 . This can be checked by Horner's rule. Horner's Rule 0 0 1 1 1 0 2 6 1 3 7 1 14 15 0 30 30 1 60 61 1 122 123 Horner's rule can convert octal (737)8 to decimal using 8 as the multiplier. The computation is summarized in the table below. Horner's Rule 7 7 Notice that 3 56 59 7 472 479 (737)8 = 7 82 + 3 8 + 7 = 479 Choose a base 2 b < 10 and a string over that base. Convert the string to decimal using Horner's rule. Show that you understand how the string you wrote represents the decimal value computed by Horner's rule. cse 1400 applied discrete mathematics conversions between number systems 11 Conversion of Integers
Signed integers can be written in two's complement notation. By construction, an integer m and it's two's complement m sum to 2s where s is the word size of m. To convert the two's complement binary number m = 0 1100 1000 to decimal do the following. 1. Recognize that m is positive: It's leading, leftmost, bit is 0. 2. Use Horner's rule to convert 0 1100 1000 to decimal. Horner's Rule 0 0 1 1 0 0 2 6 1 3 6 0 12 12 1 24 25 0 50 0 0 100 200 200 50 100 0 1100 1000 = +200.
To convert the two's complement binary number m = 1 1100 1000 to decimal do the following. 1. Recognize that m is negative: It's leading, leftmost, bit is 1. 2. Method 1: Use Horner's rule to convert 1 1100 1000 to decimal. Horner's Rule 1 1 1 1 2 6 3 7 0 14 14 0 28 28 1 56 57 0 114 0 0 228 456 456 114 228 Subtract 29 = 512 to get 456  512 = 56 1 1100 1000 = 56. 3. Method 2: Compute the two's complement of 1 1100 1000 to get 0 0011 1000. Convert to decimal (in your head or by Horner's rule) to get 56. Negate the result. 1 1100 1000 = 56. Conversion of Rational Numbers
The rational number two and ninesixteenth when written in binary is (0010.1001)2 . Horner's rule followed by division by 24 will convert this string into its decimal fraction form: 41/16. Notices the similarity of division by 2 to the fourth and writing 3.1415 as 31415/104 . Horner's Rule 0 0 0 0 0 1 0 1 0 2 2 1 4 5 0 10 10 0 20 20 1 40 41 Figure 1: Converting (0011.0101)2 to 41/16. cse 1400 applied discrete mathematics conversions between number systems 12 Conversion of Floating Point Numbers
Floating point numbers are commonly used to approximate the real numbers. It is beyond the scope of this course to provide a complete description of floating point numbers, but some essential ideas should be known before writing solutions to problems that involve real numbers. Floating point notation is built upon scientific notation. In general, rational numbers written in scientific notation have the form t = d. f 10
e For instance, the scientific notation for 0.577215 is 5.77215 101 . Restricting the leading digit to be nonzero is called This avoids multiple representations for identical values. For instance, 0.0060221415 1026 is normalized as 6.0221415 1023 . In computing practice, t could be stored as a concatenated string t = s e d f , where s is a sign bit. where d is a nonzero digit, f is a decimal string, and e is a base 10 exponent. To gain understanding of floating point numbers let's consider how to write rational numbers in the form t = 1. f 2e where 8 bits are used to encode the sign, the fraction f , and the exponent e. Denote this set of floating pointing numbers F. A binary floating point number t F is an 8bit string that is parsed into three parts as shown below. Sign Bit s Exponent (bias=3) e2 e1 e0 Fraction f 1 f 2 f 3 f 4 The sign bit s controls the whether the floating point number is positive or negative. The next three bits e = e2 e1 e0 encode a base 2 exponent written in biased notation, with bias b = 3. That means the biased exponents in the range 000, . . . , 111 represent the natural numbers in the range 3, . . . , 4 . The four fraction bits f = f 1 f 2 f 3 f 4 encode the natural numbers from 0 to 15, but their value is interpreted as The sign bit s conveniently encodes the sign of t by the function (1)s . When s = 0 the floating point number is positive. When s = 1 the floating point number is negative. ( f 1 f 2 f 3 f 4 )2 f = 16 24
Finally, except for 0, which is the all zero string 0 000 0000, we assume that all floating point numbers are normalized. Therefore, if t = s e2 e1 e0 f 1 f 2 f 3 f 4 = s e f is a floating point number, it represents the rational number t = (1)s 1 + f 16
This is similar to writing the decimal number 0.3141 as 3141/104 . 2e cse 1400 applied discrete mathematics conversions between number systems 13 where s B, 0 f 15, and 3 e 4. The eight line graphs that follow show the distribution of these floating point numbers at each exponential scale. 0 0 0 0 0 0 0 0
16 64 16 32 17 128 24 128 24 64 24 32 24 16 31 128 31 64 31 32 31 16 31 8 31 4 31 2 x x x x x x x 1 2 4 8 16 3 6 12 24 31 x Floating Point Arithmetic
Floating point number systems are rife with arithmetic errors. Even the most basic rules do not apply. Floating point arithmetic is not closed under addition. For instance t = 16 = 1.0 24 = (0 111 0000) f p and s = 1.0 21 = 0.5 = (0 010 0000) f p
Addition is computed by (a) aligning exponents to the higher power: 1.0 24 + 0.00001 24 ; (b) and adding fractional parts 1.00001 24 , and truncating to the accuracy of the system, in our system, 4 places to the right of the binary point: 16 + 0.5 = 1.0000 24 = 16. are floating point number, but their t + s = 16.5 sum is not a number in this system. Floating point arithmetic is not associative. For instance (16 + 0.5) + 0.5 = 16 but 16 + (0.5 + 0.5) = 17
There are several measures of floating point errors that occur when approximating arithmetic over the real numbers. Let t( x ) be the floating point number closest to real number x. Then e( x ) =  x  t( x ) is the rounding error in approximating x by floating point number t( x ). As the graphs above show, the rounding error increases as the magnitude of x increases. The relative error in approximating x = 0 by t( x ) is defined to be E( x ) =  x  t( x ) e( x ) = x x Look at the first line graph above, where the magnitude of scale is the smallest. cse 1400 applied discrete mathematics conversions between number systems 14 0 8 128 16 17 128 128 24 128 31 128 x The floating point number closest to x = 8/128 = 1/16 is t = 0. Therefore 1/16 rounds to 0. The rounding error is e(1/16) = 1/16 and the relative error is E(1/16) = 1. The floating point number closest to x = 16/128 = 1/8 is t = 17/128. Therefore 1/8 rounds to 17/128. The rounding error is e(1/8) = 1/128 and the relative error is E(1/8) = 1/16. The floating point number closest to x = 33/256 is t = 17/128. Therefore 33/256 rounds to 17/128. The rounding error is e(33/256) = 1/256 and the relative error is E(33/256) = 1/33. Real x
8 128 16 128 33 256 33 128 33 64 33 32 33 16 33 8 33 4 33 2 FloatingPoint t( x ) 0
17 128 17 128 16 64 16 32 16 16 16 8 16 4 16 2 16 1 RoundingError e( x )
1 16 1 128 1 256 1 128 1 64 1 32 1 16 1 8 1 4 1 2 RelativeError E( x ) 1
1 16 1 33 1 33 1 33 1 33 1 33 1 33 1 33 1 33 Machine Epsilon
In floating point arithmetic, n = 5 is the power of 2 such that 1 + 2n = 1. The value = 25 = 1/32 is called the machine's epsilon and measures accuracy or inaccuracy to floating point arithmetic. 1 = 1 + 26 = 65/64 F 1 = 1 + 25 = 33/32 F 1 < 1 + 24 = 17/16 F Problems on Converting Another Base to Decimal
1. Use Horner's rule to convert the following unsigned numbers into decimal notation. (a) (0000 1001)2 (b) (1111 1111)2 (e) (747)8 (f) (123)4 (g) ( A47)16 (c) (1100 1100)2 (d) (1010 1010)2 2. Convert the signed decimal integers below into two's complement notation. cse 1400 applied discrete mathematics conversions between number systems 15 (a) +76. (b) 76. 3. Negate the two's complement integers below. (a) 0100 1100. (b) 1100 0000. (c) 1010 0100. (d) 1000 0000. (c) 137. (d) +177. 4. Convert the following two's complement integers into decimal notation. (a) 0100 1100. (b) 1100 0000. (c) 1010 0100. (d) 0010 1000. 5. Using two's complement notation what range of integers from most negative to most positive can be represented using (a) 2 bits? (b) 8 bits? (c) 32 bits? (d) 64 bits? 6. Consider ten's complement notation. An integer and its complement should sum to zero. Writing in 4 digits the integer 1234 has complement 8766 since 1234 + 8766 = 1 0000. The smaller numbers from 0000 to 4999 are positive and have their "normal" value. The larger values 5000 to 9999 are negative and defined by the complement rule illustrated in the example. (a) What are the complements of (a) 3141? (b) 7316? (c) 9999? (d) 5000? (b) What are the decimal numbers for the ten's complements numbers (a) 3141? (b) 7316? (c) 9999? (d) 5000? 7. The following binary strings are floating point numbers where the first (leftmost) bit is a sign bit, the next three bits are exponent bits written in biased notation with bias b = 3, and the last four bits are fraction bits. These floating point are normalized. What are decimal names for these floating point numbers? (a) 1001 1000 (b) 0101 1011 (c) 1111 1111 (d) 0000 0001 8. Using the 8 bit floating point numbers from the course, explain why 17/128 is the smallest positive floating point number and why 1/8 is not. CSE 1400 Applied Discrete Mathematics Modular Numbers
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2
2.1 2.2 Conversion Between Units Modular Numbers
Division mod n 1 3
6 6 Linear Congruence Equations Relatively Prime Numbers Extended Euclidean Algorithm 10 3
3.1 3.2 3.3 Euclidean Algorithm for the Greatest Common Divisor
11 14 8 Solving Linear Congruence Equations 4 Problems on Modular Numbers
Abstract 17 1 Conversion Between Units Pretend you'd like to covert one foot (12 inches) into its equivalent length in meters. You know one foot goes into one meter about 3 times with a remainder of about 3 inches. The empirical approach to convert feet to meters is to lay the footlong ruler along a meter stick as many times as it will go; in this case 3 times. 1 foot 1 meter There will be a tiny piece left over, not covered, on the meter stick. Call the length of this tiny piece r and note that r is some fraction of a foot. To compute r, lay it along the footlong ruler and measure that about three r's almost covers a foot, so that r 0.3333 feet and 1 meter is approximately 3.3333 feet. The conversion between units is 1 meter 3.2808 feet The Euclidean algorithm compute these approximations. 1 foot 1 meter One meter is approximately three feet. 1 meter = 3 feet + r feet where r is some fractional part of one foot. Three, the number of time a foot goes into a meter is called the quotient, and r is called the remainder or residue. 1 foot 0.3048 meters cse 1400 applied discrete mathematics modular numbers 2 1 foot But there is still a tiny piece left over, not covered, on the footlong ruler. Call the length of this tiny piece r1 , and let's also rename r, the first fraction of a foot, by calling it r0 from now on. To compute the length r1 , lay it along the fractional foot r0 = 1 3 almost cover and measure that two of these smaller remainder r1 = r0 = , but by a little too much. We can continue this process until: Some multiple of a tiny remainder exactly covers the previous one. The approximation computed is accurate enough for its intended purpose. Let's stop at this step and note what we've discovered. 1 meter = (3 + r0 ) feet 1 foot = (3r0 + r1 ) feet We make a truncation error by ignoring the value of r2 , effectively setting its value to 0, but we gain a conversion factors to change meters into feet and vice versa. That is, we have r1 feet 1 foot (3r0 + r0 feet 2 r0 feet = (2r1  r2 ) feet r0 7r ) = 0 feet 2 2 r0 feet 2/7 feet 2 1 meter (3 + ) feet 7 Or, 1 meter is about 23/7 = 3.28571428571 feet. Let us declare that 3 + 2/7 = 23/7 3.2857 feet is "good enough for our uses" as an approximation to 1 meter. In practice we would like to have a ruler 1/7 of a footlong so we subdivide 1 foot evenly into 7 parts and 1 meter (almost) evenly into 23 parts. Here's how we can construct a rule oneseventh of a footlong. Lay out three meters and you'll discover you've covered 3(3 + 2/7) = 9 + 6/7 feet. Now lay out ten footlong rulers to 10 feet. Recall from above, 1 meter is approximately 3.2808 feet. cse 1400 applied discrete mathematics modular numbers 3 1 foot 1 meter The 10 foot distance is (about) oneseventh of a foot longer than 3 meters. That is, 3 meters = 3(3 + 2 feet 7 =3 23 feet 7 69 = feet 7 1 = 10  feet 7 Look at the equation 3 (23/7) = 10  1/7) Clear its denominator 7 3 23 = 10 7  1) and rearranging terms to find that 1 = 10 7  3 23 which states
If you lay out 10 feet, measured by 7 oneseventh of a footlong rulers, and compare it to 3 meters, measured by 23 of the oneseventh of a footlong rulers, then 1 unit of measure (oneseventh of a foot) will be leftover. 2 Modular Numbers For every natural number n there is a set Zn of modular numbers where Zn = {0, 1, . . . , (n  1)} Initial instances of these sets are given below. Z0 = Z1 = {0} Z2 = {0, 1} Z3 = {0, 1, 2} Z4 = {0, 1, 2, 3} Z5 = {0, 1, 2, 3, 4} This is the extended Euclidean algorithm which when given 7 and 23 computes 1, 10 and 3. 1 is the greatest common divisor of 7 and 23. Ten and 3 are parameters that express the 1 = gcd(7, 23) as a linear combination of 7 and 23. The set Zn is often read as "the integers mod n". Any integer a can be mapped to one of the integers mod n by computing the nonnegative remainder when a is divided by n. For instance, mod 2 maps all even integers map to 0 and all odd integers map to 1. cse 1400 applied discrete mathematics modular numbers 4 Let a be an integer. Divide a by n to compute a quotient q and nonnegative remainder r, that is, a = qn + r, 0 r < n The mod n function maps the integer a to the remainder r. This is written a mod n = r For instance 38 mod 7 = 3 27 mod 7 = 6 53 mod 12 = 5 78 mod 12 = 6
Do you see the easy way to compute 38 mod 7 given the value of 38 mod 7 is 3? Since 38 and 38 sum to 0, 38 mod 7 and 3 must sum to 0. That is, 38 mod 7 must equal 4. Alternatively compute a quotient q = 6 and remainder r = 4 such that 38 = 6 7 + 4. 38 mod 7 = 4 27 mod 7 = 1 53 mod 12 = 7 78 mod 12 = 6 When arithmetic operations are performed on modular numbers it can occur that the result lies outside the set Zn . The integers mod n is a cyclic number system. For instance, in mod 5 arithmetic, counting starts at 0, goes to 4, and continues by cycling back to 0. While in mod 7 arithmetic counting cycles every seven steps. Integers Mod 5 [1]5 [2]5 [3]5 . . . 9 4 1 6 11 . . . . . . 8 3 2 7 12 . . . . . . 7 2 3 8 13 . . . Integers Mod 7 [2]7 [3]7 [4]7 . . . 12 5 2 9 16 . . . . . . 11 4 3 10 17 . . . . . . 10 3 4 11 18 . . . On Z7 3+4 34 25 = = = 7 12 3 = = = 0+7 5+7 47 = = = 0 5 4 [0]5
. . . 10 5 0 5 10 . . . [4]5
. . . 6 1 4 9 14 . . . [0]7
. . . 14 7 0 7 14 . . . [1]7
. . . 13 6 1 8 15 . . . [5]7
. . . 9 2 5 12 19 . . . [6]7
. . . 8 1 6 13 20 . . . When the context is clear, the syntatic sugar can be dropped and you can write r = [r ]n . A key idea is: The integers mod n partition the integers into n equivalence classes. The names of these classes are [0]n through [n  1]n . Each class represents a subset of the integers. In particular, [r ]n = {nk + r : k Z}
For instance, an integer mod 5 is a name for one of five subsets of integers. The syntatic sugar of brackets and subscripts can be dropped when the context is clear. Subsets that partition a set are called equivalence classes. cse 1400 applied discrete mathematics modular numbers 5 0 = [0]5 = {5k : k Z} 2 = [2]5 = {5k + 2 : k Z} 3 = [3]5 = {5k + 3 : k Z} 4 = [4]5 = {5k + 4 : k Z} For the mod 5 instance, convince yourself of the following statements about the equivalence classes [0]5 , [1]5 , [2]5 , [3]5 , [4]5 . 1. Every integer is in one and only one equivalence classes. 2. When two integers a and b are in the same equivalence class [r ]5 , then (a) a  b is a multiple of 5 When a, b [r ]n write For instance, 5 0 mod 5 16 1 mod 5 17 3 mod 5
If a = sn + r and b = tn + p where 0 r, p < (n  1) so that a mod n = r and b mod n = p then a + b mod n = ((s + t)n + r + p) mod n The union of equivalence classes is the set of all integers. Th equivalence classes are pairwise disjoint. 1 = [1]5 = {5k + 1 : k Z} (b) a and b have the same remainder r when divided by 5 a b mod n Addition and multiplication operations behave as with integers, ( a + b) mod n = ( a mod n) + (b mod n) ( a b) mod n = ( a mod n) (b mod n)
except answers are reduced mod n. For instance, the following calculations hold in mod 9 arithmetic. 28 33 47 5 42 314 23 = (r + p) mod n = (r mod n) + ( p mod n) = ( a mod n) + (b mod n)
Also, a b mod n = (stn2 + (sp + rt)n + rp) mod n = 16 = 9 = 28 = 56 = 85 = 7+9 = 0+9 = 1+39 = 3+39 = 4+49 = = = = = 7 0 1 3 4 = rp mod n = (r mod n) ( p mod n) = ( a mod n) (b mod n) The mod 9 multiplication table below contains interesting informa cse 1400 applied discrete mathematics modular numbers 6 tion. 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8
0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 0 2 4 6 8 1 3 5 7 0 3 6 0 3 6 0 3 6 0 4 8 3 7 2 6 1 5 0 5 1 6 2 7 3 8 4 0 6 3 0 6 3 0 6 3 0 7 5 3 1 8 6 4 2 0 8 7 6 5 4 3 2 1 The integers 1, 2, 4, 5, 7 and 8 have multiplicative inverses mod 9. 2.1 Division mod n
Recall from college algebra that the reciprocal a1 = 1 , the mula tiplicative inverse, of a nonzero real number a = 0 satisfies the equation 1 a a 1 = a = 1 a This is how division is defined: The integer b divided by a is b times a 1 . b = b a 1 a The multiplication table above shows the mod 9 integers: 1, 2, 4, 5, 7, and 8 have reciprocals. They are 11 = 1, 2 4 7
1 1 1 The multiplicative inverse is also called the reciprocal. because because because because because because = 5, = 7, = 4, 2 5 = 1 mod 9 4 7 = 1 mod 9 5 2 = 1 mod 9 7 4 = 1 mod 9 8 8 = 1 mod 9 1 1 = 1 mod 9 In mod 9 arithmetic, "divide by 2" means "multiply by 5". If you divide 51 by 2 mod 9 the answer is 3. 51 2 = (45 + 6) 2 = 6 2 = 3 If you multiply 51 by 5 mod 9 the answer is 3. 51 5 = 255 = 252 + 3 = 9 28 + 3 = 3 mod 9 mod 9 51 = 2, 81 = 8, If you divide 50 by 2 mod 9 the answer is 7. 50 2 = 25 = 18 + 7 = 7 If you multiply 50 by 5 mod 9 the answer is 7. 2.2 Linear Congruence Equations
An equation of the form ax = b mod n is called a linear congruence equation. The basic problem is to compute the value of x given parameters a, b and n. Furthermore, x must be an integer mod n. That is, x is an integer between 0 and (n  1). 50 5 = 250 = 243 + 7 = 9 27 + 7 cse 1400 applied discrete mathematics modular numbers 7 Each of the following are linear congruence equations mod 9. 2x = b mod 9 4x = b mod 9 5x = b mod 9 7x = b mod 9 8x = b mod 9 Using the reciprocals 21 = 5, 41 = 7, 51 = 2 71 = 4, and 81 = 8, a solution x Z9 can be computed for each of the above equations. x = 5b mod 9 x = 7b mod 9 x = 2b mod 9 x = 4b mod 9 x = 8b mod 9 On the other hand, 3 and 6 do not have reciprocals mod 9. Recall row 3 and 6 from the multiplication table. 3 6 0 1 2 3 4 5 6 7 8
0 0 3 6 6 3 0 0 3 6 6 3 0 3 0 6 6 3 3x is never equal to 1, so 3 has no multiplicative inverse, and likewise neither does 6. The linear congruence equations 3x b mod 9 6x b mod 9 have solutions x Z9 only when b = 3 or b = 6, and in these cases there are multiple solutions. 3x 3 mod 9 3x 6 mod 9 6x 3 mod 9 6x 6 mod 9 has solutions has solutions has solutions has solutions x = 1, 4, 7 x = 2, 5, 8 x = 2, 5, 8 x = 1, 4, 7 cse 1400 applied discrete mathematics modular numbers 8 3 Euclidean Algorithm for the Greatest Common Divisor The Euclidean algorithm computes the greatest common divisor of two natural numbers. Definition 1 (Greatest Common Divisor). The greatest common divisor of a and n, call it gcd( a, n) or g for short, is a natural number that divides both a and n. ga and gn Some people call it the greatest common factor. For instance, 10 is the greatest common divisor of 30 and 50. And 7 is the greatest common divisor of 1512 and 1925. The mathematical notation for these instances is 10 = gcd(30, 50) and 7 = gcd(1512, 1925) Furthermore, if d is any divisor of both a and n, then d divides g. Table 1 lists the greatest common divisor of a pair of numbers ( a, n). Table 1: Greatest common divisors on digit pairs. Greatest Common Divisor gcd( a, n) n= 0 1 2 3 4 5 6 7 8 9 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 3 1 1 3 1 1 3 1 8 3 1 4 1 2 1 4 1 2 1 4 1 2 5 1 1 1 1 5 1 1 1 1 5 6 1 2 3 2 1 6 1 2 3 2 7 1 1 1 1 1 1 7 1 1 1 8 1 2 1 4 1 2 1 8 1 2 10 a= 9 10 1 1 1 2 3 1 1 2 1 5 3 2 1 1 1 2 9 1 1 10 The Euclidean algorithm is based on the quotient remainder theorem which states: For any integer a Z and natural number n there exists a unique integer q and a unique natural number 0 r < n such that a = q n + r The Euclidean algorithm can be summarized by the recursive function described in the code below. The interpretation of the code is this: Given natural numbers a and n, compute their greatest common divisor gcd( a, n) by doing the following. 1. If n = 0, then a is the greatest common divisor of a and n. 2. Otherwise, when n = 0, gcd( a, n) is the gcd of n and the remainder r when a is by n. That is, compute gcd(n, r ) to find the answer. ( a Z)(n N) (!q Z)(!r Zn )( a = q n + r ) Although it is not a practical algorithm, you can find the greatest common divisor gcd( a, n) from the prime factorization of a and n. For instance a = 30 = 2 3 5 and n = 50 = 2 52 n = 1925 = 52 7 11 implies that 2 5 = gcd(30, 50). implies 7 = gcd(1512, 1925). a = 1512 = 23 33 7 and What happens when a = 0 and n = 0? cse 1400 applied discrete mathematics modular numbers 9 Here's the Haskell code for the Euclidean algorithm when a is a natural number. A more robust gcd( a, n) function is defined in Haskell's Prelude.
euclid :: Natural Natural > Natural { if n = 0, then gcd(a, 0) = a } euclid a 0 = a { else gcd(a, n) = gcd(n, a `mod` n) } euclid a n = euclid n (a `mod` n) The table below shows three steps of Euclidean algorithm applied to the pair (14, 5). The numbers are colorcoded to illustrate divisors values moving up to the dividend row and remainders moving up to the divisor row. Euclidean Algorithm Compute gcd(14, 5) Dividend Divisor Remainder Quotient a n r q 14 5 4 2 5 4 1 1 4 1 0 4 Each column represents an instance of the quotient remainder theorem 14 = 5 2 + 4 5 = 41+1 4 = 14+0 The output of the Euclidean algorithm is the last nonzero divisor, 1 in this instance. The output is the greatest common divisor of the input. Let us compute the gcd(189, 80) to provide another example of the Euclidean algorithm. Euclidean Algorithm Compute gcd(189, 80) Dividend Divisor Remainder Quotient a n r q 189 80 29 2 80 29 22 2 29 22 7 1 22 7 1 3 7 1 0 7 gcd(14, 5) = 1 Scratch work: 189 80 = 2 80 29 = 2 29 22 = 1 22 7 = 3 71 = 7 189 80 29 22 7 mod 80 = 29 mod 29 = 22 mod 22 = 7 mod 7 = 1 mod 1 = 0 Let us discover how the Euclidean algorithm iterates through its steps. To compute the greatest common divisor gcd( a, n) start by cse 1400 applied discrete mathematics modular numbers 10 renaming them r0 = a r1 = n Also rename the quotient and remainder from the quotient remainder theorem q1 = q r2 = r Then the quotientremainder equation a = n q + r can be rewritten as r0 = r1 q1 + r2 Generalize this equation by replacing 0 with an index variable k, and likewise replace 1 are 2 with k + 1 and k + 2, respectively. r k = r k +1 q k +1 + r k +2 Given rk and rk+1 , the Euclidean algorithm iteratively computes quotients qk+1 qk+1 = rk div rk+1 and remainders rk+2 r k +2 = r k mod rk+1 The algorithm terminates when a remainder rk+2 is 0. The value returned by the algorithm is rk+1 . It is also useful to write the recurrence for the remainders using the equation r k +2 = r k  q k +1 r k +1 Recall from the discussion on unit conversion, we would like to be able to compute the greatest common divisor of a and n as a linear combination of a and n, that is, gcd( a, n) = as + tn for some integers s and t. But before learning this extension to the Euclid's algorithm, the concept of relatively prime natural numbers will be introduced. 3.1 Relatively Prime Numbers
Two natural numbers that have no common factor are prime relative to each other. cse 1400 applied discrete mathematics modular numbers 11 Definition 2 (Relative Prime). Two natural numbers a and n are relatively prime when their greatest common divisor is 1. As instances, the following pairs are relatively prime. gcd( a, n) = 1 = a and n are relatively prime. (3, 8) (12, 35) 1 = gcd(3, 8) = 8 2 + 3 (5) 1 = gcd(12, 35) = 35 (1) + 12 3 When a and n are relatively prime the linear congruence equation ax = b mod n always has a solution: ba1 where a1 is an integer mod n. On the other hand, when a and n are not relatively prime the linear congruence equation ax = b mod n may or may not have a solution. In this case, a solution exists if and only if b is a multiple of the greatest common divisor of a and n. One interesting fact about a relatively prime pair is that every integer can be written as a linear combination of them. That is, if a and n are relatively prime, then there exists integers s and t such that 1 = as + tn. Therefore for every z Z, z = a(zs) + n(zt). 3.2 Extended Euclidean Algorithm The Euclidean algorithm can be extended to compute integers s and t such that gcd( a, n) = as + tn
This is a simple example of Bzout's Theorem. Linear combinations are fundamentally useful! Relating an input value x to an output value y by the equation ax + ny = c Determines a line in ( x, y)space that is characterized by the coefficients a, n, and c. We can organize the computation by starting a "magic table" that contains the coefficients from the above equations. 121 21 1 0 0 1 Consider the problem of computing s and t such that 121s + 21t = gcd(121, 21) Start by writing trivial equations for 120 and 21. 121 1 + 21 0 = 121 121 0 + 21 1 = 21 Next apply a step of the quotient remainder theorem to write 121 = 21 5 + 16 and extend the magic table 2 to the right by appending a new column labeled by the quotient 5. Foll in the third column by comput Table 2: A magic table for the extended Euclidean algorithm. Note that 1 0 0 1 is a matrix with determinate det 121 1 0 1 0 0 =1 1 21 0 1 5 1 5 cse 1400 applied discrete mathematics modular numbers 12 ing the values first column  5second column = third column 0  5 1 = 5 These values come from the quotientremainder equation with some rearrangement of terms. 121 = 21 5 + 16 150 = 1 121(1  5 0) + 21(0  5 1) = 16 121 1 + 21 0 = (121 0 + 21 1) 5 + 16 The next step of the Euclidean algorithm divides 21 by the remainder 16 to yield a new quotient q = 1 and new remainder r = 5. 21 = 16 1 + 5 Extends the "magic table" 3.2 by appending a fourth column labeled 1 with values computed by the formula second column  1third column = fourth column 1  1 (5) = 6 0  1 1 = 1 These values come from the quotientremainder equation with some rearrangement of terms. 21 = 16 1 + 5 121 (1) + 21 6 = 5 121 1 0 21 0 1 5 1 5 1 1 6 21 = (121 1 + 21 (5)) 1 + 5
See how the values in each row are computed by the recursion s k 2 + s k 1 q k = s k t k 2 + t k 1 q k = t k s0 = 0 t0 = 1 s1 = 1 t1 = 0 with initial conditions Continuing the Euclidean algorithm, compute quotients 121 = 21 5 + 16 21 = 16 1 + 5 16 = 5 3 + 1 5 = 15+0 and fill in the "magic table" 121 1 0 21 0 1 5 1 3 5 1 1 4 21 5 6 23 121 cse 1400 applied discrete mathematics modular numbers 13 The next to last column represent the equation 121 4 + 21 (23) = 1 This equation expresses the greatest common divisor of 21 and 121 as a linear combination of 121 and 21. 1 = gcd(121, 21) = 121 4 + 21 (23) = 121s + 21t where s = 4 and t = 23. Here is another example of the extended Euclidean algorithm. To find parameters s and t such that 1 = gcd(13, 5) = 13s + 5t Start a magic table 13 1 0 5 0 1
13 = 13 1 + 5 0 5 = 13 0 + 5 1 Compute a quotient and remainder when 13 is divided by 5 13 = 5 2 + 3 Append a column to the magic table: Label the column by the quotient 2 and compute values in the third column by the formula third column = first column  quotient second column 13 1 0 5 0 1 2 1 2
13 1 + 5 (2) = 3 Compute a quotient and remainder when 5 is divided by 3 5 = 31+2 Append a column to the magic table: Label the column by the quotient 1 and compute values by the formula fourth column = second column  quotient third column 13 1 0 5 0 1 2 1 2 1
13 (1) + 5 3 = 2 1 3 Compute a quotient and remainder when 3 is divided by 2 3 = 21+1 cse 1400 applied discrete mathematics modular numbers 14 Append a column to the magic table: Label the column by the quotient 1 and compute values by the formula fifth column = third column  quotient fourth column 13 1 0 5 0 1 2 1 2 1 1 Notice that this last computation expresses 1, the greatest common divisor of 13 and 5 as a linear combination of 13 and 5. 1 = 13 2 + 5 (5) It is wise to continue one more step to verify your calculations. Compute a quotient and remainder when 2 is divided by 1 2 = 12+0 Append a column to the magic table: Label the column by the quotient 2 and compute values by the formula sixth column = fourth column  quotient fifth column 13 1 0 5 0 1 2 1 2 1 1 2 1 2 3 5 The last column contains the (plus or minus) the original values, and this serves as a check that the computations are correct. 1 2 5 3 5 13 3.3 Solving Linear Congruence Equations
Once you've discovered the equality 13 3 + 5 (5) = 1 you've also discovered that 5 (5) = 1 mod 13 That is, 5 and 5 are multiplicative inverses of one another mod 13. Or, the reciprocal of 5 is 5 mod 13. Or, 51 is 5 mod 13. Of course 5 = 8 mod 13, so that 5 and 8 are reciprocals of one another mod 13. That is, 5 8 = 40 = (39 + 1) = 1 mod 13 51 = 8 mod 13 81 = 5 mod 13
13 3 is equivalent to 0 mod 13. cse 1400 applied discrete mathematics modular numbers 15 Therefore, the value of x that solves the linear congruence equation 5x = 6 mod 13 is x = 8 6 = 48 = 9 mod 13 To solve the general linear congruence equation ax = b mod n execute the extended Euclidean algorithm to find the greatest common divisor g of a and n and parameters s and t such that g = gcd( a, n) = as + nt 1. If g = 1, then as = 1 mod n and a and s are reciprocals mod n. In this case, the value of x that solves the linear congruence equation ax = b mod n is x = bs mod n 2. If g = 1, then ax = b mod n has a solution only when b is a multiple of g. If b is a multiple of g, that is, if b = gk for some integer k, then one value of x that solves the linear congruence equation ax = b mod n is x = ks mod n Consider two examples: One where a and n are relatively prime, and a second where a and n are not relatively prime. 1. Consider the case where a and n are relatively prime. Let a = 14 and n = 115 and pick b = 2. To solve the linear congruence equation 14x = 2 mod 115 execute the extended Euclidean algorithm to compute g = gcd(115, 14) and parameters s and t such that g = 115s + 14t. 115 1 0 14 0 1 8 4 1 2
Replace b in ax = b mod n by gk, multiply both sides of ax = gk mod n by s and use as = g mod n, to get gx = gks mod n or, canceling the common g, x = ks mod n. Multiply both sides of ax = b mod n by s and use as = 1 mod n. In 1 = as + nt, the term nt is equal to 0 mod n. Multiply both sides of 5x = 6 mod 13 by 8. Use 8 5 = 1 mod 13 and 48 = 13 3 + 9 = 9 mod 13. 1 4 5 14 8 33 41 115 cse 1400 applied discrete mathematics modular numbers 16 115 = 14 8 + 3 14 = 3 4 + 2 3 = 21+1 2 = 12+0 Therefore the greatest common divisor of 14 and 115 is 1 and 115 5 + 14 (41) = 1 Moreover, 41 = 74 mod 115 is the reciprocal of 14 mod 115, and value of x that solves the linear congruence equation 14x = 2 mod 115 is x = 2 74 = 148 = 33 mod 115 2. Now consider the case where a and n are not relatively prime. To solve the linear congruence equation 14x = 2 mod 105 execute the extended Euclidean algorithm to compute g = gcd(105, 14) and parameters s and t such that g = 105s + 14t. 105 = 14 7 + 7 14 = 7 2 + 0 105 1 0 14 0 1 7 1 7 2 2 15 Therefore the greatest common divisor of 14 and 105 is 7. Compute the determinant det 1 7 2 = 15 1 + 2 (7) = 1 15 This looks like an error has been made, but it demonstrates what occurs when a = 14 and n = 105 are not relatively prime. The equation 15 1 + 2 (7) = 1 can be "fixed" by multiplying through by 7 to obtain 105 1 + 14 (7) = 7 In mod 105 arithmetic 105 1 is 0 and 7 is 98. 105 1 + 14 98 = 14 98 = 7 mod 105 cse 1400 applied discrete mathematics modular numbers 17 Consider the start of the multiplication table for 14 mod 105 14 0 0 1 14 2 28 3 42 4 56 5 70 6 84 7 98 8 9 10 11 12 13 77 14 15 16 17 91 0 14 28 7 21 35 49 63 The value 7 is smallest nonzero value and every and only multiple of 7 up to 98 are mapped onto in cycles of length 15. In particular, there is no mod 105 integer x such that 14x = 2 mod 105 On the other hand, 14x = 21 mod 105 has seven solutions: x = 9, 25, 39, 54, 69, 84, 99. The first value x = 9 can be computed by multiplying the equation 14x = 2 mod 105 through by 98 and using 14 98 = 7 mod 105 to obtain 14 98x = 7x = 21 98 = 63 = 7 9 mod 105 so that, on canceling the common 7 you'll find x = 9 mod 105 The next six values can be computing by incrementing by 14. 4 Problems on Modular Numbers 1. Describe an algorithm that could be used to convert 1 pound into kilograms. 2. Describe the residue (equivalence) classes for (a) Congruence mod 4. (b) Congruence mod 5. 3. How many residue classes are there mod n? 4. For the given values of a and n below, compute the quotient q and nonnegative remainder r that satisfy the quotientremainder equation a = qn + r, r 0 (a) a = 26, n = 13. (b) a = 27, n = 13. 5. Construct an addition table for the integers mod 6. 6. Construct a multiplication table for the integers mod 4. 7. Construct a multiplication table for the integers mod 7. 8. Solve the following linear congruence equations. (a) 3x 5 (mod 7) (c) a = 27, n = 13. (d) a = 45, n = 13. cse 1400 applied discrete mathematics modular numbers 18 (b) 5x 4 (mod 7) (c) 2x 1 (mod 7) (d) 6x 3 (mod 7) 9. Let p = 25 34 117 1310 196 and q = 36 115 1312 174 . (a) What is the greatest common divisor of p and q? (b) What is the least common multiple of p and q? 10. Use Euclid's algorithm to compute the greatest common divisors listed below. (a) gcd(19, 8). (b) gcd(25, 40). (c) gcd(70, 27). (d) gcd(66, 99). (e) gcd(189, 80). (f) gcd(511, 255). (c) Verify the gcd( p, q) lcm( p, q) = pq. 11. Using your work from question 10, find integers a and b such that (a) 1 = 19a + 8b. (b) 5 = 40a + 25b. (c) 1 = 70a + 27b. (d) 1 = 66a + 99b. 12. Using your work from question 11, solve the following linear congruence equations. (a) 8x = 5 mod 19. (b) 25x = 38 mod 40. (c) 27x = 4 mod 70. (d) 66x = 22 mod 99. CSE 1400 Applied Discrete Mathematics Sets
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2 3
3.1 Set Basics Common Sets 1 3 3
4 Operations On Sets Cartesian Product Subset of a Set Cardinality of a Set Power Set of a Set 6
Binomial Coefficients Counting Bit Strings Precedence of Set Operations 4 5 6 7
7.1 7.2 4 5 6
7 9 8 9 Boolean Laws Partition of a Set 9 11 12 14
Abstract 10 Venn and Euler Diagrams 11 Problems on Sets 1 Set Basics A set is an unordered collection of things . The things in a set A are said to be elements or members of A. The natural number 7 is a member of the set O of octal numerals 7 O = {0, 1, 2, 3, 4, 5, 6, 7} The natural number 8 is not a member of the set O of octal numerals 8 O = {0, 1, 2, 3, 4, 5, 6, 7} If a is an element in A write a A. Of course, it can occur that a particular element a is not a member of set A, in which case write a A. cse 1400 applied discrete mathematics sets 2 A can be described by listing its members as a comma separated list enclosed in curly braces {}. No element is duplicated in a set: A thing in a set is listed once and only once. A can be also described by comprehension. For instance, B = {b : b is a bit} More generally, A can be comprehended by a description A = { a : p ( a) is True} where p ( a) is a proposition about variable a. Even more generally, A can be comprehended by a description A = { f ( a) : p ( a) is True} where f is a function and p ( a) is a proposition about the variable a. When context demands it, the set of all possible things, called the universal set and denoted U, can be named. Sets can be represented by diagrams, for instance, a single set X is drawn as a circle inside a rectangle. U X
For instance, the set of even natural numbers is comprehended by the description 2N = { a : a = 2n n N} For instance, the set of even natural numbers is comprehended by the description 2N = {2a : a N} For instance, B = {0, 1}, is the set of bits. In computing practice, set comprehension requires the proposition p ( a) to be computable, that is, there must be an algorithm that returns True when a A and False when a A. For instance, the set of natural numbers is the universal set for many computing problems. Strings over an alphabet could be U in other applications. Two sets X and Y can be drawn in several relationships, called Euler diagrams. U Y X X and Y are disjoint. X X and Y intersect. Y U Y X U For instance, when no members of X are in Y the sets are disjoint. Contrapositively, no members of Y are in X. Similarly, when some in X are in Y then some members of Y are in X and the sets intersect. Lastly, when all members of X are in Y, X is said to be a subset of Y. X is a subset of Y. Characteristic functions describe these three scenarios. Definition 1 (Characteristic Function). The characteristic function of A is denoted A and computed by the conditional statement False if a A A ( a ) = True if a A When X and Y are disjoint, the values X ( a) and Y ( a) cannot both be True simultaneously. That is, ( a)(X ( a) Y ( a) = False) cse 1400 applied discrete mathematics sets 3 When X and Y intersect, their is some element a where X ( a) and Y ( a) are simultaneously True. That is, ( a)(X ( a) Y ( a) = True)
And when X is a subset of Y, every element in X also belongs to Y. That is, X ( a ) Y ( a ) 2 Common Sets In mathematics, the name of a set is usually written in a font called blackboard bold. Thus, for instance, we have The bits or Boolean values B = {0, 1} = {1, 0} The digits D = {0, 1, . . . , 9} The hexadecimal digits H = {0, 1, . . . , 9, A, . . . , F } The natural numbers N = {0, 1, 2, . . .} The integers Z = {0, 1, 2, . . .} The rational numbers Q = { a/b : a, b Z, b = 0} The English alphabet A = { a, b, c, . . . , x, y, z} The Unicode character set U = {c : 0 c (10FFFF )16 } The integers mod n Zn = {0, 1, 2, . . . , (n  1)} 3 Operations On Sets Sets can be combined in simple ways to create complex expressions. Let X and Y name two sets. The union operator X Y returns the set of all elements in either set: X or Y. X Y = {z : z is in X or z is in Y} The intersection operator X Y returns only the set of elements that are in both sets X and Y. X Y = {z : z is in X and z is in Y} It could be that X = Y, so that two names refer to the same value. U Y X X Y is set union. cse 1400 applied discrete mathematics sets 4 Set complement, X, operates on a single set and returns the elements not in X. X = {z : z is not in X} For instance, let X = {1, 5, 9} , Y = {2, 3, 5, 7} , and V = {4, 6, 8, 9} U Y X X Y is the intersection operator. be three subsets of the universe of decimal digits. D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Then X V = {9}
X U (X Y) V = {0, 1, 2, 3, 5, 7} X Y = {1, 2, 3, 5, 7, 9} X = {0, 2, 3, 4, 6, 7, 8} X is the set complement operator. 3.1 Precedence of Set Operations
Precedence and associativity determine the order in which operations are performed. For sets, complement is computed before intersection, which is before union. All operations are computed lefttoright unless parenthesis or other brackets are used to specify order.
In arithmetic you learn that exponentiation is performed before multiplication, which are performed before addition. Furthermore, the associativity of addition and multiplication is lefttoright, but exponentiation is righttoleft. For instance, 6 + 5 22 = 6 + 5 28 = 6 + 5 256 For instance, when A = {0}, B = {0, 1} and C = {1, 2} compute A B C = {0} {1}
3 4 Cartesian Product Cartesian products provides the foundation for building relations and functions. The Cartesian product of X and Y is the set of ordered ( x, y) that relates every value x X with every value y Y. The Cartesian product of X and Y is written X Y = {( x, y) : x X y Y} The Cartesian product X Y is two dimensional: It can be represented as a set of ordered pairs, for instance, B D = {(0, 0), (0, 1), . . . , (0, 9), (1, 0), (1, 1), . . . , (1, 9)} The Cartesian product can be represented as a table, for instance B D is the table where each entry is True, represented by 1. (A B) C = {0, 1} {1, 2} = {1} = {0, 1} College algebra teaches how to draw functions and relations on the real numbers. y 2 y = x2 + 1 x 2 + ( y  1)2 = 1 x y = x+ 1 2 This is the incestuous relation, where each element b B is related to every element d D. cse 1400 applied discrete mathematics sets 5 0 0 1 1 1 1 1 1 2 1 1 3 BD 4 1 1 5 6 1 1 1 1 7 1 1 8 9 1 1 1 1 1 1 Subsets of B D are called relations from B to D. For instance, the the evenodd relation can be represented by the table where row 0 picks out the even digits as True row 1 picks out the odd digits as
True EvenOdd Relation 0 0 1 1 0 1 0 1 2 1 0 3 0 1 4 1 0 5 6 0 1 1 0 7 0 1 8 9 1 0 0 1 A Cartesian product can be represented as a nodeedge graph. Subgraphs of a complete graph arise in computing practice. For instance, the evenodd relation 9 8 7 6 1 0 5 4 3 2 1 0 5 Subset of a Set Often it is useful to talk about a collection of some elements, but perhaps not all elements, of a set. Such a collection is called a subset. The set of composite digits C = {4, 6, 8, 9} is a subset of the digits D. The subset relation between two sets is very much like the less than relation between two integers. A proper subset is strictly smaller than its superset, just as 5 is strictly less than 7. C = {4, 6, 8, 9} {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} = D If there is some element in A that is not in X, then A is not a subset of X. Stated contrapositively, if A X, then every member of A is a member of X. There is one and only one smallest set. It is the set without any elements, and it is called the empty set. The empty set is denoted by the symbol . Interestingly, the empty set is a subset of any set A. If it were not, there would have to be an element in that is not in A, but there can be no such element a since contains no elements. The vacuous proof that A is that every element in is an element in A. To allow for the possibility of equality, write a b for integers and A X for sets. If A is not a subset of X, write A X cse 1400 applied discrete mathematics sets 6 6 Cardinality of a Set Informally, the cardinality of a set A is the count of elements in A. If this count can be named by a natural number, then A is a finite set. If A is not a finite set, it is an infinite set. There are at least two types of infinite sets. Those that are countable and those that are not. The natural numbers is the definition of countable, infinite set. Any other set A is countable if there is a onetoone and onto function f mapping N to A. For instance, the set of fractions 1 1 1 A= , , ,... 1 2 3 is countable because the function f (n) = 1 n+1 Set A is finite with cardinality n when the elements of A can be put into a onetoone and onto correspondence with the set {0, 1, . . . , n  1}. A finite set is also countable. The idea behind countability is that given any natural number n we can (eventually) count to it. It is not difficult to imagine examples of countable sets. There are examples that are counterintuitive. establishes a onetoone and onto correspondence between the two sets. 7 Power Set of a Set The collection of all subsets of a set A is called A's power set. If A has 3 elements then A's power set contains 23 = 8 elements, each of which is a subset of A. Think of constructing a subset. For each element there are two choices: include it in the subset or leave it out. Consider the decision tree for constructing subsets of A = { a, b, c}. When the left branch is followed, the element is not included in the subset. When the right branch is followed, the element is included in the subset. a b c c c b c The power set of A is denoted by 2A . {c} {b} {b, c} { a} { a, c} { a, b} { a, b, c} Theorem 1 (Power Set Cardinality). A set with n elements has 2n subsets, that is, the power set of A contains all 2n subsets of A when A = n. If A = n, then 2A  = 2A = 2n . cse 1400 applied discrete mathematics sets 7 7.1 Binomial Coefficients
Given a set A with cardinality n, how many melement n subsets does A have? The binomial coefficient ( m ) denotes this number. When a step of an algorithm requires the selection of a subset of values, the chosen subset is called a combination. The size (cardinality) n of the sample space and the size (cardinality) m of the combination determine the count of combinations that can be constructed. The example above shows that a three element set has 1 subset without any elements, (3) = 1 0 3 subsets with one element, (3) = 3 1 3 subsets with two elements, (3) = 3 2 1 subset with three elements, (3) = 1 3 Any given set A has 1 subset without any elements, the empty . Also, there is 1 subset of A that contains every element in A, the set A itself. For small sets each subset can be listed. Let A be a set with cardinality A = n. There are 2n subsets of A. Figure 1 shows the 23 = 8 subsets of A = {0, 1, 2}. The subsets of {0, 1, 2, 3} can be constructed recursively in terms of the subsets of {0, 1, 2}. For instance, to build all 2element subsets of N3 = {0, 1, 2, 3} use the one and twoelement subsets of N2 = {0, 1, 2}. There are two cases to consider. 1. Element 3 is in a 2element subset of N3 . 2. Element 3 is not in a 2element subset of N3 . These two cases are handled by steps below that build a 2element subset of N3 . 1. Take the union of {3} with each 1element subset of {0, 1, 2}. 2. Include in the collection of subsets each already built 2element subset of N2 = {0, 1, 2}.
n Using the binomial coefficient (m) to name the count of 2elements subsets of a 4element set, write n The symbol (m) is called "n choose m". There is only one way to choose nothing at all. There is only one way to choose everything. The boundary conditions on the binomial coefficients are (n) = (n) = 1. 0 n It is convenient to declare that the empty set is a subset of any given set A. Describing how to construct something often leads to a method for counting those things. 4 2 = 3 3 + 1 2 = 3+3 = 6 These six subsets are shown in figure 2. cse 1400 applied discrete mathematics sets 8 Subsets Figure 1: The 23 = 8 subsets of {0, 1, 2}. {0} {1} {2} {0, 1} {0, 2} {1, 2} {0, 1, 2} Subsets Figure 2: The 24 subsets of {0, 1, 2, 3}. {0} {1} {2} {3} {0, 3} {1, 3} {2, 3} {0, 1} {0, 2} {1, 2} {0, 1, 3} {0, 2, 3} {1, 2, 3} {0, 1, 2} {0, 1, 2, 3} cse 1400 applied discrete mathematics sets 9 7.2 Counting Bit Strings
There are 2 n different bits strings of length n. The number of bit strings of length n with m 1's and n  m 0's is equal to the number of melement subsets of an nelement set. For instance, there are 6 bits strings of length 4 with two bits set to 1 and two bits set to 0. Recursion can be used to construct an nlong bit string with m 1's. There are two cases. 1. Let sn1 be an n  1long bit string with m  1 1's. 2. Let tn1 be an n  1long bit string with m 1's. Then 1sn1 and
n The strings 1sn1 and 0tn1 are different Let (m1 ) denote the num1 n 1 ber of strings like sn1 and let ( m ) denote the number of strings like tn1 . Then the number of nlong bit strings with m 1's can be computed by the recursion equation Think of the bit string as a record that elements are in the subset (the bit is 1) or not in the subset (the bit is 0.) {0011, 0101, 0110, 1001, 1010, 1100} is an bit string of length n with m 1's. is an bit string of length n with m 1's.
1sn1 has a leading 1 while 0tn1 has a leading 0. 0tn1 n m = n1 n1 + m1 m This recursion equation is known as Pascal's identity. Table 1 lists the binomial coefficients "n choose m" for pairs of digits. 8 Boolean Laws Notice how the sum of two values in one row determine the value of a term in the next row. 21 + 35 = 56 15 + 6 = 21 7 7 + 2 3 6 6 + 5 5 n1 n1 + m1 m = = = 8 3 7 5 n m The power set 2A of a set A together with the union, intersection, and set complement operations form a Boolean algebra. That is, the followin properties hold for subsets X, Y and Z of A. Identity Laws 1. X = X 2. X A = X Complement Laws 1. X X = A 2. X X = Associative Laws 1. (X Y) Z = X (Y Z) Boolean logic on propositions using or (), and (), and not () operations form a similar Boolean algebra. cse 1400 applied discrete mathematics sets 10
n Table 1: Binomial coefficients (m) count the number of different ways to choose m elements from a set of n elements. 0 0 1 2 3 4 5 6 7 8 9 n Binomial Coefficients (m) Choose m 1 2 3 4 5 6 7 8 9 n 1 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 3 6 10 15 21 28 36 1 4 10 20 35 56 84 1 5 15 35 70 126 1 6 21 56 126 1 7 1 28 8 1 84 36 9 1 2. (X Y) Z = X (Y Z) Commutative Laws 2. X Y = Y X Distributive Laws 2. X (Y Z) = (X Y) (X Z) 1. X (Y Z) = (X Y) (X Z) 1. X Y = Y X Many theorems can be derived from these fundamental laws, for instance De Morgan's laws XY = XY XY = XY A proof of theorems such as De Morgan's laws can be given by examining all cases. The case examination can be organized into a truth table. Cases Results zX 0 0 1 1 zY 0 1 0 1 z XY 1 0 0 0 z XY 1 0 0 0 In English, not (x or y) is not x and not y, and not x and y is not x or not y. cse 1400 applied discrete mathematics sets 11 Cases zX 0 0 1 1 zY 0 1 0 1 Results z XY 1 1 1 0 z XY 1 1 1 0 9 Partition of a Set To partition is to separate into parts. For instance the evenodd relation partitions the digits into two subsets. {0, 2, 4, 6, 8} and {1, 3, 5, 7, 9} A similar instance is the mod 3 relation which partitions the digits into three subsets based on their remainder upon division by 3. {0, 3, 6, 9} , {1, 4, 7} , and {2, 5, 8} For sets with small cardinality it is possible to list all of the partitions. Partitions with 2 subset Set 1 subset 3 subset { 0, 1, 2 } { 0, 1 } {0} {{ 0, 1, 2 }} {{ 0, 1 }} {{ 0 }} { 0, 1, 2, 3 } {{ 0, 1, 2, 3 }} {{ 0, 1, 2 } , { 3 }} {{ 0, 3 } , { 1, 2 }} {{ 0 } , { 1, 2, 3 }} {{ 1, 3 } , { 0, 2 }} {{ 1 } , { 0, 2, 3 }} {{ 2, 3 } , { 0, 1 }} {{ 2 } , { 0, 1, 3 }} {{ 0 } , { 1, 2 }} {{ 1 } , { 0, 2 }} {{ 2 } , { 0, 1 }} {{ 0 } , { 1 }} {{ 0 } , { 1 } , { 2 }} {{ 0 } , { 1, 2 } , { 3 }} {{ 1 } , { 0, 2 } , { 3 }} {{ 2 } , { 0, 1 } , { 3 }} {{ 0 } , { 1 } , { 2, 3 }} {{ 0 } , { 1, 3 } , { 2 }} {{ 0, 3 } , { 1 } , { 2 }} The number ways an nelement set can be partitioned into m subsets n is a Stirling number of the second kind denoted by { m } . A Stirling number of the second kind can be computed by the recurrence equation n n1 n1 = +m m m1 m cse 1400 applied discrete mathematics sets 12 with boundary conditions 0 0 = 1, n 0 = 0 and n n = 1, for n > 0 These ideas occur in the study of equivalence relations, which are relations that partition sets into equivalence classes. 10 Venn and Euler Diagrams
Venn's diagramming technique show relationships between sets. When used in logic, Venn diagrams show relationships among propositions. Venn diagramming begins with an rectangle representing the universe of elements. If the rectangle is not shaded it represents the empty set . U The empty set Shading a region in a Venn diagram indicates it is not empty; it is full. U Mathematicians shade the nonempty region. Logician shade the empty region. Students suffer. A nonempty universe Using this shading rule two regions that can be identified: The universe U and the empty set . When one subset, call it X, is drawn as a circle inside the universe, two additional regions that can recognized: The set X and its complement X. When two intersecting subsets, call them X and Y, are drawn as circles inside the universe, an additional 12 regions that can identified. One way to understand this is to name the four regions in the Venn diagram. Call them a, b, c and d, and note they can be expressed as intersections of X and Y or their complements. Region a b c d Set Expression XY XY XY XY U X The set X U X X: The complement of X cse 1400 applied discrete mathematics sets 13 You can construct the empty set from the set of regions { a, b, c, d} by not choosing any of them. The universe is constructed by the opposite: Choose every region and compute their union. These are the boundary conditions. There are interior cases: Choose one region, Choose two regions, or choose three regions. These cases can be diagrammed. From the four regions { a, b, c, d} choose One region Two regions Three regions a Y b d X U Y b d X U Y b d X U Y b d X a Y b d X U Y b d X c c c a Y b d X U c c a Y b d X U a Y b d X c c c a Y b d X U a Y b d X U c c c U a Y b d X U a Y b d X U c c U a Y b d X U c U a Y c U b d X No regions a Y b d X c U Four regions a Y b d X c U a a a a A functional relationship between the number intersecting subsets and number of different regions that can be described can be ex cse 1400 applied discrete mathematics sets 14 pressed by a function r (n) = 22 n where n is the number of intersecting subsets and r (n) counts the total number of distinct regions that can be constructed. Count of Subsets Count of Regions Function 0 2 1 4 2 16 3 256
 4 65536 Regions = 22 Subsets 11 Problems on Sets
1. Describe the following sets. List a representative sample of elements establishing a pattern. Give a function that computes the elements. (a) The set of even integers. (b) The set of odd integers. (c) The set of integers that have a remainder of 2 when divided by 3. (d) The Mersenne numbers. (e) The triangular numbers. (g) The set of solutions to the equation  x   1 = 0. (a) x is an element of X. (b) x is not an element of X. (c) X is a subset of Y. (d) X is a proper subset of Y. (e) X is not a subset of Y. (f) The union of X and Y. (g) The intersection of X and Y. (h) The complement of X. (i) The empty set 3. Answer True or False. (a) 2 {{2}}. (d) { x }. (f) The set of solutions to the polynomial equation x2  x  1 = 0. 2. What notation would be used to stand for the following phrases? (b) {}. (c) 0 . (f) { x } { x }. (e) { x } { x }. 4. Below are standard names for sets that occur in computing. Describe these sets. (a) B (b) H (c) N (d) Z cse 1400 applied discrete mathematics sets 15 (e) Z+ (f) Q 5. What is the cardinality of each of these sets? (a) . (b) {}. (c) D. (d) x : x2  x  1 = 0 . (e) N. (f) Q. (g) R. (g) R (h) 6. What is the power set of each of these sets? (a) {0}. (b) x: (c) . x2 x1 = 0 . (d) {}. 7. What is the cardinality of each of these sets? (a) The power set of {0}. (b) The power set of x : x2  x  1 = 0 . (d) The power set of H, the set of hexadecimal numerals. (c) The power set of D, the set of digits. 8. Describe how to define the set difference operator: Y  X using the standard union, intersection, and set complement operators. 9. Shade the Venn diagram to indicate the given region is not empty. (a) X Y. Y X (b) X Y V. Y X Z X V (d) X Y Z. U Y Z X (c) X Y Z. Y Z U U U 10. Shade the Venn diagram to indicate the given region is not empty. (a) X Y. U Y X Z cse 1400 applied discrete mathematics sets 16 (b) X Y Z. U Y U Y X Z (d) X Y Z. Y X (c) X Y Z. 11. Let X and Y be subsets of some universal set U. Are the following statements True or False? (a) X = X (b) X = X (c) X U = X (e) X U = (f) X Y = X Y (g) X Y X Z U X Z (d) X U = U 12. Let M10 = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511} be the set of the first 10 Mersenne numbers. Let T10 = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45} be the set of the first 10 triangular numbers. Find (a) M10 T10 . (b) M10 T10 . (c) M10  T10 . 13. Using the three sets X = {1, 2, 3, 4, 5} over the universe of digits compute the following set operations (a) X Y D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} (c) (X Y) Z Y = {0, 2, 4, 6, 8} Z = {0, 3, 5, 9, } (d) T10  M10 . (b) X Z 14. Using the three sets X = {1, 2, 3, 4, 5} over the universe of digits (d) (X Y) Z Y = {0, 2, 4, 6, 8} Z = {0, 3, 5, 9, } write expressions using set operators union , intersection and complement that are equal to the following sets. D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} cse 1400 applied discrete mathematics sets 17 (a) S = {6, 8} (c) V = {0, 1, 2, 3, 4, 5, 6, 8} (d) W = {3, 5} (b) T = {1, 2, 4} 15. Consider the "set" S = { x : x x }. (b) Show that S S is a contradiction. This is known as Russell's paradox. (a) Show that S S is a contradiction. CSE 1400 Applied Discrete Mathematics Boolean Logic
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 Control Structures Boolean Logic
Normal Forms Normal Forms 1
3 4 4 6 9 10 10 12 12 3 The Conditional Operator Complex Propositions Truth Tables 7 Logical Equivalence Satisfiable and Valid Propositions Constructing Boolean Functions Satisfiability 12 Counting Boolean Expressions Consistency and Completeness of Boolean Algebra 3 Problems on Boolean Logic
Abstract Logic controls the action of a computer. 13 1 Control Structures The BhmJacopini theorem shows that only three fundamental control structures are necessary to implement any Turing algorithm. 1. Execute instructions sequentially one after another as in figure 1 2. Select one of two instruction to execute according to the value of a Boolean variable as in figure 2 3. Iterate through a sequence of instructions until a Boolean variable changes value as in figure 3 cse 1400 applied discrete mathematics boolean logic 2 Figure 1: Sequential execution of statements. Statement Next Statement Figure 2: Conditional execution of statements. Boolean Condition Then Statement(s) Else Statement(s) Figure 3: Loop (iterative) execution of statements. Boolean Condition Loop Statement(s) cse 1400 applied discrete mathematics boolean logic 3 2 Boolean Logic Boolean logic provides the basis to control the execution of algorithms. Propositional calculus studies the behavior of formulas constructed using Boolean variables. The domain of these variables is the set of truth values B = {False, True}. A Boolean variable is also called a proposition and is often interpreted as the name for a declarative natural language sentence: A proposition is a sentence that can only be True or False. A formal syntax describes what propositions are and how they can be manipulated. 1. False, also called 0, is a proposition. 2. True, also called 1, is a proposition. 3. Boolean variables over the set of bits are propositions. If p is a Boolean variable, then p {0, 1}. 4. If p and q are propositions, then (a) Not p, denoted p is a proposition Boolean variables are typically named p, q, r, s, . . .. All humans are mortal. Socrates is human. Socrates is mortal. (c) p or q, denoted p q is a proposition 5. Nothing else is a proposition. (b) p and q, denoted p q is a proposition p and p are called literals. One of them is False, the other is True. Haskell uses && to express and. Haskell uses to express or. To begin we need to define the Boolean operations described above. The not operator is defined by truth table 1. The and Input p 0 1 p Output
Table 1: The not operator. p
1 0 p operator is defined by truth table 2. or operator is defined by truth table 3 From a mathematical point of view, the meaning of proposition p is immaterial. Collections of Boolean variables are manipulated using the above rules, that is all. From a computing point of view, the meaning of a proposition gives reasons for manipulating it. 2.1 Normal Forms
A literal cse 1400 applied discrete mathematics boolean logic 4 Input p 0 0 1 1 p q q 0 1 0 1 Output pq 0 0 0 1
Table 2: The and operator. pq Input Output pq 0 1 1 1
Table 3: The or operator. p 0 0 1 1 p q q 0 1 0 1 pq 2.2 Normal Forms
A form is a syntactic structure. A form is normal if every expression can be transformed into its structure. Two normal forms for Boolean logic are conjunctive and disjunctive normal forms. 2.3 The Conditional Operator
Conditional statements bridge from True statement to
True statement. In logic, the conditional is written if p then q where p and q are Boolean variables. Symbolically, the conditional is written pq The value of a conditional `if p then q' is defined as follows. 1. When p is True the value of the conditional has the value of q. 2. When p is False the value of the conditional is True. That is, if p then q = q if p = True True if p = False
The logical conditional is similar to the Haskell conditional if p then q else true. cse 1400 applied discrete mathematics boolean logic 5 These rules are summarized in the truth table below, which also shows that the conditional p q is equivalent to p q. The
Table 4: The conditional operator. Input Output p 0 0 1 1 p q pq q 0 1 0 1 pq 1 1 0 1 p q
1 1 0 1 value (True or False) of a conditional can be difficult to understand, especially when the premise is False. To gain some understanding, consider these statements. "John scores above 90 on the final." Call this p. "John earns an A in the course." Call this q. Pretend I make the statement "If John scores above 90 on the final, then John earns an A in the course." That is p q. Ask yourself, when my statement is True and when it is False? There are four cases. Two cases where p is True: 1. If John scores above 90 on the final and John earns an A in the course, do you agree my statement p q is True? 2. If John scores above 90 on the final and John does not earn an A in the course, do you agree my statement p q is False? And two cases where p is False. 2. If John scores 90 or below on the final and John's grade is B or below, do you agree my statement p q is not False and therefore must be True? 3. If John scores 90 or below on the final and John grade is A, do you agree my statement p q is not False and therefore must be True? Notice the statement p q tells you nothing about the value of q when p = False. The conditional operator is at the heart of establishing a proof. p q is called an argument. p is called the premise. q is called the conclusion. cse 1400 applied discrete mathematics boolean logic 6 2.4 Complex Propositions
Complex propositions can be made from by combining simple propositions using Boolean not, and and or operations. For values of n, it is useful to list the expressions that can be created using n Boolean variables p0 through p n1 . 1. When n = 0 there are no propositions, but there are two Boolean functions, the constant True and the constant False. 2. When n = 1 there is one proposition p and four Boolean functions: True, False, p, and p. 3. When n = 2 there is 2 propositions p and q, and sixteen Boolean functions. Name
False There are 22 Boolean functions on n Boolean variables. n Notice that True can be written as an expression in p: True = p p. Also, False can be written as an expression in p: False = p p. See the section on primitive type Bool. Symbol 0 ( ) p ( ) q Name NOT 00 nor) equivalence NOT q converse NOT p conditional NOT AND (nand)
True Symbol AND NOT conditional Buffer p NOT converse Buffer q Exclusive OR OR Input p 0 0 1 1 q 0 1 0 1 Binary Input p 0 0 1 1 q 0 1 0 1 Binary 0 0 0 0 0 0 pq 0 0 0 1 () q p () 1
I use the binary value in the table as a checksum to know that each of the 2 22 = 16 Boolean functions are listed. Function ( p q ) p ( q p ) q
0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 pq 0 1 1 0 pq 0 1 1 1 1 2 3 4 5 6 7 Functions ( p q ) q
1 0 0 0 1 0 0 1 1 0 1 0 qp 1 0 1 1 p
1 1 0 0 pq 1 1 0 1 ( p q )
1 1 1 0 1 1 1 1 1 15 8 9 10 11 12 13 14 cse 1400 applied discrete mathematics boolean logic 7 4. When n = 3 there are twohundredandfiftysix, that is 22 = 28 = 256, different Boolean functions can be constructed using 3 Boolean variables p, q, and r. 5. In general, 2 different Boolean functions can be defined on a domain of n Boolean variables p0 , . . . , p n1 . Not only do the number of Boolean functions grow rapidly as the number of propositional variables increases, there are multiple names for identical functions.
2n
3 Each of the three variables can assume one of two values giving eight combinations (0, 0, 0) through (1, 1, 1). A function maps each combination to one of two values. Therefore there are 28 different functions. 2.5 Truth Tables
Given a Boolean function B ( p 0 , . . . , p n 1 ) how do you compute its output for given input values for its variables p0 , . . . , p n1 ? For small values of n, a truth table is a reasonable method to express the computation. For instance, pretend you want to know the input/output behavior of the function B( p, q ) = ( p q ) Using the basic operations described above you can create a truth table for B( p, q ). The four combinations of input values are listed in the two left columns, and the outputs for these inputs are listed in the column colored crimson. Input p 0 0 1 1 q 0 1 0 1 Output 1 0 0 0 (p q)
0 1 1 1 When the output column is always True, the Boolean expression is said to be a tautology. The expression (( p ) ( p q )) q, called modus ponens, is a basic rule of inference. Input p 0 0 1 1 q 0 1 0 1 Output ( p ( p q ))
0 0 1 1 0 0 0 1 1 1 0 1 1 1 1 1 q 0 1 0 1 cse 1400 applied discrete mathematics boolean logic 8 This xkcd cartoon used under a Creative Commons license. See http://xkcd.com/license.html A tautology is a theorem of Boolean logic. There are several useful Boolean logic tautologies. Modus Tollens q (p q) p
Reductio ad Absurdum ( p False) p
Resolution ( q q ) (= p r ) q r
Simplification (q q ) p
Hypothetical Syllogism (p q) (q r) p r
The negation of a tautology is called a contradiction. Consider the expression
Apply DeMorgan's laws and convert disjunctive forms a b to conditional a b notation. (( p q ) ( p r )) ( q r )
which is the negation the resolution rule of inference Input p 0 0 0 0 1 1 1 1 q 0 0 1 1 0 0 1 1 r 0 1 0 1 0 1 0 1 ( p q ) ( p r )) ( q r )
Output (( p q ) ( p r )) ( q r )
0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 cse 1400 applied discrete mathematics boolean logic 9 A contingency is a Boolean expression that is sometimes True and sometimes False. 2.6 Logical Equivalence You can convey the same meaning (or value) in many ways. Consider the three statements. 1. If it is raining and sunny there will be a rainbow. 2. If there is no rainbow, then it is not raining or not sunny. 3. It is not raining or it is not sunny or there is a rainbow. Although it may not be obvious at first glance, these three propositions are equivalent. To understand this, let p, q, and r be the atomic propositions "it is raining", "it is sunny", "there is a rainbow" Using these names, and logical operations, the three complex propositions 1, 2, 3 can be represented symbolically. 1. ( p q ) r 2. ( r ) (( p ) ( q )) 3. ( p ) ( q ) r Using these symbolic representations, a truth table can be constructed. Notice that the output is identical for each combination of input signals. Input p 0 0 0 0 1 1 1 1 q 0 0 1 1 0 0 1 1 r 0 1 0 1 0 1 0 1 Output Satisfiability (SAT for short) is a classic hard decision problem: Given a Boolean expression B( p0 , p1 , . . . , p n1 ) in n Boolean variables, is there an assignment of True or False values to each of the variables that make B( p0 , p1 , . . . , p n1 ) True? Logicians would identify p, q, and r as temporal propositions. Their truth is not absolute, but depends on time. Likewise, their truth depends on location as well. Spaciotemporal reasoning is an advanced field with many applications. ( p q ) r ( r ) (( p ) ( q )) ( p ) ( q ) r
1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 In the truth table, the output values can reasoned as follows. 1. For statement 1, the output is 1 for p = 0 or q = 0, which fills in the first 6 rows. The output of seventh row is 0 because the premise p q is True and the conclusion r is False. And, the output in row eight is 1 because the premise is True and the conclusion is True. cse 1400 applied discrete mathematics boolean logic 10 2. For statement 2, the output is 1 whenever r = 1, which fills every other row with 1 starting from the second. The output is also 1 whenever p or q is false. For the seventh row, the output is 0 because the premise r is True and the conclusion p q is False. 3. Verify the output for statement 3 for exercise. Boolean expressions are equivalent when they have identical inputoutput behavior. This equivalence partitions Boolean expressions into equivalence classes. Notice this instance of equivalence is a relation that is reflexive, symmetric, and transitive. Reflexive: B( p, q, . . .) B( p, q, . . .) for all Boolean expressions B( p, q, . . .). Symmetric: If B( p, q, . . .) C ( p, q, . . .), then C ( p, q, . . .) B( p, q, . . .), for all Boolean expressions B( p, q, . . .) and C ( p, q, . . .). Transitive: If A( p, q, . . .) B( p, q, . . .) and B( p, q, . . .) C ( p, q, . . .), then A( p, q, . . .) C ( p, q, . . .), for all Boolean expressions A( p, q, . . .), B( p, q, . . .), and C ( p, q, . . .). 2.7 Satisfiable and Valid Propositions Definition 1 (Truth Assignment). Let p = p ( x0 , x1 , . . . , xn1 ) be a Boolean function in the atomic (True or False) variables. An assignment T maps values True or False to each of the variables x 0 , x 1 , . . . , x n 1 . The assignment T is a truth assignment if the value of p is True. Definition 2 (Satisfiable Propositions). A Boolean expression p is satisfiable if p has a truth assignment. Definition 3 (Valid Propositions). A Boolean expression p is valid if p is true for all assignments. Corollary 1 (Unsatisfiable Propositions). If p is valid, then p is unsatisfiable, that is, p has no truth assignment. ( x0 , x1 , x2 ) = (True, False, True) is an assignment of the variables in the Boolean function
p = p ( x 0 , x 1 , . . . , x n 1 ) 2.8 Constructing Boolean Functions How can you build a circuit that has given inputoutput behavior? Pretend you needed to construct a Boolean function that behaves as indicated in the table below. Input p 0 0 1 1 q 0 1 0 1 Output r 1 0 0 1 To build the Boolean function as a disjunction of conjunctions write a conjunctive clause for each row where the output is True. cse 1400 applied discrete mathematics boolean logic 11 The clause is the AND of literals in the row. The variable used if it is True and the negation of the variable is used otherwise. For instance in the truth table above there are two rows with output 1. Using the rule, the first row produces the conjunctive clause ( p q ), and the fourth row produces the conjunctive clause ( p q ). Next, form the disjunction (OR) of all the conjunctive clauses. r ( p, q ) = ( p q ) ( p q ) To build a Boolean function as a conjunction of disjunctions write a disjunctive clause for each row where the output is False. The clause is the OR of literals in the row. The variable used if it is False and the negation of the variable is used otherwise. Using the truth table above there are two rows with output 0. Using the rule, the second row produces the disjunctive clause. ( p q ), and the third row produces the disjunctive clause. ( p q ). Form the AND of all the disjunctive clauses. r ( p, q ) = ( p q ) ( p q ) A more complex instance is given in the truth table below that describes a full adder: The Boolean function that adds two bits a and b and a carryin bit cin to produce a sum bit s and a carryout bit cout Input a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 cin 0 1 0 1 0 1 0 1 Output s 0 1 1 0 1 0 0 1 cout 0 0 0 1 0 1 1 1 The sum bit s can be represented by the expression s = ( a b cin ) ( a b cin ) ( a b cin ) ( a b cin ) which can be factored as a b cin where is the xoroperation. The carryout bit cout can be represented by the expression cout = ( a b cin ) ( a b cin ) ( a b cin ) ( a b cin ) cse 1400 applied discrete mathematics boolean logic 12 which can be factored as ( a b ) ( cin ( a b ))
Two expressions that compute output s are ( p q r ) ( p q r ) ( p q r ) ( p q r )
and ( p q r ) ( p q r ) ( p q r ) ( p q r ) 2.9 Satisfiability
The satisfiability problem is:
Given a Boolean function, is there some assignment of truth values that maps to True?
SAT is how one refers to the satisfiability problem. Satisfiability is known to be a hard problem. To find a truth assignment for a Boolean function B( p0 , . . . , p n1 ) one may have to test all 2n possible truth assignments of the n Boolean variables p0 , . . . , p n1 . 2.10 Counting Boolean Expressions
Many propositions can be constructed using Boolean operations over a set of propositions. Pretend you are given a set of n propositions. Think about it. A Boolean expression constructed using the formal syntax rules above is a function from the domain B B B = Bn of the propositions p 0 , p 1 , . . . , p n 1 Call the n propositions p0 , p1 , . . . , p n1 . to the range B = {0, 1}. The cardinality of the domain is 2n since each proposition p k , k = 0, 1, . . . , n  1 can be in one of two states: True or False. The cardinality of the range is 2. To define a function, each of the 2n input values in the domain is mapped to one, and only one, of the 2 values in the range. That is, there are 2 choices 2n n times or 22 different choices. Each one represents a different Boolean function. 2.11 Consistency and Completeness of Boolean Algebra
Boolean algebra is based on underlying axioms and the theorems that can be derived from from the axioms using rules of inference. A direct proof of a proposition q is obtained by applying the rule of inference cse 1400 applied discrete mathematics boolean logic 13
If p is True and p q is True, then q is True. Boolean logic is consistent if it is not possible to construct a Boolean proposition p such that both p and p are True. Stated differently, Boolean logic is inconsistent if it is possible to construct a Boolean proposition p such that both p and p are True. Boolean logic is complete if it there is a proof of every True Boolean proposition s. Stated differently, Boolean logic is incomplete if there is a True proposition s that no proof within Boolean logic. It turns out that Boolean logic is both consistent and complete. The next few ideas outline why this is True. Consider the Boolean expression s = p ( p q ) Construct a truth table for r and determine that it is a tautology. Input p 0 0 1 1 q 0 1 0 1 p 0 0 1 1 Output Within the system of Boolean logic it is possible to prove every True proposition (complete) and not possible to prove any False proposition. 1 1 1 1 ( p q )
0 1 1 1 Tautologies can be used in proof, and it is convenient to name them. Let's call s = p ( p q ) the consistency/complete rule. Now, let's pretend that Boolean logic is inconsistent. That is, let's pretend there is a Boolean proposition p such that both p and = p are theorems. Then, since is s = p ( p q ) is a theorem and p is True, it must be that p q is True. And, since p is True, it must be that q is True. That is,
If Boolean logic is inconsistent, then every proposition q is a theorem. Stated in the contrapositive, if there is proposition q that is not a theorem, then Boolean logic is consistent. To complete the argument, the proposition q = r s is an instance of a proposition that is not always True. Therefore, Boolean logic is consistent. 3 Problems on Boolean Logic 1. Match the term with its symbol. cse 1400 applied discrete mathematics boolean logic 14 (a) (b) (c) (d) (e) (f) (g) (h) AND Equivalent Exclusive or
True False (a) (b) (c) (d) (e) 0 (f) (g) Implies (if . . . then . . . ) NOT OR (h) 1 (i) Conditional (if . . . then . . . ) 2. Given that p = True, q = False and r = False, compute the value of the following propositions. (a) p r (e) p r (b) p r (c) ( p q ) r (d) ( p r ) q 3. Express the conditional operator pq= using the not and or operations.
if p then q else r (f) ( p q ) r (g) ( p q ) r (h) p ( r q ) 1 if p = 0 or (p = 1 and q = 1) if p = 1 and q = 0 0 4. Write the Haskell expression 5. When p is False, describe the output values of the conditional from problem 4. 6. When p is True, describe the output values of the conditional from problem 4. 8. Construct truth tables to prove DeMorgan's laws (a) ( p q ) ( p ) ( q ) (b) ( p q ) ( p ) ( q ) 7. Show that the conditional p q is equivalent to p q. as a Boolean expression using variables p, q and r and operators , and . 9. Show how to distribute NOT into a conditional. ( p q ) = (
10. Show how to factoring NOT out of a conditional. ) p q ( ) cse 1400 applied discrete mathematics boolean logic 15 11. Construct a truth table to prove a conditional is equivalent to its contrapositive, that is, p q q p 12. Construct a truth table to prove AND distributes over OR, that is, p (r r) (p r) (p r) 13. Construct a truth table to prove OR distributes over AND, that is, p (r r) (p r) (p r) Construct a truth table for the Boolean expression (( p q ) ( q r )) ( p r )
14. Construct a truth table for the Boolean expression (( p q ) r ) ( p ( q r ))
Is the equivalence True or False? Explain your answer. 15. Construct a truth table for the Boolean expressions ( p q ) ( q p )
16. Identify each statement as a tautology, a contradiction, or a contingency. (b) A (B C) = (A B) (A C) (d) (0, 1) {(0, 0), (0, 1), (1, 0), (1, 1)} (e) (0, 1) {(0, 0), (0, 1), (1, 0), (1, 1)} (f) ( p ( q q )) p (a) A = U (c) {(0, 1)} {(0, 0), (0, 1), (1, 0), (1, 1)} 17. Complex computer circuits can be build from three basic gate types, called And, Or, and Not, and drawn as illustrated below. p q
And Gate pq p q
Or Gate pq p
Not Gate p cse 1400 applied discrete mathematics boolean logic 16 The inputs p and q are high (1) or low (0) voltages. Fill in the chart below. p 0 0 q 0 1 0 p
0 pq pq 1 18. Let Bn be the set of all strings of high or low voltages of length n. For instance there are 4 strings of length 2. B2 = {00, 01, 10, 11} What is the cardinality of Bn ? 19. How many functions can be constructed from Bn to B = {0, 1} using And, Or, and Not operations? 20. How many functions can be constructed from Bn to Bm = {0m , . . . , 1m } using the gate operations And, Or, and Not? 21. It is estimated that there are 1080 atoms in the universe. Find the number of propositions n such that there are more Boolean functions in n variables than there are atoms in the universe. CSE 1400 Applied Discrete Mathematics Predicates
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 Predicate Logic 1
6 6 7 Predicate Logic Inference Rules Negation of Quantified Predicate Statements Reasoning about Quantification Order Counterexamples 7 7 Satisfiable and Valid Predicates Consistent, Complete, and Decidable Models 8 2 1 Problems on Predicate Logic Predicate Logic 8 A Boolean statement is either True or False. By constrast, the truth value of a predicate statement depends on the value one or more variables and functions and relations between them. A predicate statement can be True for all values of the variables. Logicians call this a universal affirmative. An instance of a universally True predicate statement is
"For all natural number, the sum of the first n is n(n  1)/2." Predicate logic is also called firstorder logic. Call "The sum (of the first n natural numbers)" the subject and label it S. You can think of S as the set of numbers that are sums of first n natural numbers S = {0, 1, 3, 6, 10, 15, . . .} Call "n(n  1)/2" the predicate and label it P. You can think of P as the set of numbers that are of the form n(n  1)/2 where n is a natural number P= n ( n  1) :nN 2 cse 1400 applied discrete mathematics predicates 2 The predicate statement above can be represented by the Euler diagram P S U which shows every s S is a member of P. A universally affirmative predicate statement can be represented by the logic formula (s)(s S s P)
which states that for all values s that are the sums of the natural numbers (starting at 0 and stopping at some finite value n) can be computed by the formula n(n  1)/2 for some natural number n. There are, of course, others ways to express this, for instance, (s S)(n N)(s = n(n  1)/2) A predicate statement can be True for no values of the variables. Logicians call this a universal negative. An instance of a universally False predicate statement is
"For all natural numbers is the sum of the first n natural numbers is not equal to 7." This predicate statement can be represented by the Euler diagram U S P which shows no element s S is a member of P = {7} and vice versa. A univerally negative statement can be written as (s)(s S s P)
which states if s is the sum of natural numbers (starting at 0 and stopping at some finite value n) then s is not equal to 7. cse 1400 applied discrete mathematics predicates 3 A predicate statement can be True for at least one list of values for the variables. Logicians call this a particular affirmative. An instance of predicate statement that is True for some values of the variable is
"The sum of the first n natural numbers is 10." This predicate statement can be represented by the Euler diagram U P S which shows there is a nonempty intersection between S and P = {10}. A particular affirmative statement can be written as (s)(s S s P)
which states there is an element s that is in the intersection of S and P (the intersection is not empty). A predicate statement can be False for at least one list of values for the variables. Logicians call this a particular negative. An instance of predicate statement that is False for some values of the variable is
"The sum of the first n natural numbers is not odd" This predicate statement can be represented by the Euler diagram U P S A particular negative statement can be written as which shows there is at least one element in S that is not in P = {0, 2, 4, . . .}. (s)(s S s P)
which states there is an element s that is in S and not in P. cse 1400 applied discrete mathematics predicates 4 In each of the above predicate statements grammarians call "The sum (of the first n natural numbers)" the subject and they call "n(n  1)/2", "7", "10", "not odd" the predicates. The following statements are instances of predicate statements. 1. The sum of the first n natural numbers is n(n  1)/2. This statement is True for all natural numbers n. 2. The sum of the first n powers of 2 is 2n  1. This statement is True for all natural numbers n. 3. The sum of the first n odd natural numbers is n squared. This statement is True for all natural numbers n. 4. The integer n times (n + 2) is an even number. This statement is True for some natural numbers n. 5. If n 10, then 2n < n3 . This statement is False for all natural numbers n 10. 6. If n is a positive integer and 0 < k < n, then there is an integer quotient q and an remainder r where 0 r < n and n = kq+r 7. n straight line cuts can divide a circle no more than 2n slices. 8. The real number x squared minus 1 is equal to 0. 9. The real number x is greater than real number y. 10. Given a set with n elements, there are n!/(k!(n  k)!) different subsets with k elements. Being lazy, mathematicians use shorthand notation for predicates. For instance, p (n) can stand for the predicate "The sum of the first n natural numbers is n(n  1)/2." and g ( x, y) can stand for the predicate "The real number x is greater than real number y." 1. A universally affirmative predicate p (n) (one that is True for all values of its variable(s)) can be written as 2. True for no values of its variable(s); that is, False for all values of its variable(s). 3. True for some values of its variable(s) 4. False for some values of its variable(s) cse 1400 applied discrete mathematics predicates 5 The phrases "for all" and "for some" are called quantifiers. Mathematicians use the symbol to stand for "for all." They use the symbol to stand for "for some." Predicate logic reasons over collections of things . This contrasts with Boolean logic, which reasons over a single instance. Predicate logic adds two quantifiers to propositional logic. The quantifiers are something and everything, as in some thing satisfies a property or every thing satisfies a property. For instance, you may say that there is a real number x that satisfies the equation x2  x  1 = 0 Or, you may say that every real number x satisfies the equation x+0 = x Mathematicians use standard symbols for these and similar phrases. There are, in fact, two solutions. The golden ratio = (1 5)/2 and its + conjugate = (1  5)/2. "There exists" "There is a least one" "For all" "For every"
Quantifiers modify a predicate, which is a statement about a thing . If the name of the thing is x and the name of the statement is p, then the predicate has the form p(x) Predicates arise in computing as Boolean expressions that control the flow of a program. Predicates state relations between functions, variables and constants. p ( x, y, a, b, c) = ( ax + by = c) p ( x, X, y, Y) = ( x X = y Y) p ( a, b, m, c) = ( a  b = mc) The symbol ! is used to say "there is one and only one," that is, the thing that exists is unique. Statements in predicate logic have forms such as All S are P No S are P Some S are P Some S are not P p ( x0 , x1 , f ) = (( x0 , x1 X x0 = x1 ) = f ( x0 ) = f ( x1 ))
Let a = 2, b = 3 and c = 7 in ax + by = c. Then 2 1 + 3 5 = 7 is False but 2 2 + 3 1 = 7 is True. In a given instance the predicate may be True or False. Describing the set of values where a predicate is True leads to useful definitions and theorems. Line The set of all points ( x, y) in the Cartesian coordinate plane that satisfy the equation ax + by = c for given realvalued constants a, b, and c. cse 1400 applied discrete mathematics predicates 6 Congruence mod m a b mod m if there exists an integer c such that a  b = mc Subset X Y if for all x X, it is the case that x Y. Onetoone function When every pair of distinct domain values map to distinct range values, the function f is onetoone. Here are two conjectures that appear to be True, but no one has discovered a proof or counterexample. Twin primes: There are infinitely many prime pairs ( p, p + 2) For instance twin prime pairs include (3, 5), (5, 7), (11, 13), and (17, 19).
In computing practice, the sets of things reasoned about in predicate statements belong to some type. athletes mammals natural numbers green things logicians rock bands functions on the integers permutations floating point numbers (n N)( p P)(( p > n) ( p, p + 2 P))
Goldbach: Every even integer greater than 2 can be written as the sum of two primes. For instance, 4 = 2 + 2, 6 = 3 + 3, 8 = 5 + 3, and 10 = 5 + 5. (n N)[(n > 2) (n mod 2 = 0) = ( p P)(q P)( p, q P n = p + q)] 1.1 Predicate Logic Inference Rules There are four basic rules to reason about quantified statements. Universal Instantiation If ( x U)( p ( x )) is True then (c U)( p (c)) is True Universal Generalization If p (c) is True for an arbitrary c U, then ( x U)( p ( x )) is True
The fact that the square of every integer is greater than or equal to 0 implies 42 0. The fact that the square of an even integer is divisible by four implies (2n N)(n N)(4 div n2 ). Existential Instantiation If ( x U)( p ( x )) is True, then p (c) is True for some instance c Existential Generalization If p (c) is True, then ( x U)( p ( x )) is
True 1.2 Negation of Quantified Predicate Statements If something is not always True , there is an instance where it is False . If there is not an instance when something True, then the something is always False. [( x X)( p ( x ))] ( x X)( p ( x )) [( x X)( p ( x ))] ( x X)( p ( x )) cse 1400 applied discrete mathematics predicates 7 1.3 Reasoning about Quantification Order
When is it the case that the order of and can be swapped? Consider the three cases 1. ( x X)(y Y)( p ( x, y)) (y Y)( x X)( p ( x, y)) 2. ( x X)(y Y)( p ( x, y)) (y Y)( x X)( p ( x, y)) 3. ( x X)(y Y)( p ( x, y)) (y Y)( x X)( p ( x, y)) In the first two questioned equivalences above, the repeated quantifiers are tied together using and. Therefore, pairs can be commuted and pair can be too. The third questioned equivalence is read "for all x there is a y such that p ( x, y) is True" is equivalent to "there is a y such that for every x p ( x, y) is True" Consider the True statement
For instance, "for every x and for every y p ( x, y) is True" is equivalent to "for every y and for every x p ( x, y) is True".
? ? ? ( x R)(y R)( x + y = 0)
and the False statement (y R)( x R)( x + y = 0) Consider the statement "All mathematicians love a logician." Does it mean "All mathematicians love Haskell Curry." a particular logician? Or does it mean "Every mathematician loves some logician." who may or may not be Haskell Curry? For a given x, let y =  x. No fixed real number y satisfies the equation x + y = 0 for every x. 1.4 Counterexamples
This instance is called a counterexample. You can prove a universally quantified statement is False by showing one instance when it is False. For instance, consider the statement that for every real number x and for every real number y, the algebraic equation x 2  y = x + y2 is True. One counterexample happens for x = y = 1, where the lefthand side of the equation is 0 and the righthand side is 2. ( x R)(y R)( x2  y = x + y2 ) 1.5 Satisfiable and Valid Predicates Definition 1 (Satisfiable). A predicate expression p is satisfiable if there is model in which p is True. Definition 2 (Valid). A predicate expression p is valid if p is True for all models Definition 3 (Boolean Validity). A predicate expression p whose Boolean form is valid (a tautology) is valid. cse 1400 applied discrete mathematics predicates 8 1.6 Consistent, Complete, and Decidable Models
Valid, If p is a theorem, then it is valid Definition 4 (Complete). A Boolean expression p is valid if p is true for all assignments. 2 Problems on Predicate Logic 1. The weak can never forgive (Ghandi) 2. The predicate statements below come from (?). (a) No Frenchmen like plumpudding. (b) All Englishmen like plumpudding. (c) Some thin persons are not cheerful. (d) All pigs are fat. (e) Some lessons are difficult. (f) All clever people are popular. (g) Some healthy people are fat. For each statement, identify the subject and predicate and write the statement using quantifiers ( and ) and logical operators ( , , , and ) (a) (n N)(n2 > 0) (c) (n N)(n2 0) 3. Which of the statements below are True and which are False? (b) (n N)(n2 > 0) (d) (n N)(n2 0) 4. Let p ( x ) be the statement x2 = x + 1. What is the truth value of the following statements. (a) p (0) (b) p ((1 + (d) ( x )( p ( x )) 5)/2) (e) ( x )( p ( x )) (f) ( x )( p ( x )) (c) ( x )( p ( x )) 5. This question is from (?). Let canfool ( p, t) be the proposition "You can fool person p at time t." Write Abraham Lincoln's famous quotation
You can fool some of the people all of the time, and all of the people some of the time, but you cannot fool all of the people all of the time. using the quantifiers over people p and times t and the canfool ( p, t) predicate. CSE 1400 Applied Discrete Mathematics Relations
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2 3
3.1 3.2 3.3 3.4 3.5 3.6 Relations and Their Graphs A Sampling of Relations
Equality Less than Divides 4 5 6 4 4 2 2 4 A Relation's Domain, Codomain, and Range Congruence Modulo n Perpendicular on Lines The Incestuous and Empty Relations 6 4 5 6 7
7.1 7.2 7.3 7.4 A Relation is a Set of Ordered Pairs The Inverse Relation Counting Relations Relational Properties
Reflexive Property Symmetric Property Antisymmetric Property Transitive Property 11 6 7 7 8
8 9 10 8
8.1 8.2 8.3 8.4 8.5 Orders and Equivalences
Orders 12 13 14 WellOrdered Sets Equivalences 12 Equivalence Relations Partition a Set Stirling Numbers of the Second Kind 15 17 cse 1400 applied discrete mathematics relations 2 9 Problems on Relations 17
Abstract A relation describes how things are connected. That a thing a is related to a thing b can be represented by 1. An ordered pair ( a, b). 2. An directed edge a A relation is b . 3. Or more commonly, simply using relational notation a b. 1. A set G of ordered pairs. 2. A directed graph G of nodes and edges. 3. A matrix of True and False values. Higherdimensional relations among a, b, c or more parameters can be defined. Higherdimensional relations occur as tables in relational databases and as data in multivariable problems. 1 Relations and Their Graphs
A relation can be pictured of as a graph G. g h d c A relation is a set of ordered pairs. G = {( x, y) : x y} = {( x, y) : x is related to y.} There are many examples of relations. You are, no doubt, familiar with relations among people: MotherDaughter, FatherSon, ParentChild, AuntNephew. Familial relations often become murky. We study relations that can be precisely defined. A few common relations are equality, congruence mod n, less than, divides, subset, and perpendicular. In this course, relationships will be between two things a and b. Relationships among 3 or more things are common and useful, but these ideas are not within the scope of this course. e a b f
This graph represents the relation G = {( a, b), (b, c), (c, d), (d, h), (h, f ), ( f , e), (e, a)} The course studies binary relations. 2 A Relation's Domain, Codomain, and Range The things involved in a relation need names: Call them the things x and y. Write xy to express the phrase "x is related to y." cse 1400 applied discrete mathematics relations 3 The value x belongs to a set X called the domain of . The value y belongs to a set Y called the codomain of . The domain X is the set of elements that appear on the lefthand side of . For this course, you can assume that every element in X appears on the lefthand side of , that is, every relation we encounter is total, defined on all members of X. The codomain Y is the set of elements that can appear on the righthand side of . A potentially smaller set is the range of . The range is the set of elements in Y that actually do appear on the righthand side of . In general, not every element y in Y occurs on the righthand side of . A relation is into its codomain and onto its range. That is, the codomain of a relation, is the set of values y that could be related to some x. When a relation is onto its codomain every element in Y is related to some element x in X, written (y Y)( x X)( x y) A relation maps an element x in the domain X onto zero or more elements y in the range A Y. Consider the graph in figure 1 that depicts a relation from vertices x0 , x1 , x2 , x3 in domain X to vertices y0 , y1 , y2 , y3 in codomain Y X x3 x2 x1 x0 Y y3 y2 y1 y0 A relation is said to be total when every x X occurs on on the lefthand side of for some y Y. ( x X)(y Y)( x y) If there is an x X such that no y Y is related to x, then is said to be partial. ( x X)(y Y)( x y)
An instance of a partial relation on the real numbers is the pairing ( x, 1/x ), which is undefined (has a pole) at x = 0. A relation maps its domain into its codomain and onto its range. Figure 1: Domain X = { x0 , x1 , x2 , x3 }, CoDomain Y = {y0 , y1 , y2 , y3 }, Range A = {y0 , y1 , y3 }, Here are some things to notice about figure 1. 1. The relation is total: there is at least one directed edge from each vertex in X. 2. The relation is not onto its codomain. 3. The relation is nondeterministic: A given input x can be related to many outputs y. For instance, in figure 1 x0 is related to y0 and y1 . A relation is partial when a given input x cannot be related to any output y. cse 1400 applied discrete mathematics relations 4
Figure 2: A partial relation: The relation is not defined on x1 . X x3 x2 x1 x0 Y y3 y2 y1 y0 3 A Sampling of Relations You are familiar with many mathematical relations: Equality, less than, multiple of, and so on. These relations are between two things : a and b, and are called binary relations. Multidimensional relations are common in practice. 3.1 Equality
Equality is the most basic relation. 5= 25 10 72 = = 72 5 2 5 The name (5, 25/5, . . .) can change, the thing remains the same. equal :: Integer > Integer > Bool equal a b = (0 == b  a) 3.2 Less than
Less than establishes an order on the integers. Figure 3: Haskell for deciding equality on the integers.
lessthan :: Integer > Integer > Bool lessthan a b = (0 < b  a) < 3 < 2 < 1 < 0 < 1 < 2 < 3 Figure 4: Haskell for deciding less than on the integers. 3.3 Divides
7 divides 35. "b divides a" is written A natural number b divides a natural number a when there is an quotient q N such a = bq. Divides is a relation on N N. For instance, 15 divides 60 because 60 = 15 4 Stated the other way around, 60 is a multiple of 15. On the other hand, 60 is not a multiple of 8; 8 does not divide 60. 60 divided by 8 leaves a remainder of 4. In general, let a and b be natural numbers. Then b divides a, if there is a natural number q such that a = bq. ba "b does not divide a" is written b a "a is a multiple of b" is written a0 a0 mod b "a is not a multiple of b" is written mod b If b divides a, then a is a multiple of b. cse 1400 applied discrete mathematics relations 5 The natural numbers can be partially ordered by the divides relation. The Hesse graph in figure 5 illustrates this ordering for the first few natural numbers. Given natural numbers a and b, it is straightforward to write code to test if a divides b.
7 3 1 2 5 11 Figure 5: 1 is the smallest natural number with respect to divides; 1 divides every natural number. 0 is the largest natural number with respect to divides; every natural number divides 0. 6 4 10 9 8 0 3.4 Congruence Modulo n
Congruence mod n has applications in many areas, cryptology is just one interesting application that can be named. When natural number n divides the difference a  b, the integers a and b are said to be congruent mod n. For instance, the following pairs are congruent mod 2. (15, 9), (26, 30), (9, 21), (6, 28), (6, 27), (17, 17) (17, 16) while the following pairs are congruent mod 3. divides :: Nat > Nat > Bool divides a b = (a 'div' b == 0) (15, 9), (26, 29), (8, 19), Congruence collects pairs of integers based on their remainder when divided by n. Mod 2 collects pairs ( a, b) that are both even (2s, 2t) or both odd (2s + 1, 2t + 1). Congruence mod 2 partitions the integers into two equivalence classes: The even integers and the odd integers. Mod 3 collects pairs ( a, b) based on remainders upon division by 3. There are 3 cases. 1. Both a and b are multiples of three: (3s, 3t) 2. Both have a remainder of 1 when divided by three: (3s + 1, 3t + 1) 3. Both have a remainder of 2 when divided by three: (3s + 2, 3t + 2) Congruence mod 3 partitions the integers into three equivalence classes: Integers that are multiples of 3, integers that are multiples of 3 plus 1, and integers that are multiples of 3 plus 2. In general, two integers a and b are congruent mod n if a  b is a multiple of n. Congruence mod n partitions the integers into n equivalence classes. A convenient notation for these sets of integers is [0], [1], [2], . . . , [ n  1] Figure 6: Haskell for deciding divides on the natural numbers. n is called the modulus. If both a and b are even, then their difference is divisible by 2. If both a and b are odd, then their difference is divisible by 2. where For instance, mod 7, the set [3] is [r ] = {nk + r : k Z} syntatic sugar can be added to denote the modulus: [r ]n . [3] = {7s + 3 : s Z} = {3, 7 + 3, 14 + 3, . . .} cse 1400 applied discrete mathematics relations 6 while mod 11, the set [3] is [3] = {11s + 3 : s Z} = {3, 11 + 3, 22 + 3, . . .} 3.5 Perpendicular on Lines
Two lines are perpendicular if they intersect at right angles. Recall a straight line can be written as a function l ( x ) = mx + b = y where l is the name of the function, the line, m is its slope, and b is its yintercept, and x is an independent variable. Ordered pair ( x, y) that satisfy the equation are related by lying on the line l. A straight line can be named by the ordered pair (m, b) of its slope and y intercept. Using analytic geometry it is simple to prove that two lines (m0 , b0 ) and (m1 , b1 ) are perpendicular when the product of their slopes is negative one m0 m1 = 1 In which case we can write When x takes on the values in the natural numbers, the linear function generates an arithmetic sequence. y y = 2x  1 x y = 1x 1 2 . (m0 , b0 ) (m1 , b1 ). 3.6 The Incestuous and Empty Relations
The incestuous relation is where each element is related to every other element. A table of all 1's represents the incestuous relation. On the other hand, a table of all 0's represents the empty relation where no thing is related to any thing . The empty relation, being a set, is the empty set .
Incestuous Relation a b c d e a b c d e 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 A Relation is a Set of Ordered Pairs A relation between X and Y is a subset of the Cartesian product X Y = {( x, y) : x X Y} As instances consider the relations. The = relation on the natural numbers the set of ordered pairs
A relation is a set of ordered pairs. {(0, 0), (1, 1), (2, 2), . . .} = {(n, n) : n N} cse 1400 applied discrete mathematics relations 7 The less than relation (<) on the natural numbers the set of ordered pairs {(0, 1), (0, 2), (1, 2), (0, 3), (1, 3), (2, 3), . . .} = {(n, m) N N : n < m}
The divides relation () on the natural numbers the set of ordered pairs {(0, 0), (1, 0), (1, 1), (1, 2), (2, 0), (2, 2), (1, 3), (3, 0), (3, 3), . . .} = {(n, m) N N : n  m}
Representing relations as ordered pair facilitate counting relations and relations with given properties. For instance, there are 2nm relations from X to Y when X = n and Y = m.
There are nm elements (ordered pairs) in X Y. A set with nm elements has 2nm subsets 5 The Inverse Relation The inverse of a relation changes the order of a pair of related things . Let L be a relation from X to Y. Write x y when x is related to y, that is, when ( x, y) L. Then the inverse of L is the set L = {( x, y) : x X y Y x y} L1 = {(y, x ) : x X y Y x y}
For instance, the inverse of the relation < is the relation > and the inverse of divides is multiple of. 6 Counting Relations How many relations can be defined from X to Y? The answer depends on the sizes, the cardinalities, of the two sets. Pretend these sets have cardinality n =  X  and m =  Y  . As a first step it is important to be clear about what we are to count. By definition, a relation from X to Y is a subset of the Cartesian product X Y. Answering the question reduces to counting subsets. The cardinality of the Cartesian product is is the count of ordered pairs ( x, y ) where x X and y Y. This count is Every subset of X Y is a relation; every relation is a subset of X Y. There are 2 nm subsets of an nmelement set.  X Y  =  X   Y  = nm Theorem 1 (Counting Relations). Let the cardinalities of set X and Y by X = n and Y = m. There are 2nm relations from X to Y. In particular, 2 there are 2n relations on X. Recall there are (nm) kelement subsets k of a set with nmelements. The sum of nm ( k ) as k ranges from 0 to nm counts the number of subsets of X Y. Recall from the binomial theorem that the sum of binomial coefficients in row nm of Pascal's triangle is 2nm . cse 1400 applied discrete mathematics relations 8 7 Relational Properties There are properties of relations that allow things to be sorted or decide that two things are equivalent. A relation can have several properties. A relation could be reflexive, symmetric, antisymmetric, or transitive. 7.1 Reflexive Property
If every element a A is related to itself, then the relation is reflexive on A. ( a A)( a a)
The following relations are reflexive. 1. Equality on the integers. Proof: a = a for all a Z. 2. Congruence mod n on the integers. Proof: For all a Z, a  a = 0 is a multiple of n. Therefore a a mod n for all integers a. 3. Divides on the natural numbers. Proof: For all n N, n = n 1. Therefore n  n for all natural numbers n. The next list of relations are not reflexive. 1. Not equal on the set of natural numbers. Counterexample: 0 = 0 is false. 2. Less than on the integers. Counterexample: 0 < 0 is false. 3. Perpendicular on the set of lines. Counterexample: The line x  y = 0 is not perpendicular to itself. When a relation is represented as a table you can see if it is reflexive or not. When the main diagonal, from upperleft to lowerright, contains only 1's the table states each element is related to itself. That is, the relation is reflexive. Tables also provide a convenient tool to count reflexive relations on a set A. To be reflexive, the values on the main diagonal must be 1, but the offdiagonal values can either 0 or 1. Therefore, there are 2(count of offdiagonal elements) reflexive relations on a set. That is, there are 2n ( n 1)
draw a "selfloop" It is common not to draw selfloops for a reflexive relation; they clutter the graph. The exceptions are finite state machines where selfloops show a transition from a state directly back to itself. To show that a node is related to itself, A Reflexive Relation a b c d e a b c d e 1 0 0 1 1 1 1 1 1 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 cse 1400 applied discrete mathematics relations 9 reflexive relations on a set with cardinality n. The problem of counting reflexive relations reduces to counting offdiagonal elements in an n n table. Pretend the cardinality of A is A = n. Then there are n2 elements in the table and n of them lie along the main diagonal. Therefore, there are n2  n offdiagonal elements. You can also count the number of offdiagonal elements directly. For instance, count there are 1, 2, 3 up to n  1 elements along diagonals in the lower triangle of the table. The sum of natural numbers from 0 to n  1 is a triangular number.
0 k < n n2  n = n ( n  1) k = 0 + 1 + 2 + + ( n  1) = n ( n  1) 2 Double this count to include the offdiagonal elements above that main diagonal too. Conclude that there are n(n  1) offdiagonal elements. Knowing the number of offdiagonal elements, compute that there are 2n(n1) reflexive relations on an nelement set. 7.2 Symmetric Property
A relation is symmetric if it is its own inverse. When a is related to b, b must also be related to a.
The graph of a symmetric relation is undirected. The edge between related nodes x and y does not need arrowhead. a b ( a A)(b A)(( a b) (b a))
The following relations are symmetric. 1. Equality on the integers. proof: If a = b, then b = a for all a, b Z. 2. Inequality on the integers. proof: If a = b, then b = a for all a, b Z. 3. Congruence mod n on the integers. proof: If n divides a  b, then n divides b  a. 4. Parallel on the set of lines in the two dimensional Cartesian plane. proof: If l is parallel to l, then l is parallel to l. 5. Perpendicular on the set of lines in the two dimensional Cartesian plane. proof: If l is perpendicular to , then is perpendicular to l. The next list of relations are not symmetric. 1. Less than on the integers. counterexample: 2 is less than 3, but 3 is not less than 2. A precisionist might draw arrowheads a b at both ends. Symmetry is fundamental to defining equivalent (not equal) things . cse 1400 applied discrete mathematics relations 10 2. Divides on the natural numbers. counterexample: 2 divides 4, yet 4 does not divide 2. 3. Subset on the power set of a set. counterexample: {0} is a subset of B = {0, 1}, but {0, 1} is not a subset of {0}. When a relation is represented as a table you can to see if it is symmetric or not. Symmetry is a property between elements in the upper and lower triangle of a matrix. When the matrix is folded along the diagonal, the values in the upper and lower triangle align. The value in row i, column j equals the value in row j, column i. When 1 is in row i, column j, then 1 is in the symmetric location: row j, column i. When 0 is in row i, column j, then 0 is in the symmetric location: row j, column i. Tables also provide a convenient tool to count symmetric relations on a set A. To compute this count consider the number of main diagonal and offdiagonal elements in the table. To be symmetric, the values on the main diagonal can be either 0 or 1. However, offdiagonal values are constrained by the rule:
The value in row i, column j matches the value in row j, column i. A Symmetric Relation a b c d e a b c d e 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 That is, choosing a value for a lower triangular element determines the value for its symmetric upper triangular element. Since the triangular number n(n  1)/2 counts the elements in the lower triangle, there are 2n(n1)/2 ways to set the offdiagonal elements in a symmetric table. Therefore, there are 2(count of main diagonal elements) 2(count of offdiagonal elements)/2 symmetric relations on a set with cardinality n. That is, there are 2n 2n(n1)/2 = 2n(n+1)/2 = 2n ( n +1) Notice when you fold the matrix along its main diagonal the values align. Counts of reflexive reflexive relations was computed in a similar manner above. There are 2n different ways to set the value of elements on the main diagonal. symmetric relations on a set with cardinality n. 7.3 Antisymmetric Property
A relation is antisymmetric when a is related to b and b is related to a only if a and b are equal. Antisymmetry is fundamental deciding how to order things . cse 1400 applied discrete mathematics relations 11 ( a)(b)(( a b b a) ( a = b)) ( a)(b)(( a b b a) ( a = b))
The following relations are antisymmetric. 1. Equality on the integers. proof: For all a, b Z, "if a = b and b = a, then a = b" is True. 2. Less than on the integers. proof: For all a, b Z, "if a < b and b < a, then a = b" is True. 3. Divides from the natural numbers to the integers. proof: if a divides b and b divides a, then, by the domain definition for divides, both a and b are natural numbers. Also there are natural numbers c and d such that ac = b and bd = a. Therefore acd = bd = a, cd = 1, and c = d = 1. 4. Subset on the power set of a set. The next list of relations are not antisymmetric. 1. Inequality on the integers. counterexample: "if 0 = 1 and 1 = 0, then 0 = 1." is False. 2. Congruence mod n on the integers. 3. Parallel on the set of lines. 4. Perpendicular on the set of lines. When a relation is represented as a table you can see if it is antisymmetric or not. When 1 occurs in row i, column j, then a 0 must appear in the symmetric location: row j, column i.
a b c d e An Antisymmetric Relation a b c d e 1 0 0 1 0 1 1 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 0 1 Use the logical equivalence ( p q ) ( p q ) and one of DeMorgan's laws to write antisymmetry as a disjunction. That equality is both symmetric and antisymmetric shows antisymmetry is not the same as not symmetric. Notice when you fold the matrix along its main diagonal the offdiagonal 1's align with 0's. 7.4 Transitive Property
A relation is transitive when a is related to b and b is related to c implies a is related to c. The following relations are transitive. 1. Equality on the integers. proof: For all a, b Z, "if a = b and b = a, then a = b" is True. 2. Less than on the integers. proof: For all a, b Z, "if a < b and b < a, then a = b" is True. 3. Congruence mod n on the integers. Transitivity is key to keeping relations consistent. cse 1400 applied discrete mathematics relations 12 4. Divides from the natural numbers to the integers. proof: if a divides b and b divides a, then, by the domain definition for divides, both a and b are natural numbers. Also there are natural numbers c and d such that ac = b and bd = a. Therefore acd = bd = a, cd = 1, and c = d = 1. 5. Subset on the power set of a set. 6. Parallel on the set of lines. The next list of relations are not transitive. 1. Inequality on the integers. counterexample: "if 0 = 1 and 1 = 0, then 0 = 0." is False. 2. Perpendicular on the set of lines. 3. Before in three dimensional space. Consider a pinwheel an Escher drawing(?) 8 Orders and Equivalences Two important classes of relations are orders and equivalences. Orders describe how one thing is before or after another. Equivalences allow grouping of things based on common attributes. 8.1 Orders
An order relation establishes a precedence between thing s: You can decide if one thing is before or after another thing . Total orders allow before or after comparison between every pair of thing s. For instance, on the integers is a total order. An order is partials when only some pairs of thing s can be placed in a precedence graph. For instance, the subset relation on the power set of a set is a partial order. A partial order is a relation that is reflexive, antisymmetric, and transitive. The antisymmetric is The following relations are partial orders. 1. Equality on the integers: a = b for a, b Z. 2. Less than or equal on the integers: a b for a, b Z. 3. Divides on the natural numbers: a  b for a, b N. 4. Subset on the power set 2A of a set A: X Y for X, Y A. {0} {0, 1} {1} Figure 7: The subset precedence graph on the power set of {0, 1}. The subsets {0} and {1} are not related. cse 1400 applied discrete mathematics relations 13 The following relations are not partial orders. 1. Inequality on the integers. (a) Inequality is not reflexive: a = a is False for every integer a Z. (b) Inequality is not antisymmetric: if a = b and b = a, then a = b is False. (c) Inequality is not transitive: if a = b and b = c, then a = c can be False. In particular, transitivity fails when a = c. 2. Congruence mod n on the integers (a) Congruence mod n is not antisymmetric. A counterexample to the statement congruence mod n is antisymmetric is 2 0 mod 2 but 2 = 0. The integers mod n can be strictly ordered by the inherited less than relation on the integers: 0 < 1 < 2 < (n  1). However, this is not the congruence mod n relation. 3. Parallel on the set of lines in two dimensions. Consider the general case. That is, when integers a and b have the identical remainders when divided by n, they are congruence, but not necessarily equal. That is, when integers a = nc + r and b = nd + r, and c = d, then a b mod n and b a mod n, but a = b (a) Parallel is not antisymmetric: Two lines can be parallel without being equal. 4. Perpendicular on the set of lines: Two lines can be perpendicular without being equal. The natural order on an alphabet can be extended to strings over the alphabet. Definition 1 (Alphabetic Order). 1. The empty string precedes every string s. 2. If s and t are strings of length 1 or greater, then s = u and t = v for some characters , A and True if < st=
For instance, the English alphabet is naturally ordered a < b < c < < x < y < z 8.2 WellOrdered Sets True False otherwise if = and u v A set is wellordered when every nonempty subset has a least element. A useful theorem is that any nonempty subset A of natural numbers has a least element under the standard relation. cse 1400 applied discrete mathematics relations 14 Theorem 2 (WellOrdering). Let A be a nonempty subset of the natural numbers. There exists an element a A such that a b for all b A. This element a is called the least element of A. Writing the statement in predicate form yields ( aA)(b A)( a b)
which helps to show the absurdity of its negation. ( a A)(b A)( a b) = ( a A)(b A)(b > a)
The wellordering principle for the natural numbers is equivalent to Peano's axiom of induction. 8.3 Equivalences
An Equivalence relation partitions a set into a collection of disjoint subsets called equivalence classes. The adjacency matrix for congruence mod 3 on the digits is shown below. The equivalence classes can be better seen if you permute the rows and columns. Congruence mod 3 on the digits 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1
7 For instance, congruence mod 3 partitions the digits into 3 equivalence classes. 9 1 4 0 6 8 3 2 5 cse 1400 applied discrete mathematics relations 15
Figure 8: Describing an equivalence relation on {0}. Relation 00 Pair Graph 0 Matrix 0 0 1 Partition {(0, 0)} {{0}} Congruence mod 3 on the digits 0 3 6 9 1 4 7 2 5 8 0 3 6 9 1 4 7 2 5 8 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 That is, two homogeneous points ( x, y) and (u, v) are equivalent if they lie on the same ray through the origin. The standard name for a homogeneous point is the one lying on the unit circle x2 + y2 = 1. Homogeneous coordinates establish an equivalence relation on the punctured plane R  {(0, 0)}. Computer graphics depends on homogeneous coordinates. In twodimensions, the homogeneous coordinates ( x, y) and (u, v) are equivalent if xv  uy = 0
v y/x = v/u xv  uy = 0 y x u 8.4 Equivalence Relations Partition a Set
For small sets each equivalence relation can be listed. Let A be a set with cardinality A = n. There are many notations for describing a relation: Itself, a set of ordered pairs, a graph 1 , or a matrix 1. When A = {0} and n = 1 there is one equivalence relation. It is described in figure 8. 2. When A = {0, 1} and n = 2 there are two different equivalence relations that can be defined. They are described in figure 9. 3. When A = {0, 1, 2} and n = 3 there are 5 different equivalence relations that can be defined. Many of the notations are cumbersome. Listing partitions of the set seems less cumbersome. In the Homogeneous coordinates project point onto the unit circle. Do you see why the origin was left out? It is convenient to define the as an equivalence relation on itself, so there is 1. Otherwise, the relation is not an equivalence relation on any other set.
1 Selfloops are not drawn. cse 1400 applied discrete mathematics relations 16 diagram below partitions of A are listed based on the number of subsets in the partition: 1, 2, or 3. Partitions {{0, 1, 2}} {{0} , {1, 2}} {{1} , {0, 2}} {{2} , {0, 1}} {{0} , {1} , {2}} 4. When A = {0, 1, 2, 3} and n = 4 there are 15 different equivalence relations that can be defined. Partitions {{0, 1, 2, 3}} {{3} , {0, 1, 2}} {{0} , {1, 2, 3}} {{1} , {0, 2, 3}} {{2} , {0, 1, 3}} {{0, 3} , {1, 2}} {{1, 3} , {0, 2}} {{2, 3} , {0, 1}} {{0} , {1, 2} , {3}} {{1} , {0, 2} , {3}} {{2} , {0, 1} , {3}} {{0} , {1} , {2, 3}} {{0} , {1, 3} , {2}} {{0, 3} , {1} , {2}} {{0} , {1} , {2} , {3}} If you study the partitions, you'll find an algorithm that computes the number of partitions with a given number of subsets. Consider the seven 2subset partitions of {0, 1, 2, 3}. They were constructed from the 1subset and 2subset partitions of {0, 1, 2}. 1. The union of {{3}} with the 1subset partition {{0, 1, 2}} formed a 2subset partition {{0, 1, 2} , {3}} of {0, 1, 2, 3}. 2. The union of {3} with each of the two sets in the three 2subset partition of {0, 1, 2} formed six more 2subset partitions of {0, 1, 2, 3}. This construction is general.
For instance, the six 3subset partitions of {0, 1, 2, 3}, were constructed from the 2subset and 3subset partitions of {0, 1, 2}. cse 1400 applied discrete mathematics relations 17 8.5 Stirling Numbers of the Second Kind
A set with cardinality n can be partitioned into m subsets n in { m } ways. Stirling numbers of the second kind are defined by the recurrence equation n m Check that the following arithmetic can be verified by the numbers in table 1. 4 3 5 3 7 5 = n1 n1 +m m1 m n n = = = 3 3 +3 2 3 4 4 +3 2 3 6 6 +5 4 5 = 3+31 = 7+36 = 65 + 5 15 with boundary conditions 0 0 = 1, n 0 = 0 and = 1, for n > 0
n The notation {m} is called n subset m. Table 1: Stirling numbers of the secn ond kind {m} count the number of partitions of n things into m subsets.
n Stirling Numbers of the Second Kind {m} Subset m 0 1 2 3 4 5 6 7 8 0 1 2 3 n 4 5 6 7 8 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 3 1 7 6 15 25 31 90 63 301 127 966 0 0 0 0 1 10 65 350 1701 0 0 0 0 0 1 15 140 1050 0 0 0 0 0 0 1 21 266 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 28 1 9 Problems on Relations 1. Describe the relation p q = True over the set of Boolean variables p, q B when is each of the Boolean operators , , , . 2. How many relations can be defined on the following sets? (a) The sets of bits B = {0, 1}. (c) From the bits to the digits. (b) The sets of digits D = {0, 1, . . . , 9}. (d) From Bn , the bit strings of length n, to the bits B. cse 1400 applied discrete mathematics relations 18 3. A relation on an nelement set A can be represented by an n n adjacency matrix. Given that there are 2(count of offdiagonal elements) reflexive relations on a set, how many reflexive relations are there for n = 0, 1, 2, 3 and 4? 4. Given that there are f (n) = 2n 2n(n1)/2 = 2n(n+1)/2 = 2n ( n +1) symmetric relations on a set with cardinality n. Compute the value of f (n) for n = 0, 1, 2, 3 and 4. 5. Describe what must be true for two lines, written as slopeintercept pairs (m0 , b0 ) and (m1 , b1 ), to be perpendicular. Use the notation The line (m, b) is described by the equation y = mx + b. (m0 , b0 ) (m1 , b1 ) to denote the perpendicular relationship between two lines. 6. Describe what must be true for two lines, written in standard form ( a0 , b0 , c0 ) and ( a1 , b1 , c1 ), to be perpendicular. Use the notation The line ( a, b, c) is described by the equation ax + by = c. ( a0 , b0 , c0 ) ( a1 , b1 , c1 ) to denote the perpendicular relationship between two lines. 7. Describe what must be true for two lines, written as slopeintercept pairs (m0 , b0 ) and (m1 , b1 ), to be parallel. Use the notation (m0 , b0 ) (m1 , b1 ) to denote the parallel relationship between two lines. 8. Interpret the following ordered pairs as slopeintercept descriptions of lines. Which pairs are perpendicular? Which pairs are parallel? (a) (1, 2) and (1, 3). (b) (3, 2) and (3, 3). (c) (0.5, 2) and (2, 3). (d) (3, 2) and (4, 3). 9. For each relation, determine if it is reflexive, symmetric, antisymmetric, or transitive. (a) Equality on the natural numbers, written a = b. (b) Divides on the natural numbers, written a  b. (c) Subset on the power set 2A of A, written X Y for subsets X and Y of A. (d) Congruence mod m on the integers, written a b mod m. (e) x y if x  y = 9. (f) x y if  x  y is prime. 10. Let r = ( a, b) and s = (c, d) be ordered pairs of integers. (You could think of r and s as rational numbers.) If the crossproduct ad and cb are equal say r is equivalent to s and write r s. (a) Give instances of r = ( a, b) and s = (c, d) that are equivalent. (b) Give instances of r = ( a, b) and s = (c, d) that are not equivalent. (c) What pairs are equivalent to the pair (1, 1)? (d) Is is r s reflexive? Explain. (e) Is r s symmetric? Explain. (f) Is r s transitive? Explain. cse 1400 applied discrete mathematics relations 19 (g) Is r s an equivalence relation? Explain. (h) How does this relation describe equivalent names for rational number fractions? (i) How does this relation describe a geometric relationship between points in a twodimensional space? 11. Let a, b, c, d be integers and say the ordered pair ( a, b) related to (c, d) if a + d = b + c. ( a, b) (c, d) if a + d = b + c
(b) Is symmetric? Explain. (d) Is an equivalence relation? Explain. (c) Is transitive? Explain. (a) Is reflexive? Explain. 12. Say that two floating point numbers x and y are approximately equal if the differ by 3.125 102 . x y if and only if  x  y (a) Is approximately equal reflexive? Explain. (b) Is approximately equal symmetric? Explain. (c) Is approximately equal antisymmetric? Explain. (d) Is approximately equal transitive? Explain. (e) Is approximately equal an equivalence relation? Explain. (f) Is approximately equal a partial order? Explain. 13. On the set of real numbers R = { x :  < x < } define the relation S = {( x, y) : x, y R, and x  y is an integer} Show that S is an equivalence relation on R. = 1/32 = 14. Consider the childhood game "rock beats scissors, scissors beat paper, paper beats rock." (a) Construct the adjacency matrix that represents the "beats" relation. (b) Is "beats" reflexive, symmetric, antisymmetric, transitive? 15. Let R and S be sequences of natural numbers. Say that sequence R precedes S and write R S if ri si for all i = 0, 1, 2, . . . As an example, R = 0, 1, 2, 3, . . . precedes S = 1, 2, 4, 8, . . . because i 2i for all natural numbers i. (a) Show that precedes is a partial order. (b) Draw a graph showing the order of the 8 finite sequences 0, 0, 0 1, 0, 0 0, 0, 1 1, 0, 1 0, 1, 0 1, 1, 0 0, 1, 1 1, 1, 1 16. The U. S. Post Office can increase its efficiency by sorting letters based on width and height. Define a partial order on a set of ordered pairs (w, h) that describe the width and height of a letter. 17. The U. S. Post Office also ships packages that have a width, height, and depth. Define a partial order on ordered triples (w, h, d) to help the U.S.P.O. sort packages. 18. Negate the definition of "relation is reflexive:" ( x X)( x x )
to define "relation is not reflexive." cse 1400 applied discrete mathematics relations 20 19. Negate the definition of "relation is symmetric:" ( x X)(y X)(( x y) = (y x ))
to define "relation is not symmetric." cse 1400 applied discrete mathematics relations 21 Relations 0 0, 1 1 0 0, 0 1, 1 0, 1 1 Graphs Matrices 0 0 1 0 1 1 0 0 0 1 0 1 1 1 1 0 1 1 1 1 Pairs Figure 9: Describing two equivalence relations on {0, 1}. {(0, 0), (1, 1)} {(0, 0), (0, 1), (1, 0), (1, 1)}
Partitions {{0} , {1}} {{0, 1}} CSE 1400 Applied Discrete Mathematics Graphs
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 A Josephus Network 1
Abstract A graph G is an ordered pair (V, E) where V is a nonempty set of vertices or nodes, and E is a set of edges between nodes. V = { v 0 , v 1 , . . . , v n 1 } E ( vi , v j ) : vi , v j V 1 A Josephus Network A Josephus network is a directed graph with n > 0 nodes with the following structure. Node 0 is the source node and it has one directed edge to node m for some m n. Node m had one directed edge to node 2m mod n And, in general, node k had one directed edge to node j where j is m nodes away from k skipping over any already visited nodes. For instance, here is the Josephus network for n = 8 and m = 3. 0 7 6 5 4 And, here is the Josephus network for n = 8 and m = 4. 3 1 2 cse 1400 applied discrete mathematics graphs 2 0 7 6 5 4 The Josephus problem is to find the last node in the network. The Josephus sequence problem is compute the order of each node in the network. When n is prime, call it p. Here's some things that can be noticed about the Josephus problem. Theorem 1. For any m < p the sequence of steps through the network 0, m, 2m, . . . , ( p  1)m does not contain any duplicate values. Proof. If the sequence contained duplicate values, say km and jm mod p for some 0 k < j p  1, then km  jm = (k  j)m mod p
The last node in a network is usually called the "sink." 1 2 3 CSE 1400 Applied Discrete Mathematics Equivalences
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 Abstract Establishing equivalences is a common activity. When two things have a common property they can be called equivalent. Describe an equivalence among 0, 2, 4, and 6. Describe an equivalence among blue, red, green, tan. How are How are , , , , , equivalent? equivalent? Is every thing equivalent to itself? If one thing is equivalent to a second thing, is the second thing equivalent to the first? If one thing is equivalent to a second thing and the second thing is equivalent to a third, is the first thing equivalent to the third thing? Can you partition the animal kingdom by the way the move? Fish, penguins and people can swim. I'm going to say beetles cannot, but I am not certain that is true. Penguins and peole also walk on two legs. This type of information can be recorded in a table of True and False values. Method of Motion cse 1400 applied discrete mathematics equivalences 2 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 1 Do you see information in the matrix that tells you the "motion" relation is reflexive? Do you see information in the matrix that tells you the "motion" relation is symmetric? But, is "motion" is transitive? CSE 1400 Applied Discrete Mathematics Orders
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 Abstract Placing things in order is a common activity. Ordinal numbers: first, second, third, fourth, and so on are used to describe the order to discrete things. Smalltolarge or largetosmall are ways to compare things, placing them in order. Before and after are words used to describe the order of temporal events. Less than and greater than are also common phrases used to decribe the order of numbers. Place 2, 7, 1, 8 in order. Place blue, red, green, tan in order. Place Place , , , , , , in order. in order. Place {0, 1} , {1} , {0} , in order. Place , , in order. Comparisons are used to determine the order of things. Some words used to describe comparisons are: smaller, larger, before, after, less than, and greater than. The result of a comparison is a Boolean value: False or True. CSE 1400 Applied Discrete Mathematics Functions
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 Functions 1
2 3 3 4 4 4 Counting Functions Onto Functions Cardinality Defined Inverse Function Function Composition OnetoOne Functions 2 Problems on Functions 5
Abstract A function is a deterministic relation. 1 Functions
In college algebra and precalculus, you have studied functions such as y=x y = x2 y = log x y = ex y = cos x y = sin x In college algebra, the function concept is often explained by the vertical line test: "If every vertical line crosses a graph at most once, the graph represents a function." A given value x in the domain of a function maps to one and only one value y in the range of the function. Functions are denoted by writing f :XY where X is the domain and Y is the codomain of function f . The range G of f is the subset of Y for which there is an x X such that y = f ( x ). The range of f also called the image of X and written G = f (X) Y To write f is a function from X to Y in predicate logic requires the conjunction of two propositions. ( x X)(y Y)( f ( x ) = y) cse 1400 applied discrete mathematics functions 2 y 1 x = 1/2, y =
Figure 1: The vertical line x = 0.5 crosses the circle twice. The relation y = 1  x2 between x and y is not a function. 3/2 1 2 1 1 2
1 2 1 x 1 x = 1/2, y =  3/2 x2 + y2 = 1 is relation, but not a function. and ( x X)(y, z Y)(( f ( x ) = y f ( x ) = z) = y = z)
The first proposition states that every element x in the domain maps to some element y in the range: The function is total. The second predicate states that if x maps to two different names y and z, their values are, in fact, equal. There are several things worth knowing about functions. For instance, it is useful to know The number of different functions from X to Y that can be defined. Basic properties such as onto and onetoone. When a function can be inverted. How functions can be composed using the output of one function as the input to another. And, it is useful to have a collection of functions that occur frequently in computing applications. 1.1 Counting Functions
It is easy to construct a function. For every x in the domain, choose a single y in the codomain and include the pair ( x, y) in cse 1400 applied discrete mathematics functions 3 function. For instance, you can construct 32 functions from { a, b} to set {0, 1, 2}: For x = a choose y = 0, y = 1, or y = 2; For x = b choose y = 0, y = 1, or y = 2. Each of these 9 functions can be represented by one of the 9 sets below. {( a, 2), (b, 0)} {( a, 1), (b, 0)} {( a, 0), (b, 0)} {( a, 0), (b, 1)} {( a, 2), (b, 1)} {( a, 1), (b, 1)} {( a, 0), (b, 2)} {( a, 2), (b, 2)} {( a, 1), (b, 2)} Another example: if X = 6 and Y = 5, then 56 functions from X to Y can be defined. In general, if X = n and Y = m, there are m n =  Y  X functions from X to Y. For each of the six x's choose one of the five y's to map x to. That's 5 choices 6 times. 1.2 Onto Functions
A function f : X Y is onto when its codomain Y is its range. In college algebra, the concept of "onto function" is often explained by the horizontal line test: If every horizontal line crosses the graph of the function y = f ( x ), then f is onto. Another way to visualize the meaning of onto is to fill or not completely fill the codomain in the illustration of a function. f X Y X f Y f : X Y is onto when f (X) = Y. Otherwise, f is said to map X into Y. f : X Y is onto when (y Y)( x X)( f ( x ) = y)
0.5 y = x4 = x ( x  1)( x  2)( x  3) 0 0.5 1 0 0.5 1 1.5 x 2 2.5 3 f maps X onto Y f does not map X onto Y The falling power x4 is not onto R.
4 y = x5 = x ( x  1)( x  2)( x  3)( x  4) It is useful to note that when X has fewer elements than Y it is not possible to construct onto functions from X to Y. That is, if X < Y, then (( f : X Y))( f is not onto) 2 0 2 1.3 OnetoOne Functions
Function f is onetoone when no element y in its range is the image of more than domain element x. In college algebra, this concept is often explained by another horizontal line test: If every horizontal line crosses the graph of y = f ( x ) at most once 4 0 1 2 x 3 4 The falling power x5 is onto R. ( x0 , x1 X)(( x0 = x1 ) = f ( x0 ) = f ( x1 ) f : X Y is onetoone when cse 1400 applied discrete mathematics functions 4 then f is onetoone. If the cardinality of X is greater than that of Y, then no (total) onetoone function can exist. This is known as the pigeonhole principle. You can't put 10 pigeons in 9 pigeonholes. 4 y = x3 + x2 + x + 1 2 0 2 1 0.5
0 x 0.5 1 The geometric sum y = x3 + x2 + x + 1 is a onetoone function. 1.4 Cardinality Defined
The cardinalities of two sets X and Y are equal when there is a onetoone function f that maps X onto Y. In particular, X has cardinality n when its elements can be put onto a onetoone correspondence with Zn = {0, 1, . . . (n  1)}. 1.5 Inverse Function
A key to cryptology is to find a function f that is easy to compute and all but impossible to invert. The inverse of a relation {( a, b) : a b} is the set {(b, a) : a b}. When f is a function from X to Y, that is, when f = {( a, b) X Y : f ( a) = b} simply reversing the order of its pairs will define a relation between Y and X, but the resulting set may not be a function. That is, f 1 = {(b, a) : f ( a) = b} may not be a function from Y to X. If f is onetoone, then f 1 is a partial function. If f is onetoone and onto, then f 1 is a total function.
b may be the image of more that one value a X. Some b Y may not be the image of any value a X. 1.6 Function Composition
Complex functions can be constructed from simple functions. The diagram below illustrates composition of functions f :XY g:YZ cse 1400 applied discrete mathematics functions 5 and follows an element x mapped by f to y which g maps to z. y X x f Y g Z z The composition of f : X Y and g : Y Z is denoted g f , and ( g f )( x ) = g( f ( x )) 2 Problems on Functions
(a) The set X is the range of function f . 1. Let f : X Y be a function. Answer the following True or False. Explain your answer. (b) The set X is the domain of function f . (c) The set Y is the range of function f . (d) The set Y is the domain of function f . 2. Let A = { a, b, c} and B = {0, 1}. Which of the following are functions from A to B. (a) {( a, 0), (b, 1), (c, 0)} (b) {( a, 0), ( a, 1), (c, 0)} (d) {( a, 1), (b, 1), (c, 1)} (c) {( a, b), (b, a), ( a, c)} 3. Consider this algorithm for constructing a function f from X to Y.
For each element x X choose an element y Y and place the ordered pair ( x, y) in f . (a) If the cardinality of X is 5, how many times does the algorithm choose an x from X? (b) If the cardinality of Y is 9, how many choice of y are there for each x? (c) True or False: If the X = 5 and Y = 9, then there are 59 functions f from X to Y. Explain your answer. (d) True or False: If the X = 5 and Y = 9 then there are 45 functions f from X to Y. Explain your answer. (e) True or False: If the X = 5 and Y = 9 then there are 95 functions f from X to Y. Explain your answer. 4. Answer the following True or False. Explain your answer. (f) If X = n and Y = m how many functions f can be defined from X to Y? (a) The domain of a function of one Boolean variable is {0, 1}. (c) The codomain of a Boolean function is {0, 1}. (b) The domain of a function of two Boolean variables is {(0, 0), (0, 1), (1, 0), (1, 1)}. 5. How many Boolean functions B( p ) in one variable are there? 6. How many Boolean functions B( p, q ) in two variables are there? 7. How many Boolean functions B( p, q, r ) in three variables are there? cse 1400 applied discrete mathematics functions 6 8. Let f : X Y be a function. Answer the following True or False. Explain your answer. (a) If for every y Y there is an x X such that f ( x ) = y, then f is onetoone. (b) If for every y Y there is an x X such that f ( x ) = y, then f is onto. (c) If for every pair x1 , x2 X, x1 = x2 implies f ( x1 ) = f ( x2 ), then f is onetoone. 9. Define a function that maps the natural numbers from 0 to 2n  1 onto the two's complement numbers 2n1 to 2n1  1. (d) If for every pair x1 , x2 X, x1 = x2 implies f ( x1 ) = f ( x2 ), then f is onto. CSE 1400 Applied Discrete Mathematics Polynomials
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 Polynomials
Constants 1
2 2 2 4 4 5 5 7 3 Linear Polynomials Quadratic Polynomials The Power Basis The Binomial Theorem Taylor Polynomials Rising Factorial Powers Horner's Rule for Evaluating Polynomials Falling Factorial Powers 2 Problems on Polynomials 8
If f is a continuous realvalued function on [ a, b] and if any > 0 is given, then there exists a polynomial p on [ a, b] such that  f ( x )  p( x ) < for all x in [ a, b]. In words, any continuous function on a closed and bounded interval can be uniformly approximated on that interval by polynomials to any degree of accuracy. Abstract Polynomial functions are computationally primitive and form bases for approximating more complicated functions. 1 Polynomials Polynomials are important because 1. They are easy to evaluate. 2. They can approximate arbitrarily well many more complex functions. Low degree polynomials p( x ) are studied in college algebra. College algebra studies how to solve polynomial equations p( x ) = 0. and students learn to graph polynomial equations p( x ) = y in a Cartesian coordinate system. Instances of polynomials include p( x ) = 3x + 2 p( x ) = x2  x  1 p( x ) = x2  4 p( x ) = x3 + x2 + x + 1 The zeros of polynomials can be computed. at x = 2/3 1 5 x2  x  1 = 0 at x = 2 x2  4 = 0 at x = 2 at x = 1, i 3x + 2 = 0 x3 + x2 + x + 1 = 0 cse 1400 applied discrete mathematics polynomials 2 1.1 Constants
Constants are polynomials. Constants are polynomials of degree 0. There are famous, important constants. 0, Zero 1, One 2 1.414213, The square root of 2 = (1 + 5)/2 1.618033, The golden ratio 3.141592, pi e 2.718281, Euler's or Napier's constant 0.577215, The EulerMascheroni constant 1.2 Linear Polynomials
Polynomials that grow by a constant increment are called linear. A linear polynomial p( x ) is written p( x ) = mx + b for some slope m R, m = 0 and yintercept b R. These functions are called first degree polynomials. Lines through the origin are interesting. They have the form ax + by = 0 where ( a = 0) (b = 0)
ax + by is the inner product of two vectors a, b and x, y . When the inner product is 0, the vectors are orthogonal (perpendicular). y The zero of the equation p( x ) = 0 is x = m1 b. Onedimensional affine space establishes an equivalence between two nonorigin points ( x0 , y0 ) and ( x1 , y1 ) provided they lie on the same line through the origin. That is, ax0 + by0 = 0 and ax1 + by1 = 0 1.3 Quadratic Polynomials
Quadratic polynomials arise in many applications. A quadratic polynomial p( x ) is written p( x ) = ax + bx + c
2 a, b x, y x where a = 0
The zeros of the equation p( x ) = 0 are x = (b b2  4ac)/2a. The slope changes instantaneously as the function p ( x ) = 2ax + b cse 1400 applied discrete mathematics polynomials 3 And the yintercept is c R. These functions are called second degree polynomials. The golden quadratic is ( x ) = x2  x  1 It is named golden because one of its zeros, the values of x where ( x ) = 0, is the 1+ 5 = 1.618033 2 and the other is the conjugate root. 1 5 = 0.618033 2 1.4 The Power Basis
Pretend a process consumes 1 + y unit of resources and produces 1 + xy units of product each period of time. The process compounds when the output is feed back as input during the next production cycle. 1 y 1+xy Assume that y is initially 0. y Table of y versus discrete time n = 0, 1, 2, 3, . . . shows how the feedback system operates. The polynomial
Table 1: Computing of y at rate x. Time y 0 1 0 1 2 1+x 3 1 + x + x2 4 1 + x + x2 + x3 p ( x ) = 1 + x + x 2 + x 3 + + x n 1 is called a geometric sum. You can prove a geometric sum is equal to the rational function p( x ) = xn  1 x1 for x = 1 cse 1400 applied discrete mathematics polynomials 4 using mathematical induction. For instance, consider x = 2. Each period you invest one unit and y, all of your previous investments. Your investment is worth 1 + 2y at the end of the period; the beginning of the next period. Let yn be the value of y at time step n. Compute. y0 = 0 y1 = 1 y2 = 3 y3 = 7 Did you discover the formula yn = 2n  1? These are Mersenne numbers. They count the number of binary strings of length n. 1.5 The Binomial Theorem
The binomial theorem states ( x + y)n = 0 k n n nk k x y k n n 2 2 n x y ++ x2 yn2 + nxyn1 + yn 2 n2 = x n + nx n1 y + 1.6 Horner's Rule for Evaluating Polynomials
Horner's rule is an efficient algorithm for evaluating a polynomial p ( x ) at a given value x = c. For instance, to evaluate x 2  x  1 at x = 3, write Horner's Rule 1 1 Set x = 1 and y = 1 to derive the useful fact that 2n is the sum of binomial coefficients in row n of Pascal's triangle. Interpret the binomial coefficient (n) as k the count of kelements subsets over an nelement set to conclude there are 2n subsets of an nelement set. 1 3
2 1 6
5 For instance, to evaluate 3x 2  4x + 7 at x =  2, write Horner's Rule 3 3  10 4 6 7 20 27 cse 1400 applied discrete mathematics polynomials 5 For instance, to evaluate 7x 5  2x 3 + 5x  4 at x = 4, write Horner's Rule 7 7 0 28 28 2 112
110 0 440 440 5 1760 1755 4 7020
7016 1.7 Taylor Polynomials
Consider what happens when Horner's rule is iterated. For instance, for ( x ) = x 2  x  1 at x = 3, we find Iterated Horner's Rule 1 1 1 0 1 What this says is ( x ) = x2  x  1 = ( x  3)2 + 5( x  3)1 + 5 which you can easily check. ( a) = c Horner's Rule 1 1
For instance, we can write ( x ) = x 2  x  1 = ( x  a )2 + b ( x  a ) + c for some shift a and coefficients b and c 1 3
2 3 5 1 6
5 1 a
a1 a 2a  1 a2  a  1 1 a ( a  1) 1 ( x ) = x2  x  1 = ( x  a)2 + (2a  1)( x  a) + ( a2  a  1) 1.8 Falling Factorial Powers
The falling factorial powers x n = x ( x  1) ( x  n + 1) cse 1400 applied discrete mathematics polynomials 6 occur in some applications. The falling factorial powers are related to binomial coefficients by the identity. x n = x ( x  1) ( x  n + 1) = n!x! x = n! n n!( x  n)! The falling factorial powers are a natural basis for the sum and difference calculus. The fundamental theorem of the sum and difference calculus is the equation 0 k < n xn = x n +1 n+1 This follows from the fact that the sum of values in column n of Pascal's triangle up to row x is equal to the value in the column n + 1 and row x + 1. That is 0 x < n 0 x < n x n = x+1 n+1 xn ( x + 1 ) n +1 = n! ( n + 1) ! Stirling numbers of the second kind relate the polynomial power basis to falling factorial powers. That is, x0 = x1 = x2 = x3 = x4 = x0 = 1 x1 = x x3 + 3x2 + x1 = x ( x  1)( x  2) + 3x ( x  1) + x x 2 + x 1 = x ( x  1) + x x4 + 6x3 + 7x2 + x1 = x ( x  1)( x  2)( x  3) + 6x ( x  1)( x  2) + 7( x  1) + x The general formula is xn = 0 k n n k x k These are Stirling's subset numbers and they count the number of ways to partition an n element set into m subsets, that is they count equivalence relations. Where {n} are Stirling numbers of the second kind, defined by the k recurrence n n1 n1 = +m m m1 m cse 1400 applied discrete mathematics polynomials 7 Output values y = 1, y = x, y = x ( x  1), y = x ( x  1)( x  2) 0 20 40 60 3 2
0 1 1 Input values x 2 3 1.9 Rising Factorial Powers
The rising factorial powers x n = x ( x + 1) ( x + n  1) occur in some applications. The rising factorial powers are related to binomial coefficients by the identity. x n = x ( x + 1) ( x + n  1) = x+n1 n!( x + n  1)! = n! n!( x  1)! n Stirling numbers of the first kind relate the polynomial power basis to rising factorial powers. That is, x0 = x1 = x2 = x3 = x4 = x0 = 1 x1 = x x2 + x1 = x2 + x x3 + 3x2 + 2x1 = x ( x + 1)( x + 2) x4 + 6x3 + 11x2 + 6x1 = x ( x + 1)( x + 2)( x + 3) The general formula is xn = 0 k n n k x k cse 1400 applied discrete mathematics polynomials 8 Where [n] are Stirling numbers of the first kind, defined by the recurk rence n n1 n1 = + ( n  1) m m1 m These are Stirling's cycle numbers and they count the number of ways permute n elements into m cycles. Output values y = 1, y = x, y = x ( x + 1), y = x ( x + 1)( x + 2) 60 40 20 0 3 2 0 1 1 Input values x 2 3 2 Problems on Polynomials
(a) p( x ) = x5 + 4x3 + 2x  7 (b) p( x ) = 5x10  1 (c) p( x ) = an1 x n1 + an2 x n2 + + a1 x + a0 1. Compute the degree of the polynomials 2. What are the roots of the polynomial equation x2  x  1 = 0? 4. Answer the following True or False. Explain your answer. (b) ( x + 1)( x  1) = x2  1. (a) (1)( x  1) = x  1. (d) p( x ) = 0kn1 ak x k 3. For a = 0, what are the roots of the polynomial equation ax2 + bx + c = 0? (d) ( x n1 + x n1 + + x + 1)( x  1) = x n  1. (c) ( x3 + x2 + 1)( x  1) = x3  1. cse 1400 applied discrete mathematics polynomials 9 (e) x n1 + x n2 + + x + 1 = ( x n  1)/( x  1) provided x = 1. 5. Use Horner's rule to evaluate the following polynomials at the given value of x. (a) p( x ) = 3x4  5x2  16x  4 at x = 3. (b) p( x ) = 3x5  4x3 + 3x2  7 at x = 2. (c) p( x ) = 2x4  3x3 + 2x2 + 4x  3 at x = 3. (d) p( x ) = x5  2x3 + 3x2  1 at x = 2. (e) p( x ) = x4 + x3 + x2 + x + 1 at x = 2. (f) p( x ) = x4 + 4x3 + 6x2 + 4x + 1 at x = 2. 6. Polynomials can be written in the falling (factorial) power basis x0 = 1, x1 = x, x2 = x ( x  1), x3 = x ( x  1)( x  2), . . . , x n = x ( x  1)( x  2) ( x  n + 1) as an alternative to the standard basis 1, x, x2 , x3 , . . . , x n . (a) Horner's rule evaluates a polynomial a n x n + a n 1 x n 1 + a 1 x + a 0 written in the standard basis using n additions and n multiplies. Devise an algorithm to evaluate a polynomial a n x n + a n 1 x n 1 + a 1 x 1 + a 0 x 0 written in the falling power basis. Count the number of additions and multiplications your algorithm uses. 7. The set of all points ( x, y) that lie on a line through the origin can be written in the form ax + by = 0 where ( a = 0) (b = 0) (a) What is a logically equivalent way to write the clause ( a = 0) (b = 0)? (b) Consider a, b to be the tip of a vector from the origin. What is the Euclidean length of a, b and how can you state the length is not zero? CSE 1400 Applied Discrete Mathematics Logarithms and Exponents
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2 Logarithms 1 3 Problems on Logarithms and Exponentials
Abstract Logarithmic functions and their inverses, exponential functions occur in many application areas: annuities and loans, growth and decay, seismic modeling, and algorithm analysis. 1 Logarithms The logarithm base e is called the natural logarithm. Using calculus it can be established that ln(1 + x ) x  x2 x3 xn +  + (1)n1 2 3 n where the approximation grows more accurate as the degree n of the approximating MacLaurin polynomial increases. The inverse of the natural logarithm is the exponential base e ex 1 + x + x2 x3 xn + ++ 2! 3! n! MacLaurin's approximation, together with Horner's rule provides an algorithm for approximating the logarithmic and exponential functions at a value x = a. cse 1400 applied discrete mathematics logarithms and exponents 2 2 1 lg( x ) 0 1 2
0 4 3 2x 2 1 0 1 2 x 3 4 2 1 0 x 1 2 Logarithms have several useful properties. They were invented to simplify computations. They convert multiplication into addition, division into subtraction, and exponentiation into multiplication. These are the easily established rules. 1. Log of a product is the sum of logs ln ab = ln a + ln b because e a eb = e a+b 2. Log of a quotient is the difference of logs ln because a = ln a  ln b b ea = e ab eb cse 1400 applied discrete mathematics logarithms and exponents 3 3. Log of a power is the power times the log ln ab = b ln a because (e a )b = e ab In computer science, decisions can be reduced to "yes" or "no" answers. Because of this the binary logarithm lg x = log2 x plays an important role. Luckily, logarithms in one base can be easily related to logarithms in another base. Consider how the log base of x can be evaluated using the log base . Read the equations from lefttoright and toptobottom. y = log x y log = log x y = x y= log x log log y = log x log x = log x log 2 Problems on Logarithms and Exponentials 1. Answer True or False. Explain your answer. (a) 2a 2b = 2a+b . (b) 2a 2b = 2ab . (c) 2n 2n = 22n . (d) 2n 2n = 2n .
2 (e) (2a )b = 2ab . (f) (2a )b = 2a . (g) (2n )n = 2n . (h) (2n )n = 2n .
n 2 b 2. Evaluate the logarithm base 2 function lg x at the given value for x. (a) lg(256) (b) lg(0.25) (c) lg(0.125) (d) lg(1/1024) (e) lg( 3 16) (f) lg( 5 8) (g) lg 3 32 (h) log16 3 32
(i) lg(2n! ) 3. In binary notation, how many bits are required to name a natural number n when 23 n < 24 ? 4. In binary notation, how many bits are required to name a natural number n cse 1400 applied discrete mathematics logarithms and exponents 4 5. True or False: The logarithm (base 2) function lg( x ) maps the open interval (0, ) onto the set of real numbers. Explain your answer. 6. True or False: The logarithm (base 2) function lg( x ) is not onetoone. Explain your answer. 7. True or False: Since 210 = 1024 is approximately equal to 103 = 1000, the log base 2 of 10 is approximately equal to 3 and 1/3. Explain your answer. 8. Use the fact that 27 = 128 is approximately equal to 53 = 125 to approximate the value of log5 (2). 9. Given that ln 2 0.693147 and log 2 0.301030 Show that lg x ln x + log x Specifically, that the error is less than 1% in that ln x + log x  1 < 0.01 lg x 10. For each problem below, find a constant c R such that the equation is an identity. (a) lg( x ) = c ln( x ) (b) ln( x ) = c lg( x ) (c) lg( x ) = c log( x ) (d) log( x ) = c lg( x ) (e) lg( x ) = c logb ( x ) (f) logb ( x ) = c lg( x ) 11. Consider the proposition: loga (b) logb ( a) = 1. Is the position True or False. You may assume a and b are natural numbers greater than or equal to 2. Explain your answer. 12. Use the "sum of logs is log of a product rule" to write the sum 1 k n lg k as a logarithm that involves a factorial. 13. A solution's pH measures its acidity or alkalinity, with 7 called neutral. In particular, pH =  log10 (H3 O+ ) where H3 O+ is the concentration of hydronium ions in the solution. The pH scale is logarithmic: When pH increases by 1, alkalinity increases 10fold. Likewise, when pH decreases by 1, acidity increases 10fold. Pretend the average pH of sea water will decrease by 0.5 in 100 years. By what factor will the acidity sea water increase? 14. If a principle of P dollars is invested at an interest rate r compounded n times per year, then the amount after t years is r nt A = P 1+ n Pretend P = $1 is invested at a 10% rate compounded quarterly. How many years t will go by before A = $10? CSE 1400 Applied Discrete Mathematics Integer Functions
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 Integer Functions 1
1 4 Floor, Ceiling, and Related Functions Number Theoretic Functions 2 Problems on Integer Functions
Abstract 7 1 Integer Functions Some things are easy to model continuously, but only discrete integer values make sense: The 2000 census reports there are 0.90 children per family in the United States of America! There are several kinds of integer functions. One kind has a signature f :RZ This type of integer function maps real numbers to integers. These are useful when rounding or truncating computed values to integer approximations. Another type maps integers to integers. This kind has a signature f :ZZ and is useful in number theory and its applications. 1.1 Floor, Ceiling, and Related Functions
The floor of a real number x is the integer n immediately below x: n x. The floor functions has signature :RZ 2.75 = 2 18.5 = 18 5 =5 =3 2.5 = 3 12.6 = 13 5 = 5  = 4
e =2  e = 3 =1  = 2 cse 1400 applied discrete mathematics integer functions 2 y= x 3 2 1 x 1 0 1 2 3 1 The ceiling lies above x. y= x 3 2 1 x 2.75 = 3 18.5 = 19 5 =5 =4 2.5 = 2 12.6 = 12 5 = 5  = 3
e =3  e = 2 =2  = 1 1 0 1 2 3 1
The floor and ceiling functions are useful when reasoning about the pigeonhole principle principle. Pretend you have a things to place in n places. For instance, pretend you have 13 shirts to place in 5 boxes. A natural, nearly uniform, distribution places 2 shirts in all 5 boxes and 1 shirt each of 2 boxes. Notice that 12/5 = 2 and 12/5 = 3. 1. If all boxes contained 3 or more shirts, then there would be at least 3 5 = 15 shirts, but there are only 12 shirts. Therefore some box must contain 2 = 12/5 or less shirts. {2.75} = 0.75 { } 0.1416 {e} 0.7183 {18.5} = 0.5 {5} = 0.0 {2.5} = 0.5 { } 0.8584 {12.6} = 0.4 {e} 0.2817 { } 0.6180 { } 0.3820 {5} = 0.0 This is an application of the quotient remainder theorem: 13 = 5 2 + 3 and in general a = nq + r where 0 r < n. (box)(shirts in box 12/5 )
It is useful to consider the function that maps shirts to boxes. Name the shirts s0 to s11 and the name the boxes b0 to b4 . Placing cse 1400 applied discrete mathematics integer functions 3 the shirts in the boxes is described the the function that maps each shirt sk to some box b j . Or, in general (y)( {k : f (k) = y}  a/n )
2. If all boxes contained 2 or fewer shirts, then there would be at most 2 5 = 10 shirts, but there are 12 shirts. Therefore some box must contain 3 = 12/5 or more shirts. (box)(shirts in box 12/5 )
Related to the floor is the fractional part function that subtracts x from x leaving only a small remainder. {x} = x  x
The fraction part of a real number starts at 0 but never reaches 1. y = {x} 2 1 x 1 0 1 2 3 1
Also related is the round function that selects the closest integer to x. With a bias to always round up to n + 1 when there is a tie at the halfway point n + 0.5 between n and n + 1, the round function can be implemented as ( x ) = x + 0.5 y = ex 3 2 1 x (2.75) = 3 (2.5) = 2 (18.5) = 19 (5) = 5 (12.6) = 13 (5) = 5 ( ) = 3 (e) = 3 ( ) = 3 ( ) = 2 (e) = 3 ( ) = 2 1 0 1 2 3 1 cse 1400 applied discrete mathematics integer functions 4 There are many relationships that can be derived among these functions. For instance,  x =  x . Consider the proof. Proof. There is an integer n such that n x < n + 1 and n = x . Therefore n  1 <  x n and  x = n. Don't like the proof in text? Consider the graph 1.2 Number Theoretic Functions
Just as x and { x } functions split a real number x into integer and fractional parts, division partitions an integer a into q parts of size n with a remainder r. For instance, a = 23 is 4 parts of size 5 plus a remainder of 3. a 23 n is x's floor; n is  x ceiling. (n + 1)  x n 0 n x n+1 x = qn + r = 54 + 3 Notice the reciprocity of 4 and 5: a = 23 is 5 parts of size 4 plus a remainder of 3. The quotient and remainder are not unique as you can see from the arithmetic 23 = (5 4 + 3) = (5 5  2) = (5 6  7) = (5 7  12) = Quotients and remainders give rise to important relations, such as congruence and divides. = (5 4 + 3) = (5 3 + 8) = (5 2 + 13) = (5 1 + 18) = This demonstrates the quotient q can be any integer, but the remainder lies along an arithmetic sequence. We will to make decisions so that a unique quotient and remainder can be computed: We will define a function q( a, n) and a function r ( a, n) that map a pair ( a, n) Z (Z  {0}) to an integer quotient and an integer remainder. The choices begin from the ancient theorem that an integer can be divided into parts of a given size with remaining residue, that could be 0. Theorem 1 (QuotientRemainder). Given an integer a Z and an integer n = 0, there exists integers q and r, called the quotient and remainder such that a = qn+r and 0 r  < n. Since n = 0, we can divide the equation a = n q + r through by n and write a/n = q + r/n. Now a/n is bounded below and above by integers a/n and a/n , which provide two choices for the value of quotient q. Name the fractional part of a/n ny x = { a/n} so that 0 x < 1. The values of x and 1  x play roles in computing the value of remainder r. Variable a n q r Name dividend divisor quotient remainder Read the section on unit conversion. 23 2 2 + = 5 + = 23 = 5 (5) + 2 5 5 5
q(23, ) = 5 cse 1400 applied discrete5mathematics r (23, ) = 2 integer 5functions 5 23 2 2 + = 5 + = 23 = (5) (5)  2 5 5 5 q(23, 5) = 5 r (23, 5) = 2 x a/n a/n 1x a/n Consider what happens when the quotient is set to the floor of a/n. a a +x = n n a q+x = n nq + nx = a a = nq + nx a = nq + r 23 3 3 + = 4+ = 23 = (5) (4)  3 5 5 5
q(23, 5) = 4 r (23, 5) = 3 With q = a/n , consider the four cases a, n where a = 23 and n = 5. 23 2 + = 5 5 23 5 = 5 = 23 = 5 5  2 q(23, 5) = 5 23 3 + = 5 5 23 5 r (23, 5) = 2 = 4 = 23 = 5 (4)  3 In this case the residue is r = nx and its algebraic sign is the same as that of the divisor n. Next, consider what happens when the quotient is set to the ceiling of a/n. a a + (1  x ) = n n a + (1  x ) = q n a + n(1  x ) = nq q(23, 5) = 4 23 3 + = 5 5 23 5 r (23, 5) = 3 = 4 = 23 = (5) (4) + 3 q(23, 5) = 4 r (23, 5) = 3 23 2 + = 5 5 q(23, 5) = 5 r (23, 5) = 2 23 5 = 5 = 23 = (5) (5) + 2 a = qn + r a = qn + n( x  1) In this case the residue is r = n( x  1) and its algebraic sign is the opposite of n's sign. With all of these choices for quotients and remainders the decision on quotient and remainder definitions is not clear. In number theory, the decision is to always choose the nonnegative residue r guaranteed by the quotient remainder theorem. This choice for the remainder function r ( a, n) is called the Euclidean mod function, and it computes the remainder based on the sign of n. n { a/n} if n > 0 0 r = a mod n = n({ a/n}  1) if n < 0 Consider the instances where remainder r is nonnegative. { a/n} 0 is the fractional part of a/n. cse 1400 applied discrete mathematics integer functions 6 3 5 2 5 + 5 3 4 + 5 2 5+ 5 4+ = = = = 23 3 + 5 5 23 2 + 5 5 23 3 + 5 5 23 2 + 5 5 = = = = 23 = 5 4 + 3 23 = 5 (5) + 2
23 = (5) (4) + 3 23 = (5) (5) + 2 With this choice for computing the value of remainder r, the Euclidean div computes the quotient q by setting it to a floor or ceiling based on the sign of n. a/n if n > 0 q = a div n = a/n if n < 0 Very few, if any, programming languages have native implementation for the Euclidean mod and div functions. In computing practice, most processors have circuitry that compute truncation division, and so most programming languages support operations to compute truncated quotients and remainders. Truncated division rounds quotients toward 0. That is, when a/n 0, q is set to the floor of a/n, but when a/n < 0, q is set to the ceiling of a/n, 3 5 3 4  5 3 4 + 5 3 4 5 4+ Figure 1: In Haskell, truncated quotient and remainder operators are written.
a `quot` n = q a `rem` n = q = = = = 23 3 + 5 5 23 3  5 5 23 3  5 5 23 3 + 5 5 = = = = 23 = 5 4 + 3 Using truncated division, the sign of dividend a determines the sign of remainder r. 23 = 5 (4)  3
23 = (5) (4) + 3 23 = (5) (4)  3
Figure 2: In Haskell, the floored quotient and remainder operators are written.
a `div` n = q a `mod` n = q Knuth makes the choice to always use the floor of a/n as the quotient q. cse 1400 applied discrete mathematics integer functions 7 3 5 2 5 + 5 2 5  5 3 4 5 4+ = = = = 23 3 + 5 5 2 23 + 5 5 23 2  5 5 23 3  5 5 = = = = 23 = 5 4 + 3 23 = 5 (5) + 2
23 = (5) (5)  2 23 = (5) (4)  3 Choosing the remainder of smallest magnitude is another criteria that could be used to define quotients and remainders. 2 5 2 5 + 5 2 5  5 2 5+ 5 5 Using floored division, the sign of the divisor n determines the sign of the remainder r. = = = = 23 2  5 5 23 2 + 5 5 23 2  5 5 23 2 + 5 5 = = = = 23 = 5 5  2 23 = 5 (5) + 2
23 = (5) (5)  2 23 = (5) 5 + 2 2 Problems on Integer Functions I am not aware of a programming language that has native functions implementing the smallest remainder criteria. 1. Answer the following True or False. Explain your answer. (a) (b) (c) (d) x = n if and only if n x < n + 1. x = n if and only if x n < x + 1. (g) Every integer n > 0 can be represented in lg(n) + 1 bits. (h) Every integer n > 0 can be represented in lg(n + 1) bits. (i) If 12 objects are put in 5 boxes some box must contain at least 12/5 = 3 objects and some box must contain no more than 12/5 = 2 objects. x = n if and only if x  1 < n x. x = n if and only if n  1 < x n. (e) x = x + { x }, where { x } if the fractional part function. (f) If n and m are positive integers, then n/m is the quotient when n is divided by m. 2. Evaluate the following floors. cse 1400 applied discrete mathematics integer functions 8 (a) (b) (c) e 2 (d) (e) (f) = (1 + 5)/2 3. Evaluate the following ceilings. (a) (b) (c) e 2 (d) (e) (f) = (1 + 5)/2 0.5772 4. Evaluate the following fractional parts rounded to 4 decimal places. (a) 2 (d) { } = (1 + (e) { } = (1  (f) {} 5)/2 (b) { } (c) {e} 5)/2 5. Evaluate the following rounds. (a) 2 (c) ( ) (d) () (b) ( ) 6. Prove that x +  x = 0 if x Z, but x +  x = 1 if x Z. 8. What can you conclude about the sum of the fractional parts of x and  x 7. What can you conclude about the sum of the floor of x and  x { x } + { x } = ?
10. How would you define a b mod 0? 9. How would you define a b mod 1 for a, b Z? CSE 1400 Applied Discrete Mathematics Permutations
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 Permutations 1
2 2 4 Cyclic Notation Permutations ReOrder a Sequence Stirling Numbers of the First Kind Problems on Permutations
Abstract 4 A permutation is a onetoone function from a set onto itself. 1 Permutations A permutation is a function that rearranges the order of terms in a sequence. It is useful to study a few small examples. Consider the suits in a deck of playing cards: clubs , diamonds , hearts , and spades . In computing practice, sorting a group of objects into a preferred order is a fundamental operation. Sorting algorithms perform a sequence of permutations on the objects, each bringing them closer to the preferred order. There are 2! = 2 permutations of two things . Starting with a , after picking up a , place it before or after the . If you next draw a it can be place before, in the middle, or after the already permuted pairs. Imagine inserting a into one of the already arranged suits, say . There are four places where the can be inserted: first, second, third, or fourth. Reasoning like this it is not difficult to observe there are 4! = 4 6 = 4 3 2 1 = 24 There are 3! = 6 permutations of three things . , , , cse 1400 applied discrete mathematics permutations 2 permutations on 4 things . Let A be a ith n elements. The symbol for the count of ways to permute the elements of A is n! and pronounced "n factorial." This count of permutations can be computed by evaluating the product n! = n(n  1)(n  2) (2)(1) called n factorial. 1.1 Cyclic Notation
Under a permutation a thing in spot n "goes to" spot m. Cyclic notation describes "goes to." Consider the permutation "shift by 2"
In computing practice, you may need to save the thing is spot m before overwriting it with the thing from spot n. For instance, under the permutation Original Order Permuted Order 0 4 1 3 2 2 3 1 4 0 [0, 2, 4, , 24][1, 3, 5, , 25]
on the English alphabet applied to the characters in the statement
a man a plan a canal panama c ocp c rncp c ecpcn rcpcoc value 0 goes to position 4 and 4 goes to 0, 1 goes to position 3 and 3 goes to 1, and 2 stays put. In cyclic notation, the above permutation is written [0, 4][1, 3][2] 1.2 Permutations ReOrder a Sequence
For small sets each permutation can be listed. Let A be a set with cardinality A = n. There are n factorial different permutations of the elements in A. Figure 1 shows the 3! = 6 permutations of the elements in {0, 1, 2} written in cyclic notation. The permutations on {0, 1, 2, 3} can be defined recursively, that is, from the permutations on {0, 1, 2}. For instance, to build all 2cycle permutations of {0, 1, 2, 3}. use the one and twocycle permutations of {0, 1, 2}. 1. Append the cycle [3] to each 1cycle permutation of {0, 1, 2} 2. Insert new element 3 in three positions in each 2cycle permutations of {0, 1, 2}
n Using [m] to name the count of 2cycle permutations of a 4element set, write 4 3 3 = +2 = 2 + 3 3 = 11 2 1 2 Okay! Blank did not shift. It is convenient to say there is a permutation of the , so there is 1. That is, 0! = 1. These eleven permutations are shown in figure 2. cse 1400 applied discrete mathematics permutations 3 Permutations Figure 1: Cyclic notation for the 3! permutations of {0, 1, 2}. [0, 1, 2] [0, 2, 1] [0][1, 2] [1][0, 2] [2][0, 1] [0][1][2] Permutations Figure 2: Cyclic notation for the 4! permutations of {0, 1, 2, 3}. [0, 1, 2, 3] [0, 1, 3, 2] [0, 3, 1, 2] [0, 2, 1, 3] [0, 2, 3, 1] [0, 3, 2, 1] [0, 1, 2][3] [0, 2, 1][3] [0][1, 2, 3] [0][1, 3, 2] [0, 3][1, 2] [1][0, 2, 3] [1][0, 3, 2] [1, 3][0, 2] [2][0, 1, 3] [2][0, 3, 1] [2, 3][0, 1] [0][1, 2][3] [1][0, 2][3] [2][0, 1][3] [0][1][2, 3] [0][1, 3][2] [0, 3][1][2] [0][1][2][3] cse 1400 applied discrete mathematics permutations 4 1.3 Stirling Numbers of the First Kind
The elements of set with cardinality n can be permuted n into m cycles in [ m ] ways. Stirling numbers of the first kind are defined by the recurrence equation n n1 n1 = + ( n  1) m m1 m with boundary conditions n = 1, n and n = 0, for n > 0 0 Check that the following arithmetic can be verified by the numbers in table 1. 4 3 3 = +3 = 3+31 3 2 3 5 4 4 = +4 = 11 + 4 6 3 2 3 7 6 6 = +6 = 85 + 6 15 5 4 5
n The notation [m] is called n cycle m. Table 1: Stirling numbers of the first n kind [m] count the permutations with m cycles of n things .
n Stirling Numbers of the First Kind [m] Cycle m 1 2 3 4 5 6 0 0 1 2 3 4 5 6 7 8 1 0 0 0 0 0 0 0 0 7 8 n 0 1 1 2 6 24 120 720 5040 0 0 1 3 11 50 274 1764 13068 0 0 0 1 6 35 225 1624 13132 0 0 0 0 1 10 85 735 6769 0 0 0 0 0 0 0 0 0 0 1 0 15 1 175 21 1960 322 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 28 1 1.4 Problems on Permutations
1. True or false: A permutation of X is a onetoone function from X onto X. 3. True or false: [ a, a, b] is a permutation of { a, b, c}. 2. True or false: [c, a, b] is a permutation of { a, b, c}. 4. True or false: There are 2n permutations of an n element set. 5. True or false: There are n! permutations of an n element set. 6. Let H = {0, 1, 2, . . . , E, F }. (a) How many permutations can be defined on H? (b) In how many ways can you choose 5 elements from H cse 1400 applied discrete mathematics permutations 5 (c) In how many ways can you choose and permute 5 elements from H (d) How many permutations on H have 16 cycles? (e) How many permutations on H have 1 cycle? 7. Let X be an 8element set. How many permutations on X have 4 cycles? That is, what is the value of the Stirling number [8] "8 cycle 4"? You may want to know row 7 of Stirling's triangle of the first kind is 4 7 0 1 2 3 4 0 720 1764 1624 735 9. Use cyclic notation to describe the permutation (0, 2, 4, 6, 1, 3, 5, 7) of the octal alphabet {0, 1, 2, 3, 4, 5, 6, 7} 8. Use cyclic notation to describe the permutation (0, 1, 2, 3) of the elements in the set {0, 1, 2, 3} 10. Use cyclic notation to describe the permutation (1, 2, 0, 7, 3, 4, 5, 6) of the octal alphabet {0, 1, 2, 3, 4, 5, 6, 7} CSE 1400 Applied Discrete Mathematics Mathematical Induction
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 Induction 1
1 7 8 10 Summations The Tower of Hanoi and Mersenne Numbers Rabbit Population Growth and Fibonacci Numbers Induction on Arithmetic and Geometric Sequences 2 Problems on Induction 13
Abstract The word induction has many meanings. For us it is a formal proof process that a predicate p (n) is True for all natural numbers n belonging to some set, most often the set of natural numbers N = {0, 1, 2, . . .}. The principle of induction is: If set X contains zero and if x X implies its successor x + 1 X, then every natural number is in X, that is X = N. 1 Induction Induction often involves sums:
If the sum of n term equals some formula, then the sum of n + 1 terms equals the same formula with appropriate substitutions. Induction often involves recurrsion:
A function f (n) satisfies a recurrence relation.
An inductive proof of the truth of predicate p (n) for all natural numbers n has two steps. 1. A proof that p (0) is True. 2. A proof of the truth of the conditional statement 1.1 Summations
Consider the predicate: The sum of the first n natural numbers is n(n  1)/2. If p (n) is True, then p (n + 1) is True.
A short notation for this is p (0) p ( n ) p ( n + 1) (n N) p (n) Which is read "p (0) is True; and if p (n) is True, then p (n + 1) is True. Therefore, p (n) is True for all natural numbers n." cse 1400 applied discrete mathematics mathematical induction 2 For instance, the sum of the first 5 natural numbers is 0 + 1 + 2 + 3 + 4 = 10 = 5 (5  1)/2 = 5 4/2 Since the sum of the first 5 natural numbers is 10, the sum of the first 6 natural numbers is 10 + 5 = 15 = 6 5 2 You could use the notation p (n) to denote the truth value of the statement The heart of mathematical induction relies on (1) noticing a pattern for small initial cases, and (2) establishing a link allowing a proof of of an instance from the truth of previous instances. In this case, the pattern is 0 + 1 + 2 + 3 + 4 + + ( n  1) = n n1 2 "The sum of the first n natural numbers is n(n  1)/2." The sum of n terms in an arithmetic progression is n times the average of the first and last term. which can be phrases as "the sum of the first n natural numbers is n times n  1 divided by 2." or p (n) for short. To establish the link between the truth of p (n) and p (n + 1) requires a little algebra. We must generalize the instance above where the step was from 5 to 6. If the sum of the first n natural numbers is n(n  1)/2, then the sum of the first n + 1 natural numbers is n(n  1)/2 plus n. That is, if 0 + 1 + 2 + 3 + 4 + + ( n  1) = then n ( n  1) 2 The sum of the first n + 1 natural numbers is the sum of the first n natural numbers plus n, the (n + 1)st natural number. [0 + 1 + 2 + + (n  1)] + n = n ( n  1) +n 2 n1 =n +1 2 n = ( n + 1) 2 This shows that if the function n(n  1)/2 correctly computes the value in the nth case, then it correctly computes the value in the (n + 1)st case. This fact about the sum of natural numbers has a classic "proof by pictures." The statement: "The sum of the first n natural numbers is n(n  1)/2" is a predicate: A proposition whose truth value depends on one or more variables, in this case, one variable named n. Many Another example of a predicate is x squared minus 1 equals 0.
This predicate is True for x = 1 and False for all other values of x. cse 1400 applied discrete mathematics mathematical induction 3 0 + 1 + 2 + 3 + 4 + 5 + 6 = 21 = 1 7(7  1) 2 n 1 k =0 k = 0 + 1 + 2 + + ( n  1) = 2 n ( n  1)
Table 1: The number of dots in the rectangle is n (n  1). Onehalf of the dots sums the natural numbers from 1 to (n  1). 1 predicates, especially predicates about summations and recurrence equations, can be proved True by mathematical induction. Summation notation is used to write phrases such as "the sum of the first n natural numbers." The summation notation for this phrase is k The phrase "the sum of the first n powers of 2" is written
0k<n 0k<n 2k The phrase "the sum of the first n odd natural numbers" is written
0k<n ( 2k + 1 ) In each of these examples, k is a "dummy variable" that successively takes on the values 0, 1, 2, up to and including ( n  1 ) . The symbol stands for "sum the values" of the terms which are k, 2 k and ( 2k + 1 ) in the three examples. Thus,
0k<n 0k<n 0k<n k = 0 + 1 + 2 + 3 + 4 + + (n  1) 2k = 20 + 21 + 22 + 23 + 24 + + 2(n1) ( 2k + 1 ) = 1 + 3 + 5 + 7 + 9 + + ( 2n  1 ) cse 1400 applied discrete mathematics mathematical induction 4 When n = 0, the dummy variable k ranges over absurd values 0 up to and including  1. By convention, we take this sum to mean the sum of no values and interpret the sum's value to be 0. That is,
0k<0 tk 0 This sum is called the empty sum and its values is equal to 0 no matter the values of the terms t k . Let's give proofs by mathematical induction of the following predicates. 1. "The sum of the first n powers of 2 is 2 n  1."
0k<n 2k = 2n  1 (1) Basis for Induction: The sum of the first n = 0 powers of 2 is the empty sum 2k and equal to 0. The righthand side of equation 1 is the value of the function 2 n  1 at n = 0, that is, 2 0  1, which is also equal to 0. As additional confirmation of the predicate in initial cases note (a) The sum of the first n = 1 powers of 2 is 2 0 = 2 1  1 (b) The sum of the first n = 2 powers of 2 is 2 0 + 2 1 = 3 = 2 2  1.
0k<0 Inductive Conclusion: If the sum of the first n powers of 2 is  n  1 plus 2n . 1, then the sum of the first (n + 1) powers of 2 is 2 That is, If 2k = 2n  1 then
0 k < n Inductive Premise: Pretend that for some unspecified n, the sum of the first n powers of 2 is 2 n  1. 2n We know that the sum of the first n powers of 2 is 2n  1 is true for n = 0, 1 and 2. 0k <(n+1) 2k = = 2 2n  1 = 2n +1  1 = (2n  1 ) + 2n 0 k < n 2k + 2n That is, if the function 2x  1 correctly computes the value of the nth case, then it correctly computes the value of the (n + 1)st case. cse 1400 applied discrete mathematics mathematical induction 5 2. "The sum of the first n odd natural numbers (n + 1)2 ." This fact about the sum of odd natural numbers has a classic "proof by pictures," see Table 2. 1 + 3 + 5 + 7 + 9 + 11 = 36 = 62 n 1 k =0 (2k + 1) = 1 + 3 + 5 + (2n  1) = n2
Table 2: The number of dots in sucKnow that an implicit use of induction cessive squares is the sum used. is occurring when are of successive odd natural numbers from 1 to (2n  1). We can reduce the problem of summing odd numbers to problem of summing natural numbers. That is, the sum of the first n odd natural numbers is 1 + 3 + 5 + 7 + + (2(n  1) + 1) =(2 0 + 1) + (2 1 + 1) + (2 2 + 1) + (2 3 + 1) + + (2(n  1) + 1) = n2 =2(n(n  1)/2) + n =2(0 + 1 + 2 + 3 + + (n  1)) + (1 + 1 + 1 + 1 + 1 + + 1) Here is an inductive proof that
n 1 k =0 (2k + 1) = n2 . (2) Basis for Induction: The sum of the first n = 0 odd natural numbers is the empty sum
0 k <0 (2k + 1) and equal to 0. The righthand side of the equation is the value of the function n2 at n = 0, that is, the lefthand side and the righthand side of equation 2 are both equal to 0 when n = 0. As additional confirmation of the predicate in initial cases note cse 1400 applied discrete mathematics mathematical induction 6 (a) The sum of the first n = 1 odd natural numbers is 1 = 12 . (b) The sum of the first n = 2 odd natural numbers is 1 + 3 = 22 . (c) The sum of the first n = 3 odd natural numbers is 1 + 3 + 5 = 32 . Inductive Premise: Pretend that for some unspecified n, the sum of the first n odd natural numbers is n2 . Inductive Conclusion: If the sum of the first n odd natural numbers is n2 , then the sum of the first (n + 1) odd natural numbers is n2 plus (2n + 1). That is, If then
0k <(n+1) 0 k < n (2k + 1) = n2 (2k + 1) = = n2 + 2n + 1 = ( n + 1)2 0 k < n (2k + 1) + (2n + 1) That is, if the function x2 correctly computes the value in the nth case, then it correctly computes the value in the (n + 1)st case. 3. "There are 2n bit string of length n." Basis for Induction: There is 1 = 20 bit strings of length n. It is the empty string, often named . As additional confirmation of the predicate in initial cases note (a) There are 2 bit strings of length 1: 0 and 1. (b) There are 4 = 22 bit strings of length 2: 00, 01, 10, and 11. Inductive Premise: Pretend that for some unspecified n, there are 2n bit strings of length n. Inductive Conclusion: Consider each bit string a of length n. The string a can be made into a bit string of length n + 1 by appending a 0 and it can be made into another bit string of length n + 1 by appending a 1. a 0a 1a cse 1400 applied discrete mathematics mathematical induction 7 No disks: No moves That is, every bit string of length n gives rise to 2 different bits strings of length n + 1. Therefore, if there are 2n bit strings of length n, there are 2 2n = 2n+1 bit strings of length n + 1. One disk: Before move 1.2 The Tower of Hanoi and Mersenne Numbers
Some problems are just fanciful, such as the Tower of Hanoi. Somewhere in southeast Asia, near Hanoi, monks are moving 64 golden disks from one diamond needle onto another subject to God's laws. 1. Move only one disk at a time. 2. Never place a large disk on a smaller one. When the monks complete their task, the world will end. If the monks can move 1 disk every day, we can compute the end of the world by computing the total number of disks they must move. As God instructed, it is helpful to name things, so let n be the number of disks, and let mn be the number of moves the monks will need to make. For small values of n, the number of moves can be computed by examining them all. Number of Disks Number of Moves n= mn = 0 0 1 1 2 3 3 7 4 15 5 31 6 63
Two disks: Before moves One disk: After one move Two disks: After one move Two disks: After two moves Two disks: After three moves The trick to discovering the recurrence equation that models this problem is to notice that to move the bottom disk the disks on top of it must be moved twice: once off of the bottom disk and once back on to the bottom disk. Convince yourself that for 4 disks the top 3 disks must be moved twice (offof and onto the bottom disk) and the bottom disk must be moved only once. In notation, m4 = m3 + 1 + m3 = 2m3 + 1 with initial condition m0 = 0. If you've studied the example, perhaps you've noticed the Mersenne numbers are computed by the function mn = 2n  1. Mathematical induction furnishes a proof the function solves the recurrence equation.
The numbers mn = 2n  1, n = 0, 1, 2, . . . are called Mersenne numbers. They are fundamental in computing. Oh yes, moving one disk per day, the world will end in 264  1 days 1019.2 days 4.3 1016 years, that's about 43 quadrillion years. In general, the number of moves mn can be computed from the recurrence equation mn = 2mn1 + 1 cse 1400 applied discrete mathematics mathematical induction 8 Basis: For n = 0, there are no moves and m0 = 20  1 = 0 also. Induction: If mn1 = 2n1  1, then mn = 2mn1 + 1 = 2n  1 = 2 (2n 1  1 ) + 1 1.3 Rabbit Population Growth and Fibonacci Numbers
Overrun by rabbits, Fibonacci determined to model their growth. He let Fn name the number of pairs of rabbits alive during month n. Fibonacci's rules for bunny growth are: 1. In the beginning there were no pairs of rabbits: F0 = 0. 2. At the first instance of bunny time, God created an original pair of rabbits: F1 = 1. 3. At one month of age the pair mated: F2 = F1 = 1. 4. At two months of age they produced a pair of offspring: F3 = F2 + 1 = 2 5. Each pair repeated the same cycle every month. 6. No pair every perishes. From these facts we can deduce that the number of pairs alive during cycle n is the sum of pairs alive during cycle n  1 plus pairs alive during cycle n  2 all of whom produce a pair of offspring. That is, Fn = Fn1 + Fn2 Bunny time Original pair First Generation Second Generation Third Generation Fourth Generation Totals 0 0 1 1 2 1 3 1 1 4 1 1 1 5 1 1 1 2 0 5 6 1 1 1 2 3 8 1 1 2 3 cse 1400 applied discrete mathematics mathematical induction 9 The sequence of numbers generated by this scheme are called Fibonacci numbers. Fibonacci numbers can be computed by the recurrence equation Fn = Fn1 + Fn2 with initial condition F0 = 0 and F1 = 1. The Fibonacci numbers can also be computed by the function Fn = where = (1 + is the golden ratio and = is its conjugate root. Basis: For n = 0, F0 = 0 is given, and the function = 0 also. 5 Because of the stronger recurrence we must prove a stronger basis for induction. That is, for n = 1, F1 = 1 is given, and the function
1  1 5 0  0 This is stronger form of recurrence. It requires an assignment of values to two initial condition: F0 = 0 and F1 = 1. and are the zeros of the polynomial equation x2  x  1 = 0 In particular, 2 = + 1 and 2 = + 1 n  n 5 5)/2 1.618033 1 5 0.618033 2 = 1 also. cse 1400 applied discrete mathematics mathematical induction 10 Induction: If Fn2 = n 2  n 2 5 and Fn1 = n 1  n 1 , 5 then Fn = Fn1 + Fn2 n 2  n 2 n 1  n 1 + 5 5 n 2 ( + 1 )  n 2 ( + 1 ) = 5 n 2 ( 2 )  n 2 ( 2 ) = 5 n  n = 5 = 1.4 Induction on Arithmetic and Geometric Sequences
Summations occur in many applications. Sums over an arithmetic sequence are common. An arithmetic sequence has terms given by the function an = mn + b for n Z The terms an in an arithmetic sequence lie along a straight line with slope m and yintercept b. A linear function is given by the formula y = f ( x ) = mx + b where m is called the slope of the line; and b is the yintercept cse 1400 applied discrete mathematics mathematical induction 11 Let t(i, n, m, b) denote the sum of ak as k goes from i to i + n  1 in increments of 1. t(i, n, m, b) =
i k <i + n ak = i k <i + n (mk + b)
The formula for t(i, n, m, b) looks formidable, but it is just the number of terms n times the average of the first and last term in the sum. The sum of the first n natural numbers t(0, n, 1, 0) = n(n  1)/2 is an instance of the general formula. These triangular numbers occurs by setting i = 0, m = 1 and b = 0. This sum is computed by the function t(i, n, m, b) = n a i + a i + n 1 2 [mi + b] + [m(i + n  1) + b] =n 2 mn(n  1) = n(mi + b) + 2 That this function correctly computes the value of the sum can be established by mathematical induction on n, the number of terms in the sum. Basis: For n = 0, the sum is over the empty range i k < i. This is the empty sum, and its value is defined to be 0. It can be seen that when n = 0, the formula t(i, 0, m, b) = 0. This establishes the basis for induction. cse 1400 applied discrete mathematics mathematical induction 12 Induction: If t(i, n, m, b) = n(mi + b) + then t(i, n + 1, m, b) = t(i, n, m, b) + [m(i + n) + b] mn(n  1) 2
You deserve an A in algebraic manipulation if you follow this reasoning and can recreate it yourself. = n(mi + b) + = = = = mn(n  1) + [ m (i + n ) + b ] 2 mn(n  1) (n + 1)(mi + b) + + mn 2 mn(n  1) 2mn (n + 1)(mi + b) + + 2 2 mn(n  1) + 2mn (n + 1)(mi + b) + 2 mn(n + 1) (n + 1)(mi + b) + 2 This establishes the form of the function is preserved when n is incremented by 1. A geometric sequence has terms given by the function gn = br n for r = 0 and n Z The sum of gk for k incrementing by 1 from i to i + n  1 is g(i, n) =
i k <i + n gk = i k <i + n br k It can be discovered that this sum can be computed by the function g(i, n) = bri rn  1 r n +i  r i =b r1 r1 That this function is correctly computes the value of the sum can be established by mathematical induction on n, the number of terms in the sum Basis: For n = 0, the sum is over the empty range i k < i. This is the empty sum, and its value is defined to be 0. It can be seen that when n = 0, the formula g(i, 0) = 0. This establishes the basis for induction. Induction: If g(i, n) = bri r n i  1 r1 cse 1400 applied discrete mathematics mathematical induction 13 then g(i, n + 1) = g(i, n) + bri+n rn  1 + bri+n r1 rn  1 = bri + rn r1 r n  1 r n (r  1) = bri + r1 r1 = bri = bri = bri r n +1  1 r1 r n  1 + r n +1  r n ) r1 This establishes the form of the function is preserved when n is incremented by 1. 2 Problems on Induction 1. Use mathematical induction to prove the sum of the first n natural numbers is n(n  1)/2. That is,
0 k < n k= n ( n  1) 2 2. Use mathematical induction to prove the sum of the first n powers of 2 is 2n  1. That is,
0 k < n 2k = 2n  1 3. Use mathematical induction to prove the sum of the even natural numbers from 0 to 2n is n(n + 1). That is,
k =0 2k = n(n + 1) n 4. Use mathematical induction to prove the sum of products consecutive pairs of natural numbers is the product of three consecutive number divided by 3, that is,
n 1 k =0 k ( k  1) = n(n  1)(n  2) 3 5. Use mathematical induction to prove the summation formula 1 n = (2k  1)(2k + 1) 2n + 1 k =1 n is true for all natural numbers n 0. cse 1400 applied discrete mathematics mathematical induction 14 6. Use mathematical induction to prove the sum the cubes is a square, that is,
n 1 k =0 k3 = n ( n  1) 2 2 7. Use mathematical induction to prove the sum of k times k! from k = 0 to k = n  1 is n!  1
n 1 k =0 k k! = n!  1.
n 8. Use mathematical induction to prove the summation formula 1 1 < 2 2 n k k =1 is true whenever n is a natural number greater than 1. 9. Prove 6 divides 7n  1 for all natural numbers n. 11. Prove the function T (n) = 3n  2 satisfies the recurrence equation Tn = 3Tn1 + 4 12. Prove the function T (n) = lg(n) satisfies the recurrence equation T2n = Tn + 1 with initial condition T1 = 0. 13. Use mathematical induction to prove that sn = 2n + 3n solves sn = 5sn1  6sn2 with initial conditions s0 = 2, s1 = 5. 14. Let Fn denote a term in the Fibonacci sequence n 0 1 2 3 4 5 6 Fn 0 1 1 2 3 5 8 7 13 8 21 9 34 ... ... with initial condition T0 = 1 10. Prove n! 2n for all natural numbers n 4. (a) Use mathematical induction to show that the sum of the first n Fibonacci numbers is a Fibonacci number minus one. Specifically, show that F0 + F1 + + Fn1 = Fn+1  1 (b) Use mathematical induction to prove that Fn 2Fn1 (c) Use induction over k to prove that Fn+k = Fk Fn+1 + Fk1 Fn for n 2. cse 1400 applied discrete mathematics mathematical induction 15 (d) Prove that for n 1 gcd( Fn , Fn1 ) = 1 (e) Prove that the sum of the first n  1 Fibonacci numbers is 1 less than the n + 1 Fibonacci number. That is, Fn = 1 +
n 2 k =0 Fk if n 2 (f) Prove that the sum of the oddindexed Fibonacci numbers up to F2n+1 equals F2n+2 . That is, k =0 F2k+1 = F2n+2 n (g) Prove that k =0 F2k = F2n+1  1
= n (h) Prove that n n1 n2 0 + + ++ 0 1 2 n
2 Fn+1 Fn1  Fn = (1)n , k =0 n nk k = Fn+1 (i) Prove Cassini's identity for n > 0 where Fk is a Fibonacci numbers number. (j) Define the Lucas numbers Ln by Ln = Ln1 + Ln2 , for n > 1, i. Show that the Lucas numbers Ln satisfy the equation L0 = 2, L1 = 1 Ln = Fn+1 + Fn1 ii. Prove that F2n = Fn Ln where Fn is a Fibonacci number. 15. Prove that the sum of terms in a column of Pascal's triangle equals a term in the next column, that is,
n 1 k=m k m = n , m+1 n m+1 16. Prove that the sum of term in a row of Pascal's triangle equals a power of 2, that is, k =0 n n k = 2n 17. Use mathematical induction to prove that the Harmonic solve the recurrence equation
n 1 k =1 Hk + n = nHn CSE 1400 Applied Discrete Mathematics Sequences
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 1.7 Sequences 1
2 3 5 6 8 Operations on Sequences Useful Sequences Growth Rates Defined by Recurrence Equations Computed by Algorithms NonComputable Sequence
Abstract Defined by Functions on the Natural Numbers 8 9 1 Sequences Sequences are ordered lists of values. Ordinal numbers: first, second, third, fourth, . . . , specify the positions of these values. One famous sequence is the Fibonacci sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . The first, second, third, fourth, and fifth Fibonacci numbers are 0, 1, 1, 2, and 3. The values in the Fibonacci sequence can be named f k where the subscript k denotes the position of the value. In computing, it is customary to start the subscript k at 0 so that the first, second, third, fourth, and fifth Fibonacci numbers are named f 0 , f 1 , f 2 , f 3 , and f 4 . Let S = s0 , s1 , s2 , s3 , s4 , . . . be a sequence. The subscripted names s0 , s1 , s2 , s3 , s4 , . . . , are called terms and they refer to values in the first, second, third, fourth, fifth, etc., positions of the sequence. In computing theory, sequences cse 1400 applied discrete mathematics sequences 2 contain a countably infinite number of terms. In computing practice, sequences have a finite number of terms. For instance, the sequence of primes less than 30 is P< 30 = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 There is a a sequence with no terms at all, called the empty sequence. I'll use to denote the empty sequence, so that = . 1.1 Operations on Sequences
There are some basic operations that can be performed on sequences. empty() maps a sequence to True or False. True if S is empty null(S) = False if S contains at least one term length(S) = n head() maps a nonempty sequence to its first element head(S) = s0 last() maps a nonempty, finite sequence to its last element last(S) = sn1 tail() removes the first term from a sequence tail(S) = s1 , s2 , s3 , . . . , sn1 concat(,) concatenates two finite sequences to form a single sequence concat(S, T ) = s1 , s2 , . . . , sn1 , t0 , t1 , . . . , tm map(,) applies a function f to each term of a sequence map( f , S) = f (s1 ), f (s2 ), . . . , f (n1 ) length() maps a finite sequence to the number of terms it contains. cse 1400 applied discrete mathematics sequences 3 1.2 Useful Sequences
Here is a list of useful sequences. The Alice sequence A = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . . keeps a "tally." The Gauss sequence G = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 . . . computes the sum of a "tally." The sequence of triangular numbers T = 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, . . . computes the number of edges in a complete graph. The doubling sequence D = 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, . . . computes a common growth model. The Mersenne sequence M = 0, 1, 3, 7, 15, 31, 63, 127, 255, 511 . . . computes the sum of the doubling growth model. The factorial sequence n! = 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, . . . computes the ways to order things. The Fermat sequence F = 3, 5, 17, 257, 65537, 4294967297, . . . computes the ways to order things. The Fibonacci sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 . . . computes an interesting growth rate based on the golden ratio . cse 1400 applied discrete mathematics sequences 4 The sequence of prime numbers P = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, . . . are fundamental to the understanding of number theory. The sequence of composite numbers C = 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, . . . are likewise fundamental in number theory. The divisor sequence = 1, 2, 2, 3, 2, 4, 2, 4, 3, 4, . . . counts the divisors of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 . The relations sequence R = 1, 2, 16, 512, 65536, 33554432, . . . counts the number of relations on an n element set for n = 0, 1, 2, 4, . . .. The sequence of binomial coefficient B = 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, . . . counts the number of melements subsets of an nelement set as m ranges from 0 to n and n goes from 0 onward. The Catalan sequence = 1, 1, 2, 5, 14, 42, 132, 439, . . . counts the number of binary trees with n nodes for n = 0, 1, 2, 3, 4, . . . Stirling numbers of the first kind S1 = 1, 0, 1, 0, 1, 1, 0, 2, 3, 1, 0, 6, 11, 6, 1, . . . counts the number of mcycle permutations of an nelement set as m ranges from 0 to n and n goes from 0 onward. Stirling numbers of the second kind S2 = 1, 0, 1, 0, 1, 1, 0, 1, 3, 1, 0, 1, 7, 6, 1, . . . counts the number of msubset partitions of an nelement set as m ranges from 0 to n and n goes from 0 onward. The sequence of harmonic numbers H= 0, 1 3 11 25 137 , , , , ,... 1 2 6 12 60 cse 1400 applied discrete mathematics sequences 5 1.3 Growth Rates
The above examples show that values of terms in many sequence increase as the position in the sequence increases. The above examples also show that values of terms in some sequence oscillate. In any case, we can often roughly describe a sequence by saying its order of growth is bounded by some function. A sequence of constants c, c, c, c, . . . is said to be of order 1, or bigOh of 1, written O(1). A arithmetic sequence b, a + b, 2a + b, 3a + b, . . . is said to be of order n, or bigOh of n, written O(n). This is a linear rate of growth. The triangular 0, 0, 1, 3, 6, . . . , n(n  1)/2, . . . is said to be of order n2 , or bigOh of n squared, written O(n2 ). This is a quadratic rate of growth. A geometric sequence 1, a, a2 , a3 a4 , . . . is said to be of order a to the n, or bigOh of a to the n, written O( an ). This is an exponential rate of growth. The doubling, Mersenne, and Fibonacci sequence grow exponentially The doubling and Mersenne sequences grow like 2n d n = 2n
1+ 5 2 . n m n = 2n  1 The Fibonacci sequence grows like n , where is the golden ratio, which is equal to f n = O( ) = O 1+ 5 2 n The factorial sequence grows like the function 2n n e n The sequence of Harmonic numbers grow like ln(n) Polynomial or slower growth is called tractable, which loosely means that an algorithm with polynomial time complexity can be solves problems in a reasonable amount of time. Tractable problems are considered easy. Exponential grow is called intractable, which loosely means that an algorithm with exponential time complexity takes an unacceptable amount of time solve problems. It is hard to solve with an intractable problems. cse 1400 applied discrete mathematics sequences 6 1.4 Defined by Recurrence Equations
Terms in many sequences can be computed by using a recurrence equation. Let S = s0 , s1 , s2 , s3 , s4 , . . . be a sequence. A recurrence equation computes sn as an expression involving previous sequence values s0 , s1 , s2 , . . . , sn1 . For instance, terms in the Fibonacci sequence can be computed by the recurrence equation. f n = f n1 + f n2 , n N, n 2 To be used, initial values for f 0 and f 1 must be specified. In particular, set f 0 = 0 and f 1 = 1 to compute the values f2 = f0 + f1 = 0 + 1 = 1 f3 = f2 + f1 = 1 + 1 = 2 f4 = f3 + f2 = 2 + 1 = 3 . . . Here is list of recurrence relations for some useful sequences. Terms in the Alice sequence can be computed by the recursion a n = a n 1 n Z+ = {1, 2, 3, 4, . . .} and initial condition a0 = 1. Terms in the Gauss sequence can be computed by the recursion g n = g n 1 + 1 and initial condition g0 = 1. Terms in the sequence of triangular numbers can be computed by the recursion t n = t n 1 + ( n  1 ) and initial condition t0 = 0. Terms in the sequence of doubling numbers can be computed by the recursion dn = 2dn1 n Z+ = {1, 2, 3, 4, . . .} n Z+ = {1, 2, 3, 4, . . .} n Z+ = {1, 2, 3, 4, . . .} and initial condition d0 = 1. cse 1400 applied discrete mathematics sequences 7 Terms in the Mersenne sequence can be computed by the recursion mn = 2mn1 + 1 and initial condition m0 = 0. Terms in the factorial sequence can be computed by the recursion n! = n(n  1)! n Z+ = {1, 2, 3, 4, . . .} n Z+ = {1, 2, 3, 4, . . .}, 0! = 1 and initial condition 0! = 1. Terms in the Fibonacci sequence can computed by the recursion f n = f n 1 + f n 2 , n {2, 3, 4, . . .} and two initial conditions f 0 = 0 and f 1 = 1. Terms in the sequence of harmonic numbers can computed by the recursion 1 n Z+ Hn = Hn1 + n and initial condition H0 = 0. Terms in the Catalan sequence are computed by the recursion c n = c 0 c n 1 + c 1 c n 2 + + c n 2 c 1 + c n 1 c 0 and initial condition c0 = 1. Terms in the binomial sequence can be computed by the recursion n m
The recursion for Catalan numbers is called a convolution. n N = n1 n1 + m1 m n, m N, n m and boundary conditions (n) = 1 and (n) = 1 0 n Stirling numbers of the first kind can be computed by n n1 n1 = + ( n  1) , n>0 m m1 m and boundary conditions [n] = 1 and [n] = 1 0 n Stirling numbers of the second kind can be computed by n m n1 n1 +m , n>0 m1 m = and boundary conditions {n} = 1 and {n} = 1 0 n cse 1400 applied discrete mathematics sequences 8 1.5 Defined by Functions on the Natural Numbers
Terms in many sequences can be computed by using simple functions. Here is short list of useful sequences and the simple functions that compute the value of their terms. Terms in the Alice sequence are computed by the constant function a(n) = 1 n N = {0, 1, 2, 3, 4, . . .} Terms in the Gauss sequence are computed by the linear function g(n) = n n N Terms in the triangular sequence are computed by the quadratic function t(n) = n ( n  1) 2 n N = {0, 1, 2, 3, 4, . . .} Terms in the Mersenne sequence are computed by the exponential function m ( n ) = 2n  1 n N Terms in the Fermat sequence are computed by the hyperexponential function n r (n) = 22 + 1 n N Terms in the relation count sequence are computed by the function l ( n ) = 2n
2 n N 1.6 Computed by Algorithms
Some sequences do not have simple functions or simple recurrence equations that compute their terms. There is no simple recurrence equation or simple function that will compute the values in the sequence of prime numbers. However there are algorithms that will compute the sequence of prime numbers. These algorithms will not halt because there are a countably infinite number of primes, but given any natural number n, the algorithms will compute all primes less than n. Although there is a simple recurrence equation for the factorial sequence there is no simple function for the terms. Although factorials are often defined by the expression n! = n(n  1)(n  2) (2)(1) cse 1400 applied discrete mathematics sequences 9 with initial condition 0! = 1, this expression is more an algorithm than a function. By extension, computing the value of binomial coefficients by the factorial expression n m = n! m!(n  m)! is more an algorithm, than a simple function. 1.7 NonComputable Sequence
Let S be the set of all countably infinite sequences on the natural numbers, that is, S = S : (S = s0 , s1 , s2 , . . . ) (k N)(sk N) Consider the decision problem: Is every sequence in S computable? That is, for each sequence, is there an algorithm that will compute the sequence's terms? It turns out that the answer is no. There are sequences of natural numbers that cannot be algorithmically computed. It is beyond the scope of this class to present formal definitions of computability, but the basic concepts can be appreciated without complete understanding of the detail. As an introduction, a decision problem is computable if there is a Turing machine that solves the problem. Basically, a Turing machine takes in some input values, runs a program on them, and out puts the answer. Because of the way in which Turing machines are constructed, there are only a countably infinite number of them. That is, there is a onetoone and onto correspondence between Turing machines and the natural numbers N. Therefore, there are only a countably infinite number of sequences. On the other hand, there are more than a countable number of sequences in the set S. Thus, there must sequences of natural numbers that cannot be computed. The halting sequence gives the number of steps Turing machine Tk executes on input Ij . If machine Tk does not halt on input Ij , then define the number of steps to be the symbol . The halting sequence cannot be computed. The busy beaver sequence gives the maximal number of steps an n state Turing machine can make on an initially blank tape and halt. The busy beaver sequence cannot be computed. Most sequences cannot even be described! CSE 1400 Applied Discrete Mathematics Recurrences
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 1.7 Recurrence Equations 1
2 3 3 5 6 6 7 The Alice Recurrence Equation The Gauss Recurrence Equation The Triangular Recurrence Equation The Mersenne Recurrence Equation The Factorial Recurrence Equation The Fermat Recurrence Equation The Fibonacci Recurrence Equation 2
2.1 2.2 2.3 Still More Recurrences
Bisection 7 7
9 12 Newton's Rootfinding Method Dissecting Space with Hyperplanes 3 Problems on Recurrences 16 Abstract The definition of "recursive" that I like is Recursive: adj. See: Recursive "Devil's DP Dictionary," Stan KellyBootle, English computer scientist and author (1929 ) 1 Recurrence Equations Recurrence equations are the discrete analog of differential equations. Recurrence equations have two parts. Recurrence equations are similar to differential equations. Recurrence equations are studied in discrete mathematics, Differential equations studied in continuous mathematics. cse 1400 applied discrete mathematics recurrences 2 1. An equation that describes how new values are computed from previous values. The form a recurrence equation is something like tn = some formula involving tn1 t n 2 , t n 3 , . . . , t 0 and perhaps lower terms such as 2. One or more initial values to seed the computational process. These initial values are given for the first term t0 and perhaps higher terms such as t1 and t2 . There are several basis recurrence equations that occur in discrete mathematics. 1.1 The Alice Recurrence Equation
Alice terms are defined by the recurrence equation equation a n = a n 1 n N, n 1 "Can you do Addition?" the White Queen asked. "What's one and one and one and one and one and one and one and one and one and one?" "I don't know," said Alice. "I lost count." "She can't do Addition," the Red Queen interrupted. "Can you do Subtraction? Take nine from eight." A simple recurrence, but Alice is fundamental to counting. with initial condition a0 = 1. The Alice recurrence generates terms in the unary sequence A = 1, 1, 1, 1, 1, 1, 1, 1, . . . Terms in the Alice sequence can also be computed by the constant function a(n) = 1 n N = {0, 1, 2, 3, 4, . . .} Unary notation for the natural numbers is based on the Alice sequence. Mathematical induction can be used to prove the function a(n) = 1 solves the recurrence equation a n = a n 1 with initial condition a0 = 1. Initial Condition: The function a(n) = 1 correctly computes the initial term a0 = 1. That is, a(0) = 1 since a(n) = 1 for all n N. Induction Premise: Pretend that for some unspecified n, an1 = 1. We know this is true for n = 1. Inductive Conclusion: Use the recurrence equation a n = a n 1 and the premise an1 = 1, to conclude that an = 1. Using the unary alphabet {1} with only the character 1 can name the positive natural numbers 1 = 1 2 = 11, 3 = 111, . . . . Of course, Unary notation wastes space. To write 256 in unary notation requires a string of 256 unary 1's, but only 3 digits or 9 bits. cse 1400 applied discrete mathematics recurrences 3 1.2 The Gauss Recurrence Equation
Gauss terms are computed by the recurrence equation equation g n = g n 1 + 1
The well known story of Gauss summing the natural numbers from 1 to 100 and Gauss' genius at number theory caused me to name the sequence of natural numbers for Gauss. n N, n 1 with initial condition g0 = 0. The Gauss recurrence generates terms in the sequence of natural numbers G = 0, 1, 2, 3, 4, 5, 6, 7, 8, . . . Terms in the Gauss sequence can also be computed by the function g(n) = n n N Mathematical induction can be used to prove the function g(n) = n solves the recurrence equation g n = g n 1 + 1 with initial condition g0 = 0. Initial Condition: The function g(n) = n correctly computes the initial term g0 = 0. Induction Premise: Pretend that for some unspecified n, gn1 = ( n  1). Inductive Conclusion: Using the recurrence equation gn = g n 1 + 1 and gn1 = (n  1), to conclude that gn = (n  1) + 1 = n.
Consider graphs with 1, 2, 3 and 4 nodes. They are fullyconnected if there is an edge between each pair of nodes. The number of edges in such graphs is 0, 1, 3 and 6. This sequence of terms can start with 0, the number of edges in the empty graph. 1.3 The Triangular Recurrence Equation Triangular terms are computed by the recurrence equation t n = t n 1 + ( n  1 ) n N, n 1 with initial condition t0 = 0. The Triangular recurrence generates terms in the fullyconnected numbers T = 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, . . . Terms in the Triangular sequence can also be computed by the function n ( n  1) t(n) = n N 2 Summing terms from the Gauss sequence produces triangles. Some authors define triangular numbers by the function t(n) = n(n + 1)/2 and start with initial condition n = 1. cse 1400 applied discrete mathematics recurrences 4 0 k <7 k = 0 + 1 + 2 + 3 + 4 + 5 + 6 = 21 = 0 1 2 3 4 5 6 7(7  1) 2 6 5 4 3 2 1 0 7(7  1) 2 0 k <7 (6  k) = 6 + 5 + 4 + 3 + 2 + 1 + 0 = 21 = The triangular number tn is the sum of the first n natural numbers. tn = 0 k < n k = 0 + 1 + + ( n  1) + n = n ( n  1) 2 n ( n  1) 2 = 0 k < n ( n  1  k ) = ( n  1) + ( n  2) + + 0 = You can stack pixelated triangles on top one another to create pyrimids. y x z The sum triangular numbers are called pyramidal or tetrahedral numbers. The sequence of pyrimidal numbers is Y = 0, 0, 0, 1, 4, 10, 20, 35, 56, 84, . . . cse 1400 applied discrete mathematics recurrences 5 where terms pn in Y are computed as partial sums of terms in T. pn = 0 k < n k ( k  1) (n  1)(n  2) n(n  1)(n  2) = 0+0+1+3++ = 2 2 32 You could, if you like, stack pyrimid on pyramids in 4dimensional space and create what are called pentatope numbers, but let's stop here. It is useful to write the Alice, Gauss, triangular, and higher order numbers as columns in a twodimensional list. Alice 1 1 1 1 1 1 1 Gauss 0 1 2 3 4 5 6 Triangular 0 0 1 3 6 10 15 Pyrimidal 0 0 0 1 4 10 20 Pentatopic 0 0 0 0 1 5 15 Do you recognize Pascal's triangle in this array? 1.4 The Mersenne Recurrence Equation
Mersenne terms are computed by the recurrence equation mn = 2mn1 + 1 n N, n 1
The Mersenne number 2n  1 is the largest natural number that can be named using n bits. with initial condition m0 = 0. Terms in the Mersenne sequence name the largest natural numbers that can be named binary notation and n bits. M = 0, 1, 3, 7, 15, 31, 63, 127, 255, . . . Terms in the Mersenne sequence are computed by the function m ( n ) = 2n  1 mersenne :: Natural > Natural mersenne n = 2**n  1 n N or
mersenne :: Natural > Natural mersenne 0 = 0 mersenne n = 2 * mersenne (n1) + 1 Mathematical induction can be used to prove the function m(n) = 2n  1 solves the recurrence equation mn = 2mn1 + 1 with initial condition m0 = 0. Initial Condition: The function m(n) = 2n  1 correctly computes the initial term m0 = 0, that is, m(0) = 0. Induction Premise: Pretend that for some unspecified n, mn1 = 2n1  1. We know this is true for n = 1. Figure 1: Haskell function that computes Mersenne numbers. cse 1400 applied discrete mathematics recurrences 6 Inductive Conclusion: Use the recurrence equation mn = 2mn1 + 1 and the premise mn1 = 2n1  1 to write mn = 2mn1 + 1 = 2 (2n 1  1 ) + 1 = 2n  1 The largest known prime is the Mersenne number 243112609  1 which has 12, 978, 189 digits The Mersenne numbers are a rich source for large prime numbers. You too can join the Great Internet Mersenne Prime Search (GIMPS) at http://www.mersenne.org/ 1.5 The Factorial Recurrence Equation Factorial terms are computed by the recurrence equation f n = n f n 1 n N, n 1
The common notation is n! read "n factorial." with initial condition f 0 = 1. Terms in the Factorial sequence count the number of permutations of n distinct things . n! = 1, 1, 2, 6, 24, 120, 720, 5040, . . . While there is no simple function that computes n! Stirling's approximations n n n! 2n e is a remarkably accurate formula for n!. factorial :: Natural > Natural factorial 0 = 1 factorial n = n * factorial (n1) 1.6 The Fermat Recurrence Equation
Fermat terms are computed by several recurrence equations r n = ( r n 1  1 )2 + 1 rn = rn = rn1 + 22
2 r n 1
n 1 Figure 2: Haskell function that computes factorials. r n = r 0 r n 1 + 2  2 ( r n 2  1 )2 r 0 r n 2 with initial condition r0 = 3. The solution to each of these recurrences is the function r (n) = 22 + 1 The sequence of Fermat terms is R = 3, 5, 17, 257, 65 537, 4 294 967 297, . . . That r (n) = 22 + 1 solves each of the recurrences above can be demonstrated by mathematical induction.
n n n N Terms in the Fermat sequence are 1 more than the count of Boolean functions on n Boolean variables. That is, the Fermat sequence is important because it closely counts the number of different Boolean functions in n variables. cse 1400 applied discrete mathematics recurrences 7 Initial Condition: The function r (n) = 22 + 1 correctly computes the 0 initial term r0 = 3, that is, r (0) = 22 + 1 = 21 + 1 = 3. Induction Premise: Pretend that for some unspecified n, rn1 = n 1 22 + 11. We know this is true for n = 1. Inductive Conclusion: Use the recurrence equation r n = ( r n 1  1 )2 + 1 and the premise rn1 = 22
n 1 n + 1 to write r n = ( r n 1  1 )2 + 1 = ( 22 = 22
2n n 1 )2 + 1 +1 n 1 2 = 2 +1 1.7 The Fibonacci Recurrence Equation
Terms in the Fibonacci sequence can computed by the recursion Fn = Fn1 + Fn2 , n N, n 2
fibonacci :: Natural > Natural fibonacci 0 = 0 fibonacci 1 = 1 fibonacci (n) = fibonacci (n1) + fibonacci(n2) with initial conditions F0 = 0 and F1 = 1. F = 0, 1, 1, 2, 3, 5, 8, 13, 21, . . . The golden ratio = (1 + 5)/2 1.618033 and its conjugate = (1  5)/2 0.618033 can be used to write Fibonacci numbers as n  n Fn = 5 Figure 3: Haskell function that computes Fibonacci numbers. Since 2 Still More Recurrences 2.1 Bisection
There are several problems that can be solved by one "test" that narrows the solution space by onehalf. This bisection solution technique can be described by the recurrence equation b2n = bn + 1 which can be interpreted as stating that "to solve a problem of size 2n, do 1 thing and then solve a problem of size n." For instance to find the word "mouse" in the sorted list The Fibonacci number Fn is approximately 1.6Fn1 which makes the Fibonacci sequence a good way to translate from miles to kilometers: One mile is about 1.6 kilometers. For instance, 30 miles written in Fibonacci numbers is 30 = 21 + 8 + 1 which is approximately 34 + 13 + 2 = 49 kilometers. n lim n = 0 cse 1400 applied discrete mathematics recurrences 8
aarvark, brown, dog, fox, green, kelp, jumped, lazy, mouse, over, quick, purple, skunk, the, zebra Compare "mouse" to "lazy," the middle word in the list. Seeing they are not equal eliminates half the words to be searched. Then compare "mouse" to "quick" the middle word of the last half. Seeing they are not equal eliminates the upper quarter the words to be searched. Continuing in this manner locates "mouse" in 4 comparisons. lazy quick jumped green kelp over Dictionaries, telephone books, and other lookup tables are sorted to enable quick searches. fox brown aardvark dog the zebra mouse purple skunk In a similar manner, the zero of a function can be located by the bisection rootfinding method. For instance, the function f ( x ) = x3  x2  2x + 1 changes sign from x = 0 to x = 1. 1. Evaluating f ( x ) at x = 0.5 allows the interval [0.5, 1.0] to be discarded. 2. Evaluating f ( x ) at x = 0.25 allows the interval [0.0, 0.25] to be discarded. 3. Evaluating f ( x ) at x = 0.375 allows the interval [0.25, 0.375] to be discarded. 4. Evaluating f ( x ) at x = 0.4375 allows the interval [0.375, 0.4375] to be discarded. In only 4 steps the search domain has been reduced from length 1 to length 0.0625. cse 1400 applied discrete mathematics recurrences 9 The logarithmic function bn = lg n satisfies the recurrence equation b2n = bn + 1. This can be verified by substitution into the equation. b2n = lg 2n = lg 2 + lg n = 1 + lg n = 1 + bn 2.2 Newton's Rootfinding Method
Newton devised a fast method to compute roots or zeros of a function f ( x ). A root of f ( x ) is a value of x such that f ( x ) = 0. Newton's method is to 1. Guess an initial value x0 to be a root of f ( x ). 2. Construct the sequence x n = x n 1  f ( x n 1 ) f ( x n 1 ) (1) where f ( x ) is the derivative of f ( x ). One application of Newton's method is the computation of square roots. For instance, the square root of 2 is a zero of the function f ( x ) = x2  2. That is, 2 ia a root of the equation x2  2 = 0 cse 1400 applied discrete mathematics recurrences 10 2 In this case, f ( x ) = 2x, so that substituting into equation 1 yields the recurrence equation x n = x n 1 
2 x n 1  2 2xn1 = = 2 x n 1 2 + 2xn1 2xn1 x 1 = n 1 + 2 x n 1 1 2 = x n 1 + 2 x n 1 2 2xn1 x2  2  n 1 2xn1 2xn1 Starting with an initial guess that x0 = 1 is equal to 2 the recur rence generates the sequence of approximations to 2
1, or in fixedpoint notation 1.0, 1.5, 1.4666 , 1.41421568627 , . . . which is accurate to five decimal places. Although Newton's name is attached this method the basic idea was known to ancient mathematicians of Mesopotamia, the region of modern day Iraq and Iran. Clay tablets dated from around 1800 B.C. to 1600 B.C. have been found there that show how to compute 2. These ancients considered an isosceles right triangle with legs of length 1 h 1 1 We know from the Pythagorean theorem that 12 + 12 = h2 3 17 577 , , ,... 2 12 408 so that the hypotenuse h has length h = 2 1.41421356 The Babylonians' knew how to approximate the value of h = 2 to many decimals places, although they used sexagesimal notation. Although it is not certain what reasoning the Babylonians' used, their calculations indicate this is what they did: cse 1400 applied discrete mathematics recurrences 11 Let h0 = 1 be an initial approximation to 2 Clearly 1 is too small as the Babylonians' could easily measure If 1 = 2, then 1 1 = 2 2 = 2 and 2/1 = 2 As it is, 2/1 is too large The average of the under estimate 1 and the over estimate 2/1 provides a better approximation to 2, call this h1 = 1 2 h0 + 2 h0 = 1 2 1+ 2 1 = 3 2 But h1 = 3/2 is too large as the Babylonians' could measure If 3/2 were the exact square root, then 2/(3/2) = 4/3 would equal 2 As it is, 4/3 1.333 is too small The average of the over estimate 3/2 and the under estimate 4/3 will provide a better approximation h2 = 1 2 h1 + 2 h1 = 1 2 3 4 + 2 3 = 17 1.41166 12 But h2 = 17/12 is too small The Babylonians' carried out this iteration a few more times com puting the 2 accurately to at least 9 decimal places That is, they next computed the average of h2 = 17/12 and 2/h2 = 24/17 h3 = 1 2 1 = 2 1 = 2 h2 + 2 h2 17 24 + 12 17 289 + 288 17 12 1.41421568628 Newton generalized this idea and his method is one of the best rootfinding methods ever devised. cse 1400 applied discrete mathematics recurrences 12 2.3 Dissecting Space with Hyperplanes
Consider this problem: Given an infinite straight line stretching in both directions what is the maximum1 number of regions the line can be cut into by using m points? Using m = 1, m = 2, and m = 3 points, it is fairly clear that 2, 3, and 4 regions are the most there are. m = 1, two regions m = 2, three regions m = 3, four regions And from these examples confidently conclude that when m points are used, the maximum number of regions is m + 1. This can be recorded in a table Points Regions 1 2 2 3 3 4 4 5 5 6 1 What if you changed the problem to minimum number of regions? m Notice you could start at m = 0 and include the column 0 1 Can you write an explanation of this observation in English? Can you use induction in your explanation? m+1 A more challenging problem is: What is the maximum number of regions the Euclidean plane can be cut into by m straight lines? It is fairly clear that When m = 0 the plane is undivided and there is 1 region When m = 1 the plane is divided into 2 regions When m = 2 the plane can divided into as many as 4 regions And, when m = 3 the plane can divided into as many as 7 regions 2 1 7 4 6 5 3 This data can also be collected into a table. Lines Regions 0 1 1 2 2 4 3 7 4 11 5 16 m ? cse 1400 applied discrete mathematics recurrences 13 I've included columns for 4 and 5 lines, but left the general formula as a question. Even more difficult to visualize is the maximum number of regions that 3 dimensional Euclidean space can be cut into by m flat planes. It turns out the sequence of regions starts out as 1, 2, 4, 8, 15, 26, . . .. Although it may appear strange, it is useful to consider 0 dimensional space, a point, and how many regions it can be cut into, which of course is always 1. Collecting all of this data into one table allows a pattern to emerge. Hyperplanes Regions in 0 Dimensions Regions in 1 Dimension Regions in 2 Dimensions Regions in 3 Dimensions 0 1 1 1 1 1 1 2 2 2 2 1 3 4 4 3 1 4 7 8 4 5
An n  1 dimensional space in an n dimensional space is called a hyperplane. That is, a point is a hyperplane on a line; a line is a hyperplane on a plane, a plane is a hyperplane in 3 dimensional space; and 3 dimensional space is a hyperplane in 4 dimensional space. 1 1 5 6 11 16 15 26 1 m+1 ? ? m It appears that if you add two consecutive numbers in a column the sum is the value in the next column, for instance, 7 + 8 = 15 and 5 + 11 = 16. To express this observation a notation is needed for the values in the table. The depend on two variables: The dimension of the space being cut up and the number of hyperplanes. Let's agree to use n for the dimension of the space and m for the number of hyperplanes. Let's also agree to use the notation n m for the values in the table. Using this notation the observation that sums of values in a column yields the value in the next column can be written as n1 n n + = m m1 m1 For instance 2 = 11 4 3 = 26 5 and This is called a recurrence equation. It computes values in the table using previously computed values. Have you seen anything similar to this? Consider this table. 0 0 1 2 3 4 5 1 1 1 1 1 1 1 0 1 2 3 4 5 2 0 0 1 3 6 10 3 0 0 0 1 4 10 4 0 0 0 0 1 5 5 0 0 0 0 0 1 m 0 0 0 0 0 0 cse 1400 applied discrete mathematics recurrences 14
n Use the notation (m) for the value in row n, column m. What is the recurrence equation for the above table? What is an interpretation of the values? Here are two other tables of useful numbers. Do you see the recurrence in them? 0 0 1 2 3 4 5 1 0 0 0 0 0 0 0 1 2 3 4 5 1 0 0 0 0 0 1 2 3 0 0 0 1 6 35 3 0 0 0 1 6 25 4 0 0 0 0 1 10 4 0 0 0 0 1 10 5 0 0 0 0 0 1 5 0 0 0 0 0 1 0 0 1 0 1 1 2 3 6 11 24 50 1 0 1 1 1 1 1 2 0 0 1 3 7 15 m 0 0 0 0 0 0 m 0 0 0 0 0 0 n n Use the notation [m] for the value in the first table and {m} for second table. Let's return to the table that counts the maximum number of regions cut by hyperplanes and find functions for the values. Hyperplanes Regions in 0 Dimensions Regions in 1 Dimension Regions in 2 Dimensions Regions in 3 Dimensions 0 1 1 1 1 1 1 2 2 2 2 1 3 4 4 3 1 4 7 8 4 5 1 1 5 6 11 16 15 26 m 1 m+1 ? ? The function for values in the 0 dimensions row is a polynomial of degree 0, that is p0 (m) = 1. And, the function for values in the 1 dimension row is a polynomial of degree 1, that is p1 (m) = m + 1. It is reasonable to conjecture that the function for values in the 2 dimensions row is a polynomial of degree 2, that is p2 (m) = am2 + bm + c for some coefficients a, b and c. We can compute these values by computing differences and then using Newton's finite difference formula. Please check that p2 (m) = 1 + m(m + 1)/2 correctly computes the values in the table. cse 1400 applied discrete mathematics recurrences 15 p2 ( m ) 1 1 2 2 4 3 7 4 11 5 16 p2 ( m ) = p2 (0) + p2 (0) m + p2 (0) m ( m  1) 2 1 1 0 1 0 1 0
2 3 m ( m  1) 2 m ( m + 1) = 1+ 2 = 1+m+ In the same manner the formula for p3 (m) can be found. p2 ( m ) 1 1 2 2 4 4 8 7 15 11 26 p3 (0) m ( m  1) + 2 m(m  1) m(m  1)(m  2) = 1+m+ + 2 6 2  1) m(m = 1+m+ 6 p3 (0) m + p3 (0) m(m  1)(m  2) 6 4 3 1 2 1 0 1 1 0
2 3 4 Please check that p3 (m) = 1 + m + m(m2  1)/6 correctly computes the values in the table. p3 ( m ) = p3 (0) + cse 1400 applied discrete mathematics recurrences 16 Consider Pascal's triangle 0 0 1 2 3 4 5 1 1 1 1 1 1 1 0 1 2 3 4 5 2 0 0 1 3 6 10 3 0 0 0 1 4 10 4 0 0 0 0 1 5 5 0 0 0 0 0 1 m 0 0 0 0 0 0
The Kleene star notation 0 means a repeated, unending sequence of zeros. And a row of it, say 1, 3, 3, 1, 0 What happens when you construct a differrence table for it?
3 (m) 1 2 3 4 2 3 0 3 1 0 0 2 1
0 3 Problems on Recurrences 1. Find a recurrence equation and initial condition that enumerates the sequence of even natural numbers. 2. What change(s) must be made to your answer to problem 1 to enumerate the sequence of odd natural numbers? 3. Use mathematical induction to prove the following recurrence equations and initial conditions are solved by the given functions. (a) tn = 3tn1 , t0 = 2, t(n) = 2 3n . (b) tn = 3tn1 + 2, t0 = 0, t(n) = (c) tn = 5tn1  6tn2 , t0 t ( n ) = 2n + 3n . (d) tn = 2tn1 + tn2 , t0 = 2, t1 = 2, t(n) = (1 + 2)n + (1  2)n .  1. = 2, t1 = 5, 3n 4. Let A = a0 , a1 , a2 , . . . , an , . . . be an arithmetic sequence sequence. That is, terms in A are given by a linear function a(n) = mn + b for some slope m and yintercept b. Find a recurrence equation and initial condition that enumerates the terms in the sequence. 5. Let G = g0 , g1 , g2 , . . . , gn , . . . be a geometric sequence sequence. That is, terms in G are given by a exponential function g(n) = br n for some ratio r and yintercept b. Find a recurrence equation and initial condition that enumerates the terms in the sequence. cse 1400 applied discrete mathematics recurrences 17 6. Use mathematical induction to prove that the common logarithm function Tn = log(n) satisfies the recurrence equation T10n = Tn + 1 with initial condition T1 = 0. 7. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence r n = r n  1 + 22 with initial condition r0 = 3. 8. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence
2 r n = r n 1  2 ( r n 2  1 )2
n n 1 n r 0 r n 2 with initial condition r0 = 3. 9. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence r n = r 0 r n 1 + 2 with initial condition r0 = 3. 10. Morse code is a series of dots () and dashes (). Pretend a dot can be typed in 1 second while a dash takes 2 seconds to type. Find a recurrence equation that describes how many messages can be typed in n seconds. 11. In how many ways can n 1 be expressed as a sum of 1's and 2's? Different term orders are considered different sums. 12. A domino is a rectangular tile 1 unit long and 2 units high
n Dominos can be laid out to tile an n 2 area. For example, there are 2 ways to tile a 2 2 area And 3 ways to tile a 3 2 area: 13. Pretend you invested $1 on January 2, 2010. Pretend interest accrues at an annual compound rate of 10%. (For example, on January 2, 2011 and January 2, 2012 you will have $1.10 and $1.21 in your account.) How many years will you need to wait to save over $1, 000, 000? 14. Pretend you invested $1 on January 2 every year. Pretend interest accrues at an annual compound rate of 10%. (For example, on January 2, 2011 and January 2, 2012 you will have $2.10 and $1.00 + $2.10 + $0.21 = $3.31 in your account) How many years will you need to wait to save over $1, 000, 000? 15. Pretend you invested $1 on the second day of every month. Pretend interest accrues at an monthly compound rate of 10%. How many months will you need to wait to save over $1, 000, 000? Find a recurrence relation that counts the number of n 2 tilings. cse 1400 applied discrete mathematics recurrences 18 16. Consider the sequence generated by adding the alternating integers 1, 2, 3, 4, 5, . . .. The first few sums of these alternating integers are 1, 1, 2, 2, 3, . . . Find a function f (n) that generate these partial sums. That is, f (0) should equal 1, f (1) should equal 1, f (2) should equal 2, f (3) should equal 2, and so on. , a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb, . . . Name the terms in this sequence sn so that s0 = , s1 = a = s0 a, s2 = s0 b, s3 = s1 a = aa, s4 = s1 b = ab, and so on. Find a recursion equation that models the generation of these alphabetically ordered strings. 17. Consider the strings of over the alphabet { a, b} listed in order by length then alphabetically, that is, CSE 1400 Applied Discrete Mathematics Definitions
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 Definitions
Arithmetic 1
1 2 4 4 Alphabets, Strings, Languages, & Words Number Systems Machine Numbers 2 3 4 5 6 Boolean Logic Relations Functions 6 6 5 Predicate (FirstOrder) Logic FirstOrder Logic 7
Abstract 6 1 Definitions
0 is called a constant. 0 can be thought of as a function z( x ) that returns the value 0 for all input values x. 1.1 Arithmetic
Definition 1 (Zero). 0 is a natural number. Definition 2 (Successor Function). If n is a natural number, then (n) = n + 1 is a natural number called the successor of n. Definition 3 (Addition). If n and m are natural numbers, then n + m is a natural number called the sum of n and m. Definition 4 (Multiplication). If n and m are natural numbers, then nm is a natural number called the product of n and m. Definition 5 (Exponentiation). If n and m are natural numbers, then nm is a natural number called n raised to the exponent m. cse 1400 applied discrete mathematics definitions 2 Definition 6 (Positive Exponents). n0 = 1 n m = n n m 1 Definition 7 (Negation of Exponents). nm = Definition 8 (Fractional Exponents). n a/b = 1 nm b na Definition 9 (Multipling Powers Add Exponents). n a nb = n a+b Definition 10 (Raising Powers to Powers Multiply Exponents). (n a )b = n ab
Definition 11 (Logarithms). logn a = m where nm = a 1.2 Alphabets, Strings, Languages, & Words
Definition 12 (Alphabet). An alphabet is a finite set of characters Example 1 (Example Alphabets). The binary alphabet B = {0, 1} = {False, True} The decimal alphabet D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} The hexadecimal alphabet H = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } The integers mod n Zn = {0, 1, 2, . . . , (n  1)} The quantifier alphabet (for all and there exists) Q = {, } cse 1400 applied discrete mathematics definitions 3 The delimiter alphabet L = {(, ), [, ], {, }} The dna alphabet DNA = { A, C, G, T } The English alphabet A = { a, b, c, . . . , x, y, z} The Greek alphabet G = {, , , , , , , , , , , , , , o, , , , , , , , , } The Unicode character set U = {c : 0 c (10FFFF )16 } Definition 13 (String). A string is a finite list of characters from an alphabet . Definition 14 (Kleene Closure). The Kleene closure is the set of all strings over an alphabet . Definition 15 (Language). A language L is a subset of . Definition 16 (Regular Language). The empty set is a regular language. The set {} containing only the empty string is a regular language. For every character a , the set { a} is a regular language. If L0 and L1 are regular languages, then the following are regular languages. The union L0 L1 = { s : s L0 L1 } The concatenation L0 L1 = {st : s L0 and t L1 } The string with no characters is the empty string . cse 1400 applied discrete mathematics definitions 4 1.3 Number Systems
Definition 17 (Natural Numbers). The natural numbers are the values in the set N = {0, 1, 2, 3, 4, 5, . . .} Definition 18 (Integers). The integers are the values in the set Z = {0, 1, 2, 3, 4, 5, . . .} Definition 19 (Rationals). The rationals are the values in the set a Q= : a, b Z, b = 0 b The natural numbers values shown are written in decimal notation. The integer values shown are written in signedmagnitude decimal notation. 1.4 Machine Numbers
Definition 20 (Computer Word). A fixedlength string of bits, often written in hexadecimal notation. Example 2. 8Bit Word (00)16 to ( FF )16 16Bit Word (0000)16 to ( FFFF )16 32Bit Word (0000 0000)16 to ( FFFF FFFF )16 64Bit Word Definition 21 (The Machine Naturals). The machine naturals are the values in the set Nn = {0, 1, 2, 3, . . . , 2n  1} where n is the computer's word length. Definition 22 (The Machine Integers). The machine integers are the values in the set Zn = 2n1 , 2n1 + 1, . . . , 1, 0, 1, . . . , 2n1  1 where n is the computer's word length. Definition 23 (The Machine Rationals (Floating Point)). The (normalized) floating point numbers are the values in the set Qn = (1)s . f 2eb : se f = 0 is a computer word {0} where s is a single bit, called the sign. e is string of bits representing an integer written in biased notation. f is string of bits representing the fractional part of the number.
The "meaning" of a computer word depends on "context" or "state", often called "type". n bits can name 2n things: 0 through 2n  1. When n is a multiple of 4, n/4 hexadecimal digits can name 16n/4 things. Common computer architectures represent integers in two's complement notation. If m is an integer written in two's complement notation, then m= Common computer architectures have used word lengths that are multiples of 8. A string of 8 bits is called a byte. ( m )2 m  2n if the leftmost bit of m is 0. if the leftmost bit of m is 1. where n is the computer's word length. Common computer architectures represent the integer exponent e in biased notation. If m is an integer written in biased notation, then m = ( m )2  b where b > 0 is bias. cse 1400 applied discrete mathematics definitions 5 2 Boolean Logic Definition 24 (Proposition). A proposition is a statement that is either always True or always False. Definition 25 (Boolean Variable). A Boolean variable is a character, for example p, that stands for a proposition. Definition 26 (Negation). p is the negation of Boolean variable p and defined by the formula False if p = True p = True if p = False Definition 27 (Negation). p is the negation of Boolean variable p and defined by the formula False if p = True p = True if p = False A Boolean variable is a Boolean expressions expressions formed by applying the above operations are Boolean expressions. Definition 29 (Truth Assignment). Let = { p0 , p1 , . . . , p n1 } be a set of Boolean variables. A truth assignment for is a Definition 30 (Tautology). A tautology is a Boolean expression that is always True. Definition 31 (Contradiction). A contradiction is a Boolean expression that is always False. Definition 32 (Contingency). A contingency is a Boolean expression that is sometimes True and sometimes False. And (Conjunction) p q is true only when both p and q are true. Or (Disjunction) p q is false only when both p and q are false. Conditional p q is true when (1) p is false and when (2) both p and q are true. Equivalence p q is true when both p and q are true or when both p and q are false. Definition 28 (Boolean Expressions). True and False are Boolean expressions cse 1400 applied discrete mathematics definitions 6 3 Relations Definition 33 (Relation). A relation r from X to Y is a subset of ordered pairs from the Cartesian product X Y. Definition 34 (Reflexive Relation). A relation r from X to X is reflexive if ( x, x ) r for all x X. Definition 35 (Symmetric Relation). A relation r from X to X is symmetric if ( x, y) r implies (y x ) r. Definition 36 (Transitive Relation). A relation r from X to X is transitive if ( x, y) r and (y, z) r implies ( x, z) r. Definition 37 (Antisymmetric Relation). A relation r from X to X is antisymmetric if ( x, y) r and (y, x ) r implies x = y. Definition 38 (Equivalence Relation). An equivalence relation that is reflexive, symmetric, and transitive Definition 39 (Partition). Definition 40 (Partial Orders). A partial order is a relation that is reflexive, antisymmetric, and transitive. 4 Functions Definition 41 (Function). A function f from X to Y is a relation such that ( x, y1 ) f and ( x, y2 ) f implies y1 = y2 . Definition 42 (Onto Function). A function f from X to Y is onto if for every y Y there is an x X such that ( x, y1 ) f . Definition 43 (OnetoOne Function). A function f from X to Y is onetoone if ( x1 , y) f and ( x2 , y) f implies x1 = x2 . 5 Predicate (FirstOrder) Logic Definition 44 (Predicates). A predicate is a statement that is true or false depending of the value or one or more (domain) variables. Definition 45 (Universal Quantification). A predicate can be prefixed with a universal quantifier meaning the predicate is true (or false) for all values of the domain variable(s). Definition 46 (Existential Quantification). A predicate can be prefixed with an existential quantifier meaning the predicate is true (or false) for at least one value of the domain variable(s). cse 1400 applied discrete mathematics definitions 7 6 FirstOrder Logic Firstorder logic is a syntax capable of expressing detailed mathematical statements, semantics that identify a sentence with its intended mathematical application, and a generic proof system that is surprisingly comprehensive. Christos H. Papadimitriou, Computational Complexity Definition 47 (Vocabulary). A vocabulary V is a set of functions F, a set of relations R, and variable names { x, y, z, w, . . .} to which the functions and relations are applied. Definition 48 (Terms over a Vocabulary). 1. Any variable is a term. 2. If f is a function and t is a term, then f (t) is a term. Definition 49 (FirstOrder Expressions). 1. If is a relation and t and s are terms, then t s is an (atomic firstorder) expression. 2. If p and q are (firstorder) expressions, then the following are (firstorder) expressions. (a) p, pronouced "not p". (b) p q, pronouced "p and q". (c) p q, pronouced "p or q". (d) ( x )( p ), pronouced "for all x, p". The negative of "for all x, p" is ( x )( p ) = ( x )( p ), pronouced "there exists an x such that not p. Definition 50 (Models). A mo (graph theory, set theory, number theory) Definition 51 (Valid Statements). Valid statements: statements that are True in every model. Definition 52 (True Statements). True statements: statements that True are of a given model. Definition 53 (Proof). Definition 54 (Provable Statements). Proveable statements: statements that can be proven True of a given model. Definition 55 (Complete). A model is complete if for every expression p there is a proof of p or there is a proof of p. Definition 56 (Inconsistent). A model is inconsistent if it there proof of every expression p. Definition 57 (Consistent). A model is consistent if it there is no there expression p such that both p and p have a proof in the theory. CSE 1400 Applied Discrete Mathematics Theorems
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 Theorems 1
1 2 2 3 3 3 3 4 4 4 Theorems about Arithmetic Theorems about Algebra Theorems about Sets Theorems about Boolean Logic Theorems about Predicate Logic Theorems about Relations Theorems about Functions Theorems about Sequences Theorems about Theorems Theorems about Modular Numbers 1 Theorems
Abstract Theorems are statements that have been proven True. 1.1 Theorems about Arithmetic Theorem 1 (Fundamental Theorem of Arithmetic). Every natural number m greater than 1 is either prime or the product of unique prime factors. Theorem 2 (WellOrdering). Let X be a nonempty subset of the natural numbers. There exists an element a X such that a x for all x X. This element a is called the least element of X. Theorem 3 (Archimedean property). For every natural number m there is a natural number n such that n > m. The order of the prime factors is not considered important. cse 1400 applied discrete mathematics theorems 2 Theorem 4 (QuotientRemainder). Given an integer a Z and an integer n = 0, there exists an integer q and a natural number r, called the quotient and remainder, such that a = qn+r and 0 r < n. Theorem 5 (Euclid's Theorem). There is no largest prime number. Lemma 1. If a2 is an even integer, then a is even. Theorem 6 (Irrational Square Roots). The square root of 2 is not a rational number. Theorem 7 (Bzout's Theorem). Given integers a and b there exists integers s and t such that gcd( a, b) = as + bt Theorem 8 (Prime Number Theorem). Let P = {2, 3, 5, 7, 11, . . .} be the set of prime numbers. Then the number of primes less than or equal to x is approximately x/ ln x as x goes to infinity. That is, lim x  { p P : ( p x )}  ln x =1 x 1.2 Theorems about Algebra
(n  1)m + 2b 2 Theorem 10 (Geometric Sums). Let x R, x = 1. Then
b + (m + b) + (2m + b) + + ((n  1)m + b) = n xn  1 x1 1 + x + x 2 + + x n 1 = Theorem 9 (Arithmetic Sums). Let m, b R. Then
An arithmetic sum has the form b + (m + b) + (2m + b) + + ((n  1)m + b ). A geometric sum has the form 1 + x + x 2 + + x n 1 . Theorem 11 (Binomial Theorem). Let x and y be real numbers, and let n be a natural number. Then ( x + y)n = = 0 k n n nk k x y k n n n n 1 n n 2 2 n n n x + x y+ x y ++ xyn1 + y 0 1 2 n1 n 1.3 Theorems about Sets
Theorem 12 (De Morgan's Laws). XY = XY XY = XY cse 1400 applied discrete mathematics theorems 3
The numbers (n) are called binomial k coefficients and read as "n choose k." Binomial coefficients are computed by Pascal's recursion equation n m Theorem 13 (Counting Subsets). A set with n elements has subsets. (n) k kelement Corollary 1 (Counting All Subsets). A set with n elements has 2n subsets = 1.4 Theorems about Boolean Logic
Theorem 14 (De Morgan's Laws). with boundary conditions n 0 n1 n1 + m1 m n n = 1, =1 ( p q = p q
Theorem 15 (Counting Truth Assignments). Let B be a expression in n Boolean variables. There are (n) ways to assign True to k of the variables k and False to the other n  k variables. ( p q = p q Corollary 2 (Counting All Truth Assignments). Let B be a expression in n Boolean variables. Then B has 2n truth assignments. 1.5 1.6 Theorems about Predicate Logic Theorems about Relations Theorem 16 (Counting Relations). Let the cardinalities of set X and Y be X = n and Y = m, respectively. There are 2nm relations from X to Y. In 2 particular, there are 2n relations on X. Theorem 17 (Partitions and Equivalence Relations). The relation is an equivalence on X if an only if partitions X into a collection of subsets. Theorem 18 (Stirling Numbers of the Second Kind). Let X be a set n with cardinality X = n. The Stirling numbers {m} defined by the recurrence equation n n1 n1 = +m m m1 m with boundary conditions n n = 1, n 0 = 0for n > 0 count the number of equivalence relations on X with m subsets in their partition. 1.7 Theorems about Functions
Theorem 19 (Counting Functions from X to Y). Let X and Y be finite sets with cardinality n and m, respectively. Then there are m n =  Y  X functions from X to Y. cse 1400 applied discrete mathematics theorems 4 Lemma 2 (Counting Functions on X). Let X be a finite set with cardinality n. Then there are n n =  X  X functions on X. Let function f : X Y have domain X with cardinality n and codomain Y with cardinality m. Then there is at least one element y Y that is the image of at least n/m elements in X. Corollary 3. Let function f : X Y have domain X with cardinality n and codomain Y with cardinality m. If n > m, then f is not onetoone. Corollary 4. Let function f : X Y have domain X with cardinality n and codomain Y with cardinality m. If n < m, then f is not onto.
If n pigeons are placed into a coop with m holes, then some hole will have at least h(n, m) = n/m pigeons. Consider the cases. Theorem 20 (Pigeonhole Principle). 1.
n > m: In this case h(n, m) > 1, and if all holes contained less than n/m pigeons, then there would be fewer than m n/m < n pigeons. 2. n < m: In this case h(n, m) = 0, and some pigeonhole will contain no pigeons. 3. n = m: In this case h(n, m) = 1, and some pigeonhole must contain at least one pigeon. 1.8 1.9 Theorems about Sequences Theorems about Modular Numbers Theorem 21 (Linear Congruence Equations). Let a and b be integers and let n be a positive integer, then the congruence ax b (mod n) has a solution for x if and only if b is divisible by the greatest common divisor of a and n When this is the case, and x0 is a solution, then the set of all solutions is given by n : k {Z} d . In particular, there will be exactly d = gcd(a, n) solutions in the set of residues Z = {0, 1, 2, ..., n  1}. x0 + k 1.10 Theorems about Theorems
It can be interesting to reason about what we can reason about. A axiomatic system Theorem 22. Boolean logic is consistent and complete. Theorem 23 (Gdel's Completeness Theorem). If statement p is valid under the assumptions q0 , q1 , . . . , q n1 , then there is a proof that p is True. Theorem 24 (Gdel's Soundness Theorem). If there is a proof that p is
True, under the assumption q0 , q1 , . . . , q n1 , then p is valid under these assumptions. Theorem 25 (Gdel's Incompleteness Theorem). There are True statements about arithmetic that have no proof. CSE 1400 Applied Discrete Mathematics Proofs
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2 3
3.1 3.2 3.3 3.4 3.5 3.6 Axioms 2 2 3
3 4 4 5 7 7 Rules of Inference Proof Techniques
Counterexamples Direct Proofs Vacuous and Trivial Proofs Proofs by Contradiction Proofs by Contraposition Proofs by Resolution 4
4.1 4.2 4.3 4.4 4.5 4.6 4.7 Significant Theorems
Euclid's Lemma Bzout's Theorem Lam's Theorem 9 8 7
8 8 Fundamental Theorem of Arithmetic The Quotient Remainder Theorem 9 11 11 The Binomial Theorem The Prime Number Theorem 5 Problems on Proofs 11
Abstract Mathematics seeks to prove statements are always True or always
False, or sometimes True and sometimes False. The statements can be about almost anything, but, in computing, can often be reduced to statements about natural numbers. Starting from an initial set of axioms there are several techniques (arguments) that can be used to establish new truths: direct, indirect, cse 1400 applied discrete mathematics proofs 2 1 Axioms An initial collection of True premises is necessary to establish a mathematical system. The premises, called axioms, model a system that is interesting to reason about. Euclid's axioms of geometry are perhaps the best known axiomatic system. The Peano axioms for the natural numbers may be less well known, but are essential ideas for building a system of discrete mathematics. The Peano axioms are 1. There is natural number called zero denoted by the symbol 0. 2. If n is a natural number, then n + 1 is a natural number. 3. Zero is not the successor of any natural number n. That is, 0 = (n + 1) for any natural number n. 4. If the successor of n equals the successor of m, then n and m are equal. 5. If set A contains zero and the successor of every element in A, then every natural number is in A, that is A = N. Peano's arithmetic also postulate the existence of an equality relation on the natural numbers that satisfies the rules 1. Reflexive: For all natural numbers n, n = n. 2. Symmetric: For all natural numbers n and m, if n = m, then m = n. 3. Transitive: For all natural numbers n, m, and o, if n = m and m = o, then n = o. The axioms of Euclidean geometry are roughly stated as follows. 1. There is a straight line segment between any two points. 2. A straight line segment can be extended indefinitely into a line. 3. A circle can be constructed with center at one end of a radius of a given a straight line segment. 4. All right angles are identical. 5. Two straight lines intersect if they are not parallel. Axiom 5 is called the induction axiom. It is equivalent to the wellordering property: Every nonempty set of natural numbers has a least element. Peano's axioms are consistent if they are incapable of deriving a wellformed formula that is both True and False. Peano's axioms are complete if any wellformed formula can be proven either True or False. Gdel proved any logical system L in which Peano axioms are True (a) Cannot be both consistent and complete (b) Cannot be proven consistent unless it is inconsistent. 2 Rules of Inference inference rules allow the discovery of new truths from an initial set of axioms. The most simple sound argument form has one premise pand one conclusion c. This sound argument is a demonstration that 1. p is True, and 2. p c is True Therefore, infer that c is True. This basic rule of inference is called modus ponens. Modus ponens is True because its form is always True. This can be demonstrated by the truth table Modus ponens is often written using the notation p pc c Read "p is True and p c is True. Therefore c is True. You will gain understanding by constructing a truth table for the Boolean expression ( p ( p c )) c cse 1400 applied discrete mathematics proofs 3 Input p 0 0 1 1 c 0 1 0 1 Output [ p ( p c )] c
1 1 1 1 There are many useful rules of inferences: modus tollens, reductio ad absurnum, syllogism, resolution, and others. A rule of inference is a statement in propositional calculus that is always True. A rule of inference is a tautology. A tautology is a propositional statement that is always True. The truth table for modus tollens is Input p 0 0 1 1 q 0 1 0 1 Output Modus tollens is written as q pq p [ q ( p q )] p
1 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 Read "q is not True and p q is True. Therefore p is not True." Induction is written as 3 Proof Techniques p (0) (n N)( p (n) p (n + 1)) (n N) p (n) A proof of proposition c is a sound argument that c is True . An argument in propositional calculus is a sequence of propositions p 0 , p 1 , . . . , p n  1 , c. The first n propositions p 0 , p 1 , . . . , p n  1 are called premises. The last proposition c is called the conclusion. An argument is valid when the conditional Read "p (n) is True for n = 0; there is a natural number n such that if p (n) is True, then p (n + 1) is True. Therefore p is not True." ( p0 p1 pn1 ) c
is always True. A valid argument is sound when all of the premises are True. In this case, we'll write
The argument is valid when any one of the premises is False or when all of the premises are True and the conclusion is True. In this latter case, the argument is sound. ( p 0 p 1 p n  1 ) = c
and say the premises prove the conclusion. 3.1 Vacuous and Trivial Proofs
Consider a conditional statement. cse 1400 applied discrete mathematics proofs 4 If p, then q This conditional statement is True when p is False. This is called a vacuous proof that the conditional statement "If p, then q" is True. A conditional statement is also True when q is True. Knowing that q is True provides a trivial proof that the conditional "If p, then q" is True.
By definition, set X is a subset of Y if every element x X is also an element of setY. Therefore, since the statement is True for every x. This conditional is vacuously True because x always False. That is, is a subset of any set Y. "If x A, then x U (the universal set)" is a trivial proof that the every set is a subset of the universal set. "If x , then x Y" 3.2 Counterexamples
A statement of the form ( a)( p ( a))
can be demonstrated to be False by providing some value a where p ( a) is False. The value a is said to be a counterexample to the statement ( a)( p ( a)). The existence of a counterexample a proves that it is not the case that p ( a) is true for all elements a, that is, ( a)( p ( a))
Consider the statements: 1. Every natural number is the sum of squares of two natural numbers. Notice that 0 = 02 + 02 1 = 02 + 12 2 = 12 + 12 But 3 is a counterexample to the statement since 3 cannot be written as the sum of squares of two natural numbers. 2. Every natural number is a prime or composite. Both 0 and 1 are counterexamples. 3. All prime numbers are odd. The number 2 is a counterexample. 3.3 Direct Proofs Pretend you could prove p (p q) cse 1400 applied discrete mathematics proofs 5 is True . By modus ponens you could draw the conclusion that q is True. This is called a direct proof of q. Input p 0 0 1 1 q 0 1 0 1 Output Direct proofs use modus ponens. To prove q is True, prove or know p = True and prove p implies q is True. (p q p)
0 0 0 1 1 1 1 1 q 0 1 0 1 For instance, from the True proposition p = ( a, b Z)(( a  b)2 0) we can prove the geometric mean is always less than or equal to the arithmetic mean. From p we reason as follows. 0 ( a  b)2 = a2  2ab + b2
The value ( a + b)/2 is arithmetic mean of a and b. The value ab is geometric mean of a and b. The direct proof states the geometric mean is less than or equal to the arithmetic mean. ( a + b )2 4 a+b ab 2
ab 4ab a2 + 2ab + b2 = ( a + b)2 3.4 Proofs by Contradiction
Pretend you could prove p False
is a True statement. Then you could draw the conclusion that p is True, otherwise the conditional would not be True. This is called the reductio ad absurnum rule of inference: The proof reduces proposition p to an absurdity, and allows the conclusion that the p = True. The reductio ad absurnum schema is: To prove a proposition p is True use a proof by contradiction 1. Pretend p is True. 2. Demonstrate that p False is True. Most often the value of False is expressed as q q, where q is some proposition. 3. Conclude p is False, that is, p is True. Euclid's proof that there are infinitely many prime numbers is a classic reductio ad absurnum. cse 1400 applied discrete mathematics proofs 6 Theorem 1 (Euclid's Theorem). There are infinitely many prime numbers. (Proof by contradiction). Pretend there are only finitely many prime numbers and name them p0 , p1 , . . . , pn1 . Consider their product plus 1. p = ( p 0 p 1 p n 1 ) + 1 Assume the negation of the proposition is True. Clearly p is not one of the prime numbers p0 , p1 , . . . , pn1 : It is greater than each of them. None of the prime numbers p0 , p1 , . . . , pn1 divide p: There is always are remainder of 1 when p is divided by any of the primes pk . Therefore p has only two divisors: 1 and p; and therefore p is prime. Therefore, the assumption "there are finitely many primes" leads to the construction of a natural number p that is both prime and not prime. This contradiction allows the conclusion "there are an unbounded number of prime numbers." Another ancient theorem is called the Archimedean property Theorem 2 (Archimedean property). For every real number x there is an integer n such that n > x. (Proof by contradiction). Pretend there is a real number x such that n x for every integer n. Thus there must exist an integer m that is larger than every other integer. But m + 1 is an integer and m < m + 1. A third ancient theorem, that appears in Euclid's Elements is the following. Theorem 3 (Irrational Square Roots). The square root of 2 is not a rational number. Lemma 1. If a2 is an even integer, then a is even. (Proof by contradiction). Pretend 2 is rational and write 2 = a/b were a and b are integers. We may also pretend that a/b has been reduced to lowest terms by cancelling any common factors. That is, a and b are relatively prime. Consider the equations a 2= square both sides b a2 2= 2 clear the denominator b 2b2 = a2 a2 is even, so a = 2c 2b2 = 4c2 b2 = 2c2 b2 is even, so b is even The integer p is not a prime number. This is a propostion, name it q, that is True if there are finitely many primes. The statement "p is prime" is q and it must be True if there are finitely many primes. p mod pk = 1 for all k = 0, 1, . . . , n  1. cse 1400 applied discrete mathematics proofs 7 Thus both a and b are even, contradicting that they are relatively prime. 3.5 Proofs by Contraposition
Pretend you could prove statement ( p q ) ( q )
is True . You could then draw the conclusion that p is True. (( p q ) ( q )) ( p )
This is called a proof by contraposition. Input p 0 0 1 1 q 0 1 0 1 Output
A proof by contraposition relies on the logical equivalence p q q p. (p q q)
1 0 0 0 1 1 1 1 p
1 1 0 0 3.6 Proofs by Resolution
Pretend you could prove the conjunction Proofs by contraposition use modus tollens. To prove p is True, prove or know q True and prove or know p q True. ( p q ) ( p r )
is True . That is, both conditional statements are True . You could then draw the conclusion that q r is True. This is called the resolution rule of inference. 4 Significant Theorems There are many theorems that can be derived from many different axiomatic systems. Theorems about the natural numbers N can be important in discrete mathematics applications. There are several reasons for this. 1. The natural numbers are fundamental for arithmetic: addition and multiplication. 2. The natural numbers provide a counting system. 3. The natural numbers provide a naming or indexing system.
extending the operations to include subtraction and division requires extending the natural numbers to the integers and rationals. So many things to count; so little time. A single natural number can point to a complex descriptive name. cse 1400 applied discrete mathematics proofs 8 4.1 Fundamental Theorem of Arithmetic
Theorem 4 (Fundamental Theorem of Arithmetic). Every natural number m greater than 1 is either prime or the product of unique prime factors. Proof. Let n > 1 be a natural number. For the first few values natural numbers the theorem is True. So let's pretend the theorem has been establishes for each natural number k = 2, 3, . . . , (n  1). Consider the next natural number n. If n is prime the theorem is established. On the other hand, if n is composite there exists natural numbers n1 and n2 such that n = n1 n2 and each has a unique prime factorization. This establishes a unique factorization of n. The order of the prime factors is not considered important. 2, 3, 22 , 5, 2 3, 7, 23 4.2 Euclid's Lemma
Another useful number theoretic fact is Euclid's lemma. Lemma 2 (Euclid's). Let p P be a prime number and let a, b N be natural numbers. If p divides ab, then p divides a or p divides b. Proof. Pretend p divides ab and p does not divide a. That is, (c N)( pc = ab) ( a mod p = r = 0)
By the Fundamental Theorem of Arithmetic ab can be factored as a product of primes. Since p does not divide a, p is not one of the prime factors of a. Therefore, since the prime factorization is unique, p must be a prime factor of b. That is, p divides b. 4.3 The Quotient Remainder Theorem
For another instance of a direct proof recall the quotient remainder theorem. Theorem 5 (QuotientRemainder). Given an integer a Z and an integer n = 0, there exists integers q and r, called the quotient and remainder such that a = qn+r and 0 r  < n. Proof. Let us pretend a, n Z, n = 0 are integers and consider the nonempty set of natural numbers A = { a  nq 0 : q Z} By the well ordered principle of the natural numbers, A has a least
For instance, A = {5, 11, 17, 23, 29, . . .} when a = 23 and n = 6. A is not empty. To see this, let q= a/n a/n if n > 0, that is, a nq if a/n q. if n < 0, that is, a nq if a/n q. where and are the floor and ceiling functions. For the first case, q = a/n a/n straightforwardly implies a  nq 0. The second case is left as an exercise. cse 1400 applied discrete mathematics proofs 9 element 0 r = a  nq for some q. By contradiction we can show that r n. Consider what happens when you pretend r > n. From n < r = a  nq
conclude that 0 < a  nq  n = a  n(q + sgn n) A But that makes a  nq  n a member of A smaller than the least member r! 4.4 Bzout's Theorem
Theorem 6 (Bzout's Theorem). Given integers a and b there exists integers s and t such that gcd( a, b) = as + bt Proof. Consider the set A = { as + bt > 0 : s, t Z} By the well ordered principle, there is a least element g = as + bt A. By the quotient remainder theorem there exists integers q and r such that a = gq + r, with 0 r < g Notice that r = a  gq = a(1  sq) + btq
If r > 0, then r A and r is smaller than g, the least element in A. Therefore r = 0 and g divides a. The same argument holds when b replaces a. Thus, g divides a and b. = a  ( as + bt)q 4.5 Lam's Theorem
Lam's theorem establishes an upper bound on the time complexity of the Euclidean algorithm for computing the greatest common divisor of two integers. The result is that Euclid's algorithm has logarithmic time complexity. Specifically, no more than 3 lg(max( a, n)) divisions are required to compute gcd( a, n), the greatest common divisor of a and n. The Fibonacci numbers are occur in the proof of Lam's theorem. cse 1400 applied discrete mathematics proofs 10 Theorem 7 (Lam's Theorem). Let a, b Z+ with a b. Let n be the number of divisions in Euclid's algorithm to compute gcd( a, b). Then n  1 3 lg b Proof. Let r0 = a and r1 = b. Euclid's algorithm computes r0 r1 = r1 q1 + r2 = r2 q2 + r3 . . . = rn qn 0 r2 < r1 0 r3 < r2 0 r n < r n 1 r n 2 r n 1 = r n 1 q n 1 + r n using n divisions to compute rn = gcd( a, b). Note that qi 1, i = 1, 2, . . . , n  1 Let Fi denote the ith Fibonacci number. Then rn r n 2 r2 r1 r n 1 r n < r n 1 q n 2 1 = F2 rn1 + rn F3 + F2 = F4 . . . r2 + r3 Fn + Fn1 = Fn+1 r3 + r4 Fn1 + Fn2 = Fn = rn qn 2rn 2 = F3 Using the growth rate of the Fibonacci numbers Fn+1 n1 , we find b = r1 Fn+1 > n1 Taking the logarithm base of both sides of the inequality yields log b = Since (lg )1 < 3 we have 3 lg b > lg b > n1 lg lg b > n1 lg Another way to state the result is that if b can be represented in k bits, then the number of divisions in Euclid's algorithm is less than 3 times the number of bits in b's binary representation. cse 1400 applied discrete mathematics proofs 11 4.6 The Binomial Theorem
Theorem 8 (Binomial Theorem). Let x and y be real numbers, and let n be a natural number. Then ( x + y)n = = 0 k n n nk k x y k n n n n 1 n n 2 2 n n n x + x y+ x y ++ xyn1 + y 0 1 2 n1 n 4.7 The Prime Number Theorem Theorem 9 (Prime Number Theorem). Let P = {2, 3, 5, 7, 11, . . .} be the set of prime numbers. Then the number of primes less than or equal to x is approximately x/ ln x as x goes to infinity. That is, lim x  { p P : ( p x )}  ln x =1 x 5 Problems on Proofs 1. Construct a truth table to prove that resolution [( p q ) ( p r )] ( q r )
is a tautology. 2. Let n be an integer. Prove that if n is odd, then n = 4k + 1 or n = 4n + 3 for some integer k. 3. Find a counterexample to prove the statement "All shapes that have four sides of equal length are squares." 4. Let a be an integer. Prove that if a2 is odd, then a is odd. 5. If b < 0 show that the remainder r = a  bq is greater than or equal to 0 when the quotient q is has value q = a/b . 6. Is the conditional statement `If x then x X.' True or False? Explain your answer. 7. Prove that "if n is even and n is odd, then n2 = 2n" is a True statement. 8. Let a be a natural number. Prove that if a2 is a multiple of 3, then a is a multiple of 3. 9. Prove that 3 is irrational. 10. Prove that the greatest common divisor of two consecutive Mersenne numbers is 1. 11. Prove or disprove: The greatest common divisor of two consecutive triangular numbers is 1. 12. Prove of disprove the statement: The 8 bit floating point numbers from the course are closed under multiplication. 13. Prove of disprove the statement: The 8 bit floating point numbers from the course obey the associative law for multiplication. cse 1400 applied discrete mathematics proofs 12 14. Prove the integers are countable by describing a onetoone and onto function that maps the natural number to the integers. 15. Prove the Cartesian product N N is countable by describing a onetoone and onto function that maps the natural number to the N N. (Hint: list the ordered pairs in triangular form (0, 0), (1, 0), (0, 1), (2, 0), (1, 1), (0, 2), . . .
and use the triangular numbers to name the ordered pairs.) CSE 1400 Applied Discrete Mathematics Algorithms
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1
1.1 1.2 Algorithms
Basic Sums 1
1 2
Abstract Horner's Rule There are many algorithms useful in computing. 1 Algorithms 1.1 Horner's Rule
Consider the problem of computing the value of the polynomial p( x ) = 5x3 + 4x2 + 7x + 2 at x = 3. This computation can be organized in several ways, one of which is called Horner. Horner's rule computes the value p(3) = 2 + 3 (7 + 3 (4 + 3 5)) (1) Which is the action of the recursive function + x * (horner x s) on the constant x = 3 and the list ( a : as) = 2, 7, 4, 5 of coefficients whose head is a = 2 and whose tail is as = 7, 4, 5 In the example, Horner's rule requires 3 multiplies and 3 additions and, in the general case, for a polynomial of degree n, Horner's rule requires n multiplies and n additions. Input: A list l = a0 , a1 , . . . , an1 and a constant c Purpose: Compute the value of the polynomial p ( x ) = a n 1 x at the value x = c. Compute: If the list l is empty, return 0
n =1 n 2 1 0 The polynomial coefficients in p( x ) = 5x3 + 4x2 + 7x + 2 can be written in two orders 1. Little Endian, that is, 2, 7, 4, 5 or 2. Big Endian, that is, 5, 4, 7, 2 The brute force approach computes p (3) = 5 3 (3 3) + 4 (3 3) + 7 3 + 2 which requires 5 multiplications and 3 additions. + a n 2 x + + a1 x + a0 x cse 1400 applied discrete mathematics algorithms 2 Otherwise return the head of the list plus c times the result of computing Horner's rule on the tail of the list. More explicitly, horner is a function with input: a value c
horner horner horner horner :: Int > [Int] > Int c = 0 c [x] = x c (x:xs) = x + c * (horner c xs) horner :: Float > [Float] > Float horner c = 0  The empty coefficient list has value $0$. horner c (x:xs) = x + c * (horner c xs)  A nonempty coefficient list  evaluates to the head  plus c times the tail. horner c = 0 horner c (x:xs) = c * (horner c xs) There are several applications of Horner's rule. 1. When c = 2 and all the coefficient are 0's or 1's Horner's rule computes the decimal value of an unsigned natural number written in base 2 (binary). (a) When c = m and all the coefficients are between 0 and m  1, Horner's rule computes the decimal value of an unsigned natural number written in base m (mary). 1.2 Basic Sums
SumNats :: [Natural] > Natural SumNats = 0 SumNats (n : ns) = n + SumNats ns SumNats :: [Arithmetic] > Integer SumNats = 0 SumNats (ns) = length ns * (head ns + tail ns)/2 SumNats :: [Geometric] > Integer SumNats = 0 SumNats (ns) = length ns * (head ns + tail ns)/2 CSE 1400 Applied Discrete Mathematics Problems
Department of Computer Sciences College of Engineering Florida Tech Spring 2011 1 2 3 4 5 6 7 8 9 Problems on Numbers 1 2 3 4 5 Problems on Numeral Systems Problems on Modular Numbers Problems on Converting Decimal to Another Base Problems on Converting Another Base to Decimal Problems on Sets 6 9 11 13 15 16 18
20 Problems on Boolean Logic Problems on Predicate Logic Problems on Relations 10 Problems on Functions 11 Problems on Logarithms and Exponentials 12 Problems on Integer Functions 13 Problems on Polynomials
13.1 Problems on Permutations 19 20 23 14 Problems on Induction 15 Problems on Recurrences 16 Problems on Proofs 1 Problems on Numbers 25 1. Identify if the propositions are True or False. (a) 5 N. (c) 5 Q. The notation x X means element x is a member of set X. (b) 5 N. (d) 5i Q. 2. Is the relation on the natural numbers N is strict? That is, is it True that if a b, then b a? cse 1400 applied discrete mathematics problems 2 3. Place the sets N, Z, Q, R and C in order given by set inclusion. 4. What is the smallest positive rational number? 5. What is (3)3 ? 6. What is 43 mod 7? 8. Describe the residue (equivalence) classes for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 9. Construct an addition table for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 10. Construct a multiplication table for the modular numbers. (a) Integers mod 4. (b) Integers mod 5. 11. 0 is the symbol for the cardinality of N, the count of elements in the set of natural numbers. 0 is pronouced alephnaught. Cantor called 0 a "transfinite" number. Cantor called the cardinality of R, the set of real numbers, 1 and he proved 0 = 1 . (a) Why is transfinite a good word to use? (b) Are there transfinite numbers between 0 and 1 ? 7. What is 43 mod 7? (c) Read the Wikipedia page on natural numbers. The last time I checked, it provided a good summary of useful ideas. 2 Problems on Numeral Systems 1. The following natural numbers are written using their binary names. What are their hexadecimal names? (a) 0000 1001. (b) 1111 1111. (c) 011 1100 1100. (d) 110 1011 1010. 2. Why is it awkward to group the bits by fours from lefttoright when converting a binary string to hexadecimal? 3. Expand the hexadecimal names below to their binary equivalent. (a) FE (b) ACED (c) 577 (d) 3141 4. Explain how to covert from binarytooctal and octaltobinary. 5. How many length n octal strings are there? 6. How many length n decimal strings are there? 7. How many length n hexadecimal strings are there? cse 1400 applied discrete mathematics problems 3 8. How many length n strings of lower case English letters are there? 9. How many length n strings of lower case English letters and decimal numerals are there? 10. How many length n strings of lower case Greek letters are there? 11. Write the number twentyfive in Roman numerals, in decimal, in binary, in octal and in hexadecimal. 12. How many things can be named using strings of a given length? (c) Length 4 hexadecimal strings. (d) Length n decimal strings. (a) Length 4 decimal strings. (b) Length 4 binary strings. (e) Length n binary strings. (f) Length n hexadecimal strings. 13. How many characters are needed to name the given number of things ? (a) 5 things in binary. (b) 50 things in decimal. (c) 500 things in hexadecimal. (d) n things in binary. (e) n things in decimal. (f) n things in hexadecimal. 14. Pretend you need to blackbox test a program by entering each and every input combination to verify the output is correct for each input. Pretend the set of input combinations is a set of strings of length 1 through 10 drawn from an alphabet of 94 symbols. How many input combinations are there? 3 Problems on Modular Numbers 1. Describe an algorithm that could be used to convert 1 pound into kilograms. 2. Describe the residue (equivalence) classes for (a) Congruence mod 4. (b) Congruence mod 5. 3. How many residue classes are there mod n? 4. For the given values of a and n below, compute the quotient q and nonnegative remainder r that satisfy the quotientremainder equation a = qn + r, r 0 (a) a = 26, n = 13. (b) a = 27, n = 13. 5. Construct an addition table for the integers mod 6. 6. Construct a multiplication table for the integers mod 4. 7. Construct a multiplication table for the integers mod 7. 8. Solve the following linear congruence equations. (a) 3x 5 (mod 7) (c) a = 27, n = 13. (d) a = 45, n = 13. cse 1400 applied discrete mathematics problems 4 (b) 5x 4 (mod 7) (c) 2x 1 (mod 7) (d) 6x 3 (mod 7) 9. Let p = 25 34 117 1310 196 and q = 36 115 1312 174 . (a) What is the greatest common divisor of p and q? (b) What is the least common multiple of p and q? 10. Use Euclid's algorithm to compute the greatest common divisors listed below. (a) gcd(19, 8). (b) gcd(25, 40). (c) gcd(70, 27). (d) gcd(66, 99). (e) gcd(189, 80). (f) gcd(511, 255). (c) Verify the gcd( p, q) lcm( p, q) = pq. 11. Using your work from question 10, find integers a and b such that (a) 1 = 19a + 8b. (b) 5 = 40a + 25b. (c) 1 = 70a + 27b. (d) 1 = 66a + 99b. 12. Using your work from question 11, solve the following linear congruence equations. (a) 8x = 5 mod 19. (b) 25x = 38 mod 40. (c) 27x = 4 mod 70. (d) 66x = 22 mod 99. 4 Problems on Converting Decimal to Another Base
Repeatedly divide q and following quotients by 2 pushing the remainder bits onto a stack. 1. Convert the following natural numbers (all named q) from decimal to binary. (a) q = 13. (b) q = 134. (c) q = 145. (d) q = 257. 2. Convert the following natural numbers from decimal to hexadecimal. (a) q = 13. (b) q = 134. (c) q = 145. (d) q = 257. Instead of dividing by 16 and stacking remainders, it may be easier to convert to binary and group bits by fours. 3. Convert the following signed integers from decimal to two's complement binary. (a) q = 13. (c) q = 145. (b) q = +134. (d) q = 257. cse 1400 applied discrete mathematics problems 5 4. Convert the following signed integers from decimal to biased decimal notation. (a) q = 13 with bias b = 32. (c) q = 145 with bias b = 256. (b) q = +134 with bias b = 256. (d) q = 257 with bias b = 512. 5. Convert the following rational numbers, written in decimal, to binary. (a) q = 27/8. (b) q = 5.1. (c) q = 0.3125. (d) q = 0.3333 . 5 Problems on Converting Another Base to Decimal 1. Use Horner's rule to convert the following unsigned numbers into decimal notation. (a) (0000 1001)2 (b) (1111 1111)2 (e) (747)8 (f) (123)4 (g) ( A47)16 (c) (1100 1100)2 (d) (1010 1010)2 2. Convert the signed decimal integers below into two's complement notation. (a) +76. (b) 76. 3. Negate the two's complement integers below. (a) 0100 1100. (b) 1100 0000. (c) 1010 0100. (d) 1000 0000. (c) 137. (d) +177. 4. Convert the following two's complement integers into decimal notation. (a) 0100 1100. (b) 1100 0000. (c) 1010 0100. (d) 0010 1000. 5. Using two's complement notation what range of integers from most negative to most positive can be represented using (a) 2 bits? (b) 8 bits? (c) 32 bits? (d) 64 bits? 6. Consider ten's complement notation. An integer and its complement should sum to zero. Writing in 4 digits the integer 1234 has complement 8766 since 1234 + 8766 = 1 0000. The smaller numbers from 0000 to 4999 are positive and have their "normal" value. The larger values 5000 to 9999 are negative and defined by the complement rule illustrated in the example. cse 1400 applied discrete mathematics problems 6 (a) What are the complements of (a) 3141? (b) 7316? (c) 9999? (d) 5000? (b) What are the decimal numbers for the ten's complements numbers (a) 3141? (b) 7316? (c) 9999? (d) 5000? 7. The following binary strings are floating point numbers where the first (leftmost) bit is a sign bit, the next three bits are exponent bits written in biased notation with bias b = 3, and the last four bits are fraction bits. These floating point are normalized. What are decimal names for these floating point numbers? (a) 1001 1000 (b) 0101 1011 (c) 1111 1111 (d) 0000 0001 8. Using the 8 bit floating point numbers from the course, explain why 17/128 is the smallest positive floating point number and why 1/8 is not. 6 Problems on Sets 1. Describe the following sets. List a representative sample of elements establishing a pattern. Give a function that computes the elements. (a) The set of even integers. (b) The set of odd integers. (c) The set of integers that have a remainder of 2 when divided by 3. (d) The Mersenne numbers. (e) The triangular numbers. (g) The set of solutions to the equation  x   1 = 0. (a) x is an element of X. (b) x is not an element of X. (c) X is a subset of Y. (d) X is a proper subset of Y. (e) X is not a subset of Y. (f) The union of X and Y. (g) The intersection of X and Y. (h) The complement of X. (i) The empty set 3. Answer True or False. (a) 2 {{2}}. (d) { x }. (f) The set of solutions to the polynomial equation x2  x  1 = 0. 2. What notation would be used to stand for the following phrases? (b) {}. (c) 0 . (f) { x } { x }. (e) { x } { x }. cse 1400 applied discrete mathematics problems 7 4. Below are standard names for sets that occur in computing. Describe these sets. (a) B (b) H (c) N (d) Z 5. What is the cardinality of each of these sets? (a) . (b) {}. (c) D. (d) x : x2  x  1 = 0 . (e) N. (f) Q. (g) R. (e) Z+ (f) Q (g) R (h) 6. What is the power set of each of these sets? (a) {0}. (b) x: (c) . x2 x1 = 0 . (d) {}. 7. What is the cardinality of each of these sets? (a) The power set of {0}. (b) The power set of x : x2  x  1 = 0 . (d) The power set of H, the set of hexadecimal numerals. (c) The power set of D, the set of digits. 8. Describe how to define the set difference operator: Y  X using the standard union, intersection, and set complement operators. 9. Shade the Venn diagram to indicate the given region is not empty. (a) X Y. Y X (b) X Y V. Y X Z X V (d) X Y Z. U Y Z X (c) X Y Z. Y Z U U U 10. Shade the Venn diagram to indicate the given region is not empty. cse 1400 applied discrete mathematics problems 8 (a) X Y. Y X (b) X Y Z. Y X Z X Z (d) X Y Z. U Y Z X (c) X Y Z. Y Z U U U 11. Let X and Y be subsets of some universal set U. Are the following statements True or False? (a) X = X (b) X = X (c) X U = X (e) X U = (f) X Y = X Y (g) X Y X (d) X U = U 12. Let M10 = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511} be the set of the first 10 Mersenne numbers. Let T10 = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45} be the set of the first 10 triangular numbers. Find (a) M10 T10 . (b) M10 T10 . (c) M10  T10 . 13. Using the three sets X = {1, 2, 3, 4, 5} over the universe of digits compute the following set operations (a) X Y D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} (c) (X Y) Z Y = {0, 2, 4, 6, 8} Z = {0, 3, 5, 9, } (d) T10  M10 . (b) X Z 14. Using the three sets X = {1, 2, 3, 4, 5} over the universe of digits (d) (X Y) Z Y = {0, 2, 4, 6, 8} Z = {0, 3, 5, 9, } write expressions using set operators union , intersection and complement that are equal to the following sets. D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} cse 1400 applied discrete mathematics problems 9 (a) S = {6, 8} (c) V = {0, 1, 2, 3, 4, 5, 6, 8} (d) W = {3, 5} (b) T = {1, 2, 4} 15. Consider the "set" S = { x : x x }. (b) Show that S S is a contradiction. This is known as Russell's paradox. (a) Show that S S is a contradiction. 7 Problems on Boolean Logic
(a) (b) (c) (d) (e) (f) (g) (h) AND Equivalent Exclusive or
True False 1. Match the term with its symbol. (a) (b) (c) (d) (e) 0 (f) (g) Implies (if . . . then . . . ) NOT OR (h) 1 (i) Conditional (if . . . then . . . ) 2. Given that p = True, q = False and r = False, compute the value of the following propositions. (a) p r (e) p r (b) p r (c) ( p q ) r (d) ( p r ) q 3. Express the conditional operator pq= using the not and or operations.
if p then q else r (f) ( p q ) r (g) ( p q ) r (h) p ( r q ) 1 if p = 0 or (p = 1 and q = 1) if p = 1 and q = 0 0 4. Write the Haskell expression 5. When p is False, describe the output values of the conditional from problem 4. as a Boolean expression using variables p, q and r and operators , and . cse 1400 applied discrete mathematics problems 10 6. When p is True, describe the output values of the conditional from problem 4. 7. Show that the conditional p q is equivalent to p q. 8. Construct truth tables to prove DeMorgan's laws (a) ( p q ) ( p ) ( q ) (b) ( p q ) ( p ) ( q ) 9. Show how to distribute NOT into a conditional. ( p q ) = (
10. Show how to factoring NOT out of a conditional. ) p q ( ) 11. Construct a truth table to prove a conditional is equivalent to its contrapositive, that is, p q q p 12. Construct a truth table to prove AND distributes over OR, that is, p (r r) (p r) (p r) 13. Construct a truth table to prove OR distributes over AND, that is, p (r r) (p r) (p r) Construct a truth table for the Boolean expression (( p q ) ( q r )) ( p r )
14. Construct a truth table for the Boolean expression (( p q ) r ) ( p ( q r ))
Is the equivalence True or False? Explain your answer. 15. Construct a truth table for the Boolean expressions ( p q ) ( q p )
16. Identify each statement as a tautology, a contradiction, or a contingency. (b) A (B C) = (A B) (A C) (d) (0, 1) {(0, 0), (0, 1), (1, 0), (1, 1)} (e) (0, 1) {(0, 0), (0, 1), (1, 0), (1, 1)} (f) ( p ( q q )) p (a) A = U (c) {(0, 1)} {(0, 0), (0, 1), (1, 0), (1, 1)} cse 1400 applied discrete mathematics problems 11 17. Complex computer circuits can be build from three basic gate types, called And, Or, and Not, and drawn as illustrated below. p q
And Gate pq p q
Or Gate pq p
Not Gate p The inputs p and q are high (1) or low (0) voltages. Fill in the chart below. p 0 0 q 0 1 0 p
0 pq pq 1 18. Let Bn be the set of all strings of high or low voltages of length n. For instance there are 4 strings of length 2. B2 = {00, 01, 10, 11} What is the cardinality of Bn ? 19. How many functions can be constructed from Bn to B = {0, 1} using And, Or, and Not operations? 20. How many functions can be constructed from Bn to Bm = {0m , . . . , 1m } using the gate operations And, Or, and Not? 21. It is estimated that there are 1080 atoms in the universe. Find the number of propositions n such that there are more Boolean functions in n variables than there are atoms in the universe. 8 Problems on Predicate Logic 1. The weak can never forgive (Ghandi) 2. The predicate statements below come from (?). (a) No Frenchmen like plumpudding. (b) All Englishmen like plumpudding. (c) Some thin persons are not cheerful. (d) All pigs are fat. (e) Some lessons are difficult. (f) All clever people are popular. (g) Some healthy people are fat. cse 1400 applied discrete mathematics problems 12 For each statement, identify the subject and predicate and write the statement using quantifiers ( and ) and logical operators ( , , , and ) 3. Which of the statements below are True and which are False? cse 1400 applied discrete mathematics problems 13 (a) (n N)(n2 > 0) (c) (n N)(n2 0) (b) (n N)(n2 > 0) (d) (n N)(n2 0) 4. Let p ( x ) be the statement x2 = x + 1. What is the truth value of the following statements. (a) p (0) (b) p ((1 + (d) ( x )( p ( x )) 5)/2) (e) ( x )( p ( x )) (f) ( x )( p ( x )) (c) ( x )( p ( x )) 5. This question is from (?). Let canfool ( p, t) be the proposition "You can fool person p at time t." Write Abraham Lincoln's famous quotation
You can fool some of the people all of the time, and all of the people some of the time, but you cannot fool all of the people all of the time. using the quantifiers over people p and times t and the canfool ( p, t) predicate. 9 Problems on Relations 1. Describe the relation p q = True over the set of Boolean variables p, q B when is each of the Boolean operators , , , . 2. How many relations can be defined on the following sets? (a) The sets of bits B = {0, 1}. (c) From the bits to the digits. (b) The sets of digits D = {0, 1, . . . , 9}. (d) From Bn , the bit strings of length n, to the bits B. 3. A relation on an nelement set A can be represented by an n n adjacency matrix. Given that there are 2(count of offdiagonal elements) reflexive relations on a set, how many reflexive relations are there for n = 0, 1, 2, 3 and 4? 4. Given that there are f (n) = 2n 2n(n1)/2 = 2n(n+1)/2 = 2n ( n +1) symmetric relations on a set with cardinality n. Compute the value of f (n) for n = 0, 1, 2, 3 and 4. 5. Describe what must be true for two lines, written as slopeintercept pairs (m0 , b0 ) and (m1 , b1 ), to be perpendicular. Use the notation The line (m, b) is described by the equation y = mx + b. (m0 , b0 ) (m1 , b1 ) to denote the perpendicular relationship between two lines. 6. Describe what must be true for two lines, written in standard form ( a0 , b0 , c0 ) and ( a1 , b1 , c1 ), to be perpendicular. Use the notation The line ( a, b, c) is described by the equation ax + by = c. ( a0 , b0 , c0 ) ( a1 , b1 , c1 ) to denote the perpendicular relationship between two lines. cse 1400 applied discrete mathematics problems 14 7. Describe what must be true for two lines, written as slopeintercept pairs (m0 , b0 ) and (m1 , b1 ), to be parallel. Use the notation (m0 , b0 ) (m1 , b1 ) to denote the parallel relationship between two lines. 8. Interpret the following ordered pairs as slopeintercept descriptions of lines. Which pairs are perpendicular? Which pairs are parallel? (a) (1, 2) and (1, 3). (b) (3, 2) and (3, 3). (c) (0.5, 2) and (2, 3). (d) (3, 2) and (4, 3). 9. For each relation, determine if it is reflexive, symmetric, antisymmetric, or transitive. (a) Equality on the natural numbers, written a = b. (b) Divides on the natural numbers, written a  b. (c) Subset on the power set 2A of A, written X Y for subsets X and Y of A. (d) Congruence mod m on the integers, written a b mod m. (e) x y if x  y = 9. (f) x y if  x  y is prime. 10. Let r = ( a, b) and s = (c, d) be ordered pairs of integers. (You could think of r and s as rational numbers.) If the crossproduct ad and cb are equal say r is equivalent to s and write r s. (a) Give instances of r = ( a, b) and s = (c, d) that are equivalent. (b) Give instances of r = ( a, b) and s = (c, d) that are not equivalent. (c) What pairs are equivalent to the pair (1, 1)? (d) Is is r s reflexive? Explain. (e) Is r s symmetric? Explain. (f) Is r s transitive? Explain. (g) Is r s an equivalence relation? Explain. (h) How does this relation describe equivalent names for rational number fractions? (i) How does this relation describe a geometric relationship between points in a twodimensional space? 11. Let a, b, c, d be integers and say the ordered pair ( a, b) related to (c, d) if a + d = b + c. ( a, b) (c, d) if a + d = b + c
(b) Is symmetric? Explain. (d) Is an equivalence relation? Explain. (c) Is transitive? Explain. (a) Is reflexive? Explain. 12. Say that two floating point numbers x and y are approximately equal if the differ by 3.125 102 . x y if and only if  x  y (a) Is approximately equal reflexive? Explain. (b) Is approximately equal symmetric? Explain. = 1/32 = cse 1400 applied discrete mathematics problems 15 (c) Is approximately equal antisymmetric? Explain. (d) Is approximately equal transitive? Explain. (e) Is approximately equal an equivalence relation? Explain. (f) Is approximately equal a partial order? Explain. 13. On the set of real numbers R = { x :  < x < } define the relation S = {( x, y) : x, y R, and x  y is an integer} Show that S is an equivalence relation on R. 14. Consider the childhood game "rock beats scissors, scissors beat paper, paper beats rock." (a) Construct the adjacency matrix that represents the "beats" relation. (b) Is "beats" reflexive, symmetric, antisymmetric, transitive? 15. Let R and S be sequences of natural numbers. Say that sequence R precedes S and write R S if ri si for all i = 0, 1, 2, . . . As an example, R = 0, 1, 2, 3, . . . precedes S = 1, 2, 4, 8, . . . because i 2i for all natural numbers i. (a) Show that precedes is a partial order. (b) Draw a graph showing the order of the 8 finite sequences 0, 0, 0 1, 0, 0 0, 0, 1 1, 0, 1 0, 1, 0 1, 1, 0 0, 1, 1 1, 1, 1 16. The U. S. Post Office can increase its efficiency by sorting letters based on width and height. Define a partial order on a set of ordered pairs (w, h) that describe the width and height of a letter. 17. The U. S. Post Office also ships packages that have a width, height, and depth. Define a partial order on ordered triples (w, h, d) to help the U.S.P.O. sort packages. 18. Negate the definition of "relation is reflexive:" ( x X)( x x )
19. Negate the definition of "relation is symmetric:" to define "relation is not reflexive." ( x X)(y X)(( x y) = (y x ))
to define "relation is not symmetric." 10 Problems on Functions
1. Let f : X Y be a function. Answer the following True or False. Explain your answer. (a) The set X is the range of function f . (b) The set X is the domain of function f . (c) The set Y is the range of function f . (d) The set Y is the domain of function f . 2. Let A = { a, b, c} and B = {0, 1}. Which of the following are functions from A to B. cse 1400 applied discrete mathematics problems 16 (a) {( a, 0), (b, 1), (c, 0)} (c) {( a, b), (b, a), ( a, c)} (b) {( a, 0), ( a, 1), (c, 0)} (d) {( a, 1), (b, 1), (c, 1)} 3. Consider this algorithm for constructing a function f from X to Y.
For each element x X choose an element y Y and place the ordered pair ( x, y) in f . (a) If the cardinality of X is 5, how many times does the algorithm choose an x from X? (b) If the cardinality of Y is 9, how many choice of y are there for each x? (c) True or False: If the X = 5 and Y = 9, then there are 59 functions f from X to Y. Explain your answer. (d) True or False: If the X = 5 and Y = 9 then there are 45 functions f from X to Y. Explain your answer. (e) True or False: If the X = 5 and Y = 9 then there are 95 functions f from X to Y. Explain your answer. 4. Answer the following True or False. Explain your answer. (f) If X = n and Y = m how many functions f can be defined from X to Y? 5. How many Boolean functions B( p ) in one variable are there? 6. How many Boolean functions B( p, q ) in two variables are there? 7. How many Boolean functions B( p, q, r ) in three variables are there? 8. Let f : X Y be a function. Answer the following True or False. Explain your answer. (a) If for every y Y there is an x X such that f ( x ) = y, then f is onetoone. (b) If for every y Y there is an x X such that f ( x ) = y, then f is onto. (c) The codomain of a Boolean function is {0, 1}. (b) The domain of a function of two Boolean variables is {(0, 0), (0, 1), (1, 0), (1, 1)}. (a) The domain of a function of one Boolean variable is {0, 1}. 9. Define a function that maps the natural numbers from 0 to 2n  1 onto the two's complement numbers 2n1 to 2n1  1. (d) If for every pair x1 , x2 X, x1 = x2 implies f ( x1 ) = f ( x2 ), then f is onto. (c) If for every pair x1 , x2 X, x1 = x2 implies f ( x1 ) = f ( x2 ), then f is onetoone. 11 Problems on Logarithms and Exponentials
1. Answer True or False. Explain your answer. (a) 2a 2b = 2a+b . (b) 2a 2b = 2ab . (c) 2n 2n = 22n . (d) 2n 2n = 2n .
2 (e) (2a )b = 2ab . (f) (2a )b = 2a . (g) (2n )n = 2n . (h) (2n )n = 2n .
n 2 b 2. Evaluate the logarithm base 2 function lg x at the given value for x. cse 1400 applied discrete mathematics problems 17 (a) lg(256) (b) lg(0.25) (c) lg(0.125) (d) lg(1/1024) (e) lg( 3 16) (f) lg( 5 8) (g) lg 3 32 (h) log16 3 32
(i) lg(2n! ) 3. In binary notation, how many bits are required to name a natural number n when 23 n < 24 ? 4. In binary notation, how many bits are required to name a natural number n 5. True or False: The logarithm (base 2) function lg( x ) maps the open interval (0, ) onto the set of real numbers. Explain your answer. 6. True or False: The logarithm (base 2) function lg( x ) is not onetoone. Explain your answer. 7. True or False: Since 210 = 1024 is approximately equal to 103 = 1000, the log base 2 of 10 is approximately equal to 3 and 1/3. Explain your answer. 8. Use the fact that 27 = 128 is approximately equal to 53 = 125 to approximate the value of log5 (2). 9. Given that ln 2 0.693147 and log 2 0.301030 Show that lg x ln x + log x Specifically, that the error is less than 1% in that ln x + log x  1 < 0.01 lg x 10. For each problem below, find a constant c R such that the equation is an identity. (a) lg( x ) = c ln( x ) (b) ln( x ) = c lg( x ) (c) lg( x ) = c log( x ) (d) log( x ) = c lg( x ) (e) lg( x ) = c logb ( x ) (f) logb ( x ) = c lg( x ) 11. Consider the proposition: loga (b) logb ( a) = 1. Is the position True or False. You may assume a and b are natural numbers greater than or equal to 2. Explain your answer. 12. Use the "sum of logs is log of a product rule" to write the sum
1 k n lg k as a logarithm that involves a factorial. 13. A solution's pH measures its acidity or alkalinity, with 7 called neutral. In particular, pH =  log10 (H3 O+ ) where H3 O+ is the concentration of hydronium ions in the solution. The pH scale is logarithmic: When pH increases by 1, alkalinity increases 10fold. Likewise, when pH decreases by 1, acidity increases 10fold. Pretend the average pH of sea water will decrease by 0.5 in 100 years. By what factor will the acidity sea water increase? cse 1400 applied discrete mathematics problems 18 14. If a principle of P dollars is invested at an interest rate r compounded n times per year, then the amount after t years is r nt A = P 1+ n Pretend P = $1 is invested at a 10% rate compounded quarterly. How many years t will go by before A = $10? 12 Problems on Integer Functions
1. Answer the following True or False. Explain your answer. (a) (b) (c) (d) x = n if and only if n x < n + 1. x = n if and only if x n < x + 1. (g) Every integer n > 0 can be represented in lg(n) + 1 bits. (h) Every integer n > 0 can be represented in lg(n + 1) bits. (i) If 12 objects are put in 5 boxes some box must contain at least 12/5 = 3 objects and some box must contain no more than 12/5 = 2 objects. x = n if and only if x  1 < n x. x = n if and only if n  1 < x n. (e) x = x + { x }, where { x } if the fractional part function. (f) If n and m are positive integers, then n/m is the quotient when n is divided by m. 2. Evaluate the following floors. (a) (b) (c) e 2 (d) (e) (f) = (1 + 5)/2 3. Evaluate the following ceilings. (a) (b) (c) e 2 (d) (e) (f) = (1 + 5)/2 0.5772 4. Evaluate the following fractional parts rounded to 4 decimal places. (a) 2 (d) { } = (1 + (e) { } = (1  (f) {} 5)/2 (b) { } (c) {e} 5)/2 5. Evaluate the following rounds. (a) 2 (c) ( ) (d) () (b) ( ) cse 1400 applied discrete mathematics problems 19 6. Prove that x +  x = 0 if x Z, but x +  x = 1 if x Z. 8. What can you conclude about the sum of the fractional parts of x and  x 7. What can you conclude about the sum of the floor of x and  x { x } + { x } = ?
10. How would you define a b mod 0? 9. How would you define a b mod 1 for a, b Z? 13 Problems on Polynomials 1. Compute the degree of the polynomials (a) p( x ) = x5 + 4x3 + 2x  7 (b) p( x ) = 5x10  1 (c) p( x ) = an1 x n1 + an2 x n2 + + a1 x + a0 2. What are the roots of the polynomial equation x2  x  1 = 0? 4. Answer the following True or False. Explain your answer. (b) ( x + 1)( x  1) = x2  1. (a) (1)( x  1) = x  1. (d) p( x ) = 0kn1 ak x k 3. For a = 0, what are the roots of the polynomial equation ax2 + bx + c = 0? 5. Use Horner's rule to evaluate the following polynomials at the given value of x. (a) p( x ) = 3x4  5x2  16x  4 at x = 3. (b) p( x ) = 3x5  4x3 + 3x2  7 at x = 2. (c) p( x ) = 2x4  3x3 + 2x2 + 4x  3 at x = 3. (d) p( x ) = x5  2x3 + 3x2  1 at x = 2. (e) x n1 + x n2 + + x + 1 = ( x n  1)/( x  1) provided x = 1. (d) ( x n1 + x n1 + + x + 1)( x  1) = x n  1. (c) ( x3 + x2 + 1)( x  1) = x3  1. (e) p( x ) = x4 + x3 + x2 + x + 1 at x = 2. (f) p( x ) = x4 + 4x3 + 6x2 + 4x + 1 at x = 2. 6. Polynomials can be written in the falling (factorial) power basis x0 = 1, x1 = x, x2 = x ( x  1), x3 = x ( x  1)( x  2), . . . , x n = x ( x  1)( x  2) ( x  n + 1) as an alternative to the standard basis 1, x, x2 , x3 , . . . , x n . (a) Horner's rule evaluates a polynomial a n x n + a n 1 x n 1 + a 1 x + a 0 written in the standard basis using n additions and n multiplies. Devise an algorithm to evaluate a polynomial a n x n + a n 1 x n 1 + a 1 x 1 + a 0 x 0 written in the falling power basis. Count the number of additions and multiplications your algorithm uses. cse 1400 applied discrete mathematics problems 20 7. The set of all points ( x, y) that lie on a line through the origin can be written in the form ax + by = 0 where ( a = 0) (b = 0) (a) What is a logically equivalent way to write the clause ( a = 0) (b = 0)? (b) Consider a, b to be the tip of a vector from the origin. What is the Euclidean length of a, b and how can you state the length is not zero? 13.1 Problems on Permutations 1. True or false: A permutation of X is a onetoone function from X onto X. 3. True or false: [ a, a, b] is a permutation of { a, b, c}. 2. True or false: [c, a, b] is a permutation of { a, b, c}. 4. True or false: There are 2n permutations of an n element set. 5. True or false: There are n! permutations of an n element set. 6. Let H = {0, 1, 2, . . . , E, F }. (a) How many permutations can be defined on H? (b) In how many ways can you choose 5 elements from H (c) In how many ways can you choose and permute 5 elements from H (d) How many permutations on H have 16 cycles? (e) How many permutations on H have 1 cycle? 7. Let X be an 8element set. How many permutations on X have 4 cycles? That is, what is the value of the Stirling number [8] "8 cycle 4"? You may want to know row 7 of Stirling's triangle of the first kind is 4 7 0 1 2 3 4 0 720 1764 1624 735 9. Use cyclic notation to describe the permutation (0, 2, 4, 6, 1, 3, 5, 7) of the octal alphabet {0, 1, 2, 3, 4, 5, 6, 7} 8. Use cyclic notation to describe the permutation (0, 1, 2, 3) of the elements in the set {0, 1, 2, 3} 10. Use cyclic notation to describe the permutation (1, 2, 0, 7, 3, 4, 5, 6) of the octal alphabet {0, 1, 2, 3, 4, 5, 6, 7} 14 Problems on Induction
1. Use mathematical induction to prove the sum of the first n natural numbers is n(n  1)/2. That is,
0 k < n k= n ( n  1) 2 2. Use mathematical induction to prove the sum of the first n powers of 2 is 2n  1. That is,
0 k < n 2k = 2n  1 cse 1400 applied discrete mathematics problems 21 3. Use mathematical induction to prove the sum of the even natural numbers from 0 to 2n is n(n + 1). That is,
k =0 2k = n(n + 1) n 4. Use mathematical induction to prove the sum of products consecutive pairs of natural numbers is the product of three consecutive number divided by 3, that is,
n 1 k =0 k ( k  1) = n(n  1)(n  2) 3 5. Use mathematical induction to prove the summation formula 1 n = (2k  1)(2k + 1) 2n + 1 k =1 n 6. Use mathematical induction to prove the sum the cubes is a square, that is,
n 1 k =0 is true for all natural numbers n 0. k3 = n ( n  1) 2 2 7. Use mathematical induction to prove the sum of k times k! from k = 0 to k = n  1 is n!  1
n 1 k =0 k k! = n!  1.
1 1 < 2 2 n k k =1
n 8. Use mathematical induction to prove the summation formula is true whenever n is a natural number greater than 1. 9. Prove 6 divides 7n  1 for all natural numbers n. 11. Prove the function T (n) = 3n  2 satisfies the recurrence equation Tn = 3Tn1 + 4 12. Prove the function T (n) = lg(n) satisfies the recurrence equation T2n = Tn + 1 with initial condition T1 = 0. 13. Use mathematical induction to prove that sn = 2n + 3n solves sn = 5sn1  6sn2 with initial conditions s0 = 2, s1 = 5. with initial condition T0 = 1 10. Prove n! 2n for all natural numbers n 4. cse 1400 applied discrete mathematics problems 22 14. Let Fn denote a term in the Fibonacci sequence n 0 1 2 3 4 5 6 7 8 9 Fn 0 1 1 2 3 5 8 13 21 34 ... ... (a) Use mathematical induction to show that the sum of the first n Fibonacci numbers is a Fibonacci number minus one. Specifically, show that F0 + F1 + + Fn1 = Fn+1  1 (b) Use mathematical induction to prove that Fn 2Fn1 (c) Use induction over k to prove that Fn+k = Fk Fn+1 + Fk1 Fn (d) Prove that for n 1 gcd( Fn , Fn1 ) = 1 for n 2. (e) Prove that the sum of the first n  1 Fibonacci numbers is 1 less than the n + 1 Fibonacci number. That is, Fn = 1 +
n 2 k =0 Fk if n 2 (f) Prove that the sum of the oddindexed Fibonacci numbers up to F2n+1 equals F2n+2 . That is, k =0 F2k+1 = F2n+2 n (g) Prove that k =0 F2k = F2n+1  1
= n (h) Prove that n n1 n2 0 + + ++ 0 1 2 n
2 Fn+1 Fn1  Fn = (1)n , k =0 n nk k = Fn+1 (i) Prove Cassini's identity for n > 0 where Fk is a Fibonacci numbers number. (j) Define the Lucas numbers Ln by Ln = Ln1 + Ln2 , for n > 1, i. Show that the Lucas numbers Ln satisfy the equation Ln = Fn+1 + Fn1 L0 = 2, L1 = 1 cse 1400 applied discrete mathematics problems 23 ii. Prove that F2n = Fn Ln where Fn is a Fibonacci number. 15. Prove that the sum of terms in a column of Pascal's triangle equals a term in the next column, that is,
n 1 k=m k m = n , m+1 n m+1 16. Prove that the sum of term in a row of Pascal's triangle equals a power of 2, that is, k =0 n n k = 2n 17. Use mathematical induction to prove that the Harmonic solve the recurrence equation
n 1 k =1 Hk + n = nHn n 15 Problems on Recurrences
1. Find a recurrence equation and initial condition that enumerates the sequence of even natural numbers. 2. What change(s) must be made to your answer to problem 1 to enumerate the sequence of odd natural numbers? 3. Use mathematical induction to prove the following recurrence equations and initial conditions are solved by the given functions. (a) tn = 3tn1 , t0 = 2, t(n) = 2 3n . t ( n ) = 2n + 3n . (d) tn = 2tn1 + tn2 , t0 = 2, t1 = 2, t(n) = (1 + 2)n + (1  2)n . (b) tn = 3tn1 + 2, t0 = 0, t(n) = 3n  1. (c) tn = 5tn1  6tn2 , t0 = 2, t1 = 5, 4. Let A = a0 , a1 , a2 , . . . , an , . . . be an arithmetic sequence sequence. That is, terms in A are given by a linear function a(n) = mn + b for some slope m and yintercept b. Find a recurrence equation and initial condition that enumerates the terms in the sequence. 5. Let G = g0 , g1 , g2 , . . . , gn , . . . be a geometric sequence sequence. That is, terms in G are given by a exponential function g(n) = br n for some ratio r and yintercept b. Find a recurrence equation and initial condition that enumerates the terms in the sequence. 6. Use mathematical induction to prove that the common logarithm function Tn = log(n) satisfies the recurrence equation T10n = Tn + 1 with initial condition T1 = 0. 7. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence r n = r n  1 + 22 with initial condition r0 = 3.
n 1 n r 0 r n 2 cse 1400 applied discrete mathematics problems 24 8. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence
2 r n = r n 1  2 ( r n 2  1 )2
n n with initial condition r0 = 3. 9. Use mathematical induction to prove that the function r (n) = 22 + 1 solves the Fermat recurrence r n = r 0 r n 1 + 2 with initial condition r0 = 3. 10. Morse code is a series of dots () and dashes (). Pretend a dot can be typed in 1 second while a dash takes 2 seconds to type. Find a recurrence equation that describes how many messages can be typed in n seconds. 11. In how many ways can n 1 be expressed as a sum of 1's and 2's? Different term orders are considered different sums. 12. A domino is a rectangular tile 1 unit long and 2 units high Dominos can be laid out to tile an n 2 area. For example, there are 2 ways to tile a 2 2 area And 3 ways to tile a 3 2 area: 13. Pretend you invested $1 on January 2, 2010. Pretend interest accrues at an annual compound rate of 10%. (For example, on January 2, 2011 and January 2, 2012 you will have $1.10 and $1.21 in your account.) How many years will you need to wait to save over $1, 000, 000? 14. Pretend you invested $1 on January 2 every year. Pretend interest accrues at an annual compound rate of 10%. (For example, on January 2, 2011 and January 2, 2012 you will have $2.10 and $1.00 + $2.10 + $0.21 = $3.31 in your account) How many years will you need to wait to save over $1, 000, 000? 15. Pretend you invested $1 on the second day of every month. Pretend interest accrues at an monthly compound rate of 10%. How many months will you need to wait to save over $1, 000, 000? 16. Consider the sequence generated by adding the alternating integers 1, 2, 3, 4, 5, . . .. The first few sums of these alternating integers are 1, 1, 2, 2, 3, . . . Find a function f (n) that generate these partial sums. That is, f (0) should equal 1, f (1) should equal 1, f (2) should equal 2, f (3) should equal 2, and so on. , a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb, . . . Name the terms in this sequence sn so that s0 = , s1 = a = s0 a, s2 = s0 b, s3 = s1 a = aa, s4 = s1 b = ab, and so on. Find a recursion equation that models the generation of these alphabetically ordered strings. Find a recurrence relation that counts the number of n 2 tilings. 17. Consider the strings of over the alphabet { a, b} listed in order by length then alphabetically, that is, cse 1400 applied discrete mathematics problems 25 16 Problems on Proofs
1. Construct a truth table to prove that resolution [( p q ) ( p r )] ( q r )
is a tautology. 2. Let n be an integer. Prove that if n is odd, then n = 4k + 1 or n = 4n + 3 for some integer k. 3. Find a counterexample to prove the statement "All shapes that have four sides of equal length are squares." 4. Let a be an integer. Prove that if a2 is odd, then a is odd. 5. If b < 0 show that the remainder r = a  bq is greater than or equal to 0 when the quotient q is has value q = a/b . 6. Is the conditional statement `If x then x X.' True or False? Explain your answer. 7. Prove that "if n is even and n is odd, then n2 = 2n" is a True statement. 8. Let a be a natural number. Prove that if a2 is a multiple of 3, then a is a multiple of 3. 9. Prove that 3 is irrational. 10. Prove that the greatest common divisor of two consecutive Mersenne numbers is 1. 11. Prove or disprove: The greatest common divisor of two consecutive triangular numbers is 1. 12. Prove of disprove the statement: The 8 bit floating point numbers from the course are closed under multiplication. 13. Prove of disprove the statement: The 8 bit floating point numbers from the course obey the associative law for multiplication. 14. Prove the integers are countable by describing a onetoone and onto function that maps the natural number to the integers. 15. Prove the Cartesian product N N is countable by describing a onetoone and onto function that maps the natural number to the N N. (Hint: list the ordered pairs in triangular form (0, 0), (1, 0), (0, 1), (2, 0), (1, 1), (0, 2), . . .
and use the triangular numbers to name the ordered pairs.) ...
View
Full
Document
This note was uploaded on 02/11/2012 for the course MTH 2051 taught by Professor Shoaff during the Fall '11 term at FIT.
 Fall '11
 Shoaff
 Math, Sets

Click to edit the document details