Onyx logo

Previous topic

onyx.util.mathutils – Numerical utilitites

Next topic

onyx.util.safediv – Utility routine for doing safe division of Numpy arrays

This Page

onyx.util.pi_spigots – Spigot algorithms for digits of pi

See the paper, “Unbounded Spigot Algorithms for the Digits of Pi”, Jeremy Gibbons, 2005.

onyx.util.pi_spigots.main(args)

As a command-line script, takes one argument, the number of digits to print out; use -1 for unbounded number of digits.

>>> main(['10'])
3 1 4 1 5 9 2 6 5 3
onyx.util.pi_spigots.pi_spigot_rabinowitz()

Returns a generator that yields successive decimal digits of pi computed using Rabinowitz’s spigot algorithm. See the paper “Unbounded Spigot Algorithms for the Digits of Pi”, Jeremy Gibbons, 2005.

>>> tuple(itertools.islice(pi_spigot_rabinowitz(), 30))
(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7)
onyx.util.pi_spigots.pi_spigot_simple()

Returns a generator that yields successive decimal digits of pi.

Based on code on the web by John Zelle, after Gibbons, “Streaming Algorithms”.

>>> tuple(itertools.islice(pi_spigot_simple(), 35))
(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8)