{"id":17723759,"url":"https://github.com/ncw/iprime","last_synced_at":"2026-03-07T12:02:29.108Z","repository":{"id":13929205,"uuid":"16628775","full_name":"ncw/iprime","owner":"ncw","description":"All integer Mersenne prime checker","archived":false,"fork":false,"pushed_at":"2015-12-07T17:37:16.000Z","size":1686,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-06-20T17:52:42.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ncw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-07T21:58:32.000Z","updated_at":"2023-10-04T19:49:43.000Z","dependencies_parsed_at":"2022-07-15T14:48:28.556Z","dependency_job_id":null,"html_url":"https://github.com/ncw/iprime","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncw%2Fiprime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncw%2Fiprime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncw%2Fiprime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ncw%2Fiprime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ncw","download_url":"https://codeload.github.com/ncw/iprime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243532517,"owners_count":20306151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-25T15:43:58.633Z","updated_at":"2025-10-30T04:16:59.876Z","avatar_url":"https://github.com/ncw.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"iprime\n======\n\nThis is a Mersenne prime checker using integer only code.\n\nIt is written in Go for portability between platforms and the easy of\nadding assembler to the code.\n\nThe code is working but the FFTs need more work.\n\nThere is optimised assembler for ARM and AMD64 architectures.\n\nThis code is a port of\n[ARMPrime](http://www.craig-wood.com/nick/armprime/) software which ran\non RISC OS only and was never very portable.\n\nI made a first cut at making ARMPrime more portable in\n[my ioccc 2012 entry](http://www.craig-wood.com/nick/articles/ioccc-2012-mersenne-prime-checker/) which was written in C.\n\nI decided to re-write again in Go because of the cross platform\nsupport and the fact that Go integrates really nicely with assembler\ncode.  The testing suite has come in really useful as have the\nbenchmarking suite.\n\nInstall\n-------\n\nIprime is a Go program and comes as a single binary file.\n\nDownload the relevant binary from\n\n- http://www.craig-wood.com/nick/pub/iprime/\n\nOr alternatively if you have Go installed use\n\n    go get github.com/ncw/iprime\n\nand this will build the binary in `$GOPATH/bin`.  You can then modify\nthe source and submit patches.\n\nUsage\n-----\n\nUse `iprime -h` to see all the options.\n\n    Mersenne prime tester\n    \n    Usage:\n    \n    ./iprime [options] q\n    \n    where q = Mersenne exponent to test\n    \n    Options:\n      -cpuprofile=\"\": Write cpu profile to file\n      -fft-size=0: minimum size for FFT (2**n)\n      -iterations=0: Number of iterations to check run - 0 for full test\n\nThe `-iterations` argument to the program allows the number of\niterations to be put in, and using this it has been validated against\nthe Prime95 test suite.\n\nThe program comes with a unit test - run it like\n\n    go test -v -short\n\nIf if you have lots of time to spare\n\n    go test -v\n\nExample output\n\n    $ ./iprime 521\n    Testing 2**521-1 with fft size 2**5 for 0 iterations\n    Residue 0x0000000000000000\n    That took 4.424103ms for 519 iterations which is 8.524us per iteration\n\nA residue of 0 after the full number of iterations means you've found\na mersenne prime!\n\nHow it works\n------------\n\nThis program proves the primality of [Mersenne\nprimes](http://en.wikipedia.org/wiki/Mersenne_prime) of the form `2^p\n- 1`.  The biggest known primes are of this form because there is an\nefficient test for primality - the [Lucas Lehmer\ntest](http://mathworld.wolfram.com/Lucas-LehmerTest.html).\n\nIf you run the program and it produces `0x0000000000000000` (0 in hex)\nas an answer then you've found a prime of the form `2^p-1`.  If it\nproduces anything else then `2^p-1` isn't prime.  The printed result is\nthe bottom 64 bits of the last iteration of the Lucas Lehmer test.\n\nThe test is implemented using arithmetic module a prime just less than\n`2^64`, `0xFFFFFFFF00000001` = `2^64-2^32+1` (p from now on), with\nsome rather special properties.\n\nThe most important of which is that arithmetic modulo p can all be\ndone without using divisions or modulo operations (which are really\nslow).\n\nThe next important property is that p-1 has the following factors\n\n    2^32 * 3 * 5 * 17 * 257 * 65537\n\nAll those factors of 2 make a [Fast Fourier\nTransform](http://mathworld.wolfram.com/FastFourierTransform.html)\nover the [Galois Field](http://mathworld.wolfram.com/FiniteField.html)\nGF(p) which is arithmetic modulo p possible.\n\nTo make a truly efficient Mersenne primality prover it implements the\n[IBDWT](http://en.wikipedia.org/wiki/Irrational_base_discrete_weighted_transform)\na variant of the FFT using an irrational base.  This halves the size\nof the FFT array by combining the modulo and multiply steps from the\nLucas Lehmer test into one.\n\nIt can use an irrational base in a discrete field where every element\nis an integer, because the p chosen has n-th roots of 2 where n is up\nto 26, which means that an IBDWT can be defined for FFT sizes up to\n`2^26`. 7 is a primitive root of GF(p) so all follows from that!\n\nThis all integer IBDWT isn't susceptible to the round off errors that\nplague the floating point implementation, but does suffer in the speed\nstakes from the fact that modern CPUs have much faster floating point\nunits than integer units.  This is particularly noticeable in the x86\nworks where 64 bit integer multiplies take 64 cycles.  However ARM\nchips, which this was originally designed for, 32x32 -\u003e 64 multiples\nonly take 1 cycle.\n\nFor example to check if `2^18000000-1` is prime (a 5,418,539 digit\nnumber) [Prime95](http://www.mersenne.org/freesoft/) (the current\nspeed demon) uses a `2^20` FFT size and each iteration takes it about\n25ms. On similar hardware it this program takes about 1.2s also using\nan FFT size of `2^20`!\n\nThis program can do an FFT of up to `2^26` entries.  Each entry can have\nup to 18 bits in (as `2*18+26 \u003c= 63`), which means that the biggest\nexponent that it can test for primality is `18*(2^26)-1 = 1,207,959,551`.\nThis would be number of 363 million decimal digits so could be used to\nfind a 100 million digit prime and scoop the [EFF $150,000\nprize](https://www.eff.org/awards/coop)!  It would take rather a long\ntime though...\n\nRoadmap\n-------\n\nImplement\n  * FFT for small sizes which only have shifts - DONE\n  * Optimised ffts with shifts - DONE\n  * Four step fft so can use these ffts and improve cache locality - DONE but needs more work\n  * Assembler primitives - DONE\n  * Assembler FFTs - DONE\n  * New FFT schemes (like the one used in FFTW)\n  * Save progress\n  * PrimeNet support\n\nLicense\n-------\n\nThis is free software under the terms of MIT license (check COPYING file\nincluded in this package).\n\nAuthor\n------\n\n- Nick Craig-Wood \u003cnick@craig-wood.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncw%2Fiprime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fncw%2Fiprime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fncw%2Fiprime/lists"}