Given the following polynomial of maximum degree \(N_{Max}\):
\( P(x)=a_n x^n + a_{n-1} x^{n-1} + \cdots a_1 x + a_0 \)
where \(n\) (polynomial degree) \(\leq\) \(n_{max}\) and \(a_i\) are real numbers.
The operations of the abstract data type \(\texttt{Polynomial}\) are the following :
- Create the constant polynomial \(a_0\), where \(a_0\) is a real number
- Create the polynomial \(Q(x).x + a\), where \(Q\) is a polynomial and \(a\) is a real number
- Return the \(i^{th}\) coefficient \(a_i\) of a polynomial (\(i \geq 0\))
- Calculate the value of \(P(x)\) for a given \(x\)
- Return the polynomial degree
- Calculate the sum of two given polynomials \(P(x)\) and \(Q(x)\): the sum of two polynomials is a polynomial where the \(n^{th}\) coefficient \(a_n=b_n+c_n\) (\(b_n\) and \(c_n\) are respectively the \(n^{th}\) coefficient in the first and in the second polynomial)
Type: \(\texttt{Polynomial(NMax)}\)
Use: \(\texttt{Float, Integer}\)
Functions:
\(\begin{array}{p{1cm} l l l} & \textbf{Create}: & \texttt{Float} & \rightarrow \texttt{Polynomial}\\ & \textbf{Construct}: & \texttt{Polynomial} \times \texttt{Float} & \rightarrow \texttt{Polynomial}\\ & \textbf{Ith}: & \texttt{Polynomial} \times \texttt{Integer} & \rightarrow \texttt{Float}\\ & \textbf{Value}: & \texttt{Polynomial} \times \texttt{Float} & \rightarrow \texttt{Float}\\ & \textbf{Degree}: & \texttt{Polynomial} & \rightarrow \texttt{Integer}\\ & \textbf{Sum}: & \texttt{Polynomial} \times \texttt{Polynomial} & \rightarrow \texttt{Polynomial}\\ \end{array}\)
Constructors: ...
Preconditions: ...
Axioms: ...
Fill in missing paragraphs.
Difficulty level

This exercise is mostly suitable for students
Constructors: Create, Construct
Preconditions: None
Axioms:
Let P and Q be 2 polynomials, n an integer, x and y 2 floats
* Ith(Create(x),n) = IF n = 0 then x else 0
* Ith(Construct(P,x),n) = IF n = 0 then x else Ith(P,n-1)
* Value(Create(x),y) = x
* Value(Construct(P,x),y) = x + Value(P,y)*y
* Degree(Create(x)) = 0
* Degree(Construct(P,x)) = 1 + Degree(P)
* Sum(Create(x),Construct(P,y)) = Construct(P,y+x)
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
