Skip to main content

Python library for primes algorithms

Project description

Generic badge PyPI version Build Status codecov Codacy Badge

Installation

To install the package use pip:

pip install nprime

Introduction

Some algorithm on prime numbers.

Algorithm developed :

  • Eratosthenes sieve based

  • Fermat’s test (based on Fermat’s theorem)

  • Prime generating functions

  • Miller Rabin predictive algorithm

Specifications

  • Language: Python 3.5.2

  • Package:

    • Basic python packages were preferred

    • Matplotlib v2.0 - graph and math

Integration and pipeline

Code quality is monitored through codacity. For the tests coverage, there’s codecov which is run during the Travis CI pipeline.

Math

Here are a bit of information to help understand some of the algorithms

Congruence

“ means congruent, a ≡ b (mod m) implies that m / (a-b), ∃ k ∈ Z that verifies a = kn + b

which implies:

a ≡ 0 (mod n) <-> a = kn <-> "a" is divisible by "n"

Erathostene’s Sieve

For n ∈ N and for ∀ a ∈[1, ..., √n] then n/a ∉ N is true.

Erathostene example

Fermat’s Theorem

If n is prime then ∀ a ∈[1, ..., n-1]

a^(n-1) ≡ 1 (mod n) ⇔ a^(n-1) = kn + 1

Miller rabin

For n ∈ N and n > 2, Take a random a ∈ {1,...,n−1} Find d and s such as with n - 1 = 2^s * d (with d odd) if (a^d)^2^r ≡ 1 mod n for all r in 0 to s-1 Then n is prime.

The test output is false of 1/4 of the “a values” possible in n, so the test is repeated t times.

Strong Pseudoprime

A strong pseudoprime to a base a is an odd composite number n with n-1 = d·2^s (for d odd) for which either a^d = 1(mod n) or a^(d·2^r) = -1(mod n) for some r = 0, 1, ..., s-1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nprime-0.1.6.tar.gz (22.6 kB view details)

Uploaded Source

File details

Details for the file nprime-0.1.6.tar.gz.

File metadata

  • Download URL: nprime-0.1.6.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nprime-0.1.6.tar.gz
Algorithm Hash digest
SHA256 8dcb2bf6dce58d7a7d4ba14e94ccf5fc1452a409602e3ff3360c66515838ebe3
MD5 2c99a733843ff9eb931a5d75639af016
BLAKE2b-256 c8b54aebe4f669015d58eca86e75ca1f33a4eadf311dd9e9704891b02264055b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page