Math You Need

Check out my other, more practical math blog: Math You Need.

Sunday, May 6, 2012

Repeating Decimals

Question
Occasionally I need to represent a repeating decimal, such as .11111..., .523523523..., or even 3.0714256425642564256..., as a fraction for simplification or number theoretic purposes, or just because I feel like it. What algorithm allows us to do this conversion?

Math Time
Here's an outline for what we're going to do:

  1. First we are going to ignore the non-repeating part. We'll deal with it later. We will just pretend that we have 0.523523523..., or whatever the repeating part is (left justified up to the decimal point).
  2. Next we're going to look at the repeating decimal as similar chunks added together which have increasing powers of 10 in the denominator.
  3. After factoring out the similar numerators, we will approach the sum of reciprocal powers of 10 and notice that they sum to a fraction similar to 1/9999..., depending on how long the repeating part of the decimal is.
  4. Finally we'll add back in the non-repeating part to complete the fractional representation.
By showing this algorithm for any arbitrary repeating decimal, you must realize that, unlike the irrational square root of 2, all repeating decimals are rational! Now, on to the proof!

For notation, I will use y1y2...ym to refer to the m digits of the non-repeating part and x1x2x3...xn to refer to the n digits of the repeating part. An arbitrary digit of the non-repeating part will be referred to as yi, and of the repeating part as xi.

First, let us remove the non-repeating part. Let R be the number with a repeating decimal. R = y1y2...ymx1x2...xn. Even if the repeating begins to the left of the decimal place, count everything to the left of the decimal place as being part of the non-repeating part. Thus, all xi occur to the right of the decimal point. Moreover, multiply R by one (while multiplying by 1 doesn't change anything, it sure can be useful!) in the form of 10^k / 10^k where k is the number of decimal places that the yi go to the right of the decimal point (3.07123123123... would require k=2 since the non-repeating part, 3.07, goes 2 places to the right of the decimal point). If we hold 1/10^k as a multiplied factor to the left of the equaiton and multiply in 10^k, then this will cause the decimal place to lie directly between the yi and xi. So R = 1/10^k (y1y2...ym . x1x2...xn....) = 1/10^k (y1y2...ym + .x1x2...xn...). Notice the . used to show where the decimal point is located. Now let's focus on the xi.

Notice that .x1x2...xnx1x2...xnx1x2...xn.... can be split up into an infinite sum, namely x1x2...xn / 10^n + x1x2...xn / 10^2n + x1x2...xn / 10^3n + .... (if we had .454545.... we would get 45/100 + 45/10000 + 45/1000000 + ....). Factor out x1x2...xn and you are left with x1x2...xn (10^-n + 10^-2n + 10^-3n + ....). Time to examine that sum of spaced out reciprocal powers of 10.

First, notice that .111111...., or 1/10 + 1/100 + 1/1000 + ...., is 1/9. This is trivial using long division. Let's look at .01010101.... now. A little insight shows us that it is 1/99. If we continue in this fashion, we see that .001001001.... is 1/999, and so on. In other words, the infinite sum 10^-n + 10^-2n + 10^-3n + .... = 1/999.... that is, 1 over n 9's. Let's put that finding back into our problem. (For brevity, I avoided proving this step, but it is commonly called a geometric series and is cleverly proven using the idea of telescoping).

So we have x1x2...xn (10^-n + 10^-2n + ....) = x1x2...xn (1/9999...). Remembering about our 10^k / 10^k trick earlier, R = 1/10^k (y1y2...ym + x1x2...xn / 999...). Using basic fraction arithmetic (multiply each fraction by the number one in the form of D/D where D is the denominator of the other fraction involved) we get R =  ((999...) * y1y2...ym + x1x2...xn) / (999... * 10^k), where 999... is the number of 9's equal to the length of the repeating part, or n 9's.

As an example, let's take a fraction with 7 in the denominator, which, other than numerators that are divisible by 7, always ends up as a repeating decimal. 17/7 = 2.428571428571.... Using our tricks (note, we don't have to do our 10^k trick) we get (999999*2 + 428571) / 999999 which, surprisingly enough, is 2428569 / 999999 = (142857/142857) * (17/7) = 2.428571428571.... and so on. Amazing!


Final Answers
In order to turn a number with a repeating decimal into a fraction, first determine where the decimal place "should" go. Take the number digits in the non-repeating portion to the right of the decimal point (2 for 3.07666666...) and replace k below with that number. Figure out the length of the repeating portion (only consider the repeating portion to the right of the decimal place, 1231.231231.... would have a repeating length of 3 and we would consider the repeating portion to be 231). There will be a term of 9999... where the number of 9s is the same as the length of the repeating portion.

So for a number with a repeating decimal, it is equal to the fraction [9999... * (the non-repeating portion as a whole number) + (the repeating portion as a whole number)] / (9999... * 10^k)

Or if you followed along above it is [(999...) * y1y2...ym + x1x2...xn] / (999... * 10^k)

A few more examples:

  • 3.04123123123... becomes (999 * 304 + 123) / (999 * 100) = 303819 / 99900 = 3/3 * 101273 / 33300
  • 12341.234123412341... becomes (9999 * 12341 + 2341) / (9999) = 123400000 / 9999 (that's the reduced form!)
  • .0000354235423542.... becomes (9999*0 + 3542) / (9999 * 10000) = 3542 / 99990000 = 22/22 * 161/ 4545000
  • 17.363636.... becomes (99*17 + 36) / 99 = 1719 / 99 = 9/9 * 191 / 11
If you're curious how I'm finding the common factor of 3/3, 22/22, and 9/9 in the examples above, I'm just finding the Greatest Common Divisor (gcd) of the numerator and denominator. Some number theory is required to understand how to do that (Euclidean Algorithm is easy and fast, but is a little magical without really thinking about it). I just used a gcd calculator online.

No comments:

Post a Comment