prime

package
v0.0.0-...-a4a72b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Factorize

func Factorize(n int64) map[int64]int64

Factorize is a function that computes the exponents of each prime in the prime factorization of n

func Generate

func Generate(limit int) []int

Generate returns a int slice of prime numbers up to the limit

func GenerateChannel

func GenerateChannel(ch chan<- int)

Generate generates the sequence of integers starting at 2 and sends it to the channel `ch`

func MillerRabinDeterministic

func MillerRabinDeterministic(num int64) (bool, error)

MillerRabinDeterministic is a Deterministic version of the Miller-Rabin test, which returns correct results for all valid int64 numbers.

func MillerRabinProbabilistic

func MillerRabinProbabilistic(num, rounds int64) (bool, error)

MillerRabinProbabilistic is a probabilistic test for primality of an integer based of the algorithm devised by Miller and Rabin.

func MillerRandomTest

func MillerRandomTest(num int64) (bool, error)

MillerRandomTest This is the intermediate step that repeats within the miller rabin primality test for better probabilitic chances of receiving the correct result with random witnesses.

func MillerTest

func MillerTest(num, witness int64) (bool, error)

MillerTest tests whether num is a strong probable prime to a witness. Formally: a^d ≡ 1 (mod n) or a^(2^r * d) ≡ -1 (mod n), 0 <= r <= s

func MillerTestMultiple

func MillerTestMultiple(num int64, witnesses ...int64) (bool, error)

MillerTestMultiple is like MillerTest but runs the test for multiple witnesses.

func OptimizedTrialDivision

func OptimizedTrialDivision(n int64) bool

OptimizedTrialDivision checks primality of an integer using an optimized trial division method. The optimizations include not checking divisibility by the even numbers and only checking up to the square root of the given number.

func Sieve

func Sieve(in <-chan int, out chan<- int, prime int)

Sieve Sieving the numbers that are not prime from the channel - basically removing them from the channels

func TrialDivision

func TrialDivision(n int64) bool

TrialDivision tests whether a number is prime by trying to divide it by the numbers less than it.

func Twin

func Twin(n int) (int, bool)

This function returns twin prime for given number returns (n + 2) if both n and (n + 2) are prime -1 otherwise

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL