Skip to content

Identifying semantically meaningful clusters in the OEIS database. A Python library for integer triangles and their ranking.

License

Notifications You must be signed in to change notification settings

PeterLuschny/tablInspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tables

tablInspector

No, the name has no typo. 'tabl' is a keyword in the Online Encyclopedia of Integer Sequences (OEIS). It classifies a sequence as a regular triangular array of numbers.

The goal of this library is to identify semantically meaningful clusters around integer triangles, to implement these triangles, and to provide tools to study them.

The implementations are written in annotated Python and refer to a uniform interface.

An integer triangle is a list of integer lists (list[list[int]]). As usual in Python, all lists are 0-based; in particular, all triangles have offset = 0.

This allows us to identify an integer triangle with a list whose indexing is like this:

[ [(0,0)], [(1,0), (1,1)], [(2,0), (2,1), (2,2)], ..., [(n,0), (n,1), ... (n,k), ... (n,n)] ]

For example, G. W. Leibniz wrote down a number triangle in his "Dissertatio de arte combinatoria", Leipzig in 1666, that we will display like this:

    [0]    [0]
    [1]    [0,   1]
    [2]    [0,   2,    2]
    [3]    [0,   3,    4,   3]
    [4]    [0,   4,    6,   6,    4]
    [5]    [0,   5,    8,   9,    8,    5]
    [6]    [0,   6,   10,  12,   12,   10,    6]
    [7]    [0,   7,   12,  15,   16,   15,   12,    7]
    [8]    [0,   8,   14,  18,   20,   20,   18,   14,   8]
    [9]    [0,   9,   16,  21,   24,   25,   24,   21,  16,  9]

The first (left) column indicates the row number and is not part of the triangle.

To use the library, put the file Tables.py in the same directory where your project is or somewhere else where the interpreter can find it. Make sure your Python has the "more_itertools" package installed. The other Python files are not needed as long as you do not want to make your own additions to the library.

Test the installation.

Example 1

    from Tables import TablesListPreview
    TablesListPreview()

This shows the list of the sequences implemented.

To use a Table from the library:

Example 2

    from Tables import Abel, InspectTable
    InspectTable(Abel)

Use the Table as an iterable:

Example 3

    AbelRows = Abel.itr(7)
    for row in AbelRows:
        print(row, 'sum:', sum(row))

... or add your own table:

Go to the file "Template.py". It describes how you can add your own Table class to the library in three simple steps.

The methods

Currently, 116 triangles are included in this library implementing the class Table that provides the following methods:

    __call__(self, n: int, k: int) -> int | T(n, k)
    val (n:int, k:int)   -> int  | T(n, k)
    row (n: int)         -> tblrow | n-th row of table
    itr (size: int)      -> Iterator[list[int]] | traverse the first 'size' rows
    flat (size: int)     -> list[int] | flattened form of the first size rows
    diag(n, size: int)   -> list[int] | diagonal starting at the left side
    col (k, size: int)   -> list[int] | k-th column starting at the main diagonal
    sum (size: int)      -> list[int] | sums of the first size rows
    antidiag (size: int) -> list[int] | upward anti-diagonals
    rev (size: int)      -> tblrow | reversed rows
    acc (size: int)      -> tblrow | accumulated row 
    alt (size: int)      -> tblrow | alternating signs 
    diff (size: int)     -> tblrow | first difference of row
    der (size: int)      -> tblrow | derivative of row
    tab (size: int)      -> tabl | table with size rows
    mat (size: int)      -> tabl | matrix form of lower triangular array
    inv (size: int)      -> tabl | inverse table
    revinv (size: int)   -> tabl | row reversed inverse
    invrev (size: int)   -> tabl | inverse of row reversed
    off (N: int, K: int) -> rowgen | new offset (N, K)
    revinv11 (size: int) -> tabl | revinv from offset (1, 1)
    invrev11 (size: int) -> tabl | invrev from offset (1, 1)
    poly(n: int, x: int) -> int  | sum(T(n, k) * x^j for j=0..n)
    trans(s: seq, size)  -> list[int] | linear transformation induced by T
    invtrans(s: seq, size) -> list[int] | inverse transformation induced by T
    show (size: int)     -> None | prints the first 'size' rows with row-numbers

These methods provide various functionalities for manipulating and generating integer triangles. For example, the row method returns the n-th row of the triangle, the rev method returns the reversed row of the triangle, and the antidiag method returns the n-th antidiagonal of the triangle.

Triangles as semantically meaningful clusters in the database.

This project aimed to identify the crucial triangles without relying on subjective assessment. For this, a metric had to be developed. We based the ranking on the number of distinct sequences generated by a fixed pool of elementary transformations mapping the triangles to other sequences. These transformations are called 'table traits' and are implemented in the module '_tabltraits'. These are very simple transformations that occur everywhere in the OEIS, but are not always recognized as such and then often lead to unnecessarily complicated formulas.

