10 (* compound operator *)
11 type compound_operator = op list
13 let string_of_cop op =
14 if op = [] then "id" else String.concat "" (List.map string_of_op op)
16 let dot_of_cop op = "\"" ^ string_of_cop op ^ "\""
18 let rec matita_of_cop v =
21 | I::tl -> "i (" ^ matita_of_cop v tl ^ ")"
22 | C::tl -> "c (" ^ matita_of_cop v tl ^ ")"
23 | M::tl -> "m (" ^ matita_of_cop v tl ^ ")"
25 (* representative, other elements in the equivalence class,
26 leq classes, geq classes *)
27 type equivalence_class =
28 compound_operator * compound_operator list *
29 equivalence_class list ref * equivalence_class list ref
31 let string_of_equivalence_class (repr,others,leq,_) =
32 String.concat " = " (List.map string_of_cop (repr::others)) ^
37 (function (repr',_,_,_) ->
38 string_of_cop repr ^ " <= " ^ string_of_cop repr') !leq)
42 let dot_of_equivalence_class (repr,others,leq,_) =
44 let eq = String.concat " = " (List.map string_of_cop (repr::others)) in
45 dot_of_cop repr ^ "[label=\"" ^ eq ^ "\"];" ^
46 if !leq = [] then "" else "\n"
47 else if !leq = [] then
53 (function (repr',_,_,_) ->
54 dot_of_cop repr' ^ " -> " ^ dot_of_cop repr ^ ";") !leq)
56 (* set of equivalence classes *)
57 type set = equivalence_class list
60 String.concat "\n" (List.map string_of_equivalence_class s)
62 let ps_of_set (to_be_considered,under_consideration) ?processing s =
63 let ch = open_out "xxx.dot" in
64 output_string ch "digraph G {\n";
65 (match under_consideration with
68 output_string ch (dot_of_cop repr ^ " [color=yellow];"));
70 (function repr -> output_string ch (dot_of_cop repr ^ " [color=green];")
72 output_string ch (String.concat "\n" (List.map dot_of_equivalence_class s));
73 output_string ch "\n";
74 (match processing with
76 | Some (repr,rel,repr') ->
77 output_string ch (dot_of_cop repr ^ " [color=red];");
79 (dot_of_cop repr' ^ " -> " ^ dot_of_cop repr ^
81 (if rel="=" then "arrowhead=none " else "") ^
83 output_string ch "}\n";
85 ignore (Unix.system "dot -Tps xxx.dot > xxx.ps")
87 let test to_be_considered_and_now set rel candidate repr =
88 ps_of_set to_be_considered_and_now ~processing:(candidate,rel,repr) set;
90 (string_of_cop candidate ^ " " ^ rel ^ " " ^ string_of_cop repr ^ "? ");
92 assert (Unix.system "cp formal_topology.ma xxx.ma" = Unix.WEXITED 0);
93 let ch = open_out_gen [Open_append] 0 "xxx.ma" in
96 (function (repr,others,leq,_) ->
101 ("axiom ax" ^ string_of_int !i ^
103 matita_of_cop "A" repr ^ " = " ^ matita_of_cop "A" repr' ^ ".\n");
106 (function (repr',_,_,_) ->
109 ("axiom ax" ^ string_of_int !i ^
111 matita_of_cop "A" repr ^ " ⊆ " ^ matita_of_cop "A" repr' ^ ".\n");
115 ("theorem foo: \\forall A." ^ matita_of_cop "A" candidate ^ " " ^ rel ^ " " ^
116 matita_of_cop "A" repr ^ ". intros; auto size=6 depth=4. qed.\n");
119 Unix.system "../../../matitac.opt xxx.ma >> log 2>&1" = Unix.WEXITED 0
121 print_endline (if res then "y" else "n");
124 let normalize to_be_considered_and_now candidate set =
127 [] -> raise Not_found
128 | (repr,others,leq,geq) as eqclass :: tl ->
129 if test to_be_considered_and_now set "=" candidate repr then
130 (repr,others@[candidate],leq,geq)::tl
137 let locate to_be_considered_and_now ((repr,_,leq,geq) as node) set =
141 | (repr',_,leq',geq') as node' :: tl ->
142 if repr = repr' then ()
143 else if test to_be_considered_and_now set "⊆" repr repr' then
145 leq := node' :: !leq;
146 geq' := node :: !geq'
148 else if test to_be_considered_and_now set "⊆" repr' repr then
150 geq := node' :: !geq;
151 leq' := node :: !leq'
158 let analyze_one to_be_considered repr hecandidate (news,set) =
159 let candidate = hecandidate::repr in
160 if List.length (List.filter ((=) M) candidate) > 1 then
164 let set = normalize (to_be_considered,Some repr) candidate set in
170 let node = candidate,[],leq,geq in
171 let set = node::set in
172 locate (to_be_considered,Some repr) node set;
176 let rec explore i set news =
177 let rec aux news set =
182 List.fold_right (analyze_one tl repr) [I;C;M] (news,set)
186 let news,set = aux [] set news in
189 print_endline ("PUNTO FISSO RAGGIUNTO! i=" ^ string_of_int i);
190 print_endline (string_of_set set ^ "\n----------------");
191 ps_of_set ([],None) set
195 print_endline ("NUOVA ITERAZIONE, i=" ^ string_of_int i);
196 print_endline (string_of_set set ^ "\n----------------");
197 explore (i+1) set news
201 let set = [id,[],ref [], ref []] in
202 print_endline ("PRIMA ITERAZIONE, i=0, j=0");
203 print_endline (string_of_set set ^ "\n----------------");
204 ignore (Unix.system "rm -f log");
205 ps_of_set ([id],None) set;