This Python package offers robust tools for calculating partial sums of powers of natural numbers and managing Bernoulli numbers with optimized caching techniques. Ideal for mathematicians, researchers, and software developers interested in number theory or computational mathematics.
- Compute LARGE Partial Sums: Utilize Faulhaber's formula to compute sums of powers of very long natural numbers.
- Bernoulli Numbers Generation: Efficiently generate Bernoulli numbers using the Akiyama–Tanigawa algorithm.
- Caching System: Persistent caching of computations to enhance performance of successive operations.
- Command Line Interface: Versatile CLI support for interactive and script-based usage.
- Library for your app: You can
import bernoulli
to make it a part of your app.
To get started with bernoulli
.
- Clone the repository.
git clone https://github.com/Siiir/bernoulli
- Go to the repo folder.
cd bernoulli
- Run the following command in your terminal:
python bernoulli.py help
Here are some quick examples to show you the power of the Bernoulli package.
This command prints the 6th Bernoulli number.
python bernoulli.py nth 6
Or, in interactive mode type nth(6)
.
Lists the first 11 Bernoulli numbers (0 to 10).
python bernoulli.py up_to 10
Or, in interactive mode type up_to(10)
.
- Calculates the sum of the the first (1 vigintillion + ...) of positive natural numbers, each taken to the power of
k
=1873.
python bernoulli.py psum 1509096632309561804061385286158050392946131124427766465467743034 1873
- Or, in interactive mode type
psum(1509096632309561804061385286158050392946131124427766465467743034, 1873)
- I have choosen a "small"
n
for the purpose of readability. You can try increasing the first argument quite freely. Whereas increasing thek
will have a noticable computional cost.
sin(psum(20, 3) - psum(10, 3)) + 2**6
Detailed documentation is available within the module. Use the help command for more information on specific functions:
python bernoulli.py help nth_Bernoulli_num
Or, in interactive mode type
help(nth_Bernoulli_num)
You can even use short aliases.
help(nth)
- As of time of writing the most optimized is the interactive mode as it doesn't need to perform the startup (big cache deserialization) between calls to different app commands. It also supports session-local, in-RAM caching.
- Currently caching is set to 3000 [u], but only 2000*u+2 numbers are saved on GitHub. This means that performing operations like
nth k
orpsum n k
withk
≤ 2000 from GitHub clone should be almost const time.k
≤ 3000 will trigger full caching increasing the app startup time and enhancing largek
computations.k
> 3000 will trigger only in-RAM caching enhancing computations during one interactive session..
Interested in contributing? We're always looking for help to improve documentation, fix issues, or make optimizations.
Distributed under the Apache License. See LICENSE
for more information.
Bernoulli was created by Tomasz Nehring, a creative mathematician and software engineer.