A Go tool find_arctan_relations that searches for Machin‑style arctan formulas for π by selecting arctan(1/x) terms according to prime‑factor norms and applying the PSLQ integer‑relation algorithm.
This reposistory also contains score_arctan.py which is used to process the log files generated by find_arctan_relations.
There is an accompanying paper which explains how this program works which can be found on arXiv at https://arxiv.org/abs/2508.08307
The full set of results found with this program are available at https://doi.org/10.5281/zenodo.16758216
The top results are available in the results-by4-top.txt and results-by4-top.csv files in this repository.
Here is an example of formulae found this this program which are the lowest known Lehmer measure relations with 5 and 6 terms.
- Groups primes (excluding 2) into combinations of configurable size.
- Computes norms of potential arctan terms y/x and filters by size.
- Runs PSLQ to find integer relations combining π and selected arctan terms.
- Supports evolving prime‑groups to discover new formulas.
- Caches intermediate values and runs in parallel.
- Go 1.23 or newer
- Dependencies (fetched via
go get):github.com/ncw/pslqgithub.com/hashicorp/golang-lru/v2
- Python 3.12 (tested with this version, likely works with others)
- Optionally sympy if the prime groups need to be displayed.
Download the latest release or build from source:
git clone https://github.com/ncw/find_arctan_formulae.git
cd find_arctan_formulae
go build
./find_arctan_formulae -help
python score_arctan.py --helpgo build
go test -v
./regression.sh./find_arctan_formulae [flags]Usage of ./find_arctan_formulae:
-algorithm int
PSLQ: which algorithm to use. 1: orig, 2: pslqm2 (default 2)
-alpha uint
Don't output arctan terms bigger than 1/alpha (default 1)
-arctan-cache-size int
Cache this many arctan values (default 10000)
-candidate-cache-size int
Cache this many candidate norm lists (default 64)
-cpuprofile string
Write cpu profile to file
-evolve int
If set, use this many groups to evolve new relations from
-group string
A comma or space separated list of primes to use as the prime group
-group-cache-size int
Cache this many group values (default 10000)
-group-extra-primes value
Number of extra primes to add to a group iteration
-groups-file string
a file of comma or spare separated groups, one per line
-iteration-type string
Iteration type normal|random|weighted (default "normal")
-iterations int
PSLQ: number of iterations to use max (default 1000000)
-log-max-coeff uint
PSLQ: log2(max coefficient size) (default 64)
-max-fails int
Stop PSLQ with this many failures in a row (default 1000)
-max-group-length int
Maximum number of members for prime groups (default 10)
-max-items int
Maximum number of entries to run PSLQ on (default 20)
-max-lehmer-measure float
Don't print formulae with a Lehmer measure greater than this
-max-no-new int
Stop PSLQ if no new results for this many iterations (default 10000)
-max-numerator uint
arctan terms should have numerator <= this (default 1)
-max-prime value
Maximum prime factor to consider for groups (default 5000)
-min-group-length int
Minimum number of members for prime groups (default 5)
-min-items int
Minimum number of items required to run PSLQ on (default 2)
-norm-cache-size int
Cache this many norms lists (default 100000)
-prec uint
PSLQ: precision to use (bits) (default 1024)
-pslq-verbose
Cause the PSLQ algorithm to print lots of info
-skip-relations
if set skip PSLQ on any relations which contain previously found relations
-skip-zeros
if set skip PSLQ on any relations which contain previously found zero relations
-sort-max-x
If set sort by max X rather than Lehmer measure when evolving
-target-precision float
PSLQ: target precision of the result as fraction of prec (default 0.75)
-trim-start
If set, trim PSLQ list from start if too big
-verbose
Print more info while running
-workers int
Use this many threads for the search (default 16)
Find the best known 5-term relation from the prime group given
./find_arctan_formulae -max-fails 100 -min-items 1 -max-items 20 -alpha 50 -max-prime 100_000 -max-fails 1000 -max-lehmer-measure 1.86 -group "5,13,37,24113,76369"Results are printed as Lehmer measure, prime list and the formula line:
# 1.4571904502 Primes [5 13 37 24113 76369] from group [5 13 37 24113 76369]
+1 * pi = +116 * arctan(1/68) +168 * arctan(1/117) -60 * arctan(1/2675143) -20 * arctan(1/2976163) -20 * arctan(1/302342643)
Find record breaking formulae
./find_arctan_formulae -evolve 1000 -skip-relations -trim-start -max-items 30 -max-no-new 100_000 -max-fails 1000 -alpha 10 -max-prime 2_000_000 -max-lehmer-measure 1.86 -max-numerator 2 | tee results.logAfter that has run for a few days use this to process the results
python -u score_arctan.py --group-by-terms --max-lehmer-measure 1.86 --purify | tee results.txtAdd --alternate 1000 to generate alternate completions using numbers up to 1000 bits.
This program is used for finding and organising the relations found in the output of the find_arctan_formulae program.
It can also "purify" relations with arctan(a/b) where a != 1 to arctan(1/b) terms with the --purify flag.
It can also extend relations using the --alternate flag.
python -u score_arctan.py [flags] file.log file2.logusage: score_arctan.py [-h] [--max-lehmer-measure MAX_LEHMER_MEASURE] [--show] [--groups] [--pure] [--purify] [--verify] [--group-by-terms] [--top TOP]
[--save-groups SAVE_GROUPS] [--find-double-checks] [--alpha ALPHA] [--by4] [--alternate ALTERNATE]
[inputs ...]
Score lines containing multiple arctan(a/b) terms
positional arguments:
inputs Input files (reads stdin if none provided)
options:
-h, --help show this help message and exit
--max-lehmer-measure MAX_LEHMER_MEASURE, -m MAX_LEHMER_MEASURE
Maximum Lehmer measure; skip lines above this
--show, -s Show source files for each relation
--groups, -g Show prime groups for each relation
--pure, -u Only include relations where numerator a == 1
--purify, -P Try to make numerator a == 1 if possible
--verify, -x Check to see the relations are correct
--group-by-terms, -G Group the output by number of terms, lowest first
--top TOP, -n TOP Only show this many results
--save-groups SAVE_GROUPS, -S SAVE_GROUPS
Save prime groups found to this file, one per line
--find-double-checks If set find the best relation and double check pairs
--alpha ALPHA, -a ALPHA
Only show relations with terms <= 1/alpha
--by4, -4 If set output pi/4 = versions
--alternate ALTERNATE, -A ALTERNATE
Calculate alternate endings of numbers up to this many bits
Find pure relations only with Lehmer measure < 1.60 and group them by terms, verifying them in the process
python -u score_arctan.py --verify --pure --group-by-terms --groups --max-lehmer-measure 1.60 *.log | tee results.txtFind and purify all relations with Lehmer measure < 1.86
python -u score_arctan.py --group-by-terms --max-lehmer-measure 1.86 --purify *.log | results-1.86.txtExtend all relations found up to terms up to 1000 bits
python -u score_arctan.py --group-by-terms --max-lehmer-measure 1.86 --purify --alternate 1000 *.log | results-1.86-extended.txtMIT License.