The Four Meanings of "Accurate to 3 Places"
|
08-18-2018, 02:45 PM
Post: #7
|
|||
|
|||
RE: The Four Meanings of "Accurate to 3 Places"
(12-30-2017 08:10 PM)ttw Wrote: This recursion is basically x=1/[1/x] where [] means floor is called the Gauss Map. It drifts rather quickly because the error in continued fraction approximation (p/q) is of order 1/q^2 (actually much better). The accuracy of the continued fraction part quickly exceeds the floating point precision of the calculator. The algorithm's greatest strength (good accuracy) tends to make it tricky. Hi, ttw: On machine that can produce good modulus, x = 1/fraction(x) error can be removed. Code: def genCF(n, d=1): >>> list(genCF(2**0.5)) [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 7, 1, 2, 33, 2, 7, 5, 2, 1, 1, 16, 2] Above look bad (exact coefs of sqrt(2) = [1, 2, 2 ...]), but not really. genCF actually generated correct coefficients. Python cannot produce 2**0.5 exactly, but as: 12738103345051546 / 2**53 ~ 1.4142135623730951 >>> list(genCF(12738103345051546, 2**53) ### all done in integers ... # exact coefficents as above You can also confirm this IEEE fraction in Mathematica. It will generate same coefs. Why the accuracy ? Because modulus operation is exact, using this algorithm. |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
The Four Meanings of "Accurate to 3 Places" - acapde - 12-29-2017, 10:06 PM
RE: The Four Meanings of "Accurate to 3 Places" - Joe Horn - 12-30-2017, 12:12 AM
RE: The Four Meanings of "Accurate to 3 Places" - acapde - 12-30-2017, 01:47 AM
RE: The Four Meanings of "Accurate to 3 Places" - Joe Horn - 12-30-2017, 07:46 PM
RE: The Four Meanings of "Accurate to 3 Places" - ttw - 12-30-2017, 08:10 PM
RE: The Four Meanings of "Accurate to 3 Places" - Albert Chan - 08-18-2018 02:45 PM
RE: The Four Meanings of "Accurate to 3 Places" - acapde - 01-01-2018, 12:53 AM
|
User(s) browsing this thread: 2 Guest(s)