#C4.txt 4/4/19 Help:=proc(): print(`GuessPol1(L,n,d) , GuessPol(L,n), Comp(n,k) `): end: #GuessPol1(L,n,d): inputs a list of pairs [[input,output], ...] a variable name n #and a pos. integer d, outputs a polynomial of degree d f such that f(input)=output GuessPol1:=proc(L,n,d) local a,i,f,var,eq: if nops(L)FAIL then f:=GuessPol1(L,n,d): if f<>FAIL then RETURN(f): fi: fi: od: print(`Too bad, it did not work out, generate more date, or bad news, it is not a polynomial`): FAIL: end: #Comp(n,k): inputs non-neg. integers n and k and outputs the SET of # compositions of n into k parts (vectors of non-neg. integers that add-up to n) #of length k Comp:=proc(n,k) local S,a1,S1, s1: option remember: if k<0 or n<0 then RETURN({}): fi: if n=0 then RETURN({[0$k]}): fi: if k=0 then if n=0 then RETURN({[]}): else RETURN({}): fi: fi: S:={}: for a1 from 0 to n do S1:=Comp(n-a1,k-1): S:=S union {seq([a1,op(s1)], s1 in S1)}: od: S: end: