Skip to content

Implementation of mathematically efficient ways to compute the functions. The app compares the time taken by math, numpy, and the theoretical formulas to compute e, pi, factorial.

Notifications You must be signed in to change notification settings

kate-melnykova/Efficient_computations_of_fn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scientific computations: which is faster?

Science vs math package vs numpy package

Ever wondered how efficient the math and numpy packages are?

New scientific formulas are highly efficient in the time complexity (including) constants, while well-developed packages utilize the fastest possible implementation.

For the comparison, I selected three functions:

π ≈ 3.14, e ≈ 2.72, and factorial (!)

Why these functions?

Constants are pre-computed in math and numpy packages.

Precomputed is faster, but may not provide infinite accuracy.

Indeed, scientific formulas will compute the constants up to that many digits as required which is an issue with π and e. Moreover, math and numpy return float values with stores only a few digits after the dot. The computations above return Decimal objects which has pre-specified accuracy.

Factorial faces another challenge: too large numbers. Python handles this issue well: it does not have integer overflow issue. Clearly, that would be a fair comparison between scientific formulas, math package, and numpy package. Especially when numbers get very large, and the time complexity is a game changer. However, please be patient with this test -- it may be time-consuming.

Installation and usage

Please make sure that Docker and docker-compose are installed. To start, clone the repository in the preferred directory

git clone https://github.com/kate-melnykova/Efficient_computations_of_fn

To start the server, run

docker-compose up --build

The server should start automatically, and you will see the main page main page Enter the parameter to see the comparison and press the button.

Algorithm sources

Function factorial.py computes factorial by the formula introduced by Fikret Cihana, Fatih Aydinb, Adnan Fatih Kocamaz (no parallel computing part) This method is claimed to be significantly faster than recursive implementation.

Function compute_pi.py uses Chudnovsky algorithm for computing the value of pi.

Function compute_e.py utilizes Brothers' Formulae

About

Implementation of mathematically efficient ways to compute the functions. The app compares the time taken by math, numpy, and the theoretical formulas to compute e, pi, factorial.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published