In the table below, the two columns on the right are examples of hundreds of similar identities that can be generated with the module. Note: References to OEIS-Ids are approximate. They often differ in signs and offset, sometimes also in the first few values.

Name Formula Triangle Trait
Triangle $ T_{n,k} $ Abel A137452
Tinv $ (T^{-1})_{n,k} $ Abel A059297
Trev $ T_{n,n-k} $ StirlingSet A106800
Tinvrev $ (T_{n,n-k})^{-1} $ FallingFactorial A132013
Trevinv $ (T^{-1})_{n,n-k} $ DyckPaths A054142
Toff11 $ T_{n+1,k+1} $ StirlingSet A008277
Trev11 $ T_{n+1,n-k+1} $ Eulerian A008292
Tinv11 $ (T^{-1})_{n+1,k+1} $ Eulerian A055325
Tinvrev11 $ (T_{n+1,n-k+1})^{-1} $ Eulerian A055325
Trevinv11 $ (T^{-1})_{n+1,n-k+1} $ StirlingSet A094638
Tantidiag $ T_{n-k,k}\ \ (k \le n/2) $ Motzkin A106489
Tacc $ \sum_{j=0}^{k} T_{n,j} $ Binomial A008949
Talt $ T_{n,k} (-1)^{k} $ Binomial A130595
Tder $ T_{n,k+1}\ (k+1) $ Abel A225465
TablCol0 $ T_{n ,0} $ WardCycle A000007
TablCol1 $ T_{n+1,1} $ WardCycle A000142
TablCol2 $ T_{n+2,2} $ WardCycle A000276
TablCol3 $ T_{n+3,3} $ WardCycle A000483
TablDiag0 $ T_{n ,n} $ WardSet A001147
TablDiag1 $ T_{n+1,n} $ WardSet A000457
TablDiag2 $ T_{n+2,n} $ WardSet A000497
TablDiag3 $ T_{n+3,n} $ WardSet A000504
TablLcm $ \text{lcm} { \ | T_{n,k} | : k=0..n } $ Binomial A002944
TablGcd $ \text{gcd} { \ | T_{n,k} | : k=0..n } $ Fubini A141056
TablMax $ \text{max} { \ | T_{n,k} | : k=0..n } $ BinaryPell A109388
TablSum $ \sum_{k=0}^{n} T_{n,k} $ Binomial A000079
EvenSum $ \sum_{k=0}^{n} T_{n,k}\ (2 \mid k) $ Binomial A011782
OddSum $ \sum_{k=0}^{n} T_{n,k}\ (1 - (2 \mid k)) $ Binomial A131577
AltSum $ \sum_{k=0}^{n} T_{n,k} (-1)^{k} $ Binomial A000007
AbsSum $ \sum_{k=0}^{n} | T_{n,k} | $ EulerTan A009739
AccSum $ \sum_{k=0}^{n} \sum_{j=0}^{k} T_{n,j} $ Binomial A001792
AccRevSum $ \sum_{k=0}^{n} \sum_{j=0}^{k} T_{n,n-j} $ StirlingCycle A000774
AntiDSum $ \sum_{k=0}^{n/2} T_{n-k, k} $ Binomial A000045
ColMiddle $ T_{n, n / 2} $ Binomial A001405
CentralE $ T_{2 n, n} $ Binomial A000984
CentralO $ T_{2 n + 1, n} $ Binomial A001700
PosHalf $ \sum_{k=0}^{n}T_{n,k}\ 2^{n-k} $ FallingFactorial A010842
NegHalf $ \sum_{k=0}^{n}T_{n,k}\ (-2)^{n-k} $ FallingFactorial A000023
TransNat0 $ \sum_{k=0}^{n}T_{n,k}\ k $ Binomial A001787
TransNat1 $ \sum_{k=0}^{n}T_{n,k}\ (k+1) $ Binomial A001792
TransSqrs $ \sum_{k=0}^{n}T_{n,k}\ k^{2} $ Lah A103194
BinConv $ \sum_{k=0}^{n}T_{n,k}\ \binom{n}{k} $ FallingFactorial A002720
InvBinConv $ \sum_{k=0}^{n}T_{n,k}\ (-1)^{n-k}\ \binom{n}{k} $ FallingFactorial A009940
PolyRow1 $ \sum_{k=0}^{1}T_{1,k}\ n^k $ Lucas A005408
PolyRow2 $ \sum_{k=0}^{2}T_{2,k}\ n^k $ Lucas A000384
PolyRow3 $ \sum_{k=0}^{3}T_{3,k}\ n^k $ Lucas A015237
PolyCol2 $ \sum_{k=0}^{n}T_{n,k}\ 2^k $ Abel A007334
PolyCol3 $ \sum_{k=0}^{n}T_{n,k}\ 3^k $ Abel A362354
PolyDiag $ \sum_{k=0}^{n}T_{n,k}\ n^k $ Abel A193678

