Answer to Quiz 2 Fri 21 Jan 2005

  1. Consider the evaluation of polynomials.
    1. Let p = a0 + a1*x + a2*x^2 + a3*x^3.
      How many additions and multiplications are needed to evaluate p?

      Answer:

          number of additions : 3 ( just count the plus signs )
          number of multiplications : 1 + 2 + 3 = 6
      
          Storing x^2 as y brings the number of multiplications
          down to 5.
      
    2. Let q = ((a3*x + a2)*x + a1)*x + a0.
      How many additions and multiplications are needed to evaluate q?

      Answer:

          number of additions : 3
          number of multiplications : 3
      

  2. Assume the floating-point arithmetic on our computer has base 10, with 4 decimal places in the fraction (or mantissa), and exponents ranging between -10 and +10.
    Show the evaluation of 34.42 + 0.012 in this floating-point system.

    Answer:

      represent:
                  34.41 = +.3441 10^2
                  0.012 = +.1200 10^(-1)
      align:
                        = +.0001200 10^2
      add:
                +.3441    10^2
                +.0001200 10^2
                --------------
                +.3442200 10^2
    
      round:
                +.3442 10^2 = 34.42