Almkvist-Giullera formula for pi: Difference between revisions
m
→{{header|Common Lisp}}: Fix names.
(→{{header|Haskell}}: Add implementation) |
m (→{{header|Common Lisp}}: Fix names.) |
||
Line 181:
; the nth integer term
(defun integral (n)
(numer (*r 32 (!r (*r 6 n)) polynomial))
(denom (*r 3 (expt-r (!r n) 6))))
(/r numer denom)))
; the exponent for 10 in the nth term of the series
Line 187 ⟶ 191:
; the nth term of the series
(defun
(/r (integral n) (expt-r 10 (abs (power n)))))
; the sum of the first n terms
(defun
(let ((s 0))
(loop for i from 0 to n doing (setq s (+r s (
s))
; the approximation to pi after n terms
(defun
(sqrt-r (/r 1 (
(format t "~A. ~44A~4A ~A~%" "N" "Integral part of Nth term" "×10^" "=Actual value of Nth term")
Line 204 ⟶ 208:
(format t "~&~a. ~44d ~3d " i (integral i) (power i))
(finish-output *standard-output*)
(print-r (
(format t "~%~%Pi after ~a iterations: " *iterations*)
(print-r (
</lang>
{{Out}}
|