(*alínea 2*)
(* to_string grau poli = 
   grau = grau máximo (comprimento da lista poli -1)
   poli= o polinómio, na sua forma de lista de coeficientes
*)

let rec to_string grau = function 
    [] -> ""
  | [el] when el = 0. -> ""
  | [el] -> string_of_float el
  | el1::el2::li ->
    let inicio =
      if el1 = 0.  then ""
      else
        let coef = if el1 = 1. then "" else (string_of_float el1) in
        let gr = if grau = 0 then ""
                 else if grau = 1 then "x" else "x^"^(string_of_int grau) in
        coef^gr
    in
    let fim = if el2 = 0. then "" else " + " in
    inicio^fim^(to_string (grau-1) (el2::li))

This document was generated using caml2html