#C7.txt Help:=proc(): print(` ProbConts(), Wt(L,x) , GFp(LL,x) , Comp(n,k) , CompU(n,k) `): print(`GuessMulPol1(L,x,k,d), GuessMulPol(L,x,k) `): end: #VD ProbConts:=proc(): [[4,1,3],[5,3,2],[4,1,5],[4,1,5], [4,1,5],[4,2,1],[2,5,1],[2,4,5],[6,5,1], [2,4,6],[4,2,1],[2,1,6],[1,2,4],[1,4,3]]: end: #maps a list of integers to x[1]^L[1]*...x[nops(L)]^L[nops(L)] Wt:=proc(L,x) local i: mul(x[i]^L[i],i=1..nops(L)): end: #GFp(LL,x) GFp:=proc(LL,x) local i: add(Wt(LL[i],x),i=1..nops(LL)): end: ####end VD #from C4.txt #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: #end C4.txt #CompU(n,k) the set of vectors with k non-neg. componets that add up to <=n CompU:=proc(n,k) local n1: {seq(op(Comp(n1,k)),n1=0..n)}: end: #GuessMulPol1(L,x,k,d): inputs a list L of data of the form [pt,value] where #pt is a list of length k, and value is the value. Guesses a polynomial #in x[1], ..., x[k] of degree d,P, such that P(L[i][1])=L[i][2] GuessMulPol1:=proc(L,x,k,d) local S,a,s,P,i,var,eq,i1: if not ( type(L,list) and {seq(type(L[i],list),i=1..nops(L))}={true} and {seq(nops(L[i]),i=1..nops(L))}={2} and {seq(type(L[i][1],list),i=1..nops(L))}={true} and {seq(nops(L[i][1]),i=1..nops(L))}={k}) then print(`bad input`): RETURN(FAIL): fi: S:=CompU(d,k): P:=add(a[s]*mul(x[i]^s[i],i=1..k), s in S): var:={seq(a[s],s in S)}: eq:={seq(subs({seq(x[i1]=L[i][1][i1],i1=1..k)},P)=L[i][2],i=1..nops(L))}: if nops(eq)-nops(var)<=3 then print(`not enough data `): RETURN(FAIL): fi: var:=solve(eq,var): if var=NULL then RETURN(FAIL): fi: P:= subs(var,P): if P=0 then RETURN(FAIL): else RETURN(P): fi: end: #Added after class ended #GuessMulPol(L,x,k): inputs a list L of data of the form [pt,value] where #pt is a list of length k, and value is the value. Guesses a polynomial #in x[1], ..., x[k] of degree <=Maxd ,P, such that P(L[i][1])=L[i][2] GuessMulPol:=proc(L,x,k) local d,P,d1: for d from 1 while nops(L)-nops(CompU(d,k))>3 do od: d:=d-1: for d1 from 1 to d do P:=GuessMulPol1(L,x,k,d1): if P<>FAIL then RETURN(P): fi: od: FAIL: end: