#John Kim #Use whatever you like Help:=proc(): print(` Gsomos4(Ini,n), Guess2NLR(L,f,n, MaxD) `): print(`GenPol(X,d,a,co), Gsomosk(Ini,k,n), GenHomPol(X,d,a,co)`): print(`GenNonHomPol(X,d,a,co)`): end: #Gsomos4(Ini,n): outputs the n-th term of the Somos4 recurrence #with initial conditions Ini, i.e. s[1]=Ini[1], etc. #For example, Gsomos4([1,1,1,1,20); Gsomos4:=proc(Ini,n) option remember: if n<=4 then Ini[n]: else normal((Gsomos4(Ini,n-1)*Gsomos4(Ini,n-3)+Gsomos4(Ini,n-2)^2)/ Gsomos4(Ini,n-4)): fi: end: #Guess2NLR(L,f,n, MaxD) #inputs a sequene L and symbols f and n and tries to guess #a NON-LINEAR recurrene of 2nd order of the form #P( f(n-2),f(n-1),f(n))=0 of degree Guess2NLR:=proc(L,f,n, MaxD) local d,ans: for d from 1 to MaxD do ans:=Guess2NLRd(L,f,n,d): if ans<>FAIL then RETURN(ans): fi: od: FAIL: end: #Guess2NLRd(L,f,n, d) #inputs a sequene L and symbols f and n and tries to guess #a NON-LINEAR recurrene of 2nd order of the form #P( f(n-2),f(n-1),f(n))=0 of exact degree d Guess2NLRd:=proc(L,f,n, d) local ans, P, X,Y,Z: end: #GenPol(X,d,a,co): #Inputs #(i) a list of variables X e.g. [x,y,z] (let m=nops(X), the number of #variables) #(ii) a pos. integer d, for the degree #(iii) a symbol a by which the coeff. (undetermined) of the pol. #are expressed #(iiii) co, starting counter #Outputs: #(i)A generic polynomial in the variables X of degree d #with coeff. expressed as a[co],ac[co+1], ..., a[co+AsNeeded] #(ii) the set of coefficients #(iii) the new value of the counter #For example, GenPol([x],1,a,0); should output #a[0]+a[1]*x,{a[0],a[1]},2 GenPol:=proc(X,d,a,co) local P, var, co1,m,i,x,X1,P1: option remember: m:=nops(X): x:=X[1]: if m=1 then RETURN(add( a[co+i]*x^i,i=0..d), {seq(a[co+i],i=0..d)},co+d+1): fi: co1:=co: X1:=[op(2..m,X)]: P:=0: var:={}: for i from 0 to d do P1:=GenPol(X1,d,a,co1): P:=expand(P+P1[1]*x^i): var:=var union P1[2]: co1:=P1[3]: od: P,var,co1: end: #Gsomosk(Ini,k,n): outputs the n-th term of the Somos-k recurrence, #where Somos-k is the natural k-th order analog of the Somos-4 recurrence. Gsomosk:=proc(Ini,k,n) option remember: local i: if n<=k then Ini[n]: else normal(add(Gsomosk(Ini,k,n-i)*Gsomosk(Ini,k,n-(k-i)),i=1..trunc(k/2))/Gsomosk(Ini,k,n-k)): fi: end: #The somos k sequence with Ini=[1$k] produces integers for k<=7, and seems to contain non-integers for k>=8. #Again, the monomial denominators end at k=7. #GenHomPol(X,d,a,co): like GenPol(X,d,a,co), but yields a homogeneous polynomial of total degree d. GenHomPol:=proc(X,d,a,co) local P, var, co1,m,i,x,X1,P1: option remember: m:=nops(X): x:=X[1]: if m=1 then RETURN(a[co]*x^d, {a[co]},co+1): fi: co1:=co: X1:=[op(2..m,X)]: P:=0: var:={}: for i from 0 to d do P1:=GenHomPol(X1,d-i,a,co1): P:=expand(P+P1[1]*x^i): var:=var union P1[2]: co1:=P1[3]: od: P,var,co1: end: #GenNonHomPol(X,d,a,co): the sum of the homog. polynomials of total degree i for i=0...d. GenNonHomPol:=proc(X,d,a,co) local P,P1,var,co1,i: option remember: co1:=co: P:=0: var:={}: for i from 0 to d do P1:=GenHomPol(X,i,a,co1): P:=expand(P+P1[1]): var:=var union P1[2]: co1:=P1[3]: od: P,var,co1: end: