Help:=proc(): print(`GuessPol(L,x) `):end: #GuessPol(L,x): inputs a sequence of numbers #and outputs a polynomial P of x, of degree nops(L)-5 #such that L[i]=P(i), for i=1..nops(L) GuessPol:=proc(L,x) local d,P,a,var,eq: d:=nops(L)-5: P:=add(a[i]*x^i,i=0..d): var:={seq(a[i],i=0..d)}: eq:={seq(subs(x=i,P)=L[i],i=1..nops(L))}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): fi: subs(var,P) end: #GuessRat1(L,x,d1,d2): inputs a sequence of numbers #and non-negative integers d1 and d2 #and outputs a rational function R of x, of top-degree #d1 and bottom-degree d2, such that #such that L[i]=P(i), for i=1..nops(L) GuessRat1:=proc(L,x,d1,d2) local d,R,a,b,var,eq: if nops(L)-d1-d2-1<5 then ERROR(`Insufficient data`): fi: R:=add(a[i]*x^i,i=0..d1)/add(b[i]*x^i,i=0..d2): var:={seq(a[i],i=0..d1),seq(b[i],i=0..d2)}: eq:={seq(subs(x=i,R)=L[i],i=1..nops(L))}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): fi: normal(subs(var,R)) : end: #GuessRat(L,x): inputs a sequence L and a variable x #and tries to find a rational function fitting it GuessRat:=proc(L,x) local d1,d2,d,R: for d from 0 to nops(L)-6 do for d1 from 0 to d do d2:=d-d1: R:=GuessRat1(L,x,d1,d2): if R<>FAIL then RETURN(R): fi: od: od: FAIL: end: