- Show that a degree
*n*two-variable polynomial has (*n*+1)(*n*+2)/2 terms and that a degree*n*three-variable polynomial has (*n*+1)(*n*+2)(*n*+3)/6 terms. - Under finite precision arithmetic, addition and multiplication
operators are commutative. In general, the associative law and
distributive law do not hold. Suppose you have a decimal computer
with four significant digits for floating number computation.
- Find three floating point numbers
*a*,*b*and*c*such that (*a*b*)**c*is not equal to*a**(*b*c*). That is, the associative law fails. - Find three floating point numbers
*a*,*b*and*c*such that*a**(*b+c*) is not equal to*a*b*+*a*c*. That is, the distributive law fails.

- Find three floating point numbers
- Function
**cos(x)**has a series similar to that of**sin(x)**:Based on the function of

**sin(x)**, write a function for**cos(x)**. Will you get strange results similar to that of**sin(x)**. - Let us minimize the effect of subtractions in the computation of
**sin(x)**and**cos(x)**. Use two variables,**positive**and**negative**. The former accumulates all terms with positive signs, while the latter accumulates all terms with negative signs. The result is**positive - negative**. Would this scheme be better? Write a program to verify it. - Given a polynomial like the following one:
it is always possible to rearrange the terms to a new form:

What is the advantages of the second form over the first one? Please count the number of multiplications. Which form would propagate errors faster? Write a function that takes a degree

*n*polynomial (coefficients in an array) and an*x*, and evaluates the polynomial at*x*using the second form. - Let us do a dramatic floating point computation experiment.
The above shows a pentagon

. If we draw the five diagonals of this pentagon, we have a smaller pentagon lying in pentagon*ABCDE*. This smaller pentagon has its vertices in white color. Let us call the original pentagon*ABCDE*and the smaller pentagon*P*, because it is the result of "going" inside of pentagon*in*(*P*).*P*If we extend the sides of the given pentagon, they will intersect in five points, which define a new pentagon lying outside of pentagon

. We call this new "outside" pentagon*P*, because it lies outside of pentagon*out*(*P*).*P*From this construction, we know that going out from

should be*in*(*P*). Similarly, going in from*P*should also be*out*(*P*). More precisely, we have*P*and*P*=*out*(*in*(*P*)). Let*P*=*in*(*out*(*P*))denote executing the "going in" operation*in*^{k}(*P*)times, and*k*denote executing the "going out" operation*out*^{k}(*P*)times. Then, the following should hold*k**P*=*out*^{k}(*in*^{k}(*P*)) =*in*^{k}(*out*^{k}(*P*))This means that going in

times followed by going out*k*times should yield pentagon*k*. Similarly, going out*P*times followed by going in*k*times should also yield pentagon*k*.*P*Now consider the following strange pentagon:

The vertices are as follows, where

can be 0.1, 0.01, 0.001, 0.0001, 0.00001 and 0.000001.*p**Vertex**x**y**A*0 1 *B*0 0 *C*1 0 *D*1 + *p*1 *E*1 1 + *p*For a given

, compute*P*,*out*^{2}(*in*^{2}(*P*)),*out*^{3}(*in*^{3}(*P*))and*in*^{2}(*out*^{2}(*P*)). Then, theoretically all four pentagons should be identical to pentagon*in*^{3}(*out*^{3}(*P*)). Unfortunately, due to finite precision arithmetic, this is not the case. As a result, we should measure the error generated from the*P*and*in*()operations. For each vertex of the pentagon*out*(), say*P*, and its corresponding result after taking the*A*= (*x*,*y*)and*in*()operations, say*out*(), we compute the maximum error as follows:*A*' = (*x*',*y*')maximum error of = maximum of |*A*| and |*x*-*x*'|*y*-*y*'The maximum error of

is the maximum over all five vertices. Then, you can compile a table as follows:*P**p**out*^{2}(*in*^{2}(*P*))*out*^{3}(*in*^{3}(*P*))*in*^{2}(*out*^{2}(*P*))*in*^{3}(*out*^{3}(*P*))0.1 **fill maximum error in each entry**0.01 0.001 0.0001 0.00001 0.000001 Write a program that uses both

**float**and**double**to perform the calculation and generate the above max. error table. Name your program**pentagon.c**. You will need (1) constructing a line from two points, and (2) computing the intersection point of two lines. Please consult your calculus and analytic geometry book. Then, use your program to do the following: (1) filling the required max. error table, (2) generating the vertices of the resulting pentagons, and (3) producing an analysis for the following questions: (a) why could the error be very large? (b) will you be able to pinpoint the potential problem(s)? (c) which vertex (or vertices) causes the largest error?, and (d) any findings that are worth mentioning.