MCS 320 Exam 1 Wednesday 21 February 2007 

> restart; 1
 

1. Consider the polynomial p = x^3+3*x^2+8.Give Maple commands (with output) 

> p := x^3 + 3*x^2 + 8;
 

(Typesetting:-mprintslash)([p := x^3+3*x^2+8], [x^3+3*x^2+8]) 

(a) to show that p is irreducible over the rational numbers : 

> factor(p); 1; irreduc(p)
 

x^3+3*x^2+8 

true 

(b) to factor p symbolically into a product of linear polynomials, adding sufficiently many formal roots : 

> alias(alpha = RootOf(p)); 1
 

alpha 

> f := factor(p, alpha); 1
 

(Typesetting:-mprintslash)([f := (x-alpha)*(x^2+3*x+x*alpha+3*alpha+alpha^2)], [(x-alpha)*(x^2+3*x+x*alpha+3*alpha+alpha^2)]) 

> op(2, f); 1
 

x^2+3*x+x*alpha+3*alpha+alpha^2 

> alias(beta = RootOf(op(2, f))); 1
 

alpha, beta 

> fp := factor(p, {beta, alpha}); 1
 

(Typesetting:-mprintslash)([fp := (x-beta)*(3+alpha+beta+x)*(x-alpha)], [(x-beta)*(3+alpha+beta+x)*(x-alpha)]) 

(c) to factor p numerically : 

> factor(p, complex); 1
 

(x+3.612887865)*(x+(-.3064439324+1.456154952*I))*(x+(-.3064439324-1.456154952*I))
(x+3.612887865)*(x+(-.3064439324+1.456154952*I))*(x+(-.3064439324-1.456154952*I))
 

(d) to show the relation between the numerical and the symbolic factorization : 

> evalf(fp); 1
 

(x+(-.3064439324+1.456154952*I))*((3.612887864+0.*I)+x)*(x+(-.3064439324-1.456154952*I))
(x+(-.3064439324+1.456154952*I))*((3.612887864+0.*I)+x)*(x+(-.3064439324-1.456154952*I))
 

2. Execute the commands  

> restart; k := 3; sum(x[k],k=1..5);
 

(Typesetting:-mprintslash)([k := 3], [3]) 

Error, (in sum) summation variable previously assigned, second argument evaluates to 3 = 1 .. 5 

(a) Explain why the third command does not give the desired result. 

The variable k has already a value before the sum command is executed. 

The sum command can therefore not use k to evaluate the range 1..5. 

(b) Modify ONLY the third command so that is returns 

> sum(x['k'],'k'=1..5);
 

x[1]+x[2]+x[3]+x[4]+x[5] 

3. The sequence 7/5, 141/100, 707/500, 7071/5000, 66441/46981 

gives rational approximations to  

When answering the questions below, also give the Maple commands used: 

(a) How many decimal places in 66441/46981 as rational approximation for sqrt(2) are correct? 

> s2 := evalf(sqrt(2));
 

(Typesetting:-mprintslash)([s2 := 1.414213562], [1.414213562]) 

> r := evalf(66441/46981);
 

(Typesetting:-mprintslash)([r := 1.414210000], [1.414210000]) 

We see that six decimal places agree. 

(b) What is the next element in the sequence? 

As the previous number is correct up to six decimal places, we evaluate sqrt(2) with 7 decimal places before converting it to a rational number: 

> convert(evalf(sqrt(2),7),rational);
 

41131/29084 

 

 

4. Do q := (x/y - 1)/(y/x - 1); and consider the expression assigned to q. 

> q := (x/y - 1)/(y/x - 1);
 

(Typesetting:-mprintslash)([q := (x/y-1)/(y/x-1)], [(x/y-1)/(y/x-1)]) 

(a) Give the Maple command(s) to display the internal representation of this expression. 

> dismantle[dec](q); 1
 


