type t_intervalle =
{ inf: float ;
sup: float }
let sof x = string_of_int (int_of_float x)
let intervalle_image it = "[" ^ sof it.inf ^ ", " ^ sof it.sup ^ "]"
let est_inclus a b = (a.inf >= b.inf && a.sup <= b.sup)
let disjoints a b = (a.sup < b.inf || a.inf > b.sup)
let affichage_gen f_inclus f_disjoint f_image i1 i2 =
let s1 = f_image i1
and s2 = f_image i2 in
if f_inclus i1 i2 then Printf.printf "%s est inclus dans %s\n" s1 s2
else if f_inclus i2 i1 then Printf.printf "%s est inclus dans %s\n" s2 s1
else if f_disjoint i1 i2 then Printf.printf "%s et %s sont disjoints\n" s1 s2
else Printf.printf "%s et %s ne sont pas disjoints, ni inclus\n" s1 s2
let afficher_relation = affichage_gen est_inclus disjoints intervalle_image
type t_prod =
{ left: t_intervalle ;
right: t_intervalle }
let prod_image p = intervalle_image p.left ^ " x " ^ intervalle_image p.right
let prod_est_inclus a b = est_inclus a.left b.left && est_inclus a.right b.right
let prod_disjoints a b = disjoints a.left b.left || disjoints a.right b.right
let prod_afficher_relation = affichage_gen prod_est_inclus prod_disjoints prod_image
let prod a b = { left = a ; right = b }
let () =
let c = { inf = 5.0 ; sup = 10.0 }
and d = { inf = 7.0 ; sup = 8.0 }
and e = { inf = 4.0 ; sup = 6.0 }
in
afficher_relation c d ;
afficher_relation d c ;
afficher_relation c e ;
afficher_relation d e ;
prod_afficher_relation (prod c c) (prod d d) ;
prod_afficher_relation (prod c d) (prod d c) ;
prod_afficher_relation (prod d c) (prod e c) ;
()