DeRhamComputation/sage/auxilliaries/linear_combination_polynomials.sage

16 lines
782 B
Python
Raw Normal View History

def linear_representation_polynomials(polynomial, list_of_polynomials):
'''Given >list_of_polynomials< and >polynomial<, which is a linear combination of polynomials in the list (over the base ring),
find coefficients of this combination.'''
F = polynomial.parent().base_ring()
monomials = polynomial.monomials()
for pol in list_of_polynomials:
monomials += pol.monomials()
monomials = Set(monomials)
monomials = list(monomials)
d = len(monomials)
M = matrix(F, d, len(list_of_polynomials))
for i, pol in enumerate(list_of_polynomials):
for j, m in enumerate(monomials):
M[j, i] = pol.monomial_coefficient(m)
v = vector([polynomial.monomial_coefficient(m) for m in monomials])
return list(M.solve_right(v))