# Revision history [back]

I think this works better -- use polynomials, not symbolic expressions. I have written the following in a way which would work for any field in place of K:

sage: K.<g> = CyclotomicField(5)
sage: R = PolynomialRing(K,K.degree(),'x')
sage: sum([R.gen(i)*(g^i).matrix() for i in range(K.degree())]).det()
x0^4 - x0^3*x1 + x0^2*x1^2 - x0*x1^3 + x1^4 - x0^3*x2 + 2*x0^2*x1*x2 - 3*x0*x1^2*x2 - x1^3*x2 + x0^2*x2^2 + 2*x0*x1*x2^2 + x1^2*x2^2 - x0*x2^3 - x1*x2^3 + x2^4 - x0^3*x3 + 2*x0^2*x1*x3 + 2*x0*x1^2*x3 - x1^3*x3 - 3*x0^2*x2*x3 - x0*x1*x2*x3 + 2*x1^2*x2*x3 + 2*x0*x2^2*x3 - 3*x1*x2^2*x3 - x2^3*x3 + x0^2*x3^2 - 3*x0*x1*x3^2 + x1^2*x3^2 + 2*x0*x2*x3^2 + 2*x1*x2*x3^2 + x2^2*x3^2 - x0*x3^3 - x1*x3^3 - x2*x3^3 + x3^4


As already mentioned, one can just as easily get the trace or even the characteristic polynomial of a general element:

sage: M = sum([R.gen(i)*(g^i).matrix() for i in range(K.degree())])
sage: M.trace()
4*x0 - x1 - x2 - x3
sage: M.charpoly('t')
t^4 + (-4*x0 + x1 + x2 + x3)*t^3 + (6*x0^2 - 3*x0*x1 + x1^2 - 3*x0*x2 + 2*x1*x2 + x2^2 - 3*x0*x3 + 2*x1*x3 - 3*x2*x3 + x3^2)*t^2 + (-4*x0^3 + 3*x0^2*x1 - 2*x0*x1^2 + x1^3 + 3*x0^2*x2 - 4*x0*x1*x2 + 3*x1^2*x2 - 2*x0*x2^2 - 2*x1*x2^2 + x2^3 + 3*x0^2*x3 - 4*x0*x1*x3 - 2*x1^2*x3 + 6*x0*x2*x3 + x1*x2*x3 - 2*x2^2*x3 - 2*x0*x3^2 + 3*x1*x3^2 - 2*x2*x3^2 + x3^3)*t + x0^4 - x0^3*x1 + x0^2*x1^2 - x0*x1^3 + x1^4 - x0^3*x2 + 2*x0^2*x1*x2 - 3*x0*x1^2*x2 - x1^3*x2 + x0^2*x2^2 + 2*x0*x1*x2^2 + x1^2*x2^2 - x0*x2^3 - x1*x2^3 + x2^4 - x0^3*x3 + 2*x0^2*x1*x3 + 2*x0*x1^2*x3 - x1^3*x3 - 3*x0^2*x2*x3 - x0*x1*x2*x3 + 2*x1^2*x2*x3 + 2*x0*x2^2*x3 - 3*x1*x2^2*x3 - x2^3*x3 + x0^2*x3^2 - 3*x0*x1*x3^2 + x1^2*x3^2 + 2*x0*x2*x3^2 + 2*x1*x2*x3^2 + x2^2*x3^2 - x0*x3^3 - x1*x3^3 - x2*x3^3 + x3^4