open Misc;; type t = | Pos of int list | Neg of int list ;; let list_inter lx ly = List.filter (fun x -> List.mem x lx) ly;; let list_diff lx ly = List.filter (fun x -> not (List.mem x ly)) lx;; let (@@) = List.rev_append;; let conj x y = match x, y with | Pos lx, Pos ly -> Pos (list_inter lx ly) | Pos lx, Neg ly -> Pos (list_diff lx ly) | Neg lx, Pos ly -> Pos (list_diff ly lx) | Neg lx, Neg ly -> Neg (lx @@ ly) ;; let disj x y = match x, y with | Pos lx, Pos ly -> Pos (lx @@ ly) | Pos lx, Neg ly -> Neg (list_diff ly lx) | Neg lx, Pos ly -> Neg (list_diff lx ly) | Neg lx, Neg ly -> Neg (list_inter lx ly) ;; let except x y = match x, y with | Pos lx, Pos ly -> Pos (list_diff lx ly) | Pos lx, Neg ly -> Pos (list_inter lx ly) | Neg lx, Pos ly -> Neg (lx @@ ly) | Neg lx, Neg ly -> Pos (list_diff ly lx) ;; let same x y = match x, y with | Pos lx, Pos ly -> List.for_all (fun x -> List.mem x ly) lx && List.for_all (fun y -> List.mem y lx) ly | Pos lx, Neg ly -> false | Neg lx, Pos ly -> false | Neg lx, Neg ly -> List.for_all (fun x -> List.mem x ly) lx && List.for_all (fun y -> List.mem y lx) ly ;; let included x y = match x, y with | Pos lx, Pos ly -> List.for_all (fun x -> List.mem x ly) lx | Pos lx, Neg ly -> List.for_all (fun x -> not (List.mem x ly)) lx | Neg lx, Pos ly -> false | Neg lx, Neg ly -> List.for_all (fun y -> List.mem y lx) ly ;; let element x y = match y with | Pos ly -> List.mem x ly | Neg ly -> not (List.mem x ly) ;; let finite = function | Pos _ -> true | Neg _ -> false ;; let infinite = function | Pos _ -> false | Neg _ -> true ;; let normalize = function | Pos l -> Pos (list_sortu l) | Neg l -> Neg (list_sortu l) ;;