evaluate result of expression containing ROOTOF

Hi, all,
I have a question about how to evaluate result of expression containing ROOTOF.

for example:
>alias(x = RootOf(Z^3+Z+1))

>A := a[2]*x^2+a[1]*x+1

>B := b[2]*x^2+b[1]*x+1

>M1 := A*B;

>expand(M1);
a[2]*x^4*b[2]+a[2]*x^3*b[1]+a[2]*x^2+a[1]*x^3*b[2]+a[1]*x^2*b[1]+a[1]*x+b[2]*x^2+b[1]*x+1
>evala(expand(M1));
x^2*(1+b[2]-b[1]+a[2]*b[1]*x+a[2]*b[2]*x^2+a[1]*b[2]*x+a[1]*b[1]+a[2]-a[1]-a[1]*x^2-x^2*b[1]-x+x^2)

I have questions about expand(M1) and evala(expand(M1)).
>expand(M1);
a[2]*x^4*b[2]+a[2]*x^3*b[1]+a[2]*x^2+a[1]*x^3*b[2]+a[1]*x^2*b[1]+a[1]*x+b[2]*x^2+b[1]*x+1

How can we make the result look better, I mean in a better order, like:
(...)*x^2+(...)*x^1

>evala(expand(M1));
x^2*(1+b[2]-b[1]+a[2]*b[1]*x+a[2]*b[2]*x^2+a[1]*b[2]*x+a[1]*b[1]+a[2]-a[1]-a[1]*x^2-x^2*b[1]-x+x^2)

Why are there brackets in the result which is actually a fully expanded expression.

Thanks a lot.

Sorry, the second question

Sorry, the second question should be:

Why are there brackets in the result which is actually NOT a fully expanded expression.

collect

collect(M1,x);

As for the second question, there is evala(Expand(...)) rather than evala(expand(...)).

Thank you. It works.

Thank you. It works.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}