A Primer on Exponentials and Logarithms. Addendum to Appendix 2:
Exponential and Logarithmic Functions. Exponentials. The square of a number b
is often ...
A Primer on Exponentials and Logarithms Addendum to Appendix 2: Exponential and Logarithmic Functions Exponentials The square of a number b is often written as b2 (read as “b squared”). This means to multiply b by itself. b2 = b ∗ b
32 = 3 ∗ 3
52 = 5 ∗ 5
(1/2)2 = (1/2) ∗ (1/2)
The cube of a number b is often written as b3 (read as “b cubed”). This means to multiply three bs together. b3 = b ∗ b ∗ b
33 = 3 ∗ 3 ∗ 3
53 = 5 ∗ 5 ∗ 5
(1/2)3 = (1/2) ∗ (1/2) ∗ (1/2)
When n is a positive integer, bn (read as “b to the nth power”) means to multiply n bs together. The base is b, and the exponent is n.
b−n
bn = b| ∗ b ∗{z· · · ∗ b} n bs n is equal to (1/b) , which is multiplying n (1/b)s together. b−n = (1/b)n = (1/b) ∗ (1/b) ∗ · · · ∗ (1/b) {z
|
n (1/b)s
}
Here are some of the boundary cases: b0 = 1
b1 = b
b−1 = 1/b
0−n is undefined
When x is a real number, but not an integer, then bx is defined (more precisely, is a real √ number) if b is positive. For example, the square root of b is b = b0.5 , but this is not a real number if b < 0. Some useful formulas for exponentials are: bx ∗ by = bx+y
bx /by = bx−y
(bx )y = bx∗y
Decimal and Binary Numbers Exponentials are the basis for decimal and binary numbers. Here are examples in decimal: 365 = 3 ∗ 102 + 6 ∗ 101 + 5 ∗ 100 3.14 = 3 ∗ 100 + 1 ∗ 10−1 + 4 ∗ 10−2 365 and an approximation to pi can also be expressed using powers of two: 365 = 28 + 26 + 25 + 23 + 22 + 20 3.140625 = 21 + 20 + 2−3 + 2−6 So, decimal 365 is binary 101101101, and decimal 3.140625 is binary 11.001001, though one should know that fractional numbers are rarely written out in binary. 1
Logarithms Logarithms can be thought of as an inverse to exponentials. If b is a real number with b > 1, and if y is a positive real number, then logb y = x if and only if bx = y. Read logb y as “log y, base b.” log10 1000 = 3 because 103 = 1000 log2 16 = 4 because 24 = 16 One way to think about logarithms is repeated division by the base b until 1 is reached. The logarithm is the number of divisions by b. 1000/(10 ∗ 10 ∗ 10) = 1 so log10 1000 = 3 16/(2 ∗ 2 ∗ 2 ∗ 2) = 1 so log2 16 = 4 For most numbers, repeated division doesn’t result in exactly 1, but a logarithm can be estimated to within 1 this way. 10/(2 ∗ 2 ∗ 2) > 1 and 10/(2 ∗ 2 ∗ 2 ∗ 2) < 1 so 3 < log2 10 < 4 Some useful formulas for logarithms are: logb (xy) = logb x + logb y
logb (x/y) = logb x − logb y
loga x = logb x/ logb a
The repeated division method is based on the first formula. Using base 2: log2 x = log2 (2 ∗ (x/2)) = log2 2 + log2 (x/2) = 1 + log2 (x/2)
The Number of Bits Needed to Represent n Objects An int in Java and C can represent any integer from −2,147,483,648 to 2,147,483,647. Why is this the case? A big part of the reason is that 32 bits are used to represent ints. The total number of int integers is 4,294,967,296 (this includes 2,147,483,648 negative integers plus 2,147,483,647 positive integers plus one zero integer). It turns out that: 4,294,967,296 = 232
and
log2 4,294,967,296 = 32
Suppose one needs to have a unique (binary) number for 1000 objects. Because 9 < log2 1000 ≤ 10 (note that 29 = 512 and 210 = 1024), at least 10 bits are needed. Back in the days when one couldn’t even buy megabyte hard disks over the counter (they were big expensive things that had to be ordered in advance), programmers had to obsess about minimizing the number of bits to represent information, helping to lead to the Y2K problem. The Y2K problem was that many programs only used two digits to represent years (from 1900 to 1999, omitting the 19), causing a problem for the year 2000. 2
Tables n 2n 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1,024 20 1,048,576 30 1,073,741,824
n 0 1 2 3 4 5 6 7 8 9 10 100 1,000
log2 n ≈ undefined 0 1 1.585 2 2.322 2.585 2.807 3 3.170 3.322 6.644 9.966
n log2 n ≈ 1 0 10 3 100 7 1,000 10 10,000 13 100,000 17 1,000,000 20 10,000,000 23 100,000,000 27 1,000,000,000 30 10,000,000,000 33 100,000,000,000 37 1,000,000,000,000 40
Exercises 1. Generate a table for powers of 3, from 30 to 310 . 2. Determine the binary numbers that correspond to decimal 2013 and decimal 7734. 3. Find the integers that bound the following numbers: (a) log2 100 (b) log2 2013 (c) log2 7734 (d) log2 (1/100) 4. In terms of n, what is the value of log2 (2n + 2n )? 5. Generate a table for log2 n for n equal to 10, 20, . . . , 100. Use the table above and the formula logb (xy) = logb x + logb y. 6. Find the integers that bound logb 1000 from b = 2 to b = 10. 7. In decimal notation, the fraction 1/3 is a repeated decimal 1/3 = 0.333, that is, where 3 keeps on repeating. Determine which of the following repeated binary fractions is equal to 1/3. Also try to figure out what the others are equal to. (a) 0.0111 (b) 0.010101 (c) 0.01001001001 (d) 0.011001100110
3