Post Reply 
(12C) Decimal to Fraction
08-07-2018, 01:52 PM (This post was last modified: 08-07-2018 03:37 PM by Albert Chan.)
Post: #9
RE: (12C) Decimal to Fraction
(08-07-2018 12:49 PM)Albert Chan Wrote:  Your Pi example illustrate even better, fraction with denominator <= 100:
continued fraction of pi => 22/7 = 3.142857
pi.limit_denominator => 311/99 = 3.141414 --> about 7X more accurate

Peeking inside Python fractions.py, I learned the procedure: (limit_denominator method)
It is continued fractions ... with a twist

using above example, pi is bounded by 2 continued fractions, both with denomination below 100

3/1 < pi < 22/7

pi = (3 + 22k) / (1 + 7k) for some k (k=0, we get 3/1, k=infinity, we get 22/7)

if k is integer, the best is k=15, next continued fraction, 333/106, slightly under-estimated (*)
Any lowered k will under-estimate more, but perhaps better than 22/7

So, we solve for biggest denominator <= 100, we get k=14

(3+22*14)/(1+7*14) < pi < 22/7
311/99 < pi < 22/7

pick the one closest to pi, thus return 311/99

(*) actually, the best is when k=16, getting the ubiquitous 355/113.

Continued fraction coefficient only uses the integer part, and not the closest integer.
This setup guaranteed the value bounded between 2 continued fractions.
So, without using a calculator to confirm, 333/106 < pi < 355/113
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Decimal to Fraction - Gamo - 08-06-2018, 12:33 PM
RE: (12C) Decimal to Fraction - Dieter - 08-06-2018, 08:44 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:29 AM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 01:02 PM
RE: (12C) Decimal to Fraction - Albert Chan - 08-07-2018 01:52 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 11:38 AM
RE: (12C) Decimal to Fraction - Gamo - 08-07-2018, 09:29 AM
RE: (12C) Decimal to Fraction - Joe Horn - 08-07-2018, 06:28 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:10 PM
RE: (12C) Decimal to Fraction - Joe Horn - 08-08-2018, 12:28 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 07:04 PM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 09:27 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 09:44 PM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 12:51 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 07:46 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 08:09 AM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 09:16 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 10:30 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 12:28 PM
RE: (12C) Decimal to Fraction - Gamo - 05-07-2019, 01:44 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 07:06 PM



User(s) browsing this thread: 1 Guest(s)