Questions tagged [continued-fractions]

Continued fractions is an alternative representation of numbers that has interesting properties for on-demand arbitrary precision while avoiding intermediary rounding errors.

29 questions
15
votes
2 answers

Algorithm Challenge: Generate Continued Fractions for a float

(EDIT: In response to grumpy comments, No it isn't homework. I am working on pitch detection, taking an array of potential harmonic peaks, and attempting to construct candidates for fundamental frequency. So, it is actually a very practical…
P i
  • 25,182
  • 33
  • 133
  • 229
6
votes
1 answer

Exact value of a floating-point number as a rational

I'm looking for a method to convert the exact value of a floating-point number to a rational quotient of two integers, i.e. a / b, where b is not larger than a specified maximum denominator b_max. If satisfying the condition b <= b_max is…
5
votes
3 answers

Python 2.7 - Continued Fraction Expansion - Understanding the error

I've written this code to calculate the continued fraction expansion of a rational number N using the Euclidean algorithm: from __future__ import division def contFract(N): while True: yield N//1 f = N - (N//1) if f ==…
5
votes
2 answers

Continued Fractions Python

I am new to Python and was asked to create a program that would take an input as a non-negative integer n and then compute an approximation for the value of e using the first n + 1 terms of the continued fraction: I have attempted to decipher the…
3
votes
2 answers

Is it possible to calculate the continued fraction of a negative number in f#?

I'm trying to make a program that can calculate the calculated fraction of a real number. It works completely fine except when I'm trying to do it for a negative real number, ex "-71/23" or in decimals "-3,086...". If I calculate the continued…
Zebraboard
  • 33
  • 8
3
votes
1 answer

Continued logarithm arithmetic: floor operator on run-length encoded terms

I'm trying to implement basic arithmetic on Bill Gosper's continued logarithms, which are a 'mutation' of continued fractions allowing the term co-routines to emit and consume very small messages even on very large or very small numbers. Reversible…
user2875414
3
votes
2 answers

Arbitrary Precision Arithmetic in Julia

This has kinda been asked, but not in this way. I have a little Python program which finds continued fractions for square roots of n (1 <= n <= 10000). I have been trying to do this in Julia and I can't see how to. Mainly because it deals with…
3
votes
2 answers

Finding the continued fraction of 2^(1/3) to very high precision

Here I'll use the notation It is possible to find the continued fraction of a number by computing it then applying the definition, but that requires at least O(n) bits of memory to find a0, a1 ... an, in practice it is a much worse. Using double…
3
votes
5 answers

Good compression scheme for continued fraction terms?

So I'm implementing a continued fraction library for handling a subset of quadratic integers and rational numbers. Continued fraction terms are represented by unsigned integers. I've noticed the following general patterns when working with…
2
votes
1 answer

How to calculate the terms of the continued fraction of pi?

The other day, the Wolfram Blog published an article about a thirteen year old boy, Neil Bickford, who computed the first 458 million terms of the simple continued fraction representation of pi, beginning with [3; 7, 15, 1, 292, ...]. Bickford…
user448810
  • 16,364
  • 2
  • 31
  • 53
2
votes
1 answer

implementing an algorithm to transform a real number to a continued fraction in #F

i am trying to implement a recursive function which takes a float and returns a list of ints representing the continued fraction representation of the float (https://en.wikipedia.org/wiki/Continued_fraction) In general i think i understand how the…
sss
  • 105
  • 5
2
votes
1 answer

Why the bleep isn't my continued fraction approximating properly?

Reading through more SICP and I'm stuck on exercise 1.3.8. My code works properly for approximating 1/phi, but doesn't work for approximating e - 2. (define (cont-frac n d k) (define (frac n d k) (if (= k 0) 1.0 (+…
hraesvelgr
  • 3,961
  • 2
  • 32
  • 58
1
vote
0 answers

Square root calculation using continued fractions to n bits of precision

This is an unsolved problem from my past arbitrary-precision rational numbers C++ assignment. For calculation, I used this expression from Wikipedia (a being the initial guess, r being its remainder): I ended up, just by guessing from experiments,…
1
vote
1 answer

Continued fraction natural logarithm(number of iterations needed to calculate right logarithm)

I have problem with my continued fraction algorithm for natural logarithm. I need to calculate natural logarithm for example ln(0.31) with accuracy on 1e-6 in 6 iterations, my algorithm will do it in 8. This is my…
Marklar
  • 21
  • 7
1
vote
1 answer

matlab code for golden ratio continued fraction

I'm trying to write a Matlab function that computes how many terms, m, it takes the golden fraction to get to n digits of accuracy. Here is what I have so far, but I keep getting an output of 0. phi = (1+sqrt(5))/2; p=1; p=[1+1/p]; LoopCounter =…
kettlebar
  • 13
  • 3
1
2