cached_zeta_function.sf 662 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 25 June 2016
  5. # Website: https://github.com/trizen
  6. # Cached method for the computation of the zeta function.
  7. # Based on the following recursive function:
  8. #
  9. # f(n) = n^p * f(n-1) + ((n-1)!)^p
  10. # f(1) = 1
  11. #
  12. # zeta(n, p) = f(n) / (n!)^p
  13. #
  14. #===============================
  15. # Also notice that:
  16. # _n_
  17. # (n!)^p = | | k^p
  18. # k=1
  19. var iter = 100 # iterate this many times
  20. var p = Complex(1/2, 21.022) # raise each n to this power
  21. func f(n) is cached {
  22. n.is_one ? 1 : (pow(n, p) * f(n-1) + pow((n-1)!, p))
  23. }
  24. say f(iter)/pow(iter!, p)