17 [C;M;I], Le, [M;I]; (* ??? *)
19 [I;M;C], Ge, [I;M]; (* ??? *)
27 let swap = function Le -> Ge | Ge -> Le;;
32 | M::tl -> new_dir (swap dir) tl
33 | (C|I)::tl -> new_dir dir tl
36 let string_of_dir = function Le -> "<=" | Ge -> ">=";;
40 (List.map (function I -> "i" | C -> "c" | M -> "-") w)
43 let string_of_eqclass eqc =
44 let eqc = List.sort compare eqc in
45 String.concat "=" (List.map string_of_w eqc)
48 let print = List.iter (fun eqc -> prerr_endline (string_of_eqclass eqc));;
52 let (@@) l1 ll2 = List.map (function l2 -> l1 @ l2) ll2;;
58 | he::tl -> aux (if List.mem he l then l else he::l) tl
63 let rec apply_rule_at_beginning (lhs,dir',rhs) (w,dir) =
70 | x::lhs,x'::w when x = x' -> aux (lhs,w)
71 | _,_ -> raise NoMatch
73 rhs @@ apply_rules (aux (lhs,w),new_dir dir lhs)
74 and apply_rules (w,_ as w_and_dir) =
81 (try apply_rule_at_beginning rule w_and_dir
89 let apply_rules (w,dir as w_and_dir) =
90 List.map (fun w' -> w,dir,w')
91 (uniq (apply_rules w_and_dir))
94 let step (l : w list) =
98 (function w -> List.map (fun x -> x@w) [[I];[C];[M];[]])
102 let classify (l : w list) =
103 List.flatten (List.map (fun x -> apply_rules (x,Le) @ apply_rules (x,Ge)) l)
108 (function (w,dir,w') ->
109 prerr_endline (string_of_w w ^ string_of_dir dir ^ string_of_w w'))
112 print_graph (classify (step (step (step [[]]))));;
116 List.iter (function eqc -> ns := eqc::!ns) s;
121 let eqc = simplify ([x] @@ eqc) in
122 if not (List.exists (fun eqc' -> eqc === eqc') !ns) then
132 List.for_all (fun x -> List.mem x l2) l1
135 let (===) l1 l2 = subseteq l1 l2 && subseteq l2 l1;;
139 let l' = uniq (List.flatten (List.map apply_rules l)) in
140 if l === l' then l else aux l'
145 let combine_class_with_classes l1 =
150 if List.exists (fun x -> List.mem x l2) l1 then
158 let combine_classes l =
162 | he::tl -> aux (combine_class_with_classes he acc) tl
167 let step (s : eqclass list) =
169 List.iter (function eqc -> ns := eqc::!ns) s;
174 let eqc = simplify ([x] @@ eqc) in
175 if not (List.exists (fun eqc' -> eqc === eqc') !ns) then
182 let classes = step (step (step (step [[[]]]))) in
183 prerr_endline ("Numero di classi trovate: " ^ string_of_int (List.length classes));