Skip to main content

Integer sequence generation and related conditional tests.

Project description

interator

Module for integer sequence generation and related conditional tests.

Installation

Use the package manager pip to install interator.

pip install interator

Contents

Fibonacci Sequence

Function Description
fibonacci_stream(start = (0,1)) Yield the next Fibonacci number starting with F(0)
negafibonacci_stream(start = (0,1)) Yield the next Fibonacci number in the negative index starting with F(0)
nth_fibonacci(n, start = (0, 1)) Given an index n, find F(n)
lucas_stream(P = 2, Q = -1, start = (0, 1)) Yield the next number in the in the (P,-Q)-Lucas sequence starting with U0(P,Q)
is_fibonacci(n, start=(0,1)) Determine if n is within the Fibonacci sequence
is_lucas(n, P = 2, Q = -1, start = (0, 1)) Determine if n is within the (P,-Q)-Lucas sequence

Generalizations

By default, fibonacci_stream, negafibonacci_stream, nth_fibonacci, and is_fibonacci work with the Fibonacci numbers, and lucas_stream and is_lucas work with the Pell numbers. However, by changing start, any generalization of these sequences can be generated. Here are some common examples:

import interator

stop = 10
numbers = {'Lucas' : (2, 1),
           'Tribonacci' : (0, 0, 1),
           'Tetranacci' : (0, 0, 0, 1)}


for name, start in numbers.items():
    print('%s numbers:' % name)
    for i, n in enumerate(interator.fibonacci_stream(start=start)):
        print(n, end = ' ')
        if i == stop:
            print('\n')
            break

Please note the Lucas numbers should not be confused with the Lucas sequence. The Lucas numbers are a specific example of the Lucas sequence.

Prime Numbers

Functions Description
prime_stream() Yield the next prime number starting with 2
composite_stream() Yield the next composite number starting with 1
is_prime() Test the primality of n by checking potential prime factors
miller_rabin(n, k = 8) Perform the Miller-Rabin Primality Test on n
is_composite(n) Test if n is a composite number by checking potential prime factors

Polygonal Numbers

Functions Description
polygonal_stream(s) Yield the next s-gonal number starting with 1
is_polygonal(n, s) Test if n is an s-gonal number

Licensing

This project is licensed under the MIT License.

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

interator-0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

interator-0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file interator-0.2.tar.gz.

File metadata

  • Download URL: interator-0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

File hashes

Hashes for interator-0.2.tar.gz
Algorithm Hash digest
SHA256 363dd61c700bae02928aec4bc7239d111d867482ff654b131f69064ea2a726c8
MD5 84725f6526f253b2d9300236bd39d19a
BLAKE2b-256 ecda04f66bd48d0b6d46b39dfd5f76a7576e3a073c99a99e1c4f8f98c75fc82c

See more details on using hashes here.

File details

Details for the file interator-0.2-py3-none-any.whl.

File metadata

  • Download URL: interator-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

File hashes

Hashes for interator-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c863d0225136d8eb64cebfc7944f99372acd3fa9690ec87ba6d068888eb35a0
MD5 79b6a1a6fbd9f6bc3d9498786219f45d
BLAKE2b-256 7f63b481cdcce360bad8c14ed1582ea93e862e9c2c4a75f4458e6937d4e78b25

See more details on using hashes here.

Supported by

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