Skip to main content

oeis-sequences

Code style: black

Python functions to generate The On-Line Encyclopedia of Integer Sequences (OEIS) sequences.

Python is the ideal language for this purpose because of the following reasons:

  1. Python is a general purpose programming language with support for file I/O and graphing.
  2. Arbitrary size integer format is standard in Python. This is important as many sequences in OEIS contain very large integers that will not fit in 64-bit integer formats. This allows the implemented functions to generate terms for arbitrary large n and they do not depend on floating point precision. For higher performance, one can use gmpy2.
  3. There exists extensive modules for combinatorics and number theory such as math, itertools and sympy.

Although Python can be slow as it is an interpreted language, this can be mitigated somewhat using tools such as pypy and numba.

Requirements

Requires python >= 3.8

Installation

pip install OEISsequences

Usage

After installation, from oeis_sequences import OEISsequences will import all the functions accessible via OEISsequences.Axxxxxx. Alternatively, invidividual functions can be imported as from oeis_sequences.OEISsequences import Axxxxxx.

For each sequence, there are (up to) 3 different kinds of functions:

  1. Functions named Axxxxxx: Axxxxxx(n) returns the n-th term of OEIS sequence Axxxxxx.

  2. Functions named Axxxxxx_T: returns T(n,k) for OEIS sequences where the natural definition is a 2D table T.

  3. Functions named Axxxxxx_gen: Axxxxxx_gen() returns a generator of OEIS sequence Axxxxxx.

The function Axxxxxx is best used to compute a single term. The generator Axxxxxx_gen is typically defined for sequences where terms are best generated sequentially and is best used when computing a sequence of consecutive terms.

For the generator, we can for example use list(islice(Axxxxxx_gen(),10)) to return the first 10 terms of sequence Axxxxxx Alternatively, setting gen = Axxxxxx_gen() and using next(gen) returns the next term of the sequence.

Given Axxxxxx_gen, one can define a function Axxxxxx as:

def Axxxxxx(n,offset=1): return next(islice(Axxxxxx_gen(),n-offset,None))

where a(offset) is the first term returned by the generator. This value of offset is the same as the offset parameter in the OEIS database.

Some functions Axxxxxx_gen contain an optional keyword startvalue that returns a generator of terms that are larger than or equal to startvalue. This keyword is only available on sequences that are nondecreasing.

For some sequences, e.g. A269483, both types of functions Axxxxxx and Axxxxxx_gen are provided.

The functions bearing the sequence number in the name allows the definition of functions such as A333962 to be essentially identical to the definition in OEIS:

def A333962(n): return A330575(A025487(n))

Examples

Least power of 3 having exactly n consecutive 7's in its decimal representation.

from oeis_sequences.OEISsequences import A131546
print(A131546(5))
>> 721

Minimal exponents m such that the fractional part of (10/9)m obtains a maximum (when starting with m=1).

from itertools import islice
from oeis_sequences.OEISsequences import A153695_gen
print(list(islice(A153695_gen(),10)))
>> [1, 2, 3, 4, 5, 6, 13, 17, 413, 555]

Numbers n such that n3 has one or more occurrences of exactly nine different digits.

from oeis_sequences.OEISsequences import A235811_gen 
print(list(islice(A235811_gen(startvalue=1475),10))) # print first 10 terms >= 1475
>> [1475, 1484, 1531, 1706, 1721, 1733, 1818, 1844, 1895, 1903]

Utility functions

The module also includes some utility functions for exploring integer sequences in OEIS such as palindrome generator, Boustrophedon transform, run length transform, Faulhaber's formula, lunar arithmetic, squarefree numbers, k-almost primes, squarefree k-almost primes, binomial coefficients modulo m, Fibonacci numbers modulo m, etc.

Download files

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

Source Distribution

oeissequences-0.2.6.2.3.tar.gz (385.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oeissequences-0.2.6.2.3-py3-none-any.whl (402.4 kB view details)

Uploaded Python 3

File details

Details for the file oeissequences-0.2.6.2.3.tar.gz.

File metadata

  • Download URL: oeissequences-0.2.6.2.3.tar.gz
  • Upload date:
  • Size: 385.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oeissequences-0.2.6.2.3.tar.gz
Algorithm Hash digest
SHA256 ec26d9b8eb4a45892fa27ecf86a83629894b93121be88387915bbdc6140b33d5
MD5 f98aa9be353552d54f91f58d82cb2b56
BLAKE2b-256 cf992b0f65c34080a80e2586b2d54cd5da9a625a425180bd84e9c065a731a147

See more details on using hashes here.

File details

Details for the file oeissequences-0.2.6.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for oeissequences-0.2.6.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 342dff4b847d02e65686309452c7495a850d29d63ba0ca28d65b257df4df47ab
MD5 679db57227f57e8fd585dcb46485d2e7
BLAKE2b-256 0785b80beaefea8fb42787a074d82eaafad0c0228a2ba5c7e842a7bfcfeb678d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.6.2.3 This release

2 files

0.2.6.2.2

2 files

0.2.6.2.1

2 files

0.2.6.2

2 files

0.2.6.1

2 files

0.2.5.10

2 files

0.2.5.9

2 files

0.2.5.8

2 files

0.2.5.7

2 files

0.2.5.6

2 files

0.2.5.5

2 files

0.2.5.4

2 files

0.2.5.3

2 files

0.2.5.2

2 files

0.2.5.1

2 files

0.2.5.0

2 files

0.2.4.9

2 files

0.2.4.8

2 files

0.2.4.7

2 files

0.2.4.6

2 files

0.2.4.5

2 files

0.2.4.4

2 files

0.2.4.3

2 files

0.2.4.2

2 files

0.2.4.1

2 files

0.2.4.0

2 files

0.2.3.6

2 files

0.2.3.5

2 files

0.2.3.4

2 files

0.2.3.3

2 files

0.2.3.2

2 files

0.2.3.1

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page