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.
After installing Fricas, you can try
fricas.guess[TAB]
to see available useful tools.Thanks a lot, this is really helpful, and an impressive library! Also there are associated papers with more references.