Python functions to generate OEIS sequences
Project description
oeis-sequences
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:
- Python is a general purpose programming language with support for file I/O and graphing.
- 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 usegmpy2
. - There exists extensive modules for combinatorics and number theory such as
math
,itertools
andsympy
.
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:
-
Functions named
Axxxxxx
: Axxxxxx(n) returns the n-th term of OEIS sequence Axxxxxx. -
Functions named
Axxxxxx_T
: returns T(n,k) for OEIS sequences where the natural definition is a 2D table T. -
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.
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, lunar arithmetic, etc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file OEISsequences-0.1.5.tar.gz
.
File metadata
- Download URL: OEISsequences-0.1.5.tar.gz
- Upload date:
- Size: 136.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 119930d34c6e3c226e3932488a1dc631fbfe61e84a4dcf591ce83ff134076cbe |
|
MD5 | d10cb0784defcb256dbdacc75c34c754 |
|
BLAKE2b-256 | 8b056bff1a1aaadf290c159854b84fa742c2afabffa559796bb6a4f372428d0d |
Provenance
File details
Details for the file OEISsequences-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: OEISsequences-0.1.5-py3-none-any.whl
- Upload date:
- Size: 142.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64c1a39becec5912ade876e5f2c78aa19ef1af23791a58dd9c611dc0904932da |
|
MD5 | 4f40e4d31788a6b89e22a443a238ddd2 |
|
BLAKE2b-256 | c2dc9ca6747884299bbdd6020c686197691cbc1b08303335a114d3adfdfaa157 |