A number of methods are especially useful when working with polynomials. Let's see how they work:
var('x') exp1 = (x + 3)^3 == (x - 1)^2 show(exp1) print("Expanded expression:") exp2 = exp1.expand() show(exp2) print("Expand left-hand side only:") show(exp1.expand('left')) lhs = exp1.expand('left').lhs() print("Factor LHS:") show(lhs.factor()) print("Information about the expanded LHS:") print(" Highest degree of x on LHS: {0}".format(lhs.degree(x))) print(" Coefficients: {0}".format(lhs.coeffs(x))) print(" Coefficient of x^2: {0}".format(lhs.coeff(x,2))) print(" Trailing coefficient of LHS: {0}".format (lhs.trailing_coefficient(x)))
The output is shown in the following screenshot: