https://github.com/h5law/primality
A Go library for checking whether an integer is prime or not, using either the AKS or Miller-Rabin algorithms.
https://github.com/h5law/primality
aks go golang miller-rabin number-theory primality-test prime-numbers
Last synced: about 2 months ago
JSON representation
A Go library for checking whether an integer is prime or not, using either the AKS or Miller-Rabin algorithms.
- Host: GitHub
- URL: https://github.com/h5law/primality
- Owner: h5law
- License: bsd-3-clause
- Created: 2024-05-17T02:14:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T11:37:30.000Z (over 1 year ago)
- Last Synced: 2025-03-17T12:41:56.274Z (7 months ago)
- Topics: aks, go, golang, miller-rabin, number-theory, primality-test, prime-numbers
- Language: Go
- Homepage: https://pkg.go.dev/github.com/h5law/primality
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# primality
Primality is a Golang library for determining whether any given integer
$i\in\mathbb{Z}^+,~i\ge1$. The library provides two implementations of algorithms
for determining the primality of an arbitrarily sized integer, using the `math/big`
library.The two methods provided are the Miller-Rabin and AKS primality test the former
being probabilistic and the latter deterministic, meaning that the Miller-Rabin
primality test doesn't guarantee 100% accuracy in certain situations. Whereas
the AKS primality test is always 100% accurate - but a lot slower on larger
integers.## Features
### Miller-Rabin:
- Highly accurate probabilistic primality test
- 25 rounds and force usage of base 2 recommended for near 100% accuracy
- Arbitrarily large integer support (`big.Int`)
- $\mathcal{O}(r\cdot s)$ time complexity (assuming `big.Int` operations are
$\mathcal{O}(1)$ where $r$ is the number of repetitions and $s$ the number of
trailing zeros on $n$, the number being tested - otherwise it is related to
the operations of `big.Int` integers and $n$ itself.
- As a prime must be odd $s\le7$ meaning the time complexity in its worst case
is $\mathcal{O}(175)=\mathcal{O}(1)$ with 25 repetitions.### AKS
- Deterministic primality test
- Slow overall - but guarantees 100% a valid outcome
- `int` support only## TODOs
- Improve speed of the AKS method
- Specifically step 5 but overall it is slow
- Make the AKS method work on arbitrarily sized integers
- use `big.Int`s over `int`s
- Determine the true time and space complexities for both methods