Help:=proc(): print(` Gsomos4(Ini,n), Guess2NLR(L,f,n, MaxD) `): print(`GenPol(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): #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: