type zbarre = Relatif of int | MoinsInf | PlusInf ;;type intervalle = zbarre * zbarre ;;(* Q5 *)let intervalle_of_bornes p q = if p > q then raise (Invalid_argument "intervalle_of_bornes") else (Relatif p,Relatif q) ;;(* Q6 *)let dd_g q = (MoinsInf,Relatif q) ;;let dd_d p = (Relatif p,PlusInf) ;;(* Q7 *)let z_prcde_strict x y = match (x,y) with | (MoinsInf,PlusInf) -> true | (MoinsInf,Relatif _ ) -> true | (Relatif _,PlusInf) -> true | (Relatif p,Relatif q) -> p < q | (_,_) -> false ;; let prefix << = z_prcde_strict ;;let z_prcde_large x y = (x = y) or (x << y) ;;(* Q8 *)let z_conscutifs x y = match (x,y) with | (Relatif p,Relatif q) when q = p + 1 -> true | (_,_) -> false ;;(* Q9 *)let conscutifs (_,ud) (vg,_) = z_conscutifs ud vg ;;let est_avant (ug,ud) (vg,vd) = ug << vg or (ug = vg & ud << vd) ;; (* Q10 *)let est__gauche_de (_,ud) (vg,_) = ud << vg ;;(* let contient (ug,ud) (vg,vd) = (z_prcde_large ug vg) & (z_prcde_large vd ud) ;; *)let rec compacter l = match l with | u::v::q when conscutifs u v -> let t = (fst u,snd v) in compacter (t::q) | u::v::q when est__gauche_de u v -> let q' = compacter (v::q) in u::q' | u::v::q when z_prcde_large (snd u) (snd v) -> let t = (fst u,snd v) in compacter (t::q) | u::_::q -> compacter (u::q) | [] -> [] | [i] -> [i] ;;(* Q11 *)let rduire l = let l1 = sort__sort est_avant l in compacter l1 ;;(* Q12, mthode bestiale *)let union l1 l2 = rduire (l1 @ l2) ;;let i1 = intervalle_of_bornes 13 17 and i2 = intervalle_of_bornes 15 22 and i3 = intervalle_of_bornes 0 5 and i4 = dd_g 2 and i5 = dd_d 19 ;;(* Q13 *)let successeur = function | Relatif p -> Relatif (p+1) | _ -> raise (Invalid_argument "successeur") ;; let prdcesseur = function | Relatif p -> Relatif (p-1) | _ -> raise (Invalid_argument "prdcesseur") ;; let fin_complmentaire = function | (_,PlusInf) -> [] | (_,Relatif p) -> [dd_d (p+1)] | (_,MoinsInf) -> raise (Invalid_argument "fin_complmentaire") ;; let rec suite_complmentaire = function | [u] -> fin_complmentaire u | u::v::q -> let t' = (successeur(snd u),prdcesseur(fst v)) in t'::(suite_complmentaire (v::q)) | [] -> raise (Invalid_argument "suite_complmentaire") ;; let complmentaire_bis = function | [] -> [(MoinsInf,PlusInf)] | (MoinsInf,_) as t::q -> suite_complmentaire (t::q) | (Relatif p,_) as t::q -> let t' = (MoinsInf,Relatif (p-1)) in t'::(suite_complmentaire (t::q)) | (PlusInf,_)::_ -> raise (Invalid_argument "complmentaire") ;; let complmentaire l = complmentaire_bis(rduire l) ;;(* Q14 *)let intersection l1 l2 = let l1' = complmentaire(rduire l1) and l2' = complmentaire(rduire l2) in complmentaire (union l1' l2') ;;let j1 = intervalle_of_bornes 1 4 and j2 = dd_g 20 ;;let l1 = [i1;i5;i3;i4;i2] and l2 = [j1;j2];;