In Visual Studio Code, the TeX formulas are displayed correctly in the preview.

Looking up the traits in the OEIS

The module provides a central function that extracts the traits from tables and simultaneously searches for further information in the OEIS database. In particular, the function returns the A-number of the sequence, provided it is in the database.

def LookUp(t: Table, tr: Trait, info: bool = True) -> int:
    """
    Look up the A-number in the OEIS database based on a trait of a table.

    Args:
        t (Table): The table to be analyzed.
        tr (Trait): A function that extracts a trait from the table.
        info (bool, optional): If True, information about the matching will be displayed. Defaults to True.

    Returns:
        int: The A-number of the sequence if found, otherwise 0.

    Raises:
        Exception: If the OEIS server cannot be reached after multiple attempts.
        Currently, the function will return -999999 if the OEIS server cannot be reached.

    Example:
        >>> LookUp(Fubini, PolyDiag)
        If info = False then the function returns 94420.
        Otherwise it additionally displays information about the matching:
        You searched: 1,1,10,219,8676,...
        OEIS-data is: 1,1,10,219,8676,...
        Info: Starting at index 0 the next 13 consecutive terms match.
        The matched substring starts at 0 and has length 135.
        *** Found: A094420 Generalized ordered Bell numbers Bo(n,n).
    """

With currently 70 implemented traits and 100 triangles, right out of the box 7000 queries can be made in this way. This not only systematically links the triangles with sequences to a network, but often reveals previously unnoticed connections.

Ranking of triangles.

In this way, we found that each of the 50 most highly ranked triangles generates, on average, 35 distinct related sequences registered in the OEIS. Thus, a high rank means the triangle is a significant structural component in the OEIS database and binds seemingly unrelated sequences into a semantically meaningful cluster.

Currently, 116 triangles are included in this ranking. The top 50 triangles are listed below. (Note that some links are not yet implemented.)

Name OEIS Distinct Hits Traits Links
1 StirlingSet A048993 51 60 T L
2 FallingFactorial A008279 48 59 T L
3 Lah A271703 46 54 T L
4 BinaryPell A038207 45 54 T L
5 Lucas A029635 44 59 T L
6 Partition A072233 43 53 T L
7 Fubini A131689 42 49 T L
8 StirlingCycle A132393 42 60 T L
9 CatalanInv A128908 41 47 T L
10 Ordinals A002262 40 65 T L
11 DyckPathsInv A085478 40 52 T L
12 Powers A004248 39 48 T L
13 Motzkin A064189 38 47 T L
14 BesselInv A122848 37 46 T L
15 DyckPaths A039599 37 48 T L
16 Eulerian A173018 37 55 T L
17 Catalan A128899 36 42 T L
18 Laguerre A021009 36 42 T L
19 Monotone A059481 36 50 T L
20 Narayana A090181 36 54 T L
21 AbelInv A059297 35 40 T L
22 Divisibility A113704 35 55 T L
23 Abel A137452 34 39 T L
24 Nicomachus A036561 34 41 T L
25 OrderedCycle A225479 34 38 T L
26 Schroeder A122538 34 42 T L
27 Bessel A132062 33 39 T L
28 BinomialBell A056857 33 39 T L
29 BinomialCatalan A098474 33 38 T L
30 CatalanPaths A053121 33 50 T L
31 ChebyshevS A168561 33 47 T L
32 LeibnizTable A094053 32 51 T L
33 Rencontres A008290 32 42 T L
34 LucasInv A112857 31 41 T L
35 Naturals A000027 31 35 T L
36 Worpitzky A028246 31 41 T L
37 SchroederP A104684 30 34 T L
38 ChebyshevT A053120 29 43 T L
39 MotzkinInv A101950 28 39 T L
40 MotzkinPoly A359364 28 41 T L
41 PartitionDist A000000 28 41 T L
42 Bell A011971 27 37 T L
43 ChebyshevU A115322 27 38 T L
44 Euler A109449 27 36 T L
45 StirlingCycleB A028338 27 38 T L
46 Binomial A007318 26 68 T L
47 DoublePochhammer A039683 26 32 T L
48 Pascal A007318 26 68 T L
49 Bessel2 A359760 25 41 T L
50 Delannoy A008288 25 49 T L

About

Identifying semantically meaningful clusters in the OEIS database. A Python library for integer triangles and their ranking.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages