Talk:Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

Line 13:
 
All CF-related articles should be under a generic "Continued fraction/" section. For instance, this article should be: "Continued fraction/r2cf" or "Continued fraction/From a Rational"--[[User:Grondilu|Grondilu]] 13:20, 5 February 2013 (UTC)
 
== Why just rationals? ==
 
It seems that the continued fraction of a number just depends on the value of that number. We don't actually need to know the information of numerator and denominator separately; we just need to know the value of the fraction they form. So instead of having a function that takes the numerator and denominator separately, we can have a function that takes one real number parameter, and for rationals we can simply divide the numerator by the denominator and pass it to this function. In fact, this can work for all real numbers, not just rationals, but also irrationals; the only difference is that the continued fraction for rationals terminate.
 
Now, with some numeric representations (e.g. floating point binary), not all rationals can be represented exactly. But actually this doesn't matter so much, since the continued fraction for two numbers that are close together will yield continued fractions that start out the same. So even an approximation will be right in the beginning (up until you see a very large number in the sequence, which you know is caused by a small error in the approximation).
 
I demonstrated this in the Python solution. I have an additional function that just takes one argument, a real number, and generates a continued fraction of it. I tested it on sqrt(2) (actually an approximation of sqrt(2), since it is floating-point), and it produces the correct beginning of the sequence. I also tested it on a rational (using an exact fraction data type), and it produces the correct result for a rational, matching the result from the function for rationals above.
 
So perhaps we can just generalize this to a function that just takes a real number. -- [[User:Spoon!|Spoon!]] 22:17, 10 February 2013 (UTC)
Anonymous user