Almkvist-Giullera formula for pi: Difference between revisions

Content added Content deleted
m (→‎{{header|dc}}: Add output header)
(→‎{{header|Common Lisp}}: Add output header.)
Line 182: Line 182:
(defun integral (n)
(defun integral (n)
(/r (*r 32 (!r (*r 6 n)) (+r (*r 532 n n) (*r 126 n) 9)) (*r 3 (expt-r (!r n) 6))))
(/r (*r 32 (!r (*r 6 n)) (+r (*r 532 n n) (*r 126 n) 9)) (*r 3 (expt-r (!r n) 6))))

; the exponent for 10 in the nth term of the series
(defun power (n) (- 3 (* 6 (1+ n))))


; the nth term of the series
; the nth term of the series
(defun a-g (n)
(defun a-g (n)
(/r (integral n) (expt-r 10 (+r (*r 6 n) 3))))
(/r (integral n) (expt-r 10 (abs (power n)))))


; the sum of the first n terms
; the sum of the first n terms
Line 197: Line 200:
(sqrt-r (/r 1 (a-g-sigma n))))
(sqrt-r (/r 1 (a-g-sigma n))))


(format t "~A. ~44A~4A ~A~%" "N" "Integral part of Nth term" "×10^" "=Actual value of Nth term")
(loop for i from 0 to 9 doing
(loop for i from 0 to 9 doing
(format t "~&~a. ~44d ~3d " i (integral i) (- 3 (* 6 (1+ i))))
(format t "~&~a. ~44d ~3d " i (integral i) (power i))
(finish-output *standard-output*)
(finish-output *standard-output*)
(print-r (a-g i) 50 nil))
(print-r (a-g i) 50 nil))
Line 206: Line 210:


{{Out}}
{{Out}}
<pre>0. 96 -3 +0.09600000000000000000000000000000000000000000000000...
<pre>N. Integral part of Nth term ×10^ =Actual value of Nth term
0. 96 -3 +0.09600000000000000000000000000000000000000000000000...
1. 5122560 -9 +0.00512256000000000000000000000000000000000000000000...
1. 5122560 -9 +0.00512256000000000000000000000000000000000000000000...
2. 190722470400 -15 +0.00019072247040000000000000000000000000000000000000...
2. 190722470400 -15 +0.00019072247040000000000000000000000000000000000000...