ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 17 May 2023 16:27:15 +0200Code for guessing formula for integer sequencehttps://ask.sagemath.org/question/68486/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](https://www.maplesoft.com/support/help/maple/view.aspx?path=gfun%2Fguessgf)) and Mathematica ([example](https://reference.wolfram.com/language/ref/FindSequenceFunction.html)) 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.Johannes SchmittWed, 17 May 2023 16:27:15 +0200https://ask.sagemath.org/question/68486/