Skip to main content

A library of mathematical functions for Project Euler

Project description

Euler Maths

Description

A collection of useful functions for mathematical calculations, mostly concerned with prime numbers and basic algebra on natural numbers.

Key features

  • Prime number sieve
  • Primality test
  • Prime factors sieve
  • Euler's totient function
  • Mobius function
  • Modular inverse

Motivation

The functions contained here are commonly used in solving Project Euler problems.

ProjectEulerProfile

Note: These are NOT solutions to any particular problem.

Module Dependencies

To improve execution speed and memory usage, many of the functions take advantage of either:

Contents

  • primes(N) - Performs prime sieve and returns an array of primes <N.
  • primes_iter(N) - Rerforms prime sieve and returns bitarray iterator of primes <N.
  • prime_factors(N) - Returns array of unique prime factors for each number < N.
  • is_prime(n) - Determines if n is prime (utilising the Miller-Rabin test for large values).
  • euler_totients(N) - Returns an array with value of Euler's totient function for numbers <N.
  • euler_totient(n, prime_factors) - Calculates Euler's totient function of n given a list of its prime factors.
  • mobius_array(N) - Returns an array with value of the Mobius function for numbers <N.
  • square_free(N) - Counts of the number of square-free values <N.
  • modular_inverse(a, n) - Computes the inverse of a modulo n.
  • isqrt2 - Integer square-root function compatible with Numba.

Installation

The package can be installed from PyPI by running:

pip install euler-maths

Usage

Once installed, simply import the module and use the functions it provides.

import euler_maths

euler_maths.primes(10)
# array([2, 3, 5, 7])

euler_maths.euler_totients(10)
# [0, 0, 1, 2, 2, 4, 2, 6, 4, 6]

Improving Performance at Runtime

The functions using native Python and Numpy are designed to be compatible with the Numba's JIT compiler. The only exception is primes_iter, which uses the Bitarray module and is not compatible with Numba.

When dealing with large enough values, Numba can significantly improve execution speed compared to vanilla Python. To take advantage of this in your script, use the numba.njit decorator on the desired function.

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

euler_maths-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

euler_maths-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file euler_maths-0.1.0.tar.gz.

File metadata

  • Download URL: euler_maths-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for euler_maths-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dc1bb20e3aaa2c538024034b93f15237bd6780db1f45f964248e62b1ba4fd3a2
MD5 f95e7424fffaa4a99bce6359ca68ab9c
BLAKE2b-256 3ff6935a10e2ae6d618fe351622547dad3d1e3ae054c0d9efb119aa9f7d15037

See more details on using hashes here.

File details

Details for the file euler_maths-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: euler_maths-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for euler_maths-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84dfd2e44100ed1a67305303edef0564fb1502d80563e106d18801e969a38e9e
MD5 359289313aafa42fd1bb02e3e0aaea0b
BLAKE2b-256 51f8fabf3d34752b4c9bfe18f503a912325a26dd8c1c3f89ef999e6f1b40d6f4

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