# Writing elements as a linear combination in a basis in a quotient ring

I have an explicit ideal in a multivariable polynomial ring R. I know a priori that the quotient ring R/I is finite dimensional (as a vector space). In fact I have an explicit basis in R/I. I have all this programmed into sage. Is there a way to find the linear combination for a given element in R/I in the given basis?

example:

sage: R.<e1,e2>=PolynomialRing(QQ)

sage: I = ideal(e1^3 -2 * e2 * e1 +1, e2 * e1^2 - e2^2 - e1)

sage: I.vector_space_dimension()

6

sage: f22= e2^2 - e1; f21 = e2*e1 - 1; f11 = e1^2 - e2; f1= e1; f2 = e2; f0 = 1;

sage: I.reduce(f21*f21)

e1*e2

sage: I.reduce(f21*f21) == f21 + f0

True

I have an ideal I in R and I know that the quotient ring R/I is 6 dimensional over the field. I have the basis f22,f21,f11,f2,f1,f0 of R/I as a vector space over QQ. I would like to find the structure constants of this finite dimensional algebra. For example compute f21^2 in the quotient ring, and write it in the basis, we get f21^2=f21+f0. But I only get it by hand and would like to compute it with sage, so that I could get the whole set of structure constants.