From dce3c4bad1a872961b21e02856467e7937cae342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Clavijo?= Date: Mon, 25 Dec 2023 00:05:37 -0300 Subject: [PATCH] Create oeis_closed_form.py: WIP --- oeis_closed_form.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 oeis_closed_form.py diff --git a/oeis_closed_form.py b/oeis_closed_form.py new file mode 100644 index 0000000..6e4d076 --- /dev/null +++ b/oeis_closed_form.py @@ -0,0 +1,47 @@ +from sage.all import * +import sys +import json +import requests +import sqlite3 + +def getSequence(id): + f = requests.get("https://oeis.org/search?fmt=json&q=id:%s" % id) + doc = json.loads(f.content) + return [int(x) for x in doc['results'][0]['data'].split(",")] + +def guessSequence(lst): + C = CFiniteSequences(QQ) + if (s:= C.guess(lst)) == 0: + return + else: + return s.closed_form() + + +def checkSequence(id,items=10): + data = getSequence(id) + seq = data[:items] + print(id,seq) + if len(seq) > 7 and (r:=guessSequence(seq)) is not None: + seq = data[:items * 5] + return guessSequence(seq) + + +def procfile(): + IDS=[line.rstrip() for line in open(sys.argv[1],'r').readlines()] + for id in IDS: + print(id, getSequence(id)) + + +def proc2(): + #conn = sqlite3.connect('oeis.db') + #cur = conn.cursor() + #cur.execute("CREATE TABLE sequence(id, name,data,formula)") + #for row in cur.execute("SELECT id,name,data,formula FROM sequence ORDER BY id"): + n = 1 + while True: + id = "A%06d" % n + print(id, checkSequence(id)) + n+=1 + +proc2() +#procfile()