1 type rel = Equal | SubsetEqual | SupersetEqual
18 (* compound operator *)
19 type compound_operator = op list
21 let string_of_cop op =
22 if op = [] then "id" else String.concat "" (List.map string_of_op op)
24 let dot_of_cop op = "\"" ^ string_of_cop op ^ "\""
26 let rec matita_of_cop v =
29 | I::tl -> "i (" ^ matita_of_cop v tl ^ ")"
30 | C::tl -> "c (" ^ matita_of_cop v tl ^ ")"
31 | M::tl -> "m (" ^ matita_of_cop v tl ^ ")"
33 (* representative, other elements in the equivalence class,
34 leq classes, geq classes *)
35 type equivalence_class =
36 compound_operator * compound_operator list *
37 equivalence_class list ref * equivalence_class list ref
39 let string_of_equivalence_class (repr,others,leq,_) =
40 String.concat " = " (List.map string_of_cop (repr::others)) ^
45 (function (repr',_,_,_) ->
46 string_of_cop repr ^ " <= " ^ string_of_cop repr') !leq)
50 let dot_of_equivalence_class (repr,others,leq,_) =
52 let eq = String.concat " = " (List.map string_of_cop (repr::others)) in
53 dot_of_cop repr ^ "[label=\"" ^ eq ^ "\"];" ^
54 if !leq = [] then "" else "\n"
55 else if !leq = [] then
61 (function (repr',_,_,_) ->
62 dot_of_cop repr' ^ " -> " ^ dot_of_cop repr ^ ";") !leq)
64 (* set of equivalence classes *)
65 type set = equivalence_class list
68 String.concat "\n" (List.map string_of_equivalence_class s)
70 let ps_of_set (to_be_considered,under_consideration,news) ?processing s =
71 let ch = open_out "xxx.dot" in
72 output_string ch "digraph G {\n";
73 (match under_consideration with
76 output_string ch (dot_of_cop repr ^ " [color=yellow];"));
78 (function repr -> output_string ch (dot_of_cop repr ^ " [color=green];")
81 (function repr -> output_string ch (dot_of_cop repr ^ " [color=navy];")
83 output_string ch (String.concat "\n" (List.map dot_of_equivalence_class s));
84 output_string ch "\n";
85 (match processing with
87 | Some (repr,rel,repr') ->
88 output_string ch (dot_of_cop repr ^ " [color=red];");
91 SupersetEqual -> repr',repr
93 | SubsetEqual -> repr,repr'
96 (dot_of_cop repr' ^ " -> " ^ dot_of_cop repr ^
98 (match rel with Equal -> "arrowhead=none " | _ -> "") ^
100 output_string ch "}\n";
102 ignore (Unix.system "tred xxx.dot > yyy.dot && dot -Tps yyy.dot > xxx.ps")
104 let test to_be_considered_and_now set rel candidate repr =
105 ps_of_set to_be_considered_and_now ~processing:(candidate,rel,repr) set;
107 (string_of_cop candidate ^ " " ^ string_of_rel rel ^ " " ^ string_of_cop repr ^ "? ");
109 assert (Unix.system "cp formal_topology.ma xxx.ma" = Unix.WEXITED 0);
110 let ch = open_out_gen [Open_append] 0 "xxx.ma" in
113 (function (repr,others,leq,_) ->
118 ("axiom ax" ^ string_of_int !i ^
120 matita_of_cop "A" repr ^ " = " ^ matita_of_cop "A" repr' ^ ".\n");
123 (function (repr',_,_,_) ->
126 ("axiom ax" ^ string_of_int !i ^
128 matita_of_cop "A" repr ^ " ⊆ " ^ matita_of_cop "A" repr' ^ ".\n");
131 let candidate',rel',repr' =
133 SupersetEqual -> repr,SubsetEqual,candidate
135 | SubsetEqual -> candidate,rel,repr
138 ("theorem foo: \\forall A." ^ matita_of_cop "A" candidate' ^
139 " " ^ string_of_rel rel' ^ " " ^
140 matita_of_cop "A" repr' ^ ". intros; auto size=6 depth=4. qed.\n");
143 (*Unix.system "../../../matitac.opt xxx.ma >> log 2>&1" = Unix.WEXITED 0*)
144 Unix.system "../../../matitac.opt xxx.ma > /dev/null 2>&1" = Unix.WEXITED 0
146 print_endline (if res then "y" else "n");
149 let normalize to_be_considered_and_now candidate set =
152 [] -> raise Not_found
153 | (repr,others,leq,geq) as eqclass :: tl ->
154 if test to_be_considered_and_now set Equal candidate repr then
155 (repr,others@[candidate],leq,geq)::tl
162 let locate to_be_considered_and_now ((repr,_,leq,geq) as node) set =
166 | (repr',_,leq',geq') as node' :: tl ->
167 if repr = repr' then ()
168 else if test to_be_considered_and_now set SubsetEqual repr repr' then
170 leq := node' :: !leq;
171 geq' := node :: !geq'
173 else if test to_be_considered_and_now set SupersetEqual repr repr' then
175 geq := node' :: !geq;
176 leq' := node :: !leq'
183 let analyze_one to_be_considered repr hecandidate (news,set) =
184 let candidate = hecandidate::repr in
185 if List.length (List.filter ((=) M) candidate) > 1 then
189 let set = normalize (to_be_considered,Some repr,news) candidate set in
195 let node = candidate,[],leq,geq in
196 let set = node::set in
197 locate (to_be_considered,Some repr,news) node set;
201 let rec explore i set news =
202 let rec aux news set =
207 List.fold_right (analyze_one tl repr) [I;C;M] (news,set)
211 let news,set = aux [] set news in
214 print_endline ("PUNTO FISSO RAGGIUNTO! i=" ^ string_of_int i);
215 print_endline (string_of_set set ^ "\n----------------");
216 ps_of_set ([],None,[]) set
220 print_endline ("NUOVA ITERAZIONE, i=" ^ string_of_int i);
221 print_endline (string_of_set set ^ "\n----------------");
222 explore (i+1) set news
226 let set = [id,[],ref [], ref []] in
227 print_endline ("PRIMA ITERAZIONE, i=0, j=0");
228 print_endline (string_of_set set ^ "\n----------------");
229 (*ignore (Unix.system "rm -f log");*)
230 ps_of_set ([id],None,[]) set;