Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Code for guessing formula for integer sequence

Hey everyone, I was wondering if there already exists some code in SageMath for solving a problem of the shape:

Given a sequence A_n of numbers/polynomials/etc, guess a formula for A_n.

E.g. a very basic use-case would be something like

sage: n = SR('n')
sage: guess({1:1,2:4,3:9,4:16,5:25,6:36,7:49}, n)
n^2
sage: R.<a,b> = PolynomialRing(QQ)
sage: guess({1:a+b, 2:a^2 + a*b + b^2, 3:a^3 + a^2*b + a*b^2 + b^3}, n)
(a^(n + 1) - b^(n + 1))/(a - b)

Of course for integer sequences, one approach is to query the Online Encyclopedia of Integer Sequences with the oeis-function. But this will not return a symbolic expression/SageMath function, and would also fail if A_n is e.g. a random polynomial of degree 5 in n.

Apart from finding a symbolic expression as above, other possible outputs could be a generating function or even a Python function. I have seen that both maple (example) and Mathematica (example) have similar functionality. In this context, I would also be interested in any references to descriptions of algorithms that can be used for such a task.

I realize this is a very open-ended question, so I am very grateful for any pointers to software/literature/etc.