quiz4.mw

Quiz 4 MCS 320 Friday 16 September 2006

> restart;

1. How many operations does it take to evaluate p = x^234 + 8 x^33 - 3 x^4 as given?

   What is the best way to evaluate p?  Give all Maple commands to justify your answer.

Answer:

> p := x^234 + 8*x^33 - 3*x^4;

p := x^234+8*x^33-3*x^4

> codegen[cost](p);

2*additions+270*multiplications

> codegen[C](p,optimized);

     t1 = x*x;
     t2 = t1*t1;

     t3 = t2*t2;

     t5 = t3*t3;

     t6 = t5*t5;

     t8 = t6*t6;

     t10 = t8*t8;

     t15 = t10*t8*t6*t3*t1+8.0*t6*x-3.0*t2;

We count 14 multiplications, one addition and one subtraction.

2. Consider

> p := x^3 + x + 1:

(a) Give the Maple command (not the output) to compute a numerical factorization of p:

(b) Give all Maple commands to compute a symbolic factorization of p.  Write the symbolic factorization of p.

(c) Give the Maple commands to show the link between the symbolic and the numeric factorization of p.

Answer to (a):

> factor(p,complex);

(x+.6823278038)*(x+(-.3411639019+1.161541400*I))*(x+(-.3411639019-1.161541400*I))

Answer to (b):

> alias(alpha=RootOf(p)):

> q1 := evala(p/(x-alpha));

q1 := x^2+alpha*x+1+alpha^2

> evala(factor(q1,alpha)); evala(factor(p,alpha));

x^2+alpha*x+1+alpha^2

(x-alpha)*(x^2+alpha*x+1+alpha^2)

We see that, while x-alpha is a factor of the p now, the q1 still does not factor, we need one more formal root.

> alias(beta=RootOf(q1));

alpha, beta

> q2 := evala(q1/(x-beta));

q2 := x+alpha+beta

or alternatively, the short way shows all the factor of p:

> evala(factor(p,{alpha,beta}));

(x+alpha+beta)*(x-beta)*(x-alpha)

Answer to (c):

We see that the three symbolic factors give us the three numerical roots of the polynomial:

> evalf(alpha); evalf(beta); evalf(-alpha-beta);

.3411639019+1.161541400*I

.3411639019-1.161541400*I

-.6823278038+0.*I

Alternative answer to (b) and (c):

> restart;

> p := x^3 + x + 1:

> evala(AFactor(p));

(x-RootOf(_Z^2+RootOf(_Z^3+_Z+1)*_Z+1+RootOf(_Z^3+_Z+1)^2))*(x+RootOf(_Z^3+_Z+1)+RootOf(_Z^2+RootOf(_Z^3+_Z+1)*_Z+1+RootOf(_Z^3+_Z+1)^2))*(x-RootOf(_Z^3+_Z+1))(x-RootOf(_Z^2+RootOf(_Z^3+_Z+1)*_Z+1+RootOf(_Z^3+_Z+1)^2))*(x+RootOf(_Z^3+_Z+1)+RootOf(_Z^2+RootOf(_Z^3+_Z+1)*_Z+1+RootOf(_Z^3+_Z+1)^2))*(x-RootOf(_Z^3+_Z+1))

> f := convert(%,radical);

f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...f := (x-1/144*(-648-72*93^(1/2)-648*I*3^(1/2)-72*I*3^(1/2)*93^(1/2)-72*I*(108+12*93^(1/2))^(1/3)*3^(1/2)+72*(108+12*93^(1/2))^(1/3)+24*(9396-72*93^(1/2)*(108+12*93^(1/2))^(1/3)+54*I*3^(1/2)*(108+12*93...

Getting the symbolic factorization is easier this way, but answering question 2(c) requires then a bit more work:

We first must select the roots from the factorization because we have no formal names associated with them.  As before, the floating-point approximations of the roots show the link with the numerical factorization.

> r1 := -(op(1,f)-x): evalf(r1);

.3411639019-1.161541400*I

> r2 := -(op(2,f)-x): evalf(r2);

-.6823278038+0.*I

> r3 := -(op(3,f)-x): evalf(r3);

.3411639019+1.161541400*I