type zbarre = Relatif of int | MoinsInf | PlusInf ;;type intervalle = {g : zbarre ; d : zbarre} ;;(* Q5 *)let intervalle_of_bornes p q = if p > q then raise (Invalid_argument "intervalle_of_bornes") else {g = Relatif p ; d = Relatif q} ;;(* Q6 *)let dd_g q = {g = MoinsInf ; d = Relatif q} ;;let dd_d p = {g = Relatif p ; d = 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 u v = z_conscutifs u.d v.g ;;let est_avant u v = u.g << v.g or (u.g = v.g & u.d << v.d);; (* Q10 *)let est__gauche_de u v = u.d << v.g ;;(* let contient u v = (z_prcde_large u.g v.g) & (z_prcde_large v.d u.d) ;; *)let rec compacter l = match l with | [] -> [] | [i] -> [i] | u::v::q when conscutifs u v -> let t = {g = u.g ; d = v.d} 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 u.d v.d -> let t = {g = u.g ; d = v.d} in compacter (t::q) | u::v::q -> let t = {g = u.g ; d = u.d} in compacter (t::q) ;;(* 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 | {g = _ ; d = PlusInf} -> [] | {g = _ ; d = Relatif p} -> [dd_d (p+1)] | {g = _ ; d = MoinsInf} -> raise (Invalid_argument "fin_complmentaire") ;; let rec suite_complmentaire = function | [u] -> fin_complmentaire u | u::v::q -> let t' = {g = successeur u.d ; d = prdcesseur v.g} in t'::(suite_complmentaire (v::q)) | [] -> raise (Invalid_argument "suite_complmentaire") ;; let complmentaire_bis = function | [] -> [{g = MoinsInf ; d = PlusInf}] | {g = MoinsInf ; d = _} as t::q -> suite_complmentaire (t::q) | {g = Relatif p ; d = _} as t::q -> let t' = {g = MoinsInf ; d = Relatif (p-1)} in t'::(suite_complmentaire (t::q)) | {g = PlusInf ; d = _}::_ -> 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];;