Exercise 2 - The roots of a polynomialExercisesExercise 1 - Usual operations over polynomialsDocumentation and user's manualTable of contentsOCaml programs

Exercise 1 - Usual operations over polynomials

Assume an Objective Caml toplevel in which the following modules (download an archive containing them) have been loaded and opened:

Write definitions of functional values according to the following specifications:

 1 
  Name:  eq_poly . Type:  rat_poly * rat_poly -> bool . Tests two polynomials for equality.

 2 
  Name:  add_poly . Type:  rat_poly * rat_poly -> rat_poly . Adds two polynomials.

 3 
  Name:  x_times . Type:  rat_poly -> rat_poly . Multiply a polynomial by the monomial X.

 4 
  Name:  deriv_poly . Type:  rat_poly -> rat_poly . Computes the derivative of a polynomial.

 5 
  Name:  rat_times_poly . Type:  rat * rat_poly -> rat_poly . Computes the polynomial ap given the pair (a,p) where a is a rational and p is a polynomial.

 6 
  Name:  mult_poly . Type:  rat_poly * rat_poly -> rat_poly . Multiplies two polynomials.

 7 
  Name:  degree . Type:  rat_poly -> int . Computes the degree of a non-zero polynomial. Fails if the polynomial is zero.

 8 
  Name:  leading_coef . Type:  rat_poly -> rat . Computes the leading coefficient of a non-zero polynomial. Fails if the polynomial is zero.

 9 
  Name:  monomial . Type:  rat * int -> rat_poly . Computes the monomial aXd from a pair (a,d) where a is a non-zero rational and d is a non-negative integer. Fails if a=0 or d<0.

 10 
  Name:  euclid_div_poly . Type:  rat_poly * rat_poly -> rat_poly * rat_poly . Computes the pair (q,r) where q is the quotient and r is the remainder in the euclidean division of p1 by p2, given a pair (p1,p2) of polynomials where the divisor p2 is non-zero. Fails if p2 is zero.

 11 
  Name:  quotient_poly . Type:  rat_poly * rat_poly -> rat_poly . Computes the quotient in the euclidean division of p1 by p2, given a pair (p1,p2) of polynomials where the divisor p2 is non-zero. Fails if p2 is zero.

 12 
  Name:  mod_poly . Type:  rat_poly * rat_poly -> rat_poly . Computes the remainder in the euclidean division of p1 by p2, given a pair (p1,p2) of polynomials where the divisor p2 is non-zero. Fails if p2 is zero.

 13 
  Name:  gcd_poly . Type:  rat_poly * rat_poly -> rat_poly . Computes the gcd (greatest common divisor) of a pair of non-zero polynomials. Fails if a component of the pair is zero.

 14 
  Name:  eval_poly . Type:  rat_poly * rat -> rat . Evaluation of a polynomial.

 15 
  Name:  function_of_poly . Type:  rat_poly -> (rat -> rat) . Computes the polynomial function associated with a polynomial.

 16 
  Name:  poly_of_coef_list . Type:  rat list -> rat_poly . Computes the polynomial given a list of its coefficients ordered according to decreasing degrees (it is written a list rather than the list because this list can begin with useless zeros).


Latest update : October 5, 2006
This document was translated from LaTeX by Hyperlatex 2.5, which is not the latest version of Hyperlatex.

Exercise 2 - The roots of a polynomialExercisesExercise 1 - Usual operations over polynomialsDocumentation and user's manualTable of contentsOCaml programs