#proj7.txt, April 13 2024 #Project Member: Gloria Liu #Project 7: Given a large positive integer A Consider the sequences of the form #Coefficient of x^0 in (a+b/x+c*x)^n for -A ≤ a,b,c ≤ A, and igcd(a,b,c)=1 #Construct a data base, in the style of the OEIS, that lists the first 30 terms of each, and the #linear recurrences obtained via the famous Almkvist-Zeilberger algorithm, with the command #AZd( (a*x+b+c/x)^n/x,n,N)[1] #in the Maple package EKHAD.txt #Find out which ones are already in the OEIS. #=====================================# Help:=proc() print(`Seq(a,b,c,K), Recurrence(a,b,c,n,N), SeqA(A), Lookup(L,db), LookupO(OEISnum,db)`): print(`ExportDBFromA(A,dest,dir), ExportDBFromResult(result,dest,dir), DatabaseImport(src,dir)`): print(`Example1(), Example2()`): end: read `EKHAD.txt`: #Seq(a,b,c,K) creates a sequence of numbers corresponding to the constant term in (a*x + b + c/x)^n) #With n from 1 to K Seq:= proc(a, b, c, K) local n, x: [seq(coeff(expand((a*x + b + c/x)^n), x, 0), n = 1 .. K)]: end: #Recurrence(a,b,c,n,N) finds the recurrence relation of the associated sequence Seq(a,b,c,K) Recurrence:=proc(a, b, c, n, N) local x: AZd((a*x + b + c/x)^n/x, x, n, N)[1]: end: #SeqA(A) finds Seq(a,b,c,30), for all -A0 then Result:=[op(Result), [-a,b,c,op(Seq(-a,b,c,30))]]: fi: fi: od: od: od: Result: end: #Given a list of at least 6 integers L, tries to match the sequence with one from a database (list of lists) of sequences db #If a matching sequence is found, also returns the corresponding recurrence relation #In the sequence that is found, the first three entries correspond to a,b,c of the sequence #The next thrity terms are the terms of the sequence #The recurrence relation is calculated using a,b,c #Inefficient Way! Lookup:=proc(L,db) local entry,l,found,i,j,recurrence,a,b,c: if nops(L) < 6 then print("Please use at least six terms to look for a sequence"): RETURN(FAIL): fi: if nops(L) > 30 then print("Please use at most 30 terms"): RETURN(FAIL): fi: found:=false: for entry in db do for j from 3 to nops(entry)-nops(L) do for i from 1 to nops(L) do if L[i]<>entry[i+j] then break: fi: if i=nops(L) then found:=true: fi: od: if found=true then a:=entry[1]: b:=entry[2]: c:=entry[3]: recurrence:=Recurrence(a,b,c,n,N): RETURN(entry,recurrence): fi: od: od: RETURN(FAIL): end: #LookupO(OEISnum,db): finds if there is a sequence in the the database (list of lists) db, that has OEIS reference number OEISnum #db needs to have its last column LookupO:=proc(OEISnum,db) local entry,i,a,b,c,recurrence: for entry in db do if entry[nops(entry)]=OEISnum then a:=entry[1]: b:=entry[2]: c:=entry[3]: recurrence:=Recurrence(a,b,c,n,N): RETURN(entry,recurrence): fi: od: RETURN(FAIL): end: #ExportDBFromA(A,dest,dir): Creates a database of sequences and exports it as a csv file. #Input: A to generate sequences, file name destination, and directory ExportDBFromA:=proc(A,dest,dir) local result,resultMatrix: result:=SeqA(A): resultMatrix:=convert(result,Matrix): Export(dest,resultMatrix,base=dir): end: #ExportDBFromResult(result,dest,dir): Exports a csv file of sequences given a list of lists(sequences). ExportDBFromResult:=proc(result,dest,dir) local resultMatrix: resultMatrix:=convert(result,Matrix): Export(dest,resultMatrix,base=dir): end: #DatabaseImport(src,dir): Imports a database of sequences from a csv file, and converts it into a list of lists. DatabaseImport:=proc(src,dir) local m: m:=Import(src,base=dir,output=Matrix): convert(m,list,nested): end: #Connecting to OEIS #I did not know how to check which sequences were already in the OEIS through Maple. #Unfortunately the OEIS package in Maple is no longer maintained. #I am using Python to retrieve the sequences instead. #Example process that uses the functions to generate sequences #It will first create a list of sequences using SeqA(A). #Then it will perform a sample lookup. #Finally, it will export the database into a csv file. Example1:=proc() local db,L,LFake: db:=SeqA(5): L:=[1,21,61,721,3201,29301]: print(Lookup(L,db)); LFake:=[1,2,9,10,11,12]: print(Lookup(LFake,db)); ExportDBFromResult(db,"seq.csv",worksheetdir): end: #Example process that uses the functions to look up sequences. #It imports a sample csv file that also has a column for the OEIS reference number. #Then it will perform a sample lookup by sequence. #Then it will perform a sample lookup by OEIS reference number. Example2:=proc() local db: db:=DatabaseImport("seq.csv",worksheetdir): print(LookupO("A084605",db)); end: