AnonGit90210 / RamanujanMachine

413 stars 75 forks source link

PiContFuncs

Generation of continuous fractions identities.

Installation

1) git lfs (large files storage) is used. Download and install it from here, and from the repository directory run:

git lfs install

if .gitattributes wasn't pulled from the repository for some reason, run:

git lfs track "hashtable_*.pkl"

2) Install everything on the requirements file:

pip install -r requirements.txt

Running

To run the project, type:

python main.py

The algorithm loads the file config.ini, in which it expects additional parameters. See configfile.py documentation for more details. There are a few examples & sanitycheck configurations in tests\fixtures, e.g.:

python main.py apery_sanitycheck_config.ini

Note: while generating/expanding the hashtable, the target constant is saved and used when the hashtable is loaded (with 'use' setting). There's a fault-safe mechanism in the logic behind it, as the result clicks are saved to the hashtable file as well. If you wish to use the hashtable with a different constant, run it once with 'expand' operation over the new constant, then you can use it for the new constant as usual.

General

This code is purposed for research, therefore it's still dynamic and experimental, and changes frequently. This file aims to give a brief introduction to the code and its structure. Due to the mentioned circumstances, it may be inaccurate.

What does the code do?

We have continued fractions which are generated by polynomials. What does that mean? object of the type: a(0)+b(1)/(a(1)+b(2)/...)) where a,b are polynomials with integer coefficients. This is the RHS. On the LHS we have a function of some constant, either rational or ULCD. A ULCD function is of the type f(const) = (u/const + const/l + c)/d while a rational function is the ratio of two polynomials. We seek for a match between some LHS function on a constant to a continued fraction. To do this, we enumerate over the coefficients of a,b and those of the rational func on the LHS/the ulcd parameters. They're all integers. We actually don't compare between the LHS to a continued fraction, but to a continued fraction after we applied some function to it, e.g. contfrac^2, sqrt(contfrac), 1/contfrac etc. In order to enhance the algorithm's complexity, we first enumerate over the parameters of the RHS, saving the results to a hashtable (a python 'dict'), and then we enumerate over the LHS and look for a match in the table. This is a TMTO (time-memory tradeoff), it's called MITM (meet in the middle), you can look it up if it's not clear. We first find matches, then filter redundant results (discussed later on), filter only continued fractions the converge fastly, find how fast are they converging, and then we know how many iterations (to what level of "nested fractions") we should calculate to get the desired precision. We calculate them to that precision, and filter again.

We wish to work with an arbitrary precision on the one hand, but want to compare only a few digits in the hashtable on the other hand. This was solved by implementing a customized hashtable over python's dict. We also wish to get rid of redundant results (results which are equivalent). There's a method for this too, which is far from perfect but reduces redundant results dramatically. At the end, we wish to save all the results, timestamped and reproducible. This is done by saving to a folder with a timestamped name, in which we save the configuration file that generated these results, csv (excel) file with the results and a PDF with the results in a more readable format.

Code structure

The code is made up of these files (some of the names may not be very indicative, as these are results of an ongoing process...):

Other