Skip to main content

PiDigits Implements the ‘Unbounded Spigot Algorithm for the Digits of Pi’ by Jeremy Gibbons. The paper describing this algorithm can be found at this URL. The same algorithm is used to generate digits of Tau. No matter which circle constant you prefer, you can now generate the decimal expansion using this package.

Installation

pidigits is avalaible through Python Package Index (PyPI) using pip.

>>> pip install --upgrade pidigits

To uninstall using pip.

>>> pip uninstall pidigits

Usage

PiDigits provides a generator function named piGenerator that yields the digits of Pi as needed. The streaming algorithm based on Lambert’s expression is used for the generator function.

>>> from pidigits import piGenerator
>>> mypi = piGenerator()
>>> first20pi = [next(mypi) for i in range(20)]
>>> first20pi
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4]

Example: Verify the Feynman point.

>>> mypi = piGenerator()
>>> first1001 = [next(mypi) for i in range(1001)]
>>> feynman = first1001[762:768]
>>> print feynman
[9, 9, 9, 9, 9, 9]

Alternatively you can also use the getPi(n) function to get the first n digits of Pi.

>>> from pidigits import getPi
>>> first20pi = getPi(20)
>>> first20pi
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4]

Alternate implementations of streaming algorithms based on Leibniz series and Gosper’s series are also available as generator functions piGenLeibniz and piGenGosper and corresponding getPiLeibniz and getPiGosper functions. These implementations are slower than the one based on Lambert’s series.

Pidigits also provides a generator function name tauGenerator that yields the digits of Tau as needed.

>>> from pidigits import tauGenerator
>>> mytau = tauGenerator()
>>> first20tau = [next(mytau) for i in range(20)]
>>> first20tau
[6, 2, 8, 3, 1, 8, 5, 3, 0, 7, 1, 7, 9, 5, 8, 6, 4, 7, 6, 9]

Alternatively you can also use the getTau(n) function to get the first n digits of Tau.

Development

If you clone the repository (GitHub, BitBucket) and make any changes to the algorithm you can run the test cases in the _tests package included with the source to test your changes.

To run the tests, in the same directory as setup.py, first run:

>>> python setup.py develop

This will install the package in the ‘development’ mode. Then run the test cases:

>>> python setup.py test

Bug reports or suggestions are most welcome.

License

pidigits is licensed under Apache License 2.0.

Metadata

Release files for pidigits 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pidigits 0.5
File Size Uploaded
pidigits-0.5.zip 18.1 kB Details

Release files / pidigits-0.5.zip

Download URL pidigits-0.5.zip
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
16c74d29f0d715550195ef262eb0f58ad1e0ab7f3b909cff6d2a162c412e5c9b
BLAKE2b-256 checksum
How to use checksums
c5ab1de553dcfd8e5912ac908ab2c0846a5a5ef70a704f8caefb4dcd148016c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5 This release

1 release file

0.4

1 release file

0.3

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page