* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download A Quick Change of Base Algorithm for Fractions
Foundations of mathematics wikipedia , lookup
Ethnomathematics wikipedia , lookup
Large numbers wikipedia , lookup
Location arithmetic wikipedia , lookup
Approximations of π wikipedia , lookup
Collatz conjecture wikipedia , lookup
List of prime numbers wikipedia , lookup
Proofs of Fermat's little theorem wikipedia , lookup
Positional notation wikipedia , lookup
We now return to our original question concerning an array with the entries 1, 2, . . . , n 2 . The key to showing that an n-by-n matrix A is a linear combination of R2 , . . . , Cn is to show that for each value of k we have aik − ai1 = a j k − a j 1 for all i and j. In particular, if we let A be the n-by-n matrix formed by listing the numbers from 1 to n 2 consecutively, then ai j = (i − 1)n + j. This means that aik − ai1 = k − 1 for every i. Thus we can do the trick described at the start of this note not just for the first 25 numbers, but for the first n 2 numbers for any n, and the predicted sum will always be the sum of the diagonal entries, 12 (n 3 + n). ◦ A Quick Change of Base Algorithm for Fractions Juan B. Gil ([email protected]) and Michael D. Weiner ([email protected]), Penn State Altoona, Altoona, PA 16601 In this note we discuss the digital (floating-point) representation in various arithmetic bases of a fraction m1 with m ∈ N. With a base b and a denominator m, we associate a corresponding key, defined as the string of digits consisting of the residues of b modulo m, and will use it to speed up some computations. For example, if m is a prime for which m1 has a maximum period expansion of m − 1 digits, and if b is a primitive root mod m, then the associated key can be used to obtain quickly the digital representation of mi for i = 2, 3, . . . , m − 1, from the representation of m1 . Recall that if m is prime, b is a primitive root mod m if b j ≡ 1 (mod m) for 1 ≤ j < m − 1. On the other hand, for arbitrary integers b and m greater than 1, we will use the key to give a surprisingly simple algorithm to change the representation of m1 in base b to its representation in base b + mt for any t ∈ N. Our arguments rely on basic modular arithmetic and well-known results that can be found in any textbook on elementary number theory; see, for example, [1] or [2]. Fractions with cyclic periods. Let us start with the simple and commonly used example of m = 7. The number 17 has a couple of fascinating properties that delight even those who are familiar with the mysteries of math. In the decimal system 17 = 0.142857. Let 132645 be the key associated with 10 and 7 by means of the residues 100 ≡ 1 (mod 7), 101 ≡ 3 (mod 7), 102 ≡ 2 (mod 7), 103 ≡ 6 (mod 7), 104 ≡ 4 (mod 7), 105 ≡ 5 (mod 7), and let k(i) be the digit in the period 142857 of key 1 7 that corresponds to the digit i in the 1 3 2 6 4 5 ↓ ↓ ↓ ↓ ↓ ↓ , 1 4 2 8 5 7 that is, k(1) = 1, k(2) = 2, k(3) = 4, and so on. Then 7i = 0.k(i) · · ·, where the missing 5 digits in the period are placed as to get a rotation of the period of 17 . That is, 2 7 56 = 0.285714, 3 7 = 0.428571, 4 7 = 0.571428, 5 7 = 0.714285, 6 7 = 0.857142. c THE MATHEMATICAL ASSOCIATION OF AMERICA 6 6 In other words, each number i × 10 7−1 is a rotation of 10 7−1 = 142857. For this reason, 142857 is called a cyclic number. This property is preserved in some other arithmetic bases. For instance, in base 3, the key is the same, and the map k from the key to the period 010212 of 17 is given by 1 3 2 6 4 5 ↓ ↓ ↓ ↓ ↓ ↓ . 0 1 0 2 1 2 Thus 1 7 = (0.010212)3 , 2 7 = (0.021201)3 , 3 7 = (0.102120)3 , 4 7 = (0.120102)3 , 5 7 = (0.201021)3 , 6 7 = (0.212010)3 . Therefore, we say that 7 generates the 3-cyclic number (010212)3 . Similarly, in base 17, we get 1 7 = (0.274e9c)17 , 2 7 = (0.4e9c27)17 , 3 7 = (0.74e9c2)17 , 4 7 = (0.9c274e)17 , 5 7 = (0.c274e9)17 , 6 7 = (0.e9c274)17 , where c = 12 and e = 14. Thus 7 also generates a 17-cyclic number. However, in the binary system, we have 1 7 = (0.001)2 , 2 7 = (0.010)2 , 3 7 = (0.011)2 , 4 7 = (0.100)2 , 5 7 = (0.101)2 , 6 7 = (0.110)2 , so 7 does not generate a 2-cyclic number. Note that in this case the key is 124, which only provides information about the behavior of 17 , 27 , and 47 . If we are flexible about the base b chosen to represent a number, then for every odd prime p we can always choose b so that 1p has a maximum period in that base. In other words, every prime generates a b-cyclic number for some base b. How many such bases are there? Are there b-cyclic numbers for every b? The answer to these questions is given by the following fact: An odd prime p generates a b-cyclic number if and only if b is a primitive root mod p. A discussion of this statement as well as other interesting facts about cyclic numbers can be found in [2] and [3]. Therefore, there are infinitely many bases for which a given prime p gives rise to a cyclic number. On the other hand, whether a given b (not a square) is a primitive root for infinitely many primes is still an open problem (known as Artin’s conjecture). In any case, in the decimal system, the numbers 7, 17, 19, 23, 29, among many others, are primes that generate cyclic numbers. However, in the widely used hexadecimal system (b = 16) for example, there are no cyclic numbers at all because a square is never a primitive root. Thus the reason why 7 generates cyclic numbers in the bases 3, 10, and 17 is that these numbers are primitive roots mod 7 (while 2 is not). In general, if p is an odd prime and b is a primitive root mod p, then the corresponding key consists of p − 1 VOL. 39, NO. 1, JANUARY 2008 THE COLLEGE MATHEMATICS JOURNAL 57 distinct digits, and the representation of period as described above. i p can be obtained from 1 p by rotating the Change of base algorithm. We continue to examine the fraction 17 . Observe that its digital representations in the bases 3, 10, and 17, are related as follows. The period in base 10 can be obtained from that in base 3 by adding the key as follows: 010212 ← base 3 + 132645 ← key 142857 ← base 10; and in the same way, 142857 ← base 10 + 132645 ← key 274e9c ← base 17. More generally, the period of 17 in base 3 + 7t consists of the 6 digits obtained by adding t times 132645 to the period 010212. In particular, since 2012 = 3 + 7 × 287, 1 7 = (0.[287][862][574][1724][1149][1437])2012 , where [287] denotes the 287th nonzero digit in base 2012, and so on. This is a consequence of the following results. Lemma. Let b and m be integers greater than 1. Then in base b the fraction the digital representation m1 = (0.a1 a2 · · · ai · · · )b with ai = 1 m has b i−1 1 (b (mod m)) − (bi (mod m)). m m Proof. For any i, we may write a1 a2 · · · ai . ai+1 · · · = Note that 0 ≤ Therefore, 1 (bi m 1 bi 1 = (bi (mod m)) + (bi − (bi (mod m))). m m m (mod m)) < 1, so the last term must be the integer part of a1 a2 · · · ai−1 ai = bi . m 1 i (b − (bi (mod m))), m and so a1 a2 · · · ai−1 = 1 i−1 (b − (bi−1 (mod m))). m a1 a2 · · · ai−1 0 = b i−1 (b − (bi−1 (mod m))). m This implies that The formula for ai follows by taking the appropriate difference. 58 c THE MATHEMATICAL ASSOCIATION OF AMERICA Theorem. Let b and m be integers greater than 1. If m1 = (0. a1 a2 · · · ai · · · )b , then for any t ∈ N, in base (b + mt), the fraction m1 has the digital representation 1 m = (0. a1 a2 · · · ai · · · )b+mt , where ai = ai + tki with ki = (bi−1 (mod m)). Proof. By the lemma, b i−1 1 (b (mod m)) − (bi (mod m)), and m m b + mt 1 ((b + mt)i−1 (mod m)) − ((b + mt)i (mod m)). ai = m m ai = On the other hand, (b + mt)i−1 ≡ bi−1 (mod m) and (b + mt)i ≡ bi (mod m). Thus we get ai − ai = t (bi−1 (mod m)) = tki , as claimed. Earlier we discussed 17 in bases 3, 10, and 17. As a second example, consider the fraction 14 . According to the theorem, if we find the representation of 14 in the bases 2, 3, 4, and 5, together with the corresponding keys, then we can easily get the digital representation of 14 in any base. Recall that the key k1 · · · k associated with m1 in base b is defined by ki = (bi−1 (mod m)), where is either the length of the fundamental period of m1 or the length of its nontrivial fractional part. Thus 1 4 = (0.01)2 → 12, 1 4 = (0.02)3 → 13, 1 4 = (0.1)4 → 1, 1 4 = (0.1)5 → 1. Hence, 14 = (0.13)6 since 01 + 12 = 13, and larly, using 1 as key, one gets for instance 1 4 = (0.2)8 , 1 4 = (0.4)16 , In particular, in base 2009, we have 1 4 1 4 = 0.25 because 13 + 12 = 25. Simiand 1 4 = (0.3)13 . = (0.[502])2009 . References 1. J. Conway and R. Guy, The Book of Numbers, Copernicus, 1996. 2. L. E. Dickson, History of the Theory of Numbers, Vol. I: Divisibility and primality, Chelsea, 1966. 3. S. Guttman, On cyclic numbers, Amer. Math. Monthly 41 (1934) 159–166. ◦ A Waiting-Time Surprise Richard Parris ([email protected]), Phillips Exeter Academy, Exeter, NH 03833 Let x1 , x2 , x3 , . . . be a sequence of numbers chosen randomly (and uniformly) from the unit interval 0 < x < 1. For each real number t ≥ 0, the first n for which VOL. 39, NO. 1, JANUARY 2008 THE COLLEGE MATHEMATICS JOURNAL 59