# Factoring a symbolic polynomial

The following code:

llambda, mu = var('λ, μ')
uVars = list(var(', '.join([f'u{n}' for n in range(1, 3 + 1)])))
aVars = list(var(', '.join([f'a{n}' for n in range(1, 3 + 1)])))

U = Matrix([[0, -uVars, uVars],
[uVars, 0, -uVars],
[-uVars, uVars, 0]])
a = Matrix([[aVars, 0, 0],
[0, aVars, 0],
[0, 0, aVars]])
I = matrix.identity(3)

L = a*llambda + U

# Characteristic polynomial

charPoly = det((L - mu*I))
factor(charPoly)


computes a characteristic polynomial and yields:

a1*a2*a3*λ^3 - a1*a2*λ^2*μ - a1*a3*λ^2*μ - a2*a3*λ^2*μ
+ a1*u1^2*λ + a2*u2^2*λ + a3*u3^2*λ + a1*λ*μ^2
+ a2*λ*μ^2 + a3*λ*μ^2 - u1^2*μ - u2^2*μ - u3^2*μ - μ^3


However, this is not the simplification I desire. I want this: $$(a_1\lambda - \mu)(a_2\lambda - \mu)(a_3\lambda - \mu) - (u_1^2 + u_2^2 + u_3^2)\mu + (a_1 \mu_1^2 + a_2 u_2^2 + a_3 u_3^2)\lambda$$

Is there a way to obtain that sort of factorization?

edit retag close merge delete

I don't think there is an easy way to achieve this. Even Mathematica doesn't know what to do with this expression (If you have it installed, you can try with charPoly._mathematica_().Factor()._sage_(), but you need to use plain text variables). Sometimes it is a bit more powerful than Maxima, but not in this case.