- Introduction.
Polynomial arithmetic is a classic application of linked data structures. For this project, you must write OCaml code that adds, multiplies, negates, and subtracts polynomials. Some of your code will use OCaml higher-order functions, which you must also write.
- Theory.
For the purposes of this project, a polynomial is a finite sum of zero or more terms, like this.
anxn + an−1xn−1 + an−2xn−2 ⋯ + a2x2 + a1x1 + a0x0
Each term has a coefficient, shown as a subscripted a. It also has a variable, shown as x with a superscripted exponent. All polynomials have the same variable. The polynomials’ coefficients are nonzero integers, its exponents are nonnegative integers, and their terms appear in decreasing order of their exponents. A polynomial with no terms is assumed to be 0. For example, suppose that we have three polynomials, p, q, and r, like this.
p = 3x⁵ + 2x⁴ + 2x³ − 1x² + 5x⁰
q = 7x⁴ + 1x² − 4x¹ − 3x⁰
r = 2x¹ + 3x⁰