reformulation_of_the_arctangent_function.sf 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/ruby
  2. # Formula due to S. M. Abrarov and B. M. Quine.
  3. # Described in their paper: "A reformulated series expansion of the arctangent function"
  4. func arctan(x, z) {
  5. sum(1..z, {|m|
  6. sum(1..(2*m - 1), {|n|
  7. (-1)**n / (2*m - 1) / (1 + (x**2 / 4))**(2*m - 1) * (x/2)**(4*m - 2*n - 1) * binomial(2*m - 1, 2*n - 1)
  8. })
  9. }) * -2
  10. }
  11. say atan(1) # Pi/4 (built-in function)
  12. say arctan(1, 70) # Pi/4
  13. say "\nFractions converging to Pi/4:"
  14. for z in (1..10) {
  15. say arctan(1, z).as_frac
  16. }
  17. __END__
  18. 0.785398163397448309615660845819875721049292349844
  19. 0.785398163397448309615660845819875721049292349844
  20. Fractions converging to Pi/4:
  21. 4/5
  22. 296/375
  23. 36772/46875
  24. 1288688/1640625
  25. 96641548/123046875
  26. 26576092808/33837890625
  27. 8637277012172/10997314453125
  28. 1079658805128928/1374664306640625
  29. 91770997994914276/116846466064453125
  30. 43591225139846360008/55502071380615234375