open Polynome
module I =
struct
type t = int
let zéro = 0
let unité = 1
let plus = ( + )
let mult = ( * )
let equal = ( = )
let print = print_int
end;;
module Xi = Make (I);;
let poly t =
Array.fold_left
(fun r (s, k) -> Xi.plus (Xi.monôme (int_of_string s) k) r)
Xi.zéro
(Array.mapi (fun i x -> (x, i)) t)
;;
let suffix t k = Array.sub t k (Array.length t - k);;
let main () =
let écho, k =
if Array.length Sys.argv > 1 && Sys.argv.(1) = "-v" then true, 2
else false, 1 in
let t = suffix Sys.argv k in
let p = poly t in
let print_eval x =
if écho then Printf.printf "P(%d) = " x;
print_int (Xi.eval p x); print_newline() in
if écho then (print_string "P = "; Xi.print p; print_newline());
while true do print_eval (int_of_string (read_line())) done
;;
try main() with End_of_file -> ();; |
|