# Homework 17 by John Miller # Please feel free to post this code. P = Primes() var('x1,x2,x3') #Definition of the function def multivariate_leading_term(f): Lst = [] L = list(f.iterator()) for i in L: Lst.append((i,(i/i.substitute(x1=1,x2=1,x3=1)).substitute(x1=P.unrank(0),x2 =P.unrank(1),x3=P.unrank(2)))) return sorted(Lst, key=lambda monomial:monomial[1])[len(Lst)-1][0] def Di(L): from itertools import imap from operator import sub return list(imap(sub,L[1:len(L)],L[0:len(L)-1])) def IsPol(L): L1 = L for i in range(len(L)-4): L1 = Di(L1) if all([v == 0 for v in L1]): return i return False def GuessPol(L,x): d = IsPol(L) if d == False: return False a = list(var("a%d" %i) for i in range(0,d+1)) P = sum([a[i]*x^i for i in range(0,d+1)]) eq = list(P.substitute(x=i+1) == L[i] for i in range(len(L))) sol = solve(eq,a,solution_dict=True)[0] return P(sol)