PROD(135277496,5)
  SUM(135277424,5)
     PROD(135277400,5)
        NAME(135011340,4): x
        INTPOS(3,2): 1
        NAME(135232876,4): y
        INTNEG(-1,2): -1
     INTPOS(3,2): 1
     INTNEG(-1,2): -1
     INTPOS(3,2): 1
  INTPOS(3,2): 1
  SUM(135277472,5)
     PROD(135277448,5)
        NAME(135232876,4): y
        INTPOS(3,2): 1
        NAME(135011340,4): x
        INTNEG(-1,2): -1
     INTPOS(3,2): 1
     INTNEG(-1,2): -1
     INTPOS(3,2): 1
  INTNEG(-1,2): -1

 

 

(b) Draw the directed acyclic graph which represents this expression. 

See the handout on paper. 

(c) Explain the outcome of subs(-1=+2,q).  Why are all the divisions gone? 

> subs(-1 = 2, q); 1
 

(x*y^2+2)*(y*x^2+2)^2 

>
 

Maple represents every object only once.  Not only do the coefficients "-1" turn into "+2", but also the divisions disappear, because a division is represented as a power product with a negative exponent for the denominator. 

 

5. Let r = (x^14-8*x^12+9*x)/(x^13+14*x^7-3*x^5) . Give all Maple commands and their output when answering the questions below. 

> r := (x^14-8*x^12+9*x)/(x^13+14*x^7-3*x^5); 1
 

(Typesetting:-mprintslash)([r := (x^14-8*x^12+9*x)/(x^13+14*x^7-3*x^5)], [(x^14-8*x^12+9*x)/(x^13+14*x^7-3*x^5)]) 

(a) Convert rinto a Horner form. 

> h := convert(r, horner); 1
 

(Typesetting:-mprintslash)([h := (9+(-8+x^2)*x^11)/(x^4*(-3+(14+x^6)*x^2))], [(9+(-8+x^2)*x^11)/(x^4*(-3+(14+x^6)*x^2))]) 

(b) Compare to the given form of r, how many arithmetical operations are gained when using the Horner form of rto evaluate  

> codegen[cost](r); 1
 

4*additions+50*multiplications+divisions 

> codegen[cost](h); 1
 

4*additions+22*multiplications+2*divisions 

> %-`%%`; 1
 

-28*multiplications+divisions 

We gained 28 multiplications at the expense of one division. 

(c) What is the most efficient way to evaluate r ? 

> codegen[C](r, optimized); 1
 

     t1 = x*x;
     t2 = t1*t1;
     t4 = t2*t2;
     t10 = t2*x;
     t18 = (t4*t2*t1-8.0*t4*t2+9.0*x)/(t4*t10+14.0*t2*t1*x-3.0*t10);
 

Here we count only 14 multiplications, 4 additions, and one division. 

 

6. Consider the polynomials p = x^2-7/4 and  

(a) Are these polynomials the same or are they different? 

> p := x^2 - 7/4; q := x^2 - 1.75;
 

(Typesetting:-mprintslash)([p := x^2-7/4], [x^2-7/4]) 

(Typesetting:-mprintslash)([q := x^2-1.75], [x^2-1.75]) 

They look different, but  

> evalf(p); 1
 

x^2-1.750000000 

they are only the same if 1.75 = 7/4.  In computer algebra 7/4 is an exact rational number and consequently p is a polynomial with coefficients in the rational number field, whereas 1.75 is regarded as a floating-point number of limited precision, here by default 10.  So the polynomial q is seen by Maple as a polynomial with floating-point real coefficients. 

(b) Explain why the outcome of factor is then so different. 

The polynomial p has rational coefficients, we call it a rational polynomial. 

The polynomial p has real floating-point coefficients, we call it a real polynomial. 

> factor(p); 1
 

x^2-7/4 

> factor(q); 1
 

(x+1.322875656)*(x-1.322875656) 

The rational polynomial p has no rational roots, so it does not factor over the rational numbers. 

The real polynomial q has two real roots, so it factors.