Skip to content

Instantly share code, notes, and snippets.

@worldmind
Created September 17, 2019 14:14
Show Gist options
  • Save worldmind/93ebf4e38ef291201b568ba06db07d53 to your computer and use it in GitHub Desktop.
Save worldmind/93ebf4e38ef291201b568ba06db07d53 to your computer and use it in GitHub Desktop.
Muller's recurrence
from decimal import Decimal
from fractions import Fraction
def muller_recurrence(y, z):
return 108 - ((815-1500/z)/y)
N = 25
x_prev = 4
x_curr = 4.25
x_prev_dec = Decimal(4)
x_curr_dec = Decimal(17)/Decimal(4)
x_prev_frac = Fraction(4)
x_curr_frac = Fraction(17, 4)
for i in range(2, N+1):
x_next = muller_recurrence(x_curr, x_prev)
x_prev, x_curr = x_curr, x_next
x_next_dec = muller_recurrence(x_curr_dec, x_prev_dec)
x_prev_dec, x_curr_dec = x_curr_dec, x_next_dec
x_next_frac = muller_recurrence(x_curr_frac, x_prev_frac)
x_prev_frac, x_curr_frac = x_curr_frac, x_next_frac
print(f"{i} | {x_next} | {x_next_dec} | {float(x_next_frac)}")
@h8nor
Copy link

h8nor commented Sep 19, 2019

(EN) The problem of rounding a row of irrational numbers: https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/
(RU) Проблема округления ряда иррациональных чисел: https://habr.com/post/258483/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment