Find the denominator n of the rational number n k ( k , n are both positive integers) such that ∣ ∣ 2 − n k ∣ ∣ is the smallest possible, out of all rational numbers with denominators less than 1 2 0 .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Using the continued fraction to calculate 2 , the last value that has a denominator less than 1 2 0 is 7 0 9 9 .
However, we can get even more precise than this. Since 2 = 2 2 we can substitute with 7 0 9 9 to get 7 0 9 9 = 9 9 1 4 0 Using this method further gets us back to 7 0 9 9 so it is no use to work with this method anymore. In addition, since the next value for the continued fraction has a denominator above 1 2 0 , we can stop here and say that 9 9 1 4 0 is the closest approximation.
In the theory of continued fractions there is a delicate distinction between convergents and semi-convergents. To find the smallest ∣ n x − m ∣ for bounded n and m , only convergents need to be considered. However, for the |x-m/n| approximation problem one also needs to consider the semi-convergents. Here is a rather imperfect reference: http://en.wikipedia.org/wiki/Continued_fraction Perhaps, someone on this forum can point to a better source.
This is also how I did it, but I feel like there's something more going on here that I couldn't explain. Since this is looks kinda like doing part of a step in Newton's approximation, could we use that to bound the error and actually prove that this is a good idea?
How did you know the continued fraction?
Sorry for not using an "approximation" (squiggly equal sign) for the thing, I didn't know how to do it in \latex
Also I am not quite sure how solid my evidence is that 9 9 1 2 0 is. (Discussion section, please let me know if you have ideas!)
Log in to reply
Use \approx to get ≈ , and \rm\LaTeX to get L A T E X .
A blog post regarding (semi)-convergents is here . There are many texts on continued fractions, most good ones will make the distinction between best rational approximations of the first and second kind.
I also found 140/99 by using this approach, and guessed it although I could not see a proof that there are no closer values. In theory there could have been a solution to k 2 = 2 n 2 ± 3 but with 3 / n 2 smaller than the case of 140/99 which is a solution to k 2 = 2 n 2 ± 2 , with difference 2 / 9 9 2 .
Something else that hasn't been mentioned is that we're all actually trying to minimize 2 − n 2 k 2 , which is NOT the square of the expression in the question. However you can prove by analysis that minimising this expression also minimises the original one.
If p / q is a best upper approximation to x , then:
If p / q is a best lower approximation to x , then:
A rational number is a best upper or lower approximation of x iff it is a convergent or semi-convergent of its continued fraction. Using the continued fraction approximation of 2 (that is, [ 1 ; 2 … ] ), we find that the under-approximation 1 4 0 / 9 9 is the best with 9 9 < 1 2 0 .
I don't understand how you got a value of 1 4 0 / 9 9 from the continued fraction of [ 1 ; 2 . . . ] . The first few partial fractions are 1 1 , 2 3 , 5 7 , 1 2 1 7 , 2 9 4 1 , 7 0 9 9 , 1 6 9 2 3 9 .
Log in to reply
1 4 0 / 9 9 is not a convergent, it is a semi-convergent. Semi-convergents are fractions of the form q k + n q k + 1 p k + n p k + 1 where q k p k is the k th convergent and n ≥ 0 is an integer ∗ .
All convergents are best rational approximations, it is incorrect to say that they are all the best rational approximations. Semi-convergents compose all best rational approximations.
Now, back to your question. Note that 2 9 4 1 and 7 0 9 9 , with n = 1 , form a semi-convergent. If n = 2 , the denominator is too large. We cannot take 2 3 9 / 1 6 9 , a larger convergent, because the denominator is too large.
∗ : Some people say that a semi-convergent is NOT a convergent as well. If you prefer this definition, say n ≥ 1 , and amend the rest appropriately.
We can use the continued fraction expansion and the solution is straightforward.
Alternatively, we use Farey series to estimate 2 − 1 . From the property of Farey series if b a and d c is the best estimate for a certain Farey series F n then the farey median c + d a + b is the new estimate in the Farey series F c + d where there are no more fractions with denominator smaller than c + d between them. Now consider F 1 2 0 and start from 1 0 and 1 1 and the solution is obvious.
Is there another solution which doesnt use much heavy machinery or advanced concepts
Log in to reply
Sorry I shall work out the principle concerning Farey sequences.
Definition. Farey sequence F n is a (finite) sequence of all reduced fractions with denominators at most n .
If two fractions are in consecutive terms in F n call them neighbours.
Lemma. If b a < d c then their mediant b + d a + c satisfies b a < b + d a + c < \frac{c}{d}).
To see this we take the difference between the fractions:
b + d a + c − b a = b ( b + d ) b c − a d
d c − b + d a + c = d ( b + d ) b c − a d
The term b c − a d has to be positive so that the fraction b + d a + c lies in a consistent interval.
Theorem. Two fractions b a and d c are neighbours on F m a x ( b , d ) if ∣ b c − a d ∣ = 1 .
We can prove this by induction on n where n refers to the Farey sequence F n . For F 1 the sequence is { 1 0 , 1 1 } that ∣ b c − a d ∣ = 1 is obviously true.
Suppose that for F n with neighbouring fractions b a , d c with ∣ b c − a d ∣ = 1 then if b + d = n + 1 then their mediant is in the next Farey sequence F n + 1 . Also we have b ( a + c ) − a ( b + d ) = 1 . It is clear that there will not be any more new fractions inserted between b a and d c as we proceed from F n to F n + 1 . Then by MI this is true for all F n
From the above, we can conclude that if b a and d c are neighbours for some F n then the fraction with smallest denominator between them will be b + d a + c . We can use this property to get the best estimate towards a real number. Here I estimate 2 − 1 by fractions. The estimate for 2 immediately follows (it is clear that the integer part won't change the denominator that gives the best estimate).
Start with 1 0 < 2 − 1 < 1 1 . Their mediant is 2 1 , so the next one is
1 0 < 2 − 1 < 2 1 . Their mediant is 3 1 , so the next one is:
3 1 < 2 − 1 < 2 1 . We repeat the step for a few times and the denominator will very soon exceed 120. We go back a few steps, and from the two fractional estimate we pick the more accurate one and get the answer.
Minimizing the distance between sqrt{2} and k/n minimizes the distance between 2 and k^2/n^2.. so we are basically minimizing (|2n^2-k^2|)/n^2
Let us start by equating 2n^2-k^2 to 1 or -1. If the ordered pair (a,b) satisfies the equation, it is easy to see that (a+b,2a+b) also satisfies that. It is clear that as we increase the values of n and k the difference reduces as (|2n^2-k^2|)/n^2=1/n^2
Therefore, starting from (2,3) we get the pairs (5,7), (12,17), (29,41),(70,99) and (169,239). We stop at (70,99) as after that the values exceed 120. We have arrived at (|2n^2-k^2|)/n^2=1/4900 after using the fraction 99/70.
Now, equating 2n^2-k^2 to 2 or -2, we again use the fact that if the ordered pair (a,b) satisfies the equation, it is easy to see that (a+b,2a+b) also satisfies that. And again, increasing values of n and k brings k/n closer to sqrt{2}. So staring from (1,2) we get the pairs (3,4), (7,10), (17,24), (41,58) and (99,140). Using the fraction 140/99 we have (|2n^2-k^2|)/n^2=2/9801<1/4900.
By equating |2n^2-k^2|=m>2, we have (|2n^2-k^2|)/n^2=m/n^2>=3/120^2>1/4900>2/9801. Therefore 140/99 is the required fraction.
Log in to reply
I think to complete the solution we will have to show that if (a,b) is a solution of 2n^2-k^2 = 1, than so is (b-a,2a-b).
We can apply the following method to find convergents of d :
Define d = [ a 1 , a 2 , a 3 , a 4 . . . ] .
Let P 0 = 0 , P 1 = 1 , and P k = a k − 1 P k − 1 + P k − 2 .
Let Q 0 = 1 , Q 1 = 0 , and Q k = a k − 1 Q k − 1 + Q k − 2 .
Then, given k>1, Q k P k will be an approximation for d .
Specifically, we want to find the convergents of 2 , so let [ a 1 , a 2 , a 3 , a 4 . . . ] = [ 1 , 2 , 2 , 2 . . . ] .
Since we want a denominator less than 1 2 0 , simply calculate the first few values of Q k (note that P i is relatively prime to Q i for all i ):
Q 2 = 1 × 0 + 1 = 1 , Q 3 = 2 × 1 + 0 = 2 , Q 4 = 2 × 2 + 1 = 5 , Q 4 = 2 × 5 + 2 = 1 2 , Q 5 = 2 × 1 2 + 5 = 2 9 , Q 6 = 2 × 2 9 + 1 2 = 7 0 .
Then, Q 7 > 1 2 0 , so Q 6 P 6 is the best approximation to 2 with denominator less than 1 2 0 . Then,
P 2 = 1 × 1 + 0 = 1 , P 3 = 2 × 1 + 1 = 3 , P 4 = 2 × 3 + 1 = 7 , P 4 = 2 × 7 + 3 = 1 7 , P 5 = 2 × 1 7 + 7 = 4 1 , P 6 = 2 × 4 1 + 1 7 = 9 9 , which is the solution.
Note that this is true because 2 = 2 2 , so 7 0 9 9 ≈ ( 7 0 9 9 ) 2 = 9 9 1 4 0 , which is a (slightly) better approximation.
Code:
public class problem {
public static void main(String[] args) {
double p = Math.pow(2, 0.5);
double min = 1;
for (int i = 1; i<=120;i++) {
double a = Math.floor(p * i);
double b = Math.ceil(p * i);
if ((p - (a/i)) < min) {
min = p - (a/i);
System.out.println("Found new min " + a + "/" + i + " min: " + min);
}
if (((b/i) - p) < min) {
min = (b/i) - p;
System.out.println("Found new min " + b + "/" + i + " min: " + min);
}
}
}
}
Of course, many of our Algebra/Number Theory problems can be quite easily solved using computer, especially with math software. However they are intended to be done by hand. The trial run of the Computer Science at Brilliant was a great success. It should be back soon, on a permanent basis, with more appropriate programming challenges.
I'm afraid this is not a computing question...
Problem Loading...
Note Loading...
Set Loading...
Almost all other solutions that were presented used the theory of Continued Fractions. There is slight mystery in it, for those who have not seen it before. In this solution, I present another method, using the idea of a Farey sequence:
A Farey sequence of order n refers to an increasing sequence of reduced rational numbers between 0 and 1, whose denominator is a positive integer that is at most n . For example, the Farey sequence of order 5 is:
1 0 , 5 1 , 4 1 , 3 1 , 5 2 , 2 1 5 3 3 2 4 3 5 4 1 1 .
Now, we'd use a fact about the Farey sequence - consecutive terms are of the form b a < d c where a d − b c = − 1 (Prove this!). Since 7 0 2 9 > 9 9 4 1 and 2 9 × 9 9 − 4 1 × 7 0 = 1 , hence these terms are consecutive.
We can also show that 7 0 9 9 > 2 > 9 9 1 4 0 , which tell us that one of these rational numbers must be the best approximation. It remains to compare these two, and we can show that 7 0 9 9 − 2 > 2 − 9 9 1 4 0 . Hence, this shows that 9 9 1 4 0 is the best approximation to 2 , hence the answer is 99).
Note: Of course, this doesn't really explain where we got these terms from, apart from being very lucky in guessing.