Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion content/post/sicp-solution-exercise-1-31.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Again, this is quite straightforward:

The formula presented in the text is not very clear, but a quick search on [wikipedia](https://en.wikipedia.org/wiki/Wallis_product) gives a formula like this:

$$\prod\_{n=1}^\infty\left(\frac{2n}{2n-1}\cdot\frac{2n}{2n+1}\right)$$
$$\frac{\pi}{2}=\prod\_{n=1}^\infty\left(\frac{2n}{2n-1}\cdot\frac{2n}{2n+1}\right)$$

This formula can be implemented directly using the `product` function:

Expand All @@ -54,6 +54,9 @@ This formula can be implemented directly using the `product` function:
(/ (* 2 n)
(+ (* 2 n) 1))))
(product term 1.0 inc n))

(define (wallis-pi/4 n)
(/ (wallis-product n) 2))
```

One can argument that this is not optimized, since `(* 2 n)` is computed multiple times. On the other hand it makes the code much easier to check.
Expand Down