Advertisement
Guest User

Untitled

a guest
Dec 1st, 2023
72
0
192 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. from decimal import *
  2. d = Decimal
  3. getcontext().prec = 256
  4. #e = d(e) #this is inaccurate
  5. pi = d(pi)  #we actually don't need a fully accurate estimate of e, the entire thing converges even
  6. #with just an aproximation
  7.  
  8. e=d('2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531')
  9. #should write an override of d, that takes in a space separated string, or even a comma delimited version,
  10. #or an underscore delimited version, and simply detects and removes the delimiters, before returning
  11. #a relevant Decimal() instance with that value.
  12.  
  13. def est_e(limit = 20, F=None, E=None):
  14.   x = d('1.391925581569705')
  15.  
  16.   if F == None:
  17.     _f = d('596.25') #596.25
  18.   else:
  19.     _f = F
  20.  
  21.   if E == None:
  22.     _e = (((1/(((((1/(x.ln() / (pi-d('0.5')).ln()))-1))-1)*(x-1)))-(1/((((1/_f)*17)+17)**2))))
  23.   else:
  24.     _e = E
  25.  
  26.   i = 0
  27.   while i < limit:
  28.     v = (1/((_e).ln()-1)).ln()
  29.     _e = ((((1/(((((1/(x.ln() / (pi-d('0.5')).ln()))-1))-1)*(x-1)))-(1/((((1/_f)*17)+17)**2)))) - (1/(_e**v)))
  30.     _f = 1/((((1/((1/(((((1/(x.ln() / (pi-d('0.5')).ln()))-1))-1)*(x-1)))-_e)).sqrt())/17)-1)
  31.     i = i + 1
  32.  
  33.   print("done!")
  34.   print(f"estimate e: {_e},  actual: {e},  ratio: {_e/e}, F: {F}")
  35.   return _f, _e
  36.  
  37.  
  38. #Edited slightly for those who want to do something like...
  39.  
  40. F, E = est_e(1, d(1))
  41. #and then
  42.  
  43. i = 0
  44. somelimit = 10000
  45. while i < somelimit:
  46.   F, E = est_e(1, F, E)
  47.   i = i + 1
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement